Skip to content

Add the Pro-boundary ratchet check and the Pro/sync placement rule - #3376

Merged
mstomar125 merged 11 commits into
mainfrom
issue-3299-pro-boundary-ratchet
Sep 30, 2026
Merged

mstomar125 merged 11 commits into
mainfrom
issue-3299-pro-boundary-ratchet

Conversation

@mstomar125

@mstomar125 mstomar125 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3299

First step of the Pro/core boundary epic. Core will ship no Pro code (ADR-081, proposed in nodespace-docs); this freezes what is there and makes every later move lower a number. Measures only: no product code changes.

What it adds

  • scripts/check-pro-boundary.ts: a ratchet in the style of check-code-references.ts. It counts 11 line markers plus proNamedFiles across packages/, scripts/ and the root README.md. It fails only when a count rises above its baseline (new Pro code), listing the hits in files this branch changed first. A count below its baseline does not fail: it prints a non-failing notice with the exact tightened BASELINES block to paste. CLI: no arguments (table, failures, notices), --list <marker>, --changed.
  • scripts/check-pro-boundary.test.ts (225 tests, bun:test, DOM-free): the enforcement point via bun run test:scripts and the merge gate.
  • CLAUDE.md: new ## Pro / Sync Boundary (CRITICAL) section (placement rule, the three accepted baseline-raise classes, the absence-test convention) and a Finding Tasks paragraph routing Pro/sync issues to nodespace-sync.
  • .claude/skills/github-issue-management/SKILL.md: ### Step 0: Confirm the issue belongs in nodespace-core.

git diff --stat origin/main lists only those four files.

Deviation 1 (design, requested by the coordinator): a one-way ratchet, not an exact one

The issue specifies exact baselines that also fail when a count drops. Many Pro-removal PRs land in parallel, so that would force every other open PR to rebase just to edit BASELINES every time one merges, serializing the drain. This PR instead makes the check a one-way ratchet:

  • Above a baseline: fails. The message names the marker, lists hits (changed files first), points at the placement rule and the accepted raise classes, and says the exact edit if a class applies (set BASELINES.<marker> to N, with a justification in the PR description).
  • Below a baseline: does not fail. The CLI prints, and the real-repo test logs, a notice per lowered marker and one block to paste. The block only lowers ceilings and never raises one, so pasting it is always safe, and it changes only the value lines that moved.
  • A PR that must temporarily raise a count edits BASELINES in its own diff and justifies it in its description (the relocation class). The check fails until the diff does; review polices the justification.
  • Strictness still arrives at the end. A baseline of 0 fails on any hit, so when the final migration issue drives every baseline to 0 the check is strict with no mode switch.

Trade-off worth knowing: while Pro code remains, headroom between a count and its baseline can be spent by new Pro code until someone tightens. The notice makes tightening a copy-paste, and removal PRs are encouraged to do it in the same diff when cheap. CLAUDE.md is updated to say all of this. One exported function is new: baselineNotices(counts, baselines?); baselineFailures no longer reports decreases and no longer appends a paste block.

Baselines: set from main at dac00a70 (after the parallel PRs that had landed)

Taken from the checker's own counts on this branch rebased onto origin/main (1,400+ scanned files, no product code changed). At the issue's base commit af8ddb61 the counts reproduced the issue's table exactly (275, 360, 95, 87, 54, 122, 322, 15, 89, 507, 314, 16). The differences below are what merged since:

Marker Baseline At af8ddb6
proCommands 275 275
proSyncModule 370 360
proProtocol 95 95
proEvents 81 87
membershipService 54 54
editionBranching 113 122
cloudBindState 203 322
cloudSyncHooks 4 15
cloudWording 74 89
tenantWording 463 (one exemption hides 1 more line) 507
proWording 294 314
proNamedFiles 18 16

proSyncModule 360 to 370 and proNamedFiles 16 to 18 are the accepted relocation of the Pro variant machine into its own files (already on main); this PR adds no Pro code. If another PR merges first, the checker needs no rebase for a lower count, only a tightening if you want one.

