lawspec 0.17.1 → 0.17.5

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 CHANGED
@@ -1,5 +1,98 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.17.5
4
+
5
+ ### `lawspec test` confirms that each law's tests ran
6
+
7
+ - A test filter that matches nothing makes Go, Rust, Node, Kotest and hspec
8
+ report success without running anything. `lawspec test` now reads each
9
+ runner's own report (pytest and Node JUnit XML, `go test -json`, the
10
+ Surefire and Gradle reports, and Rust's and hspec's per-test output) and
11
+ records a law as passing only if at least one of its tests ran and was not
12
+ skipped. A selected law with no executed test fails the run, naming the law.
13
+ - Results and runner reports live in `.lawspec/results` and `.lawspec/reports`,
14
+ each with its own `.gitignore`.
15
+
16
+ ## 0.17.4
17
+
18
+ ### `lawspec test`
19
+
20
+ - Runs the generated tests of only the laws whose results may have changed
21
+ since their last passing run, through each target's own runner, and records
22
+ the laws that pass. A law runs again when the law changes, or anything it
23
+ depends on: the types and definitions it reaches, its unit's generated
24
+ tests, the LawSpec version, the target's settings, the project's build and
25
+ lock files, the toolchain, and, for a law that calls adapters, any file in
26
+ the project LawSpec did not generate. `--fresh` runs every law. See
27
+ [`lawspec test`](docs/reference/cli.md#test).
28
+ - Every run uses one random seed for all property tests, printed in the
29
+ summary and recorded with each pass; `--seed` fixes it.
30
+ - `planGeneration` responses list each law's generated test file, its
31
+ position in the unit, its dependency key and whether it calls adapters
32
+ (`tests`).
33
+
34
+ ### Changes to generated tests
35
+
36
+ - Property tests read their seed from `LAWSPEC_SEED` on every target, so a
37
+ failing run can be repeated exactly.
38
+ - Kotlin and Haskell property tests are named `law<n>Property: <law>` like
39
+ their example and boundary tests, so each law's tests can be selected by
40
+ name.
41
+
42
+ ## 0.17.3
43
+
44
+ ### Incremental front end
45
+
46
+ - Each law's expansion and type checking, and its elaboration to Core, are
47
+ keyed by exactly their inputs: the law, the laws it invokes, its unit's
48
+ signatures and the program's data types. Editing a definition's body, or
49
+ another unit's laws, no longer re-checks a law; the dependency keys of
50
+ 0.17.2 still replan the laws that reach the edit.
51
+ - Unit validation and totality checks are keyed by the unit.
52
+ - Evidence discharge shares the test planner's work, and builds the type
53
+ registry once per program rather than once per law.
54
+
55
+ ### On-disk compiler cache
56
+
57
+ - `lawspec check`, `evidence`, `explain` and `generate` keep the compiler's
58
+ work in `.lawspec/cache` and reuse it across runs. Results are identical to
59
+ an uncached run. With every bundled example in one project, a repeated
60
+ `lawspec check` takes 4.7 seconds instead of 8.4, and generating Python
61
+ tests through the API 9.2 instead of 18.2 (natively, a third of the time).
62
+ - One folder per compiler build, with its own `.gitignore`; damaged entries
63
+ are recomputed. `--no-cache` or `"cache": false` turns it off. See
64
+ [the compiler cache](docs/reference/cli.md#the-compiler-cache).
65
+ - API requests may name a `cacheDirectory` to share work the same way.
66
+
67
+ ## 0.17.2
68
+
69
+ ### Dependency-tracked incremental compilation
70
+
71
+ - The compiler builds a dependency graph of each program. Its nodes are data
72
+ types and declarations (with their contracts and checked definitions), and
73
+ each node has a Merkle digest (SHA-256) of its content and of everything it
74
+ references, with recursive groups digested together.
75
+ - A law is planned again only when it, or a type or definition it can reach,
76
+ changes. A unit's files are emitted again only when the unit or one of its
77
+ laws' plans changes, when a data type changes (emitters name types across
78
+ the whole program), or when a checked definition is added, removed or
79
+ renamed. Editing one definition's body no longer replans and re-emits the
80
+ whole program, and reverting an edit reuses the earlier results.
81
+ - Each law is planned from only the types and definitions it reaches, which
82
+ cuts planning time for the bundled examples by two thirds. Evidence
83
+ discharge plans laws the same way, so `lawspec evidence` reports the boundary
84
+ cases the generated tests use.
85
+
86
+ ### Changes to generated tests
87
+
88
+ - Boundary search for constrained data took its depth from the number of data
89
+ types in the whole program, and seeded scalar boundaries with literals from
90
+ every type's constructor predicates. Both now come from the types the law
91
+ reaches, so adding an unrelated type no longer changes a law's tests.
92
+ Regenerating can change the boundary cases of laws over indexed families and
93
+ constrained data; among the bundled examples, `indexed_arithmetic`,
94
+ `domain_modeling` and the shop package's domain unit gain or lose cases.
95
+
3
96
  ## 0.17.1
4
97
 
5
98
  ### Faster compilation
package/README.md CHANGED
@@ -30,7 +30,7 @@ Node 22+ and the selected target's build tools are required. No Haskell
30
30
  toolchain is needed. The reference platforms are macOS and Linux.
31
31
 
32
32
  ```sh
33
- npm install --save-dev lawspec@0.17.1
33
+ npm install --save-dev lawspec@0.17.5
34
34
  npx lawspec --version
35
35
  ```
36
36
 
@@ -40,8 +40,8 @@ LawSpec can create `package.json` and its test script:
40
40
  ```sh
41
41
  mkdir lawspec-example
42
42
  cd lawspec-example
43
- npm exec --package=lawspec@0.17.1 -- lawspec init --target javascript
44
- npm install --save-dev lawspec@0.17.1
43
+ npm exec --package=lawspec@0.17.5 -- lawspec init --target javascript
44
+ npm install --save-dev lawspec@0.17.5
45
45
  npx lawspec check
46
46
  npx lawspec explain 'example.atoi_codec::itoa and then atoi yields a'
47
47
  npx lawspec doctor
package/bin/lawspec.mjs CHANGED
@@ -1,12 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
  // Generated from templates/npm/bin/lawspec.mjs by lawspec-dev generate. Do not edit.
3
- import { readFile, mkdir, readdir, stat } from "node:fs/promises";
3
+ import { readFile, mkdir, readdir, rm, stat, writeFile } from "node:fs/promises";
4
+ import { createHash } from "node:crypto";
4
5
  import path from "node:path";
5
6
  import { createCompiler } from "../api.mjs";
6
7
  import { targets, templates, commands, setup } from "../templates.mjs";
7
8
  import { generateExamples } from "../examples-command.mjs";
8
9
  import { showScalar } from "../scalars.mjs";
9
10
  import { doctor } from "../doctor.mjs";
11
+ import { spawn } from "node:child_process";
12
+ import { environmentDigest, executedTests, invocations, lawKeys, projectDigest } from "../test-command.mjs";
10
13
  import {
11
14
  readOptional,
12
15
  planWrites,
@@ -14,18 +17,18 @@ import {
14
17
  atomicWrite,
15
18
  safePath,
16
19
  } from "../files.mjs";
17
- const VERSION = "0.17.1";
20
+ const VERSION = "0.17.5";
18
21
  const args = process.argv.slice(2);
19
22
  const verb = args.shift();
20
23
  const options = {};
21
24
  const positional = [];
22
25
  for (let i = 0; i < args.length; i++) {
23
26
  const arg = args[i];
24
- if (["--target", "--project", "--config", "--output", "--machine-bits", "--example"].includes(arg)) {
27
+ if (["--target", "--project", "--config", "--output", "--machine-bits", "--example", "--seed"].includes(arg)) {
25
28
  if (!args[i + 1] || args[i + 1].startsWith("--"))
26
29
  throw new Error(`Missing value for ${arg}`);
27
30
  options[arg.slice(2)] = args[++i];
28
- } else if (["--dry-run", "--check", "--json", "--minify"].includes(arg))
31
+ } else if (["--dry-run", "--check", "--json", "--minify", "--no-cache", "--fresh"].includes(arg))
29
32
  options[arg.slice(2)] = true;
30
33
  else if (arg.startsWith("--")) throw new Error(`Unknown option: ${arg}`);
31
34
  else positional.push(arg);
@@ -237,6 +240,130 @@ function explainExamples(law) {
237
240
  ex.expectations.map(e => ` expect ${showAssertion(e)}`).join("\n")
238
241
  ).join("\n");
239
242
  }
243
+ // The compiler keeps work between runs in .lawspec/cache, in one folder per
244
+ // compiler build, so a different build never reads another's entries. The
245
+ // WebAssembly compiler sees only the working directory. A command that fails
246
+ // removes the .lawspec folder if it created it, leaving the project as it was.
247
+ let createdState = null;
248
+ async function cacheDirectory(config) {
249
+ if (options["no-cache"] || config.cache === false) return undefined;
250
+ const folder = path.join(configRoot, ".lawspec", "cache");
251
+ const relative = path.relative(process.cwd(), folder);
252
+ if (relative.startsWith("..") || path.isAbsolute(relative)) return undefined;
253
+ const build = (await buildDigest()).slice(0, 16);
254
+ const state = path.join(configRoot, ".lawspec");
255
+ if ((await readOptionalDirectory(state)) === null) createdState = state;
256
+ await mkdir(path.join(folder, build), { recursive: true });
257
+ await writeFile(path.join(folder, ".gitignore"), "*\n");
258
+ for (const entry of await readdir(folder))
259
+ if (entry !== build && entry !== ".gitignore")
260
+ await rm(path.join(folder, entry), { recursive: true, force: true });
261
+ return path.join(relative, build).split(path.sep).join("/");
262
+ }
263
+ // The compiler build, by the digest of its WebAssembly module.
264
+ let buildDigestValue = null;
265
+ async function buildDigest() {
266
+ buildDigestValue ??= createHash("sha256")
267
+ .update(await readFile(new URL("../core.wasm", import.meta.url)))
268
+ .digest("hex");
269
+ return buildDigestValue;
270
+ }
271
+ // lawspec test: run the tests of the laws whose results may have changed,
272
+ // and record each passing law's key and seed (see test-command.mjs).
273
+ async function runTests(compiler, input, selected, roots, config) {
274
+ const seed = options.seed ?? String(1 + Math.floor(Math.random() * 2147483646));
275
+ const offline = process.env.LAWSPEC_OFFLINE === "1";
276
+ const build = await buildDigest();
277
+ const summaries = [];
278
+ for (const [i, target] of selected.entries()) {
279
+ const root = roots[i];
280
+ const planned = diagnostics(await compiler.planGeneration({
281
+ ...input, target: target.language, sourceDir: target.sourceDir, testDir: target.testDir,
282
+ nativeBindings: target.nativeBindings, minify: options.minify === true,
283
+ }));
284
+ const pending = await planWrites(root, planned.files);
285
+ if (pending.changes.length)
286
+ throw new Error(`${target.language}: generated files are out of date; run lawspec generate${options.minify ? " --minify" : ""}`);
287
+ const report = await doctor(target, root, planned.files);
288
+ if (!report.ok) throw new Error(`${target.language}: ${report.message}\n${report.instructions}`);
289
+ const generated = new Set(planned.files.filter((f) => f.ownership === "generated").map((f) => f.path));
290
+ const keys = lawKeys({
291
+ build, target, machineBits: input.machineBits, minify: options.minify === true,
292
+ tests: planned.tests, files: planned.files,
293
+ environment: await environmentDigest(root, report),
294
+ project: await projectDigest(root, generated),
295
+ });
296
+ const resultsFile = path.join(configRoot, ".lawspec", "results",
297
+ `${target.language}-${createHash("sha256").update(root).digest("hex").slice(0, 12)}.json`);
298
+ const previous = JSON.parse((await readOptional(resultsFile)) ?? '{"version":1,"laws":{}}');
299
+ const stale = planned.tests.filter((entry) => options.fresh || previous.laws[entry.law]?.key !== keys.get(entry.law));
300
+ const passed = [];
301
+ const unrun = [];
302
+ let failed = false;
303
+ const scratch = path.join(configRoot, ".lawspec", "reports", target.language);
304
+ await rm(scratch, { recursive: true, force: true });
305
+ await mkdir(scratch, { recursive: true });
306
+ await writeFile(path.join(path.dirname(scratch), ".gitignore"), "*\n");
307
+ for (const run of stale.length ? invocations(target, stale, { offline, scratch }) : []) {
308
+ const since = Date.now() - 1000;
309
+ const { ok, output } = await spawned(run.command, run.args, root,
310
+ { ...process.env, ...run.env, LAWSPEC_SEED: seed, HSPEC_SEED: seed }, run.report?.kind === "go-json");
311
+ if (!ok) { failed = true; break; }
312
+ // A runner whose filter matched nothing reports success, so a law
313
+ // counts as passed only if the runner's report shows its tests ran.
314
+ const executed = new Set((await executedTests(run.report, output, root, since)).flatMap(run.ran ?? (() => [])));
315
+ passed.push(...run.laws.filter((law) => executed.has(law)));
316
+ unrun.push(...run.laws.filter((law) => !executed.has(law)));
317
+ }
318
+ if (unrun.length) failed = true;
319
+ const laws = Object.fromEntries(planned.tests.filter((entry) => previous.laws[entry.law]).map((entry) => [entry.law, previous.laws[entry.law]]));
320
+ for (const entry of passed) laws[entry.law] = { key: keys.get(entry.law), seed: Number(seed), passed: new Date().toISOString() };
321
+ await mkdir(path.dirname(resultsFile), { recursive: true });
322
+ await writeFile(path.join(path.dirname(resultsFile), ".gitignore"), "*\n");
323
+ await writeFile(resultsFile, JSON.stringify({ version: 1, laws }, null, 2) + "\n");
324
+ summaries.push({ target: target.language, seed: Number(seed), ran: stale.map((e) => e.law),
325
+ unchanged: planned.tests.length - stale.length, ok: !failed,
326
+ ...(unrun.length ? { unrun: unrun.map((e) => e.law) } : {}) });
327
+ }
328
+ output(options.json ? summaries : summaries.map((s) =>
329
+ `${s.target}: ${s.ran.length ? `ran ${s.ran.length} law(s) with seed ${s.seed}` : "nothing to run"}` +
330
+ `, ${s.unchanged} unchanged since their last passing run.${s.ok ? "" : " FAILED"}` +
331
+ (s.unrun ? `\nNo tests ran for ${s.unrun.join(", ")}; the runner matched none of their tests.` : "")).join("\n"));
332
+ if (summaries.some((s) => !s.ok)) process.exitCode = 1;
333
+ }
334
+ // Run a native test command, showing its output (on stderr with --json) and
335
+ // keeping it. Go's JSON events are shown as the text they carry.
336
+ function spawned(command, args, cwd, env, goJson = false) {
337
+ return new Promise((resolve, reject) => {
338
+ const child = spawn(command, args, { cwd, env, stdio: ["ignore", "pipe", "pipe"] });
339
+ const shown = options.json ? process.stderr : process.stdout;
340
+ let output = "";
341
+ let pending = "";
342
+ child.stdout.on("data", (chunk) => {
343
+ const text = chunk.toString();
344
+ output += text;
345
+ if (!goJson) return shown.write(text);
346
+ pending += text;
347
+ const lines = pending.split("\n");
348
+ pending = lines.pop();
349
+ for (const line of lines) {
350
+ try { const event = JSON.parse(line); if (event.Output) shown.write(event.Output); }
351
+ catch { shown.write(line + "\n"); }
352
+ }
353
+ });
354
+ child.stderr.on("data", (chunk) => { output += chunk.toString(); process.stderr.write(chunk); });
355
+ child.on("error", reject);
356
+ child.on("close", (code) => resolve({ ok: code === 0, output }));
357
+ });
358
+ }
359
+ async function readOptionalDirectory(folder) {
360
+ try {
361
+ return await readdir(folder);
362
+ } catch (error) {
363
+ if (error.code === "ENOENT") return null;
364
+ throw error;
365
+ }
366
+ }
240
367
  async function main() {
241
368
  if (options['machine-bits'] !== undefined) {
242
369
  options.machineBits = Number(options['machine-bits']);
@@ -244,7 +371,7 @@ async function main() {
244
371
  }
245
372
  if (!verb || ["help", "--help", "-h"].includes(verb)) {
246
373
  output(
247
- "LawSpec " + VERSION + "\nUsage: lawspec init --target <language> [--project <directory>] [--minify]\n lawspec check | doctor | explain <unit>::<law> | generate\n lawspec evidence [<unit> | <unit>::<declaration>]\n lawspec package [--project <package directory>]\n lawspec examples [--example payments] [--target <language>] [--output <directory>]\nOptions: --config <path>, --target <language>, --machine-bits <32|64>, --json\nGeneration: --dry-run, --check, --minify\nTargets: " +
374
+ "LawSpec " + VERSION + "\nUsage: lawspec init --target <language> [--project <directory>] [--minify]\n lawspec check | doctor | explain <unit>::<law> | generate\n lawspec evidence [<unit> | <unit>::<declaration>]\n lawspec test [--target <language>] [--fresh] [--seed <n>]\n lawspec package [--project <package directory>]\n lawspec examples [--example payments] [--target <language>] [--output <directory>]\nOptions: --config <path>, --target <language>, --machine-bits <32|64>, --json, --no-cache\nGeneration: --dry-run, --check, --minify\nTargets: " +
248
375
  targets.join(", "),
249
376
  );
250
377
  return;
@@ -286,11 +413,15 @@ async function main() {
286
413
  }
287
414
  if (options.output) throw new Error("--output is only supported by examples");
288
415
  if (options.example) throw new Error("--example is only supported by examples");
289
- if (options.minify && !["init", "generate", "examples"].includes(verb))
290
- throw new Error("--minify applies to init, generate and examples");
416
+ if (options.minify && !["init", "generate", "examples", "test"].includes(verb))
417
+ throw new Error("--minify applies to init, generate, test and examples");
418
+ if ((options.fresh || options.seed !== undefined) && verb !== "test")
419
+ throw new Error("--fresh and --seed apply to test");
420
+ if (options.seed !== undefined && !/^[0-9]+$/.test(options.seed))
421
+ throw new Error("--seed must be a whole number");
291
422
  if (verb === "init") return init();
292
423
  if (verb === "package") return packageCommand();
293
- if (!["check", "doctor", "evidence", "explain", "generate"].includes(verb))
424
+ if (!["check", "doctor", "evidence", "explain", "generate", "test"].includes(verb))
294
425
  throw new Error(`Unknown command: ${verb}`);
295
426
  const config = JSON.parse(await readFile(configFile, "utf8"));
296
427
  if (
@@ -304,7 +435,7 @@ async function main() {
304
435
  const selected = config.targets.filter(
305
436
  (t) => !options.target || t.language === options.target,
306
437
  );
307
- if (["doctor", "generate"].includes(verb) && !selected.length)
438
+ if (["doctor", "generate", "test"].includes(verb) && !selected.length)
308
439
  throw new Error("No matching configured target");
309
440
  const roots = selected.map((t) => path.resolve(configRoot, t.root));
310
441
  if (new Set(roots).size !== roots.length)
@@ -327,7 +458,10 @@ async function main() {
327
458
  return;
328
459
  }
329
460
  if (config.machineBits !== undefined && ![32, 64].includes(config.machineBits)) throw new Error("machineBits must be 32 or 64");
461
+ if (config.cache !== undefined && typeof config.cache !== "boolean") throw new Error("cache must be true or false");
462
+ const cache = await cacheDirectory(config);
330
463
  const input = {
464
+ ...(cache === undefined ? {} : { cacheDirectory: cache }),
331
465
  sources: await sources(config),
332
466
  ...(await packageInput(config, configRoot)),
333
467
  generation: config.generation,
@@ -411,6 +545,7 @@ async function main() {
411
545
  );
412
546
  return;
413
547
  }
548
+ if (verb === "test") return runTests(compiler, input, selected, roots, config);
414
549
  if (options["dry-run"] && options.check)
415
550
  throw new Error("--dry-run and --check are mutually exclusive");
416
551
  const artifacts = [];
@@ -461,7 +596,8 @@ async function main() {
461
596
  if (options.check && plans.some((p) => p.changes.length))
462
597
  process.exitCode = 1;
463
598
  }
464
- main().catch((error) => {
599
+ main().catch(async (error) => {
600
+ if (createdState !== null) await rm(createdState, { recursive: true, force: true });
465
601
  if (options.json)
466
602
  output({
467
603
  diagnostics: error.diagnostics || [
package/build.json CHANGED
@@ -56,10 +56,13 @@
56
56
  "src/LawSpec/Core/Value.hs",
57
57
  "src/LawSpec/CoreEmit.hs",
58
58
  "src/LawSpec/CoreNativeScalarEmit.hs",
59
+ "src/LawSpec/CorePersist.hs",
59
60
  "src/LawSpec/CoreScalarEmit.hs",
60
61
  "src/LawSpec/Data.hs",
61
62
  "src/LawSpec/DataNames.hs",
62
63
  "src/LawSpec/DefinitionTotality.hs",
64
+ "src/LawSpec/Dependencies.hs",
65
+ "src/LawSpec/Digest.hs",
63
66
  "src/LawSpec/Discharge.hs",
64
67
  "src/LawSpec/Domain.hs",
65
68
  "src/LawSpec/DomainModel.hs",
@@ -104,6 +107,7 @@
104
107
  "src/LawSpec/NativeRequest.hs",
105
108
  "src/LawSpec/Packages.hs",
106
109
  "src/LawSpec/Parser.hs",
110
+ "src/LawSpec/Persist.hs",
107
111
  "src/LawSpec/PortableGenerator.hs",
108
112
  "src/LawSpec/PortableTestHelpers.hs",
109
113
  "src/LawSpec/Prelude.hs",
@@ -124,6 +128,7 @@
124
128
  "src/LawSpec/Scaffold.hs",
125
129
  "src/LawSpec/Scalar.hs",
126
130
  "src/LawSpec/SpecializeDefinitions.hs",
131
+ "src/LawSpec/TestManifest.hs",
127
132
  "src/LawSpec/Testing.hs",
128
133
  "src/LawSpec/WebData.hs",
129
134
  "src/LawSpec/WebDefinitions.hs",
@@ -140,8 +145,8 @@
140
145
  ],
141
146
  "digests": {
142
147
  "dev/Gen/Embed.hs": "41cd18500c1a8c9bdb51011ab4c74817f8e04b655aa10d9894aa1b93a3fa858b",
143
- "lawspec.cabal": "dde1ada13d7a201ea5107f0d042de926ac8d27a00c199af4c46b29c85edc9ba0",
144
- "package.yaml": "a7f0583e62b8107137d22f89e3c596c0a76c71cfbb14f415a3db3d386c82e58a",
148
+ "lawspec.cabal": "7f6395dbb39d2baeff82eace1a6ef176f6b825297b772d21e6d3fe9b88db0ec2",
149
+ "package.yaml": "9d6cee849b08b1df8161d36390876dc2dc6aa33c34844588d6a3cd9fb0e81699",
145
150
  "runtime/LawSpecCodecs.hs": "1b3f6b40ad49928cf5e9386e06bc2992c9f1271754351b9fa3075e50346ef03b",
146
151
  "runtime/LawSpecCollectionCodecs.hs": "74caa786801c5142ed040897c7ebb7373abf49ee49e02af53e466646fb624f47",
147
152
  "runtime/LawSpecDataStrategies.hs": "9cc5b98476364a6c255dc3eb40c53d65b4a9d4ab0c3961a806b3515a8d5e8f7f",
@@ -166,17 +171,17 @@
166
171
  "runtime/lawspec_schema.mjs": "d77abea1a9dcb03e4a6c6eef6509971d8599fac9acdefa9b9e4b89b8d0fc5226",
167
172
  "runtime/lawspec_schema.py": "daed20d27168970350ef0b63b9cb2e566bd00598922acb4071d863c076e787ba",
168
173
  "runtime/lawspec_strategies.rs": "5e991a45548811fef1728e1e9b9f12f76ee4cc7cb9c3339eab79bc4cf5f54f6b",
169
- "runtime/rust/Cargo.lock": "aaff0a41f104cc53b8ee54ccb66df2a7f6134de526b3a2e4d40a08f71ac4012c",
170
- "runtime/rust/Cargo.toml": "b42d1d443abac5eda8a05194aa3afc5b06deefe934f61a814d3ee81a7058dee8",
171
- "src/LawSpec/Api.hs": "b93bc7c1f56cf04a7d1f2be78f1d78511784df09423c67fcc16521ef9ff38738",
174
+ "runtime/rust/Cargo.lock": "6a04cf0315ad2920129cdc61350098d8edc69d8ca17c9e8829c799560ec46db9",
175
+ "runtime/rust/Cargo.toml": "d9dc489e41368122f5d13edd26383a6c27f33064d701c816fdc7c94878e7d8c5",
176
+ "src/LawSpec/Api.hs": "c0cb09ea2754f79138697e6ee6b4817a43d8343cb410380389d6b321c2feb07b",
172
177
  "src/LawSpec/Backend.hs": "caf45afb73e7455dd801195b8b117ca7e4664ac4babc6ef0732e06faf9e64fcb",
173
178
  "src/LawSpec/Capabilities.hs": "ab457f3da440a237ee731d664b94d95a0cc1fa4d8be4d4d0403a61ebcf98e310",
174
179
  "src/LawSpec/Code/Doc.hs": "9e3b70f85deb1dcbce385af1d0cd4bea2dfa8a2d806d54745d4bb437406673e5",
175
180
  "src/LawSpec/Code/JavaScript.hs": "77bf27dcc210216e4739f68c4709f556f80130ab83b3b9387ac4a2421e790910",
176
181
  "src/LawSpec/Collections.hs": "f8cc2978b6690709deb421ee22df37985c80e5b06064f819a193d6b912328ee1",
177
182
  "src/LawSpec/Common.hs": "107612a8aaa787488413acf9c1a56622004d3bff251db89b99928343e6070883",
178
- "src/LawSpec/Compile.hs": "ec8a077041ec65ae908cf5fe48ed3cd15200f613b5cee7a4331f2f0bd9cb66ca",
179
- "src/LawSpec/Core.hs": "faa5abce4be809298212dee0fbdf1b65c992a950e23801d9509630580e615163",
183
+ "src/LawSpec/Compile.hs": "d46086c7fded4fa6f4edcf0f66723c3df44d5093a05511290d4f5e8d394741ed",
184
+ "src/LawSpec/Core.hs": "ebf780f4552bc3ad304823b7eb7c2560b925cea3f2b2f9322467abae14c2947d",
180
185
  "src/LawSpec/Core/DefinitionContracts.hs": "b7f60f038b231187ecf898e585ae1a8fb1fc113bb55bad6d1bb2660350fd969e",
181
186
  "src/LawSpec/Core/Definitions.hs": "8e0d1d7127f9d4872f2464b4af50b0f286823d5f0f203baf38fb3c316d766140",
182
187
  "src/LawSpec/Core/Eval.hs": "26c518cf3db1f395f69353cb373e1aacf7f1a0ce81d3e17b15878421e9625a8b",
@@ -191,57 +196,61 @@
191
196
  "src/LawSpec/Core/Totality.hs": "5e76100466cf4a157b9eda36738806af836a5bda949f5d568d7bf5155fa8858a",
192
197
  "src/LawSpec/Core/Types.hs": "04d9c093fcc0d84e2864c8a3b69d5fe318a92c60b32844048198f1b12fe1b6fb",
193
198
  "src/LawSpec/Core/Validate.hs": "74c2a51eb913f8414268064f22d2d5d97ebfb0e4797e146b229076c29ac38726",
194
- "src/LawSpec/Core/Value.hs": "a1e0745154c54498d7e164a89546ef2a56afade05a1d362e1c63986245ad2774",
195
- "src/LawSpec/CoreEmit.hs": "da5577b7022315df25a76b41911840f98174025cd4ce96f4c51dfadb4eb7302c",
199
+ "src/LawSpec/Core/Value.hs": "52fedabbc07c8c65acc5be1efc7b4860bee47b58931ef76d26fcbfc8a280bf41",
200
+ "src/LawSpec/CoreEmit.hs": "9d93013a5fef60011d9428d43f484cbc152a7bb7f8c999be2b4ef5828d843bc6",
196
201
  "src/LawSpec/CoreNativeScalarEmit.hs": "5a5d145a18f596682a3dc3dacb009268d48c384c2f2ca620b503268096a66940",
197
- "src/LawSpec/CoreScalarEmit.hs": "0493aa132599aca36a773717252281c2ab9c2aeb6ac1c90269dfbea50aaa36b1",
202
+ "src/LawSpec/CorePersist.hs": "682776b07e041e01470e0e2f16e50ce0531eccef2d5f5cb483497c41b212b937",
203
+ "src/LawSpec/CoreScalarEmit.hs": "59a90297b51c8073a6e4b229aab4bfb0eb970a0b513c7ecca973a29dd0f96f0a",
198
204
  "src/LawSpec/Data.hs": "f659f4e86f1009c4806334a45686970dde2efa2641585f997a7beba01d0e6f2d",
199
205
  "src/LawSpec/DataNames.hs": "2eeb0d215131981a2271725a50c21dce44c7146a167025eb239a83922fdecaf6",
200
206
  "src/LawSpec/DefinitionTotality.hs": "adf00236e0e1b1cad4299793ced5f9047dbc2321d3c2f9ba040bac30d1a87c73",
201
- "src/LawSpec/Discharge.hs": "bd1acbddecf1f060aaaad1a6796825321c56b434d556e9873eb6c9d99459fdb7",
207
+ "src/LawSpec/Dependencies.hs": "918d55923c29c66a5a82dc346bad9c6f539965bc06212b2a54d03d65d9df599f",
208
+ "src/LawSpec/Digest.hs": "ba8128e36856d5fb0d2345779fd949b11042af688a0d8cee63e5ae8818cef7ca",
209
+ "src/LawSpec/Discharge.hs": "e0c6760fa483e79782eb944c6208a815f2ff073428a5b90bbbb41aafca830bfe",
202
210
  "src/LawSpec/Domain.hs": "222d15f0012ae630802238a6d7e1ee78d1e718b599f5ebb5a1ddc4e8d29d68c3",
203
211
  "src/LawSpec/DomainModel.hs": "835e6e31c9565bd624c1139ead71ad65c1065ee660457ae365522f7ed78f7939",
204
212
  "src/LawSpec/Elaboration.hs": "aade19ada1b9b944d1d5864b1ada61f89a57a675d7e8de9e2f3bc6b6f6d84b00",
205
213
  "src/LawSpec/Emit.hs": "9f34f5765915a2a12a66a6dca647ddaef9289372956802c6d99cf0cfec447c7a",
206
214
  "src/LawSpec/Eval.hs": "b87a786ed7a512c60e00a037a1a36738933518aafa255babaa8b1b42dbb8ff6d",
207
215
  "src/LawSpec/Flow.hs": "830b9d59b94f26a05687bd5baed06b4ecbf1f47c6a634766810d3dd2a44647cd",
208
- "src/LawSpec/Frontend.hs": "5f2bb4f3580b8fca6d899a0b40000da653fb7e76f11f8c8df271eb023ad5b278",
216
+ "src/LawSpec/Frontend.hs": "85d631cb6246efcb14814177d1620ffd5f67964de725a8af241a11f1f30f5da3",
209
217
  "src/LawSpec/GoData.hs": "ffd2f91688e4efdbd65033b88ad55032278f9b29d8027f6dc9e4b2c3eb9bfbc0",
210
218
  "src/LawSpec/GoDefinitions.hs": "907fb5ba9935391fa640c0cf6d037db78d270467a8b93e1190a9d511f03561ff",
211
219
  "src/LawSpec/GoExpr.hs": "67ef004e97074976e0fd137dfef8d417efe8de3f7d5c3c08293874d30d89e9d0",
212
220
  "src/LawSpec/GoNativeBinding.hs": "1ad8ea4cec6187c7e6005651c0edeec69e196eb329fb958c833da7751225aa1b",
213
- "src/LawSpec/GoProperties.hs": "a6118510ae472de8cbeb0f1dfb025f23a84123bccc5a53af20ad39470851e639",
221
+ "src/LawSpec/GoProperties.hs": "a6ff4745bddd931506ae5d9da70f1af73b5d8c79a47c2e56246f82f98a5fff93",
214
222
  "src/LawSpec/GoTestHelpers.hs": "dee55ee8505370e932773b8c685f4a1f380129e6f43f8806bf1e82efb99451b1",
215
223
  "src/LawSpec/GoTypeRefs.hs": "7f239f5ac3ac8bd21c8f76c328049f7715d8562ee1382befa0a58abd4f15f726",
216
224
  "src/LawSpec/HaskellData.hs": "8ca1f1a353972a28b3d044c3763243cd8a2abf3e2cdb3b15b6112d8a7edf9da2",
217
225
  "src/LawSpec/HaskellDefinitions.hs": "9481901b9f1753dbfe90dcc859275eaab474acdb2f41035cd14e9d03cce45440",
218
226
  "src/LawSpec/HaskellExpr.hs": "f7ef064ac6700c027de4bd71bddeb3236853232cf7a39bed61de16153539b401",
219
227
  "src/LawSpec/HaskellNativeBinding.hs": "9f98aa0c8659b572bd6486a0e29c4692bc6432db8639fa74a09bbf1b771bbfa6",
220
- "src/LawSpec/HaskellProperties.hs": "3f99a4083b602e3a197446614f66f127384b2babd6039c5d3189a81c75329db4",
228
+ "src/LawSpec/HaskellProperties.hs": "1402eaff5984a1a012cd817b33ae9c7ebf634d29f35d4372e90d76ac56f2ff41",
221
229
  "src/LawSpec/HaskellTestHelpers.hs": "51e59b2abc9e85455e3c8e2c6baadb27e5d319081cb730d2ce56be5dc8053897",
222
230
  "src/LawSpec/HaskellTypeRefs.hs": "2225b2a5e2ab3662e7202d23b24f4d6db48353b35ae28df8acd2b92fd2b97574",
223
231
  "src/LawSpec/Imports.hs": "1182894623b69e777531706c013b5ecd9995c51dd8c8b969c1807a5a103bf2da",
224
- "src/LawSpec/IndexTerm.hs": "65e7942306f08683ec9f284f76b10ad271f8a909b1ec721da04f6275c9a1d20e",
232
+ "src/LawSpec/IndexTerm.hs": "1c694f279b934e7b853c0028158c2754048928deb45fb7d65abc1d98da382bcb",
225
233
  "src/LawSpec/Indexed.hs": "1e7ed53653cabc097f75dcf350c81facf9feb30af73f3e21f9344665fc316387",
226
234
  "src/LawSpec/Inference.hs": "8d3a8853bd691329d6d1cf0cdde9e4e8f8c895f5be944f2e77e9df348d1aa0eb",
227
235
  "src/LawSpec/JavaData.hs": "8afc712aed51240921cd6830b5d21ab029f71cc5cb0de56ca522eadd94ccb600",
228
236
  "src/LawSpec/JavaDefinitions.hs": "ba771b59878d8780613d1d40094597e8dca0478ccde11188a39df77667a01dab",
229
237
  "src/LawSpec/JavaExpr.hs": "fb1d3e64f3288e557720dead7738eb4f2a59d4563e5be4a742e1582829f19d3e",
230
238
  "src/LawSpec/JavaNativeBinding.hs": "9eb52b3be19badda078069bb3d6813d72cad4f0a9bfa708f7404e44201d3c352",
231
- "src/LawSpec/JavaProperties.hs": "7438793af96d9e9e2072670c4bc20f56729c85e054d598b5ad4e991bfdf094a1",
239
+ "src/LawSpec/JavaProperties.hs": "5a28381de13d49001540e9e5c8a67268394b62dfba3561cac8c2da735e62e775",
232
240
  "src/LawSpec/JavaTestHelpers.hs": "e6f4b9bbb7e5f07ece6ab1845e12aa661e62e8b926680b11454223fc3ec1523d",
233
241
  "src/LawSpec/KotlinData.hs": "ca3bad4dca9fcd604cd39ec713ef8ed38966aaf24b1d6b33d88d405bfc80641d",
234
242
  "src/LawSpec/KotlinDefinitions.hs": "97d7d407d4bbdb4ce16035d607dbbcb8e3d6f5db513f2123a2c269e3dc6d2b38",
235
243
  "src/LawSpec/KotlinExpr.hs": "20312f0774f1d0832a21a19b93c8103e2791ecd32a827d8e9c4f2b4830a996a0",
236
244
  "src/LawSpec/KotlinNativeBinding.hs": "1aec7854758f07a4d2288de13931fbb88ef32220f85d3c84fe8233ad67b6d095",
237
- "src/LawSpec/KotlinProperties.hs": "5c7289c97cc915cbc3432eb4b08a2fefbe786af4d6591af4b59923aa9d6a2075",
245
+ "src/LawSpec/KotlinProperties.hs": "da48d7cfef557d8453c49a1f1a664edbf3668ccfc86541adc65799ac6302b9af",
238
246
  "src/LawSpec/KotlinTestHelpers.hs": "74810d65faafc6ed4d64b1fb0596cda4186e586b7144a7441641b798795bc324",
239
- "src/LawSpec/Memo.hs": "35a0d0f2ebcf649771dd418c3609fd3c1fc9bfe7f787ffe64102cc6dab9f0fc6",
240
- "src/LawSpec/Model.hs": "72fae874b4a5aa98057254fc1b508df3f71ec8587740bc7c18ea29490526137b",
247
+ "src/LawSpec/Memo.hs": "1230a08b003cc6eee0db951b55a93f9ec573e5b6752c63d65d6c3487927b0b4e",
248
+ "src/LawSpec/Model.hs": "7922e06bc600ea9400e6ec8c17ef4412e2ba8018b8d3a37a372e8bae4b6d8cb7",
241
249
  "src/LawSpec/NativeBinding.hs": "33959b0fd432ad4150f3b685f6438e284b801c2a59d9ef3132486a1cc7c8925a",
242
250
  "src/LawSpec/NativeRequest.hs": "f8200c36725859ea32374655951f7a45e2b3342b159f9f6c88b5f9a2a6331897",
243
251
  "src/LawSpec/Packages.hs": "161fc68a9959a80762ca4ece405240351e3180ea4dbb2bf148eaca6562fb7c30",
244
252
  "src/LawSpec/Parser.hs": "953e907c51e12724085a6ce0504c767a8d622acf7ad4479913ed2cb86017251e",
253
+ "src/LawSpec/Persist.hs": "d7f63a1205782c2ac0d71b737ade3ef90041403f3876b0f3a38c2b29d60922f2",
245
254
  "src/LawSpec/PortableGenerator.hs": "69d457e39f539c77fc7a4c08205e75352bbecd9dfdff031a283a39bf44b22d49",
246
255
  "src/LawSpec/PortableTestHelpers.hs": "8d98184c92a34b431f2a820cef3ea735b0cec3a52504f519b3bb06cb5174017c",
247
256
  "src/LawSpec/Prelude.hs": "b1e155c12f58e7c346551a0c65c5d5af76d045b3f1625977ca2a5d1c97cb8c46",
@@ -255,14 +264,15 @@
255
264
  "src/LawSpec/RuntimeSources.hs": "b984cd8635be4109ea79fff5becb9accb1379f5322aaf6c50938264f01ba47b6",
256
265
  "src/LawSpec/RustData.hs": "b8bb35f2cc5835c811e01e8bbbe172f483ab2620e1e8e331cdfaf6342c23e7f1",
257
266
  "src/LawSpec/RustDefinitions.hs": "8211ad8c4db088ae658918b5172a666303aaf1bfe3f29bdd0b520a77015b2892",
258
- "src/LawSpec/RustEmit.hs": "a57aaef4f6980a4d00b6fee1caf099b5ee317f1f8f6cfc9c480f68a431d39942",
267
+ "src/LawSpec/RustEmit.hs": "bc1fd5c8ca25b23eb23f3e4fc54cdb9fc8ee53f6fc626732483694cc0ad9cc3f",
259
268
  "src/LawSpec/RustExpr.hs": "04b2ef81417b811c7b98a98acdadab4e588ca8757964a63ba8dc5936c36479e6",
260
269
  "src/LawSpec/RustNativeBinding.hs": "d50d1fb10591ee86129ae49b38a343148c084479e450eef3b320e1efdd55245d",
261
270
  "src/LawSpec/RustNativeGenerators.hs": "a3b1484d9ff0008e4f961aa81d0aa51da57ec0cd7909124e80c98d56aacc8ce9",
262
271
  "src/LawSpec/Scaffold.hs": "217328445923b9e339428dd542ce9b910c26ed132c31d1ef083de73763b749f9",
263
- "src/LawSpec/Scalar.hs": "c49180c9de3d9549dbfa715a0e21868badc2ea78357381be883026c71b477a44",
272
+ "src/LawSpec/Scalar.hs": "8ff178cbce4aa514f4b770e65efd471461cc12812e854d95f48b0dd54f0cc637",
264
273
  "src/LawSpec/SpecializeDefinitions.hs": "2bdd6d9b191941d869ef524659e02fed551499aaa2ea98c99323da03af113012",
265
- "src/LawSpec/Testing.hs": "1e0dcbfad6f504ad232ac846299be736492aec73239ee9918c4e8266baa47248",
274
+ "src/LawSpec/TestManifest.hs": "3c2018eea1528d047dff4c5fd2f353ee1ceb339cce7b1c32f0a2390df2d40ac8",
275
+ "src/LawSpec/Testing.hs": "3bb83c3e74de6f0a09b12736115e47b4db2244e2f749d640e063cfc0500f174c",
266
276
  "src/LawSpec/WebData.hs": "bbcd7d734ce3941d83cc455a9a2147b642f6111ebb34db9ef99dcb7a58b8c4ae",
267
277
  "src/LawSpec/WebDefinitions.hs": "579309c76b9303a3c9e456e1252f2d0881795210aa0b09104a00efdfe10e3e13",
268
278
  "src/LawSpec/WebExpr.hs": "0389dcd5cf7479dd23ef034b1012de6ebd70bf1dc9e3d90981dfb0ba2702596f",
@@ -274,10 +284,10 @@
274
284
  "wasm/app/Exports.hs": "4ecbdac8faa2449e6fc61b93c82e6278fa14374154f29b4dacf0eef433f06a47",
275
285
  "wasm/cabal.project": "021e560afdc5eb4cb7169e7119ecb8f92c9ee170245af909c94b612941bff5cc",
276
286
  "wasm/cabal.project.freeze": "733dbed3d2ecccb26e874fd58f136296dad772184deb1658c196b5d54a0814dc",
277
- "wasm/lawspec-wasm.cabal": "c624549c098df60abe2d1e83e4a69e1d311d7a73ba53e2174944f8814dd3d139",
278
- "npm/core.wasm": "9d5d3b367cdbe95924f20580b3638332b5f4a0e828b90ab3c01812422637ee00",
287
+ "wasm/lawspec-wasm.cabal": "21821a861d641b1156f824ea92313a59a8c32ac0812ae6ee728adc2cf3bb4b66",
288
+ "npm/core.wasm": "96c0b431747c457fc292221493e8d3b8b113488f48a1e832e5a41ba049e87913",
279
289
  "npm/core_jsffi.js": "88d136efe92f7cff5758c8fec8d9b6bbc9707fe37741cebeeb415fe34ce3d72b",
280
290
  "npm/api.mjs": "19e1624f91258c1397f3212faf65b407c62671b0fc5b118520e6a91f7ad7c6ba",
281
- "npm/index.d.ts": "2215087cc6628a2ddbdd573210c4f9021cffeb00c142d4f3ae1314fd59a397f6"
291
+ "npm/index.d.ts": "b6beef671c22633fdf369f584bfe9bc9bd0b281c54df06f1946970415e1e7793"
282
292
  }
283
293
  }
package/core.wasm CHANGED
Binary file
package/index.d.ts CHANGED
@@ -256,6 +256,7 @@ export interface CheckRequest {
256
256
  package?: PackageVersion;
257
257
  dependencies?: Record<string, string>;
258
258
  packages?: Package[];
259
+ cacheDirectory?: string;
259
260
  }
260
261
 
261
262
  export interface GenerationRequest extends CheckRequest {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lawspec",
3
- "version": "0.17.1",
3
+ "version": "0.17.5",
4
4
  "description": "State the law once. Check it everywhere.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -0,0 +1,205 @@
1
+ // Generated from templates/npm/test-command.mjs by lawspec-dev generate. Do not edit.
2
+ // lawspec test: run the generated tests of the laws whose results may have
3
+ // changed since their last passing run, through each target's own runner.
4
+ //
5
+ // A law's result is keyed by everything it depends on: its plan key (the law
6
+ // and the Merkle digests of the types and definitions it reaches), the
7
+ // compiler build, the target's configuration, its unit's generated test file,
8
+ // the project's build and lock files, the toolchain the doctor reports and, for
9
+ // a law that calls adapters, every file in the target project that LawSpec
10
+ // did not generate. A passing run records each law's key and seed; a law runs
11
+ // again when its key changes or with --fresh.
12
+ import { createHash } from "node:crypto";
13
+ import { readdir, readFile, stat } from "node:fs/promises";
14
+ import path from "node:path";
15
+
16
+ // Folders that hold dependencies, build output or caches, not code under test.
17
+ const skipped = new Set([".git", ".lawspec", "node_modules", "dist", "build", "target", "out", ".gradle",
18
+ ".stack-work", "__pycache__", ".hypothesis", ".pytest_cache", ".venv", "venv", ".idea", ".vscode"]);
19
+ // Build and lock files, which choose the toolchain and dependencies.
20
+ const environmentFiles = ["package.json", "package-lock.json", "tsconfig.json", "pyproject.toml", "go.mod",
21
+ "go.sum", "pom.xml", "build.gradle", "build.gradle.kts", "settings.gradle", "settings.gradle.kts",
22
+ "Cargo.toml", "Cargo.lock", "stack.yaml", "stack.yaml.lock", "package.yaml"];
23
+
24
+ const digest = (value) => createHash("sha256").update(value).digest("hex");
25
+
26
+ // Every file in a project that LawSpec did not generate, by content.
27
+ export async function projectDigest(root, generated) {
28
+ const hash = createHash("sha256");
29
+ async function walk(folder) {
30
+ const entries = (await readdir(path.join(root, folder), { withFileTypes: true }))
31
+ .sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
32
+ for (const entry of entries) {
33
+ const relative = folder ? `${folder}/${entry.name}` : entry.name;
34
+ if (entry.isDirectory()) {
35
+ if (!skipped.has(entry.name) && !relative.endsWith("testdata/rapid")) await walk(relative);
36
+ } else if (entry.isFile() && !generated.has(relative)) {
37
+ hash.update(relative + "\0").update(await readFile(path.join(root, relative))).update("\0");
38
+ }
39
+ }
40
+ }
41
+ await walk("");
42
+ return hash.digest("hex");
43
+ }
44
+
45
+ export async function environmentDigest(root, report) {
46
+ const parts = [JSON.stringify(report ?? null)];
47
+ const names = (await readdir(root)).filter((name) => environmentFiles.includes(name) || name.endsWith(".cabal")).sort();
48
+ for (const name of names) parts.push(name, await readFile(path.join(root, name), "utf8"));
49
+ return digest(JSON.stringify(parts));
50
+ }
51
+
52
+ // The result key of each law in a target's test manifest.
53
+ export function lawKeys({ build, target, machineBits, minify, tests, files, environment, project }) {
54
+ const contents = new Map(files.map((file) => [file.path, file.content]));
55
+ const configuration = JSON.stringify({ ...target, root: undefined });
56
+ return new Map(tests.map((entry) => [entry.law, digest(JSON.stringify([
57
+ build, configuration, machineBits, minify, entry.key, digest(contents.get(entry.file) ?? ""),
58
+ environment, entry.callsAdapters ? project : null,
59
+ ]))]));
60
+ }
61
+
62
+ const regex = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
63
+ const without = (file, extension) => file.slice(0, -extension.length);
64
+ const groupBy = (entries, key) => {
65
+ const groups = new Map();
66
+ for (const entry of entries) groups.set(key(entry), [...(groups.get(key(entry)) ?? []), entry]);
67
+ return [...groups.entries()];
68
+ };
69
+
70
+ // The native invocations that run exactly the given laws' tests, each with
71
+ // the laws it covers and how to tell, from the runner's own report, which of
72
+ // them ran. Names are matched whole, so law1 never selects law10. `scratch`
73
+ // is a folder for reports.
74
+ export function invocations(target, entries, { offline = false, scratch = "." } = {}) {
75
+ const language = target.language;
76
+ const testDir = target.testDir;
77
+ const relativeTo = (file, defaultDir) => {
78
+ const directory = testDir || defaultDir;
79
+ return file.startsWith(directory + "/") ? file.slice(directory.length + 1) : file;
80
+ };
81
+ const tests = (entry) => [`law${entry.index}Example*`, `law${entry.index}Boundary*`, `law${entry.index}Property*`];
82
+ const kinds = (entry) => new RegExp(`^law${entry.index}(Example|Boundary|Property)`);
83
+ const className = (file, defaultDir, extension) => without(relativeTo(file, defaultDir), extension).replaceAll("/", ".");
84
+ if (language === "python")
85
+ return groupBy(entries, (e) => e.file).map(([file, laws], n) => {
86
+ const report = path.join(scratch, `pytest-${n}.xml`);
87
+ return { laws, command: target.python || "python3",
88
+ args: ["-m", "pytest", "-q", file, "-k", laws.map((e) => `test_law${e.index}_`).join(" or "), `--junitxml=${report}`],
89
+ report: { kind: "junit", files: [report] },
90
+ ran: (test) => laws.filter((e) => test.name.startsWith(`test_law${e.index}_`)) };
91
+ });
92
+ if (language === "javascript" || language === "typescript") {
93
+ const pattern = (e) => `^${regex(e.label)}( example: .*| property)?$`;
94
+ const files = [...new Set(entries.map((e) => language === "typescript"
95
+ ? `dist/${without(e.file, ".ts")}.js` : e.file))];
96
+ const report = path.join(scratch, "node.xml");
97
+ const run = { laws: entries, command: process.execPath,
98
+ args: ["--test", `--test-name-pattern=(${entries.map(pattern).join("|")})`,
99
+ "--test-reporter=spec", "--test-reporter-destination=stdout",
100
+ "--test-reporter=junit", `--test-reporter-destination=${report}`, ...files],
101
+ report: { kind: "junit", files: [report] },
102
+ ran: (test) => entries.filter((e) => new RegExp(pattern(e)).test(test.name)) };
103
+ return language === "typescript"
104
+ ? [{ laws: [], command: "npm", args: ["exec", "--", "tsc", "-p", "tsconfig.json"] }, run]
105
+ : [run];
106
+ }
107
+ if (language === "go")
108
+ return groupBy(entries, (e) => path.posix.dirname(e.file)).map(([directory, laws]) => ({
109
+ laws, command: "go",
110
+ args: ["test", "-json", "-count=1", `./${directory}`, "-run", `^TestLaw(${laws.map((e) => e.index).join("|")})(Example|Boundary|Property)`],
111
+ report: { kind: "go-json" },
112
+ ran: (test) => laws.filter((e) => new RegExp(`^TestLaw${e.index}(Example|Boundary|Property)`).test(test.name)) }));
113
+ if (language === "java") {
114
+ const byClass = groupBy(entries, (e) => className(e.file, "src/test/java", ".java"));
115
+ return [{ laws: entries, command: target.maven || "mvn",
116
+ args: [...(offline ? ["-o"] : []), "-B", "test", `-Dtest=${byClass.map(([name, laws]) => `${name}#${laws.flatMap(tests).join("+")}`).join(",")}`],
117
+ report: { kind: "junit", directory: "target/surefire-reports" },
118
+ ran: (test) => entries.filter((e) => test.classname === className(e.file, "src/test/java", ".java") && kinds(e).test(test.name)) }];
119
+ }
120
+ // Kotest names tests by string, which Gradle's method filters cannot
121
+ // select. Kotest's own filter selects them within each class: one pattern,
122
+ // matched against whole names, whose * becomes .*? (several comma-separated
123
+ // patterns must all match, so alternatives go in one group).
124
+ if (language === "kotlin")
125
+ return groupBy(entries, (e) => e.file).map(([file, laws]) => {
126
+ const filter = `(${laws.flatMap((e) => ["Example", "Boundary", "Property"].map((kind) => `law${e.index}${kind}`)).join("|")})*`;
127
+ const name = className(file, "src/test/kotlin", ".kt");
128
+ return { laws, command: target.gradle || "gradle",
129
+ args: [...(offline ? ["--offline"] : []), "--console=plain", "test", "--rerun", "--tests", name],
130
+ env: { "kotest.filter.tests": filter, kotest_filter_tests: filter },
131
+ report: { kind: "junit", directory: "build/test-results/test" },
132
+ ran: (test) => laws.filter((e) => test.classname === name && kinds(e).test(test.name)) };
133
+ });
134
+ if (language === "rust")
135
+ return groupBy(entries, (e) => e.file).map(([file, laws]) => ({
136
+ laws, command: "cargo",
137
+ args: ["test", ...(offline ? ["--offline"] : []), "--test", path.posix.basename(file, ".rs"), "--", "--exact",
138
+ ...laws.map((e) => `test_${e.index}`)],
139
+ report: { kind: "lines", pattern: /^test (test_\d+) \.\.\. (ok|FAILED)/ },
140
+ ran: (test) => laws.filter((e) => test.name === `test_${e.index}`) }));
141
+ if (language === "haskell") {
142
+ const module = (e) => without(relativeTo(e.file, "test"), "Spec.hs").replaceAll("/", ".");
143
+ const matches = entries.flatMap((e) => ["Example", "Boundary", "Property"].map((kind) => `${module(e)}/law${e.index}${kind}`));
144
+ return [{ laws: entries, command: "stack",
145
+ args: ["--no-terminal", "test", "--test-arguments", matches.map((m) => `--match ${m}`).join(" ")],
146
+ report: { kind: "hspec" },
147
+ ran: (test) => entries.filter((e) => test.classname === module(e) && kinds(e).test(test.name)) }];
148
+ }
149
+ throw new Error(`lawspec test does not support ${language}`);
150
+ }
151
+
152
+ // The tests a run executed, as {name, classname}, from the runner's report or
153
+ // output. Skipped tests are not counted.
154
+ export async function executedTests(report, output, root, since) {
155
+ if (report?.kind === "junit") {
156
+ const files = report.files ?? await reportFiles(path.join(root, report.directory), since);
157
+ const tests = [];
158
+ for (const file of files) {
159
+ const xml = await readFile(path.resolve(root, file), "utf8").catch(() => "");
160
+ for (const match of xml.matchAll(/<testcase\b([^>]*?)(\/>|>([\s\S]*?)<\/testcase>)/g)) {
161
+ if (/<skipped\b/.test(match[3] ?? "")) continue;
162
+ const attribute = (name) => unescapeXml(match[1].match(new RegExp(`\\b${name}="([^"]*)"`))?.[1] ?? "");
163
+ tests.push({ name: attribute("name").replace(/\(\)$/, ""), classname: attribute("classname") });
164
+ }
165
+ }
166
+ return tests;
167
+ }
168
+ if (report?.kind === "go-json")
169
+ return output.split("\n").flatMap((line) => {
170
+ try {
171
+ const event = JSON.parse(line);
172
+ return ["pass", "fail"].includes(event.Action) && event.Test ? [{ name: event.Test, classname: event.Package }] : [];
173
+ } catch { return []; }
174
+ });
175
+ if (report?.kind === "lines")
176
+ return output.split("\n").flatMap((line) => {
177
+ const match = line.match(report.pattern);
178
+ return match ? [{ name: match[1], classname: "" }] : [];
179
+ });
180
+ if (report?.kind === "hspec") {
181
+ // hspec prints each module, then its examples indented beneath it.
182
+ const tests = [];
183
+ let module = "";
184
+ for (const line of output.split("\n")) {
185
+ if (/^\S/.test(line) && !/^(Finished|Failures|Randomized|\d+ examples?)/.test(line)) module = line.trim();
186
+ const example = line.match(/^\s+(law\d+\S*?):?(?:\s.*)?\s\[[✔✘]\]\s*$/);
187
+ if (example) tests.push({ name: example[1], classname: module });
188
+ }
189
+ return tests;
190
+ }
191
+ return [];
192
+ }
193
+
194
+ async function reportFiles(directory, since) {
195
+ const names = await readdir(directory).catch(() => []);
196
+ const files = [];
197
+ for (const name of names.filter((n) => n.endsWith(".xml"))) {
198
+ const info = await stat(path.join(directory, name));
199
+ if (info.mtimeMs >= since) files.push(path.join(directory, name));
200
+ }
201
+ return files;
202
+ }
203
+
204
+ const unescapeXml = (text) => text.replaceAll("&lt;", "<").replaceAll("&gt;", ">").replaceAll("&quot;", '"')
205
+ .replaceAll("&apos;", "'").replaceAll("&#39;", "'").replaceAll("&amp;", "&");