Skip to content

fix(scripts): normalize agent-batch help exits#3068

Merged
senamakel merged 4 commits into
tinyhumansai:mainfrom
alexzhu0:codex/OH-2611-agent-batch-help
Jun 2, 2026
Merged

fix(scripts): normalize agent-batch help exits#3068
senamakel merged 4 commits into
tinyhumansai:mainfrom
alexzhu0:codex/OH-2611-agent-batch-help

Conversation

@alexzhu0
Copy link
Copy Markdown
Contributor

@alexzhu0 alexzhu0 commented May 31, 2026

Summary

  • Makes direct agent-batch subcommand help paths exit successfully.
  • Adds --help handling to validate.mjs, overlap.mjs, and status.mjs.
  • Extends the existing CLI test coverage for the direct script entrypoints.

Problem

  • The top-level pnpm agent-batch --help path exits 0.
  • Direct subcommands such as node scripts/agent-batch/validate.mjs --help printed usage as an error and exited 2.
  • These files are executable CLIs with usage headers, so direct help should be side-effect-free and successful.

Solution

  • Add small local usage() helpers to the direct subcommands.
  • Check parsed --help / -h flags before requiring a spec path.
  • Keep missing spec paths on exit 2, preserving the invalid-usage behavior.

Submission Checklist

If a section does not apply to this change, mark the item as N/A with a one-line reason. Do not delete items.

  • Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy
  • N/A: Diff coverage gate was not run because this is a root helper script change and local Rust tooling is unavailable.
  • N/A: Coverage matrix not affected; this does not add, remove, or rename a product feature.
  • N/A: No affected feature IDs; helper CLI only.
  • No new external network dependencies introduced (mock backend used per Testing Strategy)
  • N/A: Manual smoke checklist not affected; this does not touch release-cut surfaces.
  • N/A: Related to [Automated] Weekly code-review report — 2026-05-25 #2611 but does not close it by itself.

Impact

  • Runtime/platform impact: none.
  • Developer impact: direct agent-batch helper scripts now have consistent help semantics with the dispatcher.

Related


AI Authored PR Metadata (required for Codex/Linear PRs)

Linear Issue

  • Key: N/A
  • URL: N/A

Commit & Branch

  • Branch: codex/OH-2611-agent-batch-help
  • Commit SHA: bf3de3c

Validation Run

  • pnpm --filter openhuman-app format:check (blocked after app Prettier passed; see below)
  • pnpm typecheck
  • Focused tests: node --test scripts/agent-batch/__tests__/cli.test.mjs scripts/agent-batch/__tests__/lib.test.mjs
  • Rust fmt/check (if changed): N/A, no Rust files changed
  • Tauri fmt/check (if changed): N/A, no Tauri files changed
  • node scripts/agent-batch/validate.mjs --help
  • node scripts/agent-batch/overlap.mjs --help
  • node scripts/agent-batch/status.mjs --help
  • node scripts/agent-batch/validate.mjs -h
  • node scripts/agent-batch/overlap.mjs -h
  • node scripts/agent-batch/status.mjs -h
  • node scripts/codex-pr-preflight.mjs --lightweight
  • git diff --check

Validation Blocked

  • command: env COREPACK_HOME=/Users/alex/PR/.corepack PNPM_HOME=/Users/alex/PR/.pnpm-home pnpm --filter openhuman-app format:check
  • error: sh: cargo: command not found
  • impact: The app Prettier phase passed, but Rust formatting and the pre-push hook cannot complete in this local environment until Cargo is installed.

Behavior Changes

  • Intended behavior change: direct --help / -h paths for validate, overlap, and status now exit 0.
  • User-visible effect: contributor-facing helper CLIs are easier to inspect locally.

Parity Contract

  • Legacy behavior preserved: missing spec paths still exit 2, and existing validation/status behavior is unchanged.
  • Guard/fallback/dispatch parity checks: focused direct-subcommand help tests cover both --help and -h dispatch branches.

Duplicate / Superseded PR Handling

  • Duplicate PR(s): none found during triage
  • Canonical PR: this PR
  • Resolution (closed/superseded/updated): N/A

