fix(tests): use fileURLToPath so source-safety specs pass on checkout paths with spaces#351
Open
hharsha98 wants to merge 1 commit into
Open
Conversation
…paths with spaces The source-safety assertions in command-injection.test.ts and skills-hardening.test.ts located files via `new URL(rel, import.meta.url).pathname`. URL.pathname percent-encodes the path, so a repo checked out to a directory containing a space (or other URL-special characters) yields e.g. `/foo%20bar/src/...`, and readFileSync throws ENOENT — 17 specs fail purely because of the checkout path. Use fileURLToPath(new URL(rel, import.meta.url)) instead: it decodes percent-encoding and is cross-platform, and it removes the fragile '/src/__tests__/../' string replacement. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
17 specs fail with
ENOENTwhen the repo is checked out to a path containing a space, because the source-safety assertions locate files vianew URL(rel, import.meta.url).pathname, andURL.pathnamepercent-encodes the path (space →%20).fs.readFileSyncthen can't find the file. CI never sees this because the runner path has no special characters. See #350.Fix
Resolve the paths with
fileURLToPath(new URL(rel, import.meta.url))instead. It decodes percent-encoding, is cross-platform, and lets the fragile.replace("/src/__tests__/../", "/src/")string surgery be removed.Test-only changes:
src/__tests__/command-injection.test.ts(5 sites)src/__tests__/skills-hardening.test.ts(12 sites)Verification
pnpm vitest run src/__tests__/command-injection.test.ts src/__tests__/skills-hardening.test.ts→ 132 passed (132) (was 17 failing)pnpm typecheck→ cleanThe assertions themselves are unchanged; no source or behavior changes.
Fixes #350