Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA
TypeScript
Changed-number check stops flagging tests that only share a word like limit (#4478) (#4496)
Garry Tan0ab565711287
diff --git a/changelog.d/call-site-literals-need-the-module.md b/changelog.d/call-site-literals-need-the-module.mdnew file mode 100644index 000000000..35dc90cc8--- /dev/null+++ b/changelog.d/call-site-literals-need-the-module.md@@ -0,0 +1 @@+- **/ship's changed-number check no longer stops on tests that only share a word with the change (#4478).** When an ordinary property such as `limit: 120` changed to `30`, every test that used the word "limit" and held the number 120 was reported. A test now counts only when it also names the changed module, as `docs/pregate.md` already said; tests that import the module are still reported. Thanks to @dtoelke for the report and first fix.diff --git a/docs/pregate.md b/docs/pregate.mdindex 25d3c12a4..7028612b0 100644--- a/docs/pregate.md+++ b/docs/pregate.md@@ -268,7 +268,8 @@ Two stages with separate clocks, both printed:above. A `$2` in a shell stub, a comment, or `export default 2` in a fixtureelsewhere in the file is not a consumer. A call-site name such as `attempts`or `limit` is an ordinary word, so for it the file must also name the changed- module.+ module, whatever the old value's length: a test that only uses the word is not+ a consumer, and a test that imports the module still is.A test that keeps the old value on purpose, such as the refused input after aminimum version goes up, marks that one line with a comment on it or on thecomment line directly above it:diff --git a/lib/pregate/checks/literals.ts b/lib/pregate/checks/literals.tsindex 46767f339..f4dd3bf22 100644--- a/lib/pregate/checks/literals.ts+++ b/lib/pregate/checks/literals.ts@@ -98,7 +98,8 @@ function unquote(v: string): string { return /^['"`]/.test(v) ? v.slice(1, -1) :* continues it (the line before ends open, `(` `,` `.` `=`, or the line* starts with `.` `)` `]`), comments excluded (#3492: `$2`, "from revision 2",* `export default 2`). A call-site name (`attempts`, `limit`) is an ordinary- * word, so for it the file must also name the module (gstack-evals#97).+ * word, so for it the file must also name the module whatever the value's+ * length (gstack-evals#97, #4478).** A version-history row (`[45, "<digest>"]`, the old value first in a* bracketed row) is skipped when the same table, a run of consecutive@@ -134,7 +135,7 @@ export function consumersOf(repoRoot: string, testFiles: readonly string[], chanfor (const rel of testFiles) {let text: string;try { text = fs.readFileSync(path.join(repoRoot, rel), 'utf8'); } catch { continue; }- if (nameRequired ? !(nameRe.test(text) && (!callSite || moduleRe.test(text))) : !(nameRe.test(text) || moduleRe.test(text))) continue;+ if (!((nameRequired ? nameRe.test(text) : nameRe.test(text) || moduleRe.test(text)) && (!callSite || moduleRe.test(text)))) continue;const lines = text.split('\n');const named = (i: number) => {if (comment(lines[i]!)) return false;diff --git a/test/pregate-selection.test.ts b/test/pregate-selection.test.tsindex 6b0c86a1b..e973079ab 100644--- a/test/pregate-selection.test.ts+++ b/test/pregate-selection.test.ts@@ -310,6 +310,26 @@ describe('literals (pure)', () => {expect(consumersOf(root, Object.keys(files), { name: 'attempts', old: '1', new: '3', file: 'lanes/review-noloss/judge-run.ts' })).toEqual(['tests/judge-run.test.ts:3']);fs.rmSync(root, { recursive: true, force: true });});+ // Value: protects=a call-site literal of any length (`limit: 120`) counts only in a file that also names the changed module, while a+ // test that imports the module still fails on the old value; fails_when=a file that only uses the word and holds the old number is+ // reported again (#4478: a rate limit lowered from 120 to 30 flagged 30 unrelated test files), or the importer stops being reported;+ // why_new=the module gate covered one-character values only; seam=none; no_claim=a wrapper or barrel that never names the module+ test('consumersOf: a longer call-site literal also needs the changed module in the file; an importer of it still counts (#4478)', () => {+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-literals-call-long-'));+ const nl = String.fromCharCode(10);+ const files: Record<string, string> = {+ 'tests/pagination.test.ts': ['const page = await list({ limit: 50 });', 'expect(page.rows.length).toBeLessThanOrEqual(120);', ''].join(nl),+ 'tests/upload.test.ts': ['// the size limit is checked before the upload starts', 'expect(chunk(120)).toHaveLength(3);', ''].join(nl),+ 'tests/sibling.test.ts': ["import { quota } from '../src/rate-limits-v2';", 'expect(quota().limit).toBe(120);', ''].join(nl),+ 'tests/rate-limits.test.ts': ["import { SEND_RATE } from '../src/rate-limits';", 'expect(SEND_RATE.limit).toBe(120);', ''].join(nl),+ 'tests/send.test.ts': ["import { send } from '../src/rate-limits.ts';", 'const burst = 120;', 'expect(send(burst).ok).toBe(true);', ''].join(nl),+ 'tests/send-limit.test.ts': ['expect(SEND_LIMIT).toBe(120);', ''].join(nl),+ };+ for (const [rel, text] of Object.entries(files)) { fs.mkdirSync(path.dirname(path.join(root, rel)), { recursive: true }); fs.writeFileSync(path.join(root, rel), text); }+ expect(consumersOf(root, Object.keys(files), { name: 'limit', old: '120', new: '30', file: 'src/rate-limits.ts' })).toEqual(['tests/rate-limits.test.ts:2', 'tests/send.test.ts:2']);+ expect(consumersOf(root, Object.keys(files), { name: 'SEND_LIMIT', old: '120', new: '30', file: 'src/other.ts' })).toEqual(['tests/send-limit.test.ts:1']);+ fs.rmSync(root, { recursive: true, force: true });+ });// Value: protects=a test that keeps an old value on purpose (the refused input after a minimum-version bump) can waive that one line// with a `pregate-literal: NAME=value reason` comment, while every other old-value line, a marker for another constant or value,// a marker with no reason (a bare `*/`, `**/` or `* */` closer is not a reason) and marker text inside a string still count, and a line marked