Other deviations from the issue, and things worth a look

  1. ADR-081 is not merged yet. The issue lists its merge as a dependency and Step 1 says to confirm it. This was started early on explicit authorization. CLAUDE.md links the draft filename from nodespace-docs PR 89 (decisions/081-pro-is-a-separate-app-core-ships-no-pro-code.md). Before merging, re-check that name against nodespace-docs origin/main and fix the link if the ADR merges under another name. The Finding Tasks paragraph and the skill cite "ADR-081" by number only. CLAUDE.md, the checker header and the exemption allowlist also cite ADR-084 (raise class 1, the installer recognition points) by number only; that ADR is also still a draft, so confirm it exists before merging.
  2. baselineFailures takes an optional fourth argument, hits. The issue's signature baselineFailures(counts, baselines?, changedFiles?) has no way to list hits, yet the spec requires an above-baseline message to list hits in changed files first, then every hit. The real-repo test and the CLI pass countMarkers(...).hits; the three-argument call shape from the issue still works.
  3. exemptionProblems reports one message per problem (Steps 4), so an entry with two problems yields two messages. The Exemptions section says "per bad entry"; each fixture in the tests has exactly one problem, so both readings pass.
  4. The checker strips GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE, GIT_COMMON_DIR and GIT_PREFIX from the environment of its git calls (and the tests do the same for their fixtures). I confirmed empirically that a pre-push hook run from a linked worktree, which is this repo's workflow, receives GIT_DIR. Without stripping, the push-time run that the follow-up adds would scan the wrong repository, and a fixture git init or git add in the tests would hit the real one. Covered by a test that sets a bogus GIT_DIR and expects a correct scan.
  5. changedFilesSinceMain uses git diff -z --name-only --no-renames <merge-base> (one diff against the working tree instead of committed plus uncommitted) and NUL-separated output for both git calls. It returns the same set as changedFiles() in gate-scope.ts.
  6. proEvents follows the issue's pattern exactly, which also matches an unquoted pro:tier-detected (only the sync:* alternatives require quotes), although the summary and the prose say "quoted". Kept as specified because the baseline reproduced on it. Worth deciding in the migration issue that removes those events.
  7. Exemptions are also allowed on the installer recognition points (requested by the coordinator). The issue restricts exemptions to test files. EXEMPTIBLE_NON_TEST_FILES adds an explicit allowlist of whole paths that may carry an entry too: scripts/update-homebrew-cask.ts, scripts/pkg-resources/preinstall, scripts/pkg-resources/postinstall and scripts/build-pkg.sh. It is documented in the checker header and CLAUDE.md. The match is on the whole path (no basename, suffix or prefix match), so a same-named file elsewhere is not covered, every other non-test file is still reported, and an allowlisted entry still needs a reason, a marker and a live hit. Two things to know against the ADR drafts, which I read:
    • postinstall is not in ADR-084's list. ADR-084 section 5 lists exactly three installer files (build-pkg.sh, a new preinstall, update-homebrew-cask.ts) and says the allowlist is "exactly these three"; the old guard in postinstall moves to the pre-install stage. The coordinator's list included postinstall, so it stays, but the header, the constant's comment and CLAUDE.md now say plainly that it is allowlisted only until that guard is gone and that the ADR does not list it. Recommendation: drop it from the list when the installer work removes the guard (one line plus one test entry). preinstall does not exist on main yet (the same work adds it); an entry for it reports "missing from the scan" until it does.
    • The checker's exemption is looser than ADR-081 section 8's wording. Section 8 says an allowlisted file's other markers "are counted as they would be anywhere else". Here an entry hides only its own listed markers in its own file, and everything else in the file still counts, which matches that intent, but the exemption itself is a mechanism section 8 does not describe. ADR-081 section 8 (docs PR 89, still open) should be amended to match before both merge.
  8. Arguments are validated before the repository is scanned (review follow-up). A usage error no longer costs a full scan or needs a git checkout; a test proves it by running the copied checker in a directory that is not a repository. The test file also sets a 30s default timeout, because bun's 5s default is tight for tests that spawn git and bun on a loaded machine and a timeout would eject an unrelated PR from the merge queue.
  9. Extra tests beyond the issue's list: CLI runs against a fixture repository (the checker locates its repository from its own path, so a copy placed in a fixture scans the fixture), changedFilesSinceMain in a fixture repo including a moved origin/main, the GIT_DIR case above, tests for the notices and the never-raising block, a control showing the comment-line layout is what prevents the cherry-pick conflict, and isolated cases for every pattern alternative that had none. Real-repo assertions do not pin today's counts, so they keep passing as baselines fall.

Known behavior of the one-way design

  • Headroom is not visible to the gate. If a count sits below its baseline, new Pro lines can be added without editing BASELINES, and the passing test only logs the notice (the merge gate keeps full output in a log). CLAUDE.md now says headroom is not permission and asks the PR description to name the class either way. A useful follow-up, deliberately not built here: have the CLI and test warn when the branch's own diff adds hits for a marker that sits below its baseline, which would also allow an exact-by-diff check with no baseline rebasing.
  • Queue ordering. If a tightening PR and a PR that spent headroom are queued as [spent, tightening], the second one retests above its baseline and is ejected; a rebase plus re-paste fixes it. Not a bug, worth knowing when reading an ejection.
  • SCANNED_EXTENSIONS is the issue's allow-list, so a brand-new file type under packages/ or scripts/ (for example .tsx, .yml) is not scanned until it is added. Today's tracked but unscanned text files hold no markers.

Verification

  • bun run test:changed (scripts tier only): passed on the pushed head 0b4a0551. bun run quality:scripts:check: clean. bun run scripts/check-code-references.ts: unchanged at 71 / 0. bun run scripts/check-pro-boundary.ts: exit 0, all 12 counts equal their baselines on the rebased branch.

Mutation checks

The nine from the issue, run against the real repo or the source, each confirmed and reverted. Two results differ from the issue's text because of Deviation 1:

  1. Add await invoke('pro_example'); to a tracked non-Pro frontend file (packages/desktop-app/src/lib/utils/logger.ts): CLI exits 1 and the real-repo test fails. proCommands is 276 vs 275 and the new line appears under "In files this branch changed".
  2. Delete the README's nodespaced-pro paragraph (changed by Deviation 1): the check passes (exit 0, all 211 tests pass) and prints notices for editionBranching (121), tenantWording (506) and proWording (311) plus a block. Pasting the block gives git diff of exactly those three value lines, and the CLI then reports every count equal to its baseline.
  3. touch packages/desktop-app/src/lib/components/pro-upsell.svelte: proNamedFiles fails at 17 vs 16, with the file listed under the changed files.
  4. Remove the \b from nodespace_pro\b: the proProtocol does not match "use nodespace_proto::socket;" test fails.
  5. Delete the agent EXEMPTIONS entry: tenantWording is above its baseline (raw count is one higher) and fails.
  6. Change the agent entry's markers to ["proWording"]: exemptionProblems reports it stale ("proWording has no hit left in the file"), and tenantWording is above its baseline.
  7. Replace a fragment needle with its literal in the absence fixture (both the TS ["pro", "tier"].join("_") form and the Rust concat! form): the "needles built from fragments count 0" test fails.
  8. Make formatBaselines drop the comment lines: the "source holds formatBaselines(BASELINES) verbatim" test, the one-comment-per-value test and the adjacent-markers cherry-pick test all fail.
  9. Put a .md with markers under the gitignored packages/desktop-app/src-tauri/resources/skill/ (confirmed ignored via git check-ignore, rule src-tauri/.gitignore:15): no count changes and the CLI exits 0.

