mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-08 08:44:37 +08:00
The differential and LLVM differential suites can run the same corpus program's Node oracle at the same time in one shard. Programs whose scratch directory or file was derived only from argv[1] collided, and one oracle removed the paths under the other. Their names now include the pid, as 1403 and 5567 already do. Printed output never carries the name. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
60 lines
1.7 KiB
TypeScript
60 lines
1.7 KiB
TypeScript
// readdirSync: Node returns names in OS order (unsorted), so the corpus
|
|
// checks MEMBERSHIP via includes() and never prints the order. Scratch
|
|
// paths derive from argv[1]'s tail (see 992) for parallel safety.
|
|
import {
|
|
existsSync,
|
|
mkdirSync,
|
|
readdirSync,
|
|
rmdirSync,
|
|
rmSync,
|
|
writeFileSync,
|
|
} from "node:fs";
|
|
|
|
function tail(path: string): string {
|
|
let i = path.length - 1;
|
|
while (i >= 0 && path.charAt(i) !== "/" && path.charAt(i) !== "\\") {
|
|
i = i - 1;
|
|
}
|
|
return path.slice(i + 1);
|
|
}
|
|
function freshDir(dir: string): void {
|
|
if (existsSync(dir)) {
|
|
for (const name of readdirSync(dir)) {
|
|
rmSync(dir + "/" + name);
|
|
}
|
|
rmdirSync(dir);
|
|
}
|
|
mkdirSync(dir);
|
|
}
|
|
const scratch = "tmp-993-" + tail(process.argv[1]) + "-" + process.pid;
|
|
freshDir(scratch);
|
|
|
|
console.log(readdirSync(scratch).length); // fresh dir is empty
|
|
writeFileSync(scratch + "/b.txt", "b");
|
|
writeFileSync(scratch + "/a.txt", "a");
|
|
mkdirSync(scratch + "/sub");
|
|
writeFileSync(scratch + "/sub/inner.txt", "inner");
|
|
|
|
const names = readdirSync(scratch);
|
|
console.log(names.length);
|
|
console.log(names.includes("a.txt"), names.includes("b.txt"), names.includes("sub"));
|
|
console.log(names.includes("c.txt"), names.includes("."), names.includes(".."));
|
|
|
|
// Names compose with ordinary array machinery.
|
|
const txt = names.filter((n) => n.endsWith(".txt"));
|
|
console.log(txt.length, txt.includes("sub"));
|
|
let total = 0;
|
|
for (const n of readdirSync(scratch + "/sub")) {
|
|
total = total + n.length;
|
|
}
|
|
console.log(total); // "inner.txt"
|
|
|
|
rmSync(scratch + "/sub/inner.txt");
|
|
rmdirSync(scratch + "/sub");
|
|
console.log(readdirSync(scratch).includes("sub"));
|
|
rmSync(scratch + "/a.txt");
|
|
rmSync(scratch + "/b.txt");
|
|
console.log(readdirSync(scratch).length);
|
|
rmdirSync(scratch);
|
|
console.log(existsSync(scratch));
|