Skip to content

backnotprop/pstack / skills/statechart

statechart

Unverified

Check a TLA+ model of a system that moves between states, such as a product flow, a protocol, or a service, and draw it as a Mermaid statechart. The report gives the shortest path to each state that breaks a rule. Use for /statechart, or to show a bug as a path through states.

FileKindSize
SKILL.mdskill md8.9 KB
references/render.mdmarkdown3.6 KB
scripts/backends/cfg.tsscript1.2 KB
scripts/backends/mermaid.tsscript9.0 KB
scripts/backends/plain-text.tsscript2.3 KB
scripts/backends/report.tsscript6.9 KB
scripts/frontends/config.tsscript10.4 KB
scripts/frontends/dot.tsscript2.4 KB
scripts/frontends/marks.tsscript3.2 KB
scripts/frontends/messages.tsscript1.8 KB
scripts/frontends/spec.tsscript4.1 KB
scripts/frontends/trace.tsscript988 B
scripts/frontends/value.tsscript4.6 KB
scripts/frontends/verdict.tsscript1.7 KB
scripts/frontends/view.tsscript4.3 KB
scripts/ir.tsscript14.8 KB
scripts/package.jsonmanifest233 B
scripts/passes/annotate.tsscript3.7 KB
scripts/passes/label.tsscript8.4 KB
scripts/passes/lift.tsscript2.8 KB
scripts/passes/loop-check.tsscript2.1 KB
scripts/passes/paths.tsscript1.9 KB
scripts/passes/reach.tsscript4.0 KB
scripts/passes/region-check.tsscript3.4 KB
scripts/passes/regions.tsscript9.3 KB
scripts/pipeline.tsscript2.9 KB
scripts/run.tsscript17.8 KB
scripts/statechartexecutablescript991 B
scripts/statechart.tsscript6.8 KB
scripts/test/ConfigOracle.javaother2.7 KB
scripts/test/chart.test.tsscript40.1 KB
scripts/test/charts/Braces.mmdother312 B
scripts/test/charts/Escapes.mmdother244 B
scripts/test/charts/Phases.mmdother584 B
scripts/test/cli.test.tsscript49.0 KB
scripts/test/config-fuzz.test.tsscript8.5 KB
scripts/test/corpus.test.tsscript13.7 KB
scripts/test/corpus/Counter/ChartRun.outother2.6 KB
scripts/test/corpus/Counter/Counter.cfgconfig64 B
scripts/test/corpus/Counter/Counter.tlaother185 B
scripts/test/corpus/Counter/chart.mmdother112 B
scripts/test/corpus/Counter/graph.dotother633 B
scripts/test/corpus/Counter/report.mdmarkdown243 B
scripts/test/corpus/Counter/sany.outother37.3 KB
scripts/test/corpus/Counter/verdict-1.outother2.1 KB
scripts/test/corpus/CounterAction/ChartRun.outother2.7 KB
scripts/test/corpus/CounterAction/CounterAction.cfgconfig89 B
scripts/test/corpus/CounterAction/CounterAction.tlaother255 B
scripts/test/corpus/CounterAction/chart.mmdother518 B
scripts/test/corpus/CounterAction/graph.dotother798 B
scripts/test/corpus/CounterAction/report.mdmarkdown436 B
scripts/test/corpus/CounterAction/sany.outother42.9 KB
scripts/test/corpus/CounterAction/verdict-1.exitother3 B
scripts/test/corpus/CounterAction/verdict-1.outother2.1 KB
scripts/test/corpus/CounterAction/verdict-2.exitother3 B
scripts/test/corpus/CounterAction/verdict-2.outother3.1 KB
scripts/test/corpus/CounterAction/verdict-3.outother2.6 KB
scripts/test/corpus/CounterDeadlock/ChartRun.outother2.7 KB
scripts/test/corpus/CounterDeadlock/CounterDeadlock.cfgconfig63 B
scripts/test/corpus/CounterDeadlock/CounterDeadlock.tlaother225 B
scripts/test/corpus/CounterDeadlock/chart.mmdother462 B
scripts/test/corpus/CounterDeadlock/graph.dotother633 B
scripts/test/corpus/CounterDeadlock/report.mdmarkdown624 B
scripts/test/corpus/CounterDeadlock/sany.outother41.8 KB
scripts/test/corpus/CounterDeadlock/verdict-1.exitother3 B
scripts/test/corpus/CounterDeadlock/verdict-1.outother2.1 KB
scripts/test/corpus/CounterDeadlock/verdict-2.exitother3 B
scripts/test/corpus/CounterDeadlock/verdict-2.outother3.0 KB
scripts/test/corpus/CounterFan/ChartRun.outother3.1 KB
scripts/test/corpus/CounterFan/CounterFan.cfgconfig37 B
scripts/test/corpus/CounterFan/CounterFan.tlaother338 B
scripts/test/corpus/CounterFan/chart.mmdother1.7 KB
scripts/test/corpus/CounterFan/graph.dotother5.3 KB
scripts/test/corpus/CounterFan/report.mdmarkdown239 B
scripts/test/corpus/CounterFan/sany.outother48.4 KB
scripts/test/corpus/CounterFan/verdict-1.exitother3 B
scripts/test/corpus/CounterFan/verdict-1.outother2.4 KB
scripts/test/corpus/CounterFan/verdict-2.outother2.6 KB
scripts/test/corpus/CounterGuard/ChartRun.exitother3 B
scripts/test/corpus/CounterGuard/ChartRun.outother3.3 KB
scripts/test/corpus/CounterGuard/CounterGuard.cfgconfig66 B
scripts/test/corpus/CounterGuard/CounterGuard.tlaother192 B
scripts/test/corpus/CounterGuard/chart.mmdother63 B
scripts/test/corpus/CounterGuard/graph.dotother302 B
scripts/test/corpus/CounterGuard/report.mdmarkdown954 B
scripts/test/corpus/CounterGuard/sany.outother36.1 KB
scripts/test/corpus/CounterGuard/verdict-1.exitother3 B
scripts/test/corpus/CounterGuard/verdict-1.outother2.4 KB
scripts/test/corpus/CounterGuard/verdict-2.exitother3 B
scripts/test/corpus/CounterGuard/verdict-2.outother2.9 KB
scripts/test/corpus/CounterInitPast/ChartRun.outother2.5 KB
scripts/test/corpus/CounterInitPast/CounterInitPast.cfgconfig54 B
scripts/test/corpus/CounterInitPast/CounterInitPast.tlaother169 B
scripts/test/corpus/CounterInitPast/chart.mmdother282 B
scripts/test/corpus/CounterInitPast/graph.dotother84 B
scripts/test/corpus/CounterInitPast/report.mdmarkdown425 B
scripts/test/corpus/CounterInitPast/sany.outother35.3 KB
scripts/test/corpus/CounterInitPast/verdict-1.exitother3 B
scripts/test/corpus/CounterInitPast/verdict-1.outother1.3 KB
scripts/test/corpus/CounterInitPast/verdict-2.outother2.5 KB
scripts/test/corpus/CounterInitPastHolds/ChartRun.outother2.5 KB
scripts/test/corpus/CounterInitPastHolds/CounterInitPastHolds.cfgconfig50 B
scripts/test/corpus/CounterInitPastHolds/CounterInitPastHolds.tlaother171 B
scripts/test/corpus/CounterInitPastHolds/chart.mmdother16 B
scripts/test/corpus/CounterInitPastHolds/graph.dotother84 B
scripts/test/corpus/CounterInitPastHolds/report.mdmarkdown211 B
scripts/test/corpus/CounterInitPastHolds/sany.outother34.8 KB
scripts/test/corpus/CounterInitPastHolds/verdict-1.outother2.0 KB
scripts/test/corpus/CounterInstance/ChartRun.outother2.8 KB
scripts/test/corpus/CounterInstance/CounterInstance.cfgconfig41 B
scripts/test/corpus/CounterInstance/CounterInstance.tlaother217 B
scripts/test/corpus/CounterInstance/CounterSteps.tlaother113 B
scripts/test/corpus/CounterInstance/chart.mmdother326 B
scripts/test/corpus/CounterInstance/graph.dotother599 B
scripts/test/corpus/CounterInstance/report.mdmarkdown295 B
scripts/test/corpus/CounterInstance/sany.outother73.3 KB
scripts/test/corpus/CounterInstance/verdict-1.exitother3 B
scripts/test/corpus/CounterInstance/verdict-1.outother3.0 KB
scripts/test/corpus/CounterJump/ChartRun.outother2.7 KB
scripts/test/corpus/CounterJump/CounterJump.cfgconfig57 B
scripts/test/corpus/CounterJump/CounterJump.tlaother303 B
scripts/test/corpus/CounterJump/chart.mmdother547 B
scripts/test/corpus/CounterJump/graph.dotother1.0 KB
scripts/test/corpus/CounterJump/report.mdmarkdown374 B
scripts/test/corpus/CounterJump/sany.outother44.9 KB
scripts/test/corpus/CounterJump/verdict-1.exitother3 B
scripts/test/corpus/CounterJump/verdict-1.outother2.1 KB
scripts/test/corpus/CounterJump/verdict-2.outother2.6 KB
scripts/test/corpus/CounterLoop/ChartRun.outother2.6 KB
scripts/test/corpus/CounterLoop/CounterLoop.cfgconfig41 B
scripts/test/corpus/CounterLoop/CounterLoop.tlaother232 B
scripts/test/corpus/CounterLoop/chart.mmdother320 B
scripts/test/corpus/CounterLoop/graph.dotother593 B
scripts/test/corpus/CounterLoop/report.mdmarkdown285 B
scripts/test/corpus/CounterLoop/sany.outother41.5 KB
scripts/test/corpus/CounterLoop/verdict-1.exitother3 B
scripts/test/corpus/CounterLoop/verdict-1.outother2.8 KB
scripts/test/corpus/CounterOrder/ChartRun.outother2.7 KB
scripts/test/corpus/CounterOrder/CounterOrder.cfgconfig51 B
scripts/test/corpus/CounterOrder/CounterOrder.tlaother194 B
scripts/test/corpus/CounterOrder/chart.mmdother406 B
scripts/test/corpus/CounterOrder/graph.dotother299 B
scripts/test/corpus/CounterOrder/report.mdmarkdown606 B
scripts/test/corpus/CounterOrder/sany.outother39.0 KB
scripts/test/corpus/CounterOrder/verdict-1.exitother3 B
scripts/test/corpus/CounterOrder/verdict-1.outother2.1 KB
scripts/test/corpus/CounterOrder/verdict-2.exitother3 B
scripts/test/corpus/CounterOrder/verdict-2.outother2.7 KB
scripts/test/corpus/CounterRules/ChartRun.outother2.9 KB
scripts/test/corpus/CounterRules/CounterRules.cfgconfig79 B
scripts/test/corpus/CounterRules/CounterRules.tlaother265 B
scripts/test/corpus/CounterRules/Moves.tlaother70 B
scripts/test/corpus/CounterRules/chart.mmdother485 B
scripts/test/corpus/CounterRules/graph.dotother302 B
scripts/test/corpus/CounterRules/report.mdmarkdown509 B
scripts/test/corpus/CounterRules/sany.outother60.8 KB
scripts/test/corpus/CounterRules/verdict-1.exitother3 B
scripts/test/corpus/CounterRules/verdict-1.outother2.2 KB
scripts/test/corpus/CounterRules/verdict-2.exitother3 B
scripts/test/corpus/CounterRules/verdict-2.outother2.7 KB
scripts/test/corpus/CounterRules/verdict-3.exitother3 B
scripts/test/corpus/CounterRules/verdict-3.outother3.0 KB
scripts/test/corpus/CounterRules/verdict-4.outother2.8 KB
scripts/test/corpus/CounterStart/ChartRun.outother2.7 KB
scripts/test/corpus/CounterStart/CounterStart.cfgconfig53 B
scripts/test/corpus/CounterStart/CounterStart.tlaother180 B
scripts/test/corpus/CounterStart/chart.mmdother351 B
scripts/test/corpus/CounterStart/graph.dotother466 B
scripts/test/corpus/CounterStart/report.mdmarkdown343 B
scripts/test/corpus/CounterStart/sany.outother36.6 KB
scripts/test/corpus/CounterStart/verdict-1.exitother3 B
scripts/test/corpus/CounterStart/verdict-1.outother1.3 KB
scripts/test/corpus/CounterStart/verdict-2.outother2.6 KB
scripts/test/corpus/CounterStop/ChartRun.outother2.6 KB
scripts/test/corpus/CounterStop/CounterStop.cfgconfig53 B
scripts/test/corpus/CounterStop/CounterStop.tlaother172 B
scripts/test/corpus/CounterStop/chart.mmdother87 B
scripts/test/corpus/CounterStop/graph.dotother466 B
scripts/test/corpus/CounterStop/report.mdmarkdown127 B
scripts/test/corpus/CounterStop/sany.outother36.1 KB
scripts/test/corpus/CounterStop/verdict-1.outother2.2 KB
scripts/test/corpus/CounterTie/ChartRun.outother2.8 KB
scripts/test/corpus/CounterTie/CounterTie.cfgconfig96 B
scripts/test/corpus/CounterTie/CounterTie.tlaother263 B
scripts/test/corpus/CounterTie/chart.mmdother600 B
scripts/test/corpus/CounterTie/graph.dotother798 B
scripts/test/corpus/CounterTie/report.mdmarkdown675 B
scripts/test/corpus/CounterTie/sany.outother44.3 KB
scripts/test/corpus/CounterTie/verdict-1.exitother3 B
scripts/test/corpus/CounterTie/verdict-1.outother2.1 KB
scripts/test/corpus/CounterTie/verdict-2.exitother3 B
scripts/test/corpus/CounterTie/verdict-2.outother2.5 KB
scripts/test/corpus/CounterTie/verdict-3.exitother3 B
scripts/test/corpus/CounterTie/verdict-3.outother3.2 KB
scripts/test/corpus/CounterTie/verdict-4.outother2.6 KB
scripts/test/corpus/CounterTieInGraph/ChartRun.outother2.7 KB
scripts/test/corpus/CounterTieInGraph/CounterTieInGraph.cfgconfig72 B
scripts/test/corpus/CounterTieInGraph/CounterTieInGraph.tlaother283 B
scripts/test/corpus/CounterTieInGraph/chart.mmdother455 B
scripts/test/corpus/CounterTieInGraph/graph.dotother933 B

