Skip to content

feat(miner): respect --json on CLI error paths - #5543

Merged
JSONbored merged 7 commits into
JSONbored:mainfrom
RealDiligent:feat/cli-json-errors-4836
Jul 13, 2026
Merged

feat(miner): respect --json on CLI error paths#5543
JSONbored merged 7 commits into
JSONbored:mainfrom
RealDiligent:feat/cli-json-errors-4836

Conversation

@RealDiligent

Copy link
Copy Markdown
Contributor

Summary

  • Add shared cli-error helper (reportCliFailure, argsWantJson, describeCliError) so miner CLI failure paths emit { ok: false, error } on stdout when --json is set.
  • Wire the helper across miner subcommands; wrap calibration ledger open and discover portfolio-queue open in try/catch for structured --json failures.
  • Unit tests cover helper behavior, per-command --json failure paths, and dedicated coverage for parse/runtime error branches.

Closes #4836

Test plan

  • npx vitest run test/unit/miner-cli-error.test.ts test/unit/miner-cli-json-error-coverage.test.ts
  • npx vitest run test/unit/miner-discover-cli.test.ts -t "portfolio queue open fails"
  • Prior CI green on branch (validate-code, validate-tests x6, validate-tests-merge, codecov/patch)

Notes

RealDiligent and others added 6 commits July 13, 2026 11:18
Add shared cli-error helper and wire parse/runtime failure paths across miner subcommands so --json callers always receive parseable { ok: false, error } on stdout.

Co-authored-by: Cursor <cursoragent@cursor.com>
…4836)

Extend unit tests for JSON error output across queue, plan, state, claim, ledger, governor, loop, manage-poll, and calibration. Wrap calibration ledger open in try/catch so --json callers get structured errors.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@RealDiligent
RealDiligent requested a review from JSONbored as a code owner July 13, 2026 03:56
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.87%. Comparing base (4b609eb) to head (0424746).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5543      +/-   ##
==========================================
+ Coverage   94.79%   94.87%   +0.07%     
==========================================
  Files         567      568       +1     
  Lines       45090    45035      -55     
  Branches    14675    14675              
==========================================
- Hits        42743    42726      -17     
+ Misses       1613     1575      -38     
  Partials      734      734              
Flag Coverage Δ
shard-1 43.80% <14.63%> (-0.38%) ⬇️
shard-2 35.44% <26.82%> (-0.02%) ⬇️
shard-3 32.15% <25.60%> (+0.16%) ⬆️
shard-4 31.37% <7.31%> (-0.49%) ⬇️
shard-5 33.36% <17.07%> (+0.45%) ⬆️
shard-6 44.39% <57.31%> (+0.90%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/gittensory-miner/lib/attempt-cli.js 96.73% <100.00%> (-0.09%) ⬇️
packages/gittensory-miner/lib/calibration-cli.js 100.00% <100.00%> (ø)
packages/gittensory-miner/lib/claim-ledger-cli.js 99.28% <100.00%> (+2.68%) ⬆️
packages/gittensory-miner/lib/cli-error.js 100.00% <100.00%> (ø)
packages/gittensory-miner/lib/cli.js 100.00% <100.00%> (ø)
packages/gittensory-miner/lib/deny-check.js 87.80% <100.00%> (-0.30%) ⬇️
packages/gittensory-miner/lib/discover-cli.js 100.00% <100.00%> (ø)
packages/gittensory-miner/lib/event-ledger-cli.js 98.27% <100.00%> (+1.58%) ⬆️
packages/gittensory-miner/lib/feasibility-cli.js 100.00% <100.00%> (ø)
...ckages/gittensory-miner/lib/governor-ledger-cli.js 98.48% <100.00%> (+2.83%) ⬆️
... and 10 more
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 13, 2026
@loopover-orb

loopover-orb Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Tip

🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩

✅ Gittensory review result - approve/merge recommended

Review updated: 2026-07-13 04:04:09 UTC

37 files · 1 AI reviewer · no blockers · readiness 100/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This adds a small shared cli-error.js helper (reportCliFailure/argsWantJson/describeCliError) and mechanically wires it into every miner CLI subcommand's error paths so --json failures emit a parseable {ok:false, error} object instead of plain stderr text. Along the way it also fixes two real gaps flagged in the description: calibration-cli.js now opens the prediction/event ledgers inside the try block (previously an open failure would throw uncaught before the try even started), and discover-cli.js now wraps the portfolio-queue open in try/catch. The diff is consistent — parse-error paths correctly use argsWantJson(args) (before a parsed.json field exists) while post-parse paths use parsed.json — and is backed by extensive new/updated tests exercising both branches per command.

Nits — 5 non-blocking
  • packages/gittensory-miner/lib/attempt-cli.js and loop-cli.js are already past the 400-line house threshold and this diff adds a few more lines to each — worth a follow-up split if either grows further, but not blocking here since the change itself is a thin wiring pass.
  • cli-error.js:12/14 flagged by the automated scan as 'debug leftovers' are actually the intended console.log/console.error output paths for this feature, not leftover debugging — no action needed.
  • reportCliFailure's exitCode default of 2 is implicit at every call site that omits the third arg; a short comment in cli-error.js noting '2 matches the pre-existing convention across CLI commands' would help a future reader avoid guessing why 2 was chosen over e.g. 1.
  • Consider adding a one-line JSDoc example to cli-error.js showing a typical call site (e.g. from portfolio-queue-cli.js) so new command authors can copy the pattern without hunting through call sites.
  • The calibration-cli.js and discover-cli.js try/catch fixes (ledger/queue open moved inside try) are good defensive improvements beyond the stated --json scope — worth calling out explicitly in the PR description as bug fixes rather than bundling them silently under the --json feature.
Signal Result Evidence
Code review ✅ No blockers 1 reviewer
Linked issue ✅ Linked #4836, #5541
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (2 linked issues).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 310 registered-repo PR(s), 142 merged, 25 issue(s).
Contributor context ✅ Confirmed Gittensor contributor RealDiligent; Gittensor profile; 310 PR(s), 25 issue(s).
Gate result ✅ Passing No configured blocker found.
Improvement ✅ Minor risk: clean · value: minor — Code changes are accompanied by test evidence.
Review context
  • Author: RealDiligent
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, JavaScript, Ruby, Svelte, TypeScript, Markdown, MDX
  • Official Gittensor activity: 310 PR(s), 25 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Keep the PR focused and include validation evidence before maintainer review.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
[BETA] Chat with Gittensory

Ask Gittensory a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @gittensory ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @gittensory chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @gittensory mention with a real question is routed to the closest matching read-only command automatically -- no exact syntax required.

Full command reference: https://gittensory.aethereal.dev/docs/gittensory-commands

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@loopover-orb loopover-orb Bot added the manual-review Gittensor contributor context label Jul 13, 2026
@JSONbored
JSONbored merged commit 7cffca2 into JSONbored:main Jul 13, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. manual-review Gittensor contributor context

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make CLI error paths respect --json

2 participants