Skip to content

fix(scripts): treat a feature.json pointer to a missing directory as no feature - #5667

Open
pengzh1 wants to merge 3 commits into
github:mainfrom
pengzh1:fix/feature-json-stale-pointer
Open

pengzh1 wants to merge 3 commits into
github:mainfrom
pengzh1:fix/feature-json-stale-pointer

Conversation

@pengzh1

@pengzh1 pengzh1 commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

check-prerequisites --json --paths-only exits 0 and prints FEATURE_DIR, FEATURE_SPEC, IMPL_PLAN and TASKS under a directory that no longer exists when .specify/feature.json points at it; with no feature.json it exits 1 with ERROR: Feature directory not found. ....

Cause: get_feature_paths (bash, Python, PowerShell) accepted the stored feature_directory without checking that its target is a directory.

Fix: in the feature.json branch only, the normalized path must be a directory (-d, is_dir(), Test-Path -PathType Container), else the script prints the existing missing-pointer error and exits 1. The SPECIFY_FEATURE_DIRECTORY branch is untouched: naming a not-yet-existing directory is a legitimate use of it.

Behaviour change to be aware of

setup-plan no longer recreates a directory the pointer names. If check-prerequisites.sh --json runs with SPECIFY_FEATURE_DIRECTORY naming a not-yet-existing directory, it exits 1 but still persists that path. setup-plan.sh --json in a later session without the variable used to exit 0 and create plan.md with no spec.md; it now exits 1 with the missing-pointer error. With the variable exported, as documented, nothing changes.

Alternatives considered

Narrowing the check to check-prerequisites only, so setup-plan keeps recreating the directory from a stale pointer.

Fixes #5566. Reported by jpatton-aries, reproduced by KilianTheMagnificent.

Testing

Set up this checkout's .venv and editable install using the local development guide. Run commands from the checkout root.

  • Tested locally with .venv/bin/specify --help (Windows PowerShell: .\.venv\Scripts\specify.exe --help)
  • Ran relevant existing tests with .venv/bin/python -m pytest tests -q (Windows PowerShell: .\.venv\Scripts\python.exe -m pytest tests -q); use affected test paths for focused checks and LC_ALL=en_US.UTF-8 on macOS
  • Tested with a sample project (if applicable)

Existing tests adjusted. tests/test_setup_plan_no_overwrite.py and tests/test_init_dir.py pointed at a directory they never created and relied on setup-plan recreating it. Their subject is unchanged (SPECIFY_INIT_DIR with an existing feature.json; plan.md created, not overwritten; JSON parseable); they now create that directory.

New tests/test_feature_json_stale_pointer.py runs four ports: bash, pwsh, windows-powershell (Windows PowerShell 5.1) and Python. Locally 12 passed, 12 skipped (no PowerShell host on this machine); without the fix the six bash/Python stale-pointer cases fail with exit 0 and a printed FEATURE_DIR. Full suite at the second commit: 17682 passed, 674 skipped, 0 failed; the third commit touches only that test file.

Caveats: neither PowerShell port was executed locally; CI is their first run, including the windows-powershell port that carries the 5.1 evidence. The dangling-symlink case on PowerShell is unverified. Checklist items one and three are unchecked: no manual testing.

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

AI disclosure: Authored by the agent ZCode, model GLM-5.4, autonomous mode, on behalf of the account holder (pengzh1). The agent wrote the code and the tests; no human reviewed the change or tested it manually before this PR was opened.

…no feature

`check-prerequisites --json --paths-only` exited 0 and printed FEATURE_DIR,
FEATURE_SPEC, IMPL_PLAN and TASKS under a directory that no longer exists
whenever .specify/feature.json still pointed at it, while the same command
with no feature.json exited 1. get_feature_paths in the bash, python and
PowerShell helpers accepted the stored feature_directory without checking
that its target is a directory.

The feature.json branch now requires the normalized path to be a directory
and otherwise emits the existing missing-pointer error and exits 1, so a
stale pointer, a pointer to a regular file and a pointer to a dangling
symlink are all treated as no feature. The SPECIFY_FEATURE_DIRECTORY branch
is unchanged: naming a directory that does not exist yet is a legitimate use
of the explicit override.

Assisted-by: ZCode (model: GLM-5.4, autonomous)
…nter names

With the stale-pointer fix in get_feature_paths these tests fail for the
right reason: they wrote a .specify/feature.json pointer to a directory
that was never created and relied on setup-plan recreating it. Their
subject is unchanged (composing SPECIFY_INIT_DIR with an existing
feature.json; plan.md created and not overwritten; JSON output
parseable) and the fixture only used the pointer as setup, so the tests
now create that directory themselves.

Adjusted in tests/test_setup_plan_no_overwrite.py: the plan_repo fixture,
test_setup_plan_preserves_existing_plan,
test_setup_plan_skip_message_on_stderr_in_json_mode,
test_ps_setup_plan_preserves_existing_plan and
test_ps_setup_plan_does_not_match_another_features_plan. Adjusted in
tests/test_init_dir.py: test_composes_with_target_feature_json.

Assisted-by: ZCode (model: GLM-5.4, autonomous)
@pengzh1
pengzh1 requested a review from mnriem as a code owner December 2, 2026 09:43
Copilot AI adaptive review requested due to automatic review settings December 2, 2026 09:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The tests can reject valid Git Bash paths on Windows, and the host selector leaves required Windows PowerShell 5.1 validation uncovered.

2 open issues
What changed in this PR

Fixes #5566 by rejecting stored feature pointers whose directories no longer exist, consistently across Spec Kit’s three script implementations.

Changes:

  • Validate persisted feature directories while preserving explicit environment overrides.
  • Add stale-pointer regression tests and positive controls.
  • Update existing fixtures to create directories referenced by valid pointers.

Review assistance: GitHub Copilot, model unknown, autonomous, for the requester; analysis and suggested fixes. Tests were not run.

File Description
tests/​test_setup_plan_no_overwrite.py Create valid feature directories in fixtures.
tests/​test_init_dir.py Create the directory referenced by the test pointer.
tests/​test_feature_json_stale_pointer.py Add cross-port pointer validation tests.
scripts/​python/​common.py Reject stored paths that are not directories.
scripts/​powershell/​common.ps1 Validate stored directories using literal paths.
scripts/​bash/​common.sh Reject stored paths that are not directories.

Review effort: Balanced (adaptive)

The PowerShell port of the matrix picked pwsh whenever both hosts were
installed, so the stale-pointer cases never ran under Windows PowerShell
5.1, the host CONTRIBUTING.md asks for evidence from when PowerShell
behaviour changes. The matrix now has a separate windows-powershell port
next to pwsh, and each host runs the full set of cases.

Path assertions go through a small helper that turns the /c/... drive
spelling Git for Windows Bash can emit into C:/... before Path() compares
it with the fixture's C:\... spelling. Off Windows the helper is a no-op.

Assisted-by: ZCode (model: GLM-5.4, autonomous)
Copilot AI adaptive review requested due to automatic review settings December 2, 2026 09:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Maintainer review is needed for the shared resolver’s cross-session recovery compatibility change, with dangling-symlink handling also unverified on Windows PowerShell 5.1.

No open issues 🎉

2 resolved since last review

Review effort: Balanced (adaptive)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: feature.json pointing at a missing directory is still used as the active feature

2 participants