Repository navigation
fix(cli): emit daemon progress as its own JSON event - #771
Conversation
`--json` promises NDJSON, but the execute callback passed the daemon's
progress frames straight to `log.println`. A run printed
{"plan": {…}}
{"summary": "mock preview", …}
Authorization passed for GetMemoryInfo
Executing GetMemoryInfo...
{"status": "succeeded", …}
so any consumer that parses every line — the `jq` pipeline documented
under Examples — dies on the first progress frame.
Print them as `{"event": "progress", "line": …}` instead. The human
renderer is untouched.
The regression test drives `execute_plan` with `opts.json = true` against a
daemon double streaming two progress frames, then parses every emitted
line. Reverting the JSON arm to `log.println(line)` fails it on the first
frame.
Signed-off-by: yuee3 <[email protected]>
vladimirrott
left a comment
There was a problem hiding this comment.
Reviewed at 05adac4d. Approving.
You picked the right layer for the test. It drives execute_plan itself against the daemon double, so it covers the one call site that streams progress (execute_step_checked in the main loop), and teaching the mock to send job_progress frames per action means the next --json test gets that for free. The second assertion matters too: a fix that dropped progress text would also produce valid NDJSON, and your any(line == "Executing GetMemoryInfo...") check rejects it.
What I checked:
-
The frame shape.
DaemonResponse::JobProgress { job_id, line }incrates/sysknife-daemon/src/dispatcher.rsmatches what the mock sends, andclient.rsstrips ANSI beforeon_linesees it, so the new object carries plain text. -
Callers.
execute_step_checkedinrunner.rsis the only place the CLI hands progress to a JSON-aware callback; the MCP server callsexecute_with_outcomeand collects the lines into its own result. The E2E stories run--dry-run --json, which never executes, so they see no new event. -
The fix reverted. I ran your test in a container at this head, then again with the JSON arm put back to
log.println(line);:receipt recorded for #771 at 05adac4d (observed: clean pass, mutated fail) observed_failure: test runner::tests::plan_preflight_tests::execute_plan_json_emits_progress_as_its_own_event ... FAILED -
The other direction, with the arm replaced by
let _ = line;so progress vanishes and every printed line stays valid JSON:running 1 test thread 'runner::tests::plan_preflight_tests::execute_plan_json_emits_progress_as_its_own_event' (7182) panicked at apps/sysknife-cli/src/runner.rs:4368:13: the daemon's progress text is not in the output: [] test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 349 filtered out; finished in 0.00s -
CI: all required checks pass,
dcoincluded. The evidence file goes 2106 → 2107 from the same base asmain, so no conflict.
Nothing blocks. I'll add the CHANGELOG entry myself when it lands.
Once this merges, tell me if you want another one. The CLI's output contract keeps turning up small gaps like this one, and you've now fixed two of them.
|
Thanks — yes, I'd like another one. Do you have a specific direction in mind, or are there known output-contract gaps left after #757 that I should pick up? Either way is fine; if there's no shortlist I can sweep the CLI's output surfaces ( |
|
@yuee3 Yes, I have one: #561. Your sweep is welcome as well. If you find a gap and can reproduce it, open an issue with the reproduction and I'll label it. Keep it separate from #561 so neither waits on the other. |
Closes #664.
Bug
--jsondocuments NDJSON — "one JSON object per event" — but the execute callback passed the daemon's progress frames straight tolog.println. With a daemon double streaming two frames,execute_planprinted:Anything that parses every line dies on the fourth — including the
sysknife --dry-run --json "…" | jq '.plan.steps[].action'example indocs/cli.md.Change
The JSON arm prints
{"event":"progress","line":"…"}instead. The human renderer is untouched; the only other edits are the--jsonrow and the schema block indocs/cli.md, plus the recorded test count. No refactor, no new dependency.Evidence
Test written first, run against the unfixed arm:
After the fix:
The test drives
execute_planwithopts.json = trueagainst a daemon double (the existing mock now takes aprogress_lineslist), then asserts every emitted line parses and that the daemon's text survives as aprogressevent — so silently swallowing progress fails it too.Checks
UPDATE_TEST_BASELINE=1 scripts/test_baseline.sh→2107 tests run: 2107 passed, 8 skipped, baseline 2106 → 2107 (WSL ext4, non-root)cargo nextest run -p sysknife-cli→ all greencargo fmt --checkclean,cargo clippy --workspace --all-targets --locked -- -D warningscleanDuplicate check
No open PR mentions #664;
git loghas no change to this arm since it was written. The issue's claim was released by @anyingiit and reopened to other contributors on 2026-11-05; I noted my take there before starting.