-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: treat task --help and unknown flags as CLI errors (#539) #547
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
Open
stantheman0128
wants to merge
1
commit into
openai:main
Choose a base branch
from
stantheman0128:fix/539-task-help-unknown-flags
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+130
−0
Open
Changes from all commits
Commits
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
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,86 @@ | ||
| import test from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import path from "node:path"; | ||
|
|
||
| import { parseArgs } from "../plugins/codex/scripts/lib/args.mjs"; | ||
| import { makeTempDir, run, initGitRepo } from "./helpers.mjs"; | ||
| import { buildEnv, installFakeCodex } from "./fake-codex-fixture.mjs"; | ||
| import fs from "node:fs"; | ||
|
|
||
| const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); | ||
| const SCRIPT = path.join(ROOT, "plugins", "codex", "scripts", "codex-companion.mjs"); | ||
|
|
||
| test("parseArgs rejects unknown long options when configured", () => { | ||
| const helped = parseArgs(["--help", "--cwd", "/tmp"], { | ||
| booleanOptions: ["help"], | ||
| valueOptions: ["cwd"], | ||
| rejectUnknownOptions: true | ||
| }); | ||
| assert.equal(helped.options.help, true); | ||
| assert.equal(helped.options.cwd, "/tmp"); | ||
| assert.deepEqual(helped.positionals, []); | ||
|
|
||
| assert.throws( | ||
| () => | ||
| parseArgs(["--not-a-flag"], { | ||
| booleanOptions: ["json"], | ||
| rejectUnknownOptions: true | ||
| }), | ||
| /Unknown option: --not-a-flag/ | ||
| ); | ||
| }); | ||
|
|
||
| test("parseArgs keeps unknown options as positionals by default", () => { | ||
| const { options, positionals } = parseArgs(["--not-a-flag", "hello"], { | ||
| booleanOptions: ["json"] | ||
| }); | ||
| assert.deepEqual(options, {}); | ||
| assert.deepEqual(positionals, ["--not-a-flag", "hello"]); | ||
| }); | ||
|
|
||
| test("task --help prints usage and does not dispatch a Codex thread", () => { | ||
| const repo = makeTempDir(); | ||
| const binDir = makeTempDir(); | ||
| installFakeCodex(binDir); | ||
| initGitRepo(repo); | ||
| fs.writeFileSync(path.join(repo, "README.md"), "hello\n"); | ||
|
|
||
| const result = run("node", [SCRIPT, "task", "--help", "--cwd", repo, "--json"], { | ||
| cwd: repo, | ||
| env: buildEnv(binDir) | ||
| }); | ||
|
|
||
| assert.equal(result.status, 0, result.stderr); | ||
| assert.match(result.stdout, /Usage:/); | ||
| assert.match(result.stdout, /codex-companion\.mjs task/); | ||
| assert.equal(result.stderr.trim(), ""); | ||
|
|
||
| const fakeStatePath = path.join(binDir, "fake-codex-state.json"); | ||
| if (fs.existsSync(fakeStatePath)) { | ||
| const state = JSON.parse(fs.readFileSync(fakeStatePath, "utf8")); | ||
| assert.equal((state.threads ?? []).length, 0); | ||
| } | ||
| }); | ||
|
|
||
| test("task unknown --flag errors without dispatching a Codex thread", () => { | ||
| const repo = makeTempDir(); | ||
| const binDir = makeTempDir(); | ||
| installFakeCodex(binDir); | ||
| initGitRepo(repo); | ||
| fs.writeFileSync(path.join(repo, "README.md"), "hello\n"); | ||
|
|
||
| const result = run("node", [SCRIPT, "task", "--not-a-real-flag", "--cwd", repo], { | ||
| cwd: repo, | ||
| env: buildEnv(binDir) | ||
| }); | ||
|
|
||
| assert.notEqual(result.status, 0); | ||
| assert.match(result.stderr, /Unknown option: --not-a-real-flag/); | ||
|
|
||
| const fakeStatePath = path.join(binDir, "fake-codex-state.json"); | ||
| if (fs.existsSync(fakeStatePath)) { | ||
| const state = JSON.parse(fs.readFileSync(fakeStatePath, "utf8")); | ||
| assert.equal((state.threads ?? []).length, 0); | ||
| } | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
taskis invoked in the documented quoted raw-argument form,normalizeArgvre-splits the natural-language prompt before it reaches this parser, so any prompt that mentions a short CLI flag or negative-style token now fails here before Codex is dispatched. For example,task "investigate grep -R usage"exits withUnknown option: -Rinstead of sending that prompt, which is a common shape for debugging command-line behavior; the parser should either stop option parsing once prompt text starts or avoid rejecting single-dash tokens for prompt-taking commands.Useful? React with 👍 / 👎.