mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-18 22:24:17 +01:00
/ship's changed-number check no longer stops on tests that only use the same word as a changed property: lowering `limit: 120` to `30` used to report every test that said "limit" and held 120. Why: `docs/pregate.md` already said a test counts for a word like `limit` only when it also names the changed module, but the code enforced that only for one-character values. Tests that import the module are still reported. Nothing to do. Thanks to @dtoelke, who reported this and sent the first fix in #4478. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Co-authored-by: dtoelke <14206719+dtoelke@users.noreply.github.com>
This commit is contained in:
4 files changed
+26
-3
No files matched your search
@@ -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.
|
||||
+2
-1
@@ -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 fixture
|
||||
elsewhere 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 a
|
||||
minimum version goes up, marks that one line with a comment on it or on the
|
||||
comment line directly above it:
|
||||
|
||||
@@ -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[], chan
|
||||
for (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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user