Skip to content

Commit 3d9e21a

Browse files
committed
test(scripts): pin assertion-ratchet SAFETY-comment scanner fix
The raw skipTrivia=false scanner in collectSafetyCommentLines never re-scanned the `}` ending a template substitution, so it lexed a phantom NoSubstitutionTemplateLiteral that swallowed every later comment in the file. #129769 already fixed this with per-line text matching, but shipped without a regression test, leaving the fix unpinned against reintroduction.
1 parent 0b60846 commit 3d9e21a

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎test/scripts/check-assertion-safety-ratchet.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,21 @@ describe("check-assertion-safety-ratchet", () => {
7979
expect(isGovernedAssertionSourcePath("scripts/example.ts")).toBe(false);
8080
});
8181

82+
it("recognizes SAFETY comments after template substitutions and division", () => {
83+
// A raw skipTrivia scanner never re-scans the `}` ending a template
84+
// substitution, so the closing backtick opened a phantom template that
85+
// swallowed every later comment; this pins the line-text approach.
86+
const source = [
87+
"const label = `count ${total} items`;",
88+
"const half = total / 2;",
89+
"// SAFETY: the schema parser established Shape.",
90+
"const safe = value as Shape;",
91+
"const unsafe = value as Shape;",
92+
].join("\n");
93+
94+
expect(countUnsafeAssertions(source, "src/example.ts")).toBe(1);
95+
});
96+
8297
it("blocks new debt, accepts SAFETY comments, and prunes reduced counts", () => {
8398
const root = tempDirs.make("openclaw-assertion-safety-");
8499
fs.mkdirSync(path.join(root, "config"), { recursive: true });

0 commit comments

Comments
 (0)