返回 DeepSeek-Reasonix
deploy_workflow_contract.test.ts
根目录 / workers / crash-report / src / deploy_workflow_contract.test.ts
1 import { describe, expect, it } from "vitest";
2 // @ts-expect-error Test code uses Node to inspect the repository workflow.
3 import { readFileSync } from "node:fs";
4
5 const workflow = readFileSync("../../.github/workflows/deploy-crash-worker.yml", "utf8");
6
7 describe("Firebase crash data migration workflow", () => {
8 it("keeps manual migration separate from Worker deployment", () => {
9 expect(workflow).toContain("firebase_data_action:");
10 expect(workflow).toContain("- dry-run");
11 expect(workflow).toContain("- apply");
12 expect(workflow).toContain("- verify-only");
13 expect(workflow).toContain(
14 "if: github.event_name == 'push' || inputs.firebase_data_action == 'none'",
15 );
16 expect(workflow).toContain(
17 "if: github.event_name == 'workflow_dispatch' && inputs.firebase_data_action != 'none'",
18 );
19
20 const migrationJob = workflow.slice(workflow.indexOf(" migrate-firebase-data:"));
21 expect(migrationJob).not.toContain("wrangler deploy");
22 });
23
24 it("requires the protected branch, environment approval, and all secrets", () => {
25 const migrationJob = workflow.slice(workflow.indexOf(" migrate-firebase-data:"));
26 expect(migrationJob).toContain("environment: canary");
27 expect(migrationJob).toContain('"refs/heads/main-v2"');
28 expect(migrationJob).toContain("CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}");
29 expect(migrationJob).toContain("FIREBASE_DATABASE_URL: ${{ secrets.FIREBASE_DATABASE_URL }}");
30 expect(migrationJob).toContain("FIREBASE_CLIENT_EMAIL: ${{ secrets.FIREBASE_CLIENT_EMAIL }}");
31 expect(migrationJob).toContain("FIREBASE_PRIVATE_KEY: ${{ secrets.FIREBASE_PRIVATE_KEY }}");
32 });
33
34 it("guards apply and verifies immediately on the same runner", () => {
35 const migrationJob = workflow.slice(workflow.indexOf(" migrate-firebase-data:"));
36 expect(migrationJob).toContain(
37 'if [ "$FIREBASE_DATA_CONFIRMATION" != "APPLY_FIREBASE_CRASH_DATA" ]; then',
38 );
39 const apply = migrationJob.indexOf("npm run migrate:firebase-data -- --apply");
40 const verify = migrationJob.indexOf("npm run migrate:firebase-data -- --verify-only");
41 expect(apply).toBeGreaterThan(0);
42 expect(verify).toBeGreaterThan(apply);
43 });
44 });
45
45 lines TYPESCRIPT