Skip to content

Commit 4d60c40

Browse files
test(u5b): gate the Windows namespace-marker row to the Windows leg (#2357)
The ubuntu-latest platform-unit-test arm failed on one row of this unit's own spec. Its CI assertion (job 128939518078, spec:1700) expected [deep, nested, dirname(nested)] and received only the deepest directory, because the row built its extended-length marker from path.resolve("C:/test-dir/nested") - on POSIX that spelling is not absolute at all, so it resolves under the runner's cwd and the marker fed to the writer is one the platform cannot report and the chain cannot map. Only Windows reports mkdir's created directory under the extended length namespace, so the row is now gated the way the icacls rows beside it are, and a platform-neutral row pins the other half of the same contract: an answer that is not on the walk from the target's own directory syncs no ancestor at all. Measured with the pinned node v22.23.4, dir wt-u5a-2357/src, command "node node_modules/vitest/vitest.mjs run --config vitest.services.config.ts --coverage": 11 failed | 1688 passed | 1 skipped (1700) before this commit, 11 failed | 1689 passed | 1 skipped (1701) after, with services/file-safety absent from the failure list. Those 11 are services/marketplace (2 rows), services/rules (5 rows, EPERM on unprivileged symlink creation) and services/code-index/processors/parser (TelemetryService not initialized); the identical 11 also fail with the identical command on the sibling unit's head fb03ecb, so they are not this delta. Targeted file-safety run on the Windows leg: 86 passed (86). eslint --max-warnings=0 on the touched file: 0 problems, same as at head. tsc --noEmit -p .: exit 0. prettier --check: clean.
1 parent 066f153 commit 4d60c40

1 file changed

Lines changed: 52 additions & 16 deletions

File tree

‎src/services/file-safety/__tests__/safeWriteText.spec.ts‎

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,20 +1670,57 @@ describe("safeWriteText", () => {
16701670
expect(dirSyncs).toEqual([deep, nested, root])
16711671
})
16721672

1673-
it("maps the namespace marker Windows reports for the directory it created", async () => {
1674-
// Windows answers mkdir with the created directory under the extended-length namespace,
1675-
// a different spelling from the one the write works in. The chain that decides which
1676-
// directories to fsync has to match the two, or the new ancestors go unsynced on exactly
1677-
// the platform that reports it this way - and the write still claims durability it did not
1678-
// get. The row builds the reported spelling from the same path the write resolved, so it
1679-
// asserts the mapping on both platforms.
1680-
const nested = path.resolve("C:/test-dir/nested")
1681-
const deep = path.join(nested, "deep")
1682-
const targetPath = path.join(deep, "target.txt")
1683-
const stripped = nested.startsWith("/") ? nested.slice(1) : nested
1684-
const reported = "\\\\?\\" + stripped.split("/").join("\\")
1673+
// A row about what the Windows filesystem reports, so it belongs to the Windows leg: it is
1674+
// gated exactly like the icacls rows in this describe. The marker is stripped by a string
1675+
// comparison, but deciding WHICH directories the answer names walks the runner's own path
1676+
// semantics, and on POSIX a drive-lettered path like "C:/test-dir/nested" is not even
1677+
// absolute, so a marker built that way is an input the platform cannot produce. The option
1678+
// keeps the write on the non-win32 durability branch - the branch this row is about - while
1679+
// the runner supplies win32 path semantics. The POSIX spelling of the same answer is pinned
1680+
// by the preceding row, and the answer this write cannot place by the row after it.
1681+
it.skipIf(process.platform !== "win32")(
1682+
"maps the namespace marker Windows reports for the directory it created",
1683+
async () => {
1684+
const nested = path.resolve("C:/test-dir/nested")
1685+
const deep = path.join(nested, "deep")
1686+
const targetPath = path.join(deep, "target.txt")
1687+
const stripped = nested.startsWith("/") ? nested.slice(1) : nested
1688+
const reported = "\\\\?\\" + stripped.split("/").join("\\")
1689+
vi.mocked(fs.realpath).mockResolvedValue(targetPath)
1690+
vi.mocked(fs.mkdir).mockResolvedValue(reported)
1691+
vi.mocked(fsSync.openSync).mockClear()
1692+
1693+
await safeWriteText(targetPath, "new data", { platform: "linux" })
1694+
1695+
const dirSyncs = vi
1696+
.mocked(fsSync.openSync)
1697+
.mock.calls.filter(function (call: unknown[]) {
1698+
return call[1] === "r"
1699+
})
1700+
.map(function (call: unknown[]) {
1701+
return String(call[0])
1702+
})
1703+
// The marker had to map onto the write's own paths: nothing under the marker is synced.
1704+
expect(dirSyncs).toEqual([deep, nested, path.dirname(nested)])
1705+
expect(
1706+
dirSyncs.some(function (p: string) {
1707+
return p.includes("?")
1708+
}),
1709+
).toBe(false)
1710+
},
1711+
)
1712+
1713+
it("syncs no ancestor when mkdir names a directory this write cannot place", async () => {
1714+
// The chain is derived by walking up from the target's own directory until it reaches what
1715+
// mkdir reported. An answer that is not on that walk is not a directory this write created,
1716+
// and it must not be synced: flushing a directory someone else owns, while the published
1717+
// file's own new ancestors stay unsynced, is the opposite of what step 4b is for. Only the
1718+
// immediate parent is flushed, because the commit rename put its entry there. Constructed
1719+
// from path.resolve so the answer is absolute, and off the walk, on both platforms.
1720+
const targetPath = path.join(path.resolve("/tmp/test-dir/deep"), "target.txt")
1721+
const unrelated = path.resolve("/tmp/other-tree/nested")
16851722
vi.mocked(fs.realpath).mockResolvedValue(targetPath)
1686-
vi.mocked(fs.mkdir).mockResolvedValue(reported)
1723+
vi.mocked(fs.mkdir).mockResolvedValue(unrelated)
16871724
vi.mocked(fsSync.openSync).mockClear()
16881725

16891726
await safeWriteText(targetPath, "new data", { platform: "linux" })
@@ -1696,11 +1733,10 @@ describe("safeWriteText", () => {
16961733
.map(function (call: unknown[]) {
16971734
return String(call[0])
16981735
})
1699-
// The marker had to map onto the write's own paths: nothing under the marker is synced.
1700-
expect(dirSyncs).toEqual([deep, nested, path.dirname(nested)])
1736+
expect(dirSyncs).toEqual([path.dirname(targetPath)])
17011737
expect(
17021738
dirSyncs.some(function (p: string) {
1703-
return p.includes("?")
1739+
return p.includes(unrelated)
17041740
}),
17051741
).toBe(false)
17061742
})

0 commit comments

Comments
 (0)