fix(cli): expand ~ in path arguments outside scan - #219
Conversation
The scan subcommand already expands a leading ~ in its path arguments via targets.ts's expandHome helper, but every other subcommand that takes a user-supplied path resolved it with a bare resolve(), so ~ was treated as a literal directory name (e.g. codex-security bulk-scan repos.csv --output-dir ~/security-scans created a stray literal ./~/security-scans directory instead of writing under $HOME). Add a resolveCliPath(directory, value) wrapper around the existing expandHome helper (imported from runtime.js) and use it at every affected call site: - scans list <repository> and --scan-root - install-hook <repository> - bulk-scan <input-csv> and --output-dir - export <scan-dir>, --output, and --source-root - the output directory prompted for in the interactive bulk-scan wizard (bulk-scan-discovery.ts), via a direct expandHome import scan's own repository/--path resolution, scan/bulk-scan's --output-dir, --plugin-path, and --python were verified to already expand ~ deeper in targets.ts/runtime.ts and did not need changes. Fixes openai#57
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 25349d19b2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| inputPath = resolveCliPath(currentDirectory, args.input); | ||
| outputDir = resolveCliPath(currentDirectory, options.outputDir); |
There was a problem hiding this comment.
Expand bulk-scan knowledge-base paths too
When a shell passes ~ literally, bulk-scan ... --knowledge-base ~/docs still forwards the option unchanged as knowledgeBasePaths. prepareKnowledgeBase() subsequently calls resolve(requested) without home expansion, so it looks for <cwd>/~/docs and the repository scans fail even though the CSV and output-directory arguments now resolve correctly. Apply the same home expansion to each bulk-scan knowledge-base path before invoking runMultiscan.
Useful? React with 👍 / 👎.
|
Security review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
Fixes #57
Problem
codex-security scanexpands a leading~in its path arguments, but every other subcommand called bareresolve()on user-supplied paths, so~was treated as a literal directory segment:$ codex-security bulk-scan repos.csv --output-dir ~/security-scanswrites to
./~/security-scansand leaves a stray directory named~in the working directory. Beyond writing to the wrong place, resuming a bulk scan from a different working directory then fails to find the earlier ledger, because the literal~path does not resolve consistently.This affects any shell that does not pre-expand
~in a program's arguments, which is how the issue was hit on Windows.Change
A small wrapper next to the existing helper, as suggested in the issue:
applied at the call sites that genuinely lacked expansion:
scans list <repository>and--scan-root(two sites)install-hook <repository>bulk-scan <input-csv>and--output-direxport <scan-dir>,--output,--source-rootsrc/bulk-scan-discovery.tsSites deliberately left unchanged
I checked every reported site against the code rather than taking the list as given:
scan's repository and--patharguments already expand, throughexpandHomeinsrc/targets.ts.--output-dir(forscan),--plugin-pathand--pythonalready expand deeper insrc/runtime.ts, invalidateOutputDir,resolvePluginPathandusablePython. Expanding them again in the CLI would be redundant.validateandpatchtake a positional argument that is either literal finding text or a file path, and a stat miss safely falls back to treating it as text. It is not in the reported list and has no stray-directory failure mode, so I left it alone rather than widening scope.src/bulk-scan-discovery.tsimportsexpandHomefrom./runtime.jsdirectly;runtime.tsdoes not depend on the CLI or on the discovery module, so this adds no import cycle.Verification
Five regression tests across
cli.test.ts,cli-workbench.test.ts,cli-export.test.tsandbulk-scan-discovery.test.ts. Before the fix all five failed with the exact symptom — resolved paths like/current/repository/~/projectinstead of<home>/project, andinstall-hook/bulk-scanexiting 2 instead of 0. After the fix all five pass.The tests stub
node:oswithmock.modulerather than mutatingprocess.env.HOME, becauseos.homedir()does not re-read a live-mutatedHOMEin-process under Bun. That mirrors the existingmock.moduleusage intests-ts/api.test.ts.Full suite: 722 pass / 5 skip / 0 fail (717 baseline plus the 5 new tests, no regressions).
pnpm run typesandpnpm run formatare clean.