From 0eba52ceb34f2ff6c7558d1950262023dfde3647 Mon Sep 17 00:00:00 2001 From: lnuxe Date: Thu, 19 Nov 2026 16:30:01 +0800 Subject: [PATCH 1/2] fix(pstack): resolve the temp dir before building the relative symlink linkedLauncher creates its links under os.tmpdir(), which on macOS is a symlink (/tmp -> /private/tmp, /var -> /private/var). path.relative() computes the link target lexically from the symlinked path, but the kernel resolves the link's ".." segments from the physical directory, which is one level deeper, so the spawn target does not exist and the "launcher reached through a symlink" test fails. Resolve the temp directory with fs.realpathSync() before building the link so both sides are physical. Fixes #1164. --- .../claude-code/skills/statechart/scripts/test/cli.test.ts | 6 +++++- pstack/skills/statechart/scripts/test/cli.test.ts | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/harness/pstack/claude-code/skills/statechart/scripts/test/cli.test.ts b/harness/pstack/claude-code/skills/statechart/scripts/test/cli.test.ts index 11f06a6fd7..75bcf7570d 100644 --- a/harness/pstack/claude-code/skills/statechart/scripts/test/cli.test.ts +++ b/harness/pstack/claude-code/skills/statechart/scripts/test/cli.test.ts @@ -114,7 +114,11 @@ const launcherTools = () => { }; const linkedLauncher = () => { - const links = fs.mkdtempSync(path.join(os.tmpdir(), "statechart-links-")); + // os.tmpdir() is a symlink on macOS (/tmp -> /private/tmp, /var -> /private/var). + // The kernel resolves a relative link's ".." segments from the physical directory, + // so building the link from the lexical path lands one level too shallow and the + // spawn fails. Resolve the temp directory first so both sides are physical. + const links = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "statechart-links-"))); const [first, second] = [path.join(links, "a"), path.join(links, "b")]; fs.mkdirSync(first); fs.mkdirSync(second); diff --git a/pstack/skills/statechart/scripts/test/cli.test.ts b/pstack/skills/statechart/scripts/test/cli.test.ts index 11f06a6fd7..75bcf7570d 100644 --- a/pstack/skills/statechart/scripts/test/cli.test.ts +++ b/pstack/skills/statechart/scripts/test/cli.test.ts @@ -114,7 +114,11 @@ const launcherTools = () => { }; const linkedLauncher = () => { - const links = fs.mkdtempSync(path.join(os.tmpdir(), "statechart-links-")); + // os.tmpdir() is a symlink on macOS (/tmp -> /private/tmp, /var -> /private/var). + // The kernel resolves a relative link's ".." segments from the physical directory, + // so building the link from the lexical path lands one level too shallow and the + // spawn fails. Resolve the temp directory first so both sides are physical. + const links = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "statechart-links-"))); const [first, second] = [path.join(links, "a"), path.join(links, "b")]; fs.mkdirSync(first); fs.mkdirSync(second); From 50c646a58580070aa97555d425bc927aacd5ae5e Mon Sep 17 00:00:00 2001 From: lnuxe Date: Thu, 19 Nov 2026 18:00:07 +0800 Subject: [PATCH 2/2] fix(pstack): strip CRLF from TLC output so ENDMSG markers close The Windows JVM writes CRLF. outputLines splits on \n and leaves a trailing \r, so the $ anchored @!@!@ENDMSG regex fails to match and a message stays open; readVerdict then sees no rule that broke and the worker exits silently with code 1. Normalize each line in linesOf so every consumer (messages, dot, marks) is CRLF-safe. Fixes #1170. --- .../skills/statechart/scripts/frontends/dot.ts | 13 ++++++++++++- .../statechart/scripts/test/messages.test.ts | 14 ++++++++++++++ pstack/skills/statechart/scripts/frontends/dot.ts | 13 ++++++++++++- .../statechart/scripts/test/messages.test.ts | 14 ++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/harness/pstack/claude-code/skills/statechart/scripts/frontends/dot.ts b/harness/pstack/claude-code/skills/statechart/scripts/frontends/dot.ts index 003dfc89d4..38219c458d 100644 --- a/harness/pstack/claude-code/skills/statechart/scripts/frontends/dot.ts +++ b/harness/pstack/claude-code/skills/statechart/scripts/frontends/dot.ts @@ -35,7 +35,18 @@ export const parseState = (label: string, parsed = new Map; -export const linesOf = (input: Lines) => (typeof input === "string" ? input.split("\n") : input); +// The Windows JVM writes CRLF; the @!@!@STARTMSG/@!@!@ENDMSG markers in +// messages.ts are matched with a $ anchor, so a trailing \r would keep a +// message open and readVerdict would see no rule that broke. Normalize every +// line here so all consumers (messages, dot, counters) are CRLF-safe. +const stripCR = (line: string) => (line.endsWith("\r") ? line.slice(0, -1) : line); + +export const linesOf = (input: Lines): Iterable => + typeof input === "string" + ? input.split("\n").map(stripCR) + : (function* () { + for (const line of input) yield stripCR(line); + })(); export function parseDot(input: Lines): Graph { const states = new Map(); diff --git a/harness/pstack/claude-code/skills/statechart/scripts/test/messages.test.ts b/harness/pstack/claude-code/skills/statechart/scripts/test/messages.test.ts index 61af006968..67a47db492 100644 --- a/harness/pstack/claude-code/skills/statechart/scripts/test/messages.test.ts +++ b/harness/pstack/claude-code/skills/statechart/scripts/test/messages.test.ts @@ -210,3 +210,17 @@ test("TLC's run time prints as plain TLC prints it, with each field wrapping", ( ] satisfies [number, string][]) assert.equal(runtime(ms), printed, String(ms)); }); + +test("CRLF line endings (Windows JVM) still close @!@!@ENDMSG markers", () => { + // The Windows JVM writes CRLF. The marker regexes are $ anchored, so an + // unstripped trailing \r keeps a message open and readVerdict sees no rule + // that broke. linesOf strips \r so the same output parses either way. + const lf = [ + tool(2111, 1, "Evaluating invariant Bad failed."), + tool(2186, 0, "Finished in 0ms at (T)"), + "", + ].join("\n"); + const crlf = lf.split("\n").join("\r\n"); + assert.equal(plain(lf), plain(crlf)); + assert.match(plain(crlf), /^Error: Evaluating invariant Bad failed\./); +}); diff --git a/pstack/skills/statechart/scripts/frontends/dot.ts b/pstack/skills/statechart/scripts/frontends/dot.ts index 003dfc89d4..38219c458d 100644 --- a/pstack/skills/statechart/scripts/frontends/dot.ts +++ b/pstack/skills/statechart/scripts/frontends/dot.ts @@ -35,7 +35,18 @@ export const parseState = (label: string, parsed = new Map; -export const linesOf = (input: Lines) => (typeof input === "string" ? input.split("\n") : input); +// The Windows JVM writes CRLF; the @!@!@STARTMSG/@!@!@ENDMSG markers in +// messages.ts are matched with a $ anchor, so a trailing \r would keep a +// message open and readVerdict would see no rule that broke. Normalize every +// line here so all consumers (messages, dot, counters) are CRLF-safe. +const stripCR = (line: string) => (line.endsWith("\r") ? line.slice(0, -1) : line); + +export const linesOf = (input: Lines): Iterable => + typeof input === "string" + ? input.split("\n").map(stripCR) + : (function* () { + for (const line of input) yield stripCR(line); + })(); export function parseDot(input: Lines): Graph { const states = new Map(); diff --git a/pstack/skills/statechart/scripts/test/messages.test.ts b/pstack/skills/statechart/scripts/test/messages.test.ts index 61af006968..67a47db492 100644 --- a/pstack/skills/statechart/scripts/test/messages.test.ts +++ b/pstack/skills/statechart/scripts/test/messages.test.ts @@ -210,3 +210,17 @@ test("TLC's run time prints as plain TLC prints it, with each field wrapping", ( ] satisfies [number, string][]) assert.equal(runtime(ms), printed, String(ms)); }); + +test("CRLF line endings (Windows JVM) still close @!@!@ENDMSG markers", () => { + // The Windows JVM writes CRLF. The marker regexes are $ anchored, so an + // unstripped trailing \r keeps a message open and readVerdict sees no rule + // that broke. linesOf strips \r so the same output parses either way. + const lf = [ + tool(2111, 1, "Evaluating invariant Bad failed."), + tool(2186, 0, "Finished in 0ms at (T)"), + "", + ].join("\n"); + const crlf = lf.split("\n").join("\r\n"); + assert.equal(plain(lf), plain(crlf)); + assert.match(plain(crlf), /^Error: Evaluating invariant Bad failed\./); +});