@antelopejs/tooling-configs 0.4.1 → 0.5.1

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.
Files changed (41) hide show
  1. package/README.md +68 -29
  2. package/dist/bin/api-diff.mjs +235 -37
  3. package/dist/bin/body-check.mjs +14 -11
  4. package/dist/bin/capture.mjs +173 -54
  5. package/dist/bin/check-size.mjs +1 -1
  6. package/dist/bin/checks.mjs +166 -11
  7. package/dist/bin/comment-proof.mjs +29 -7
  8. package/dist/bin/garden.mjs +8 -58
  9. package/dist/bin/lease.mjs +48 -11
  10. package/dist/bin/ratchet.mjs +48 -14
  11. package/dist/bin/suppressions.mjs +3 -3
  12. package/dist/bin/sync.mjs +199 -80
  13. package/dist/bin/verify.mjs +1163 -474
  14. package/dist/capture/index.d.mts +6 -1
  15. package/dist/capture/index.mjs +1 -1
  16. package/dist/{ci-workflow-37qJa9LX.mjs → ci-workflow-COJUT12b.mjs} +121 -1
  17. package/dist/eslint.d.mts +16 -3
  18. package/dist/eslint.mjs +21 -6
  19. package/dist/formal/index.d.mts +20 -4
  20. package/dist/formal/index.mjs +71 -19
  21. package/dist/{map-B23_WMGE.mjs → map-DRyYz_Fw.mjs} +20 -1
  22. package/dist/oxc/anti-slop/index.mjs +156 -421
  23. package/dist/oxc/guardrails/index.d.mts +1 -1
  24. package/dist/oxc/guardrails/index.mjs +789 -103
  25. package/dist/oxc/lint.d.mts +13 -15
  26. package/dist/oxc/lint.mjs +19 -29
  27. package/dist/{package-CqqBgE8Y.mjs → package-Dn7VTFUW.mjs} +71 -17
  28. package/dist/{proof-stamp-DDDC0J6l.mjs → proof-stamp-DLWpPwQE.mjs} +72 -10
  29. package/dist/{ratchet-Q-JXuZIX.mjs → ratchet-ClfblHNJ.mjs} +18 -15
  30. package/dist/require-safety-comment-for-type-assertion-mnb0CIxa.mjs +181 -0
  31. package/dist/{scenes-DZVXkcxS.mjs → scenes-d-VQ0LOm.mjs} +4 -1
  32. package/dist/semver-BDxeEcP_.mjs +57 -0
  33. package/dist/{suppression-base-9L8dlMQK.mjs → suppression-base-Drnl6Y7F.mjs} +2 -2
  34. package/dist/{suppression-budget-C0SkPO5R.mjs → suppression-budget-Dvb_IqBo.mjs} +1 -1
  35. package/dist/{suppressions-DM60NkvL.mjs → suppressions-BroaaGJ_.mjs} +1 -1
  36. package/dist/{templates-BKZv-BRw.mjs → templates-lJBZFskp.mjs} +8 -3
  37. package/dist/type-aware-rules-DMuN6sHb.mjs +30 -0
  38. package/dist/{typescript-DAgQIAAR.mjs → typescript-BBbry7uU.mjs} +123 -27
  39. package/dist/verify/index.d.mts +60 -15
  40. package/package.json +3 -1
  41. package/dist/require-safety-comment-for-type-assertion-BBQ669kj.mjs +0 -83
