Skip to content

Commit 434e269

Browse files
authored
test(sections): fail the duplicate-live control on the message it names (#502)
1 parent 34795dc commit 434e269

3 files changed

Lines changed: 23 additions & 13 deletions

File tree

‎test/sections/duplicate-live.test.ts‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
*/
77

88
import { describe, expect, test } from "bun:test";
9-
import { ok } from "neverthrow";
9+
import { err, ok } from "neverthrow";
1010
import type { GitHubClient } from "../../src/github/api.js";
1111
import type { ListSection, SectionKey } from "../../src/schema.js";
12+
import { sectionFailure } from "../../src/sections/contract/errors.js";
1213
import type { SectionModule } from "../../src/sections/contract/module.js";
1314
import { planContext, snapshotContext } from "../../src/sections/contract/plan.js";
1415
import { labelsSection } from "../../src/sections/labels/index.js";
@@ -581,19 +582,19 @@ describe("duplicate live identities", () => {
581582
);
582583

583584
test("the negative control: a snapshot that skips the guard fails the proof, and so does a refusal with extra text", async () => {
584-
const [seed] = SEEDS.labels;
585+
// The snapshot path alone: with plan() out of the proof, no plan-side failure can satisfy either anchor.
586+
const seed: Seed = { ...SEEDS.labels[0], declared: undefined };
585587
const unguarded = {
586588
...labelsSection,
587589
snapshot: async () => ok({ value: undefined, notes: [] }),
588590
} as SectionModule;
589-
await expect(proveRefused(unguarded, seed)).rejects.toThrow();
591+
await expect(proveRefused(unguarded, seed)).rejects.toThrow(/expected a failure, got a value/);
592+
// The refusal arrives as a value, so only the message comparison can fail the proof.
590593
const padded = {
591594
...labelsSection,
592-
snapshot: async () => {
593-
throw new Error(`${seed.refusal} (and more)`);
594-
},
595+
snapshot: async () => err(sectionFailure("live-duplicate", `${seed.refusal} (and more)`)),
595596
} as SectionModule;
596-
await expect(proveRefused(padded, seed)).rejects.toThrow();
597+
await expect(proveRefused(padded, seed)).rejects.toThrow(/toEqual[\s\S]*\(and more\)/);
597598
});
598599
});
599600

‎test/sections/snapshot-denial.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ describe("snapshot under a token without grants", () => {
118118
: fake.tryRequest(method, path, payload, options),
119119
tryList: () => Promise.resolve(outage),
120120
};
121-
await expect(proveClassified(section, DENIED_403, erroring)).rejects.toThrow();
121+
await expect(proveClassified(section, DENIED_403, erroring)).rejects.toThrow(
122+
new RegExp(`${section.key} under warn[\\s\\S]*not "failed"`),
123+
);
122124
});
123125

124126
test("the negative control: a denied-posture section reading a fine-grained 404 as an empty list fails the proof", async () => {
@@ -138,6 +140,8 @@ describe("snapshot under a token without grants", () => {
138140
: answer;
139141
},
140142
};
141-
await expect(proveClassified(workflows, DENIED_404, swallowing)).rejects.toThrow();
143+
await expect(proveClassified(workflows, DENIED_404, swallowing)).rejects.toThrow(
144+
/workflows under warn[\s\S]*"skipped"/,
145+
);
142146
});
143147
});

‎test/workflows/checks-workflow.test.ts‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ describe("checks.yml release PR branch spelling", () => {
3232
expectReleasePrefixes(parseYaml(text) as Workflow);
3333
});
3434

35-
test.each<[string, (text: string) => Workflow]>([
35+
test.each<[string, (text: string) => Workflow, RegExp]>([
3636
[
3737
"a drifted spelling",
3838
(text) =>
3939
parseYaml(text.replaceAll(`'${RELEASE_PR_BRANCH_PREFIX}'`, "'release-pls--'")) as Workflow,
40+
/toEqual[\s\S]*"release-pls--"/,
4041
],
4142
[
4243
"a missing anchor-check step",
@@ -47,10 +48,14 @@ describe("checks.yml release PR branch spelling", () => {
4748
}
4849
return wf;
4950
},
51+
/must run anchor-check in exactly one step/,
5052
],
51-
])("%s fails the guard (negative control)", (_case, mutate) => {
52-
expect(() => expectReleasePrefixes(mutate(text))).toThrow();
53-
});
53+
])(
54+
"%s fails the guard on the assertion that names it (negative control)",
55+
(_case, mutate, failure) => {
56+
expect(() => expectReleasePrefixes(mutate(text))).toThrow(failure);
57+
},
58+
);
5459
});
5560

5661
describe("headRefPrefixes", () => {

0 commit comments

Comments
 (0)