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/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/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/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); 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\./); +});