Skip to content

test(preview): feed the stubbed responses on stdin, not through a path - #333

Open
L4XB wants to merge 1 commit into
every-app:mainfrom
L4XB:fix/329-preview-access-tests-on-windows
Open

L4XB wants to merge 1 commit into
every-app:mainfrom
L4XB:fix/329-preview-access-tests-on-windows

Conversation

@L4XB

@L4XB L4XB commented Sep 14, 2026 •

Copy link
Copy Markdown

Refs #329.

The defect

The test wrote its canned curl responses to a temp file and handed Bash the path. On Windows that path is C:\…\responses, and Git Bash reads the backslashes in

exec 3< "C:\…\responses"

as escapes — the redirect fails with No such file or directory and the shell exits before the first loop iteration. Every case then reports status 1 and zero attempt lines, exactly as the issue describes, while Linux CI stays green.

Demonstrable without Windows, since it is the quoting that breaks rather than the filesystem:

$ bash -c 'exec 3< "C:\tmp\resp"'
bash: C:\tmp\resp: No such file or directory

The fix

The responses arrive on stdin (spawnSync's input) and the script duplicates fd 0:

exec 3<&0

There is now no path to survive the trip into Bash, so the failure mode cannot occur on any platform — rather than being translated around with cygpath or a backslash rewrite, which would leave the same shape one quoting rule away from breaking again.

It keeps the property the temp file was there for, and which the comment names: one shared descriptor that advances even inside curl's command substitution. The temp directory, its try/finally cleanup, the PREVIEW_RESPONSES variable and three imports go with it — the diff removes slightly more than it adds.

Verified

Two mutations, each breaking the shared-fd property in a different way:

mutation result
exec 3< /dev/null instead of stdin 8 of 11 fail
no input handed to bash 8 of 11 fail

The three that survive both are the single-response cases, where the first read is all that matters — which is the right shape: a test that passes on one response says nothing about a descriptor advancing.

$ npx vitest run src/lib
Test Files  4 passed (4)
     Tests  34 passed (34)

$ npx prettier --check src/lib/pr-preview-access.test.ts
All matched files use Prettier code style!

$ npx tsc --noEmit
(clean)

I could not run this on Windows — no Windows machine here. The argument that it fixes #329 is structural (there is no longer a path for Git Bash to mis-quote) plus the quoting demonstration above, not an observed green run on Windows. Worth one confirmation from a Windows contributor before you trust it.

Related: #331 covers the other half of the Windows story (CRLF checkout), sent separately as #332.

The test wrote the canned curl responses to a temp file and handed Bash
its path. On Windows that path is `C:\...\responses`, and Git Bash reads
the backslashes in `exec 3< "C:\...\responses"` as escapes: the redirect
fails with "No such file or directory" and the shell exits before the
first iteration. Every case failed with status 1 and no `attempt` lines,
while Linux CI stayed green.

The responses now arrive on stdin and the script duplicates fd 0, so
there is no path to survive the trip into Bash. That keeps the property
the file was there for -- one shared descriptor that advances even inside
curl's command substitution -- and drops the temp directory, its cleanup,
and the extra environment variable with it.

Refs every-app#329
kenchikuliu pushed a commit to kenchikuliu/open-seo that referenced this pull request Sep 15, 2026
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.

pr-preview-access tests fail on Windows (Bash + Windows paths)

1 participant