scripts/test/corpus.test.ts

View on GitHub
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { test } from "node:test";
import { fileURLToPath } from "node:url";
import { check, PINNED_FLAGS } from "../run.ts";

const here = path.dirname(fileURLToPath(import.meta.url));
const corpus = path.join(here, "corpus");
const skip = !process.env.TLA2TOOLS && "set TLA2TOOLS to the path of tla2tools.jar to run TLC";
const read = (file: string) => fs.readFileSync(file, "utf8");

for (const name of fs.readdirSync(corpus)) {
  test(`${name} gives the committed chart and report when TLC runs`, { skip }, () => {
    const dir = path.join(corpus, name);
    const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "statechart-corpus-"));
    const tlc = path.join(tmp, "tlc");
    const out = path.join(tmp, "out");
    fs.mkdirSync(tlc);
    const view = path.join(dir, "view.mjs");
    const r = spawnSync(
      process.execPath,
      [
        path.join(here, "../statechart.ts"),
        path.join(dir, `${name}.tla`),
        ...(fs.existsSync(view) ? ["--view", view] : []),
        "--out",
        out,
      ],
      {
        encoding: "utf8",
        env: {
          ...process.env,
          JAVA: path.join(here, "java.ts"),
          STATECHART_JAVA: process.env.JAVA ?? "java",
          STATECHART_RECORD: tlc,
        },
      },
    );
    assert.equal(r.stderr, "");
    if (process.env.STATECHART_UPDATE) {
      for (const f of fs.readdirSync(dir))
        if (/\.(out|exit|dot|mmd|md)$/.test(f)) fs.rmSync(path.join(dir, f));
      for (const f of fs.readdirSync(tlc)) fs.copyFileSync(path.join(tlc, f), path.join(dir, f));
      for (const f of ["chart.mmd", "report.md"])
        fs.copyFileSync(path.join(out, f), path.join(dir, f));
    }
    const report = read(path.join(out, "report.md"));
    const first = path.join(dir, "verdict-1.exit");
    const plain = fs.existsSync(first) ? Number(read(first)) : 0;
    assert.equal(r.status, plain === 0 ? 0 : [11, 12, 13].includes(plain) ? 1 : 2);
    assert.equal(report, read(path.join(dir, "report.md")));
    assert.equal(read(path.join(out, "chart.mmd")), read(path.join(dir, "chart.mmd")));
  });
}

