fix(tests): Correct pipeline test failures (#239)
Fixes 4 test failures identified in pipeline run 239: 1. RunnerJobsService cancel tests: - Use updateMany mock instead of update (service uses optimistic locking) - Add version field to mock objects - Use mockResolvedValueOnce for sequential findUnique calls 2. ActivityService error handling tests: - Update tests to expect null return (fire-and-forget pattern) - Activity logging now returns null on DB errors per security fix 3. SecretScannerService unreadable file test: - Handle root user case where chmod 0o000 doesn't prevent reads - Test now adapts expectations based on runtime permissions Quality gates: lint ✓ typecheck ✓ tests ✓ - @mosaic/orchestrator: 612 tests passing - @mosaic/web: 650 tests passing Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -802,7 +802,7 @@ describe("ActivityService", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("should handle database errors gracefully when logging activity", async () => {
|
||||
it("should handle database errors gracefully when logging activity (fire-and-forget)", async () => {
|
||||
const input: CreateActivityLogInput = {
|
||||
workspaceId: "workspace-123",
|
||||
userId: "user-123",
|
||||
@@ -814,7 +814,9 @@ describe("ActivityService", () => {
|
||||
const dbError = new Error("Database connection failed");
|
||||
mockPrismaService.activityLog.create.mockRejectedValue(dbError);
|
||||
|
||||
await expect(service.logActivity(input)).rejects.toThrow("Database connection failed");
|
||||
// Activity logging is fire-and-forget - returns null on error instead of throwing
|
||||
const result = await service.logActivity(input);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("should handle extremely large details objects", async () => {
|
||||
@@ -1132,7 +1134,7 @@ describe("ActivityService", () => {
|
||||
});
|
||||
|
||||
describe("database error handling", () => {
|
||||
it("should handle database connection failures in logActivity", async () => {
|
||||
it("should handle database connection failures in logActivity (fire-and-forget)", async () => {
|
||||
const createInput: CreateActivityLogInput = {
|
||||
workspaceId: "workspace-123",
|
||||
userId: "user-123",
|
||||
@@ -1144,7 +1146,9 @@ describe("ActivityService", () => {
|
||||
const dbError = new Error("Connection refused");
|
||||
mockPrismaService.activityLog.create.mockRejectedValue(dbError);
|
||||
|
||||
await expect(service.logActivity(createInput)).rejects.toThrow("Connection refused");
|
||||
// Activity logging is fire-and-forget - returns null on error instead of throwing
|
||||
const result = await service.logActivity(createInput);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("should handle Prisma timeout errors in findAll", async () => {
|
||||
|
||||
@@ -374,25 +374,32 @@ describe("RunnerJobsService", () => {
|
||||
id: jobId,
|
||||
workspaceId,
|
||||
status: RunnerJobStatus.PENDING,
|
||||
version: 1,
|
||||
};
|
||||
|
||||
const mockUpdatedJob = {
|
||||
...mockExistingJob,
|
||||
status: RunnerJobStatus.CANCELLED,
|
||||
completedAt: new Date(),
|
||||
version: 2,
|
||||
};
|
||||
|
||||
mockPrismaService.runnerJob.findUnique.mockResolvedValue(mockExistingJob);
|
||||
mockPrismaService.runnerJob.update.mockResolvedValue(mockUpdatedJob);
|
||||
// First findUnique returns existing job, second returns updated job
|
||||
mockPrismaService.runnerJob.findUnique
|
||||
.mockResolvedValueOnce(mockExistingJob)
|
||||
.mockResolvedValueOnce(mockUpdatedJob);
|
||||
// updateMany returns count for optimistic locking
|
||||
mockPrismaService.runnerJob.updateMany.mockResolvedValue({ count: 1 });
|
||||
|
||||
const result = await service.cancel(jobId, workspaceId);
|
||||
|
||||
expect(result).toEqual(mockUpdatedJob);
|
||||
expect(prisma.runnerJob.update).toHaveBeenCalledWith({
|
||||
where: { id: jobId, workspaceId },
|
||||
expect(mockPrismaService.runnerJob.updateMany).toHaveBeenCalledWith({
|
||||
where: { id: jobId, workspaceId, version: mockExistingJob.version },
|
||||
data: {
|
||||
status: RunnerJobStatus.CANCELLED,
|
||||
completedAt: expect.any(Date),
|
||||
version: { increment: 1 },
|
||||
},
|
||||
});
|
||||
});
|
||||
@@ -405,17 +412,23 @@ describe("RunnerJobsService", () => {
|
||||
id: jobId,
|
||||
workspaceId,
|
||||
status: RunnerJobStatus.QUEUED,
|
||||
version: 1,
|
||||
};
|
||||
|
||||
mockPrismaService.runnerJob.findUnique.mockResolvedValue(mockExistingJob);
|
||||
mockPrismaService.runnerJob.update.mockResolvedValue({
|
||||
const mockUpdatedJob = {
|
||||
...mockExistingJob,
|
||||
status: RunnerJobStatus.CANCELLED,
|
||||
});
|
||||
version: 2,
|
||||
};
|
||||
|
||||
mockPrismaService.runnerJob.findUnique
|
||||
.mockResolvedValueOnce(mockExistingJob)
|
||||
.mockResolvedValueOnce(mockUpdatedJob);
|
||||
mockPrismaService.runnerJob.updateMany.mockResolvedValue({ count: 1 });
|
||||
|
||||
await service.cancel(jobId, workspaceId);
|
||||
|
||||
expect(prisma.runnerJob.update).toHaveBeenCalled();
|
||||
expect(mockPrismaService.runnerJob.updateMany).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("should throw NotFoundException if job not found", async () => {
|
||||
|
||||
Reference in New Issue
Block a user