Skip to content
Closed
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion pstack/skills/statechart/scripts/frontends/dot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,18 @@ export const parseState = (label: string, parsed = new Map<string, [string, Valu

export type Lines = string | Iterable<string>;

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<string> =>
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<string, State>();
Expand Down
6 changes: 5 additions & 1 deletion pstack/skills/statechart/scripts/test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions pstack/skills/statechart/scripts/test/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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\./);
});