From a761981897f9d65533842f96f242884187b7d1ed Mon Sep 17 00:00:00 2001 From: Ysopwnable <161784452+N0zoM1z0@users.noreply.github.com> Date: Sun, 11 Oct 2026 03:15:44 +0800 Subject: [PATCH] test: remove module and timestamp assumptions from boundary fixtures (#1621) --- .../darwinProcessRunTokenReader.test.ts | 20 +++++++++---------- .../nativeSignatureTargetBinding.test.ts | 10 ++++++++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/tests/boundary/process/darwinProcessRunTokenReader.test.ts b/tests/boundary/process/darwinProcessRunTokenReader.test.ts index 6c783a669..6c0025d78 100644 --- a/tests/boundary/process/darwinProcessRunTokenReader.test.ts +++ b/tests/boundary/process/darwinProcessRunTokenReader.test.ts @@ -36,8 +36,8 @@ const writeBlockingCompiler = async (directory: string) => { const statePath = join(directory, "compile-state.json"); const releasePath = join(directory, "release-compiler"); const source = `#!/usr/bin/env node -const fs = require("node:fs"); -const path = require("node:path"); +const fs = process.getBuiltinModule("node:fs"); +const path = process.getBuiltinModule("node:path"); const statePath = ${JSON.stringify(statePath)}; const releasePath = ${JSON.stringify(releasePath)}; const state = fs.existsSync(statePath) @@ -69,14 +69,14 @@ const writeBlockingIdentityCompiler = async (directory: string) => { const executable = join(directory, "fake-identity-xcrun"); const statePath = join(directory, "identity-helper-state.json"); const helperSource = `#!/usr/bin/env node -const fs = require("node:fs"); +const fs = process.getBuiltinModule("node:fs"); fs.writeFileSync(${JSON.stringify(statePath)}, JSON.stringify({ - root: __dirname, + root: process.getBuiltinModule("node:path").dirname(fs.realpathSync(process.argv[1])), })); setInterval(() => {}, 1000); `; const compilerSource = `#!/usr/bin/env node -const fs = require("node:fs"); +const fs = process.getBuiltinModule("node:fs"); const outputIndex = process.argv.indexOf("-o"); const output = process.argv[outputIndex + 1]; fs.writeFileSync(output, ${JSON.stringify(helperSource)}); @@ -309,14 +309,14 @@ const writeTemporaryObjectCompiler = async (directory: string) => { const executable = join(directory, "fake-temporary-xcrun"); const statePath = join(directory, "temporary-state.json"); const source = `#!/usr/bin/env node -const fs = require("node:fs"); -const os = require("node:os"); -const path = require("node:path"); -const { spawn } = require("node:child_process"); +const fs = process.getBuiltinModule("node:fs"); +const os = process.getBuiltinModule("node:os"); +const path = process.getBuiltinModule("node:path"); +const { spawn } = process.getBuiltinModule("node:child_process"); const temporary = fs.mkdtempSync(path.join(os.tmpdir(), "TemporaryDirectory.")); const object = path.join(temporary, "ProcessRunTokenReader-1.o"); const job = spawn(process.execPath, ["-e", - "setTimeout(() => { const fs = require('node:fs'); fs.mkdirSync(" + JSON.stringify(temporary) + + "setTimeout(() => { const fs = process.getBuiltinModule('node:fs'); fs.mkdirSync(" + JSON.stringify(temporary) + ", { recursive: true }); fs.writeFileSync(" + JSON.stringify(object) + ", 'object'); }, 300)"], { detached: true, stdio: "ignore" }); job.unref(); diff --git a/tests/boundary/providers/native/nativeSignatureTargetBinding.test.ts b/tests/boundary/providers/native/nativeSignatureTargetBinding.test.ts index 7355ba075..25b9e0730 100644 --- a/tests/boundary/providers/native/nativeSignatureTargetBinding.test.ts +++ b/tests/boundary/providers/native/nativeSignatureTargetBinding.test.ts @@ -9,6 +9,7 @@ import { rename, rm, symlink, + utimes, writeFile, } from "node:fs/promises"; import { dirname, join } from "node:path"; @@ -102,8 +103,13 @@ describe("native signature target identity", () => { const runner = new Captures(async (args) => { if (!args.includes("--entitlements")) return; if (change === "remove") await rm(path); - else if (change === "rewrite") await writeFile(path, CONTENT); - else { + else if (change === "rewrite") { + const before = await lstat(path); + await writeFile(path, CONTENT); + // Identical writes may share a filesystem clock tick. Make the + // metadata change observed by the target guard explicit. + await utimes(path, before.atimeMs / 1000, before.mtimeMs / 1000 + 1); + } else { const replacement = `${path}.replacement`; await writeFile(replacement, CONTENT); await rename(replacement, path);