@sublang/spex 5.0.0 → 7.0.0-beta.2

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 (114) hide show
  1. package/README.md +453 -41
  2. package/dist/cli.js +12 -1
  3. package/dist/commands/add.d.ts +1 -1
  4. package/dist/commands/add.js +3 -3
  5. package/dist/commands/auth-target.d.ts +1 -0
  6. package/dist/commands/auth-target.js +4 -2
  7. package/dist/commands/environment.d.ts +15 -21
  8. package/dist/commands/environment.js +43 -57
  9. package/dist/commands/export.js +2 -2
  10. package/dist/commands/home.d.ts +2 -2
  11. package/dist/commands/home.js +3 -3
  12. package/dist/commands/list.js +1 -1
  13. package/dist/commands/login.js +12 -7
  14. package/dist/commands/logout.js +2 -3
  15. package/dist/commands/publish.js +16 -16
  16. package/dist/commands/remove.js +1 -1
  17. package/dist/commands/run.d.ts +1 -1
  18. package/dist/commands/run.js +22 -3
  19. package/dist/commands/search.js +1 -1
  20. package/dist/commands/settle.d.ts +1 -1
  21. package/dist/commands/settle.js +3 -3
  22. package/dist/commands/whoami.js +2 -6
  23. package/dist/guards/approval.d.ts +56 -0
  24. package/dist/guards/approval.js +158 -0
  25. package/dist/guards/checks.d.ts +207 -0
  26. package/dist/guards/checks.js +681 -0
  27. package/dist/guards/commands.d.ts +15 -0
  28. package/dist/guards/commands.js +313 -0
  29. package/dist/guards/copy.d.ts +67 -0
  30. package/dist/guards/copy.js +306 -0
  31. package/dist/guards/declaration.d.ts +45 -0
  32. package/dist/guards/declaration.js +224 -0
  33. package/dist/guards/files.d.ts +137 -0
  34. package/dist/guards/files.js +544 -0
  35. package/dist/guards/harness.d.ts +58 -0
  36. package/dist/guards/harness.js +420 -0
  37. package/dist/guards/items.d.ts +61 -0
  38. package/dist/guards/items.js +161 -0
  39. package/dist/guards/patch.d.ts +55 -0
  40. package/dist/guards/patch.js +258 -0
  41. package/dist/guards/processes.d.ts +49 -0
  42. package/dist/guards/processes.js +233 -0
  43. package/dist/guards/proofs.d.ts +88 -0
  44. package/dist/guards/proofs.js +503 -0
  45. package/dist/guards/records.d.ts +176 -0
  46. package/dist/guards/records.js +513 -0
  47. package/dist/guards/report.d.ts +26 -0
  48. package/dist/guards/report.js +492 -0
  49. package/dist/guards/runner.d.ts +42 -0
  50. package/dist/guards/runner.js +167 -0
  51. package/dist/guards/tla.d.ts +51 -0
  52. package/dist/guards/tla.js +352 -0
  53. package/dist/guards/tlapm.d.ts +81 -0
  54. package/dist/guards/tlapm.js +172 -0
  55. package/dist/guards/tlc.d.ts +191 -0
  56. package/dist/guards/tlc.js +457 -0
  57. package/dist/guards/translation.d.ts +66 -0
  58. package/dist/guards/translation.js +202 -0
  59. package/dist/guards/types.d.ts +185 -0
  60. package/dist/guards/types.js +437 -0
  61. package/dist/guards/verify.d.ts +290 -0
  62. package/dist/guards/verify.js +1191 -0
  63. package/dist/guards/xml.d.ts +18 -0
  64. package/dist/guards/xml.js +105 -0
  65. package/dist/lib/environment/archive.d.ts +16 -3
  66. package/dist/lib/environment/archive.js +39 -8
  67. package/dist/lib/environment/builtins.d.ts +10 -12
  68. package/dist/lib/environment/builtins.js +18 -20
  69. package/dist/lib/environment/exports.d.ts +14 -13
  70. package/dist/lib/environment/exports.js +31 -16
  71. package/dist/lib/environment/format.d.ts +2 -2
  72. package/dist/lib/environment/format.js +3 -3
  73. package/dist/lib/environment/git-source.js +6 -3
  74. package/dist/lib/environment/install.d.ts +14 -16
  75. package/dist/lib/environment/install.js +66 -61
  76. package/dist/lib/environment/lock.d.ts +4 -3
  77. package/dist/lib/environment/lock.js +6 -5
  78. package/dist/lib/environment/marker.js +1 -2
  79. package/dist/lib/environment/own-paths.d.ts +7 -10
  80. package/dist/lib/environment/own-paths.js +10 -13
  81. package/dist/lib/environment/placed-record.d.ts +3 -2
  82. package/dist/lib/environment/placed-record.js +5 -4
  83. package/dist/lib/environment/registries.d.ts +7 -9
  84. package/dist/lib/environment/registries.js +9 -36
  85. package/dist/lib/environment/registry.d.ts +6 -7
  86. package/dist/lib/environment/registry.js +12 -12
  87. package/dist/lib/environment/requests.d.ts +6 -5
  88. package/dist/lib/environment/requests.js +6 -8
  89. package/dist/lib/environment/resolve.d.ts +4 -4
  90. package/dist/lib/environment/resolve.js +3 -4
  91. package/dist/lib/environment/store.d.ts +34 -8
  92. package/dist/lib/environment/store.js +138 -43
  93. package/dist/lib/files.d.ts +72 -12
  94. package/dist/lib/files.js +200 -65
  95. package/dist/lib/git-host.d.ts +52 -258
  96. package/dist/lib/git-host.js +52 -265
  97. package/dist/lib/home-file.d.ts +13 -10
  98. package/dist/lib/home-file.js +28 -18
  99. package/dist/lib/instance.d.ts +1 -1
  100. package/dist/lib/instance.js +1 -1
  101. package/dist/lint.d.ts +22 -0
  102. package/dist/lint.js +36 -0
  103. package/dist/testing/standin-registry.js +1 -1
  104. package/package.json +7 -3
  105. package/scaffold/.file-history.json +14 -7
  106. package/scaffold/i18n/zh/source-pins.json +41 -0
  107. package/scaffold/i18n/zh/specs/decisions/000-spec-structure-format.md +0 -1
  108. package/scaffold/i18n/zh/specs/intents/000-spdx-headers.md +0 -1
  109. package/scaffold/i18n/zh/specs/map.md +0 -1
  110. package/scaffold/i18n/zh/specs/meta.md +18 -35
  111. package/scaffold/i18n/zh/specs/packages/git.md +0 -1
  112. package/scaffold/i18n/zh/specs/packages/licensing.md +0 -1
  113. package/scaffold/specs/meta.md +18 -3
  114. package/scripts/test-exit-guard.mjs +28 -0
