-
-
Notifications
You must be signed in to change notification settings - Fork 1
fix(cli): validate mutually-exclusive flags instead of silently resolving by precedence #2039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gfargo-horizon-agent
merged 2 commits into
main
from
agent/coco-1744-coco-1889-cmd-16-fix-cli-mutually-exclus
Aug 2, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { Argv } from 'yargs' | ||
| import { builder } from './config' | ||
|
|
||
| // The builder's `.check()` callback enforces --dry-run/--apply mutual | ||
| // exclusion (#1889). Exercise it directly against a minimal yargs-chain | ||
| // stub instead of a full `.parseSync()`, since yargs' default failure | ||
| // handler calls `process.exit` on a thrown check error rather than | ||
| // propagating it to the test. | ||
| function extractCheckFn(): (argv: Record<string, unknown>) => boolean { | ||
| let captured: ((argv: Record<string, unknown>) => boolean) | undefined | ||
| const fakeYargs = { | ||
| options: () => fakeYargs, | ||
| check: (fn: (argv: Record<string, unknown>) => boolean) => { | ||
| captured = fn | ||
| return fakeYargs | ||
| }, | ||
| usage: () => fakeYargs, | ||
| } | ||
| builder(fakeYargs as unknown as Argv) | ||
| if (!captured) throw new Error('builder did not register a .check() callback') | ||
| return captured | ||
| } | ||
|
|
||
| describe('amend config validation (#1889)', () => { | ||
| const check = extractCheckFn() | ||
|
|
||
| it('rejects --dry-run combined with --apply', () => { | ||
| expect(() => check({ dryRun: true, apply: true })).toThrow( | ||
| '--dry-run and --apply cannot be combined — --dry-run previews, --apply amends.' | ||
| ) | ||
| }) | ||
|
|
||
| it('accepts --dry-run alone', () => { | ||
| expect(check({ dryRun: true })).toBe(true) | ||
| }) | ||
|
|
||
| it('accepts --apply alone', () => { | ||
| expect(check({ apply: true })).toBe(true) | ||
| }) | ||
|
|
||
| it('accepts neither flag', () => { | ||
| expect(check({})).toBe(true) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import { Argv } from 'yargs' | ||
| import { builder } from './config' | ||
|
|
||
| // The builder's `.check()` callback enforces the mutually-exclusive split | ||
| // flag rules (#1889). Exercise it directly against a minimal yargs-chain | ||
| // stub instead of a full `.parseSync()`, since yargs' default failure | ||
| // handler calls `process.exit` on a thrown check error rather than | ||
| // propagating it to the test. | ||
| function extractCheckFn(): (argv: Record<string, unknown>) => boolean { | ||
| let captured: ((argv: Record<string, unknown>) => boolean) | undefined | ||
| const fakeYargs = { | ||
| options: () => fakeYargs, | ||
| check: (fn: (argv: Record<string, unknown>) => boolean) => { | ||
| captured = fn | ||
| return fakeYargs | ||
| }, | ||
| usage: () => fakeYargs, | ||
| } | ||
| builder(fakeYargs as unknown as Argv) | ||
| if (!captured) throw new Error('builder did not register a .check() callback') | ||
| return captured | ||
| } | ||
|
|
||
| describe('commit config validation (#1889)', () => { | ||
| const check = extractCheckFn() | ||
|
|
||
| it('rejects --plan combined with --apply', () => { | ||
| expect(() => check({ plan: true, apply: true, _: [] })).toThrow( | ||
| '--plan and --apply cannot be combined — --plan previews, --apply commits.' | ||
| ) | ||
| }) | ||
|
|
||
| it('rejects --print-message combined with --split', () => { | ||
| expect(() => check({ printMessage: true, split: true, _: [] })).toThrow( | ||
| '--print-message cannot be combined with --split, --plan, --apply, or --strict-split.' | ||
| ) | ||
| }) | ||
|
|
||
| it('rejects --print-message combined with --plan', () => { | ||
| expect(() => check({ printMessage: true, plan: true, _: [] })).toThrow( | ||
| '--print-message cannot be combined with --split, --plan, --apply, or --strict-split.' | ||
| ) | ||
| }) | ||
|
|
||
| it('rejects --apply without --split', () => { | ||
| expect(() => check({ apply: true, _: [] })).toThrow( | ||
| '--apply requires --split (it applies a split plan).' | ||
| ) | ||
| }) | ||
|
|
||
| it('rejects --strict-split without --split or --plan', () => { | ||
| expect(() => check({ strictSplit: true, _: [] })).toThrow( | ||
| '--strict-split requires --split or --plan.' | ||
| ) | ||
| }) | ||
|
|
||
| it('accepts --split --apply', () => { | ||
| expect(check({ split: true, apply: true, _: [] })).toBe(true) | ||
| }) | ||
|
|
||
| it('accepts --plan alone', () => { | ||
| expect(check({ plan: true, _: [] })).toBe(true) | ||
| }) | ||
|
|
||
| it('accepts the `split` positional with --apply', () => { | ||
| expect(check({ apply: true, _: ['commit', 'split'] })).toBe(true) | ||
| }) | ||
|
|
||
| it('accepts the `split` positional with --strict-split', () => { | ||
| expect(check({ strictSplit: true, _: ['commit', 'split'] })).toBe(true) | ||
| }) | ||
|
|
||
| it('accepts --print-message alone', () => { | ||
| expect(check({ printMessage: true, _: [] })).toBe(true) | ||
| }) | ||
|
|
||
| it('accepts no split-related flags', () => { | ||
| expect(check({ _: [] })).toBe(true) | ||
| }) | ||
|
|
||
| // handler.ts:58 emits a structured `emitJson({ error })` payload when | ||
| // `--json` is combined with `--split`/`--plan`/`--apply`, for machine | ||
| // consumers. These combos must NOT throw here — check() runs before the | ||
| // handler, so throwing would replace that JSON contract with a plain-text | ||
| // yargs failure (#2039 review feedback). | ||
| it('defers to the handler for --json + --plan + --apply instead of throwing', () => { | ||
| expect(check({ json: true, plan: true, apply: true, _: [] })).toBe(true) | ||
| }) | ||
|
|
||
| it('defers to the handler for --json + --apply without --split', () => { | ||
| expect(check({ json: true, apply: true, _: [] })).toBe(true) | ||
| }) | ||
|
|
||
| it('defers to the handler for --json + --apply + --strict-split without --split', () => { | ||
| expect(check({ json: true, apply: true, strictSplit: true, _: [] })).toBe(true) | ||
| }) | ||
|
|
||
| it('defers to the handler for --json + --print-message + --split', () => { | ||
| expect(check({ json: true, printMessage: true, split: true, _: [] })).toBe(true) | ||
| }) | ||
|
|
||
| // `--strict-split` alone isn't covered by handler.ts's json guard (it only | ||
| // checks split/plan/apply), so it must still be validated here even under | ||
| // `--json` — otherwise `coco commit --json --strict-split` would silently | ||
| // fall into the draft-only path and drop `--strict-split` (the exact bug | ||
| // #1889 was opened to fix). | ||
| it('still rejects --json + --strict-split without --split or --plan', () => { | ||
| expect(() => check({ json: true, strictSplit: true, _: [] })).toThrow( | ||
| '--strict-split requires --split or --plan.' | ||
| ) | ||
| }) | ||
|
|
||
| it('accepts --json alone', () => { | ||
| expect(check({ json: true, _: [] })).toBe(true) | ||
| }) | ||
|
|
||
| it('accepts --json + --split (handler enforces the json/split conflict)', () => { | ||
| expect(check({ json: true, split: true, _: [] })).toBe(true) | ||
| }) | ||
| }) | ||
|
gfargo-horizon-agent[bot] marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.