Summary by CodeRabbit

  • New Features

    • Added support for help flags (--help, -h, -?) to display usage for agent-batch CLI tools.
  • Improvements

    • Standardized usage output: help prints to stdout; missing required arguments print usage to stderr.
    • Clarified short-flag handling in CLI argument parsing.
  • Tests

    • Added tests that exercise help flags and verify correct exit codes, stdout/stderr behavior.

Constraint: The direct agent-batch subcommands are documented executable CLIs, not only dispatcher internals.

Rejected: Rely only on pnpm agent-batch --help | direct scripts still returned usage as an error.

Confidence: high

Scope-risk: narrow

Directive: Keep helper CLI help paths side-effect-free and exit 0.

Tested: node --test scripts/agent-batch/__tests__/cli.test.mjs scripts/agent-batch/__tests__/lib.test.mjs; node scripts/agent-batch/validate.mjs --help; node scripts/agent-batch/overlap.mjs --help; node scripts/agent-batch/status.mjs --help; node scripts/codex-pr-preflight.mjs --lightweight; pnpm typecheck; git diff --check

Not-tested: Full format:check/pre-push hook; cargo is not installed in this environment, though the app Prettier phase passed.
@alexzhu0 alexzhu0 requested a review from a team May 31, 2026 05:31
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 31, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7a17104e-4763-47c5-b03f-8aa50a007a4d

📥 Commits

Reviewing files that changed from the base of the PR and between bf3de3c and d9db615.

📒 Files selected for processing (4)
  • scripts/agent-batch/__tests__/cli.test.mjs
  • scripts/agent-batch/overlap.mjs
  • scripts/agent-batch/status.mjs
  • scripts/agent-batch/validate.mjs
🚧 Files skipped from review as they are similar to previous changes (4)
  • scripts/agent-batch/tests/cli.test.mjs
  • scripts/agent-batch/validate.mjs
  • scripts/agent-batch/overlap.mjs
  • scripts/agent-batch/status.mjs

📝 Walkthrough

Walkthrough

Three agent-batch CLI scripts (validate, overlap, status) add usage() helpers and support --help/-h/-?. --help prints usage to stdout and missing required positional args print usage to stderr. parseArgs now recognizes -h and -?. A new test verifies help output for all three commands.

Changes

CLI Help Output and Usage Consistency

Layer / File(s) Summary
Usage helpers and parseArgs short-help
scripts/agent-batch/validate.mjs, scripts/agent-batch/overlap.mjs, scripts/agent-batch/status.mjs, scripts/agent-batch/lib.mjs
Adds usage() helpers to the three CLIs; uses usage() for --help/-h output and for missing-positional-arg stderr; parseArgs now recognizes -h and -? as boolean flags.
CLI help invocation tests
scripts/agent-batch/__tests__/cli.test.mjs
Adds a node:test case that runs each CLI with --help, -h, and -?, asserting exit code 0, command-specific usage regex in stdout, and empty stderr.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • tinyhumansai/openhuman#1759: Earlier updates to the same scripts/agent-batch CLI tooling that this PR extends with unified help handling and tests.

Poem

🐰 I hopped through lines to tidy the signs,
Three scripts now answer when someone asks "find",
Short flags and help, outputs aligned,
A test hopped along — all green and refined.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(scripts): normalize agent-batch help exits' accurately and concisely summarizes the main change: normalizing help command behavior across agent-batch CLI scripts.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
scripts/agent-batch/__tests__/cli.test.mjs (1)

128-139: ⚡ Quick win

Add -h assertions alongside --help in this matrix test.

The scripts now advertise both forms, but this test only validates --help. Including -h here would catch the current short-flag regression immediately.