test("a spec in a folder whose name is not ASCII checks under the POSIX locale", { skip }, () => {
  const dir = path.join(fs.mkdtempSync(path.join(os.tmpdir(), "statechart-corpus-")), "spec-é");
  fs.cpSync(path.join(corpus, "Login"), dir, { recursive: true });
  const out = path.join(dir, "out");
  const r = spawnSync(
    process.execPath,
    [
      path.join(here, "../statechart.ts"),
      path.join(dir, "Login.tla"),
      "--view",
      path.join(dir, "view.mjs"),
      "--out",
      out,
    ],
    { encoding: "utf8", env: { ...process.env, LC_ALL: "POSIX", LC_CTYPE: "", LANG: "" } },
  );
  assert.equal(r.stderr, "");
  assert.equal(r.status, 0);
  assert.equal(read(path.join(out, "chart.mmd")), read(path.join(corpus, "Login", "chart.mmd")));
});

test("an invariant named NoDeadlock and a deadlock break as two rules", { skip }, () => {
  const out = path.join(fs.mkdtempSync(path.join(os.tmpdir(), "statechart-corpus-")), "out");
  const r = spawnSync(
    process.execPath,
    [
      path.join(here, "../statechart.ts"),
      path.join(corpus, "UserNoDeadlock", "UserNoDeadlock.tla"),
      "--out",
      out,
    ],
    { encoding: "utf8" },
  );
  assert.equal(r.stderr, "");
  assert.equal(r.status, 1);
  const report = read(path.join(out, "report.md"));
  assert.match(
    report,
    /^## NoDeadlock breaks\nThe shortest path has 1 step:\n0\. 0\n1\. Next: 1$/m,
  );
  assert.match(
    report,
    /^## CHECK_DEADLOCK breaks\nThe shortest path has 3 steps:\n(.*\n){3}3\. Next: 3$/m,
  );
});

