lawspec 0.29.2 → 0.31.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 +407 -1
- package/README.md +9 -3
- package/api.mjs +1 -0
- package/beam-doctor.mjs +2 -2
- package/bin/lawspec.mjs +100 -102
- package/build.json +503 -411
- package/component-packages.mjs +339 -0
- package/component.d.ts +46 -0
- package/component.mjs +208 -0
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -5
- package/examples/native-payments/clojure/lawspec.edn +48 -0
- package/examples/native-payments/clojure/src/domain/payments.clj +1 -1
- package/examples/native-payments/clojure/test/domain/payment_generators.clj +1 -1
- package/examples/native-payments/csharp/lawspec.edn +48 -0
- package/examples/native-payments/elixir/lawspec.edn +123 -0
- package/examples/native-payments/erlang/lawspec.edn +128 -0
- package/examples/native-payments/fsharp/lawspec.edn +123 -0
- package/examples/native-payments/gleam/lawspec.edn +123 -0
- package/examples/native-payments/go/lawspec.edn +123 -0
- package/examples/native-payments/groovy/lawspec.edn +123 -0
- package/examples/native-payments/haskell/lawspec.edn +123 -0
- package/examples/native-payments/java/lawspec.edn +123 -0
- package/examples/native-payments/javascript/lawspec.edn +123 -0
- package/examples/native-payments/kotlin/lawspec.edn +123 -0
- package/examples/native-payments/prolog/lawspec.edn +48 -0
- package/examples/native-payments/python/lawspec.edn +123 -0
- package/examples/native-payments/rust/lawspec.edn +124 -0
- package/examples/native-payments/scala/lawspec.edn +123 -0
- package/examples/native-payments/swift/lawspec.edn +123 -0
- package/examples/native-payments/typescript/lawspec.edn +123 -0
- package/examples/packages/orders/lawspec.edn +25 -0
- package/examples/packages/shop-domain/lawspec.edn +13 -0
- package/examples/packages/shop-tax-1/lawspec.edn +9 -0
- package/examples/packages/shop-tax-2/lawspec.edn +9 -0
- package/examples/specs/handler_bindings.lawspec +2 -2
- package/examples/specs/harness_testing.lawspec +1 -1
- package/files.mjs +2 -1
- package/go.mod +4 -0
- package/index.d.ts +145 -8
- package/input-files.mjs +47 -0
- package/launcher.mjs +33 -13
- package/lsp.mjs +10 -5
- package/native-evidence.mjs +58 -19
- package/native-examples.mjs +8 -7
- package/native-host.mjs +71 -0
- package/package.json +8 -3
- package/proof.d.ts +8 -2
- package/proof.mjs +186 -34
- package/scala-build-state.mjs +59 -0
- package/templates.mjs +242 -2
- package/test-command.mjs +193 -61
- package/builtin-data-names.mjs +0 -73
- package/examples/native-payments/clojure/lawspec.json +0 -62
- package/examples/native-payments/csharp/lawspec.json +0 -62
- package/examples/native-payments/elixir/lawspec.json +0 -160
- package/examples/native-payments/erlang/lawspec.json +0 -159
- package/examples/native-payments/fsharp/lawspec.json +0 -178
- package/examples/native-payments/gleam/lawspec.json +0 -160
- package/examples/native-payments/go/lawspec.json +0 -147
- package/examples/native-payments/groovy/lawspec.json +0 -176
- package/examples/native-payments/haskell/lawspec.json +0 -160
- package/examples/native-payments/java/lawspec.json +0 -176
- package/examples/native-payments/javascript/lawspec.json +0 -160
- package/examples/native-payments/kotlin/lawspec.json +0 -176
- package/examples/native-payments/prolog/lawspec.json +0 -20
- package/examples/native-payments/python/lawspec.json +0 -160
- package/examples/native-payments/rust/lawspec.json +0 -178
- package/examples/native-payments/scala/lawspec.json +0 -176
- package/examples/native-payments/swift/lawspec.json +0 -165
- package/examples/native-payments/typescript/lawspec.json +0 -160
- package/examples/packages/orders/lawspec.json +0 -27
- package/examples/packages/shop-domain/lawspec-package.json +0 -7
- package/examples/packages/shop-tax-1/lawspec-package.json +0 -5
- package/examples/packages/shop-tax-2/lawspec-package.json +0 -5
- package/explain.mjs +0 -114
- package/expression-presentation.mjs +0 -333
- package/positional-fields.mjs +0 -13
- package/typed-presentation.mjs +0 -165
package/bin/lawspec.mjs
CHANGED
|
@@ -4,19 +4,21 @@ import { readFile, mkdir, readdir, rm, stat, writeFile } from "node:fs/promises"
|
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { createCompiler } from "../api.mjs";
|
|
7
|
+
import {readManifest, writeManifest, findManifest, dependencyRanges, resolveComponent} from "../component.mjs";
|
|
8
|
+
import {resolveDependencies, packComponent} from "../component-packages.mjs";
|
|
7
9
|
import { targets, artifactTargets, templates, commands, setup } from "../templates.mjs";
|
|
8
10
|
import { generateExamples } from "../examples-command.mjs";
|
|
9
11
|
import { proveWithZ3 } from "../proof.mjs";
|
|
10
12
|
import { serveLanguage } from "../lsp.mjs";
|
|
11
|
-
import { explainLaw, explanationViews } from "../explain.mjs";
|
|
12
13
|
import { showScalar } from "../scalars.mjs";
|
|
13
14
|
import { doctor } from "../doctor.mjs";
|
|
14
15
|
import { recordNativeAttempts, nativeSeed, attestedKeys, readNativeObservations, attachNativeEvidence, nativeEvidenceText } from "../native-evidence.mjs";
|
|
15
16
|
import { beamCoverageRequirement, collectBeamCoverage } from "../beam-coverage.mjs";
|
|
16
17
|
import { collectScalaCoverage } from "../scala-coverage.mjs";
|
|
18
|
+
import {captureScalaBuildFailure,isScalaCompilationFailure} from "../scala-build-state.mjs";
|
|
17
19
|
import { failureDatabase, projectKey } from "../failure-database.mjs";
|
|
18
20
|
import { spawn, spawnSync } from "node:child_process";
|
|
19
|
-
import { benchmarkInvocations, configurationInvocations, preparationInvocations, environmentDigest, executedTests, invocations, lawKeys, projectDigest, recordedDigest, selectByTags, mergeJunit,
|
|
21
|
+
import { benchmarkInvocations, presentationInvocations, presentationDigest, configurationInvocations, preparationInvocations, environmentDigest, executedTests, invocations, lawKeys, previousResult, projectDigest, recordedDigest, selectByTags, mergeJunit,
|
|
20
22
|
harnessStatistics, coverageTools, junitFromTests, testsToRun } from "../test-command.mjs";
|
|
21
23
|
import {
|
|
22
24
|
readOptional,
|
|
@@ -26,7 +28,7 @@ import {
|
|
|
26
28
|
safePath,
|
|
27
29
|
collectSources,
|
|
28
30
|
} from "../files.mjs";
|
|
29
|
-
const VERSION = "0.
|
|
31
|
+
const VERSION = "0.31.0";
|
|
30
32
|
const args = process.argv.slice(2);
|
|
31
33
|
const verb = args.shift();
|
|
32
34
|
const options = {};
|
|
@@ -42,13 +44,13 @@ for (let i = 0; i < args.length; i++) {
|
|
|
42
44
|
if (!args[i + 1] || args[i + 1].startsWith("--"))
|
|
43
45
|
throw new Error(`Missing value for ${arg}`);
|
|
44
46
|
options[arg.slice(2)] = [...(options[arg.slice(2)] ?? []), ...args[++i].split(",").filter(Boolean)];
|
|
45
|
-
} else if (["--dry-run", "--check", "--json", "--minify", "--no-cache", "--fresh", "--coverage", "--update-recorded", "--benchmarks", "--stdio", "--warn-matches", "--compile"].includes(arg))
|
|
47
|
+
} else if (["--dry-run", "--check", "--json", "--minify", "--no-cache", "--fresh", "--coverage", "--update-recorded", "--benchmarks", "--stdio", "--warn-matches", "--compile", "--locked", "--offline"].includes(arg))
|
|
46
48
|
options[arg.slice(2)] = true;
|
|
47
49
|
else if (arg.startsWith("--")) throw new Error(`Unknown option: ${arg}`);
|
|
48
50
|
else positional.push(arg);
|
|
49
51
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
let configFile = path.resolve(options.config || "lawspec.edn");
|
|
53
|
+
let configRoot = path.dirname(configFile);
|
|
52
54
|
const output = (value) =>
|
|
53
55
|
console.log(
|
|
54
56
|
typeof value === "string" ? value : JSON.stringify(value, null, 2),
|
|
@@ -101,46 +103,18 @@ async function sources(config) {
|
|
|
101
103
|
return lawspecFiles(configRoot, config.sources);
|
|
102
104
|
}
|
|
103
105
|
async function lawspecFiles(root,entries){return collectSources(root,entries,configRoot);}
|
|
104
|
-
// A package directory holds lawspec-package.json: its name, version, source
|
|
105
|
-
// directories and dependency ranges. The compiler checks names, versions,
|
|
106
|
-
// namespaces and which units may import which.
|
|
107
|
-
async function loadPackage(directory) {
|
|
108
|
-
const file = path.join(directory, "lawspec-package.json");
|
|
109
|
-
const manifest = JSON.parse(await readFile(file, "utf8"));
|
|
110
|
-
if (
|
|
111
|
-
typeof manifest.name !== "string" ||
|
|
112
|
-
typeof manifest.version !== "string" ||
|
|
113
|
-
!Array.isArray(manifest.sources)
|
|
114
|
-
)
|
|
115
|
-
throw new Error(`${file}: expected name, version and a sources array`);
|
|
116
|
-
return {
|
|
117
|
-
manifest,
|
|
118
|
-
package: {
|
|
119
|
-
name: manifest.name,
|
|
120
|
-
version: manifest.version,
|
|
121
|
-
dependencies: manifest.dependencies ?? {},
|
|
122
|
-
sources: await lawspecFiles(directory, manifest.sources),
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
106
|
async function packageInput(owner, root, optional = false) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
...(packages.some(Boolean) ? { packages: packages.filter(Boolean) } : {}),
|
|
137
|
-
...(owner.dependencies !== undefined ? { dependencies: owner.dependencies } : {}),
|
|
138
|
-
};
|
|
107
|
+
try {
|
|
108
|
+
const resolved = await resolveDependencies(path.join(root, "lawspec.edn"), owner,
|
|
109
|
+
{locked: !!options.locked, offline: optional || !!options.offline});
|
|
110
|
+
return {packages: resolved.packages, dependencies: dependencyRanges(owner), ...(owner.package ? {package: owner.package} : {})};
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (optional && (error.code === "ENOENT" || /Offline:/.test(error.message))) return {};
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
139
115
|
}
|
|
140
116
|
async function formatCommand() {
|
|
141
|
-
const config = positional.length ? null :
|
|
142
|
-
if(config&&(config.version!==2||config.languageProfile!=="1.0-rc.2"))
|
|
143
|
-
throw new Error("Formatting a project requires configuration version 2 and languageProfile 1.0-rc.2");
|
|
117
|
+
const config = positional.length ? null : await readManifest(configFile);
|
|
144
118
|
const root = positional.length ? process.cwd() : configRoot;
|
|
145
119
|
const files = await collectSources(root, positional.length ? positional : config.sources);
|
|
146
120
|
const compiler = await createCompiler();
|
|
@@ -157,8 +131,11 @@ async function formatCommand() {
|
|
|
157
131
|
}
|
|
158
132
|
|
|
159
133
|
async function packageCommand() {
|
|
160
|
-
const
|
|
161
|
-
const
|
|
134
|
+
const file = options.config ? configFile : path.resolve(options.project || ".", "lawspec.edn");
|
|
135
|
+
const directory = path.dirname(file);
|
|
136
|
+
const manifest = await readManifest(file);
|
|
137
|
+
if (!manifest.package) throw new Error(`${file}: expected a package identity`);
|
|
138
|
+
const own = {...manifest.package, dependencies: dependencyRanges(manifest), sources: await lawspecFiles(directory, manifest.sources)};
|
|
162
139
|
const compiler = await createCompiler();
|
|
163
140
|
const result = diagnostics(
|
|
164
141
|
await compiler.check({
|
|
@@ -184,6 +161,7 @@ async function packageCommand() {
|
|
|
184
161
|
.filter((d) => units.some((u) => d.id.startsWith(u + "::")))
|
|
185
162
|
.map((d) => d.id),
|
|
186
163
|
};
|
|
164
|
+
if (options.output) summary.archive = await packComponent(file, options.output);
|
|
187
165
|
output(
|
|
188
166
|
options.json
|
|
189
167
|
? summary
|
|
@@ -199,13 +177,16 @@ async function init() {
|
|
|
199
177
|
if (!targets.includes(language))
|
|
200
178
|
throw new Error(`Choose --target ${targets.join("|")}`);
|
|
201
179
|
const root = path.resolve(configRoot, options.project || ".");
|
|
180
|
+
if (path.extname(configFile) !== '.edn') throw new Error('Use lawspec.edn; JSON configuration is no longer supported');
|
|
181
|
+
for (const old of ['lawspec.json', 'lawspec-package.json']) {
|
|
182
|
+
if (await readOptional(path.join(configRoot, old)) !== null)
|
|
183
|
+
throw new Error(`${old} is no longer supported; use lawspec.edn`);
|
|
184
|
+
}
|
|
202
185
|
const current = await readOptional(configFile);
|
|
203
186
|
const config =
|
|
204
187
|
current === null
|
|
205
|
-
? { version:
|
|
206
|
-
:
|
|
207
|
-
if(config.version!==2||config.languageProfile!=='1.0-rc.2')
|
|
208
|
-
throw new Error('Existing projects require configuration version 2 and languageProfile 1.0-rc.2');
|
|
188
|
+
? { manifestVersion: 1, component: {name: path.basename(configRoot), version: "0.1.0"}, languageProfile: "1.0-rc.2", verification: { layers: [] }, sources: ["laws"], targets: [] }
|
|
189
|
+
: await readManifest(configFile);
|
|
209
190
|
if (
|
|
210
191
|
config.targets.some(
|
|
211
192
|
(t) =>
|
|
@@ -242,7 +223,7 @@ async function init() {
|
|
|
242
223
|
await safePath(configRoot, path.basename(configFile));
|
|
243
224
|
if (current === null && (await readOptional(starter)) !== null)
|
|
244
225
|
throw new Error(
|
|
245
|
-
"Starter specification already exists; create lawspec.
|
|
226
|
+
"Starter specification already exists; create lawspec.edn manually to use it",
|
|
246
227
|
);
|
|
247
228
|
if (!hasBuild && language !== "go")
|
|
248
229
|
await mkdir(path.join(root, "src"), { recursive: true });
|
|
@@ -263,7 +244,7 @@ async function init() {
|
|
|
263
244
|
});
|
|
264
245
|
await atomicWrite(
|
|
265
246
|
configFile,
|
|
266
|
-
|
|
247
|
+
writeManifest(config, {compact: options.minify === true}),
|
|
267
248
|
current === null,
|
|
268
249
|
);
|
|
269
250
|
output(
|
|
@@ -310,7 +291,7 @@ async function lastRuns() {
|
|
|
310
291
|
// The outcome each law last had in each attested run, by run id; across
|
|
311
292
|
// targets a failure outweighs a pass.
|
|
312
293
|
const outcomes = new Map();
|
|
313
|
-
const rank = (o) => ["passed", "known-
|
|
294
|
+
const rank = (o) => ["passed", "known-discrepancy", "skipped", "incomplete", "failed"].indexOf(o);
|
|
314
295
|
for (const name of (await readOptionalDirectory(folder)) ?? []) {
|
|
315
296
|
if (!name.endsWith(".json")) continue;
|
|
316
297
|
const recorded = JSON.parse((await readOptional(path.join(folder, name))) ?? "{}");
|
|
@@ -335,7 +316,7 @@ async function lastRuns() {
|
|
|
335
316
|
}
|
|
336
317
|
// An environment attestation: a versioned JSON document any tool may write,
|
|
337
318
|
// recording for one run where each dependency was wired and whether it was
|
|
338
|
-
// the real dependency or a stand-in. --attestation names one, or lawspec.
|
|
319
|
+
// the real dependency or a stand-in. --attestation names one, or lawspec.edn
|
|
339
320
|
// does; the compiler checks it. It is reporting only and changes no evidence.
|
|
340
321
|
async function readAttestation(config) {
|
|
341
322
|
const file = options.attestation !== undefined ? path.resolve(options.attestation)
|
|
@@ -391,7 +372,7 @@ function harnessText(item) {
|
|
|
391
372
|
if (h.repeat > 1) parts.push(`repeat ${h.repeat}`);
|
|
392
373
|
if (h.retries) parts.push(`retry flaky ${h.retries}`);
|
|
393
374
|
if (h.skip) parts.push(`skip "${h.skip}"`);
|
|
394
|
-
if (h.
|
|
375
|
+
if (h.knownDiscrepancy) parts.push(`known discrepancy "${h.knownDiscrepancy}"`);
|
|
395
376
|
if (h.orderRandom) parts.push("order random");
|
|
396
377
|
if (h.parallel) parts.push("parallel");
|
|
397
378
|
const lines = [` ${item.declaration.replace("::law::", "::")}: ${parts.join("; ") || "no harness settings"}`];
|
|
@@ -438,7 +419,7 @@ async function buildDigest() {
|
|
|
438
419
|
// harness tags, and a skipped law runs nothing. A law whose last run failed
|
|
439
420
|
// runs first, and its failing inputs are replayed first (.lawspec/failures).
|
|
440
421
|
async function runTests(compiler, input, selected, roots, config) {
|
|
441
|
-
// Recorded values live beside lawspec.
|
|
422
|
+
// Recorded values live beside lawspec.edn, under recorded/<unit>/<name>.
|
|
442
423
|
const recordedFolder = path.join(configRoot, "recorded");
|
|
443
424
|
const seed = options.seed ?? String(1 + Math.floor(Math.random() * 2147483646));
|
|
444
425
|
const offline = process.env.LAWSPEC_OFFLINE === "1";
|
|
@@ -474,15 +455,25 @@ async function runTests(compiler, input, selected, roots, config) {
|
|
|
474
455
|
const generated = new Set(planned.files.filter((f) => f.ownership === "generated").map((f) => f.path));
|
|
475
456
|
const keys = lawKeys({
|
|
476
457
|
build, target, machineBits: input.machineBits, minify: options.minify === true,
|
|
477
|
-
tests: planned.tests,
|
|
458
|
+
tests: planned.tests,
|
|
478
459
|
// Recorded values are spec data: a changed recording runs its laws again.
|
|
479
|
-
environment: await environmentDigest(root, report_)
|
|
480
|
-
|
|
460
|
+
environment: await environmentDigest(root, report_,target.language),
|
|
461
|
+
recorded: await recordedDigest(recordedFolder),
|
|
462
|
+
project: await projectDigest(root, generated,target.language,{inputRoot:configRoot,inputs:config.inputs??[]}),
|
|
481
463
|
attested,
|
|
482
464
|
});
|
|
483
465
|
const identity = projectKey(root);
|
|
484
466
|
const resultsFile = path.join(configRoot, ".lawspec", "results", `${target.language}-${identity}.json`);
|
|
485
467
|
const previous = JSON.parse((await readOptional(resultsFile)) ?? '{"version":1,"laws":{}}');
|
|
468
|
+
const presentation=presentationDigest(planned.files,await environmentDigest(root,report_,target.language));
|
|
469
|
+
if(previous.presentation!==presentation){
|
|
470
|
+
const checks=presentationInvocations(target,planned.files,{offline});
|
|
471
|
+
if(!checks.length)throw new Error(`${target.language}: no native source validator is available`);
|
|
472
|
+
for(const check of checks){
|
|
473
|
+
const result=await spawned(check.command,check.args,root,{...process.env,...check.environment});
|
|
474
|
+
if(!result.ok)throw new Error(`${target.language}: current generated source failed native validation`);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
486
477
|
const attempts = {...(previous.attempts ?? {})};
|
|
487
478
|
const {directory: failures, file: databaseFile, database} = await failureDatabase(configRoot, target.language, root);
|
|
488
479
|
// Recording again runs every law, so each records what it sees now.
|
|
@@ -539,9 +530,9 @@ async function runTests(compiler, input, selected, roots, config) {
|
|
|
539
530
|
if (target.language === "python" && stale.some((entry) => entry.parallel)) {
|
|
540
531
|
xdist = spawnSync(target.python || "python3", ["-c", "import xdist"], { cwd: root, stdio: "ignore" }).status === 0;
|
|
541
532
|
}
|
|
542
|
-
// A skipped law runs nothing. BEAM known-
|
|
533
|
+
// A skipped law runs nothing. BEAM known-discrepancy checks finish as native
|
|
543
534
|
// passing tests, so their completion must appear in the native report.
|
|
544
|
-
const expected = (entry) => !entry.skip && (!entry.
|
|
535
|
+
const expected = (entry) => !entry.skip && (!entry.knownDiscrepancy || ["erlang", "elixir", "gleam"].includes(target.language));
|
|
545
536
|
const benchmarking = options.benchmarks ? (planned.benchmarks ?? []) : [];
|
|
546
537
|
if (batches.length || benchmarking.length) {
|
|
547
538
|
for (const preparation of preparationInvocations(target, planned.files)) {
|
|
@@ -558,6 +549,10 @@ async function runTests(compiler, input, selected, roots, config) {
|
|
|
558
549
|
{ ...process.env, ...run.env, LAWSPEC_SEED: batch.seed, HSPEC_SEED: batch.seed,
|
|
559
550
|
LAWSPEC_STATS: stats, LAWSPEC_FAILURES: failures, LAWSPEC_RECORDED: recordedFolder,
|
|
560
551
|
...(options["update-recorded"] ? { LAWSPEC_UPDATE_RECORDED: "1" } : {}) }, run.report?.kind === "go-json");
|
|
552
|
+
if(!ok&&target.language==='scala'&&isScalaCompilationFailure(output)) {
|
|
553
|
+
const directory=await captureScalaBuildFailure({root,command:run.command,args:run.args,output});
|
|
554
|
+
if(directory)console.error(`Scala compiler state: ${directory}`);
|
|
555
|
+
}
|
|
561
556
|
if (run.coverage) coverageRuns.push(run.coverage);
|
|
562
557
|
const executed = await executedTests(run.report, output, root, since);
|
|
563
558
|
const observed=recordNativeAttempts(run,executed,{keys,seed:batch.seed,ok,profile,output,allEntries:planned.tests});
|
|
@@ -567,7 +562,7 @@ async function runTests(compiler, input, selected, roots, config) {
|
|
|
567
562
|
for (const law of run.laws) seedOf.set(law.law, batch.seed);
|
|
568
563
|
// A completed combined model method remains scoped to its own checks,
|
|
569
564
|
// even if another selected method in this invocation failed.
|
|
570
|
-
passed.push(...run.laws.filter(entry=>['passed','known-
|
|
565
|
+
passed.push(...run.laws.filter(entry=>['passed','known-discrepancy'].includes(observed[entry.law]?.outcome)||!expected(entry)));
|
|
571
566
|
if (report) junit.push({ target: `${target.language} (${target.root})`, xml: await junitOf(run, executed, root, since) });
|
|
572
567
|
if (!ok || executed.some((test) => test.status === "failed")) { failed = true; break batches; }
|
|
573
568
|
// A runner whose filter matched nothing reports success, so a law
|
|
@@ -600,7 +595,9 @@ async function runTests(compiler, input, selected, roots, config) {
|
|
|
600
595
|
if (!ok) { failed = true; break; }
|
|
601
596
|
}
|
|
602
597
|
const statistics = await harnessStatistics(stats);
|
|
603
|
-
|
|
598
|
+
// A renamed law keeps its result: it is found by its key.
|
|
599
|
+
const kept = (entry) => previous.laws[entry.law] ?? previousResult(previous.laws, entry.law, keys.get(entry.law));
|
|
600
|
+
const laws = Object.fromEntries(planned.tests.filter(kept).map((entry) => [entry.law, kept(entry)]));
|
|
604
601
|
for (const entry of passed) {
|
|
605
602
|
const label = entry.label;
|
|
606
603
|
const observed = statistics.filter((s) => s.law === label);
|
|
@@ -626,13 +623,16 @@ async function runTests(compiler, input, selected, roots, config) {
|
|
|
626
623
|
await writeFile(path.join(path.dirname(resultsFile), ".gitignore"), "*\n");
|
|
627
624
|
// Each attempt at a law the attestation touches names the run it was
|
|
628
625
|
// made in, whatever its outcome.
|
|
629
|
-
if (attestation) for (const entry of stale)
|
|
630
|
-
if (
|
|
626
|
+
if (attestation) for (const entry of stale) {
|
|
627
|
+
if (!seedOf.has(entry.law) || !attempts[entry.law]) continue;
|
|
628
|
+
attempts[entry.law] = {...attempts[entry.law], executionRun: attestation.run.id,
|
|
629
|
+
...(attested.has(entry.law) ? {environment: attestation.run.id} : {})};
|
|
630
|
+
}
|
|
631
631
|
// Each attestation a recorded law ran under is kept with the results.
|
|
632
632
|
const attestations = Object.fromEntries(Object.entries({ ...(previous.attestations ?? {}),
|
|
633
633
|
...(attestation ? { [attestation.run.id]: attestation } : {}) })
|
|
634
|
-
.filter(([id]) => [...Object.values(laws), ...Object.values(attempts)].some((run) => run.environment === id)));
|
|
635
|
-
await atomicWrite(resultsFile, JSON.stringify({ version: 1, laws, attempts,
|
|
634
|
+
.filter(([id]) => [...Object.values(laws), ...Object.values(attempts)].some((run) => run.environment === id || run.executionRun === id)));
|
|
635
|
+
await atomicWrite(resultsFile, JSON.stringify({ version: 1, laws, attempts,presentation,
|
|
636
636
|
...(Object.keys(attestations).length ? { attestations } : {}) }, null, 2) + "\n");
|
|
637
637
|
const flaky = statistics.filter((s) => s.outcome === "flaky").map((s) => s.law);
|
|
638
638
|
const unmet = statistics.flatMap((s) => (s.cover ?? []).filter((c) => !c.met).map((c) => `${s.law}: cover ${c.required}% "${c.label}" (${c.observed}%)`));
|
|
@@ -759,7 +759,7 @@ async function main() {
|
|
|
759
759
|
}
|
|
760
760
|
if (!verb || ["help", "--help", "-h"].includes(verb)) {
|
|
761
761
|
output(
|
|
762
|
-
"LawSpec " + VERSION + "\nUsage: lawspec init --target <language> [--project <directory>] [--minify]\n lawspec fmt [paths...] [--check] [--compile]\n lawspec lsp --stdio\n lawspec prove [--solver <z3-executable>] [--proof-timeout <ms>] [--json]\n lawspec check [--warn-matches] | doctor | explain [<unit>::<law>] [--view
|
|
762
|
+
"LawSpec " + VERSION + "\nUsage: lawspec init --target <language> [--project <directory>] [--minify]\n lawspec fmt [paths...] [--check] [--compile]\n lawspec lsp --stdio\n lawspec prove [--solver <z3-executable>] [--proof-timeout <ms>] [--json]\n lawspec check [--warn-matches] | doctor | explain [<unit>::<law>] [--view eng|math|dev] | generate\n lawspec evidence [<unit> | <unit>::<declaration>] [--attestation <file>]\n lawspec test [--target <language>] [--fresh] [--seed <n>] [--attestation <file>] [--update-recorded] [--tag <t>] [--exclude-tag <t>] [--report junit=<path>] [--coverage] [--benchmarks]\n lawspec describe --json\n lawspec fetch | update [<package>]\n lawspec package [--project <package directory>] [--output <archive.tgz>]\n lawspec examples [--example payments] [--target <language>] [--output <directory>]\nOptions: --config <path>, --target <language>, --machine-bits <32|64>, --json, --no-cache, --locked, --offline\nGeneration: --dry-run, --check, --minify\nTargets: " +
|
|
763
763
|
targets.join(", "),
|
|
764
764
|
);
|
|
765
765
|
return;
|
|
@@ -769,7 +769,7 @@ async function main() {
|
|
|
769
769
|
return;
|
|
770
770
|
}
|
|
771
771
|
if (options.compile && verb !== "fmt") throw new Error("--compile applies to fmt");
|
|
772
|
-
if (verb !== "fmt" && positional.length > (["explain", "evidence"].includes(verb) ? 1 : 0))
|
|
772
|
+
if (verb !== "fmt" && positional.length > (["explain", "evidence", "update"].includes(verb) ? 1 : 0))
|
|
773
773
|
throw new Error(`Unexpected argument: ${positional.join(" ")}`);
|
|
774
774
|
if (verb === "examples") {
|
|
775
775
|
if (
|
|
@@ -803,7 +803,7 @@ async function main() {
|
|
|
803
803
|
if (["solver","proof-timeout","proof-memory","proof-rlimit","proof-seed"].some(key => options[key] !== undefined) && verb !== "prove")
|
|
804
804
|
throw new Error("Z3 options apply to prove");
|
|
805
805
|
if (options.view && verb !== "explain") throw new Error("--view applies to explain");
|
|
806
|
-
if (options.output) throw new Error("--output is only supported by examples");
|
|
806
|
+
if (options.output && verb !== "package") throw new Error("--output is only supported by examples and package");
|
|
807
807
|
if (options.example) throw new Error("--example is only supported by examples");
|
|
808
808
|
if (options.minify && !["init", "generate", "examples", "test"].includes(verb))
|
|
809
809
|
throw new Error("--minify applies to init, generate, test and examples");
|
|
@@ -820,21 +820,23 @@ async function main() {
|
|
|
820
820
|
if (!options.stdio) throw new Error("lsp requires --stdio");
|
|
821
821
|
return serveLanguage();
|
|
822
822
|
}
|
|
823
|
+
if (!options.config && verb !== "init" && verb !== "package" && !(verb === "fmt" && positional.length)) {
|
|
824
|
+
configFile = await findManifest();
|
|
825
|
+
configRoot = path.dirname(configFile);
|
|
826
|
+
}
|
|
827
|
+
if (verb === "describe") return output(await resolveComponent(configFile, options));
|
|
828
|
+
if (verb === "fetch" || verb === "update") {
|
|
829
|
+
const manifest = await readManifest(configFile);
|
|
830
|
+
const resolved = await resolveDependencies(configFile, manifest, {...options, update: verb === "update" ? positional[0] ?? true : false});
|
|
831
|
+
return output(options.json ? resolved.lock : `Resolved ${resolved.packages.length} contract package(s).`);
|
|
832
|
+
}
|
|
823
833
|
if (verb === "fmt") return formatCommand();
|
|
824
834
|
if (verb === "init") return init();
|
|
825
835
|
if (verb === "package") return packageCommand();
|
|
826
836
|
if (!["check", "doctor", "evidence", "explain", "generate", "test", "prove"].includes(verb))
|
|
827
837
|
throw new Error(`Unknown command: ${verb}`);
|
|
828
|
-
const config =
|
|
829
|
-
|
|
830
|
-
config.version!==2 ||
|
|
831
|
-
!Array.isArray(config.sources) ||
|
|
832
|
-
!Array.isArray(config.targets)
|
|
833
|
-
)
|
|
834
|
-
throw new Error(
|
|
835
|
-
"Expected lawspec.json version 2 with languageProfile 1.0-rc.2, sources and targets arrays",
|
|
836
|
-
);
|
|
837
|
-
if (config.languageProfile !== "1.0-rc.2") throw new Error("Configuration version 2 requires languageProfile 1.0-rc.2");
|
|
838
|
+
const config = await readManifest(configFile);
|
|
839
|
+
config.targets ??= [];
|
|
838
840
|
if (verb === "test" && artifactTargets.includes(options.target))
|
|
839
841
|
throw new Error(`${options.target} is an artifact target and cannot execute application laws`);
|
|
840
842
|
const selected = config.targets.filter(
|
|
@@ -842,7 +844,7 @@ async function main() {
|
|
|
842
844
|
(verb !== "test" || !artifactTargets.includes(t.language)),
|
|
843
845
|
);
|
|
844
846
|
if (["doctor", "generate", "test"].includes(verb) && !selected.length &&
|
|
845
|
-
!(verb === "test" && !options.benchmarks && config.
|
|
847
|
+
!(verb === "test" && !options.benchmarks && config.manifestVersion === 1 && !(config.verification?.layers ?? []).some(layer => ["exhaustive", "property", "examples", "model"].includes(layer))))
|
|
846
848
|
throw new Error("No matching configured target");
|
|
847
849
|
const roots = selected.map((t) => path.resolve(configRoot, t.root));
|
|
848
850
|
if (new Set(roots).size !== roots.length)
|
|
@@ -878,12 +880,11 @@ async function main() {
|
|
|
878
880
|
machineBits: options.machineBits ?? config.machineBits ?? 64,
|
|
879
881
|
// What a law-set exemption's until is compared with: the project's
|
|
880
882
|
// version and the current UTC time.
|
|
881
|
-
...(
|
|
883
|
+
...((config.component?.version ?? config.package?.version) ? {projectVersion: config.component?.version ?? config.package?.version} : {}),
|
|
882
884
|
now: new Date().toISOString(),
|
|
883
885
|
};
|
|
884
886
|
const compiler = await createCompiler();
|
|
885
887
|
if (verb === "prove") {
|
|
886
|
-
if (config.version !== 2) throw new Error("prove requires configuration version 2 and languageProfile 1.0-rc.2");
|
|
887
888
|
const result = diagnostics(await proveWithZ3(compiler, input, {
|
|
888
889
|
...(options.solver !== undefined ? {binary: options.solver} : {}),
|
|
889
890
|
...Object.fromEntries([["proof-timeout","timeoutMs"],["proof-memory","memoryMb"],
|
|
@@ -913,9 +914,9 @@ async function main() {
|
|
|
913
914
|
["exempted", "EXEMPTED"],
|
|
914
915
|
// A law a confirmed counterexample shows false; the build fails.
|
|
915
916
|
["refuted", "REFUTED"],
|
|
916
|
-
// The harness plane:
|
|
917
|
+
// The harness plane: an acknowledged discrepancy, a law whose last
|
|
917
918
|
// run was flaky, and a law whose tests it skips.
|
|
918
|
-
["known-
|
|
919
|
+
["known-discrepancy", "KNOWN DISCREPANCY"],
|
|
919
920
|
["flaky", "FLAKY"],
|
|
920
921
|
["skipped", "SKIPPED"],
|
|
921
922
|
// A law about an open history that the entries so far do not decide.
|
|
@@ -953,7 +954,7 @@ async function main() {
|
|
|
953
954
|
return;
|
|
954
955
|
}
|
|
955
956
|
if (verb === "evidence") {
|
|
956
|
-
// An attestation named here, or in lawspec.
|
|
957
|
+
// An attestation named here, or in lawspec.edn, says where the tests
|
|
957
958
|
// ran; otherwise each law shows the attested run it last passed in.
|
|
958
959
|
// A named attestation of a run lawspec test recorded links each law to
|
|
959
960
|
// that run, with the outcome recorded for it, unless the document says
|
|
@@ -965,7 +966,7 @@ async function main() {
|
|
|
965
966
|
...(named ? { attestation: named, ...(recorded ? { attestedOutcomes: recorded } : {}) } : {}) })));
|
|
966
967
|
if (result.refuted) process.exitCode = 1;
|
|
967
968
|
let evidence = attachNativeEvidence(result.evidence,await readNativeObservations({compiler,input,selected,roots,
|
|
968
|
-
configRoot,build:await buildDigest(),evidence:result.evidence,attestation:named}));
|
|
969
|
+
configRoot,config,build:await buildDigest(),evidence:result.evidence,attestation:named}));
|
|
969
970
|
const environments = named ? [result.attestation] : [];
|
|
970
971
|
if (!named) for (const [id, attestation] of attestations) {
|
|
971
972
|
const laws = new Set([...runs].filter(([, run]) => run.environment === id).map(([law]) => law));
|
|
@@ -1041,7 +1042,8 @@ async function main() {
|
|
|
1041
1042
|
...environments.map((e) => `ENVIRONMENT ${e.environment} (run ${e.run.id}, recorded ${e.run.recordedAt}${executionText(e.run)})\n` +
|
|
1042
1043
|
(e.architecture ? ` architecture ${e.architecture.document} ${e.architecture.digest}` +
|
|
1043
1044
|
(e.architecture.topologyDigest ? `, topology ${e.architecture.topologyDigest}` : "") + "\n" : "") +
|
|
1044
|
-
(e.application ? ` application ${e.application.node}:
|
|
1045
|
+
(e.application ? ` application ${e.application.node}: ` +
|
|
1046
|
+
(e.application.component ? `component ${e.application.component.name} ${e.application.component.version} (${e.application.component.fingerprint}); ` : `contract ${e.application.contract.package} ${e.application.contract.version}; `) +
|
|
1045
1047
|
`${e.application.implementation.kind} ${e.application.implementation.product} ${e.application.implementation.version}` +
|
|
1046
1048
|
(e.application.implementation.commit ? ` (commit ${e.application.implementation.commit})` : "") + "\n" : "") +
|
|
1047
1049
|
e.dependencies.map((d) => {
|
|
@@ -1056,23 +1058,19 @@ async function main() {
|
|
|
1056
1058
|
return;
|
|
1057
1059
|
}
|
|
1058
1060
|
if (verb === "explain") {
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
compiler,input,selected,roots,configRoot,build:await buildDigest(),evidence:result.evidence,
|
|
1070
|
-
attestation:await readAttestation(config)}))};
|
|
1071
|
-
const explanations = indices.map(({e}) => explainLaw(e, observed, view));
|
|
1072
|
-
output(options.json ? explanations : explanations.map(e => e.text).join("\n\n"));
|
|
1061
|
+
// The compiler words the law (eng by default); the CLI only reads the
|
|
1062
|
+
// recorded native observations and passes their evidence rows in.
|
|
1063
|
+
const request = { ...input, view: options.view ?? "eng", ...(positional[0] ? { law: positional[0] } : {}) };
|
|
1064
|
+
let explained = diagnostics(await compiler.explain(request));
|
|
1065
|
+
const expanded = diagnostics(await compiler.expand(input));
|
|
1066
|
+
const observations = await readNativeObservations({ compiler, input, selected, roots, configRoot, config,
|
|
1067
|
+
build: await buildDigest(), evidence: expanded.evidence, attestation: await readAttestation(config) });
|
|
1068
|
+
if (observations.length)
|
|
1069
|
+
explained = diagnostics(await compiler.explain({ ...request, evidence: attachNativeEvidence(expanded.evidence, observations) }));
|
|
1070
|
+
output(options.json ? explained.explanations : explained.text);
|
|
1073
1071
|
return;
|
|
1074
1072
|
}
|
|
1075
|
-
if (verb === "test" && !options.benchmarks && config.
|
|
1073
|
+
if (verb === "test" && !options.benchmarks && config.manifestVersion === 1 && !(config.verification?.layers ?? []).some(layer => ["exhaustive", "property", "examples", "model"].includes(layer))) {
|
|
1076
1074
|
const checked = diagnostics(await compiler.check(input));
|
|
1077
1075
|
output(options.json ? { verification: checked.verification, evidence: checked.evidence, testsExecuted: 0 }
|
|
1078
1076
|
: (config.verification?.layers?.length ? "No native law checks selected. See lawspec evidence for the selected static analyses." : "No law verification layers selected. Intrinsic definition checks passed; no law checks ran."));
|