File
Blob: tests/integration/workflows-runner-happy-path.test.ts
| 1 | import { afterAll, beforeAll, describe, it } from "vitest"; |
| 2 | import { join } from "node:path"; |
| 3 | import { mkdtemp, rm } from "node:fs/promises"; |
| 4 | import { tmpdir } from "node:os"; |
| 5 | |
| 6 | import { |
| 7 | type IntegrationContext, |
| 8 | type OperatorIdentity, |
| 9 | type SessionId, |
| 10 | applyMigrations, |
| 11 | assert, |
| 12 | closeContextLogs, |
| 13 | createOperatorIdentity, |
| 14 | oidcSignInOnce, |
| 15 | printFailureContext, |
| 16 | printLogTails, |
| 17 | startDevServer, |
| 18 | stopDevServer, |
| 19 | } from "./queue-runner/harness"; |
| 20 | import { scenarioWorkflowRunPasses } from "./queue-runner/scenarios"; |
| 21 | import { startMockOidcProvider, type MockOidcServer } from "../helpers/oidc-mock"; |
| 22 | |
| 23 | describe("workflows runner integration", () => { |
| 24 | let context: IntegrationContext | null = null; |
| 25 | let mockOidc: MockOidcServer | null = null; |
| 26 | let operatorIdentity: OperatorIdentity | null = null; |
| 27 | let tempDir: string | null = null; |
| 28 | let preserveTempState = false; |
| 29 | |
| 30 | const requireContext = (): IntegrationContext => { |
| 31 | assert(context !== null, "Integration context not initialized."); |
| 32 | return context; |
| 33 | }; |
| 34 | |
| 35 | const ensureOperatorSession = async (): Promise<SessionId> => { |
| 36 | const currentContext = requireContext(); |
| 37 | |
| 38 | if (operatorIdentity === null) { |
| 39 | operatorIdentity = createOperatorIdentity(); |
| 40 | } |
| 41 | |
| 42 | return await oidcSignInOnce(currentContext, operatorIdentity); |
| 43 | }; |
| 44 | |
| 45 | beforeAll(async () => { |
| 46 | tempDir = await mkdtemp(join(tmpdir(), "anvil-workflows-int-")); |
| 47 | console.log(`Using temp state: ${tempDir}`); |
| 48 | |
| 49 | try { |
| 50 | mockOidc = await startMockOidcProvider(); |
| 51 | await applyMigrations(tempDir); |
| 52 | context = await startDevServer(tempDir, mockOidc.issuer); |
| 53 | } catch (error) { |
| 54 | preserveTempState = true; |
| 55 | throw error; |
| 56 | } |
| 57 | }); |
| 58 | |
| 59 | afterAll(async () => { |
| 60 | if (context) { |
| 61 | await stopDevServer(context.serverProcess); |
| 62 | await closeContextLogs(context); |
| 63 | } |
| 64 | |
| 65 | if (mockOidc) { |
| 66 | await mockOidc.close(); |
| 67 | } |
| 68 | |
| 69 | if (!tempDir) { |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | if (!preserveTempState) { |
| 74 | if (context) { |
| 75 | await rm(context.devVarsPath, { force: true }); |
| 76 | } |
| 77 | await rm(tempDir, { recursive: true, force: true }); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | if (context) { |
| 82 | printFailureContext(context); |
| 83 | await printLogTails(context); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | console.error(`Preserved temp state: ${tempDir}`); |
| 88 | }); |
| 89 | |
| 90 | it("signs in with tessera and passes a single workflow-backed run", async () => { |
| 91 | const currentContext = requireContext(); |
| 92 | |
| 93 | try { |
| 94 | const sessionId = await ensureOperatorSession(); |
| 95 | await scenarioWorkflowRunPasses(currentContext.baseUrl, sessionId); |
| 96 | } catch (error) { |
| 97 | preserveTempState = true; |
| 98 | throw error; |
| 99 | } |
| 100 | }); |
| 101 | }); |