Skip to content

fix: cap dumped filename length to avoid ENAMETOOLONG - #19

Open
johnhldiver-beep wants to merge 1 commit into
made-in-common:mainfrom
johnhldiver-beep:fix/7744-debug-dump-enametoolong
Open

johnhldiver-beep wants to merge 1 commit into
made-in-common:mainfrom
johnhldiver-beep:fix/7744-debug-dump-enametoolong

Conversation

@johnhldiver-beep

Copy link
Copy Markdown

Debugger.encodeId in src/debug.ts built dump filenames from the full sanitized module id with no length cap, so a very long id crashed with ENAMETOOLONG when writing under .vite-node/dump (reported as vitest-dev/vitest#7744, where a long test-file path produced a filename like _Volumes_..._very_..._long_spec_tsx--51554923.js).

The fix caps the filename at 200 bytes: a new MAX_DUMP_FILE_NAME_LENGTH = 200 constant; names that fit are returned unchanged, otherwise the sanitized prefix is sliced so prefix + '-' + hash + '.js' is exactly 200 bytes. The deterministic hashCode(id) suffix is kept, so distinct long ids still map to different files. The sanitized alphabet ([\w@-]) is ASCII-only, so bytes === chars, and negative hashes (e.g. -1252568592, the double dash in the reported filename) are handled by the length math. Short ids are byte-identical to before.

Note: Vitest 4 no longer depends on vite-node (it moved to Vite's Module Runner), so this fix is for vite-node itself and its other consumers; the reported crash came through Vitest's server.debug.dump when it still used vite-node.

Verification

  • New test/test/debug.test.ts (4 tests): long-id length cap (byteLength ≤ 200 and < 255); dumpFile/loadDump round-trip with a very long id; two distinct long ids sharing a 400-char prefix produce different filenames, both within limits; three short ids encode byte-identical to the pre-fix formula (hashes independently recomputed).
  • Full suite: 7 test files passed, 38 tests passed, 0 failed (independently re-run).
  • Typecheck (tsc --noEmit) exits 0; lint on both changed files exits 0; build (pnpm run build) succeeds.

Ref vitest-dev/vitest#7744

Truncate the sanitized id prefix in Debugger.encodeId so the resulting
dump filename (prefix + '-' + hash + '.js') stays within filesystem
limits (~200 bytes). The deterministic hashCode suffix is kept so distinct
long ids that truncate to the same prefix still map to different files.
Short ids are unchanged.

Ref: vitest-dev/vitest#7744
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