Suggested test update
 test("direct agent-batch subcommands print help with exit 0", () => {
   for (const [script, usage] of [
@@
   ]) {
-    const r = run(script, ["--help"]);
-    assert.strictEqual(r.status, 0, r.stderr);
-    assert.match(r.stdout, usage);
-    assert.strictEqual(r.stderr, "");
+    for (const flag of ["--help", "-h"]) {
+      const r = run(script, [flag]);
+      assert.strictEqual(r.status, 0, r.stderr);
+      assert.match(r.stdout, usage);
+      assert.strictEqual(r.stderr, "");
+    }
   }
 });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/agent-batch/__tests__/cli.test.mjs` around lines 128 - 139, The
matrix test "direct agent-batch subcommands print help with exit 0" only checks
the long form "--help"; update the test to also assert that the short "-h"
produces the same behavior by invoking run(script, ["-h"]) in addition to
run(script, ["--help"]) for each script (VALIDATE, OVERLAP, STATUS) and
asserting status === 0, stdout matches the same usage regex, and stderr is
empty; keep the existing assertions (assert.strictEqual and assert.match) for
both invocations to catch short-flag regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/agent-batch/validate.mjs`:
- Around line 15-18: The -h check in validate.mjs is ineffective because
parseArgs only populates long (--foo) flags, so flags.h is never set; update
validate.mjs to detect short help flags by checking process.argv (e.g., look for
'-h' or '-?' entries) before treating arguments as a spec path, or alternatively
enhance parseArgs in scripts/agent-batch/lib.mjs to map single-letter short
flags into the flags object (so flags.h is populated); reference the
validate.mjs help handling block and the parseArgs function to make the change
so `validate.mjs -h` triggers the usage() path.

---

Nitpick comments:
In `@scripts/agent-batch/__tests__/cli.test.mjs`:
- Around line 128-139: The matrix test "direct agent-batch subcommands print
help with exit 0" only checks the long form "--help"; update the test to also
assert that the short "-h" produces the same behavior by invoking run(script,
["-h"]) in addition to run(script, ["--help"]) for each script (VALIDATE,
OVERLAP, STATUS) and asserting status === 0, stdout matches the same usage
regex, and stderr is empty; keep the existing assertions (assert.strictEqual and
assert.match) for both invocations to catch short-flag regressions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0182a2b3-f7f7-46d5-b8fb-21020fc7a4ab

📥 Commits

Reviewing files that changed from the base of the PR and between 850d275 and 6b2e9d4.

📒 Files selected for processing (4)
  • scripts/agent-batch/__tests__/cli.test.mjs
  • scripts/agent-batch/overlap.mjs
  • scripts/agent-batch/status.mjs
  • scripts/agent-batch/validate.mjs

Comment thread scripts/agent-batch/validate.mjs Outdated
Constraint: CodeRabbit identified that -h was treated as a positional spec path because parseArgs only handled long flags.

Rejected: Patch validate.mjs only | overlap and status advertise the same short help contract and should share the parser fix.

Confidence: high

Scope-risk: narrow

Directive: Keep shared CLI parsing behavior covered by matrix tests for every advertised flag form.

Tested: node --test scripts/agent-batch/__tests__/cli.test.mjs scripts/agent-batch/__tests__/lib.test.mjs; node scripts/agent-batch/validate.mjs -h; node scripts/agent-batch/overlap.mjs -h; node scripts/agent-batch/status.mjs -h; git diff --check

Not-tested: Full repository format/check; cargo is unavailable locally.
coderabbitai[bot]
coderabbitai Bot previously approved these changes May 31, 2026
@alexzhu0
Copy link
Copy Markdown
Contributor Author

Thanks for the checks. I rechecked this PR on current state:

  • The only true blocker is Rust Core Coverage (cargo-llvm-cov) failing.
  • Other core checks in this PR pass; remaining failures are likely rerun / shared-suite related.
  • This is likely a shared upstream/core coverage issue across the fix(codex): compare strict preflight paths by realpath #3060-3073 batch, not a regression from this PR's diff.
  • PR Submission Checklist has historical failed/cancelled runs due to workflow re-triggers.

@alexzhu0
Copy link
Copy Markdown
Contributor Author

