Skip to content

Changed-constant check stops flagging unrelated tests for one- and two-digit numbers - #4683

Merged
capy-ai[bot] merged 3 commits into
mainfrom
fix/constant-check-short-numbers
Nov 22, 2026
Merged

capy-ai[bot] merged 3 commits into
mainfrom
fix/constant-check-short-numbers

Conversation

@garrytan

@garrytan garrytan commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Changing a small constant such as MAX_ITEMS = 10 no longer flags every test that mentions its module and holds a 10 somewhere; only lines that use something taken from the module, or name the constant, count.
Why: one-line raises of two-digit constants were blocked by dozens of false matches (#4312); on gstack itself, changing RECEIPT_RUNS_KEPT (30) flagged 20 test files and now flags 4.
Nothing to do. Three-digit and longer values keep the old rule, and a test that imports the module and asserts the old value is still caught.

What changed

Raising a one- or two-digit constant used to trip the changed-constant check on every test file that mentioned the constant's module and happened to hold the same small number anywhere, even in a comment or an unrelated timestamp. Now a one- or two-digit old value found through the module counts only on a statement that names the constant or a binding the test takes from the module.

  • lib/pregate/checks/literals.ts: for a one- or two-digit integer old value (sign not counted, so -10 is included), a test file found only through the module counts a line only when its statement names the constant or a binding the file takes from the module: a JS/TS import of it (named, aliased, default, namespace or multi-line; type-only imports excluded) or a variable that a line naming the module declares (const out = run('scripts/arms.ts'), const { a } = require(...)). One-character values keep needing the constant's name.
  • The GST-820 test now runs its fixtures twice. At 120 -> 180 every original module match still counts, and at the incident's own 12 -> 18 importers and kept results still count and comment-only, type-only and unbound mentions do not.
  • A new test covers unrelated importers, comments, type-only imports, multi-line, namespace and require bindings, -10, and a three-digit control. Both tests fail on main and pass here.
  • docs/pregate.md states the new rule in the literals entry.

Known trade-off: some tests that really do use a changed one- or two-digit value are no longer reported early. That covers a test that runs the module without taking a binding from it, a typed or array-destructured declaration, and a test that imports the module but asserts through another module's function. Three-digit values still use the old rule, and the full test run still runs every such test.

Rebuilt on current main from #4354 by @ElNeMeR70 (co-author), using the narrower rule @Davmunrey proposed in review so GST-820's two-digit importer case stays covered. Closes #4312.

Security read

Pure text matching over test files the check already reads. Nothing new spawns a process, reads new files, touches the network, auth, CI, install scripts or dependencies. The outside diff was read as text only; no outside branch was fetched or run.

Blast radius

Only the changed-constant check's choice of which test files to warn about moves; it reads the same files as before and starts no process. A warning it no longer gives is still caught when the test itself runs, locally and in the full CI run (confirmed by reading consumersOf in lib/pregate/checks/literals.ts and by base-vs-head probes over gstack's own test tree).

Pre-Landing Review

One read-only full review of the final head by four readers: a batched specialist, a red team, a same-family adversarial reader and a second-model review. None found a defect that fails a test, breaks production or loses data. The second-model review marked two early-warning gaps as blocking (listed below); they were ruled notes because the stale assertion still fails when the test runs.

Review notes
  • lib/pregate/checks/literals.ts:149 (testing): a one- or two-digit value asserted on a statement that names the module inline, with no binding in the file, is no longer reported early.
  • Red-team note: details recorded privately.
  • lib/pregate/checks/literals.ts:203 (adversarial): typed, array-destructured, defaulted and multi-variable declarations are not followed as bindings, and the look-back stays at three lines.
  • lib/pregate/checks/literals.ts:149 (adversarial): a code line naming both the module and the old value no longer counts without a binding.
  • lib/pregate/checks/literals.ts:196 (adversarial): binding chains stop after four rounds, and statements are built from text with comment lines removed.
  • lib/pregate/checks/literals.ts:181 (second-model review, ruled note): a test that imports the module but asserts through another module's function (for example test/design-lint-fifth-cycle.test.ts:112 for WAIVER_MIN_REASON) is no longer reported early.
  • lib/pregate/checks/literals.ts:203 (second-model review, ruled note): const items: string[] = listItems() is not followed as a binding.
Exploratory QA

