Skip to content

🐛 fix(init): refuse a project .prompts entry that is not a directory - #326

Merged
hivecommons-hive[bot] merged 2 commits into
mainfrom
scanner/fix-325
Oct 24, 2026
Merged

hivecommons-hive[bot] merged 2 commits into
mainfrom
scanner/fix-325

Conversation

@hivecommons-hive

Copy link
Copy Markdown
Contributor

Closes #325

Summary

Fixed promptargs init to fail with a UsageError (exit 1) when .prompts exists but is not a directory, instead of reporting it as already created and exiting 0.

Changes

  • Reuse the existing lstatSync() result to check if the entry is a directory
  • Throw UsageError if the entry exists but is not a directory
  • Keep existing symlink refusal and directory-exists message logic

Testing

  • Added test in src/commands.test.ts to verify UsageError is thrown when .prompts is a regular file
  • Added test in src/cli.test.ts to verify exit code 1 and stderr message

dist/ sync

Hand-mirrored dist/commands.js, dist/commands.test.js, and dist/cli.test.js to 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

Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Oct 24, 2026
@kubestellar-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign clubanderson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

hive/awaiting-ci: CI pending — sweep will merge when green.


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

@kubestellar-prow kubestellar-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 24, 2026
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>
@hivecommons-hive hivecommons-hive Bot added author/hive This repository's own hive (the App or one of its agent lanes) authored this PR dco All commits are DCO signed-off role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Oct 24, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author

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: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Oct 24, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed — no findings from this perspective.

— hive: agent=ci-maintainer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed — no findings from this perspective.

— hive: agent=adjudicator backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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: the UsageError is thrown inside the try, but UsageError (src/flags.ts:1-6) carries no .code, so the catch at line 42 (code !== 'ENOENT') rethrows it rather than swallowing it. ENOENT still falls through to mkdirSync as before.
  • src/cli.ts:202-204: main().catch routes it through diag('cli_error', …) to stderr and process.exit(1) — matches the exit-1/stderr assertions in the new cli.test.ts case.
  • Symlink refusal and the existing-directory message are preserved; dist/commands.js matches 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

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reviewed (docs-currency) — one advisory, not blocking.

  • Orphaned test rationale comment (src/commands.test.ts:162-168 at merge-base, same in dist/commands.test.js:149-155): the diff deletes the comment block explaining why the doInit when the .prompts pre-flight lstat fails test swaps the lstatSync builtin and calls syncBuiltinESMExports() ("doInit swallows only ENOENT … No filesystem layout makes lstat … fail with anything but ENOENT … so swap the builtin"), and inserts the new doInit when .prompts is a regular file describe in its place. The lstat-fails test (now src/commands.test.ts:189+) keeps its non-obvious mocking but loses its explanation. Suggest restoring the comment directly above that describe, dropping the now-stale existsSync wording (the PR removes existsSync from src/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

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks correct to me; this does what #325 asks and nothing else.

What I verified at b6c41ff:

  • src/commands.ts:30-45 — lstatSync result now drives all three branches (symlink → diag + exitCode 1, non-directory → UsageError, directory → "already exists"). The UsageError is thrown inside the try, but the catch at :43 only swallows code === 'ENOENT'; UsageError (src/flags.ts:1-6) has no code, 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().catch logs the message and process.exit(1), which is exactly what the new src/cli.test.ts:216-224 asserts.
  • existsSync import removed and no remaining uses in src/commands.ts or dist/commands.js.
  • Rebuilt dist/ with npx tsc -p . on the PR head: git status --porcelain -- dist/ is empty, so the committed dist/ (including the .map files the body flagged as possibly stale) matches source. npm test: 456 pass, 0 fail.
  • changelog.d/fixed-init-prompts-not-a-directory.md present; README init row (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

@hivecommons-hive
hivecommons-hive Bot merged commit 7802e8b into main Oct 24, 2026
11 of 12 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the scanner/fix-325 branch October 24, 2026 06:21
@hivecommons-hive

Copy link
Copy Markdown
Contributor Author
Evidence bundle `#326b6c41ff` sha256:2ba9beca87c62b7f1b6f3f7978a7bdb292d86cd6dd715ceb9674196a454b2b24 — download from the dashboard or `hivectl review evidence #326`.

@github-actions

Copy link
Copy Markdown

Thank you for your contribution! Your PR has been merged.

We'd love to hear how your experience was: share feedback

@hivecommons-hive hivecommons-hive Bot removed role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/hive This repository's own hive (the App or one of its agent lanes) authored this PR copilot dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[scanner] init reports '.prompts/ already exists!' and exits 0 when .prompts is a regular file

0 participants