const writeSpec = (name: string, tla: string[], cfg: string) => {
  const base = path.join(fs.mkdtempSync(path.join(os.tmpdir(), "statechart-corpus-")), name);
  fs.writeFileSync(`${base}.tla`, `${tla.join("\n")}\n`);
  fs.writeFileSync(`${base}.cfg`, cfg);
  return base;
};
const login = path.join(corpus, "Login", "Login");
const broken = () =>
  writeSpec(
    "Broken",
    ["---- MODULE Broken ----", "VARIABLE x", "Init == x = 0", "Next == x' = y", "===="],
    "INIT Init\nNEXT Next\n",
  );

const plainTlc = (base: string) => {
  const name = path.basename(base);
  const r = spawnSync(
    process.env.JAVA ?? "java",
    [
      "-cp",
      String(process.env.TLA2TOOLS),
      "tlc2.TLC",
      ...PINNED_FLAGS,
      "-config",
      `${name}.cfg`,
      `${name}.tla`,
    ],
    { cwd: path.dirname(base), encoding: "utf8" },
  );
  return {
    exit: r.status === 0 ? 0 : [11, 12, 13].includes(r.status ?? -1) ? 1 : 2,
    rule: r.stdout.match(/^Error: Invariant (\w+) is violated\.$/m)?.[1],
    path: [...r.stdout.matchAll(/^State \d+: <(\w+) line/gm)].map((m) => m[1]),
  };
};