Smoke: the targeted tests (test/pregate-selection.test.ts, test/spawnsync-timeout-tripwire.test.ts) passed, 60 tests, and the readers ran base-vs-head consumersOf probes on synthetic files and on gstack's own test tree; the probe for WAIVER_MIN_REASON 24 -> 25 was rerun independently (base flags test/design-lint-fifth-cycle.test.ts:112, head does not). No plan checks apply (bug fix). No separate browser or QA charter ran.

Documentation

Status: current. No documentation edits were needed in this read-only audit.

Scope: branch fix/constant-check-short-numbers at ed2dd06 against base c2b4f0d2: 4 committed files (lib/pregate/checks/literals.ts, test/pregate-selection.test.ts, docs/pregate.md, changelog.d/pregate-literals-short-numbers.md). Nothing was staged, unstaged or untracked.

Documentation health:

  • docs/pregate.md: current. The literals section already describes the new rule for one- and two-digit integers: they count only in statements that name the constant or a binding taken from the module, type-only imports are excluded, and local helpers are not followed. This matches the code.
  • docs/troubleshooting.md (PREGATE_LITERALS): current. Its general wording is unaffected.
  • changelog.d/pregate-literals-short-numbers.md: reviewed only, since the release owner owns changelog content. Its file counts were not re-measured.

Coverage debt: none found. Diagram drift: none, because no diagrams cover this check.

Issues

Fixes #4312
Refs #4354
Refs p1/red-team#1
Refs p1/red-team#2
Refs p1/specialist-batched#1
Related: #4354 (@ElNeMeR70)

Tests
  • bun test test/pregate-selection.test.ts test/spawnsync-timeout-tripwire.test.ts: 60 pass, 0 fail
  • Full free suite in CI (free-tests.yml run 44997596538 at ed2dd06): green, 1743 files
Agent notes

Agent notes

Lane GSTA-805, issue GST-3487. Repro: ~/.capy/work/gsta-805/zz-gsta805-repro.test.ts on the lane machine. Final read-only review run ship-4683-r2 at ed2dd06.

Approvals

Approved: yes (record r-09272b9fd20d). The full approval record stays private.
Plan: exempt: bug fix
Plan check: exempt bug fix

REVIEW_LOOP: passes=1 blocking_found=2 deferred=0 noted=5 fixed=0 scope=frozen open=2 dispatches=4
Gate edits: none detected (1 listed, 1 read; patterns: RH-1,RH-3,RH-4,RH-12,RH-13,RH-14,RH-15,RH-16; unlisted idioms: none)
Ruled note: lib/pregate/checks/literals.ts:181:outside-voice at ed2dd06 ruled by GSTA-36 (relayed from GSTA-805:2026-11-22T07:14:20Z) at 2026-11-22T07:14:21.157Z: Captain ruled ship with note: pregate early-warning gap, CI and the import-graph tests stage still run the stale assertion (approval a-73a9248ba861)
Ruled note: lib/pregate/checks/literals.ts:203:outside-voice at ed2dd06 ruled by GSTA-36 (relayed from GSTA-805:2026-11-22T07:14:20Z) at 2026-11-22T07:14:21.369Z: Captain ruled ship with note: pregate early-warning gap, CI and the import-graph tests stage still run the stale assertion (approval a-6216073c9fc4)
Refs GST-3487

