fix(ttsc): make TS config loaders and the virtual layout Windows-safe#308
Conversation
The lint fix from #300 left two byte-identical siblings hardcoding the loader tsconfig's rootDir to "/", which is never an ancestor of drive-letter paths (TS6059, #304). Extract the volume-root resolution into a named loaderRootDir helper (also restoring gofmt-stable formatting in linthost) and apply it to the banner and strip drivers. Rooting at the volume is still not enough when the system temp dir and the config file live on different drives: no single rootDir spans two volumes and relative import specifiers cannot cross them (#305). Create the ephemeral loader tree under the config's nearest node_modules/.cache in that case — on all three Go drivers and the lint JS factory — keeping the system temp dir whenever the volumes already match. Also normalize separators in the runtime hooks' isWithin so the slash-form manifest rootDir the loader tsconfig now emits (C:/) matches native real paths, and align the ttsx e2e fixture that mirrored the loader's rootDir synthesis. Resolves #304, resolves #305. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…lege linkVirtualEntry handled directories, plain files, and directory-target symlinks in a Windows-safe way, but its final branch re-symlinked file symlinks with a bare fs.symlinkSync — which needs SeCreateSymbolicLinkPrivilege on Windows and crashed the run with EPERM without admin rights or Developer Mode (#306, same class as #218). Mirror the plain-file branch's hard-link/copy fallback, and skip a link whose target no longer exists: it can serve no module and none of the fallbacks can materialize it. Resolves #306. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR completes Windows path/filesystem hardening for TypeScript config loaders across @ttsc/lint, @ttsc/banner, and @ttsc/strip, and makes the ttsx “virtual layout” mirroring resilient to Windows symlink privilege limitations. It aligns loader rootDir and loader temp-directory placement with Windows volume semantics and adds targeted regression tests.
Changes:
- Make generated loader tsconfigs Windows-safe by deriving
rootDirfrom the loader directory’s volume root (e.g.C:/) instead of hardcoding"/". - Avoid cross-volume failures by placing ephemeral loader trees under the config’s nearest
node_modules/.cachewhen system temp and config are on different volumes. - Harden virtual layout mirroring to avoid EPERM crashes when re-symlinking file-symlink entries on Windows, and add new unit/e2e coverage around the updated behavior.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test-ttsc/src/features/ttsx-runtime/test_ttsx_virtual_layout_mirrors_a_file_symlink_project_entry.ts | Adds an e2e regression test for handling a project-root file symlink during virtual-layout mirroring. |
| tests/test-ttsc/src/features/ttsx-runtime/test_ttsx_serves_a_files_listed_source_outside_the_tsconfig_directory.ts | Updates fixture rootDir synthesis to use the platform volume root instead of "/". |
| packages/ttsc/src/launcher/internal/runtimeHooks.ts | Normalizes path separators in isWithin so manifest rootDir comparisons work on Windows. |
| packages/ttsc/src/launcher/internal/prepareExecution.ts | Adds a Windows-safe fallback when re-symlinking special entries would require privileged file symlinks. |
| packages/strip/test/typescript_loader_tsconfig_rootdir_contains_inputs_test.go | Adds a unit test asserting the generated loader tsconfig rootDir contains both files entries. |
| packages/strip/test/linkname_helpers_test.go | Exposes additional unexported strip driver helpers to tests via go:linkname. |
| packages/strip/test/config_loader_temp_base_stays_on_config_volume_test.go | Adds a unit test asserting loader temp base stays on the config volume when system temp differs. |
| packages/strip/driver/config.go | Uses volume-aware loader rootDir and volume-aware temp base selection for strip TS config loading. |
| packages/lint/test/config/loader_temp_base_stays_on_config_volume_test.go | Adds a unit test for lint loader temp base behavior across volumes. |
| packages/lint/test/config/loader_rootdir_contains_loader_and_config_test.go | Adds a unit test for lint loader rootDir containment of loader+config inputs. |
| packages/lint/src/index.ts | Adds JS-side loader temp base selection to avoid cross-volume path.relative/rootDir failures. |
| packages/lint/linthost/config.go | Replaces inline rootDir resolver with a helper; adds loader temp base selection matching volume behavior. |
| packages/banner/test/typescript_config_loader_tsconfig_rootdir_contains_inputs_test.go | Adds a unit test asserting banner loader tsconfig rootDir contains both inputs. |
| packages/banner/test/linkname_helpers_test.go | Exposes banner loader temp base helper to tests via go:linkname. |
| packages/banner/test/config_loader_temp_base_stays_on_config_volume_test.go | Adds a unit test asserting banner loader temp base stays on the config volume across volumes. |
| packages/banner/driver/banner.go | Uses volume-aware loader rootDir and temp base selection for banner TS config loading. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| try { | ||
| fs.symlinkSync(realEntry, virtualEntry); | ||
| } catch { | ||
| if (!fs.existsSync(realEntry)) { | ||
| return; | ||
| } | ||
| try { | ||
| fs.linkSync(realEntry, virtualEntry); | ||
| } catch { | ||
| fs.copyFileSync(realEntry, virtualEntry); | ||
| } | ||
| } |
| fs.symlinkSync(linkedFile, entry); | ||
| assert.equal(fs.lstatSync(entry).isSymbolicLink(), true); |
Driving the whole loader chain end-to-end on a two-volume Windows machine surfaced three gaps in the previous commit: - A linked node_modules (junction/symlink) broke the loader: the ESM runtime realpaths the loader module at import time, so a relative config specifier computed from the link-form .cache path resolved against the wrong directory. The temp base is realpathed now; NTFS junctions defeat filepath.EvalSymlinks, so the Go drivers chase the link component with os.Readlink first. - Cross-volume configs with no usable node_modules/.cache fell back to the system temp dir — guaranteed to fail. They now fall back to the config's own directory, which is always on the right volume and keeps the relative import a plain "./". - isWithin now compares case-insensitively on Windows (a lowercase TEMP yields a c:-rooted manifest rootDir for the volume real paths spell C:), and is exported alongside linkVirtualEntry so the e2e suite can pin the Windows normalization and EPERM-fallback branches that a spawned run cannot reach on CI. New coverage: the temp-base tests pin the blocked-.cache, missing node_modules, and junction realpath branches; api e2e tests drive linkVirtualEntry's copy fallback and dangling-entry skip (the dangling fixture is a junction, so it exercises the real privilege-less EPERM path on Windows) and isWithin's root/slash/case matching. Verified on Windows 11 with the project on D: and TEMP on C:, including live cross-drive config evaluation through real ttsx + tsgo on both the JS factory and the Go driver paths. Refs #304, #305, #306. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Follow-up push (f3e6875) closing every deferred item from the PR body:
Verification on Windows 11 (D: repo + C: TEMP): full |
Add a windows-latest matrix entry running `pnpm run test:go` as the
minimal Windows safety net — the Go unit suites cover the
platform-sensitive layers (config loaders, path handling) without the
POSIX-only e2e runner, and only need the ttsx launcher build.
Everything that kept that lane red gets fixed with it:
- scripts/test-go-utility-plugins.cjs wrote forward-slash `use` paths
into its go.work; Go's workspace-module matching on Windows rejects
them ("directory ... is not one of the workspace modules"), so every
suite failed at setup. Write native separators.
- packages/ttsc's build script copied README with unix `cp`, which cmd
has no notion of; use a node one-liner.
- The banner suites faked launchers as extensionless `#!/bin/sh`
scripts, which Windows cannot spawn. A new writeDirectLauncher helper
emits the sh script on POSIX and an equivalent `.cmd` on Windows,
keeping both off the node-routed extension list.
- The tempdir-failure case pointed TMPDIR at a file; os.TempDir reads
TMP/TEMP on Windows, so override those there.
- Two assertions were unhermetic on machines with a stray drive-root
node_modules; they now tolerate discoveries outside the fixture.
The relative-config-path case surfaced a real regression in the new
loaderTempBase helpers: a volume-less location compared unequal to the
system temp's volume and was misrouted to the cross-volume branch,
breaking the Rel-failure contract (and creating loader dirs relative to
the cwd). All four helpers now keep the historical default for
volume-less locations, with test scenarios pinning it.
Refs #304, #305.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A locally-run paths Go test materializes its external-file fixture inside the package directory and leaves it behind; the previous commit swept it up unintentionally. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Two problems surfaced running the paths suite on a machine whose repo and temp dir live on different drives (the windows-latest layout): - TestCommandRewritesAllModuleSpecifierForms materialized its external files-list fixture inside the package directory. With the project in the system temp dir that makes the tsconfig `files` list span two volumes, and project loading hangs until the go test timeout (#310 tracks the sidecar behavior; tsc errors fast on the same input). The fixture moves to a sibling temp dir — still outside the tsconfig directory, same volume, and it can no longer leak into the tree when a test dies mid-run. - The utility-plugin runner now prewarms the plugin/driver build before `go test`: the command tests `go run ./plugin` during test execution, so on a cold CI cache the full typescript-go compile counted against the 10-minute test timeout. With these, all three utility suites pass on Windows for the first time (banner 16s, paths 20s, strip 27s locally). Refs #308, #310. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Residue from the two timed-out suite runs predating the fixture relocation; the previous commit swept them up. The relocation itself prevents any further leaks. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
CI Windows runners hand out an 8.3 short-name TEMP (RUNNER~1), so the helper's EvalSymlinks-normalized result never compared equal to a raw Join of the fixture root even though both name the same directory. Normalize the expectation the same way. Refs #308. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
assert.ok on `entry?.isSymbolicLink()` narrows that expression, not `entry`, so the `Dirent | undefined` from Array.find reached linkVirtualEntry and failed typecheck. Assert existence first. Refs #308. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
A trailing `>&2` glued to a payload ending in a digit would turn that digit into a file-descriptor redirect; putting the redirect first sidesteps both that and the trailing-space form. Also document the cmd-metacharacter constraint on payloads. Refs #308. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Overview
Completes the Windows path-hardening that #300 started, in three parts:
rootDir: "/"(same TS6059 as #299) #304 — thebannerandstripGo drivers still hardcoded the loader tsconfig'srootDirto"/", which is never an ancestor of drive-letter paths, so every TypeScript config evaluation failed withTS6059on Windows. The volume-root resolution is extracted into a namedloaderRootDirhelper (per driver, mirroring the existing per-package helper duplication) and applied to all three drivers; the inline func literal from fix(lint): dynamically resolve rootDir for Windows compatibility #300 is replaced by the same helper, which also restores gofmt-stable formatting inlinthost/config.go.C:, project onD:), no singlerootDirspans bothfilesentries and relative import specifiers cannot cross drives, so evaluation still failed. All three Go drivers and the lint JS factory now create the ephemeral loader tree under the config's nearestnode_modules/.cachewhen the volumes differ, keeping the system temp dir when they match (POSIX behavior is unchanged: both roots are always/).linkVirtualEntryfalls back to a plainfs.symlinkSync— EPERM on Windows without Developer Mode #306 —linkVirtualEntry's final branch re-symlinked file-symlink entries with a barefs.symlinkSync, which needsSeCreateSymbolicLinkPrivilegeon Windows and crashed the run with EPERM (same class as ttsx virtual layout: symlinked entries fail with EPERM on Windows (junction fallback missing in linkVirtualEntry) #218). It now falls back to the plain-file branch's hard-link/copy strategy, skipping dangling links.Follow-ups folded in from #304: the runtime hooks'
isWithinnormalizes separators (the synthesized manifestrootDiris slash-formC:/while real paths are native), and the ttsx e2e fixture that mirrored the loader'srootDir: "/"synthesis now derives the volume root.Test plan
rootDircontains bothfilesentries, andloaderTempBasekeeps the system temp on matching volumes / moves undernode_modules/.cacheacross volumes (the cross-volume branch runs for real on drive-letter platforms, guarded by afilepath.VolumeNameprobe elsewhere).rootDir.D:, TEMP onC:): all six new Go tests pass, including the real cross-volume branch; fullstripGo suite passes;banner/lintsuites show only failures already present on unchangedmaster(sh-script fake launchers,ttsxsubprocess resolution — environmental, tracked separately).tsc --noEmitis clean forpackages/lintandpackages/ttsc; changed files formatted with prettier and the repo's gofmt pipeline.Deferred
node_modulesanywhere) intentionally falls back to the historical system-temp behavior.linkVirtualEntryfalls back to a plainfs.symlinkSync— EPERM on Windows without Developer Mode #306 has no automated test: creating a file-symlink fixture on Windows requires the same privilege the fallback exists to avoid.Resolves #304, resolves #305, resolves #306.
🤖 Generated with Claude Code