Repository navigation
fix(doctor): detect tracked .charter/telemetry and name the untrack fix - #316
Conversation
28b7eb8 to
d282fd0
Compare
…ix (closes #306) A gitignore entry never untracks a file already in the index, so repos bootstrapped before #298 keep staging every appended telemetry line on each "git add -A". doctor now reads the git index for <configPath>/telemetry and prints the one-time remedy. Withheld under --adf-only and outside a git repo, so the existing doctor --adf-only --ci gate is unchanged. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
stackbilt-admin
left a comment
There was a problem hiding this comment.
CHANGES_REQUESTED
The check itself is well built: the git-only determination is correct, the path derivation honours --config, the placement is right, and the red/green split is exactly as reported. One blocking item — an undisclosed CI behaviour change — plus four nits.
-
[BLOCKING] The CHANGELOG reassures about the wrong gate and omits that bare
doctor --cinewly fails.CHANGELOG.md:11ends "…and is withheld outside a git repository and under--adf-only, so the existingdoctor --adf-only --cigate is unchanged." That is true and it is the misleading part: it names the one CI invocation that is unaffected and says nothing about the one that is. Traced:checkTelemetryTrackingreturnsWARN(doctor.ts:110),hasWarnis anyWARN(doctor.ts:543), anddoctor.ts:559returnsEXIT_CODE.POLICY_VIOLATIONwhenoptions.ciMode && hasWarn. So any downstream repo running barecharter doctor --ciwith telemetry in its index goes red on upgrade. That is not a hypothetical invocation —docs/cli-reference.md:146documentsnpx charter doctor --ci --format json # CI mode: exit 1 on warningsas the CI incantation. Please (a) state in the CHANGELOG that baredoctor --cican newly fail for repos with tracked telemetry, with the one-line remedy inline, and (b) add telemetry tracking to the doctor description atdocs/cli-reference.md:141, which enumerates what doctor validates and does not list it. -
[NIT]
WARNvsINFO— the precedent cuts towardINFO, but this is defensible.doctor.ts:512-517carries an explicit ruling on exactly this shape: "Intentionally INFO, not WARN: doctor fails CI on any WARN, and emitting a warning here would break every repo that hasn't opted in yet (#186)." Anddocs/cli-reference.md:186-187turns it into a promise — the LOC-budget nudge "never fails an existing repo's CI on upgrade." Tracked telemetry is the same class: state charter's own pre-#298 bootstrap created, which the user never opted into, surfacing on upgrade. The strongest counter is #289checkGateEnforcement(CHANGELOG.md:26), added recently asWARNwith noINFOvariant — but it is gated onconfig.git.requireTrailers && FAIL/STRICT(doctor.ts:170-174), i.e. it only fires under a strict configuration the user chose. This one fires on state the tool produced. Note also thatpatternsandpolicy docsare not a precedent here: they pre-date any current green CI, so they break nothing on upgrade. I'd demote toINFO; if you keepWARN, item 1 becomes non-negotiable. -
[NIT] The remedy steps are in an order that loses the race.
doctor.ts:114-119printsgit rm -r --cached <dir>first and "Addtelemetry/to<configPath>/.gitignore" last. Afterrm --cachedthe file is untracked-but-present, and the habit that caused the bug in the first place — a reflexivegit add -A— re-stages it before the user reaches the last line. Put the ignore entry first. Separately,<configPath>/.gitignoredoes not exist in pre-#298 repos (it does not exist in this one), and in repos like charter the root.gitignore:19-20already covers telemetry, so the line is unconditional advice that is sometimes already satisfied. -
[NIT] The
catchasserts a fact it did not establish.doctor.ts:95-102turns arunGitthrow intostatus: 'PASS'withdetails: "<dir> is not tracked by git."The check only runs insideif (inGitRepo)(doctor.ts:198-202), so a throw here means something genuinely odd — an unreadable index, or a--configpath outside the work tree — and the output claims the opposite of "unknown". This is the same failure mode the PR deliberately avoids five lines later:doctor.ts:196-197withholds the check outside a repo rather than reporting it vacuously OK. Either omit on throw, or keepPASSand word it as "could not read the git index". -
[NIT] Unquoted path in the remedy.
doctor.ts:117interpolatestelemetryDirbare intogit rm -r --cached ${telemetryDir}. A--configdirectory containing a space yields a command that does not copy-paste.
Verified against source, not description:
- Path derivation —
doctor.ts:88usespath.join(configPath, 'telemetry')with backslash normalisation, matching thetelemetry.ts:89/149/180writers.options.configPathcomes from--config(index.ts:130) and flows into both detection and the printed remedy. Thecustom-cfg/telemetrytest covers it and does assert the remedy string, not just the status. - git as sole authority — confirmed by inspection:
checkTelemetryTrackingcontains nofscall of any kind; the only I/O isrunGit(['ls-files', '--', telemetryDir]). The case-insensitivity trap is sidestepped by construction. Stating it precisely: the tests use exact-case paths and never exercise case divergence, so this holds by construction, not by test — which is the right way round. - Placement — inside
if (!adfOnly)alongsideconfig file/patterns/policy docs/gate enforcement(doctor.ts:160-202). Consistent, and--adf-onlygenuinely omits it. - Not-a-git-repo — omitted, not vacuously passed, matching
checkGateEnforcement'sinGitRepoguard atdoctor.ts:172. Cannot read as "checked and fine". - Remedy correctness —
git rm -r --cachedremoves from the index and leaves the working tree file intact.readEvents(telemetry.ts:136-141) reads the file off disk viaexistsSync/readFileSyncand never consults git, socharter telemetry reportdoes keep working. Claim holds. - Pathspec precision —
git ls-files -- .charter/telemetrymatches at path-component boundaries, so a sibling like.charter/telemetryfoois not caught.
Red/green, executed: reverted packages/cli/src/commands/doctor.ts to main and ran the test file — 4 failed, 2 passed, exactly as reported. The 4 failures include passes when telemetry exists on disk but is untracked, which fails pre-fix because the check is absent entirely. The 2 pre-fix passes are the --adf-only and not-a-git-repo omission guards, which pass vacuously on main for the same reason. The PR states this rather than counting them as detectors; the honesty holds. Full doctor suite: 13/13 pass with the change in place.
Working tree: the scratch copy of main's doctor.ts was written to the session scratchpad outside the repo; the source file was restored with git checkout --. git status --porcelain after restore shows only ?? .ai/context.adf and ?? .ai/context.snapshot.json. Nothing modified, committed, or pushed.
…lure Review round 2. The condition is state Charter's own pre-#298 bootstrap created, not anything the user opted into, so reporting it on upgrade must not fail an existing repo's CI. doctor.ts already carries this exact ruling for the source LOC budget nudge (#186), and docs/cli-reference.md promises that soft nudge "never fails an existing repo's CI on upgrade" while documenting bare "charter doctor --ci" as the CI incantation. WARN -> INFO. Also: - Put the .gitignore step before "git rm -r --cached": the untrack leaves the file on disk, so a reflexive "git add -A" re-staged it first. Worded as a condition that may already be satisfied, since <configPath>/.gitignore does not exist in pre-#298 repos. - Omit the check when "git ls-files" throws instead of claiming a PASS it did not establish. - Quote the interpolated path so a --config dir containing a space is copy-pasteable. - Document the check in docs/cli-reference.md. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…acked Only repos where someone ran "git add -A" have it in the index, and the check reads the index, so staged-but-uncommitted counts too. "have it committed" was false on both counts. Same conditional-truth fix applied to the CHANGELOG entry. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Closes #306
Follow-up to #298 / #304.
Problem
#304 added
telemetry/to the<configPath>/.gitignorethatcharter bootstrap/initgenerate (viainitializeCharter,init.ts:426), so newly bootstrapped repos no longer stage.charter/telemetry/events.ndjson. It also documented a one-timegit rm -r --cached .charter/telemetry.An ignore entry never untracks a file already in the index. Any repo bootstrapped before #304 keeps staging every appended telemetry line on each
git add -A— silently, and precisely for the users who hit the original bug. The documented cleanup only helps people who go looking for it.This is the class of drift
doctorexists to catch: repo state that no longer matches what the current generator would produce.Change
New
telemetry trackingcheck inpackages/cli/src/commands/doctor.ts:<configPath>/telemetryviagit ls-files -- <dir>. The filesystem is never consulted for the tracked determination, so the result is identical on case-sensitive and case-insensitive checkouts.INFO, naming the tracked files and the remedy.PASS.git ls-filesthrowing (unreadable index, a--configdirectory outside the work tree) → check omitted rather than a PASS it did not establish.options.configPaththe same waycommands/telemetry.ts:52derives it, so--configis honoured rather than.charter/being assumed. The interpolated path is quoted, so a config directory containing a space still yields a copy-pasteable command.Advisory, not a CI failure
The diagnostic is
INFOand never fails CI. This wasWARNin the first revision; review round 2 correctly rejected that, and the repo settles the question three times over:doctor.tsalready carries the ruling for exactly this shape (feat(adf): add source LOC budget enforcement to catch godobject drift #186): "Intentionally INFO, not WARN: doctor fails CI on any WARN, and emitting a warning here would break every repo that hasn't opted in yet."docs/cli-reference.mdturns it into a promise: the soft nudge "never fails an existing repo's CI on upgrade."docs/cli-reference.mddocuments the CI incantation as barenpx charter doctor --ci --format json— exactly the invocation a WARN would newly break.Tracked telemetry is the same class as #186: state Charter's own pre-#298 bootstrap created, which the user never opted into, surfacing on upgrade. #289's
checkGateEnforcementis not a counter-precedent — it is gated onconfig.git.requireTrailersplusFAIL/STRICT, a strict configuration the user chose; this fires on state the tool produced.Verified empirically, which is the whole point: with
.charter/telemetry/events.ndjsonforce-added to this repo's index, baredoctor --ciexits 0, overall statusPASS, zeroWARNchecks — and the condition is still reported:(The index was restored afterwards;
git ls-files .charter/telemetryis empty again.)Remedy ordering
The ignore entry comes before
git rm -r --cached, deliberately. After the untrack the file is untracked-but-still-present, so the exact habit that caused the bug — a reflexivegit add -A— re-stages it before the user reaches the last line. It is worded as a condition that may already be satisfied ("or any .gitignore already covering it"), because<configPath>/.gitignoredoes not exist in pre-#298 repos — it does not exist in this one, where the root.gitignore:19-20does the work.Placement
Inside the existing
if (!adfOnly)block, next to the other<configPath>-hygiene checks (config file,patterns,policy docs), and withheld outside a git repository — matchinggate enforcement(#289), which is likewise not pushed rather than reported as a vacuous PASS..github/workflows/governance.yml:55and theverify:adfscript both pass--adf-onlyand are unaffected; withINFO, no doctor invocation in any repo goes red from this.Does charter itself trigger it?
No.
git ls-files .charter/telemetryandgit log --all -- .charter/telemetryare both empty — it was never committed here. One correction worth recording: it is ignored by the root.gitignore(lines 19-20), not by a.charter/.gitignore, which does not exist in this repo. #304 changed the generated bootstrap template, not charter's own config dir.Docs
docs/cli-reference.mdgains a Tracked telemetry subsection undercharter doctor, and the command's summary line now mentions the check. It states the advisory status explicitly, so the "never fails CI on upgrade" promise stays true as written.Tests
packages/cli/src/__tests__/doctor-telemetry-tracked.test.ts, mirroring the fixture style ofdoctor-gate-enforcement.test.ts. 9 cases.Measured, not reasoned about — the 9-case file run against each prior tree:
main(no check at all)d282fd0(round 1,WARN+ unordered remedy)HEAD(The first revision's 6-case file scored 4 failed / 2 passed against
main.)Red on
main— genuine detectors for the original bug:git rm -r --cached ".charter/telemetry"andcharter telemetry reportPASS(guards against over-warning)--configdirectory reports the custom path, not.charter--configpath containing a space stays quoted and copy-pasteableAlso red on
d282fd0— these catch the round-2 review findings specifically, so they are regression detectors for this PR's own history, not just formain:WARN(guards the feat(adf): add source LOC budget enforcement to catch godobject drift #186 "never fails CI on upgrade" promise)Green on
main, and honestly just guards — they encode placement decisions and detect nothing:--adf-onlyomits the checkFull suite: 931/931 passed (922 baseline + 9),
pnpm run typecheckclean.🤖 Generated with Claude Code