{
  "schema_version": 1,
  "pr": 4683,
  "head": "ed2dd06d317a75c4b95cb13785de889dea4adcfa",
  "version": "1.102.2.0",
  "base": "main",
  "gate": {
    "targeted": {
      "pass": 60,
      "fail": 0,
      "skip": 0
    },
    "free": {
      "pass": 1743,
      "fail": 0,
      "skip": 0
    }
  },
  "ci_carried": [
    {
      "lane": "free",
      "run": 44997596538,
      "attempt": 1,
      "tree": "7b4b12f2e7defdce76fa170b78a34e1ffb21778a"
    }
  ],
  "calls": 38,
  "session_kind": "unattended",
  "run": "ship-4683-r2",
  "head_tree": "7b4b12f2e7defdce76fa170b78a34e1ffb21778a",
  "product_patch_id": "c93edca6dff09042947f492c00a436b2a0c97f64",
  "gstack_version": "1.102.2.0",
  "review_depth": {
    "depth": "full",
    "class": "gate",
    "runtime_lines": 61,
    "rules": "630fd3101899e28e",
    "base": "ef72e4142fb0972089c41286fc160374d3f191c4",
    "registry": "ef72e4142fb0972089c41286fc160374d3f191c4",
    "gate_scan": {
      "tagged": 0,
      "head": "ed2dd06d317a75c4b95cb13785de889dea4adcfa"
    },
    "reasons": [
      "gate-class",
      "risk:security",
      "runtime=61"
    ],
    "risk": [
      "security"
    ],
    "mode": "panel"
  },
  "pregate": "requires-remote cleared @7b4b12f2e7de (8 checks, current for ed2dd06d317a)",
  "requires_remote": [
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/44997596538/attempts/1",
    "windows-smoke.yml/windows-smoke: https://github.com/garrytan/gstack/actions/runs/44994471214/attempts/1",
    "pregate.json/remote_gate: remote-gate tree=7b4b12f2e7de tests=38816 skipped=67 runs=44997596538/1 profiles=ci-reuse/free-tests heads=ed2dd06d317a verified=2026-11-22T08:02:28.024Z"
  ],
  "issues": {
    "fixes": [
      4312
    ],
    "refs": [
      4354
    ],
    "flakes": [],
    "related": [
      {
        "pr": 4354,
        "author": "ElNeMeR70",
        "closes": [
          4312
        ]
      }
    ]
  },
  "docs": {
    "status": "current",
    "scope": "docs/, README.md, CLAUDE.md, AGENTS.md, CONTRIBUTING.md (read-only audit at ed2dd06 vs c2b4f0d2)"
  },
  "review_loop": {
    "passes": 1,
    "blocking_found": 2,
    "deferred": 0,
    "noted": 5,
    "fixed": 0,
    "scope": "frozen",
    "rounds": 1,
    "dispatches": {
      "specialist": 3,
      "red-team": 1
    }
  },
  "ruled_notes": [
    {
      "finding": "lib/pregate/checks/literals.ts:181:outside-voice",
      "head": "ed2dd06d317a75c4b95cb13785de889dea4adcfa",
      "by": "GSTA-36",
      "reason": "Captain ruled ship with note: pregate early-warning gap, CI and the import-graph tests stage still run the stale assertion",
      "at": "2026-11-22T07:14:21.157Z",
      "approval": "a-73a9248ba861",
      "relayed": "GSTA-805:2026-11-22T07:14:20Z"
    },
    {
      "finding": "lib/pregate/checks/literals.ts:203:outside-voice",
      "head": "ed2dd06d317a75c4b95cb13785de889dea4adcfa",
      "by": "GSTA-36",
      "reason": "Captain ruled ship with note: pregate early-warning gap, CI and the import-graph tests stage still run the stale assertion",
      "at": "2026-11-22T07:14:21.369Z",
      "approval": "a-6216073c9fc4",
      "relayed": "GSTA-805:2026-11-22T07:14:20Z"
    }
  ],
  "gate_dispositions": []
}
{"head":"ce369af1325e2d26460572f3a50e254cc6d3f7b6","run":"ship-4683-r1","status":"started","review_loop":{"passes":2,"blocking_found":4,"deferred":0,"noted":7,"fixed":3,"scope":"frozen","rounds":2,"dispatches":{"specialist":6,"red-team":2}}}
{"head":"ed2dd06d317a75c4b95cb13785de889dea4adcfa","run":"ship-4683-r2","mark":"stop","tree":"7b4b12f2e7defdce76fa170b78a34e1ffb21778a"}

Open in Capy

When a one- or two-digit constant changes, a test file found only through
the constant's module now counts as a consumer only on a line that uses a
name it took from that module, or names the constant. A comment naming the
module beside an unrelated 10 no longer blocks a push, while a test that
imports the module and asserts the old value still does. Fixes #4312;
rebuilt from #4354, with the narrower rule from the review on it.

Co-authored-by: Mahmoud ElNeMR <[email protected]>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@trunk-io

trunk-io Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

garrytan and others added 2 commits November 22, 2026 06:09
…lease note's numbers

The narrower rule for one- and two-digit values now also follows a variable
declared or assigned from an imported name or from the module (const items =
listItems(), out = run(...) inside a hook, or a declaration whose module path
sits on a continuation line), so those tests still count as consumers. The
release note's before/after numbers now come from a recount over gstack's own
test tree with the check's real inputs.

Review-Finding: p1/red-team#1 reader=red-team
Review-Finding: p1/specialist-batched#1 reader=testing
Review-Finding: p1/red-team#2 reader=red-team
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
… guard passes

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pregate literals: raising a two-digit constant flags every unrelated occurrence of the old value

1 participant