const counter = (name: string, before: string[], variables: string[]) => [
  ...before,
  `---- MODULE ${name} ----`,
  "EXTENDS Naturals",
  ...variables,
  "Init == x = 0",
  "Next == x < 2 /\\ x' = x + 1",
  "Spec == Init /\\ [][Next]_x",
  "Low == x < 2",
  "====",
];

for (const [input, name, tla] of [
  [
    "a `(*` inside a `\\*` comment",
    "Paren",
    [
      "---- MODULE Paren ----",
      "EXTENDS Naturals",
      "\\* The reader calls f(*) on each tick.",
      "VARIABLES x, y",
      "Init == x = 0 /\\ y = 0",
      "Tick == x < 2 /\\ x' = x + 1 /\\ UNCHANGED y",
      "Next == Tick",
      "Spec == Init /\\ [][Next]_<<x, y>>",
      "(* x never passes 1 *)",
      "Low == x < 2",
      "====",
    ],
  ],
  [
    "a nested block comment",
    "Nested",
    counter("Nested", [], ["(* outer (* inner *) VARIABLES ghost *)", "VARIABLE x"]),
  ],
  [
    'a "(*" string',
    "Str",
    [
      "---- MODULE Str ----",
      "EXTENDS Naturals",
      "VARIABLE x",
      'Open == "(*"',
      "VARIABLE y",
      'Close == "*)"',
      "Init == x = 0 /\\ y = 0",
      "Next == x < 2 /\\ x' = x + 1 /\\ UNCHANGED y",
      "Spec == Init /\\ [][Next]_<<x, y>>",
      "Low == x < 2",
      "====",
    ],
  ],
  [
    "text before the module header",
    "Pre",
    counter("Pre", ["Notes before the header: VARIABLES fake"], ["VARIABLE x"]),
  ],
] as const) {
  test(`a spec with ${input} gives plain TLC's exit and path`, { skip }, () => {
    const base = writeSpec(name, [...tla], "SPECIFICATION Spec\nINVARIANT Low\n");
    const tlc = plainTlc(base);
    assert.equal(tlc.rule, "Low");
    const out = path.join(path.dirname(base), "out");
    const r = spawnSync(
      process.execPath,
      [path.join(here, "../statechart.ts"), `${base}.tla`, "--out", out],
      { encoding: "utf8" },
    );
    assert.equal(r.stderr, "");
    assert.equal(r.status, tlc.exit);
    const steps = read(path.join(out, "report.md")).match(
      new RegExp(
        `^## ${tlc.rule} breaks\\nThe shortest path has \\d+ steps?:\\n0\\. .*\\n((?:\\d+\\. .*\\n?)*)`,
        "m",
      ),
    );
    assert.ok(steps, `the report has a path for ${tlc.rule}`);
    assert.deepEqual(
      [...steps[1].matchAll(/^\d+\. (\w+): /gm)].map((m) => m[1]),
      tlc.path,
    );
  });
}

