Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .agents/skills/statechart/scripts/statechart.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { cannotRunTlc, findTlc } from "./tlc-tools.mjs";

const here = path.dirname(fileURLToPath(import.meta.url));
const { MAX_STRING_LENGTH } = constants;
const tempDir = (prefix) => fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), prefix)));

class CannotFinish extends Error {}
class TlcStopped extends CannotFinish {}
Expand Down Expand Up @@ -183,7 +182,7 @@ function runJava(file, args, options, dot) {

async function tlc(tools, spec, cfg, base, { dump, module, workers = "1" } = {}) {
fs.writeFileSync(`${base}.cfg`, cfg);
const metadir = tempDir("tlc-");
const metadir = fs.mkdtempSync(path.join(os.tmpdir(), "tlc-"));
// TLC writes the standard modules, such as Naturals.tla, to java.io.tmpdir under fixed names,
// so runs that share that folder can read a module while another run rewrites it.
const javaTmp = path.join(metadir, "tmp");
Expand Down Expand Up @@ -609,7 +608,7 @@ function outDir(flagged, input, name) {
}

async function inWorkFolder(body) {
const work = tempDir("statechart-");
const work = fs.mkdtempSync(path.join(os.tmpdir(), "statechart-"));
fs.mkdirSync(path.join(work, "tlc"));
let keep = false;
try {
Expand Down
31 changes: 7 additions & 24 deletions .agents/skills/statechart/scripts/test/statechart.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
mkdtempSync,
readdirSync,
readFileSync,
realpathSync,
renameSync,
rmSync,
statSync,
Expand Down Expand Up @@ -5845,21 +5844,6 @@ const writeLamp = (dir) => {
return join(dir, "Lamp-statechart");
};

test("a symlinked TMPDIR keeps diagnostic paths relative to the workspace", needsTlc, () => {
const dir = mkdtempSync(join(tmpdir(), "statechart-"));
writeLamp(dir);
const tmp = join(dir, "tmp");
mkdirSync(tmp);
const alias = join(dir, "alias");
symlinkSync(tmp, alias, "dir");
writeFileSync(join(dir, "Lamp.map.mjs"), 'export const state = () => { throw new Error("mapping failed"); };\n');
const r = node("statechart.mjs", ["from-spec", "Lamp.tla"], dir, { TMPDIR: alias });
assert.equal(r.status, 2, r.stderr);
const kept = r.stderr.match(/ The files that this run wrote are in (tmp\/statechart-\w+)\.\n$/)?.[1];
assert.ok(kept, r.stderr);
assert.ok(existsSync(join(dir, kept, "tlc", "Lamp.out")));
});

test("a rerun without --png removes the chart.png of an earlier run", needsTlc, () => {
const dir = mkdtempSync(join(tmpdir(), "statechart-"));
const out = writeLamp(dir);
Expand Down Expand Up @@ -6176,7 +6160,6 @@ int rename(const char *from, const char *to) {
}
`;
const failingRenames = (() => {
if (process.platform !== "linux") return null;
const dir = mkdtempSync(join(tmpdir(), "statechart-preload-"));
writeFileSync(join(dir, "rename.c"), failRenames);
const so = join(dir, "rename.so");
Expand All @@ -6185,7 +6168,7 @@ const failingRenames = (() => {
})();
test(
"a run whose rename fails after it moves the output folder aside puts the folder back, or says where it is",
{ skip: needsTlc.skip || (!failingRenames && "requires Linux LD_PRELOAD and a C compiler") },
{ skip: needsTlc.skip || (!failingRenames && "cannot compile a rename preload") },
() => {
const dir = mkdtempSync(join(tmpdir(), "statechart-"));
writeLamp(dir);
Expand Down Expand Up @@ -6221,7 +6204,7 @@ test(

test(
"a run on a filesystem that cannot rename copies its files into place",
{ skip: needsTlc.skip || (!failingRenames && "requires Linux LD_PRELOAD and a C compiler") },
{ skip: needsTlc.skip || (!failingRenames && "cannot compile a rename preload") },
() => {
const dir = mkdtempSync(join(tmpdir(), "statechart-"));
writeLamp(dir);
Expand All @@ -6248,7 +6231,7 @@ test(

test(
"a run that cannot rename replaces a folder that another run makes before its copy, and keeps one that another run makes during its copy",
{ skip: needsTlc.skip || (!failingRenames && "requires Linux LD_PRELOAD and a C compiler") },
{ skip: needsTlc.skip || (!failingRenames && "cannot compile a rename preload") },
() => {
const dir = mkdtempSync(join(tmpdir(), "statechart-"));
writeLamp(dir);
Expand Down Expand Up @@ -6280,7 +6263,7 @@ test(

test(
"a run that cannot rename stops when another run removes its folder during its copy and makes an empty one in its place, and keeps that folder",
{ skip: needsTlc.skip || (!failingRenames && "requires Linux LD_PRELOAD and a C compiler") },
{ skip: needsTlc.skip || (!failingRenames && "cannot compile a rename preload") },
() => {
const dir = mkdtempSync(join(tmpdir(), "statechart-"));
writeLamp(dir);
Expand All @@ -6301,7 +6284,7 @@ test(

test(
"a run that cannot rename keeps the folder that another run puts in place of its folder as soon as the run makes it",
{ skip: needsTlc.skip || (!failingRenames && "requires Linux LD_PRELOAD and a C compiler") },
{ skip: needsTlc.skip || (!failingRenames && "cannot compile a rename preload") },
() => {
const dir = mkdtempSync(join(tmpdir(), "statechart-"));
writeLamp(dir);
Expand Down Expand Up @@ -6527,7 +6510,7 @@ exit $s
const folders = new Set();
for (const line of runs) {
const [folder, parsed] = line.split(": ");
assert.ok(folder.startsWith(join(realpathSync(tmp), "tlc-")), line);
assert.ok(folder.startsWith(join(tmp, "tlc-")), line);
assert.ok(parsed.startsWith(`Parsing file ${folder}/`), line);
folders.add(folder);
}
Expand All @@ -6552,7 +6535,7 @@ test(
const [, file] = r.stderr.match(
/^(\S+\/tlc\/Pay\.out): TLC stopped on an error that is not a broken rule: Assumption .* is false\.\n$/,
);
assert.ok(file.startsWith(realpathSync(tmp)), file);
assert.ok(file.startsWith(tmp), file);
assert.match(readFileSync(file, "utf8"), /Assumption .* is false/);
assert.equal(existsSync(join(dir, "Pay-statechart")), false);
},
Expand Down
2 changes: 1 addition & 1 deletion .agents/skills/statechart/scripts/tlc-tools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function findTlc() {
if (TLA2TOOLS) return { jar: TLA2TOOLS, java: JAVA || "java" };
const command = (tools) =>
`cd "$(mktemp -d)" && MISE_CEILING_PATHS="$PWD" mise install ${tools.map((t) => `'${t}'`).join(" ")}`;
const empty = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "statechart-mise-")));
const empty = fs.mkdtempSync(path.join(os.tmpdir(), "statechart-mise-"));
const env = { ...process.env, MISE_CEILING_PATHS: empty };
const run = (...args) => spawnSync("mise", args, { cwd: empty, env, encoding: "utf8" });
const mise = (...args) => {
Expand Down
Loading