fix(tests): Resolve pipeline #243 test failures
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
ci/woodpecker/pr/woodpecker Pipeline failed

Fixed 27 test failures by addressing several categories of issues:

Security spec tests (coordinator-integration, stitcher):
- Changed async test assertions to synchronous since ApiKeyGuard.canActivate
  is synchronous and throws directly rather than returning rejected promises
- Use expect(() => fn()).toThrow() instead of await expect(fn()).rejects.toThrow()

Federation controller tests:
- Added CsrfGuard and WorkspaceGuard mock overrides to test module
- Set DEFAULT_WORKSPACE_ID environment variable for handleIncomingConnection tests
- Added proper afterEach cleanup for environment variable restoration

Federation service tests:
- Updated RSA key generation tests to use Vitest 4.x timeout syntax
  (second argument as options object, not third argument)

Prisma service tests:
- Replaced vi.spyOn for $transaction and setWorkspaceContext with direct
  method assignment to avoid spy restoration issues
- Added vi.clearAllMocks() in afterEach to properly reset between tests

Integration tests (job-events, fulltext-search):
- Added conditional skip when DATABASE_URL is not set to prevent failures
  in environments without database access

Remaining 7 failures are pre-existing fulltext-search integration tests
that require specific PostgreSQL triggers not present in test database.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Jason Woltje
2026-02-06 12:15:21 -06:00
parent 519093f42e
commit 10b49c4afb
7 changed files with 133 additions and 54 deletions

View File

@@ -53,79 +53,79 @@ describe("CoordinatorIntegrationController - Security", () => {
expect(guards).toContain(ApiKeyGuard);
});
it("POST /coordinator/jobs should require authentication", async () => {
it("POST /coordinator/jobs should require authentication", () => {
const mockContext = {
switchToHttp: () => ({
getRequest: () => ({ headers: {} }),
}),
};
await expect(guard.canActivate(mockContext as any)).rejects.toThrow(UnauthorizedException);
expect(() => guard.canActivate(mockContext as never)).toThrow(UnauthorizedException);
});
it("PATCH /coordinator/jobs/:id/status should require authentication", async () => {
it("PATCH /coordinator/jobs/:id/status should require authentication", () => {
const mockContext = {
switchToHttp: () => ({
getRequest: () => ({ headers: {} }),
}),
};
await expect(guard.canActivate(mockContext as any)).rejects.toThrow(UnauthorizedException);
expect(() => guard.canActivate(mockContext as never)).toThrow(UnauthorizedException);
});
it("PATCH /coordinator/jobs/:id/progress should require authentication", async () => {
it("PATCH /coordinator/jobs/:id/progress should require authentication", () => {
const mockContext = {
switchToHttp: () => ({
getRequest: () => ({ headers: {} }),
}),
};
await expect(guard.canActivate(mockContext as any)).rejects.toThrow(UnauthorizedException);
expect(() => guard.canActivate(mockContext as never)).toThrow(UnauthorizedException);
});
it("POST /coordinator/jobs/:id/complete should require authentication", async () => {
it("POST /coordinator/jobs/:id/complete should require authentication", () => {
const mockContext = {
switchToHttp: () => ({
getRequest: () => ({ headers: {} }),
}),
};
await expect(guard.canActivate(mockContext as any)).rejects.toThrow(UnauthorizedException);
expect(() => guard.canActivate(mockContext as never)).toThrow(UnauthorizedException);
});
it("POST /coordinator/jobs/:id/fail should require authentication", async () => {
it("POST /coordinator/jobs/:id/fail should require authentication", () => {
const mockContext = {
switchToHttp: () => ({
getRequest: () => ({ headers: {} }),
}),
};
await expect(guard.canActivate(mockContext as any)).rejects.toThrow(UnauthorizedException);
expect(() => guard.canActivate(mockContext as never)).toThrow(UnauthorizedException);
});
it("GET /coordinator/jobs/:id should require authentication", async () => {
it("GET /coordinator/jobs/:id should require authentication", () => {
const mockContext = {
switchToHttp: () => ({
getRequest: () => ({ headers: {} }),
}),
};
await expect(guard.canActivate(mockContext as any)).rejects.toThrow(UnauthorizedException);
expect(() => guard.canActivate(mockContext as never)).toThrow(UnauthorizedException);
});
it("GET /coordinator/health should require authentication", async () => {
it("GET /coordinator/health should require authentication", () => {
const mockContext = {
switchToHttp: () => ({
getRequest: () => ({ headers: {} }),
}),
};
await expect(guard.canActivate(mockContext as any)).rejects.toThrow(UnauthorizedException);
expect(() => guard.canActivate(mockContext as never)).toThrow(UnauthorizedException);
});
});
describe("Valid Authentication", () => {
it("should allow requests with valid API key", async () => {
it("should allow requests with valid API key", () => {
const mockContext = {
switchToHttp: () => ({
getRequest: () => ({
@@ -134,11 +134,11 @@ describe("CoordinatorIntegrationController - Security", () => {
}),
};
const result = await guard.canActivate(mockContext as any);
const result = guard.canActivate(mockContext as never);
expect(result).toBe(true);
});
it("should reject requests with invalid API key", async () => {
it("should reject requests with invalid API key", () => {
const mockContext = {
switchToHttp: () => ({
getRequest: () => ({
@@ -147,8 +147,8 @@ describe("CoordinatorIntegrationController - Security", () => {
}),
};
await expect(guard.canActivate(mockContext as any)).rejects.toThrow(UnauthorizedException);
await expect(guard.canActivate(mockContext as any)).rejects.toThrow("Invalid API key");
expect(() => guard.canActivate(mockContext as never)).toThrow(UnauthorizedException);
expect(() => guard.canActivate(mockContext as never)).toThrow("Invalid API key");
});
});
});