I reviewed all open PRs from alexzhu0 in this batch (#3060-3073).

Clarification on PR Submission Checklist

Most PR Submission Checklist failure/cancellation entries are historical/retry artifacts rather than new functional regressions:

  • Multiple checklist runs are expected for these PRs because re-runs happen while soft checks are triggered.
  • In the same PRs, CodeRabbit, lint/format, and most pipeline checks are passing.
  • The remaining hard blockers are concentrated in Rust Core Coverage (cargo-llvm-cov) and, for a subset, Frontend Coverage (Vitest) / Playwright web lane 1.

Suggested action

Please treat PR Submission Checklist failures for this batch as noise unless accompanied by a fresh diff-scope failure in core quality gates.

This should help avoid blocking PRs that are not functionally regressed by their own changes.

@sanil-23 sanil-23 assigned sanil-23 and unassigned sanil-23 May 31, 2026
Copy link
Copy Markdown
Contributor

@sanil-23 sanil-23 left a comment

Choose a reason for hiding this comment

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

@alexzhu0 the code is clean and the approach is correct — consolidating the usage string into a helper and keeping the error vs help stdout/stderr split is the right call.

One thing the tests don't catch: -? gets parsed into flags['?'] in the updated parseArgs, but all three CLIs only check flags.help || flags.h, so node validate.mjs -? still exits 2 with the usage string on stderr. Either remove -? from the parseArgs branch or add flags['?'] to each CLI's help check alongside flags.h.

The only failing CI check is Rust Core Coverage, which is unrelated to this JS-only PR — worth checking if that's a pre-existing flake on main. Once that's resolved (or confirmed unrelated) and the -? inconsistency is sorted, i'll come back and approve.

Comment thread scripts/agent-batch/lib.mjs
Copy link
Copy Markdown
Contributor

@graycyrus graycyrus left a comment

Choose a reason for hiding this comment

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

@alexzhu0 solid PR! The consolidation of usage() helpers and the parseArgs fix in commit bf3de3c for handling -h are both clean.

sanil-23's feedback about the -? inconsistency is spot-on though: parseArgs now sets flags['?'] = true, but the CLI scripts only check flags.help || flags.h, so node validate.mjs -? still exits with code 2 instead of 0. Either remove -? from the parseArgs branch (if it's not intended as a user-facing help form) or add || flags['?'] to each CLI's help check alongside flags.h.

Once that's sorted and CI (Rust Core Coverage) passes, this is ready to go.

The parser already recognizes -?, so each direct agent-batch CLI should treat it like the other advertised help aliases instead of falling through to missing-spec handling.

Constraint: Reviewer feedback identified node scripts/agent-batch/validate.mjs -? as an exit-2 path after parseArgs accepted the flag.

Rejected: Remove -? from parseArgs | Keeping the accepted alias preserves the current parser contract and matches the requested help behavior.

Confidence: high

Scope-risk: narrow

Directive: Keep direct CLI help aliases covered by the shared subcommand matrix test.

Tested: node --test scripts/agent-batch/__tests__/cli.test.mjs; git diff --check

Not-tested: Full repository format/check; unrelated Rust CI remains noisy upstream.
Copy link
Copy Markdown
Contributor

@graycyrus graycyrus left a comment

Choose a reason for hiding this comment

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

@alexzhu0 hey! the code looks good to me — the latest commit d9db615 honors -? properly across all three CLI scripts, test coverage now validates all three help flags (--help, -h, -?), and the prior feedback is resolved.

flag handling is clean:

  • parseArgs now sets flags for -h and -?
  • all three CLIs check flags.help || flags.h || flags["?"] before treating args as spec path
  • tests validate all three flags exit 0 with usage printed to stdout

there are some CI jobs still pending (PR Submission Checklist, Frontend Quality, Build Playwright, Rust Quality). once those clear, i'll come back and approve this. let me know if you hit any blockers.

Copy link
Copy Markdown
Contributor

@sanil-23 sanil-23 left a comment

Choose a reason for hiding this comment

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

@alexzhu0 code looks clean — my earlier flags['?'] concern is addressed in d9db615. Once CI is green I'll come back and approve. No blockers from me.

Copy link
Copy Markdown
Contributor

@sanil-23 sanil-23 left a comment

Choose a reason for hiding this comment

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

@alexzhu0 the latest commit (d9db615) correctly addresses my prior concern: all three CLIs now check flags["?"] alongside flags.h and flags.help, and the test matrix iterates over --help, -h, and -? for all three scripts. that finding is resolved.

two things are blocking approval:

  1. Rust Core Coverage has been failing since the first review — this is a pre-existing upstream issue and clearly unrelated to your JS-only change. not a blocker you need to fix.

  2. E2E Playwright lane 1/4 is a new failure that wasn't present in the prior scan. lanes 2, 3, and 4 all passed, so it may be a flaky test, but please check the run log (https://github.com/tinyhumansai/openhuman/actions/runs/26766265637/job/78894469541) and rerun if it's unrelated. once CI is 100% green i'll approve — the code itself is in good shape.

@senamakel senamakel merged commit 8319b95 into tinyhumansai:main Jun 2, 2026
17 of 19 checks passed
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.

4 participants