Skip to content

fix(scripts): count subdirectory-only dirs as non-empty in PowerShell (parity with bash)#3137

Open
jawwad-ali wants to merge 1 commit into
github:mainfrom
jawwad-ali:fix/ps-dir-nonempty-subdir-parity
Open

fix(scripts): count subdirectory-only dirs as non-empty in PowerShell (parity with bash)#3137
jawwad-ali wants to merge 1 commit into
github:mainfrom
jawwad-ali:fix/ps-dir-nonempty-subdir-parity

Conversation

@jawwad-ali

Copy link
Copy Markdown
Contributor

Description

Test-DirHasFiles in scripts/powershell/common.ps1 (the documented PowerShell twin of bash check_dir) tested directory non-emptiness with:

Get-ChildItem -Path $Path | Where-Object { -not $_.PSIsContainer } | Select-Object -First 1

The Where-Object { -not $_.PSIsContainer } filter counts only top-level files and ignores subdirectories. But the three sibling code paths all count any entry:

  • bash check_dir (common.sh): [[ -d "$1" && -n $(ls -A "$1") ]]
  • PowerShell JSON contracts checks (check-prerequisites.ps1, setup-tasks.ps1): Get-ChildItem ... | Select-Object -First 1 (no filter)

So a contracts/ directory whose only contents are subdirectories (e.g. a versioned/grouped layout contracts/v1/openapi.yaml) was reported present by bash, by bash JSON, and by PowerShell JSON — but [FAIL]/absent by PowerShell text mode. Test-DirHasFiles is the lone outlier, and it's internally inconsistent with the JSON path in its own files.

Fix

Drop the PSIsContainer filter so Test-DirHasFiles counts any entry, matching the other three paths (one-line change).

Testing

  • Tested locally with uv run specify --help (exit 0)

  • Ran existing tests with uv sync && uv run pytest

  • uvx ruff check clean.

  • uv run pytest tests/test_setup_tasks.py10 passed, 16 skipped (no regressions; bash + pwsh-only tests skip on my host).

  • Verified directly with PowerShell: before, a subdir-only contracts/[FAIL]; after → [OK]; a genuinely empty dir and a missing dir still → [FAIL].

  • New parity tests in tests/test_setup_tasks.py (bash check_dir + PowerShell Test-DirHasFiles) assert a subdir-only contracts/ is reported non-empty in both shells. The PowerShell test fails on main ([FAIL] contracts/) and passes with this fix.

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (describe below)

Found and fixed with Claude Code (Claude Opus 4.8) under my direction. AI located the divergence across the four code paths; I reproduced the [FAIL] vs present discrepancy under PowerShell, confirmed the one-line fix restores parity (and that empty/missing dirs still report [FAIL]), and reviewed the diff before submitting. I'll disclose if any review responses are AI-assisted as well.

Test-DirHasFiles (the documented PowerShell twin of bash check_dir) tested
non-emptiness with `Get-ChildItem | Where-Object { -not $_.PSIsContainer }`,
counting only top-level FILES and ignoring subdirectories. Bash check_dir
(`-n $(ls -A ...)`) and the PowerShell JSON-path contracts checks
(check-prerequisites.ps1 / setup-tasks.ps1, no PSIsContainer filter) both
count ANY entry. So a contracts/ directory whose only contents are
subdirectories (e.g. contracts/v1/openapi.yaml) was reported present by
bash, by bash JSON, and by PowerShell JSON, but [FAIL]/absent by PowerShell
text mode — the lone outlier.

Drop the PSIsContainer filter so Test-DirHasFiles counts any entry, matching
the other three code paths.

Add bash + PowerShell parity tests asserting a subdir-only contracts/ dir is
reported non-empty in both shells.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jawwad-ali jawwad-ali requested a review from mnriem as a code owner June 23, 2026 21:41
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.

1 participant