On top of those, a mutation harness applied 128 mutations (one per behavior: each git ls-files flag, sorting, exclusions, extension rules, git-failure handling, GIT_* stripping, unreadable-file handling, exemption scoping, each exemptionProblems check, each TEST_PATH alternative, each changedFilesSinceMain step, every baselineFailures and baselineNotices branch and message part, formatBaselines, each marker's individual pattern alternatives, isProNamedFile, the CLI's modes, argument validation, exit codes and output streams, and the recognition-point allowlist). Each was killed by the test written for that behavior. Earlier passes found survivors (a sort test that git's ordering happened to satisfy, a changedFilesSinceMain test whose origin/main equalled the merge-base, an untested CLI failing path, and an un-isolated pattern alternative); all were closed with new tests.

Not changed

scripts/check-code-references.ts and its baselines, anything under packages/agent (scanned only), and any Pro code. Running the check at push time is the follow-up.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Design deviation from issue #3299, requested by the coordinator: a one-way ratchet instead of an exact one.

The issue specifies exact baselines that also fail when a count drops. With many Pro-removal PRs landing in parallel, that forces every other open PR to rebase just to edit BASELINES each time one merges, which serializes the whole drain. This PR changes that part of the design:

  • A count above its baseline fails. That is new Pro code. The message lists the hits (changed files first) and, if an accepted raise class applies, the exact edit (set BASELINES.<marker> to N, justified in the PR description).
  • A count below its baseline does not fail. The CLI prints (and the real-repo test logs) a non-failing notice per lowered marker plus one block to paste. The block only ever lowers ceilings, never raises one, and changes only the value lines that moved.
  • A PR that must temporarily raise a count (for example the relocation of the Pro variant machine into its own files) edits BASELINES in its own diff and justifies it in its description. The check fails until the diff does.
  • Strictness still arrives at the end. A baseline of 0 fails on any hit, so when the final migration issue (Drive every Pro-boundary ratchet count to zero and make the check a hard ban #3371) drives every baseline to 0, the check is strict with no mode switch.

Trade-off: while Pro code remains, headroom between a count and its baseline can be spent by new Pro code until someone tightens. The notice makes tightening a copy-paste and removal PRs should tighten in the same diff when it is cheap.

Also done in this update: rebased onto origin/main (8e24544d, after #3373, #3374, #3375 and #3377 merged) and set BASELINES from main's actual counts. Compared with the issue's af8ddb61 numbers, proSyncModule 360 to 370 and proNamedFiles 16 to 18 are the already-merged Pro variant relocation; proEvents, editionBranching, cloudBindState, cloudWording, tenantWording and proWording are lower. CLAUDE.md, the checker's header comment, the tests and the PR description all describe the one-way behavior. 211 tests in the checker's test file pass, and a 110-mutation harness was rerun against the new design with every mutation killed by its expected test.

A fresh pragmatic review of the new head follows.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic code review: PR #3376 (initial review of head 5f90318)

Review Type: Initial Review (medium effort)

Summary: Net positive and close to mergeable. The checker is small, git-based, well commented, and the one-way ratchet is implemented consistently in the checker, its header comment, CLAUDE.md, the tests and the PR text. No blockers. I would do items 1 and 2 below before merging (both cheap); item 3 is the real hazard of the one-way design and is mostly a documentation fix plus a follow-up.

Requirements Check (issue #3299)

Criterion Result
Exports the specified API; quality:scripts:check PASS. Names and signatures match. eslint on both files and tsc --noEmit -p scripts/tsconfig.json are clean. Extras: optional 4th hits arg on baselineFailures (documented in the PR) and new baselineNotices.
Patterns and summaries verbatim PASS. I diffed all 11 line-marker patterns and summaries against the issue text programmatically: identical. proNamedFiles regex identical.
BASELINES layout, one comment line above each value; source equals formatBaselines(BASELINES) PASS (test plus reading).
CLI exits 0 and prints all 12 counts equal to baseline PASS. Ran on this head: 12 of 12 equal, exit 0.
Adding one Pro line fails, naming the marker, showing it under "In files this branch changed", pointing to the absence convention and raise classes PASS. Ran on a scratch copy with await invoke('pro_example'); appended to logger.ts: exit 1, proCommands 276 > 275, the new line under the changed-files header, guidance text present.
Removing a line: issue says fail plus paste block INTENTIONAL DEVIATION (one-way ratchet). Implemented correctly: exit 0, per-marker notice, one block that can only lower ceilings. Not a finding.
Gitignored files never counted; untracked non-ignored counted PASS (ls-files --cached --others --exclude-standard; discovery tests).
CLAUDE.md and the checker's two files not counted; packages/agent counted PASS.
EXEMPTIONS has exactly the one agent entry PASS.
exemptionProblems() empty on the real repo; fixture per problem kind PASS. It returns one message per problem (an entry with 3 problems gives 3), which the PR states.
Fragment needles count 0; literals count PASS.
check-code-references.ts stays 71 / 0 PASS (ran it).
CLAUDE.md section between Architecture & Docs and Node Type System; Finding Tasks paragraph after "Never assign"; skill Step 0 before Step 1 PASS, text matches the issue. Caveat: the ADR-081 link is the draft filename (nodespace-docs PR 89 is still open, so it does not resolve on docs main yet), and ADR-084, cited in raise class 1, is also an unmerged draft (docs PR 95). Both are merge preconditions; the PR only mentions 081.
Only 4 files changed PASS (git diff --stat origin/main...HEAD).

Verification I ran: bun test scripts/check-pro-boundary.test.ts gives 211 pass. I also re-ran four mutations on a scratch copy: count <= baseline to count < (fails 6+ tests), Math.min to Math.max in the paste block (fails 4), dropping the changed-files-first filter (fails 3), notices at <= (fails 6+). The suite is mutation-sensitive as claimed.

Code Review Findings

Critical / Blocker

None.

Improvements

1. [Improvement, fix before merge] The CLI usage test is the flakiest test in the file and the checker scans the whole repo before it validates its arguments. scripts/check-pro-boundary.ts:464-490, scripts/check-pro-boundary.test.ts:1073-1079 (also 973-993).
countMarkers(listScannedFiles()) runs at line 466, before the --list/--changed argument checks. So every usage error costs a full 1,400-file scan: bun run scripts/check-pro-boundary.ts --nope takes 0.65s wall, the same as a full run. The test an unknown marker or option prints usage and exits 2 spawns that four times in one test. Measured: 1.8s alone at load ~5, and 3.7s in one full-suite run at load ~7, against bun's 5s default per-test timeout, with no --timeout, bunfig.toml or setDefaultTimeout anywhere. CLAUDE.md says test:changed runs the scripts tier at low priority and the repo has seen load 160 on this machine, so a timeout here is a plausible flake that ejects an unrelated PR from the merge queue.
Fix (two parts, both small):

  • In the checker, validate arguments first and scan only inside the branches that need it. Prototype: computing valid from args and calling usage() before the scan makes --nope exit 2 near-instantly.
  • In the test, give the spawn-based tests an explicit timeout (test(name, fn, 30_000) or setDefaultTimeout at the top of the file). Optionally keep just one real-repo CLI smoke test; the three real-repo CLI tests (973-993) each add a full subprocess scan on top of the in-process real-repo test, and the fixture-based CLI tests already cover the modes.

2. [Improvement, fix before merge] The ratchet starts loose because the baselines are already stale against main. scripts/check-pro-boundary.ts:172-197, and the PR description's baseline table.
origin/main is one commit ahead of the base (#3378, "Replace DatabaseSettingsNode Pro fields..."), and it lowers counts. I applied gh pr diff 3378 to a scratch copy of this branch and ran the checker: cloudBindState 203 vs baseline 321 (118 lines of free headroom), tenantWording 463 vs 504, proWording 300 vs 310, cloudWording 82 vs 87. Nothing fails (correct for the design), but the PR lands with 118 lines of sync_enabled / bound_tenant / auth_status that new code can add silently (see item 3).
Fix: git rebase origin/main, run bun run scripts/check-pro-boundary.ts, paste the block (it changes only those four value lines), and refresh the PR's table. There is no queue conflict risk since the file is new.

3. [Improvement] Spending headroom is invisible to the gate and the CLI, and the CLAUDE.md wording overstates what the check catches. CLAUDE.md:116-117, scripts/check-pro-boundary.ts:481-486.
The design deliberately trades exactness for no rebase coupling, and the header comment and PR text say headroom can be spent. Concretely, I reproduced it on a scratch copy: delete 5 pro_ lines from pro_sync.rs (proCommands 270/275, notice printed), then add 5 new invoke("pro_new_a") lines in a new file. Result: proCommands 275 275, exit 0, no notice about them, and only the generic "some are below" line for other markers. Two consequences the PR does not cover:

  • The notices come from a passing test, and the merge gate writes full output to a log and only tails it on failure (CLAUDE.md, gate description). So from the gate nobody sees them; only a manual CLI run does.
  • CLAUDE.md line 117 says a raise is made by editing BASELINES "(the check fails until the diff does)" and that the PR names "each raised marker (old to new)". That is only true when the count is at its baseline. Inside headroom a class-3 relocation or a new Pro line passes with no BASELINES edit, so nothing prompts the author to name a class, and --changed lists every hit in each touched file, not just the added lines, so it cannot show what was added either.
  • Queue side effect: if a tightening PR (A) and a PR that spent headroom (H) are queued as [H, A], the bisect lands H alone, then A retests on top of it and fails "above baseline", so the good-citizen tightening PR is the one ejected. A rebase plus re-paste fixes it, but it is confusing. Not a bug, just worth knowing.
    Suggested fix now: adjust CLAUDE.md line 117 to say the edit is required only when a count would exceed its baseline, that inside headroom reviewers must still treat any added Pro line as needing a class, and use "count old to new" instead of baseline old to new. Suggested follow-up (non-blocking, separate issue): have the CLI and the real-repo test print a non-failing warning when the branch's diff (git diff -U0 <merge-base>, matched with the same MARKERS) adds hits for a marker that sits below its baseline. The same delta would let the ratchet eventually be exact-by-diff with no baseline rebasing at all.

Nits

  • Nit: scripts/check-pro-boundary.ts:58-72. SCANNED_EXTENSIONS is an allow-list, so a new file type under packages/ or scripts/ (.tsx, .mjs, .cjs, .yml, .yaml, .txt) fails open, unlike the template's deliberate "fails closed" comment about new packages. I checked today's tracked but unscanned text files (.golden, .txt, .svg, .jsonl): zero markers, so adding those extensions changes no baseline. The list is spec-defined, so this is your call.
  • Nit: the ADR preconditions: re-check the ADR-081 filename against nodespace-docs origin/main before merge, as the PR says, and add ADR-084 (docs PR 95) to that check since class 1 in CLAUDE.md depends on it (it is cited by number only, with no link, so a rename cannot break the link).
  • Nit: scripts/check-pro-boundary.test.ts:918-920, 927. Two notice tests assert the whole message string with toBe, so any rewording of the notice breaks them. Fine for an actionable-message contract; just be aware it is deliberate coupling.

Things I checked that are fine

  • One-way logic: count <= baseline continues; tightenedBaselines uses Math.min, so the paste block cannot raise a ceiling; a notice is on stdout with "Optional, not a failure", exit 0, and the success line reads "No count is above its baseline (some are below...)", so it cannot be mistaken for a failure. Failures go to stderr, exit 1; usage exits 2.
  • Baseline 0 is strict, and the PR text, header, CLAUDE.md and tests agree.
  • Discovery: git-based, NUL-separated, deduplicated and sorted; unreadable/deleted files skipped; non-git directory throws; GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE, GIT_COMMON_DIR, GIT_PREFIX stripped. changedFilesSinceMain is best effort and only orders the failure listing; a stale local origin/main only widens the "changed" set.
  • Exemption semantics: per file, per marker, raw-hit stale detection, proNamedFiles excluded by type and by check.
  • Tests: no dependence on init.defaultBranch, identity, gpg or a present origin/main (fixtures set -c user.name/email/commit.gpgsign=false and use update-ref). Real-repo assertions do not pin today's counts (they compare against the imported BASELINES), so they keep passing as baselines fall.
  • Code comments carry no issue numbers or docs paths (check-code-references.ts stays 71 / 0).
  • CLAUDE.md claim that bun run test:changed skips the scripts tier for frontend-only and .md-only diffs is accurate (classify and isInert in scripts/gate-scope.ts).
  • Cherry-pick tests (adjacent markers replay clean, same marker conflicts, no-comment control conflicts) exercise the real merge-queue mechanism with plain git.

Recommendation: APPROVE. No blockers. Please address items 1 and 2 in the address-review pass (both are small), and decide on item 3's CLAUDE.md wording now and the delta-warning as a follow-up. Merge stays gated on the ADR-081 / ADR-084 checks and the user's go-ahead.

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment; GitHub blocks self-approval). Full findings in the review comment above.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Address-review summary (round 1)

Responding to the review of head 5f903180 (APPROVE, no blockers). Pushed head: 7e832058, rebased on origin/main ca6a50e0.

Addressed

  1. [Improvement] The CLI scanned the whole repo before validating its arguments, and the usage test was a timeout flake risk. Arguments are now parsed and validated first (parseArguments), and the repository is scanned only in the branches that need it. A new test runs the copied checker in a directory that is not a git repository and asserts exit 2 with the usage text (and not "needs a git checkout"), which proves the ordering without relying on timing. Another test pins that a valid command outside a checkout fails with the clear error. The test file also sets setDefaultTimeout(30_000). Kept the three real-repo CLI smoke tests: with validation first they cost one scan each and the fixture tests carry the data assertions.
  2. [Improvement] Baselines were stale against main. Rebased and regenerated BASELINES from the checker's own counts on ca6a50e0: cloudBindState 321 to 203, cloudWording 87 to 82, tenantWording 504 to 463, proWording 310 to 300. The PR table is refreshed.
  3. [Improvement] CLAUDE.md overstated what the check catches inside headroom. The raise bullet now says the BASELINES edit is forced only when a count would rise above its baseline, that headroom below a baseline is not permission (the same three classes apply), and that the PR description names each marker whose count rises as "old to new count" and quotes only the added lines (--changed lists every hit in each changed file). The checker's header comment says the same.
  4. Nit: ADR-084. Added to the PR's pre-merge checklist next to ADR-081 (both are still drafts; ADR-084 is cited by number only, so a rename cannot break a link).

Also done in this round (coordinator request, not from the review): exemptions are now allowed on the four installer recognition points via an explicit whole-path allowlist (EXEMPTIBLE_NON_TEST_FILES: scripts/update-homebrew-cask.ts, scripts/pkg-resources/preinstall, scripts/pkg-resources/postinstall, scripts/build-pkg.sh), documented in the header and CLAUDE.md with the ADR references. Both paths are tested: each allowlisted file accepts a live entry, and a same-named file in another directory, a sibling script and any other non-test file are still rejected.

Skipped, with reasons

  • Suggested follow-up: warn when the branch's diff adds hits for a marker that sits below its baseline. A good idea, but it is new mechanism beyond both the issue and the agreed one-way design, so it is documented in the PR ("Known behavior of the one-way design") rather than built here. It would also be the path to an exact-by-diff check with no baseline rebasing.
  • Nit: SCANNED_EXTENSIONS fails open for new file types. The list is specified by the issue and today's unscanned tracked text files hold no markers; noted in the PR.
  • Nit: two notice tests assert the whole message with toBe. Deliberate: the notice text is an actionable-message contract.

Verification: 225 tests pass in the checker's test file, bun run test:changed (scripts tier) passes, quality:scripts:check is clean, the code-reference ratchet is unchanged at 71 / 0. The mutation harness now has 124 mutations, all killed by their expected test, including new ones for argument validation and every allowlist behavior.

Re-Review Decision

Decision: RE-REVIEW NEEDED (delta only).

Rationale: the CLI entry block was restructured (argument parsing), and the exemption check gained new allowlist logic with its own tests. Both are logic changes rather than wording. A delta re-review of the commits since 5f903180 follows.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Pragmatic code review: PR #3376 (re-review, delta 6b3b96d..7e83205)

Review Type: Re-Review (delta 6b3b96d..7e83205, medium effort)

Previous Review Summary: 6 recommendations (3 improvements, 3 nits). 3 improvements addressed and verified, nits handled as stated (ADR-084 added to the pre-merge list; the other two consciously skipped with reasons I accept). New issues found in the delta: 1 improvement, 2 nits. No blockers.

Previous feedback, verified by running it

Item Result
1. Validate arguments before the scan, and timeout FIXED. parseArguments runs before countMarkers(listScannedFiles()). I moved the scan back in front of the validation on a scratch copy: the new non-git test a usage error is reported before the repository is scanned... fails, so it proves the ordering rather than timing. setDefaultTimeout(30_000) works: a 5.5s test passes with the call and times out at 5000ms without it.
2. Baselines stale against main FIXED. bun run scripts/check-pro-boundary.ts on the head: all 12 counts equal their baselines, exit 0. Main has since moved one commit (#3382, a deletion; its added lines contain no Pro marker), which at worst adds non-failing headroom.
3. CLAUDE.md headroom wording FIXED and accurate. "Headroom is not permission", "old to new count", and "--changed lists every hit in each changed file, so quote only the added ones" all match the checker (--changed prints every hit in each changed file). The header comment says the same.
Nit: ADR-084 pre-merge check Done (PR body item 1).

Requirements check (delta)

Requirement Result
Usage exit code stays 2, all previously valid invocations still work PASS. Ran on the worktree: no args, --changed, --list <marker> (including proNamedFiles) exit 0. Exit 2 for: --list, --list bogus, --list proCommands extra, --changed extra, --nope, "", --list "", "" --changed, proCommands --list, --changed --list proCommands, --list --changed, --list constructor, --list __proto__, --list toString (the includes check on the marker array is immune to prototype keys), --help, -h, --changed=1. Same behavior as the old branch chain.
Allowlist documented in the header with the ADR reference PASS on form (check-pro-boundary.ts:32-37, 91-97, CLAUDE.md:123). See Improvement 1 for a content problem.
Exemptions outside the allowlist still fail on non-test files PASS. Fixture run of the real exemptionProblems: scripts/other/update-homebrew-cask.ts, scripts/pkg-resources/postinstall-old, packages/x/src/lib.rs, scripts/build-pkg.ts each give exactly one "only test files (TEST_PATH) and the installer recognition points (EXEMPTIBLE_NON_TEST_FILES) may be exempted" problem.
A test for both paths PASS. 12 tests under installer recognition points (accepts a live entry on each of the four, hides only its own marker, still needs a live hit / reason / marker, rejects same-named and sibling files).
Path tricks PASS. scripts/./build-pkg.sh, scripts//build-pkg.sh, ./scripts/build-pkg.sh and scripts/build-pkg.sh/ all fail twice (not in the scan, not on the allowlist), because the allowlist and exemptMarkers both compare the exact string and git ls-files never emits a non-normalized path. No basename or prefix bypass in the code.
Allowlisted file cannot exempt proNamedFiles PASS. "proNamedFiles" is not a marker that can be exempted for both an allowlisted and a pro-named file.
Allowlisted path that does not exist yet (scripts/pkg-resources/preinstall is not on main; it arrives with the in-flight #3349 work) Handled sensibly: an entry for it reports one "missing from the scan. Remove the entry" problem until the file exists, so the entry must land in the same PR as the file.
Whole run bun test scripts/check-pro-boundary.test.ts: 225 pass, 0 fail, 5.6s at load ~10. eslint on both files and tsc --noEmit -p scripts/tsconfig.json: clean. check-code-references.ts: 71 / 0.

Code review findings

Critical / Blocker

None.

Improvements

1. [Improvement] The allowlist names scripts/pkg-resources/postinstall, and the ADR wording the header, CLAUDE.md and PR body cite does not cover it. scripts/check-pro-boundary.ts:32-37, 91-102, CLAUDE.md:123, scripts/check-pro-boundary.test.ts:514-519, PR body item 7.
I read both drafts. ADR-084 section 5 (the table of checks) lists exactly three installer-side files: scripts/build-pkg.sh, scripts/pkg-resources/preinstall (new) and scripts/update-homebrew-cask.ts, and says "allowlist exactly these three files". ADR-081 section 8 says "Nothing else goes on the allowlist". The postinstall guard is the one ADR-081 problem 4 says cannot fire, and ADR-084 moves the check "from postinstall to the pre-install stage". The in-flight #3349 branch confirms it: its postinstall diff drops the guard (postinstall | 46 +---) and no Pro wording is left in it. So the statement "the installer recognition points that ADR-081 (section 2d) lets core keep and ADR-084 assigns to it" is false for postinstall, and there is nothing in that file that will ever need an exemption. Today its Pro-wording hits are the old guard that the migration should delete and count down, and an allowlist slot would let someone hide them instead.
A second, smaller mismatch to state honestly rather than fix: ADR-081 section 8 says an allowlisted file's other markers "are counted as they would be anywhere else" and that an allowlist entry "exempts nothing more". The coordinator-requested exemption path is a deliberate departure from that text (the ADR's allowlist is about the NodeSpaceProduct key, which this checker has no marker for). It is defensible, but the PR body item 7 should say it departs, and ADR-081 section 8 (docs PR 89 is still open) should be amended to match, otherwise the checker and the ADR disagree once both merge.
Fix: remove "scripts/pkg-resources/postinstall" from EXEMPTIBLE_NON_TEST_FILES, from RECOGNITION_POINTS in the test (the "exactly the four" test becomes "exactly the three"), and from CLAUDE.md:123 ("scripts/pkg-resources/preinstall" alone). Alternatively keep it, but then reword all three places to say it is a transitional exception that ADR-084 does not list. Add a sentence to PR item 7 on the ADR-081 section 8 wording.

Nits

  • Nit: scripts/check-pro-boundary.test.ts:559-567. The "any other non-test file is rejected" test cannot catch a prefix-match regression. I mutated !EXEMPTIBLE_NON_TEST_FILES.includes(entry.file) to !EXEMPTIBLE_NON_TEST_FILES.some((f) => entry.file.startsWith(f)) on a scratch copy: all 12 allowlist tests still pass. Basename, suffix, substring, directory-prefix, "reject everything" and "remove the allowlist" mutants are all killed, so the whole-path claim holds except for prefix. Fix: add a scanned near-miss to others, for example scripts/pkg-resources/postinstall-old (no extension, so it is scanned; I confirmed the real code gives it exactly one problem). The PR body says the allowlist mutation set is fully killed; this one survives.
  • Nit: scripts/check-pro-boundary.test.ts:1138-1144, scripts/check-pro-boundary.ts:494-501. The empty-string argument is correct today (exit 2, verified above) but not pinned: changing parseArguments to treat args[0] === "" as a plain check survives the CLI tests. Add [""] and ["--list", ""] to the args list in the usage test.
  • Nit (docs only): CLAUDE.md:123. scripts/pkg-resources/preinstall is named as if it exists, but it is not on main yet (it comes from the Move the .pkg guard to a static pre-install check and declare NodeSpaceProduct #3349 work; ADR-084 marks it "new"). The checker handles the absence correctly (see above); a few words such as "(added by the ADR-084 installer work)" would keep a reader from grepping for it.

Things I checked that are fine

  • parseArguments (check-pro-boundary.ts:490-498) is exactly the three forms usage() prints; option order, extra args and empty strings all fall to null. import.meta.main guard unchanged, so importing from tests still does not run it. bun run strips a bare -- before the script (bun behavior, not a checker change), so -- --changed reaches the checker as --changed.
  • The non-git fixture tests are sound: the pre-existing tests at lines 367-370 and 842-844 already use the same GIT_CEILING_DIRECTORIES: dirname(dir) pattern. I checked git's handling with a symlinked cwd and a symlinked ceiling (the macOS /var to /private/var shape): the ceiling still stops discovery. Nothing depends on where tmpdir() lives, and the two new tests need no network and no timing.
  • The rejection message names both the rule and the constant, so a contributor knows where to look. The existing toContain("only test files") assertion still matches.
  • EXEMPTIBLE_NON_TEST_FILES is a readonly string[] export next to EXCLUDED_FILES and TEST_PATH, consistent with the file's conventions. An entry still needs a live hit, a reason and a marker, and the stale-entry check is unchanged.
  • Worktree left untouched: git status is clean after all my runs.

Recommendation: APPROVE. Improvement 1 is a wrong claim about what the ADRs allow (plus one unneeded allowlist slot on a file that #3349 strips), cheap to fix in the same pass; the nits are optional. Merge stays gated on the ADR-081 / ADR-084 checks and the user's go-ahead.

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review (re-review): APPROVE (posted as a comment; GitHub blocks self-approval). Full findings in the review comment above.

@mstomar125
mstomar125 force-pushed the issue-3299-pro-boundary-ratchet branch from 7e83205 to 0b4a055 Compare September 30, 2026 10:44
@mstomar125

Copy link
Copy Markdown
Contributor Author

Address-review summary (round 2)

Responding to the re-review of the delta 6b3b96df..7e832058 (APPROVE, no blockers, one improvement and two nits). Pushed head: 0b4a0551, rebased on origin/main dac00a70.

Addressed

  1. [Improvement] The allowlist claim was wrong for postinstall. I read the ADR-081 and ADR-084 drafts: ADR-084 section 5 lists exactly three installer files (build-pkg.sh, a new preinstall, update-homebrew-cask.ts) and says the allowlist is "exactly these three"; the old postinstall guard moves to the pre-install stage. The claim as written ("the recognition points ADR-081 lets core keep and ADR-084 assigns to it") was not true of postinstall. The coordinator's explicit list includes postinstall, so I kept the four paths but made every statement accurate: the checker header, the constant's comment and CLAUDE.md now name the three files ADR-084 lists and say postinstall is allowlisted only until its old guard is gone, that the ADR does not list it, and that the slot should then be dropped. The PR body says the same, and also states the departure from ADR-081 section 8 that the reviewer pointed out (the exemption mechanism is not described there; ADR-081 section 8 should be amended before both merge). Decision for the coordinator: keep postinstall on the allowlist, or drop it now. Dropping it is one line in the constant plus one entry in the test's list; I recommend dropping it once the installer work removes that guard.
  2. Nit: a prefix-match allowlist regression was not caught. Added two extensionless near-miss names that begin with allowlisted paths (scripts/pkg-resources/preinstall-old, scripts/pkg-resources/postinstall-old) to the rejection test. Mutation-checked: a startsWith allowlist and an endsWith allowlist are now both killed.
  3. Nit: empty-string arguments were not pinned. Added [""] and ["--list", ""] to the usage test. Mutation-checked: treating an empty first argument as the default mode, and accepting an empty marker, are both killed.
  4. Nit (docs): preinstall is named as if it exists. CLAUDE.md now says it is added by the ADR-084 installer work. The checker already handles its absence (an entry for it reports "missing from the scan" until the file exists).

Baselines were regenerated again from main at dac00a70 (after the embedding seam removal): cloudSyncHooks 15 to 4, cloudWording 82 to 74, proWording 300 to 294. Nothing failed while main moved: the check printed notices and exited 0.

Verification: 225 tests pass in the checker's test file, bun run test:changed (scripts tier) passes, quality:scripts:check is clean, the code-reference ratchet is unchanged at 71 / 0, and the checker reports every count equal to its baseline. The mutation harness is at 128 mutations, all killed by their expected test.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED.

Rationale: this round changed comments, CLAUDE.md wording and PR text, and added test cases (two near-miss names, two arguments). No checker logic changed. The one logic-bearing area the re-review covered (parseArguments and the allowlist check) was verified by the reviewer against many inputs and is now additionally pinned by four new mutation kills. The baseline values are regenerated from the checker's own output.

mstomar125 and others added 11 commits September 30, 2026 12:50
…loses #3299)

scripts/check-pro-boundary.ts counts eleven Pro/sync line markers plus
Pro-named files across packages/, scripts/ and README.md, and fails when any
count moves off its checked-in baseline in either direction. Files come from
git ls-files so gitignored build output stays out of the counts. Each baseline
sits under its own comment line so the merge queue's cherry-pick replay only
conflicts PRs that change the same marker. Test-file exemptions are per file
and per marker, and fail once stale.

CLAUDE.md gains the "Pro / Sync Boundary" section (placement rule, the three
accepted baseline-raise classes, the absence-test convention) and a Finding
Tasks paragraph routing Pro/sync issues to nodespace-sync; the issue
management skill gets the same routing as Step 0.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
A count above its baseline fails; a count below it prints a notice with the
tightened BASELINES block instead of failing, so parallel Pro-removal changes
do not each have to rebase just to edit BASELINES. The printed block only
lowers ceilings and never raises one. A baseline of 0 fails on any hit, which
is the strict end state. CLAUDE.md's Pro / Sync Boundary section says the same.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…eanup

proEvents 87 -> 81, cloudWording 89 -> 88, proWording 314 -> 312; every
other marker is unchanged. The block was pasted from the checker's own notice.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…nd the free-user wording cleanups

proSyncModule 360 -> 370 and proNamedFiles 16 -> 18 come from the planned
relocation of the Pro variant machine into its own files; editionBranching
122 -> 113, cloudBindState 322 -> 321, cloudWording 88 -> 87, tenantWording
507 -> 504 and proWording 312 -> 310 come from the removals that landed
alongside it. Generated from the checker's own counts.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
… ejecting PRs

A usage error no longer pays for a full scan or needs a git checkout, proven
by running the copied checker in a directory that is not a repository. The test
file gets a 30s default timeout because many tests spawn git or bun and bun's
5s default is tight on the loaded machines the merge gate shares with builds.
The header comment now says headroom below a ceiling is not permission to add
Pro lines.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…headroom rule

EXEMPTIBLE_NON_TEST_FILES names the four scripts (cask updater, pkg pre and
postinstall, pkg builder) that must name other NodeSpace products to refuse
installing over them. Matching is on the whole path; any other non-test file is
still reported. CLAUDE.md now says headroom below a baseline is not permission
to add Pro lines, and lists the recognition points.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…and app-lib split

cloudBindState 321 -> 203, cloudWording 87 -> 82, tenantWording 504 -> 463 and
proWording 310 -> 300; every other marker is unchanged. Generated from the
checker's own counts.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
… more edge cases

ADR-084 lists three installer files; postinstall is allowlisted only until its
old guard moves to the pre-install stage, and the header, the constant's
comment and CLAUDE.md now say so. The rejection test gains extensionless
near-miss names that begin with allowlisted paths, and the usage test gains
empty-string arguments.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…oval

cloudSyncHooks 15 -> 4, cloudWording 82 -> 74, proWording 300 -> 294; every
other marker is unchanged. Generated from the checker's own counts.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-3299-pro-boundary-ratchet branch from 0b4a055 to 40efa54 Compare September 30, 2026 10:50
@mstomar125
mstomar125 merged commit d4a4ab2 into main Sep 30, 2026
@mstomar125
mstomar125 deleted the issue-3299-pro-boundary-ratchet branch September 30, 2026 10:50
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.

Add the Pro-boundary ratchet check and the CLAUDE.md Pro/sync placement rule

1 participant