agent-formal-verify 0.4.9 → 0.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGES.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 0.4.10 - baselines keep each check's run and each Kani constraint's function
|
|
4
|
+
|
|
5
|
+
The specification baseline now records the checks that apply to each TLA+ run and the inputs selected by each reach check. Moving check lines below a run or changing which run a reach check selects no longer compares unchanged. Kani assumptions, covers and stubs now retain their qualified owning function, and harness names include their modules, so moving a constraint between functions is reported. The Rust reader supports free functions under inline modules and rejects Kani forms in an owner it cannot identify, including macro definitions and implementation or trait bodies. Baseline records use format 2; create a new record after updating rather than reuse a format 1 record.
|
|
6
|
+
|
|
3
7
|
## 0.4.9 - a specification baseline, Lean kernel replay and checked witnesses
|
|
4
8
|
|
|
5
9
|
The specification baseline now preserves whitespace and comment markers inside string literals, so edits to those parts of TLA+ properties and Kani assumptions are reported as changes. Lean kernel replay now selects exact modules and their project imports, leaving out cached objects from deleted, unimported descendants.
|
package/package.json
CHANGED
|
@@ -73,7 +73,7 @@ The helpers:
|
|
|
73
73
|
- The Lean checker, [`scripts/lean-check.sh`](scripts/lean-check.sh), builds every `.lean` file in the pinned Lake project and audits every declaration of every built module. It fails on a build error, a `sorry`, a declaration that rests on an axiom beyond `propext`, `Classical.choice` and `Quot.sound`, or a `.lean` file that no Lake library owns. It checks each `<Property>.witness` theorem against its property's hypotheses, and fails on a witness that states something else, as the [Lean brief](references/lean-brief.md) describes. It then replays every built module, and every project module it imports, through the Lean kernel with the pin's `leanchecker`, which rejects a declaration that a command added without a kernel check. A pin without `leanchecker`, such as Lean 4.20.0, passes with the replay reported as unavailable. Use `--freeze` before the file names to record statement types and definition bodies in each model's `.statements` file before proving it. Freezing permits `sorry` and reports FROZEN, not a proof PASS. Later checks enforce those records and permit proof changes and added declarations. Given file names after the project, it checks only those files. Copy [`examples/lean-template/Model/BoundedQueue.lean`](examples/lean-template/Model/BoundedQueue.lean) to start a model.
|
|
74
74
|
- The Rust checker, [`scripts/kani-check.sh`](scripts/kani-check.sh), runs the pinned Kani on the crate's proof harnesses. It reports each harness's unwind bound and check count, rejects failed checks and unsatisfied cover conditions, and prints concrete playback tests when available. Copy [`examples/kani-template/`](examples/kani-template/src/lib.rs) for a bounded-queue example.
|
|
75
75
|
- The mutation runner, [`scripts/mutate.py`](scripts/mutate.py), takes a model's `<Name>.mutations` file and applies each listed bug to a temporary copy of the model. It prints DETECTED or MISSED per mutation with what failed, UNCOVERED for a TLA+ property or Kani harness that no mutation targets or for a public theorem in a Lean model's `.statements` file whose proof no mutation makes fail, and a SUMMARY line. Lean names are fully qualified. A Lean DETECTED line means the existing proof fails; it does not establish that the statement is false or its hypotheses can hold. A Lean mutation that changes the statement of a theorem, example or `#guard`, such as renaming a definition that the statement names, reaches no verdict. A Lean model needs its `.statements` file before its mutations run. All three templates include a mutations file.
|
|
76
|
-
- The baseline helper, [`scripts/baseline.py`](scripts/baseline.py), records what each model specifies and later names each part that changed. For TLA+ it records
|
|
76
|
+
- The baseline helper, [`scripts/baseline.py`](scripts/baseline.py), records what each model specifies and later names each part that changed. For TLA+ it records each run's inputs and effective checks, each reach check's selected run and inputs, and the definitions of `Spec`, of the checked and reach operators, and of the operators those reference, including the initial state. It shares the matrix runner's execution plan, so a check applies only to the runs after it in its section. It does not follow `Spec` into the actions it names under `[][...]_vars`, `WF_` or `SF_`, because every correction of the transcription changes them. An operator that `Spec` names outside those, such as a fairness definition, is followed into its actions. A column-0 definition whose header it cannot read, such as an infix operator, is recorded whether or not a property references it, with the operators it references. For Lean it records the `.statements` file. For Kani it records each qualified harness name and each `kani::assume`, `kani::any_where`, `kani::cover!` and `#[kani::stub]` with its qualified owning function, including helper functions. The Rust reader supports free functions under inline modules; a Kani form in a macro, implementation or trait body, or another owner it cannot identify, fails the record. A spelling it cannot read, such as an import that renames `kani::assume`, also fails. It does not record a harness's assertions, input construction, surrounding guards or calls to assumption helpers; read `git diff` for those. Create a new record after updating the helper if it reports an unsupported record format.
|
|
77
77
|
|
|
78
78
|
Run every existing model's checker and mutations once, before any agent changes a model, and record the results. Then record what the models specify with `python3 <skill-dir>/scripts/baseline.py record <record-file> <model files>`, naming each existing `.matrix`, `.statements` and Kani harness file. Put `<record-file>` in a temporary directory outside the repository, and leave its path out of every brief. For a TLA+ or Lean model a pass shows only that the old description still holds; a Kani harness runs the code as it is now. A model that still describes the code needs no agent. When it passes, refresh its header as step 5 says; when it fails, take the failure through step 4. A Kani compile error means the harness no longer fits the code, so give it to an agent. An UNCOVERED line means the mutations file lacks a bug that the property detects, not that the code fails; give the model to an agent to add one. A check that passes here and fails after the update was passing on a stale description; say so in the reply.
|
|
79
79
|
|
|
@@ -151,7 +151,7 @@ Write the reply, and any pull request or document, for a reader who knows the co
|
|
|
151
151
|
| A bounded search passes | Every input up to the stated bound was tried. |
|
|
152
152
|
| Mutations detected | Deliberate bugs were planted in copies of the model, and the checks caught each one. For Lean, this shows that existing proofs fail, not that the mutated statements are false. |
|
|
153
153
|
| Past fix detected | The checks fail on the behaviour before a recorded bug fix. For Lean, report proof sensitivity separately from whether a checked counterexample establishes that the property rules out that bug. |
|
|
154
|
-
| Specification unchanged | The baseline comparison
|
|
154
|
+
| Specification unchanged | The baseline comparison preserved each recorded run's inputs and checks, reach check's selected inputs, property and fairness definition, statement record, qualified Kani harness name and function-owned assumption, cover and stub. It does not cover a Kani harness's assertions, input construction, surrounding guards or calls to assumption helpers; `git diff` does. |
|
|
155
155
|
| UNAVAILABLE | The tool could not run. This target was not checked; give the printed remedy. |
|
|
156
156
|
| reproduced | A deterministic test or race-detector run fails on the production code. |
|
|
157
157
|
| reachable at shipped settings | The shipped constants and callers permit the counter-example, but no production reproduction has confirmed it yet. |
|
|
@@ -9,11 +9,13 @@ change, and so is an added item whose kind narrows what is checked.
|
|
|
9
9
|
|
|
10
10
|
.statements Lean. The toolchain, and each declaration's kind, type hash and value hash.
|
|
11
11
|
Added declarations are allowed.
|
|
12
|
-
.matrix TLA+. Each
|
|
12
|
+
.matrix TLA+. Each run's effective checks and each reach check's selected inputs,
|
|
13
|
+
and the normalized definitions of Spec,
|
|
13
14
|
of each operator a check or reach line names, and of the operators those
|
|
14
15
|
reference, in the spec each section names. Spec is not followed into its actions.
|
|
15
|
-
.rs Kani. Each harness name, and each kani::assume, kani::any_where,
|
|
16
|
-
#[kani::stub]
|
|
16
|
+
.rs Kani. Each qualified harness name, and each kani::assume, kani::any_where,
|
|
17
|
+
kani::cover! and #[kani::stub] with its owning free function, under inline
|
|
18
|
+
modules. Unsupported owners fail. Added covers and harnesses are allowed.
|
|
17
19
|
Added assumes and stubs are changes.
|
|
18
20
|
|
|
19
21
|
Usage:
|
|
@@ -39,7 +41,7 @@ sys.dont_write_bytecode = True
|
|
|
39
41
|
import tlc
|
|
40
42
|
|
|
41
43
|
HERE = Path(__file__).resolve().parent
|
|
42
|
-
FORMAT =
|
|
44
|
+
FORMAT = 2
|
|
43
45
|
NARROWING = {"lean": (), "tla": (), "kani": ("assume", "stub")}
|
|
44
46
|
KINDS = {".statements": "lean", ".matrix": "tla", ".rs": "kani"}
|
|
45
47
|
STRING = re.compile(r'"(?:\\.|[^"\\])*"', re.DOTALL)
|
|
@@ -63,6 +65,7 @@ class Surface(dict):
|
|
|
63
65
|
count += 1
|
|
64
66
|
candidate = f"{name} #{count}"
|
|
65
67
|
self[candidate] = value
|
|
68
|
+
return candidate
|
|
66
69
|
|
|
67
70
|
|
|
68
71
|
def lean_surface(path):
|
|
@@ -158,27 +161,30 @@ def tla_closure(definitions, roots):
|
|
|
158
161
|
|
|
159
162
|
def tla_surface(path):
|
|
160
163
|
surface = Surface()
|
|
161
|
-
|
|
164
|
+
specs = {}
|
|
162
165
|
parsed = list(tlc.directives(tlc.read_raw(path).split("\n")))
|
|
163
|
-
|
|
164
|
-
if
|
|
165
|
-
|
|
166
|
+
tasks = list(tlc.execution_plan(parsed))
|
|
167
|
+
errors = ["; ".join(tlc.render(task)) for task in tasks if isinstance(task, tlc.Result)]
|
|
168
|
+
if errors:
|
|
169
|
+
raise ValueError(f"{path}: {'; '.join(errors)}")
|
|
166
170
|
for directive in parsed:
|
|
167
171
|
if isinstance(directive, tlc.Spec):
|
|
168
172
|
if not directive.path:
|
|
169
173
|
raise ValueError(f"{path}: spec line has no path")
|
|
170
174
|
surface.add(f"spec {directive.path}")
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
surface.add(f"reach {sections[-1][0]} {directive.operator} | {collapse(directive.match)}")
|
|
178
|
-
sections[-1][1].add(directive.operator)
|
|
175
|
+
specs.setdefault(directive.path, set())
|
|
176
|
+
for task in tasks:
|
|
177
|
+
if task.reach:
|
|
178
|
+
surface.add(f"reach {task.spec} {task.reach.operator} | {collapse(task.reach.match)}",
|
|
179
|
+
{"run": collapse(task.run.label), "constants": collapse(task.run.constants)})
|
|
180
|
+
specs[task.spec].add(task.reach.operator)
|
|
179
181
|
else:
|
|
180
|
-
surface.add(f"run {
|
|
181
|
-
|
|
182
|
+
run = surface.add(f"run {task.spec} {collapse(task.run.label)}", collapse(task.run.constants))
|
|
183
|
+
for check in task.checks:
|
|
184
|
+
for name in check.names:
|
|
185
|
+
surface.add(f"check {task.spec} {check.kind} {name} | [{run}]")
|
|
186
|
+
specs[task.spec].update(check.names)
|
|
187
|
+
for spec, operators in specs.items():
|
|
182
188
|
source = path.parent / spec
|
|
183
189
|
if not source.is_file():
|
|
184
190
|
raise ValueError(f"{path}: spec {spec} not found")
|
|
@@ -251,7 +257,7 @@ def rust_masks(source):
|
|
|
251
257
|
|
|
252
258
|
|
|
253
259
|
def after_closing(mask, opener):
|
|
254
|
-
closer = {"(": ")", "[": "]"}[mask[opener]]
|
|
260
|
+
closer = {"(": ")", "[": "]", "{": "}"}[mask[opener]]
|
|
255
261
|
depth = 0
|
|
256
262
|
for i in range(opener, len(mask)):
|
|
257
263
|
depth += (mask[i] == mask[opener]) - (mask[i] == closer)
|
|
@@ -260,6 +266,59 @@ def after_closing(mask, opener):
|
|
|
260
266
|
raise ValueError(f"unbalanced {mask[opener]} at offset {opener}")
|
|
261
267
|
|
|
262
268
|
|
|
269
|
+
class RustFunction(NamedTuple):
|
|
270
|
+
name: str
|
|
271
|
+
start: int
|
|
272
|
+
body: int
|
|
273
|
+
end: int
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
RUST_ITEM = re.compile(r"\b(fn|mod)\s+((?:r#)?\w+)\b")
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def rust_functions(mask):
|
|
280
|
+
"""Locate free functions under inline modules; leave macro and other item bodies opaque."""
|
|
281
|
+
functions, opaque, counts = [], [], {}
|
|
282
|
+
|
|
283
|
+
def walk(start, end, namespace=(), in_function=False):
|
|
284
|
+
i, boundary, item = start, start, None
|
|
285
|
+
while i < end:
|
|
286
|
+
if match := RUST_ITEM.match(mask, i):
|
|
287
|
+
item = (match[1], match[2])
|
|
288
|
+
i = match.end()
|
|
289
|
+
elif mask[i] in "([":
|
|
290
|
+
stop = after_closing(mask, i)
|
|
291
|
+
if mask[boundary:i].rstrip().endswith("!"):
|
|
292
|
+
opaque.append((i, stop))
|
|
293
|
+
i = stop
|
|
294
|
+
elif mask[i] == "{":
|
|
295
|
+
stop = after_closing(mask, i)
|
|
296
|
+
header = mask[boundary:i].rstrip()
|
|
297
|
+
macro = header.endswith("!") or bool(re.search(r"\bmacro_rules\s*!\s*\w+\s*$", header))
|
|
298
|
+
if item and not macro:
|
|
299
|
+
kind, name = item
|
|
300
|
+
qualified = (*namespace, name)
|
|
301
|
+
if kind == "fn":
|
|
302
|
+
owner = "::".join(qualified)
|
|
303
|
+
counts[owner] = counts.get(owner, 0) + 1
|
|
304
|
+
suffix = f"[{counts[owner]}]" if counts[owner] > 1 else ""
|
|
305
|
+
functions.append(RustFunction(owner + suffix, boundary, i, stop))
|
|
306
|
+
walk(i + 1, stop - 1, qualified, kind == "fn")
|
|
307
|
+
elif in_function and not macro and not re.search(r"\b(?:impl|trait|struct|enum|union|extern|macro)\b", header):
|
|
308
|
+
walk(i + 1, stop - 1, namespace, True)
|
|
309
|
+
else:
|
|
310
|
+
opaque.append((i, stop))
|
|
311
|
+
i = boundary = stop
|
|
312
|
+
item = None
|
|
313
|
+
else:
|
|
314
|
+
if mask[i] == ";":
|
|
315
|
+
boundary, item = i + 1, None
|
|
316
|
+
i += 1
|
|
317
|
+
|
|
318
|
+
walk(0, len(mask))
|
|
319
|
+
return functions, opaque
|
|
320
|
+
|
|
321
|
+
|
|
263
322
|
KANI_ATTRIBUTE = r"#\s*\[\s*(?:cfg_attr\s*\(\s*kani\s*,\s*)?kani\s*::\s*"
|
|
264
323
|
MACROS = (
|
|
265
324
|
("assume", re.compile(r"\bkani\s*::\s*assume\s*\(")),
|
|
@@ -268,7 +327,6 @@ MACROS = (
|
|
|
268
327
|
("stub", re.compile(KANI_ATTRIBUTE + r"stub\s*\(")),
|
|
269
328
|
)
|
|
270
329
|
PROOF = re.compile(KANI_ATTRIBUTE + r"proof(?:_for_contract\s*\([^)]*\))?\s*\)?\s*\]")
|
|
271
|
-
FUNCTION = re.compile(r"(?:pub(?:\s*\([^)]*\))?\s+)?(?:(?:async|unsafe|const)\s+)*fn\s+(\w+)")
|
|
272
330
|
KANI_TOKEN = re.compile(r"\bkani\s*::\s*(?:assume|any_where|cover|stub|proof)\w*\b")
|
|
273
331
|
RENAMING_IMPORT = re.compile(r"\buse\s+[^;]*?(?<![\w:])(?:::\s*)?kani\b[^;]*?(?:\bas\b|\*|\b(?:assume|any_where|cover|stub|proof)\w*\b)|\bextern\s+crate\s+kani\s+as\b")
|
|
274
332
|
|
|
@@ -278,6 +336,16 @@ def kani_surface(path):
|
|
|
278
336
|
text, mask = source.uncommented, source.without_comments_or_strings
|
|
279
337
|
if renaming := RENAMING_IMPORT.search(mask):
|
|
280
338
|
raise ValueError(f"{path}: '{collapse(renaming[0])}' brings a Kani assumption, cover, stub or harness attribute in under another name; write each as kani::<name> so the record can read it")
|
|
339
|
+
functions, opaque = rust_functions(mask)
|
|
340
|
+
|
|
341
|
+
def owner_at(position, *, attribute=False):
|
|
342
|
+
if not any(start <= position < end for start, end in opaque):
|
|
343
|
+
for function in reversed(functions):
|
|
344
|
+
if function.start <= position < function.end and (position < function.body if attribute else position > function.body):
|
|
345
|
+
return function.name
|
|
346
|
+
line = mask.count("\n", 0, position) + 1
|
|
347
|
+
raise ValueError(f"{path}:{line}: cannot identify a function owner; write Kani forms in free functions under inline modules, outside macro definitions and impl or trait bodies")
|
|
348
|
+
|
|
281
349
|
surface = Surface()
|
|
282
350
|
spans, read = [], []
|
|
283
351
|
for kind, pattern in MACROS:
|
|
@@ -285,26 +353,17 @@ def kani_surface(path):
|
|
|
285
353
|
end = after_closing(mask, match.end() - 1)
|
|
286
354
|
read.append((match.start(), end))
|
|
287
355
|
argument = rust_masks(text[match.end():end - 1])
|
|
288
|
-
|
|
356
|
+
owner = owner_at(match.start(), attribute=kind == "stub")
|
|
357
|
+
spans.append((match.start(), f"{kind} {collapse(argument.uncommented, argument.literals)} in {owner}"))
|
|
289
358
|
for match in PROOF.finditer(mask):
|
|
290
359
|
read.append(match.span())
|
|
291
|
-
|
|
292
|
-
while True:
|
|
293
|
-
i = len(mask) - len(mask[i:].lstrip())
|
|
294
|
-
if mask.startswith("#", i):
|
|
295
|
-
i = after_closing(mask, mask.index("[", i))
|
|
296
|
-
else:
|
|
297
|
-
break
|
|
298
|
-
name = FUNCTION.match(mask, i)
|
|
299
|
-
if not name:
|
|
300
|
-
raise ValueError(f"{path}: #[kani::proof] at offset {match.start()} is not followed by a function")
|
|
301
|
-
spans.append((match.start(), "harness", name[1]))
|
|
360
|
+
spans.append((match.start(), f"harness {owner_at(match.start(), attribute=True)}"))
|
|
302
361
|
for token in KANI_TOKEN.finditer(mask):
|
|
303
362
|
if not any(start <= token.start() < end for start, end in read):
|
|
304
363
|
line = mask.count("\n", 0, token.start()) + 1
|
|
305
364
|
raise ValueError(f"{path}:{line}: '{collapse(token[0])}' is in a form the record cannot read; write kani::assume(...), kani::any_where(...), kani::cover!(...), #[kani::stub(...)] or #[kani::proof], alone or under #[cfg_attr(kani, ...)]")
|
|
306
|
-
for _,
|
|
307
|
-
surface.add(
|
|
365
|
+
for _, item in sorted(spans):
|
|
366
|
+
surface.add(item)
|
|
308
367
|
return surface
|
|
309
368
|
|
|
310
369
|
|
|
@@ -319,7 +378,7 @@ def read_record(path):
|
|
|
319
378
|
record = json.loads(path.read_text(encoding="utf-8"))
|
|
320
379
|
models = record.get("models") if isinstance(record, dict) else None
|
|
321
380
|
if not isinstance(models, dict) or record.get("format") != FORMAT:
|
|
322
|
-
raise ValueError(f"{path}: unsupported record format")
|
|
381
|
+
raise ValueError(f"{path}: unsupported record format; run record with a new record file")
|
|
323
382
|
for model, entry in models.items():
|
|
324
383
|
if not isinstance(entry, dict) or entry.get("kind") not in SURFACES or not isinstance(entry.get("surface"), dict):
|
|
325
384
|
raise ValueError(f"{path}: malformed entry for {model}")
|
|
@@ -160,9 +160,8 @@ def check_tla(spec, checker, kinds, section, mutation, work):
|
|
|
160
160
|
checks = [d for d in section if isinstance(d, tlc.Reach) and f"reach:{d.operator}" == mutation.detects]
|
|
161
161
|
results = []
|
|
162
162
|
runner = tlc.Runner(checker, work, mutation.only, results.append, work)
|
|
163
|
-
for
|
|
164
|
-
runner.
|
|
165
|
-
runner.finish_spec()
|
|
163
|
+
for task in tlc.execution_plan([tlc.Spec(spec.name), *checks, *(d for d in section if isinstance(d, tlc.Run))]):
|
|
164
|
+
runner.check(task)
|
|
166
165
|
if runner.runs_total == 0:
|
|
167
166
|
return Result(Verdict.ERROR, f"no run matches '{mutation.only}'")
|
|
168
167
|
if not runner.failed:
|
|
@@ -22,6 +22,8 @@ Usage: tlc-matrix.sh <matrix-file> [label-substring]
|
|
|
22
22
|
JAVA=<path> the java binary (default: java on PATH)
|
|
23
23
|
TLC_WORKERS=<n> TLC worker threads (default auto)
|
|
24
24
|
"""
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
25
27
|
import os
|
|
26
28
|
import re
|
|
27
29
|
import subprocess
|
|
@@ -162,6 +164,42 @@ class Result:
|
|
|
162
164
|
lines: tuple = ()
|
|
163
165
|
|
|
164
166
|
|
|
167
|
+
@dataclass(frozen=True)
|
|
168
|
+
class Task:
|
|
169
|
+
spec: str
|
|
170
|
+
run: Run
|
|
171
|
+
checks: tuple = ()
|
|
172
|
+
reach: Reach | None = None
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
def execution_plan(directives):
|
|
176
|
+
"""Snapshot each run's effective checks and resolve each reach to its first matching run."""
|
|
177
|
+
spec, checks, reaches, runs = "", [], [], []
|
|
178
|
+
|
|
179
|
+
def reach_tasks():
|
|
180
|
+
for reach in reaches:
|
|
181
|
+
run = next((run for run in runs if reach.match in run.label), None)
|
|
182
|
+
if run is None:
|
|
183
|
+
yield Result(Outcome.NO_RUN, Path(spec).name.removesuffix(".tla"), operator=reach.operator, detail=reach.match)
|
|
184
|
+
else:
|
|
185
|
+
yield Task(spec, run, reach=reach)
|
|
186
|
+
|
|
187
|
+
for directive in directives:
|
|
188
|
+
if isinstance(directive, Spec):
|
|
189
|
+
yield from reach_tasks()
|
|
190
|
+
spec, checks, reaches, runs = directive.path, [], [], []
|
|
191
|
+
elif isinstance(directive, Check):
|
|
192
|
+
checks.append(directive)
|
|
193
|
+
elif isinstance(directive, Reach):
|
|
194
|
+
reaches.append(directive)
|
|
195
|
+
elif isinstance(directive, Run):
|
|
196
|
+
runs.append(directive)
|
|
197
|
+
yield Task(spec, directive, tuple(checks))
|
|
198
|
+
else:
|
|
199
|
+
yield Result(Outcome.MALFORMED, detail=directive.message)
|
|
200
|
+
yield from reach_tasks()
|
|
201
|
+
|
|
202
|
+
|
|
165
203
|
def render(result):
|
|
166
204
|
"""Return the lines the matrix runner prints for one result."""
|
|
167
205
|
name, label, operator = result.name, result.label, result.operator
|
|
@@ -192,56 +230,37 @@ class Runner:
|
|
|
192
230
|
|
|
193
231
|
def __init__(self, tlc, matrix_dir, only, emit, work):
|
|
194
232
|
self.tlc, self.matrix_dir, self.only, self.emit, self.work = tlc, matrix_dir, only, emit, work
|
|
195
|
-
self.spec, self.checks, self.reaches, self.runs = "", [], [], []
|
|
196
233
|
self.runs_total = self.passed = self.states = self.reach_total = self.reached = 0
|
|
197
234
|
self.failed = False
|
|
198
235
|
|
|
199
|
-
def feed(self, directive):
|
|
200
|
-
if isinstance(directive, Spec):
|
|
201
|
-
self.finish_spec()
|
|
202
|
-
self.spec, self.checks, self.reaches, self.runs = directive.path, [], [], []
|
|
203
|
-
elif isinstance(directive, Check):
|
|
204
|
-
self.checks.append(directive.line)
|
|
205
|
-
elif isinstance(directive, Reach):
|
|
206
|
-
self.reaches.append(directive)
|
|
207
|
-
elif isinstance(directive, Run):
|
|
208
|
-
self.runs.append(directive)
|
|
209
|
-
self.check_run(directive)
|
|
210
|
-
else:
|
|
211
|
-
self.report(Result(Outcome.MALFORMED, detail=directive.message))
|
|
212
|
-
|
|
213
|
-
def finish_spec(self):
|
|
214
|
-
"""Run each reach check of the current spec in the first run whose label contains its substring."""
|
|
215
|
-
for reach in self.reaches:
|
|
216
|
-
run = next((run for run in self.runs if reach.match in run.label), None)
|
|
217
|
-
if run is None:
|
|
218
|
-
self.reach_total += 1
|
|
219
|
-
self.report(Result(Outcome.NO_RUN, Path(self.spec).name.removesuffix(".tla"), operator=reach.operator, detail=reach.match))
|
|
220
|
-
else:
|
|
221
|
-
self.check_run(run, reach.operator)
|
|
222
|
-
|
|
223
236
|
def report(self, result):
|
|
224
237
|
self.failed |= result.outcome not in (Outcome.PASS, Outcome.WITNESS)
|
|
225
238
|
self.emit(result)
|
|
226
239
|
|
|
227
|
-
def
|
|
240
|
+
def check(self, task):
|
|
241
|
+
if isinstance(task, Result):
|
|
242
|
+
self.reach_total += task.outcome is Outcome.NO_RUN
|
|
243
|
+
self.report(task)
|
|
244
|
+
return
|
|
245
|
+
spec, run = task.spec, task.run
|
|
246
|
+
operator = task.reach.operator if task.reach else ""
|
|
228
247
|
if self.only not in run.label:
|
|
229
248
|
return
|
|
230
249
|
if operator:
|
|
231
250
|
self.reach_total += 1
|
|
232
251
|
else:
|
|
233
252
|
self.runs_total += 1
|
|
234
|
-
name = Path(
|
|
235
|
-
if not (self.matrix_dir /
|
|
236
|
-
self.report(Result(Outcome.MISSING, name, run.label, detail=
|
|
253
|
+
name = Path(spec).name.removesuffix(".tla")
|
|
254
|
+
if not (self.matrix_dir / spec).is_file():
|
|
255
|
+
self.report(Result(Outcome.MISSING, name, run.label, detail=spec))
|
|
237
256
|
return
|
|
238
257
|
directory = Path(tempfile.mkdtemp(prefix="run.", dir=self.work))
|
|
239
|
-
for module in (self.matrix_dir /
|
|
258
|
+
for module in (self.matrix_dir / spec).parent.glob("*.tla"):
|
|
240
259
|
(directory / module.name).write_bytes(module.read_bytes())
|
|
241
260
|
constants = "".join(f" {pair.split('=')[0]} = {pair.split('=', 1)[-1]}\n" for pair in run.constants.split())
|
|
242
261
|
config = f"CONSTANTS\n{constants}SPECIFICATION Spec\n"
|
|
243
262
|
if not operator:
|
|
244
|
-
status, log = self.tlc.run(directory, name, config + "\n".join(
|
|
263
|
+
status, log = self.tlc.run(directory, name, config + "\n".join(check.line for check in task.checks) + "\n", reach=False)
|
|
245
264
|
self.report(self.ordinary(name, run, status, log, directory / "tlc.log"))
|
|
246
265
|
return
|
|
247
266
|
wrapper = f"Reach{uuid.uuid4().hex}"
|
|
@@ -292,9 +311,8 @@ def main():
|
|
|
292
311
|
return 3
|
|
293
312
|
with tempfile.TemporaryDirectory() as work:
|
|
294
313
|
runner = Runner(tlc, Path(matrix).resolve().parent, only, lambda result: print("\n".join(render(result)), flush=True), Path(work))
|
|
295
|
-
for
|
|
296
|
-
runner.
|
|
297
|
-
runner.finish_spec()
|
|
314
|
+
for task in execution_plan(directives(read_raw(matrix).split("\n"))):
|
|
315
|
+
runner.check(task)
|
|
298
316
|
if runner.runs_total == 0:
|
|
299
317
|
matching = f"matching '{only}' " if only else ""
|
|
300
318
|
print(f"FAIL no run {matching}in {matrix}")
|