test("a property that breaks on a loop draws the loop and reports it", { skip }, () => {
  const base = writeSpec(
    "Cycle",
    [
      "---- MODULE Cycle ----",
      "EXTENDS Integers",
      "VARIABLE x",
      "Init == x = 0",
      "Next == x' = (x + 1) % 3",
      "Spec == Init /\\ [][Next]_x /\\ WF_x(Next)",
      "Prop == <>(x = 5)",
      "====",
    ],
    "SPECIFICATION Spec\nPROPERTY Prop\n",
  );
  const out = path.join(path.dirname(base), "out");
  const r = spawnSync(
    process.execPath,
    [path.join(here, "../statechart.ts"), `${base}.tla`, "--out", out],
    { encoding: "utf8" },
  );
  assert.equal(r.stderr, "");
  assert.equal(r.status, 1);
  assert.match(
    read(path.join(out, "report.md")),
    /^## Prop breaks\nTLC's counterexample is in tlc-Prop\.out\. It has 3 steps:\n0\. 0\n1\. Next: 1\n2\. Next: 2\n3\. Next: 0\nThe run loops through "0", "1" and "2" forever\.$/m,
  );
  assert.equal(read(path.join(out, "chart.mmd")).match(/^ {2}class s\d+ repeats$/gm)?.length, 3);
});