@@ -22,7 +22,9 @@ type CaptureStep = {
22
22
  /**
23
23
  * A scene as a `docs/captures.ts` declares it. A screenshot scene writes `output`, a `.webp` path
24
24
  * relative to the repository root. A setup scene (`setup: true`, such as the onboarding that
25
- * creates the administrator) runs its steps once, before any screenshot, and writes nothing.
25
+ * creates the administrator) runs its steps once, before any screenshot, and writes nothing. Each
26
+ * screenshot scene opens a fresh browser with the session the setup scenes left, or an empty one
27
+ * with `signedOut: true`.
26
28
  */
27
29
  interface CaptureSceneInput {
28
30
  id: string;
@@ -33,6 +35,8 @@ interface CaptureSceneInput {
33
35
  crop?: string;
34
36
  output?: string;
35
37
  setup?: boolean;
38
+ /** Opens the scene in a browser with no session, such as the sign-in page. */
39
+ signedOut?: boolean;
36
40
  }
37
41
  /** A scene with every default filled in. */
38
42
  interface CaptureScene {
@@ -43,6 +47,7 @@ interface CaptureScene {
43
47
  crop?: string;
44
48
  output?: string;
45
49
  setup: boolean;
50
+ signedOut: boolean;
46
51
  }
47
52
  /** Types the `docs/captures.ts` default export: `export default defineScenes([...])`. */
48
53
  declare function defineScenes(scenes: CaptureSceneInput[]): CaptureSceneInput[];
@@ -1,2 +1,2 @@
1
- import { t as defineScenes } from "../scenes-DZVXkcxS.mjs";
1
+ import { t as defineScenes } from "../scenes-d-VQ0LOm.mjs";
2
2
  export { defineScenes };
@@ -1,6 +1,6 @@
1
1
  import { existsSync, readFileSync, readdirSync } from "node:fs";
2
2
  import { join } from "node:path";
3
- import { Scalar, isMap, isPair, isScalar, isSeq, parseDocument, visit } from "yaml";
3
+ import { Scalar, isMap, isNode, isPair, isScalar, isSeq, parseDocument, visit } from "yaml";
4
4
  //#region src/guardrails/renovate.ts
5
5
  /** The Renovate config file sync writes when a repository has none. */
6
6
  const RENOVATE_PATH = "renovate.json";
@@ -221,6 +221,125 @@ function staleNeeds(document, path, removed = []) {
221
221
  return problems;
222
222
  }
223
223
  //#endregion
224
+ //#region src/guardrails/yaml-comments.ts
225
+ function sourceLines(source) {
226
+ const [first = "", ...rest] = source.split(/\r?\n/);
227
+ const hash = first.indexOf("#");
228
+ const below = rest.slice(0, -1).map((line) => {
229
+ const trimmed = line.trimStart();
230
+ return {
231
+ column: line.length - trimmed.length,
232
+ text: trimmed ? trimmed.replace(/^#/, "") : void 0
233
+ };
234
+ });
235
+ return {
236
+ inline: hash === -1 ? void 0 : first.slice(hash + 1),
237
+ below
238
+ };
239
+ }
240
+ /** Where the first comment matching `starts` begins, the blank lines before it included. */
241
+ function cut(lines, starts) {
242
+ let index = lines.findIndex(({ column, text }) => text !== void 0 && starts(column));
243
+ if (index === -1) return lines.length;
244
+ while (index > 0 && lines[index - 1].text === void 0) index -= 1;
245
+ return index;
246
+ }
247
+ function commentBlock(lines) {
248
+ const start = lines.findIndex(({ text }) => text !== void 0);
249
+ if (start === -1) return void 0;
250
+ let end = lines.length;
251
+ while (lines[end - 1].text === void 0) end -= 1;
252
+ return {
253
+ comment: lines.slice(start, end).map(({ text }) => text ?? "").join("\n"),
254
+ blankBefore: start > 0,
255
+ blankAfter: end < lines.length
256
+ };
257
+ }
258
+ function scalarKey(pair) {
259
+ if (isScalar(pair.key)) return pair.key;
260
+ if (isNode(pair.key)) return void 0;
261
+ const key = new Scalar(pair.key);
262
+ pair.key = key;
263
+ return key;
264
+ }
265
+ function followingKey(path) {
266
+ for (let index = path.length - 1; index > 0; index -= 2) {
267
+ const pair = path[index];
268
+ const map = path[index - 1];
269
+ if (!isPair(pair) || !isMap(map)) return void 0;
270
+ const next = map.items[map.items.indexOf(pair) + 1];
271
+ if (next) return scalarKey(next);
272
+ }
273
+ }
274
+ function withBlankAfter(block) {
275
+ return block.blankAfter ? `${block.comment}\n` : block.comment;
276
+ }
277
+ function placeBefore(key, block) {
278
+ if (key === void 0) return false;
279
+ key.commentBefore = [withBlankAfter(block), key.commentBefore].filter((comment) => comment !== void 0).join("\n");
280
+ key.spaceBefore = block.blankBefore || void 0;
281
+ return true;
282
+ }
283
+ function placeAfter(map, block) {
284
+ const comment = withBlankAfter(block);
285
+ map.comment = [map.comment, block.blankBefore ? `\n${comment}` : comment].filter((comment) => comment !== void 0).join("\n");
286
+ }
287
+ function columnOf(text, offset) {
288
+ return offset - (text.lastIndexOf("\n", offset - 1) + 1);
289
+ }
290
+ /**
291
+ * Splits the comment lines under a key into those indented under it, those at its column, which belong before the next
292
+ * key, and, when no key follows it in the source, those dedented past it, which belong to an enclosing map.
293
+ */
294
+ function partition(below, keyColumn, followedInSource) {
295
+ const shallow = cut(below, (column) => column <= keyColumn);
296
+ const dedented = followedInSource ? below.length : Math.max(cut(below, (column) => column < keyColumn), shallow);
297
+ return {
298
+ deep: commentBlock(below.slice(0, shallow)),
299
+ sibling: commentBlock(below.slice(shallow, dedented)),
300
+ outer: commentBlock(below.slice(dedented))
301
+ };
302
+ }
303
+ /** The comment lines `yaml` gave the empty value of the map's `index`th pair, read back from `text`. */
304
+ function emptyValueComments(map, index, text) {
305
+ const { key, value } = map.items[index];
306
+ if (!isScalar(value) || value.value !== null || value.comment === void 0) return void 0;
307
+ const keyStart = isScalar(key) ? key.range?.[0] : void 0;
308
+ const [, valueEnd, nodeEnd] = value.range ?? [];
309
+ if (keyStart === void 0 || valueEnd === void 0) return void 0;
310
+ const next = map.items.at(index + 1);
311
+ const nextKey = next && scalarKey(next);
312
+ const { inline, below } = sourceLines(text.slice(valueEnd, nextKey?.range?.[0] ?? nodeEnd));
313
+ return {
314
+ value,
315
+ nextKey,
316
+ inline,
317
+ ...partition(below, columnOf(text, keyStart), nextKey?.range != null)
318
+ };
319
+ }
320
+ function restorePair(map, index, path, text) {
321
+ const found = emptyValueComments(map, index, text);
322
+ if (!found || !found.sibling && !found.outer) return;
323
+ const { value, nextKey, inline, deep, sibling, outer } = found;
324
+ if (nextKey) nextKey.commentBefore = void 0;
325
+ value.spaceBefore = void 0;
326
+ value.comment = [inline, deep?.comment].filter((line) => line !== void 0).join("\n") || void 0;
327
+ if (sibling && !placeBefore(nextKey, sibling)) placeAfter(map, sibling);
328
+ if (outer && !placeBefore(followingKey(path), outer)) placeAfter(map, outer);
329
+ }
330
+ /**
331
+ * The `yaml` parser hands the first comment line under a key with an empty value, such as `workflow_dispatch:`, to that
332
+ * value as its trailing comment, so a rewrite prints it on the key's line and splits the comment block with a blank
333
+ * line. This reads the comment lines back from `text`, the source `document` was parsed from, and places them by
334
+ * column: lines indented under the key stay with its value, lines at the key's column go before the next key or, under
335
+ * a map's last key, after the map, and lines dedented past the key go before the next key of an enclosing map.
336
+ */
337
+ function restoreEmptyValueComments(document, text) {
338
+ visit(document, { Map(_key, map, path) {
339
+ for (const index of map.items.keys()) restorePair(map, index, path, text);
340
+ } });
341
+ }
342
+ //#endregion
224
343
  //#region src/guardrails/ci-workflow.ts
225
344
  const CI_PATH = ".github/workflows/ci.yml";
226
345
  /** The status context GitHub derives from the caller job id and the shared workflow's `checks` job. */
@@ -494,6 +613,7 @@ function ciWorkflow(current, callers, syncCallers, docsFiles, placeholderTests =
494
613
  const stale = staleNeeds(document, CI_PATH, removed);
495
614
  if (stale.length) throw new Error(stale.join("\n"));
496
615
  if (!changed) return current;
616
+ restoreEmptyValueComments(document, current);
497
617
  blockOverflowingFlow(document);
498
618
  return document.toString({
499
619
  lineWidth: 0,
package/dist/eslint.d.mts CHANGED
@@ -7,11 +7,24 @@ interface AntelopeNuxtConfigOptions {
7
7
  dirs?: string[];
8
8
  /** Rules layered on top of the shared set. */
9
9
  rules?: NuxtRules;
10
+ /**
11
+ * Runs the type-aware rules of the oxlint preset on `.vue` script blocks,
12
+ * which oxlint-tsgolint cannot read; TypeScript files stay with oxlint.
13
+ * `tsconfigRootDir` is the project root, usually `import.meta.dirname`.
14
+ * Each `.vue` file must be listed by its nearest `tsconfig.json`, or it
15
+ * fails to parse. Without Volar, a type imported from another `.vue` file
16
+ * is an error type, which the `no-unsafe-*` rules report, and a
17
+ * `lang="tsx"` block fails to parse.
18
+ */
19
+ typeAware?: {
20
+ tsconfigRootDir: string;
21
+ };
10
22
  }
11
23
  /**
12
- * The shared rules for a Nuxt layer. oxlint does not lint `.vue` files yet, so
13
- * the front end stays on ESLint, and `@nuxt/eslint` supplies the Vue and
14
- * TypeScript rules; this only records where AntelopeJS layers differ from it.
24
+ * The shared rules for a Nuxt layer. oxlint runs no Vue template rule and no
25
+ * type-aware rule on `.vue` files, so the front end stays on ESLint, and
26
+ * `@nuxt/eslint` supplies the Vue and TypeScript rules; this only records
27
+ * where AntelopeJS layers differ from it.
15
28
  *
16
29
  * Formatting rules are deliberately absent. oxfmt formats `.vue`, and a lint
17
30
  * rule that also reflows markup (`vue/max-attributes-per-line`, which eight
package/dist/eslint.mjs CHANGED
@@ -1,9 +1,11 @@
1
+ import { t as TYPE_AWARE_RULES } from "./type-aware-rules-DMuN6sHb.mjs";
1
2
  import { createConfigForNuxt } from "@nuxt/eslint-config/flat";
2
3
  //#region src/eslint.ts
3
4
  /**
4
- * The shared rules for a Nuxt layer. oxlint does not lint `.vue` files yet, so
5
- * the front end stays on ESLint, and `@nuxt/eslint` supplies the Vue and
6
- * TypeScript rules; this only records where AntelopeJS layers differ from it.
5
+ * The shared rules for a Nuxt layer. oxlint runs no Vue template rule and no
6
+ * type-aware rule on `.vue` files, so the front end stays on ESLint, and
7
+ * `@nuxt/eslint` supplies the Vue and TypeScript rules; this only records
8
+ * where AntelopeJS layers differ from it.
7
9
  *
8
10
  * Formatting rules are deliberately absent. oxfmt formats `.vue`, and a lint
9
11
  * rule that also reflows markup (`vue/max-attributes-per-line`, which eight
@@ -44,10 +46,23 @@ function antelopeNuxtConfig(options = {}) {
44
46
  ...ANTELOPE_NUXT_RULES,
45
47
  ...options.rules
46
48
  };
47
- return createConfigForNuxt({
48
- features: { tooling: true },
49
+ const composer = createConfigForNuxt({
50
+ features: options.typeAware === void 0 ? { tooling: true } : {
51
+ tooling: true,
52
+ typescript: true
53
+ },
49
54
  dirs: { src: options.dirs ?? [] }
50
- }).onResolved((configs) => configs.map((config) => {
55
+ });
56
+ if (options.typeAware !== void 0) composer.append({
57
+ name: "antelopejs/vue-type-aware",
58
+ files: ["**/*.vue"],
59
+ languageOptions: { parserOptions: {
60
+ projectService: true,
61
+ tsconfigRootDir: options.typeAware.tsconfigRootDir
62
+ } },
63
+ rules: Object.fromEntries(TYPE_AWARE_RULES.map((rule) => [`@typescript-eslint/${rule}`, "error"]))
64
+ });
65
+ return composer.onResolved((configs) => configs.map((config) => {
51
66
  if (config.rules === void 0) return config;
52
67
  const rules = { ...config.rules };
53
68
  for (const [name, original] of Object.entries(rules)) {
@@ -7,6 +7,8 @@ declare const EXIT: {
7
7
  };
8
8
  /** Each recorded finding: the invariant a spec breaks today, with the number of states in TLC's shortest counterexample. */
9
9
  type Findings = Readonly<Record<string, number>>;
10
+ /** Recorded findings with the number of distinct reachable states that break each one. */
11
+ type Violating = Readonly<Record<string, number>>;
10
12
  /** What {@link checkSpec} model-checks. */
11
13
  interface CheckSpecOptions {
12
14
  /** The folder holding `<spec>.tla`, the modules it extends and `<config>.cfg`. */
@@ -17,13 +19,26 @@ interface CheckSpecOptions {
17
19
  config?: string;
18
20
  /** The invariants of the configuration expected to break. */
19
21
  findings: Findings;
22
+ /**
23
+ * The violating-state count of some `findings`: the distinct states inside
24
+ * the model, where every `CONSTRAINT` holds, that break the rule. A finding
25
+ * without one is judged by its length alone, so a new path that breaks it
26
+ * in at least as many states goes unnoticed. A configuration with an
27
+ * `ACTION_CONSTRAINT` cannot be counted.
28
+ */
29
+ violating?: Violating;
20
30
  }
21
31
  /**
22
32
  * Model-checks `<dir>/<spec>.tla` with TLC under the constants, bounds and
23
33
  * invariants of `<dir>/<config>.cfg`. Every invariant must hold except the
24
34
  * `findings`, each of which must still break with a shortest counterexample
25
- * of exactly its recorded number of states. Prints one line per rule
26
- * (`holds`, `finding`, `BROKEN`, `CHANGED` or `HOLDS`) and exits the process
35
+ * of exactly its recorded number of states and, when `violating` names it,
36
+ * in exactly that many distinct reachable states, which a further one-worker
37
+ * run counts through a generated `AntelopeJSCount` module. The rules
38
+ * expected to hold are checked on every core; when one breaks, a one-worker
39
+ * rerun picks the rule and the shortest trace that `BROKEN` prints, so both
40
+ * are the same on every run. Prints one line per rule (`holds`, `finding`, `BROKEN`, `CHANGED` or `HOLDS`) and exits the
41
+ * process
27
42
  * with {@link EXIT}`.changed` when a rule differs from its record, or
28
43
  * {@link EXIT}`.tool` when TLC could not run; returns when everything
29
44
  * matches.
@@ -42,11 +57,12 @@ interface CheckSpecOptions {
42
57
  * SHA-256, the JVM options and TLC flags with `$JAVA_TOOL_OPTIONS`,
43
58
  * `$JDK_JAVA_OPTIONS` and `$_JAVA_OPTIONS`, the spec and configuration
44
59
  * names, the printed header, the bytes of every `.tla` file in `dir`, the
45
- * configuration and worker count of each TLC run, and `findings`. A replay keeps no TLC output
60
+ * module, configuration and worker count of each TLC run, `findings` and
61
+ * `violating`. A replay keeps no TLC output
46
62
  * folder. `ANTELOPEJS_FORMAL_CACHE=off` neither reads nor writes the cache.
47
63
  * Entries are never pruned; each is a few hundred bytes, one per distinct
48
64
  * input.
49
65
  */
50
66
  declare function checkSpec(options: CheckSpecOptions): Promise<void>;
51
67
  //#endregion
52
- export { CheckSpecOptions, EXIT, Findings, checkSpec };
68
+ export { CheckSpecOptions, EXIT, Findings, Violating, checkSpec };
@@ -18,6 +18,8 @@ const JVM_ENV = [
18
18
  "_JAVA_OPTIONS"
19
19
  ];
20
20
  const CACHE_ENV = "ANTELOPEJS_FORMAL_CACHE";
21
+ const COUNT_MODULE = "AntelopeJSCount";
22
+ const COUNT_MARK = "antelopejs-violating";
21
23
  /** Exit codes of a check: 0 when every rule matches its record, 1 when a rule changed, 2 when TLC could not run. */
22
24
  const EXIT = {
23
25
  ok: 0,
@@ -94,7 +96,8 @@ function readConfig(dir, config, findings) {
94
96
  const text = readFileSync(path.join(dir, `${config}.cfg`), "utf8");
95
97
  const constants = Array.from(text.matchAll(/^\s+(\w+)\s*=\s*(.+?)\s*$/gm), ([, name, value]) => ` ${name} = ${value}`);
96
98
  const invariants = Array.from(text.matchAll(/^INVARIANT\s+(\w+)/gm), ([, name]) => name);
97
- const bounds = Array.from(text.matchAll(/^(?:CONSTRAINT|ACTION_CONSTRAINT|SYMMETRY|VIEW)\s+\w+\s*$/gm), ([line]) => line.trim());
99
+ const bounds = Array.from(text.matchAll(/^\s*(?:(?:ACTION_)?CONSTRAINTS?|SYMMETRY|VIEW)\b.*$/gm), ([line]) => line.trim());
100
+ for (const line of bounds) if (!/^(?:CONSTRAINT|ACTION_CONSTRAINT|SYMMETRY|VIEW)[ \t]+\w+$/.test(line)) fail(`${config}.cfg: "${line}" is not one keyword and one name; write one CONSTRAINT, ACTION_CONSTRAINT, SYMMETRY or VIEW line per name`);
98
101
  for (const name of Object.keys(findings)) if (!invariants.includes(name)) fail(`finding ${name} is not an INVARIANT in ${config}.cfg`);
99
102
  return {
100
103
  constants,
@@ -118,8 +121,31 @@ function readModules(dir) {
118
121
  bytes: readFileSync(path.join(dir, name))
119
122
  }));
120
123
  }
124
+ /**
125
+ * A module whose `AntelopeJSCount_<rule>` invariants always hold and print
126
+ * {@link COUNT_MARK} once for each distinct reachable state that breaks
127
+ * `<rule>`. TLC also checks invariants on successors outside a `CONSTRAINT`,
128
+ * once per transition into them, so those states print nothing.
129
+ */
130
+ function countModule(spec, rules, config) {
131
+ const outside = config.bounds.flatMap((line) => {
132
+ const [kind, name] = line.split(/\s+/);
133
+ return kind === "CONSTRAINT" ? [`~${name} \\/ `] : [];
134
+ });
135
+ const text = [
136
+ `---- MODULE ${COUNT_MODULE} ----`,
137
+ `EXTENDS ${spec}, TLC`,
138
+ ...rules.map((rule) => `${COUNT_MODULE}_${rule} == ${outside.join("")}${rule} \\/ PrintT("${COUNT_MARK}")`),
139
+ "====",
140
+ ""
141
+ ].join("\n");
142
+ return {
143
+ name: `${COUNT_MODULE}.tla`,
144
+ bytes: Buffer.from(text)
145
+ };
146
+ }
121
147
  function runTlc(workspace, run) {
122
- const { jar, work, spec } = workspace;
148
+ const { jar, work } = workspace;
123
149
  const { name, workers } = run;
124
150
  const cfg = path.join(work, `${name}.cfg`);
125
151
  writeFileSync(cfg, run.cfg);
@@ -137,7 +163,7 @@ function runTlc(workspace, run) {
137
163
  ...TLC_FLAGS,
138
164
  "-metadir",
139
165
  path.join(work, `states-${name}`),
140
- `${spec}.tla`
166
+ `${run.module}.tla`
141
167
  ], {
142
168
  cwd: work,
143
169
  encoding: "utf8",
@@ -152,7 +178,8 @@ function runTlc(workspace, run) {
152
178
  return {
153
179
  violated,
154
180
  distinct,
155
- steps: Array.from(output.matchAll(/^State \d+: <(\w+)/gm), ([, action]) => action)
181
+ steps: Array.from(output.matchAll(/^State \d+: <(\w+)/gm), ([, action]) => action),
182
+ violating: output.match(new RegExp(`^"${COUNT_MARK}"$`, "gm"))?.length ?? 0
156
183
  };
157
184
  }
158
185
  function resultKey(plan) {
@@ -202,8 +229,7 @@ async function modelCheck(plan) {
202
229
  for (const { name, bytes } of modules) writeFileSync(path.join(work, name), bytes);
203
230
  const workspace = {
204
231
  jar,
205
- work,
206
- spec
232
+ work
207
233
  };
208
234
  const lines = [];
209
235
  const print = (line) => {
@@ -216,10 +242,15 @@ async function modelCheck(plan) {
216
242
  const held = runTlc(workspace, holds.run);
217
243
  if (held.violated) {
218
244
  changed = true;
219
- print(`BROKEN ${held.violated}: ${held.steps.join(" -> ")}`);
245
+ const shortest = runTlc(workspace, {
246
+ ...holds.run,
247
+ name: "holds-shortest",
248
+ workers: "1"
249
+ });
250
+ print(`BROKEN ${shortest.violated}: ${shortest.steps.join(" -> ")}`);
220
251
  } else print(`holds ${holds.rules.join(", ")} (${held.distinct} states)`);
221
252
  }
222
- for (const { rule, expected, run } of findings) {
253
+ for (const { rule, states, run, count } of findings) {
223
254
  const found = runTlc(workspace, run);
224
255
  if (!found.violated) {
225
256
  changed = true;
@@ -227,9 +258,11 @@ async function modelCheck(plan) {
227
258
  continue;
228
259
  }
229
260
  const length = found.steps.length;
230
- const tag = length === expected ? "finding" : "CHANGED";
231
- changed ||= length !== expected;
232
- print(`${tag} ${rule}: ${length} states (recorded ${expected}): ${found.steps.join(" -> ")}`);
261
+ const violating = count === void 0 ? void 0 : runTlc(workspace, count.run).violating;
262
+ const same = length === states && violating === count?.expected;
263
+ changed ||= !same;
264
+ const counted = count === void 0 ? "" : `, ${violating} violating (recorded ${count.expected})`;
265
+ print(`${same ? "finding" : "CHANGED"} ${rule}: ${length} states (recorded ${states})${counted}: ${found.steps.join(" -> ")}`);
233
266
  }
234
267
  if (!changed) print("Every rule matches the record in SKILL.md.");
235
268
  return {
@@ -242,8 +275,13 @@ async function modelCheck(plan) {
242
275
  * Model-checks `<dir>/<spec>.tla` with TLC under the constants, bounds and
243
276
  * invariants of `<dir>/<config>.cfg`. Every invariant must hold except the
244
277
  * `findings`, each of which must still break with a shortest counterexample
245
- * of exactly its recorded number of states. Prints one line per rule
246
- * (`holds`, `finding`, `BROKEN`, `CHANGED` or `HOLDS`) and exits the process
278
+ * of exactly its recorded number of states and, when `violating` names it,
279
+ * in exactly that many distinct reachable states, which a further one-worker
280
+ * run counts through a generated `AntelopeJSCount` module. The rules
281
+ * expected to hold are checked on every core; when one breaks, a one-worker
282
+ * rerun picks the rule and the shortest trace that `BROKEN` prints, so both
283
+ * are the same on every run. Prints one line per rule (`holds`, `finding`, `BROKEN`, `CHANGED` or `HOLDS`) and exits the
284
+ * process
247
285
  * with {@link EXIT}`.changed` when a rule differs from its record, or
248
286
  * {@link EXIT}`.tool` when TLC could not run; returns when everything
249
287
  * matches.
@@ -262,35 +300,49 @@ async function modelCheck(plan) {
262
300
  * SHA-256, the JVM options and TLC flags with `$JAVA_TOOL_OPTIONS`,
263
301
  * `$JDK_JAVA_OPTIONS` and `$_JAVA_OPTIONS`, the spec and configuration
264
302
  * names, the printed header, the bytes of every `.tla` file in `dir`, the
265
- * configuration and worker count of each TLC run, and `findings`. A replay keeps no TLC output
303
+ * module, configuration and worker count of each TLC run, `findings` and
304
+ * `violating`. A replay keeps no TLC output
266
305
  * folder. `ANTELOPEJS_FORMAL_CACHE=off` neither reads nor writes the cache.
267
306
  * Entries are never pruned; each is a few hundred bytes, one per distinct
268
307
  * input.
269
308
  */
270
309
  async function checkSpec(options) {
271
- const { dir, spec, config = spec, findings } = options;
310
+ const { dir, spec, config = spec, findings, violating = {} } = options;
272
311
  const parsed = readConfig(dir, config, findings);
312
+ for (const rule of Object.keys(violating)) if (!Object.hasOwn(findings, rule)) fail(`violating ${rule} is not a finding`);
313
+ if (Object.keys(violating).length > 0 && parsed.bounds.some((line) => line.startsWith("ACTION_CONSTRAINT"))) fail(`violating counts states outside an ACTION_CONSTRAINT; ${config}.cfg has one`);
273
314
  const holding = parsed.invariants.filter((rule) => !Object.hasOwn(findings, rule));
274
315
  const plan = {
275
316
  spec,
276
317
  header: `TLC ${TLC_VERSION} on ${spec}.tla (${config}.cfg) with ${parsed.constants.map((line) => line.trim()).join(", ")}`,
277
- modules: readModules(dir),
318
+ modules: [...readModules(dir), countModule(spec, Object.keys(violating), parsed)],
278
319
  holds: holding.length > 0 ? {
279
320
  rules: holding,
280
321
  run: {
281
322
  name: "holds",
323
+ module: spec,
282
324
  workers: "auto",
283
325
  cfg: cfgText(parsed, holding)
284
326
  }
285
327
  } : void 0,
286
- findings: Object.entries(findings).map(([rule, expected]) => ({
328
+ findings: Object.entries(findings).map(([rule, states]) => ({
287
329
  rule,
288
- expected,
330
+ states,
289
331
  run: {
290
332
  name: rule,
333
+ module: spec,
291
334
  workers: "1",
292
335
  cfg: cfgText(parsed, [rule])
293
- }
336
+ },
337
+ count: Object.hasOwn(violating, rule) ? {
338
+ expected: violating[rule],
339
+ run: {
340
+ name: `count-${rule}`,
341
+ module: COUNT_MODULE,
342
+ workers: "1",
343
+ cfg: cfgText(parsed, [`${COUNT_MODULE}_${rule}`])
344
+ }
345
+ } : void 0
294
346
  }))
295
347
  };
296
348
  const key = resultKey(plan);
@@ -109,6 +109,25 @@ function loadRun(dir) {
109
109
  all: stored.all === true
110
110
  };
111
111
  }
112
+ /**
113
+ * Loads the run at `dir` for a command that deletes in it, refusing any
114
+ * folder that is not one run this checkout created: the shared runs folder,
115
+ * a repository's folder of runs, a run of another checkout, and a run.json
116
+ * that names a folder other than `dir`. A refused run is not touched.
117
+ */
118
+ function ownRun(workspace, dir) {
119
+ const runs = join(RUNS_DIR, workspace.name);
120
+ const folder = canonical(dir);
121
+ if (dirname(folder) !== canonical(runs)) throw new Error(`${dir} is not one run of ${workspace.name}: pass the folder \`new\` printed, one level under ${runs}.`);
122
+ const file = stateFile(resolve(dir));
123
+ if (!existsSync(file)) throw new Error(`No run at ${dir}: run.json is missing. Create one with \`new\`.`);
124
+ const stored = object(parseJson(readFileSync(file, "utf8")), file);
125
+ const recordedDir = str(stored, "dir");
126
+ if (canonical(recordedDir) !== folder) throw new Error(`${file} records the folder ${recordedDir}, not ${dir}: it was copied from another run.`);
127
+ const repo = str(stored, "repo");
128
+ if (canonical(repo) !== canonical(workspace.root)) throw new Error(`${dir} was created by another checkout, ${repo}: only that checkout cleans it.`);
129
+ return loadRun(dir);
130
+ }
112
131
  /** Writes `text` to `file` through a sibling temporary file and one rename, so a reader in another process sees the old content or the new, never part of it. */
113
132
  function writeWhole(file, text) {
114
133
  const staging = `${file}.${randomBytes(6).toString("hex")}.tmp`;
@@ -494,4 +513,4 @@ function planFor(workspace, baseRef, all = false) {
494
513
  };
495
514
  }
496
515
  //#endregion
497
- export { removeTree as _, readFeatures as a, writeWhole as b, allocateRun as c, isolatedEnv as d, loadRun as f, recordProcesses as g, operatorTmpdir as h, planFor as i, commandRecords as l, operatorEnv as m, SMOKE_FEATURE as n, CACHE_DIR as o, openWorkspace as p, checkMap as r, RUNS_DIR as s, DEFAULT_SHARED as t, git as u, saveRun as v, matchesPath as x, withLocalBins as y };
516
+ export { matchesPath as S, recordProcesses as _, readFeatures as a, withLocalBins as b, allocateRun as c, isolatedEnv as d, loadRun as f, ownRun as g, operatorTmpdir as h, planFor as i, commandRecords as l, operatorEnv as m, SMOKE_FEATURE as n, CACHE_DIR as o, openWorkspace as p, checkMap as r, RUNS_DIR as s, DEFAULT_SHARED as t, git as u, removeTree as v, writeWhole as x, saveRun as y };