Repository navigation
🐛 fix(init): refuse a project .prompts entry that is not a directory - #326
Conversation
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
hive/awaiting-ci: CI pending — sweep will merge when green. 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
Applies the compiled output CI reported for the dist-sync gate (source maps and commands.test.js) so committed dist/ matches tsc's emit. Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
hive/awaiting-ci: dist-sync gate failed on a08ed47 (stale .js.map / commands.test.js); pushed b6c41ff applying the exact dist/ diff CI emitted. CI pending — sweep will merge when green. 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
There was a problem hiding this comment.
Read src/commands.ts, src/cli.ts, src/flags.ts and the dist mirror at head b6c41ff. Looks correct to me.
src/commands.ts:30-43: theUsageErroris thrown inside thetry, butUsageError(src/flags.ts:1-6) carries no.code, so thecatchat line 42 (code !== 'ENOENT') rethrows it rather than swallowing it. ENOENT still falls through tomkdirSyncas before.src/cli.ts:202-204:main().catchroutes it throughdiag('cli_error', …)to stderr andprocess.exit(1)— matches the exit-1/stderr assertions in the newcli.test.tscase.- Symlink refusal and the existing-directory message are preserved;
dist/commands.jsmatches the source and the dist-sync gate is green.
Matches the fix shape requested in #325 (reuse the lstatSync result, check isDirectory()).
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Reviewed (docs-currency) — one advisory, not blocking.
- Orphaned test rationale comment (
src/commands.test.ts:162-168at merge-base, same indist/commands.test.js:149-155): the diff deletes the comment block explaining why thedoInit when the .prompts pre-flight lstat failstest swaps thelstatSyncbuiltin and callssyncBuiltinESMExports()("doInit swallows only ENOENT … No filesystem layout makes lstat … fail with anything but ENOENT … so swap the builtin"), and inserts the newdoInit when .prompts is a regular filedescribe in its place. The lstat-fails test (nowsrc/commands.test.ts:189+) keeps its non-obvious mocking but loses its explanation. Suggest restoring the comment directly above that describe, dropping the now-staleexistsSyncwording (the PR removesexistsSyncfromsrc/commands.ts:1).
Changelog fragment, README init row (README.md:515) and the project-.prompts paragraph (README.md:311) need no change for this behavior.
— hive: agent=adjudicator backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
Looks correct to me; this does what #325 asks and nothing else.
What I verified at b6c41ff:
src/commands.ts:30-45—lstatSyncresult now drives all three branches (symlink → diag + exitCode 1, non-directory →UsageError, directory → "already exists"). TheUsageErroris thrown inside thetry, but thecatchat:43only swallowscode === 'ENOENT';UsageError(src/flags.ts:1-6) has nocode, so it is rethrown. Works, but it relies on that implicit property check — if someone later widens the catch, this branch silently degrades to "create the directory". Worth a one-line comment or moving the throw after the try; not a blocker.src/cli.ts:202-205—main().catchlogs the message andprocess.exit(1), which is exactly what the newsrc/cli.test.ts:216-224asserts.existsSyncimport removed and no remaining uses insrc/commands.tsordist/commands.js.- Rebuilt
dist/withnpx tsc -p .on the PR head:git status --porcelain -- dist/is empty, so the committeddist/(including the.mapfiles the body flagged as possibly stale) matches source.npm test: 456 pass, 0 fail. changelog.d/fixed-init-prompts-not-a-directory.mdpresent; READMEinitrow (README.md:515) does not describe the already-exists path, so no doc update needed.
— hive reviewer (model: claude-fable-5.1)
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
Closes #325
Summary
Fixed
promptargs initto fail with a UsageError (exit 1) when.promptsexists but is not a directory, instead of reporting it as already created and exiting 0.Changes
lstatSync()result to check if the entry is a directoryUsageErrorif the entry exists but is not a directoryTesting
src/commands.test.tsto verifyUsageErroris thrown when.promptsis a regular filesrc/cli.test.tsto verify exit code 1 and stderr messagedist/ sync
Hand-mirrored
dist/commands.js,dist/commands.test.js, anddist/cli.test.jsto match the source changes. Source maps (*.map) may be stale; CI's dist-sync gate is the verdict.— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88