Skip to content

Commit 8565cbb

Browse files
committed
[policy] Isolate CI base fallback tests
Change-Id: I16ef1f0a809511a622bd1c0ef1d7f594360164c6
1 parent 0ebba4d commit 8565cbb

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

scripts/verify.test.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,11 @@ describe("verification profiles", () => {
4343
});
4444

4545
test("rejects an explicit BASE that is not a commit", () => {
46-
expect(() => resolveComparisonBase("not-a-real-commit")).toThrow("is not a commit");
46+
expect(() => resolveComparisonBase("not-a-real-commit", false)).toThrow("is not a commit");
4747
});
4848

4949
test("falls back when a push base disappeared after a GitHub history rewrite", () => {
50-
const previous = process.env.GITHUB_ACTIONS;
51-
process.env.GITHUB_ACTIONS = "true";
52-
try {
53-
expect(resolveComparisonBase("not-a-real-commit")).toBeTruthy();
54-
} finally {
55-
if (previous === undefined) delete process.env.GITHUB_ACTIONS;
56-
else process.env.GITHUB_ACTIONS = previous;
57-
}
50+
expect(resolveComparisonBase("not-a-real-commit", true)).toBeTruthy();
5851
});
5952
});
6053

scripts/verify.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@ function gitCommitExists(ref: string): boolean {
5252
return Bun.spawnSync(["git", "cat-file", "-e", `${ref}^{commit}`], { cwd: root, stderr: "ignore" }).exitCode === 0;
5353
}
5454

55-
export function resolveComparisonBase(explicitBase = process.env.BASE): string | undefined {
55+
export function resolveComparisonBase(
56+
explicitBase = process.env.BASE,
57+
allowMissingExplicitBase = process.env.GITHUB_ACTIONS === "true",
58+
): string | undefined {
5659
if (explicitBase && !/^0+$/.test(explicitBase)) {
5760
if (gitCommitExists(explicitBase)) return explicitBase;
58-
if (process.env.GITHUB_ACTIONS !== "true") {
61+
if (!allowMissingExplicitBase) {
5962
throw new Error(`Verification BASE '${explicitBase}' is not a commit.`);
6063
}
6164
console.warn(`Verification BASE '${explicitBase}' is unavailable after a history rewrite; using a local fallback.`);

0 commit comments

Comments
 (0)