test(
  "a property's loop comes from the whole state graph when TLC explores for over 3 seconds",
  { skip },
  () => {
    const base = writeSpec(
      "SlowLoop",
      [
        "---- MODULE SlowLoop ----",
        "EXTENDS Integers, TLC",
        "VARIABLE x",
        'Late(v) == IF \\E i \\in 1..2000000000 : TLCGet("duration") >= 6 THEN v ELSE v',
        "Init == x = 0",
        "Deep == x \\in 0..14 /\\ x' = IF x = 5 THEN Late(x + 1) ELSE x + 1",
        "Turn == x = 15 /\\ x' = 16",
        "Back == x = 16 /\\ x' = 15",
        "Leave == x = 0 /\\ x' = -1",
        "Return == x = -1 /\\ x' = 0",
        "Next == Deep \\/ Turn \\/ Back \\/ Leave \\/ Return",
        "Spec == Init /\\ [][Next]_x /\\ WF_x(Next)",
        "Prop == <>(x = 99)",
        "====",
      ],
      "SPECIFICATION Spec\nPROPERTY Prop\n",
    );
    const out = path.join(path.dirname(base), "out");
    const r = spawnSync(
      process.execPath,
      [path.join(here, "../statechart.ts"), `${base}.tla`, "--out", out],
      { encoding: "utf8" },
    );
    assert.equal(r.stderr, "");
    assert.equal(r.status, 1);
    assert.match(
      read(path.join(out, "report.md")),
      /^## Prop breaks\nTLC's counterexample is in tlc-Prop\.out\. It has 17 steps:\n0\. 0\n1\. Deep: 1\n(.*\n){14}16\. Turn: 16\n17\. Back: 15\nThe run loops through "15" and "16" forever\.$/m,
    );
  },
);

