Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions test/workflows/paths-mirror.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { load } from "js-yaml";
import { describe, expect, it } from "vitest";

// ci.yml + ci-skip.yml と codeql.yml + codeql-skip.yml は
// paths-ignore (実 workflow) と paths (stub workflow) が完全補完である必要があり、
// 片側だけ変わると docs-only PR で required check の状態が壊れる
// (未生成 → BLOCKED、または stub 側が起動せず ci.yml が実 job で走る)。
// 4 workflow 間で path 定義の drift を防ぐ pattern-level 検証。

const WORKFLOWS_DIR = join(process.cwd(), ".github", "workflows");

type WorkflowEvents = {
push?: { "paths-ignore"?: string[]; paths?: string[] };
pull_request?: { "paths-ignore"?: string[]; paths?: string[] };
};

type Workflow = { on: WorkflowEvents };

function loadWorkflow(name: string): Workflow {
const raw = readFileSync(join(WORKFLOWS_DIR, name), "utf8");
return load(raw) as Workflow;
}

function sortedPaths(list: string[] | undefined): string[] {
return [...(list ?? [])].sort();
}

const CI = loadWorkflow("ci.yml");
const CI_SKIP = loadWorkflow("ci-skip.yml");
const CODEQL = loadWorkflow("codeql.yml");
const CODEQL_SKIP = loadWorkflow("codeql-skip.yml");

describe("workflow paths-mirror", () => {
describe("ci pair (ci.yml + ci-skip.yml)", () => {
it("ci.yml: push.paths-ignore === pull_request.paths-ignore", () => {
expect(sortedPaths(CI.on.push?.["paths-ignore"])).toEqual(
sortedPaths(CI.on.pull_request?.["paths-ignore"]),
);
});

it("ci-skip.yml: push.paths === pull_request.paths", () => {
expect(sortedPaths(CI_SKIP.on.push?.paths)).toEqual(
sortedPaths(CI_SKIP.on.pull_request?.paths),
);
});

it("ci.yml paths-ignore === ci-skip.yml paths (補完 pair 整合)", () => {
expect(sortedPaths(CI.on.pull_request?.["paths-ignore"])).toEqual(
sortedPaths(CI_SKIP.on.pull_request?.paths),
);
});
});

describe("codeql pair (codeql.yml + codeql-skip.yml)", () => {
it("codeql.yml: push.paths-ignore === pull_request.paths-ignore", () => {
expect(sortedPaths(CODEQL.on.push?.["paths-ignore"])).toEqual(
sortedPaths(CODEQL.on.pull_request?.["paths-ignore"]),
);
});

it("codeql.yml paths-ignore === codeql-skip.yml paths (補完 pair 整合)", () => {
expect(sortedPaths(CODEQL.on.pull_request?.["paths-ignore"])).toEqual(
sortedPaths(CODEQL_SKIP.on.pull_request?.paths),
);
});
});

describe("全 pair 統一 pattern", () => {
it("4 workflow の path 定義がすべて同一", () => {
const canonical = sortedPaths(CI.on.pull_request?.["paths-ignore"]);
expect(canonical).not.toHaveLength(0);
expect(sortedPaths(CI_SKIP.on.pull_request?.paths)).toEqual(canonical);
expect(sortedPaths(CODEQL.on.pull_request?.["paths-ignore"])).toEqual(canonical);
expect(sortedPaths(CODEQL_SKIP.on.pull_request?.paths)).toEqual(canonical);
});
});
});
2 changes: 1 addition & 1 deletion tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["electron", "electron.vite.config.ts", "src/types", "src/lib/lru-cache.ts"]
"include": ["electron", "electron.vite.config.ts", "src/types", "src/lib/lru-cache.ts", "test"]
}
9 changes: 9 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export default defineConfig({
exclude: [...configDefaults.exclude, "e2e/**", "out/**"],
},
},
{
extends: true,
test: {
name: "workflows",
environment: "node",
include: ["test/**/*.test.ts"],
exclude: [...configDefaults.exclude, "e2e/**", "out/**"],
},
},
],
},
});
Loading