Repository navigation
fix(doctor): report an unparseable roles manifest, and keep --json stdout parseable - #1898
Conversation
…dout parseable Two bugs, one trigger, and either alone still leaves the other broken (Tencent#1885). `doctor` stopped with the manifest's error. `buildRulesDeliveryChecks` and `buildInstructionDeliveryChecks` called `buildRolePullContext` unguarded, and the throw escaped `buildChecks` before the report was written, so `doctor --json` printed nothing at all. Both now return the `unresolvableCheck` the skills and agents builders already use, so the manifest's error lands in a failed check's `fix` and the command still exits 1. `pull` is unchanged: it must fail closed rather than deliver namespaces the manifest gates. Every other `--json` command printed the load warning on stdout ahead of its JSON. `list`, `digest`, `recall maintenance --update-quality` and `codebase --lint` each set stderr-only themselves, if at all, and a later `log.warn` in shared code adds another leaking command. The program's `preAction` hook now sets it once for any command whose `--json` is `true` — first, so the config load and the auto-migration under it are covered. `--json <payload>` takes a string, so `workflow claim/report/answer` are untouched. Co-Authored-By: Claude Code <[email protected]>
The PR description includes a representative real-CLI verify-world record, so the runtime-testing requirement is satisfied. No other confident findings in the scoped diff. |
SaulMoro
left a comment
There was a problem hiding this comment.
This was generated by AI during triage.
Approving at 43be4ea.
What I checked
- Red on main, green here. With main's
doctor-delivery.tsandindex.ts, the newdoctor-delivery.test.tscase throwsInvalid roles manifest: roles must be a non-empty array, and all four cases ofjson-stdout-contract-1885.test.tsfail against a build of main. With this head and a fresh build,doctor-delivery.test.tspasses (71), the E2E file passes (4), and typecheck passes. - Both causes are fixed where they start. The rules and instructions builders now return
unresolvableCheckas the skills and agents builders already do, sodoctor --jsonwrites a report andpullstill fails closed. ThepreActionhook sets stderr-only before the config load for any boolean--json, and the--json <payload>commands are left alone because their value is a string.
CI review: we disagree with its P1. The E2E file spreads process.env, but the E2E setup has already removed every tool-root variable from it by then. vitest.e2e.config.ts seeds CLAUDE_CONFIG_DIR, CODEX_HOME and the Cursor ones, and clear-agent-session-env.ts deletes each of toolRootVariables() before any test file runs. isolate-e2e-env.ts points HOME at a sandbox as well. So init --self --agent claude can't reach a real Claude config from this fixture, and the many other E2E files that spread process.env rely on the same setup.
[P3 nit]
- The new E2E file is named for the issue (
json-stdout-contract-1885). A name for the contract, such asjson-stdout-contract.test.ts, would let the next--jsoncase join it instead of starting another file.
Merge risk. Low. Doctor reports two more builders' errors as failed checks instead of stopping, and every boolean --json command now logs to stderr. Pull and the payload-taking --json commands are unchanged.
Summary
Fixes both bugs in #1885. They share a trigger — a
manifest/roles.yamlthat does not parse — and have separate causes, so fixing one alone still leaves the other broken.doctorstopped with the manifest's error, anddoctor --jsonprinted nothing.buildRulesDeliveryChecksandbuildInstructionDeliveryCheckscalledbuildRolePullContextunguarded; the throw escapedbuildChecksbefore the report was written, so the--jsoncaller got 0 bytes. Both now return theunresolvableCheckthe skills and agents builders already use, so the manifest's error lands in a failed check'sfixand doctor still exits 1.pullis unchanged — it must fail closed rather than deliver namespaces the manifest gates.--jsoncommand printed the load warning on stdout ahead of its JSON.list,digest,recall maintenance --update-qualityandcodebase --linteach set stderr-only themselves, if at all, and alog.warnadded to shared code later would leak through another command. The program'spreActionhook now sets it once for any command whose--jsonistrue— first in the hook, so the config load and the auto-migration under it are covered.--json <payload>takes a string, nottrue, soworkflow claim/report/answerare untouched.Type of Change
Test plan
Proof is a failing test first in both places (
AGENTS.md"Proof for a bug fix is a failing test first").Bug 1 — extended the existing
doctor-delivery.test.ts, which already owns the delivered-resources checks:main:npx vitest run src/__tests__/doctor-delivery.test.ts -t "roles manifest that does not parse"→Error: Invalid roles manifest: roles must be a non-empty arraythrown fromdoctor.ts:996.buildInstructionDeliveryChecks, exactly as the issue predicted. With both guards it passes, and the three… to deliver can be resolvedchecks each carry the manifest's error.Bug 2 — new
src/__tests__/e2e/json-stdout-contract-1885.test.ts, real CLI in a self-mode project withroles: 5:list --json,digest --json,codebase --lint --json: stdout starts with{and parses; the warning is on stderr.doctor --json: writes a report withok: falseand a failed check naming the manifest, exit 1.preActionline and rebuilding turns 3 of 4 red (doctorstays green because it sets stderr-only itself — which is the point: each command had to remember). Restoring it returns 4/4.Real CLI in a verify world (
20261115T172253-4b1848, build43be4ea7):npx tsc --noEmitpasses.npm run lintpasses (oxlint type-aware + documentation checks).doctor-delivery+doctorsuites: 164/164.The ledger on that world reports one LEAK, and it is not this change:
~/.claude/plugins/claude-hud/transcript-cache/…(a plugin of the shell I ran in) names the world, which is the host-file check doing its job, not teamai writing outside the world. Everything else under(e)is the known #1808 set.Hit every surface
buildChecks, so both scopes take the same path; the world ran project scope.gitin the world.httpbuilds no roles context through these two builders, and self mode uses the samegitloaders.Notes for reviewers
setStderrOnly(true)calls indoctor,roles list,session migrate,session listandsession show. They are harmless and the issue suggests removing them separately, which keeps this diff to the two causes.--jsonpath could bypass the hook.buildCheckscatching any builder's throw as one failed check named for that builder is the structural fix the issue points at; that is a larger change than this bug.Disclosure
Implemented with AI assistance (Claude Code); every line reviewed and tested by the author.