for (const [width, height, config, status, drawn, chart, header] of [
  [
    20,
    25,
    "INVARIANT Typed",
    0,
    true,
    true,
    "TLC reached 500 states and 955 steps. The chart draws 500 states and 955 arrows.",
  ],
  [
    3,
    167,
    "INVARIANT Typed",
    0,
    false,
    false,
    "TLC reached 501 states, more than the chart budget of 500, so the command wrote no chart.mmd.",
  ],
  [
    40,
    40,
    "INVARIANT Typed",
    0,
    false,
    false,
    "TLC reached 1,600 states, more than the chart budget of 500, so the command wrote no chart.mmd.",
  ],
  [
    40,
    40,
    "INVARIANT Near",
    1,
    true,
    true,
    "TLC reached more states than the chart budget of 500, so the chart draws only the bug paths: 4 states and 3 arrows.",
  ],
  [
    40,
    40,
    "INVARIANT Far",
    1,
    false,
    true,
    "TLC reached more states than the chart budget of 500, so the chart draws only the bug paths: 79 states and 78 arrows.",
  ],
] as const)
  test(
    `TLC keeps the chart within its budget of 500 states on a ${width} by ${height} grid with ${config}`,
    { skip },
    () => {
      const base = writeSpec(
        "Wide",
        [
          "---- MODULE Wide ----",
          "EXTENDS Naturals",
          "VARIABLES x, y",
          "Init == x = 0 /\\ y = 0",
          `IncX == x < ${width - 1} /\\ x' = x + 1 /\\ y' = y`,
          `IncY == y < ${height - 1} /\\ y' = y + 1 /\\ x' = x`,
          "Next == IncX \\/ IncY",
          "Typed == x \\in 0..39",
          "Near == ~(x = 2 /\\ y = 1)",
          `Far == ~(x = ${width - 1} /\\ y = ${height - 1})`,
          "====",
        ],
        `INIT Init\nNEXT Next\n${config}\nCHECK_DEADLOCK FALSE\n`,
      );
      const tlc = path.join(path.dirname(base), "tlc");
      const out = path.join(path.dirname(base), "out");
      fs.mkdirSync(tlc);
      const r = spawnSync(
        process.execPath,
        [path.join(here, "../statechart.ts"), `${base}.tla`, "--out", out],
        {
          encoding: "utf8",
          env: {
            ...process.env,
            JAVA: path.join(here, "java.ts"),
            STATECHART_JAVA: process.env.JAVA ?? "java",
            STATECHART_RECORD: tlc,
          },
        },
      );
      assert.equal(r.stderr, "");
      assert.equal(r.status, status);
      assert.equal(fs.existsSync(path.join(tlc, "ChartRun.out")), drawn);
      assert.equal(fs.existsSync(path.join(out, "chart.mmd")), chart);
      assert.equal(read(path.join(out, "report.md")).split("\n")[2], header);
    },
  );

for (const [what, tla, where] of [
  [
    "an unknown name",
    ["---- MODULE Broken ----", "VARIABLE x", "Init == x = 0", "Next == x' = y", "===="],
    /^line 4, col 14 to line 4, col 14 of module Broken\n+Unknown operator: `y'\.$/m,
  ],
  [
    "a parse error",
    ["---- MODULE Broken ----", "VARIABLE x", "Init == x = = 0", "Next == x' = x", "===="],
    /^Encountered "0" at line 3, column 15/m,
  ],
  [
    "twelve unknown names",
    [
      "---- MODULE Broken ----",
      "VARIABLE x",
      "Init == x = 0",
      ...Array.from({ length: 12 }, (_, i) => `D${i} == u${i}`),
      "Next == x' = x",
      "====",
    ],
    /^\*\*\* Errors: 12\n+line 4, col 7 to line 4, col 8 of module Broken\n+Unknown operator: `u0'\.$/m,
  ],
] as const)
  test(
    `a spec with ${what} gets SANY's line and column, not a Java stack trace`,
    { skip },
    async () => {
      const base = writeSpec("Broken", [...tla], "INIT Init\nNEXT Next\n");
      await assert.rejects(check(`${base}.tla`, `${base}.cfg`), (error: Error) => {
        assert.match(error.message, /^SANY could not read .*Broken\.tla \(exit 1\):\n/);
        assert.match(error.message, where);
        assert.doesNotMatch(error.message, /^\s+at tla2sany\./m);
        return true;
      });
    },
  );

test(
  "check() leaves no statechart- folder in the temp dir when it returns and when it throws",
  { skip },
  async () => {
    const base = broken();
    const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "statechart-corpus-"));
    const saved = process.env.TMPDIR;
    process.env.TMPDIR = tmp;
    try {
      await check(`${login}.tla`, `${login}.cfg`);
      await assert.rejects(check(`${base}.tla`, `${base}.cfg`), /SANY could not read/);
    } finally {
      if (saved === undefined) delete process.env.TMPDIR;
      else process.env.TMPDIR = saved;
    }
    assert.deepEqual(fs.readdirSync(tmp), []);
  },
);
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 192kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 192kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 192kUpdated Claude CodeCodexVerifiedInstall