lawspec 0.24.0 → 0.25.0
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/CHANGELOG.md +67 -1
- package/README.md +29 -22
- package/UNICODE-LICENSE.txt +39 -0
- package/api.mjs +14 -23
- package/bin/lawspec.mjs +186 -65
- package/build.json +255 -159
- package/builtin-data-names.mjs +73 -0
- package/core.wasm +2 -2
- package/examples/native-payments/clojure/lawspec.json +13 -2
- package/examples/native-payments/csharp/lawspec.json +13 -2
- package/examples/native-payments/elixir/lawspec.json +14 -3
- package/examples/native-payments/erlang/lawspec.json +14 -3
- package/examples/native-payments/fsharp/lawspec.json +14 -3
- package/examples/native-payments/gleam/lawspec.json +14 -3
- package/examples/native-payments/go/lawspec.json +14 -3
- package/examples/native-payments/groovy/lawspec.json +14 -3
- package/examples/native-payments/haskell/lawspec.json +14 -3
- package/examples/native-payments/java/lawspec.json +14 -3
- package/examples/native-payments/javascript/lawspec.json +14 -3
- package/examples/native-payments/kotlin/lawspec.json +14 -3
- package/examples/native-payments/python/lawspec.json +14 -3
- package/examples/native-payments/rust/lawspec.json +14 -3
- package/examples/native-payments/scala/lawspec.json +14 -3
- package/examples/native-payments/swift/lawspec.json +14 -3
- package/examples/native-payments/typescript/lawspec.json +14 -3
- package/examples/packages/orders/lawspec.json +25 -5
- package/examples/packages/orders/orders.lawspec +36 -34
- package/examples/packages/shop-domain/src/domain.lawspec +23 -21
- package/examples/packages/shop-tax-1/src/rates.lawspec +4 -4
- package/examples/packages/shop-tax-2/src/rates.lawspec +5 -4
- package/examples/rc1/authorization-snapshots.lawspec +112 -0
- package/examples/rc1/banner-filenames.lawspec +63 -0
- package/examples/rc1/bit-codec.lawspec +56 -0
- package/examples/rc1/bounded-witness-search.lawspec +144 -0
- package/examples/rc1/conflicting-requirements.lawspec +30 -0
- package/examples/rc1/constructive-witnesses.lawspec +113 -0
- package/examples/rc1/documentary-review.lawspec +42 -0
- package/examples/rc1/empty-domains.lawspec +46 -0
- package/examples/rc1/finite-integer-domains.lawspec +75 -0
- package/examples/rc1/law-metadata.lawspec +29 -0
- package/examples/rc1/native-payments.lawspec +107 -0
- package/examples/rc1/nesting/rrr.lawspec +33 -0
- package/examples/rc1/nesting/rru.lawspec +56 -0
- package/examples/rc1/nesting/rur.lawspec +57 -0
- package/examples/rc1/nesting/ruu.lawspec +77 -0
- package/examples/rc1/nesting/urr.lawspec +52 -0
- package/examples/rc1/nesting/uru.lawspec +72 -0
- package/examples/rc1/nesting/uur.lawspec +73 -0
- package/examples/rc1/nesting/uuu.lawspec +95 -0
- package/examples/rc1/order-workflow.lawspec +126 -0
- package/examples/rc1/parcel-measurements.lawspec +92 -0
- package/examples/rc1/picture-records.lawspec +51 -0
- package/examples/rc1/picture-tuples.lawspec +47 -0
- package/examples/rc1/record-payloads.lawspec +56 -0
- package/examples/rc1/recursive-records.lawspec +64 -0
- package/examples/rc1/refund-conformance.lawspec +44 -0
- package/examples/rc1/refund-policy.lawspec +88 -0
- package/examples/rc1/requirement-composition.lawspec +89 -0
- package/examples/rc1/structural-records.lawspec +53 -0
- package/examples/rc1-authoring.lawspec +56 -0
- package/examples-command.mjs +11 -5
- package/explain.mjs +112 -0
- package/expression-presentation.mjs +333 -0
- package/files.mjs +16 -0
- package/index.d.ts +929 -11
- package/lsp.mjs +231 -0
- package/migrate.mjs +135 -0
- package/migration-bindings.mjs +86 -0
- package/migration-cases.mjs +45 -0
- package/migration-collections.mjs +54 -0
- package/migration-correspondence.mjs +275 -0
- package/migration-generation.mjs +99 -0
- package/migration-laws.mjs +102 -0
- package/migration-records.mjs +166 -0
- package/migration-source.mjs +247 -0
- package/migration-write.mjs +156 -0
- package/native-evidence.mjs +187 -0
- package/native-examples.mjs +8 -1
- package/node-events-reporter.mjs +23 -0
- package/package.json +8 -1
- package/positional-fields.mjs +13 -0
- package/proof.d.ts +35 -0
- package/proof.mjs +174 -0
- package/starter-rc1.lawspec +25 -0
- package/templates.mjs +2 -2
- package/test-command.mjs +107 -35
- package/typed-presentation.mjs +165 -0
package/test-command.mjs
CHANGED
|
@@ -99,6 +99,12 @@ const groupBy = (entries, key) => {
|
|
|
99
99
|
return [...groups.entries()];
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
+
// Hpack discovers generated modules before native result keys are computed.
|
|
103
|
+
// Stack owns this metadata transformation; no compilation or tests run here.
|
|
104
|
+
export function configurationInvocations(target) {
|
|
105
|
+
return target.language==='haskell'?[{command:'stack',args:['--no-terminal','config','build-files']}]:[];
|
|
106
|
+
}
|
|
107
|
+
|
|
102
108
|
// Rebar and Mix run their configured compile hooks. Gleam has no corresponding
|
|
103
109
|
// hook, so build its generated crypto bridge before starting a native test VM.
|
|
104
110
|
export function preparationInvocations(target, files) {
|
|
@@ -197,7 +203,14 @@ export function benchmarkInvocations(target, entries, { offline = false } = {})
|
|
|
197
203
|
// LawSpec.TestNames), then a kind after a separator no name contains, so one
|
|
198
204
|
// law's name never selects another's. `scratch` is a folder for reports;
|
|
199
205
|
// `coverage` asks each runner to measure coverage too (see coverageSetup).
|
|
200
|
-
export function invocations(
|
|
206
|
+
export function invocations(...arguments_) {
|
|
207
|
+
return nativeInvocations(...arguments_).map(run => {
|
|
208
|
+
const matches=run.matches??run.ran;
|
|
209
|
+
return matches?{...run,matches,ran:test=>test.status==='passed'?matches(test):[]}:run;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function nativeInvocations(target, entries, { offline = false, scratch = ".", coverage = null, xdist = false,
|
|
201
214
|
root = process.cwd(), coverageConfig } = {}) {
|
|
202
215
|
if (!entries.length) return [];
|
|
203
216
|
const language = target.language;
|
|
@@ -206,12 +219,14 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
206
219
|
const directory = testDir || defaultDir;
|
|
207
220
|
return file.startsWith(directory + "/") ? file.slice(directory.length + 1) : file;
|
|
208
221
|
};
|
|
209
|
-
const
|
|
222
|
+
const model = (entry) => entry.kind === "model";
|
|
223
|
+
const named = (entry) => new RegExp(`^${regex(entry.name)}${model(entry) ? "$" : "_"}`);
|
|
210
224
|
const className = (file, defaultDir, extension) => without(relativeTo(file, defaultDir), extension).replaceAll("/", ".");
|
|
211
225
|
if (["erlang", "elixir", "gleam"].includes(language)) {
|
|
212
226
|
const run = randomUUID();
|
|
213
227
|
const file = path.join(scratch, `beam-${run}.jsonl`);
|
|
214
228
|
const identity = (entry) => `${entry.unit}::${entry.name}`;
|
|
229
|
+
const matching = test => entries.filter(entry => test.identity === identity(entry));
|
|
215
230
|
const env = { LAWSPEC_BEAM_REPORT: file, LAWSPEC_BEAM_RUN: run };
|
|
216
231
|
const measured = coverage ? {run, file: path.resolve(coverage, "runs", `${run}.coverdata`),
|
|
217
232
|
...(language === "elixir" ? {beamDirectory: coverageConfig?.compilePath} : {}),
|
|
@@ -242,34 +257,52 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
242
257
|
}
|
|
243
258
|
}
|
|
244
259
|
return [{ laws: entries, command, args, env, ...(measured ? {coverage: measured} : {}), report: {kind: "beam-events", file, run},
|
|
245
|
-
ran:
|
|
260
|
+
matches: matching, ran: test => test.status === "passed" ? matching(test) : [] }];
|
|
246
261
|
}
|
|
247
262
|
if (language === "python")
|
|
248
|
-
return groupBy(entries, (e) => e.file).
|
|
263
|
+
return groupBy(entries, (e) => e.file).flatMap(([file, selected], n) => {
|
|
264
|
+
const laws=selected.filter(entry=>!model(entry));
|
|
265
|
+
const models=selected.filter(model);
|
|
266
|
+
const invocations=[];
|
|
249
267
|
const report = path.join(scratch, `pytest-${n}.xml`);
|
|
250
268
|
// parallel: pytest-xdist runs the tests on several workers, when it
|
|
251
269
|
// is installed (lawspec test checks); otherwise one after another.
|
|
252
|
-
const workers = xdist &&
|
|
270
|
+
const workers = xdist && selected.some((e) => e.parallel) ? ["-p", "xdist", "-n", "auto"] : [];
|
|
253
271
|
const pytest = ["-m", "pytest", "-q", ...workers, file, "-k", laws.map((e) => `${e.name}__`).join(" or "), `--junitxml=${report}`];
|
|
254
|
-
|
|
272
|
+
if(laws.length)invocations.push({ laws, command: target.python || "python3",
|
|
255
273
|
args: coverage ? ["-m", "coverage", "run", "--append", `--data-file=${path.join(coverage, ".coverage")}`, ...pytest.slice(1)] : pytest,
|
|
256
274
|
report: { kind: "junit", files: [report] },
|
|
257
|
-
ran: (test) => laws.filter((e) => test.name.startsWith(`${e.name}__`)) };
|
|
275
|
+
ran: (test) => laws.filter((e) => test.name.startsWith(`${e.name}__`)) });
|
|
276
|
+
if(models.length){
|
|
277
|
+
const modelReport=path.join(scratch,`pytest-model-${n}.xml`);
|
|
278
|
+
const arguments_=["-m","pytest","-q",...workers,
|
|
279
|
+
...new Set(models.map(entry=>`${file}::${entry.name}`)),`--junitxml=${modelReport}`];
|
|
280
|
+
invocations.push({laws:models,command:target.python||"python3",
|
|
281
|
+
args:coverage?["-m","coverage","run","--append",`--data-file=${path.join(coverage,".coverage")}`,...arguments_.slice(1)]:arguments_,
|
|
282
|
+
report:{kind:"junit",files:[modelReport]},
|
|
283
|
+
ran:test=>models.filter(entry=>test.name===entry.name)});
|
|
284
|
+
}
|
|
285
|
+
return invocations;
|
|
258
286
|
});
|
|
259
287
|
if (language === "javascript" || language === "typescript") {
|
|
260
|
-
const pattern = (e) =>
|
|
288
|
+
const pattern = (e) => model(e)?`^${regex(e.label)}$`:
|
|
289
|
+
`^${regex(e.label)}( example: .*| property| known failing| skipped| replay| search)?$`;
|
|
261
290
|
const files = [...new Set(entries.map((e) => language === "typescript"
|
|
262
291
|
? `dist/${without(e.file, ".ts")}.js` : e.file))];
|
|
263
|
-
const
|
|
292
|
+
const file = path.join(scratch, "node-events.jsonl");
|
|
293
|
+
const runId=randomUUID();
|
|
294
|
+
const matching = test => entries.filter(entry => new RegExp(pattern(entry)).test(test.name));
|
|
264
295
|
// parallel: test files run at the same time too.
|
|
265
296
|
const node = ["--test", ...(entries.some((e) => e.parallel) ? ["--test-concurrency=" + Math.max(2, (globalThis.navigator?.hardwareConcurrency ?? 2))] : []),
|
|
266
297
|
`--test-name-pattern=(${entries.map(pattern).join("|")})`,
|
|
267
298
|
"--test-reporter=spec", "--test-reporter-destination=stdout",
|
|
268
|
-
|
|
299
|
+
`--test-reporter=${new URL('./node-events-reporter.mjs',import.meta.url).href}`,
|
|
300
|
+
`--test-reporter-destination=${file}`, ...files];
|
|
269
301
|
const run = { laws: entries, command: coverage ? "npx" : process.execPath,
|
|
270
302
|
args: coverage ? ["--no-install", "c8", "--reporter=text", `--reports-dir=${coverage}`, process.execPath, ...node] : node,
|
|
271
|
-
|
|
272
|
-
|
|
303
|
+
// A CLI launched from node:test must start an independent native run.
|
|
304
|
+
env:{LAWSPEC_NODE_RUN:runId,NODE_TEST_CONTEXT:undefined},report: { kind: "node-events", file, run:runId },
|
|
305
|
+
matches: matching, ran: test => test.status === 'passed' ? matching(test) : [] };
|
|
273
306
|
return language === "typescript"
|
|
274
307
|
? [{ laws: [], command: "npm", args: ["exec", "--", "tsc", "-p", "tsconfig.json"] }, run]
|
|
275
308
|
: [run];
|
|
@@ -278,7 +311,9 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
278
311
|
return groupBy(entries, (e) => path.posix.dirname(e.file)).map(([directory, laws]) => ({
|
|
279
312
|
laws, command: "go",
|
|
280
313
|
args: ["test", "-json", "-count=1", ...(coverage ? ["-cover", `-coverprofile=${path.join(coverage, `go-${directory.replaceAll("/", "_") || "root"}.out`)}`] : []),
|
|
281
|
-
`./${directory}`, "-run",
|
|
314
|
+
`./${directory}`, "-run", laws.some(model)?
|
|
315
|
+
`^(${[...new Set(laws.map(e=>regex(e.name)+(model(e)?"$":"_")))].join("|")})`:
|
|
316
|
+
`^(${laws.map((e) => regex(e.name)).join("|")})_`],
|
|
282
317
|
report: { kind: "go-json" },
|
|
283
318
|
ran: (test) => laws.filter((e) => named(e).test(test.name)) }));
|
|
284
319
|
if (language === "java") {
|
|
@@ -286,9 +321,9 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
286
321
|
return [{ laws: entries, command: target.maven || "mvn",
|
|
287
322
|
args: [...(offline ? ["-o"] : []), "-B", ...(coverage ? ["org.jacoco:jacoco-maven-plugin:prepare-agent"] : []), "test",
|
|
288
323
|
...(coverage ? ["org.jacoco:jacoco-maven-plugin:report"] : []),
|
|
289
|
-
`-Dtest=${byClass.map(([name, laws]) => `${name}#${laws.map((e) =>
|
|
324
|
+
`-Dtest=${byClass.map(([name, laws]) => `${name}#${[...new Set(laws.map((e) => model(e)?e.name:`${e.name}_*`))].join("+")}`).join(",")}`],
|
|
290
325
|
report: { kind: "junit", directory: "target/surefire-reports" },
|
|
291
|
-
ran: (test) => entries.filter((e) => test.classname === className(e.file, "src/test/java", ".java") && named(e).test(test.name)) }];
|
|
326
|
+
ran: (test) => entries.filter((e) => test.classname === (e.scope??className(e.file, "src/test/java", ".java")) && named(e).test(test.name)) }];
|
|
292
327
|
}
|
|
293
328
|
// Kotest names tests by string, which Gradle's method filters cannot
|
|
294
329
|
// select. Kotest's own filter selects them within each class: one pattern,
|
|
@@ -296,13 +331,15 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
296
331
|
// patterns must all match, so alternatives go in one group).
|
|
297
332
|
if (language === "kotlin")
|
|
298
333
|
return groupBy(entries, (e) => e.file).map(([file, laws]) => {
|
|
299
|
-
const filter =
|
|
334
|
+
const filter = laws.some(model)?
|
|
335
|
+
`(${[...new Set(laws.map(e=>regex(e.name)+(model(e)?"":"_.*")))].join("|")})`:
|
|
336
|
+
`(${laws.map((e) => `${e.name}_`).join("|")})*`;
|
|
300
337
|
const name = className(file, "src/test/kotlin", ".kt");
|
|
301
338
|
return { laws, command: target.gradle || "gradle",
|
|
302
339
|
args: [...(offline ? ["--offline"] : []), "--console=plain", "test", ...(coverage ? ["koverXmlReport"] : []), "--rerun", "--tests", name],
|
|
303
340
|
env: { "kotest.filter.tests": filter, kotest_filter_tests: filter },
|
|
304
341
|
report: { kind: "junit", directory: "build/test-results/test" },
|
|
305
|
-
ran: (test) => laws.filter((e) => test.classname === name && named(e).test(test.name)) };
|
|
342
|
+
ran: (test) => laws.filter((e) => test.classname === (e.scope??name) && named(e).test(test.name)) };
|
|
306
343
|
});
|
|
307
344
|
// ScalaTest selects tests by substring (-z): each law's tests are named
|
|
308
345
|
// after it, then a kind after a separator no name contains. Its JUnit
|
|
@@ -317,19 +354,22 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
317
354
|
const measured = coverage ? ["-O", `-coverage-out:${path.resolve(coverage, "data")}`,
|
|
318
355
|
"-O", `-coverage-exclude-files:.*/${testRoot.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}/.*`] : [];
|
|
319
356
|
return { laws, command: target.scala || "scala",
|
|
320
|
-
args: ["test", ".", ...(offline ? ["--offline"] : []), ...measured, "--test-only", name, "--",
|
|
321
|
-
...laws.
|
|
357
|
+
args: ["test", ".", ...(offline ? ["--power","--offline"] : []), ...measured, "--test-only", name, "--",
|
|
358
|
+
...[...new Map(laws.map(e=>[(model(e)?"exact:":"prefix:")+e.name,e])).values()]
|
|
359
|
+
.flatMap(e=>[model(e)?"-t":"-z",model(e)?e.name:`${e.name}_`]), "-u", directory],
|
|
322
360
|
report: { kind: "junit", directory: path.relative(root, directory) || "." },
|
|
323
|
-
ran: (test) => laws.filter((e) => test.classname === name && named(e).test(test.name)) };
|
|
361
|
+
ran: (test) => laws.filter((e) => test.classname === (e.scope??name) && named(e).test(test.name)) };
|
|
324
362
|
});
|
|
325
363
|
// A Clojure test is the law's words, a double dash and the kind of test
|
|
326
364
|
// (LawSpec.TestNames); the runner selects tests by namespace and prefix.
|
|
327
365
|
if (language === "clojure") {
|
|
328
|
-
const ns = (e) => without(relativeTo(e.file, "test"), ".clj").replaceAll("/", ".").replaceAll("_", "-");
|
|
366
|
+
const ns = (e) => e.scope??without(relativeTo(e.file, "test"), ".clj").replaceAll("/", ".").replaceAll("_", "-");
|
|
329
367
|
return [{ laws: entries, command: target.clojure || "clojure",
|
|
330
|
-
args: ["-M:test", ...entries.
|
|
368
|
+
args: ["-M:test", ...[...new Map(entries.map(e=>[(model(e)?"exact:":"prefix:")+ns(e)+"/"+e.name,e])).values()]
|
|
369
|
+
.flatMap(e=>[model(e)?"--select-exact":"--select",`${ns(e)}/${e.name}${model(e)?"":"--"}`])],
|
|
331
370
|
report: { kind: "junit", directory: "target/test-results" },
|
|
332
|
-
ran: (test) => entries.filter((e) => test.classname === ns(e) &&
|
|
371
|
+
ran: (test) => entries.filter((e) => test.classname === ns(e) &&
|
|
372
|
+
(model(e)?test.name===e.name:test.name.startsWith(`${e.name}--`))) }];
|
|
333
373
|
}
|
|
334
374
|
// A Spock feature is the law's words, a colon and the kind of test
|
|
335
375
|
// (LawSpec.TestNames), so "name: *" selects one law's features only.
|
|
@@ -337,15 +377,16 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
337
377
|
const name = (e) => className(e.file, "src/test/groovy", ".groovy");
|
|
338
378
|
return [{ laws: entries, command: target.gradle || "gradle",
|
|
339
379
|
args: [...(offline ? ["--offline"] : []), "--console=plain", "test", ...(coverage ? ["jacocoTestReport"] : []), "--rerun",
|
|
340
|
-
...entries.
|
|
380
|
+
...[...new Set(entries.map(e=>`${e.scope??name(e)}.${e.name}${model(e)?"":": *"}`))].flatMap(name=>["--tests",name])],
|
|
341
381
|
report: { kind: "junit", directory: "build/test-results/test" },
|
|
342
|
-
ran: (test) => entries.filter((e) => test.classname ===
|
|
382
|
+
ran: (test) => entries.filter((e) => test.classname === (e.scope??name(e)) &&
|
|
383
|
+
(model(e)?test.name===e.name:test.name.startsWith(`${e.name}: `))) }];
|
|
343
384
|
}
|
|
344
385
|
if (language === "rust")
|
|
345
386
|
return groupBy(entries, (e) => e.file).map(([file, laws]) => ({
|
|
346
387
|
laws, command: "cargo",
|
|
347
388
|
args: [...(coverage ? ["llvm-cov", "--no-report"] : []), "test", ...(offline ? ["--offline"] : []), "--test", path.posix.basename(file, ".rs"), "--", "--exact",
|
|
348
|
-
...laws.map((e) => e.name)],
|
|
389
|
+
...new Set(laws.map((e) => e.name))],
|
|
349
390
|
report: { kind: "lines", pattern: /^test (\S+) \.\.\. (ok|FAILED|ignored)/ },
|
|
350
391
|
ran: (test) => laws.filter((e) => test.name === e.name) }));
|
|
351
392
|
// xUnit v3 on Microsoft.Testing.Platform selects test methods with its
|
|
@@ -381,11 +422,13 @@ export function invocations(target, entries, { offline = false, scratch = ".", c
|
|
|
381
422
|
}
|
|
382
423
|
if (language === "haskell") {
|
|
383
424
|
const module = (e) => without(relativeTo(e.file, "test"), "Spec.hs").replaceAll("/", ".");
|
|
384
|
-
const matches = entries.map((e) =>
|
|
425
|
+
const matches = [...new Set(entries.map((e) => model(e)?
|
|
426
|
+
`/${e.scope??module(e)}/${e.unit} models/${e.name}/`:`${module(e)}/${e.name}_`))];
|
|
385
427
|
return [{ laws: entries, command: "stack",
|
|
386
|
-
args: ["--no-terminal", "test", ...(coverage ? ["--coverage"] : []), "--test-arguments",
|
|
428
|
+
args: ["--no-terminal", "test", ...(coverage ? ["--coverage"] : []), "--test-arguments",
|
|
429
|
+
matches.map((m) => `--match ${m.includes(" ")?JSON.stringify(m):m}`).join(" ")],
|
|
387
430
|
report: { kind: "hspec" },
|
|
388
|
-
ran: (test) => entries.filter((e) => test.classname === module(e) && named(e).test(test.name)) }];
|
|
431
|
+
ran: (test) => entries.filter((e) => test.classname === (e.scope??module(e)) && named(e).test(test.name)) }];
|
|
389
432
|
}
|
|
390
433
|
throw new Error(`lawspec test does not support ${language}`);
|
|
391
434
|
}
|
|
@@ -502,6 +545,20 @@ export async function harnessStatistics(directory) {
|
|
|
502
545
|
// The tests a run executed, as {name, classname}, from the runner's report or
|
|
503
546
|
// output. Skipped tests are not counted.
|
|
504
547
|
export async function executedTests(report, output, root, since) {
|
|
548
|
+
if(report?.kind==='node-events') {
|
|
549
|
+
const raw=await readFile(path.resolve(root,report.file),'utf8').catch(()=>'');
|
|
550
|
+
let rows;
|
|
551
|
+
try {rows=raw.trim().split('\n').map(line=>JSON.parse(line));}catch{return [];}
|
|
552
|
+
if(rows.length<2||rows[0]?.event!=='start'||rows.at(-1)?.event!=='end'||
|
|
553
|
+
rows.some(row=>row?.version!==1||row?.run!==report.run)||
|
|
554
|
+
rows.at(-1).count!==rows.length-2) return [];
|
|
555
|
+
const tests=rows.slice(1,-1);
|
|
556
|
+
if(tests.some(row=>row?.event!=='test'||typeof row.name!=='string'||typeof row.classname!=='string'||
|
|
557
|
+
!['passed','failed','skipped'].includes(row.status)||
|
|
558
|
+
(row.time!==undefined&&(!Number.isFinite(row.time)||row.time<0))||
|
|
559
|
+
(row.failure!==undefined&&typeof row.failure!=='string')))return [];
|
|
560
|
+
return tests;
|
|
561
|
+
}
|
|
505
562
|
if (report?.kind === "beam-events") {
|
|
506
563
|
// A native listener seals the invocation after its final event. Missing,
|
|
507
564
|
// stale, malformed or interrupted reports are not execution evidence.
|
|
@@ -520,11 +577,25 @@ export async function executedTests(report, output, root, since) {
|
|
|
520
577
|
const files = report.files ?? await reportFiles(path.join(root, report.directory), since);
|
|
521
578
|
const tests = [];
|
|
522
579
|
for (const file of files) {
|
|
523
|
-
const
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
580
|
+
const location=path.resolve(root,file);
|
|
581
|
+
const info=await stat(location).catch(()=>null);
|
|
582
|
+
if(!info||info.mtimeMs<since)continue;
|
|
583
|
+
const xml=await readFile(location,"utf8").catch(()=>"");
|
|
584
|
+
const attributes=opening=>Object.fromEntries([...opening.matchAll(/\s([A-Za-z_:][\w:.-]*)\s*=\s*(?:"([^"]*)"|'([^']*)')/g)]
|
|
585
|
+
.map(match=>[match[1],unescapeXml(match[2]??match[3])]));
|
|
586
|
+
for(const element of junitElements(xml,["testcase"])){
|
|
587
|
+
const values=attributes(element.opening);
|
|
588
|
+
const native=junitElements(element.xml,["failure","error","skipped"]);
|
|
589
|
+
const failure=native.filter(element=>element.name!=="skipped");
|
|
590
|
+
const status=failure.length?"failed":native.length?"skipped":"passed";
|
|
591
|
+
const detail=element=>[attributes(element.opening).message,
|
|
592
|
+
unescapeXml(element.xml.slice(element.opening.length).replace(/<\/(failure|error|skipped)>\s*$/,"")
|
|
593
|
+
.replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g,(_,text)=>text))].filter(Boolean).join("\n");
|
|
594
|
+
const time=values.time===undefined?undefined:Number(values.time);
|
|
595
|
+
tests.push({name:(values.name??"").replace(/\(\)$/, ""),classname:values.classname??"",status,
|
|
596
|
+
...(Number.isFinite(time)&&time>=0?{time}:{}),
|
|
597
|
+
...(failure.length?{failure:failure.map(detail).join("\n")}:
|
|
598
|
+
status==="skipped"?{reason:native.map(detail).join("\n")}: {})});
|
|
528
599
|
}
|
|
529
600
|
}
|
|
530
601
|
return tests;
|
|
@@ -548,7 +619,8 @@ export async function executedTests(report, output, root, since) {
|
|
|
548
619
|
let module = "";
|
|
549
620
|
for (const line of output.split("\n")) {
|
|
550
621
|
if (/^\S/.test(line) && !/^(Finished|Failures|Randomized|\d+ examples?)/.test(line)) module = line.trim();
|
|
551
|
-
const example = line.match(/^\s+(law\S*?):?(?:\s.*)?\s\[([✔✘])\]\s*$/)
|
|
622
|
+
const example = line.match(/^\s+(law\S*?):?(?:\s.*)?\s\[([✔✘])\]\s*$/) ??
|
|
623
|
+
line.match(/^\s+(model .+?|supervision)\s\[([✔✘])\]\s*$/);
|
|
552
624
|
if (example) tests.push({ name: example[1], classname: module, status: example[2] === "✔" ? "passed" : "failed" });
|
|
553
625
|
}
|
|
554
626
|
return tests;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// Generated from templates/npm/typed-presentation.mjs by lawspec-dev generate. Do not edit.
|
|
2
|
+
// Presentation only: identities, constraints and proof evidence remain in Core.
|
|
3
|
+
// In particular, a nominal record is never expanded into a structural product.
|
|
4
|
+
import { createExpressionPresentation } from './expression-presentation.mjs';
|
|
5
|
+
import { builtinDataNames } from './builtin-data-names.mjs';
|
|
6
|
+
import { showScalar } from './scalars.mjs';
|
|
7
|
+
import { positionalFields } from './positional-fields.mjs';
|
|
8
|
+
|
|
9
|
+
export function createTypePresentation(result) {
|
|
10
|
+
const declarations = new Map([...builtinDataNames, ...(result.dataTypes ?? [])].map(d => [d.id, d]));
|
|
11
|
+
const constructors = new Map([...declarations.values()].flatMap(d =>
|
|
12
|
+
d.constructors.map(c => [c.id, { declaration: d, constructor: c }])));
|
|
13
|
+
const shortName = name => ({ BigUInt: 'Whole', BigInt: 'Integer', Natural: 'Whole' })[name]
|
|
14
|
+
?? declarations.get(name)?.name ?? name.split('::type::').at(-1);
|
|
15
|
+
const names = new Map();
|
|
16
|
+
for (const d of declarations.values()) {
|
|
17
|
+
const name = shortName(d.id);
|
|
18
|
+
names.set(name, (names.get(name) ?? 0) + 1);
|
|
19
|
+
}
|
|
20
|
+
const nominalName = name => {
|
|
21
|
+
const display = shortName(name), separator = name.indexOf('::type::');
|
|
22
|
+
return names.get(display) > 1 && separator >= 0
|
|
23
|
+
? `${name.slice(0, separator)}.${display}` : display;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// The compiler marks ordinary checked recursive representation definitions.
|
|
27
|
+
// Names alone do not authorize hiding a call, and its full signature must
|
|
28
|
+
// agree with the typed application. The wire assertion is never rewritten.
|
|
29
|
+
const recursiveViews = new Map((result.units ?? []).flatMap(unit => unit.declarations
|
|
30
|
+
.filter(d => d.representation === 'structural-record-storage' && d.source === undefined
|
|
31
|
+
&& d.origin?.kind === 'generated' && d.origin.declaration === d.id && d.type.kind === 'function')
|
|
32
|
+
.map(d => [d.id, d.type])));
|
|
33
|
+
function sameType(left, right) {
|
|
34
|
+
if (!left || !right || left.kind !== right.kind) return false;
|
|
35
|
+
if (left.kind === 'variable') return left.id === right.id;
|
|
36
|
+
if (left.kind === 'function') return sameType(left.parameter, right.parameter) && sameType(left.result, right.result);
|
|
37
|
+
if (left.kind !== 'constructor' || left.name !== right.name || left.arguments.length !== right.arguments.length) return false;
|
|
38
|
+
return left.arguments.every((a, i) => {
|
|
39
|
+
const b = right.arguments[i];
|
|
40
|
+
return a.kind === b.kind && (a.kind === 'type' ? sameType(a.type, b.type)
|
|
41
|
+
: a.kind === 'natural' ? a.value === b.value : a.kind === 'indexVariable' && a.id === b.id);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Recognize only compiler-generated storage views which copy every field in
|
|
46
|
+
// order. Do not simplify user matches, erase conversions or discard unused
|
|
47
|
+
// constructor arguments: those may contain checks or undefined computations.
|
|
48
|
+
function storageView(expression) {
|
|
49
|
+
const node = expression.node;
|
|
50
|
+
if (node?.kind === 'call') {
|
|
51
|
+
const signature = recursiveViews.get(node.declaration);
|
|
52
|
+
return signature && node.arguments.length === 1
|
|
53
|
+
&& sameType(signature.parameter, node.arguments[0].type) && sameType(signature.result, expression.type)
|
|
54
|
+
? node.arguments[0] : undefined;
|
|
55
|
+
}
|
|
56
|
+
if (node?.kind !== 'match' || node.cases.length !== 1) return undefined;
|
|
57
|
+
const branch = node.cases[0], body = branch.body.node;
|
|
58
|
+
const source = constructors.get(branch.constructor), target = constructors.get(body?.constructor);
|
|
59
|
+
if (body?.kind !== 'construct' || !source || !target
|
|
60
|
+
|| source.declaration.structure?.kind !== 'record' || target.declaration.structure?.kind !== 'record'
|
|
61
|
+
|| expression.origin?.kind !== 'generated'
|
|
62
|
+
|| !branch.binders.length || !branch.binders.every(b => b.id.startsWith('lawspec::record-view::'))
|
|
63
|
+
|| branch.binders.length !== source.constructor.fields.length
|
|
64
|
+
|| body.arguments.length !== branch.binders.length
|
|
65
|
+
|| target.constructor.fields.length !== branch.binders.length) return undefined;
|
|
66
|
+
for (let i = 0; i < branch.binders.length; i++) {
|
|
67
|
+
if (source.constructor.fields[i].name !== target.constructor.fields[i].name) return undefined;
|
|
68
|
+
let argument = body.arguments[i], unwrapped;
|
|
69
|
+
while ((unwrapped = storageView(argument)) !== undefined) argument = unwrapped;
|
|
70
|
+
if (argument.node?.kind !== 'local' || argument.node.id !== branch.binders[i].id) return undefined;
|
|
71
|
+
}
|
|
72
|
+
return node.value;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function expressionText(expression, locals) {
|
|
76
|
+
const view = storageView(expression);
|
|
77
|
+
if (view) return expressionText(view, locals);
|
|
78
|
+
const node = expression.node;
|
|
79
|
+
switch (node?.kind) {
|
|
80
|
+
case 'local': return locals.get(node.id) ?? expression.text;
|
|
81
|
+
case 'field': {
|
|
82
|
+
const field = constructors.get(node.constructor)?.constructor.fields[node.index];
|
|
83
|
+
if (!field) return expression.text;
|
|
84
|
+
let value = node.value, unwrapped;
|
|
85
|
+
while ((unwrapped = storageView(value)) !== undefined) value = unwrapped;
|
|
86
|
+
const text = expressionText(value, locals);
|
|
87
|
+
return `${['local', 'field'].includes(value.node?.kind) ? text : `(${text})`}.${field.name}`;
|
|
88
|
+
}
|
|
89
|
+
case 'binary':
|
|
90
|
+
case 'shortCircuit': return `(${expressionText(node.left, locals)} ${{ '==': '=', '&&': 'and', '||': 'or' }[node.operator] ?? node.operator} ${expressionText(node.right, locals)})`;
|
|
91
|
+
case 'unary': return `${node.operator === '!' ? 'not' : node.operator} (${expressionText(node.argument, locals)})`;
|
|
92
|
+
// Keep unfamiliar expressions verbatim; never omit a restriction because
|
|
93
|
+
// a presentation does not yet know its typed node.
|
|
94
|
+
default: return expression.text;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function typeName(type, substitutions = new Map(), active = new Set()) {
|
|
99
|
+
if (type.kind === 'variable') {
|
|
100
|
+
const replacement = substitutions.get(type.id);
|
|
101
|
+
return replacement ? typeName(replacement) : type.id;
|
|
102
|
+
}
|
|
103
|
+
if (type.kind === 'function') return `(${typeName(type.parameter, substitutions, active)} -> ${typeName(type.result, substitutions, active)})`;
|
|
104
|
+
if (type.kind !== 'constructor') return type.id;
|
|
105
|
+
const declaration = declarations.get(type.name);
|
|
106
|
+
const argumentsText = () => type.arguments.map(a => {
|
|
107
|
+
if (a.kind !== 'type') return a.value ?? a.id;
|
|
108
|
+
const text = typeName(a.type, substitutions, active);
|
|
109
|
+
return a.type.kind === 'constructor' && a.type.arguments.length ? `(${text})` : text;
|
|
110
|
+
}).join(' ');
|
|
111
|
+
const named = () => nominalName(type.name) + (type.arguments.length ? ` ${argumentsText()}` : '');
|
|
112
|
+
if (declaration?.structure?.kind !== 'record' || active.has(type.name)) return named();
|
|
113
|
+
const constructor = declaration.constructors[0];
|
|
114
|
+
const bindings = new Map(substitutions);
|
|
115
|
+
declaration.parameters.forEach((parameter, i) => {
|
|
116
|
+
const argument = type.arguments[i];
|
|
117
|
+
if (argument?.kind === 'type') bindings.set(parameter, substitute(argument.type, substitutions));
|
|
118
|
+
});
|
|
119
|
+
const nested = new Set([...active, type.name]);
|
|
120
|
+
const positions = positionalFields(declaration);
|
|
121
|
+
const ordered = positions ?? constructor.fields;
|
|
122
|
+
const locals = new Map(ordered.map((f, index) => [f.id, positions ? `component${index + 1}` : f.name]));
|
|
123
|
+
const fields = ordered.map(field => {
|
|
124
|
+
const base = typeName(field.type, bindings, nested);
|
|
125
|
+
const predicates = declaration.structure.fields.find(f => f.name === field.name)?.predicates ?? [];
|
|
126
|
+
const name = locals.get(field.id);
|
|
127
|
+
const refined = predicates.length
|
|
128
|
+
? `(${name} of type ${base} where ${predicates.map(p => expressionText(p, locals)).join(' and ')})`
|
|
129
|
+
: base;
|
|
130
|
+
return positions ? refined : `${field.name} of type ${refined}`;
|
|
131
|
+
});
|
|
132
|
+
if (positions) return `(${fields.join(', ')})`;
|
|
133
|
+
return `record{${fields.join(', ')}}`;
|
|
134
|
+
}
|
|
135
|
+
function substitute(type, bindings) {
|
|
136
|
+
if (type.kind === 'variable') return bindings.get(type.id) ?? type;
|
|
137
|
+
if (type.kind === 'function') return { ...type, parameter: substitute(type.parameter, bindings), result: substitute(type.result, bindings) };
|
|
138
|
+
if (type.kind === 'constructor') return { ...type, arguments: type.arguments.map(a => a.kind === 'type'
|
|
139
|
+
? { ...a, type: substitute(a.type, bindings) } : a) };
|
|
140
|
+
return type;
|
|
141
|
+
}
|
|
142
|
+
// Only concrete bindings have already passed the compiler's stored-value
|
|
143
|
+
// validation. Keep that fact outside the wire expression objects.
|
|
144
|
+
const storedValues = new WeakSet();
|
|
145
|
+
const checkedExpressionText = createExpressionPresentation(result, { constructors, typeName, storageView,
|
|
146
|
+
isStoredValue: expression => storedValues.has(expression) });
|
|
147
|
+
// Example bindings are already checked concrete values. Render their stored
|
|
148
|
+
// structure through the same constructor metadata; do not execute anything.
|
|
149
|
+
function valueExpression(value) {
|
|
150
|
+
const text = JSON.stringify(value);
|
|
151
|
+
if (value?.kind === 'data') {
|
|
152
|
+
const expression = {type: value.type, text,
|
|
153
|
+
node: {kind: 'construct', constructor: value.constructor,
|
|
154
|
+
arguments: value.fields.map(valueExpression)}};
|
|
155
|
+
storedValues.add(expression);
|
|
156
|
+
return expression;
|
|
157
|
+
}
|
|
158
|
+
return {type: {kind: 'constructor', name: value.type, arguments: []},
|
|
159
|
+
text: showScalar(value), node: {kind: 'constant', value}};
|
|
160
|
+
}
|
|
161
|
+
function valueText(value, scope = new Map()) {
|
|
162
|
+
return checkedExpressionText(valueExpression(value), scope);
|
|
163
|
+
}
|
|
164
|
+
return { typeName, expressionText: checkedExpressionText, valueText };
|
|
165
|
+
}
|