Add JVM smoke tests, CI workflow, and TLA+ docs

This commit is contained in:
alex committed 2026-11-24 19:20:59 +00:00
1 parent 535d0d4b38
commit b3a04834e8
17 files changed
+421 -8

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
name: verify
on:
push:
pull_request:
jobs:
verify:
name: verify (Node 24, Java 11)
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Node.js 24
uses: actions/setup-node@v4
with:
node-version: "24"
- name: Set up Java 11
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "11"
- name: Install dependencies
run: npm ci
- name: Typecheck
run: npm run check
- name: Behavioral tests
run: npm test
- name: JVM smoke tests
run: npm run test:jvm
+13
View File
@@ -1,5 +1,18 @@
# Changelog
## [Unreleased]
### Fixed
- TLA+ Specification Check no longer reports SANY semantic errors as success when SANY exits 0; parse errors take precedence and semantic diagnostics are classified as failures.
- Auto-SANY no longer hides PlusCal translation or SANY timeouts as success.
- TLC results now distinguish deadlocks, invariant violations, temporal violations, specification errors, model-configuration errors, contradictions, and unexpected tool failures instead of labelling every `Error:` as a property violation.
- Java 11+ is enforced per TLA+ operation through a direct `java -version` probe, with no bash wrapper or global cache.
### Added
- Real JVM smoke tests (`npm run test:jvm`) against the vendored jar, plus a Gitea Actions verification workflow for Node 24 and Java 11.
## [1.0.0] - 2026-11-23
First release as a pi package (previously a loose extension at `~/.pi/agent/extensions/verify/`).
+22 -7
View File
@@ -13,7 +13,7 @@ pi install ./path/to/pi-verify # from a local path
> Not published to npm: the `pi-verify` name there belongs to an unrelated package.
Distribution is via the git sources above.
Requires Java 11+ for the TLA+ tools (the `tla2tools.jar` ships with the package):
The TLA+ tools require Java 11+ (the `tla2tools.jar` ships with the package). Every TLA+ operation probes `java -version` directly and reports missing, unsupported, or unparseable Java as a setup error; the probe is not cached across operations.
```bash
sudo apt-get install default-jre
@@ -25,10 +25,16 @@ Then `/reload` (or restart pi).
### Tools (callable by the agent)
- **`tla_check`** — SANY parse check for a `.tla` spec (fast; re-translates PlusCal algorithms).
- **`tlc`** — model-check a spec with TLC. Needs a `<Spec>.cfg` with the finite model (`INIT`, `NEXT`, `INVARIANT`s). Returns PASS with statistics or FAIL with the counterexample state trace.
- **`tla_check`** — TLA+ Specification Check with SANY: fast parse and basic semantic checks; re-translates PlusCal algorithms with `pcal.trans -nocfg`.
- **`tlc`** — TLA+ Model Check with TLC. Needs a `<Spec>.cfg` with the finite model (`INIT`, `NEXT`, `INVARIANT`s, `PROPERTY`, or `SPECIFICATION`). Reports pass, deadlock, invariant/temporal violation, specification error, model-config error, timeout/abort, or tool failure, with the trace or diagnostic.
- **`run_gates`** — run the project's gates from `.pi/verify.json`, per-gate pass/fail with output tails.
### Specification Check vs Model Check
`tla_check` runs SANY. A pass means SANY found no parse or semantic errors; it does not prove that a model satisfies its properties. Parse errors take precedence, semantic errors fail even when SANY exits 0, and PlusCal is re-translated whenever an algorithm is present (`-nocfg`, so the model config is never mutated).
`tlc` exhaustively checks the finite model in the `.cfg` and uses an isolated metadir per run, removed on every exit path, so parallel model checks cannot collide. Outcomes distinguish deadlocks, invariant violations, temporal violations, specification errors, model-config errors, timeouts/aborts, and unexpected tool failures instead of treating every `Error:` as a property violation. Set `ignore_deadlock` when terminal states are expected. A pass means TLC completed the search and found no error; it is only as meaningful as the model in the config.
### Hooks (deterministic enforcement)
- **Auto-SANY** (`tool_result`): every `edit`/`write` of a `*.tla` file is parsed immediately and the verdict is appended to the tool result, so parse errors land in the agent's context without it asking.
@@ -56,15 +62,16 @@ Then `/reload` (or restart pi).
- `on_settle: true` gates run automatically at agent-settle — they must be fast (seconds).
- `tla2toolsJar` — path to `tla2tools.jar`; relative resolves against the project root.
- `tlcTimeoutMs` — TLC timeout (default 300000); the `tlc` tool's `timeout_sec` param takes precedence when given.
- `tlcTimeoutMs` — TLC timeout in ms (default 300000); `timeout_sec` takes precedence when given and is clamped to 10–900 seconds.
### tla2tools.jar resolution order
1. `tla2toolsJar` in `.pi/verify.json`
2. `TLA2_TOOLS_JAR` env var
3. `vendor/tla2tools.jar` shipped inside this package
4. `~/.pi/agent/vendor/tla2tools.jar` (user-level; survives package updates)
5. `vendor/tla2tools.jar` and `tools/tla2tools.jar` in the project root
4. loose-layout `vendor/tla2tools.jar` beside the extension module
5. `~/.pi/agent/vendor/tla2tools.jar` (user-level; survives package updates)
6. `vendor/tla2tools.jar` and `tools/tla2tools.jar` in the project root
Without a jar, `tla_check`/`tlc` return setup instructions; everything else still works.
@@ -83,11 +90,19 @@ Enforcement belongs in the deterministic layer, never in prose: agents must iter
## Development
Development and CI use Node 24 (the test suites use Node's built-in `node:test`) and Java 11+ for the JVM smoke tests.
```bash
npm install # devDependencies for typechecking
npm ci # clean install from package-lock.json
npm run check # tsc --noEmit
npm test # behavioral tests; no Pi runtime or Java required
npm run test:jvm # real SANY/TLC smoke tests against vendor/tla2tools.jar; requires Java 11+
```
`npm test` covers the TLA+ module and Pi adapter with fake JVM adapters. `npm run test:jvm` copies mutable TLA+/PlusCal fixtures into temporary directories and exercises the production Node/JVM adapter against the vendored jar, including SANY parse/semantic failures, PlusCal re-translation with unchanged `.cfg`, TLC pass/violation/deadlock behavior, and parallel runs with isolated metadirs.
CI is defined in `.gitea/workflows/verify.yml` and runs `npm ci`, `npm run check`, `npm test`, and `npm run test:jvm` on Node 24 with Java 11. It requires a Gitea Actions runner carrying the workflow's `ubuntu-latest` label; the workflow file alone is not evidence of a passing run.
This repo dogfoods itself: `.pi/verify.json` runs the typecheck gate on settle.
Companion skills (kept separate, user-level): `verification-doctrine` and `tla-plus`.
+2 -1
View File
@@ -27,7 +27,8 @@
},
"scripts": {
"check": "tsc --noEmit",
"test": "node --test test/behavior/*.test.ts"
"test": "node --test test/behavior/*.test.ts",
"test:jvm": "node --test test/jvm/*.test.ts"
},
"peerDependencies": {
"@earendil-works/pi-coding-agent": "*",
+24
View File
@@ -157,6 +157,10 @@ test("existing tools and parameter schemas remain registered", async () => {
const tlaCheck = pi.tools.get("tla_check")!;
assert.deepEqual(Object.keys(tlaCheck.parameters.properties), ["spec"]);
assert.deepEqual(tlaCheck.parameters.required, ["spec"]);
assert.equal(
(tlaCheck.parameters.properties.spec as { type?: string }).type,
"string",
);
const tlc = pi.tools.get("tlc")!;
assert.deepEqual(Object.keys(tlc.parameters.properties).sort(), [
@@ -166,10 +170,30 @@ test("existing tools and parameter schemas remain registered", async () => {
"timeout_sec",
]);
assert.deepEqual(tlc.parameters.required, ["spec"]);
assert.equal(
(tlc.parameters.properties.spec as { type?: string }).type,
"string",
);
assert.equal(
(tlc.parameters.properties.cfg as { type?: string }).type,
"string",
);
assert.equal(
(tlc.parameters.properties.ignore_deadlock as { type?: string }).type,
"boolean",
);
assert.equal(
(tlc.parameters.properties.timeout_sec as { type?: string }).type,
"number",
);
const runGates = pi.tools.get("run_gates")!;
assert.deepEqual(Object.keys(runGates.parameters.properties), ["filter"]);
assert.equal(runGates.parameters.required, undefined);
assert.equal(
(runGates.parameters.properties.filter as { type?: string }).type,
"string",
);
} finally {
cleanup(root);
}
+1
View File
@@ -0,0 +1 @@
SPECIFICATION Spec
+8
View File
@@ -0,0 +1,8 @@
---- MODULE PlusCalCounter ----
EXTENDS Naturals
(* --algorithm Counter
variables x = 0;
begin
A: x := x + 1;
end algorithm; *)
====
+6
View File
@@ -0,0 +1,6 @@
---- MODULE SanyPass ----
EXTENDS Naturals
VARIABLE x
Init == x = 0
Next == x' = x + 1
====
+7
View File
@@ -0,0 +1,7 @@
---- MODULE SanySemanticError ----
EXTENDS Naturals
VARIABLE x
Init == x = 0
Next == x' = x + 1
Bad == x + true
====
+3
View File
@@ -0,0 +1,3 @@
---- MODULE SanySyntaxError ----
VARIABLE x ==
====
+2
View File
@@ -0,0 +1,2 @@
INIT Init
NEXT Next
+6
View File
@@ -0,0 +1,6 @@
---- MODULE TlcDeadlock ----
EXTENDS Naturals
VARIABLE x
Init == x = 0
Next == x < 2 /\ x' = x + 1
====
+3
View File
@@ -0,0 +1,3 @@
INIT Init
NEXT Next
INVARIANT Invariant
+7
View File
@@ -0,0 +1,7 @@
---- MODULE TlcInvariant ----
EXTENDS Naturals
VARIABLE x
Init == x = 0
Next == x' = (x + 1) % 3
Invariant == x < 2
====
+3
View File
@@ -0,0 +1,3 @@
INIT Init
NEXT Next
INVARIANT Invariant
+7
View File
@@ -0,0 +1,7 @@
---- MODULE TlcPass ----
EXTENDS Naturals
VARIABLE x
Init == x = 0
Next == x' = (x + 1) % 3
Invariant == x >= 0
====
+271
View File
@@ -0,0 +1,271 @@
import assert from "node:assert/strict";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import { test } from "node:test";
import { fileURLToPath } from "node:url";
import {
createNodeJvm,
createTlaVerification,
type Jvm,
type ModelOutcome,
type SpecificationOutcome,
type TlaSettings,
type TlaVerification,
} from "../../extensions/verify/tla.ts";
const JVM_FIXTURES = fileURLToPath(new URL("./fixtures/", import.meta.url));
const TLC_TIMEOUT_MS = 120_000;
function makeProject(...fixtures: string[]): string {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "pi-verify-jvm-"));
for (const fixture of fixtures) {
const target = path.join(root, fixture);
fs.mkdirSync(path.dirname(target), { recursive: true });
fs.copyFileSync(path.join(JVM_FIXTURES, fixture), target);
}
return root;
}
function cleanup(root: string): void {
fs.rmSync(root, { recursive: true, force: true });
}
function settings(root: string): TlaSettings {
// No configured jar: production must resolve the packaged vendor jar.
return {
root,
tlcTimeoutMs: TLC_TIMEOUT_MS,
allowProjectJars: false,
};
}
function createService(root: string, jvm?: Jvm): TlaVerification {
return createTlaVerification({
jvm,
env: {},
homeDir: path.join(root, "home"),
});
}
function expectStatus<K extends SpecificationOutcome["status"]>(
outcome: SpecificationOutcome,
status: K,
): Extract<SpecificationOutcome, { status: K }> {
assert.equal(outcome.status, status, JSON.stringify(outcome));
return outcome as Extract<SpecificationOutcome, { status: K }>;
}
function expectModelStatus<K extends ModelOutcome["status"]>(
outcome: ModelOutcome,
status: K,
): Extract<ModelOutcome, { status: K }> {
assert.equal(outcome.status, status, JSON.stringify(outcome));
return outcome as Extract<ModelOutcome, { status: K }>;
}
test("Specification Check passes a valid spec against the vendored jar", async (t) => {
const root = makeProject("SanyPass.tla");
t.after(() => cleanup(root));
const outcome = await createService(root).checkSpecification({
spec: "SanyPass.tla",
settings: settings(root),
});
const pass = expectStatus(outcome, "pass");
assert.equal(pass.exitCode, 0);
assert.equal(pass.plusCalTranslated, false);
assert.match(pass.evidence, /SANY2 Version/);
});
test("Specification Check reports a real SANY syntax error as parse-error", async (t) => {
const root = makeProject("SanySyntaxError.tla");
t.after(() => cleanup(root));
const outcome = expectStatus(
await createService(root).checkSpecification({
spec: "SanySyntaxError.tla",
settings: settings(root),
}),
"parse-error",
);
assert.match(outcome.evidence, /\*\*\*Parse Error\*\*\*/);
assert.match(outcome.evidence, /SanySyntaxError\.tla/);
});
test("Specification Check reports a real SANY semantic error despite exit code 0", async (t) => {
const root = makeProject("SanySemanticError.tla");
t.after(() => cleanup(root));
const outcome = expectStatus(
await createService(root).checkSpecification({
spec: "SanySemanticError.tla",
settings: settings(root),
}),
"semantic-error",
);
assert.equal(outcome.exitCode, 0);
assert.match(outcome.evidence, /Semantic errors:/);
assert.match(outcome.evidence, /Unknown operator/);
});
test("PlusCal is re-translated after an algorithm change without touching its cfg", async (t) => {
const root = makeProject("PlusCalCounter.tla", "PlusCalCounter.cfg");
t.after(() => cleanup(root));
const specPath = path.join(root, "PlusCalCounter.tla");
const cfgPath = path.join(root, "PlusCalCounter.cfg");
const cfgBefore = fs.readFileSync(cfgPath, "utf8");
const before = fs.readFileSync(specPath, "utf8");
assert.match(before, /--algorithm Counter/);
assert.doesNotMatch(before, /BEGIN TRANSLATION/);
const tla = createService(root);
const first = expectStatus(
await tla.checkSpecification({
spec: "PlusCalCounter.tla",
settings: settings(root),
}),
"pass",
);
assert.equal(first.plusCalTranslated, true);
const firstTranslation = fs.readFileSync(specPath, "utf8");
assert.match(firstTranslation, /BEGIN TRANSLATION/);
assert.match(firstTranslation, /x' = x \+ 1/);
assert.equal(fs.readFileSync(cfgPath, "utf8"), cfgBefore);
const changed = firstTranslation.replace("x := x + 1;", "x := x + 2;");
assert.notEqual(changed, firstTranslation);
fs.writeFileSync(specPath, changed);
const second = expectStatus(
await tla.checkSpecification({
spec: "PlusCalCounter.tla",
settings: settings(root),
}),
"pass",
);
assert.equal(second.plusCalTranslated, true);
const secondTranslation = fs.readFileSync(specPath, "utf8");
assert.match(secondTranslation, /x' = x \+ 2/);
assert.doesNotMatch(secondTranslation, /x' = x \+ 1/);
assert.equal(fs.readFileSync(cfgPath, "utf8"), cfgBefore);
expectModelStatus(
await tla.checkModel({
spec: "PlusCalCounter.tla",
settings: settings(root),
}),
"pass",
);
assert.equal(fs.readFileSync(cfgPath, "utf8"), cfgBefore);
});
test("Model Check passes a real TLC run against the vendored jar", async (t) => {
const root = makeProject("TlcPass.tla", "TlcPass.cfg");
t.after(() => cleanup(root));
const outcome = expectModelStatus(
await createService(root).checkModel({
spec: "TlcPass.tla",
settings: settings(root),
}),
"pass",
);
assert.equal(outcome.exitCode, 0);
assert.match(outcome.evidence, /Model checking completed\. No error has been found\./);
assert.match(outcome.evidence, /Finished in/);
});
test("Model Check reports a real invariant violation with a readable trace", async (t) => {
const root = makeProject("TlcInvariant.tla", "TlcInvariant.cfg");
t.after(() => cleanup(root));
const outcome = expectModelStatus(
await createService(root).checkModel({
spec: "TlcInvariant.tla",
settings: settings(root),
}),
"invariant-violation",
);
assert.equal(outcome.exitCode, 12);
assert.match(outcome.evidence, /Invariant Invariant is violated/);
assert.match(outcome.evidence, /State 1:/);
});
test("Model Check reports a real deadlock with a readable trace", async (t) => {
const root = makeProject("TlcDeadlock.tla", "TlcDeadlock.cfg");
t.after(() => cleanup(root));
const outcome = expectModelStatus(
await createService(root).checkModel({
spec: "TlcDeadlock.tla",
settings: settings(root),
}),
"deadlock",
);
assert.equal(outcome.exitCode, 11);
assert.match(outcome.evidence, /Deadlock reached/);
assert.match(outcome.evidence, /State 1:/);
});
test("Model Check passes a terminal model when deadlock checking is disabled", async (t) => {
const root = makeProject("TlcDeadlock.tla", "TlcDeadlock.cfg");
t.after(() => cleanup(root));
const outcome = expectModelStatus(
await createService(root).checkModel({
spec: "TlcDeadlock.tla",
settings: settings(root),
ignoreDeadlock: true,
}),
"pass",
);
assert.equal(outcome.exitCode, 0);
assert.match(outcome.evidence, /Model checking completed\. No error has been found\./);
});
test("parallel TLC runs get distinct metadirs and leave no metadir behind", async (t) => {
const root = makeProject("TlcPass.tla", "TlcPass.cfg");
t.after(() => cleanup(root));
const production = createNodeJvm();
const metadirs: string[] = [];
const recordingJvm: Jvm = {
probeJava: (cwd, signal) => production.probeJava(cwd, signal),
runJava: async (jar, args, cwd, timeoutMs, signal) => {
if (args[0] === "tlc2.TLC") {
const index = args.indexOf("-metadir");
assert.ok(index >= 0, `TLC run has no -metadir: ${args.join(" ")}`);
const metadir = args[index + 1];
assert.ok(
fs.existsSync(metadir),
`metadir must exist while TLC runs: ${metadir}`,
);
metadirs.push(metadir);
}
return production.runJava(jar, args, cwd, timeoutMs, signal);
},
};
const tla = createService(root, recordingJvm);
const outcomes = await Promise.all([
tla.checkModel({ spec: "TlcPass.tla", settings: settings(root) }),
tla.checkModel({ spec: "TlcPass.tla", settings: settings(root) }),
]);
assert.deepEqual(
outcomes.map((outcome) => outcome.status),
["pass", "pass"],
);
assert.equal(metadirs.length, 2);
assert.equal(new Set(metadirs).size, 2, "parallel runs shared a metadir");
for (const metadir of metadirs) {
assert.equal(fs.existsSync(metadir), false, `metadir leaked: ${metadir}`);
}
});