@@ -0,0 +1,492 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // SPDX-FileCopyrightText: 2026 SubLang International <https://sublang.ai>
3
+ /*
4
+ * Guards package (guards-16, guards-26, guards-27), DR-252: every
5
+ * word `spex verify` and `spex approve` print. Reports go to standard
6
+ * output and a refusal's cause to standard error. Nothing else in the
7
+ * guards code prints.
8
+ */
9
+ import { misuse } from "../commands/run.js";
10
+ import { fileLabel, itemLabel } from "./approval.js";
11
+ import { seconds } from "./checks.js";
12
+ import { TLC_PIN } from "./tlc.js";
13
+ import { showFields, showValue } from "./types.js";
14
+ /** The widest a wrapped line may be. */
15
+ const WIDTH = 100;
16
+ /** Print lines on standard output. */
17
+ function out(lines) {
18
+ process.stdout.write(`${lines.join("\n")}\n`);
19
+ }
20
+ /** Print a refusal's cause on standard error. */
21
+ export function refuse(command, cause) {
22
+ process.stderr.write(`spex ${command}: ${cause}\n`);
23
+ }
24
+ /** Print a refusal of how a command was called: the cause and the
25
+ * command's usage line. */
26
+ export function refuseUse(command, cause) {
27
+ refuse(command, misuse(command, cause).message);
28
+ }
29
+ /** `text` in lines no wider than the limit, each after `indent`. */
30
+ function wrap(text, indent) {
31
+ const lines = [];
32
+ let line = "";
33
+ for (const word of text.split(/\s+/).filter((part) => part !== "")) {
34
+ if (line !== "" && indent.length + line.length + 1 + word.length > WIDTH) {
35
+ lines.push(indent + line);
36
+ line = word;
37
+ }
38
+ else {
39
+ line = line === "" ? word : `${line} ${word}`;
40
+ }
41
+ }
42
+ if (line !== "")
43
+ lines.push(indent + line);
44
+ return lines;
45
+ }
46
+ // ---------------------------------------------------------------
47
+ // Steps
48
+ // ---------------------------------------------------------------
49
+ /** `<count> <word>`, the word in the singular after a count of one:
50
+ * `1 state`, `2 states`. */
51
+ function counted(count, word) {
52
+ return `${count} ${count === 1 ? word : `${word}s`}`;
53
+ }
54
+ /** An event with its params: `use user=ann`. */
55
+ function callWords(call) {
56
+ return Object.keys(call.params).length === 0 ? call.event : `${call.event} ${showFields(call.params)}`;
57
+ }
58
+ /** One step: its number, its event, each param, then `->` and the
59
+ * effect, where one is shown and has a field. */
60
+ function stepLine(number, call, effect) {
61
+ return `${number}. ${callWords(call)}${effect === null || effect === "" ? "" : ` -> ${effect}`}`;
62
+ }
63
+ /** An effect on one line; `{}` for an effect with no field. */
64
+ function effectWords(effect) {
65
+ return effect === "" ? "{}" : effect;
66
+ }
67
+ /** The lines of a sequence, each step numbered from `from`, 1 where
68
+ * it is not given, with `note` under the last one, three spaces deeper
69
+ * than the step. */
70
+ function sequenceLines(steps, indent, note = [], from = 1) {
71
+ const lines = steps.map((step, index) => indent + stepLine(from + index, step.call, step.effect));
72
+ for (const line of note)
73
+ lines.push(`${indent} ${line}`);
74
+ return lines;
75
+ }
76
+ /** A finding's sequence: the records before it, the nearest under the
77
+ * count of the others, its own record, then the model's effect, the
78
+ * code's and what the rule says of it; where the model does not find
79
+ * the event legal, that, and the code's effect alone. */
80
+ function findingLines(found, indent, forbidden) {
81
+ const lines = found.earlier === 0 ? [] : [`${indent}(${counted(found.earlier, "earlier record")}, each matched)`];
82
+ const note = found.model === null
83
+ ? ["the model does not find the event legal here", `the code gave ${effectWords(found.gave)}`]
84
+ : [
85
+ `${found.by === null ? "the model" : `the model of translation ${found.by}`} gives ${effectWords(found.model)}`,
86
+ `the code gave ${effectWords(found.gave)}`,
87
+ forbidden ? "forbidden by the rule" : "not forbidden by the rule",
88
+ ];
89
+ return [...lines, ...sequenceLines([...found.steps, { call: found.last, effect: null }], indent, note, found.earlier + 1)];
90
+ }
91
+ /** A sequence the translations judge differently (guards-61): the
92
+ * records all matched, the record at which they part with the effect
93
+ * the code gave, and under it what each translation says of it. */
94
+ function disputeLines(shown, indent) {
95
+ const lines = shown.earlier === 0 ? [] : [`${indent}(${counted(shown.earlier, "earlier record")}, each matched)`];
96
+ const note = [
97
+ `the code gave ${effectWords(shown.gave)}`,
98
+ ...shown.answers.map((one) => {
99
+ if (one.said === "matched")
100
+ return `${one.translation}: the model's effect`;
101
+ if (one.said === "not legal")
102
+ return `${one.translation}: its model does not find the event legal here`;
103
+ const words = one.said === "forbidden" ? "forbidden by the rule" : "not the model's";
104
+ return `${one.translation}: ${words}, its model giving ${effectWords(one.model ?? "")}`;
105
+ }),
106
+ ];
107
+ return [...lines, ...sequenceLines([...shown.steps, { call: shown.last, effect: null }], indent, note, shown.earlier + 1)];
108
+ }
109
+ /** Where a finding was met: the number of its record in a sequence of
110
+ * the tests, or of its step in the sequence shown under it or in a
111
+ * permitted case the module caused. */
112
+ function metWords(found) {
113
+ if (found.sequence !== null)
114
+ return `at record ${found.at} of the sequence ${found.sequence}`;
115
+ const step = `at step ${found.at} of`;
116
+ return found.case === null ? `${step} this sequence` : `${step} the ${caseWords("permitted", found.case)}`;
117
+ }
118
+ // ---------------------------------------------------------------
119
+ // One guard's block (guards-26)
120
+ // ---------------------------------------------------------------
121
+ function approvalLines(name, approval) {
122
+ if (approval.approved)
123
+ return [" Approval: approved"];
124
+ const said = approval.unreadable ?? (approval.recorded ? changes(approval).join("; ") : "no approval record");
125
+ return [` Approval: not approved — ${said}`, ` review the guard's items and files, then run spex approve ${name}`];
126
+ }
127
+ /** `changed: …`, `added: …` and `gone: …`, each where it has a label. */
128
+ function changes(approval) {
129
+ const said = [];
130
+ if (approval.changed.length > 0)
131
+ said.push(`changed: ${approval.changed.join(", ")}`);
132
+ if (approval.added.length > 0)
133
+ said.push(`added: ${approval.added.join(", ")}`);
134
+ if (approval.gone.length > 0)
135
+ said.push(`gone: ${approval.gone.join(", ")}`);
136
+ return said;
137
+ }
138
+ /** A case by its kind and its label, the label in quotes so that its
139
+ * plain words do not read on into the line: `permitted case "…"`. */
140
+ function caseWords(kind, label) {
141
+ return `${kind === null ? "" : `${kind} `}case "${label}"`;
142
+ }
143
+ /** The check of cases without the code (guards-20): that every
144
+ * translation allows each permitted case and forbids each forbidden
145
+ * case, or each failure with its case, its translation and its step. */
146
+ function casesLines(report) {
147
+ const { cases } = report;
148
+ const opening = " Cases, without the code:";
149
+ const translations = cases.translations.length;
150
+ const stopped = report.causes.find((cause) => cause.kind === "stopped" && cause.cause.endsWith("the cases"));
151
+ if (stopped?.kind === "stopped")
152
+ return [`${opening} not checked — ${stopped.cause}`];
153
+ if (cases.failures.length === 0) {
154
+ const who = translations === 1 ? "the translation" : `each of ${translations} translations`;
155
+ return [
156
+ `${opening} ${who} allows the ${counted(cases.permitted, "permitted case")} and forbids the ${counted(cases.forbidden, "forbidden case")}`,
157
+ ];
158
+ }
159
+ return [
160
+ `${opening} ${counted(cases.count, "case")}, ${counted(translations, "translation")}, ${counted(cases.failures.length, "failure")}`,
161
+ ...cases.failures.map((failure) => failure.case === null
162
+ ? ` ${failure.found}`
163
+ : ` ${caseWords(failure.kind, failure.case)}, translation ${failure.translation}: ${failure.found}`),
164
+ ];
165
+ }
166
+ /** Under a distinguishing sequence: that it was not run on the code,
167
+ * and, where it has steps before the one asked about, what their
168
+ * effects are. Each answer to the question is a translation's own. */
169
+ function notRun(earlier) {
170
+ return earlier === 0
171
+ ? "not run on the code"
172
+ : "not run on the code: the effects of the earlier steps are the model's, on which the translations agree";
173
+ }
174
+ /** How the translations compare. A guard with one has nothing to
175
+ * compare it with. A difference is the distinguishing sequence and
176
+ * the one question its last step puts, with each translation's answer. */
177
+ function comparedLines(compared, names) {
178
+ const opening = ` Translations against each other: ${counted(names.length, "translation")}`;
179
+ if (compared === null)
180
+ return [`${opening}, nothing to compare it with`];
181
+ if (compared.kind === "agreement")
182
+ return [`${opening}, in agreement at every step TLC reached`];
183
+ if (compared.kind === "not compared")
184
+ return [`${opening}, not compared — ${compared.cause}`];
185
+ const last = compared.steps.length + 1;
186
+ const said = compared.answers.map((answer) => `${answer.translation}: ${answer.answer}`).join(", ");
187
+ const question = {
188
+ legal: [`is step ${last} legal? ${said}`],
189
+ applies: [`does the rule apply at step ${last}? ${said}`],
190
+ effect: [
191
+ `what must step ${last} give?`,
192
+ ...compared.answers.map((answer) => ` ${answer.translation}: ${effectWords(answer.answer)}`),
193
+ ],
194
+ // The model's effect at that step, on which the translations
195
+ // agree, tells whether the effect asked about is the model's.
196
+ forbidden: [
197
+ `is this effect forbidden at step ${last}? ${effectWords(compared.effect ?? "")}`,
198
+ ` ${said}`,
199
+ compared.model === compared.effect ? "the model gives this effect" : `the model gives ${effectWords(compared.model ?? "")}`,
200
+ ],
201
+ }[compared.about];
202
+ return [
203
+ `${opening}, they differ at step ${last} of this sequence`,
204
+ ...sequenceLines([...compared.steps, { call: compared.last, effect: null }], " ", [
205
+ ...question,
206
+ notRun(compared.steps.length),
207
+ ]),
208
+ ];
209
+ }
210
+ /** What TLC found on the model (guards-38). */
211
+ function modelLines(report) {
212
+ const { model } = report;
213
+ const tlc = `TLC ${report.versions.tlc ?? TLC_PIN.version}`;
214
+ const opening = " On the model:";
215
+ if (model === null)
216
+ return [];
217
+ if (model.kind === "not checked")
218
+ return [`${opening} not checked — ${model.cause}`];
219
+ if (model.kind === "conflict") {
220
+ return [
221
+ `${opening} Conflict in the items — ${tlc} found it at step ${model.steps.length + 1} of this sequence, as translation ${report.judging} reads the items`,
222
+ ...sequenceLines([...model.steps, { call: model.last, effect: null }], " ", [
223
+ `the model gives ${effectWords(model.effect)}`,
224
+ "forbidden by the rule",
225
+ ]),
226
+ ];
227
+ }
228
+ const lines = [
229
+ `${opening} ${tlc} checked every state the model of translation ${report.judging} reaches: ${counted(model.states, "state")}, ${counted(model.steps, "step")}; the rule applied at ${counted(model.applied, "step")}`,
230
+ ];
231
+ if (model.collision !== null) {
232
+ lines.push(` TLC's own estimate of the chance it missed a state: ${model.collision}`);
233
+ }
234
+ return lines;
235
+ }
236
+ /** And-joined names: `b`, `b and c`, `b, c and d`. */
237
+ function joined(names) {
238
+ return names.length <= 1 ? names.join("") : `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`;
239
+ }
240
+ /** How the proofs stand: accepted for any values, with what they
241
+ * prove, or why not. */
242
+ function proofsLines(report) {
243
+ const { proofs } = report;
244
+ const opening = " Proofs:";
245
+ if (proofs.kind === "not checked")
246
+ return [`${opening} not checked — ${proofs.cause}`];
247
+ if (proofs.kind === "not accepted")
248
+ return [`${opening} not accepted — ${proofs.reason}`];
249
+ const [first, ...others] = proofs.translations;
250
+ const system = `the proof system${report.versions.proof === null ? "" : ` ${report.versions.proof.version}`}`;
251
+ const what = others.length === 0
252
+ ? "the model keeps the rule"
253
+ : `each model keeps the rule and ${joined(others)} ${others.length === 1 ? "agrees" : "agree"} with ${first}`;
254
+ return [`${opening} accepted — ${system} proved, for any values, that ${what}`];
255
+ }
256
+ /** How many sequences the project's tests wrote, and how many are
257
+ * whole. */
258
+ function testsWords(tests) {
259
+ const opening = "the project's tests ran with the probes on:";
260
+ if (tests.sequences === 0)
261
+ return `${opening} no sequence of records`;
262
+ const whole = tests.whole === tests.sequences ? (tests.sequences === 1 ? "whole" : "each whole") : `${tests.whole} whole`;
263
+ return `${opening} ${counted(tests.sequences, "sequence")} of records, ${whole}`;
264
+ }
265
+ /** The records of a copy, as TLC judged them (guards-57). */
266
+ function countsLine(counts) {
267
+ const judged = counts.forbidden + counts.differs === 0
268
+ ? `${counts.matched} matched, ${counts.notJudged} not judged`
269
+ : `${counts.matched} matched, ${counts.forbidden} gave an effect the rule forbids, ${counts.differs} not the model's, ${counts.notJudged} not judged`;
270
+ const beyond = counts.beyond === 0 ? "" : `; ${counts.beyond} matched beyond the declared values`;
271
+ const by = counts.by === null ? "" : `, as translation ${counts.by} judges them`;
272
+ return ` ${counted(counts.records, "record")} in ${counted(counts.sequences, "sequence")}${by}: ${judged}; the rule applied at ${counts.applied}; they reached ${counts.reached} of the model's ${counted(counts.steps, "step")}${beyond}`;
273
+ }
274
+ /** What the tests on the copy found (guards-21, guards-22, guards-57). */
275
+ function codeLines(report) {
276
+ const { code } = report;
277
+ const opening = " On the code:";
278
+ if (code === null)
279
+ return [`${opening} not tested${report.notTested === null ? "" : ` — ${report.notTested}`}`];
280
+ const lines = [];
281
+ const their = code.cases === 1 ? "its" : "their";
282
+ if (code.kind === "probes") {
283
+ lines.push(`${opening} ${testsWords(code.tests ?? { sequences: 0, whole: 0 })}`);
284
+ if (code.cases > 0) {
285
+ lines.push(code.casesAsStated === code.cases
286
+ ? ` the ${counted(code.cases, "permitted case")} each opened a sequence and went as ${their} steps state`
287
+ : ` ${code.casesAsStated} of ${counted(code.cases, "permitted case")} opened a sequence and went as ${their} steps state`);
288
+ }
289
+ }
290
+ else {
291
+ const tested = code.tested === code.steps ? counted(code.steps, "step") : `${code.tested} of ${counted(code.steps, "step")}`;
292
+ const gave = code.same === code.tested
293
+ ? code.tested === 1
294
+ ? "it gave the model's effect"
295
+ : "each gave the model's effect"
296
+ : `${code.same} gave the model's effect, ${code.forbidden} an effect the rule forbids, ${code.differs} another effect, ${code.notReached} not reached${code.notJudged === 0 ? "" : `, ${code.notJudged} not judged`}`;
297
+ lines.push(code.tested === 0
298
+ ? `${opening} ${tested} tested`
299
+ : `${opening} ${tested} tested, ${code.tested === 1 ? "" : "each "}after a shortest sequence from a fresh start${code.counts.by === null ? "" : `, as translation ${code.counts.by} judges them`}: ${gave}`);
300
+ // The cases' line only where a case was caused: a binding that
301
+ // failed before any event shows nothing of how a case goes.
302
+ if (code.casesCaused > 0) {
303
+ lines.push(code.casesAsStated === code.cases
304
+ ? ` the ${counted(code.cases, "permitted case")} went as ${their} steps state`
305
+ : ` ${code.casesAsStated} of ${counted(code.cases, "permitted case")} went as ${their} steps state`);
306
+ }
307
+ if (code.tests !== null)
308
+ lines.push(` ${testsWords(code.tests)}`);
309
+ }
310
+ lines.push(countsLine(code.counts));
311
+ if (code.violation !== null) {
312
+ lines.push(` Violated on the code — found ${metWords(code.violation)}`, ...findingLines(code.violation, " ", true));
313
+ }
314
+ if (code.difference !== null) {
315
+ lines.push(` Code differs from the model — found ${metWords(code.difference)}`, ...findingLines(code.difference, " ", false));
316
+ }
317
+ for (const found of code.failed) {
318
+ lines.push(` Case failed — ${caseWords(null, found.case)}, step ${found.step}, field ${found.field}: stated ${showValue(found.stated)}, observed ${showValue(found.observed)}${found.sequence === null ? "" : `, in the sequence ${found.sequence}`}`);
319
+ }
320
+ return lines;
321
+ }
322
+ /** The lines under the result for what left the checks short. */
323
+ function causeLines(found) {
324
+ const indent = " ";
325
+ switch (found.kind) {
326
+ case "cases":
327
+ return [`${indent}the check of cases without the code failed`];
328
+ case "differ":
329
+ return [`${indent}the translations differ`];
330
+ case "not compared":
331
+ return [`${indent}the translations were not compared: ${found.cause}`];
332
+ case "stopped":
333
+ return [`${indent}a timeout: ${found.cause}`];
334
+ case "never applied":
335
+ return [`${indent}the rule applied at no step of the model`];
336
+ case "binding":
337
+ return [`${indent}a failing binding: ${found.cause}`];
338
+ case "outside":
339
+ return [`${indent}a project file loaded from outside the copy: ${found.file}`];
340
+ case "timeout":
341
+ return [`${indent}a timeout: not done after ${seconds(found.seconds)}`];
342
+ case "said":
343
+ return [`${indent}${found.text}`];
344
+ case "judged differently":
345
+ return [`${indent}${found.text}`, ...disputeLines(found.shown, `${indent} `)];
346
+ case "proofs":
347
+ return [`${indent}the proofs were not accepted: ${found.reason}`];
348
+ case "not repeated":
349
+ return [
350
+ `${indent}a sequence did not repeat: caused again, its last step gave another effect`,
351
+ ...sequenceLines([...found.steps, { call: found.last, effect: null }], `${indent} `, [
352
+ `first ${effectWords(found.gave)}`,
353
+ `again ${effectWords(found.other)}`,
354
+ ]),
355
+ ];
356
+ }
357
+ }
358
+ function resultLines(report) {
359
+ const lines = [` Result: ${report.result}`];
360
+ for (const found of report.causes)
361
+ lines.push(...causeLines(found));
362
+ // One assumption to a line, the later ones under the first.
363
+ report.assumes.forEach((assumed, at) => lines.push(` ${at === 0 ? "assumes:" : " "} ${assumed}`));
364
+ const { versions, limits } = report;
365
+ const tlc = versions.tlc === null
366
+ ? "TLC not run"
367
+ : `TLC ${versions.tlc} (${versions.pinned ? "the pinned copy" : "not the pinned copy"})`;
368
+ // A proof system a variable names is used as it is: the line says
369
+ // which variable named it.
370
+ const proof = versions.proof === null
371
+ ? "no proof system"
372
+ : `the proof system ${versions.proof.version} (${versions.proof.pinned ? "the pinned copy" : (versions.proof.variable ?? "not the pinned copy")})`;
373
+ lines.push(` Spex ${versions.spex}, Node ${versions.node}, ${tlc}, ${proof}, Java ${versions.java}`);
374
+ // The solvers answer for the proofs and no tool checks them again:
375
+ // the result names each as the proof system does.
376
+ if (versions.proof !== null) {
377
+ const { solvers } = versions.proof;
378
+ lines.push(` its solvers: ${solvers.length === 0 ? "it names none" : solvers.join(", ")}`);
379
+ }
380
+ lines.push(report.digest === null
381
+ ? ` ${report.revision}, no files copied`
382
+ : ` ${report.revision}, copied files sha256 ${report.digest.slice(0, 12)}`);
383
+ lines.push(` limits: ${seconds(limits.seconds)} for each run of a tool and each command`);
384
+ return lines;
385
+ }
386
+ function faultLines(report) {
387
+ const lines = [];
388
+ for (const fault of report.faults) {
389
+ if (fault.caught === null) {
390
+ lines.push(` Kept fault ${fault.name}: not ${fault.tried ? "caught" : "tried"} — ${fault.reason}`);
391
+ if (fault.dispute != null)
392
+ lines.push(...disputeLines(fault.dispute, " "));
393
+ continue;
394
+ }
395
+ lines.push(` Kept fault ${fault.name}: caught ${metWords(fault.caught)}`);
396
+ lines.push(...findingLines(fault.caught, " ", true));
397
+ }
398
+ return lines;
399
+ }
400
+ /** Why a guard cannot be checked: each cause, and under it where TLC
401
+ * met it. */
402
+ function cannotLines(cannot) {
403
+ const lines = [];
404
+ for (const one of cannot) {
405
+ lines.push(` Cannot be checked — ${one.cause}`);
406
+ if (one.note !== null)
407
+ lines.push(` ${one.note}`);
408
+ lines.push(...sequenceLines(one.steps, " "));
409
+ }
410
+ return lines;
411
+ }
412
+ /** One guard's block. */
413
+ function blockLines(report) {
414
+ if ("cannot" in report)
415
+ return [report.name, ...cannotLines(report.cannot)];
416
+ return [
417
+ `${report.name} — checks the rule ${report.behavior}:`,
418
+ ...wrap(report.statement, " "),
419
+ ...approvalLines(report.name, report.approval),
420
+ ...casesLines(report),
421
+ ...comparedLines(report.compared, report.cases.translations),
422
+ ...modelLines(report),
423
+ ...proofsLines(report),
424
+ ...codeLines(report),
425
+ ...resultLines(report),
426
+ ...faultLines(report),
427
+ report.reasons.length === 0 ? " Passes" : ` Does not pass — ${report.reasons.join("; ")}`,
428
+ ];
429
+ }
430
+ // ---------------------------------------------------------------
431
+ // `spex verify`
432
+ // ---------------------------------------------------------------
433
+ /** There is nothing to check. */
434
+ export function sayNoGuards() {
435
+ out(["No guards under guards/."]);
436
+ }
437
+ /** The report's heading. */
438
+ export function sayHeading() {
439
+ out(["Protect critical behavior on every change"]);
440
+ }
441
+ /** One guard's block, after a blank line. */
442
+ export function sayGuard(report) {
443
+ out(["", ...blockLines(report)]);
444
+ }
445
+ /** How many guards pass, after a blank line. */
446
+ export function sayCount(passing, checked) {
447
+ out(["", `${passing} of ${checked} guards pass.`]);
448
+ }
449
+ /** Print what a person is approving, and that it is recorded: the
450
+ * guard item's statement, the rule's, then each case in the item's
451
+ * order, its plain words above its steps, then the label of every
452
+ * other input the record holds. `written` says the record's file was
453
+ * written anew; it stands as it was where its bytes were these
454
+ * already. */
455
+ export function sayApproved(guard, since, path, written) {
456
+ const { items } = guard;
457
+ const lines = [
458
+ `${guard.name} \u2014 the guard item:`,
459
+ ...wrap(items.guard.statement, " "),
460
+ "",
461
+ `${items.behavior.id} \u2014 the rule:`,
462
+ ...wrap(items.behavior.statement, " "),
463
+ ];
464
+ for (const entry of guard.cases) {
465
+ lines.push("", `${entry.kind} \u2014 ${entry.label}`, ...wrap(entry.words, " "));
466
+ entry.steps.forEach((step, at) => {
467
+ const stated = step.effect;
468
+ lines.push(` ${stepLine(at + 1, { event: step.event, params: step.params }, showFields(stated))}`);
469
+ });
470
+ }
471
+ // The record holds more than is printed above: every other input,
472
+ // by the label it is recorded under.
473
+ const shown = new Set([itemLabel(items.guard.id), itemLabel(items.behavior.id), fileLabel(`${guard.folder}/guard.yaml`)]);
474
+ const others = Object.keys(guard.inputs).filter((label) => !shown.has(label));
475
+ if (others.length > 0)
476
+ lines.push("", "Also recorded, not printed here:", ...others.map((label) => ` ${label}`));
477
+ lines.push("");
478
+ if (since === null)
479
+ lines.push("First approval.");
480
+ else if (typeof since === "string")
481
+ lines.push(`The last record cannot be read \u2014 ${since}.`);
482
+ else if (!since.approved)
483
+ lines.push("Since the last approval:", ...changes(since).map((line) => ` ${line}`));
484
+ else if (written)
485
+ lines.push("Nothing changed since the last approval.");
486
+ else
487
+ lines.push(`Nothing changed since the last approval: ${path} stands as it was.`);
488
+ if (written)
489
+ lines.push(`Approved ${guard.name} \u2014 commit ${path}.`);
490
+ out(lines);
491
+ }
492
+ //# sourceMappingURL=report.js.map
@@ -0,0 +1,42 @@
1
+ import { type Call, type EventDeclaration, type Fields } from "./types.js";
2
+ /** What the parent hands one copy's process. Everything in it was
3
+ * loaded and checked by the parent, so the process reads no guard
4
+ * file of its own. */
5
+ export type Job = {
6
+ /** The project's root, as a real path. */
7
+ root: string;
8
+ /** The copy's folder, as a real path. */
9
+ copy: string;
10
+ /** Where the lines of the result are written. */
11
+ result: string;
12
+ /** The binding's module, relative to the copy, with `/`. */
13
+ module: string;
14
+ values: Record<string, readonly string[]>;
15
+ events: Record<string, EventDeclaration>;
16
+ /** The sequences to cause, each from a fresh start, in order. */
17
+ sequences: Call[][];
18
+ };
19
+ /**
20
+ * One line of the result. The process writes a line as soon as it
21
+ * has one, so the sequences it caused to their end stand where it is
22
+ * then stopped at the time limit or ends early; the effects of a
23
+ * sequence it did not cause to its end are not written:
24
+ * - `observed`: sequence `at` (from 0) was caused to its end and
25
+ * gave these effects, one for each of its events;
26
+ * - `outside`: a project file was loaded from outside the copy;
27
+ * - `ended`: a failing binding ended the process;
28
+ * - `finished`: every sequence was caused.
29
+ */
30
+ export type Line = {
31
+ kind: "observed";
32
+ at: number;
33
+ effects: Fields[];
34
+ } | {
35
+ kind: "outside";
36
+ file: string;
37
+ } | {
38
+ kind: "ended";
39
+ cause: string;
40
+ } | {
41
+ kind: "finished";
42
+ };