lawspec 0.24.0 → 0.26.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 +109 -1
- package/README.md +34 -26
- package/UNICODE-LICENSE.txt +39 -0
- package/api.mjs +6 -23
- package/bin/lawspec.mjs +148 -65
- package/build.json +245 -177
- package/builtin-data-names.mjs +73 -0
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -0
- 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 +57 -53
- package/examples/packages/shop-domain/src/domain.lawspec +36 -33
- package/examples/packages/shop-tax-1/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-1/src/rates.lawspec +5 -4
- package/examples/packages/shop-tax-2/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-2/src/rates.lawspec +6 -4
- package/examples/rc1/authorization-snapshots.lawspec +113 -0
- package/examples/rc1/banner-filenames.lawspec +64 -0
- package/examples/rc1/bit-codec.lawspec +57 -0
- package/examples/rc1/bounded-witness-search.lawspec +151 -0
- package/examples/rc1/conflicting-requirements.lawspec +31 -0
- package/examples/rc1/constructive-witnesses.lawspec +120 -0
- package/examples/rc1/documentary-review.lawspec +43 -0
- package/examples/rc1/empty-domains.lawspec +47 -0
- package/examples/rc1/finite-integer-domains.lawspec +76 -0
- package/examples/rc1/law-metadata.lawspec +30 -0
- package/examples/rc1/native-payments.lawspec +108 -0
- package/examples/rc1/nesting/rrr.lawspec +34 -0
- package/examples/rc1/nesting/rru.lawspec +57 -0
- package/examples/rc1/nesting/rur.lawspec +58 -0
- package/examples/rc1/nesting/ruu.lawspec +78 -0
- package/examples/rc1/nesting/urr.lawspec +53 -0
- package/examples/rc1/nesting/uru.lawspec +73 -0
- package/examples/rc1/nesting/uur.lawspec +74 -0
- package/examples/rc1/nesting/uuu.lawspec +96 -0
- package/examples/rc1/order-workflow.lawspec +127 -0
- package/examples/rc1/parcel-measurements.lawspec +93 -0
- package/examples/rc1/picture-records.lawspec +52 -0
- package/examples/rc1/picture-tuples.lawspec +48 -0
- package/examples/rc1/record-payloads.lawspec +57 -0
- package/examples/rc1/recursive-records.lawspec +65 -0
- package/examples/rc1/refund-conformance.lawspec +45 -0
- package/examples/rc1/refund-policy.lawspec +89 -0
- package/examples/rc1/requirement-composition.lawspec +90 -0
- package/examples/rc1/structural-records.lawspec +54 -0
- package/examples/rc1-authoring.lawspec +57 -0
- package/examples/specs/abilities.lawspec +67 -65
- package/examples/specs/ability_imports.lawspec +58 -57
- package/examples/specs/actors.lawspec +23 -22
- package/examples/specs/algebra.lawspec +142 -141
- package/examples/specs/approvals.lawspec +16 -15
- package/examples/specs/async_bindings.lawspec +10 -9
- package/examples/specs/async_fetch.lawspec +12 -11
- package/examples/specs/atoi_codec.lawspec +16 -15
- package/examples/specs/boolean_flags.lawspec +10 -9
- package/examples/specs/builtins.lawspec +73 -72
- package/examples/specs/canonical_url.lawspec +14 -13
- package/examples/specs/collections.lawspec +153 -154
- package/examples/specs/composition.lawspec +70 -66
- package/examples/specs/concurrent_collections.lawspec +8 -7
- package/examples/specs/consistency.lawspec +4 -3
- package/examples/specs/contracts.lawspec +80 -79
- package/examples/specs/crypto.lawspec +26 -25
- package/examples/specs/ctc.lawspec +148 -0
- package/examples/specs/currying.lawspec +32 -31
- package/examples/specs/data_types.lawspec +50 -49
- package/examples/specs/distribution.lawspec +57 -56
- package/examples/specs/domain_modeling.lawspec +48 -47
- package/examples/specs/durations.lawspec +39 -38
- package/examples/specs/equivalent.lawspec +25 -24
- package/examples/specs/failures.lawspec +64 -63
- package/examples/specs/finite_data.lawspec +32 -31
- package/examples/specs/flow_stack.lawspec +64 -63
- package/examples/specs/gadt_expressions.lawspec +50 -49
- package/examples/specs/generation.lawspec +115 -114
- package/examples/specs/handler_bindings.lawspec +42 -40
- package/examples/specs/handles.lawspec +2 -1
- package/examples/specs/harness.lawspec +45 -43
- package/examples/specs/harness_testing.lawspec +18 -13
- package/examples/specs/indexed_arithmetic.lawspec +401 -126
- package/examples/specs/indexed_families.lawspec +182 -66
- package/examples/specs/keywords.lawspec +22 -21
- package/examples/specs/limits.lawspec +6 -5
- package/examples/specs/list_contracts.lawspec +121 -120
- package/examples/specs/list_refinements.lawspec +43 -42
- package/examples/specs/lists.lawspec +45 -44
- package/examples/specs/matchers.lawspec +79 -78
- package/examples/specs/matching.lawspec +43 -42
- package/examples/specs/mixed_inputs.lawspec +25 -24
- package/examples/specs/models.lawspec +44 -43
- package/examples/specs/parse_port.lawspec +28 -27
- package/examples/specs/payments.lawspec +55 -54
- package/examples/specs/railway.lawspec +59 -58
- package/examples/specs/records.lawspec +149 -148
- package/examples/specs/records_inner.lawspec +5 -4
- package/examples/specs/recursive_refinements.lawspec +30 -29
- package/examples/specs/refined_definitions.lawspec +24 -23
- package/examples/specs/refinements.lawspec +58 -57
- package/examples/specs/resilience.lawspec +159 -158
- package/examples/specs/resources.lawspec +61 -60
- package/examples/specs/scalar_adapters.lawspec +60 -59
- package/examples/specs/scalar_catalog.lawspec +165 -164
- package/examples/specs/scalars.lawspec +78 -77
- package/examples/specs/scheduling_order.lawspec +8 -7
- package/examples/specs/scheduling_overlap.lawspec +5 -4
- package/examples/specs/sequences.lawspec +66 -65
- package/examples/specs/sessions.lawspec +13 -12
- package/examples/specs/slug.lawspec +16 -15
- package/examples/specs/sum_refinements.lawspec +42 -41
- package/examples/specs/tables.lawspec +29 -28
- package/examples/specs/total_functions.lawspec +71 -70
- package/examples/specs/workflows.lawspec +101 -100
- package/examples-command.mjs +8 -4
- package/explain.mjs +114 -0
- package/expression-presentation.mjs +333 -0
- package/files.mjs +16 -0
- package/index.d.ts +406 -11
- package/launcher.mjs +9 -2
- package/lsp.mjs +235 -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 +26 -0
- package/starter.lawspec +16 -15
- package/templates.mjs +6 -4
- package/test-command.mjs +107 -35
- package/typed-presentation.mjs +165 -0
package/bin/lawspec.mjs
CHANGED
|
@@ -6,13 +6,17 @@ import path from "node:path";
|
|
|
6
6
|
import { createCompiler } from "../api.mjs";
|
|
7
7
|
import { targets, templates, commands, setup } from "../templates.mjs";
|
|
8
8
|
import { generateExamples } from "../examples-command.mjs";
|
|
9
|
+
import { proveWithZ3 } from "../proof.mjs";
|
|
10
|
+
import { serveLanguage } from "../lsp.mjs";
|
|
11
|
+
import { explainLaw, explanationViews } from "../explain.mjs";
|
|
9
12
|
import { showScalar } from "../scalars.mjs";
|
|
10
13
|
import { doctor } from "../doctor.mjs";
|
|
14
|
+
import { recordNativeAttempts, nativeSeed, attestedKeys, readNativeObservations, attachNativeEvidence, nativeEvidenceText } from "../native-evidence.mjs";
|
|
11
15
|
import { beamCoverageRequirement, collectBeamCoverage } from "../beam-coverage.mjs";
|
|
12
16
|
import { collectScalaCoverage } from "../scala-coverage.mjs";
|
|
13
17
|
import { failureDatabase, projectKey } from "../failure-database.mjs";
|
|
14
18
|
import { spawn, spawnSync } from "node:child_process";
|
|
15
|
-
import { benchmarkInvocations, preparationInvocations, environmentDigest, executedTests, invocations, lawKeys, projectDigest, recordedDigest, selectByTags, mergeJunit,
|
|
19
|
+
import { benchmarkInvocations, configurationInvocations, preparationInvocations, environmentDigest, executedTests, invocations, lawKeys, projectDigest, recordedDigest, selectByTags, mergeJunit,
|
|
16
20
|
harnessStatistics, coverageTools, junitFromTests, testsToRun } from "../test-command.mjs";
|
|
17
21
|
import {
|
|
18
22
|
readOptional,
|
|
@@ -20,15 +24,16 @@ import {
|
|
|
20
24
|
applyWrites,
|
|
21
25
|
atomicWrite,
|
|
22
26
|
safePath,
|
|
27
|
+
collectSources,
|
|
23
28
|
} from "../files.mjs";
|
|
24
|
-
const VERSION = "0.
|
|
29
|
+
const VERSION = "0.26.0";
|
|
25
30
|
const args = process.argv.slice(2);
|
|
26
31
|
const verb = args.shift();
|
|
27
32
|
const options = {};
|
|
28
33
|
const positional = [];
|
|
29
34
|
for (let i = 0; i < args.length; i++) {
|
|
30
35
|
const arg = args[i];
|
|
31
|
-
if (["--target", "--project", "--config", "--output", "--machine-bits", "--example", "--seed", "--report", "--attestation"].includes(arg)) {
|
|
36
|
+
if (["--target", "--project", "--config", "--output", "--machine-bits", "--example", "--seed", "--report", "--attestation", "--view", "--solver", "--proof-timeout", "--proof-memory", "--proof-rlimit", "--proof-seed"].includes(arg)) {
|
|
32
37
|
if (!args[i + 1] || args[i + 1].startsWith("--"))
|
|
33
38
|
throw new Error(`Missing value for ${arg}`);
|
|
34
39
|
options[arg.slice(2)] = args[++i];
|
|
@@ -37,7 +42,7 @@ for (let i = 0; i < args.length; i++) {
|
|
|
37
42
|
if (!args[i + 1] || args[i + 1].startsWith("--"))
|
|
38
43
|
throw new Error(`Missing value for ${arg}`);
|
|
39
44
|
options[arg.slice(2)] = [...(options[arg.slice(2)] ?? []), ...args[++i].split(",").filter(Boolean)];
|
|
40
|
-
} else if (["--dry-run", "--check", "--json", "--minify", "--no-cache", "--fresh", "--coverage", "--update-recorded", "--benchmarks"].includes(arg))
|
|
45
|
+
} else if (["--dry-run", "--check", "--json", "--minify", "--no-cache", "--fresh", "--coverage", "--update-recorded", "--benchmarks", "--stdio", "--warn-matches"].includes(arg))
|
|
41
46
|
options[arg.slice(2)] = true;
|
|
42
47
|
else if (arg.startsWith("--")) throw new Error(`Unknown option: ${arg}`);
|
|
43
48
|
else positional.push(arg);
|
|
@@ -85,24 +90,7 @@ function diagnostics(result) {
|
|
|
85
90
|
async function sources(config) {
|
|
86
91
|
return lawspecFiles(configRoot, config.sources);
|
|
87
92
|
}
|
|
88
|
-
async function lawspecFiles(root, entries)
|
|
89
|
-
const files = [];
|
|
90
|
-
async function visit(file) {
|
|
91
|
-
const info = await stat(file);
|
|
92
|
-
if (info.isDirectory())
|
|
93
|
-
for (const entry of (await readdir(file)).sort())
|
|
94
|
-
await visit(path.join(file, entry));
|
|
95
|
-
else if (file.endsWith(".lawspec")) files.push(file);
|
|
96
|
-
}
|
|
97
|
-
for (const source of entries) await visit(path.resolve(root, source));
|
|
98
|
-
if (!files.length) throw new Error("No .lawspec source files found");
|
|
99
|
-
return Promise.all(
|
|
100
|
-
[...new Set(files)].sort().map(async (file) => ({
|
|
101
|
-
path: path.relative(configRoot, file).split(path.sep).join("/"),
|
|
102
|
-
content: await readFile(file, "utf8"),
|
|
103
|
-
})),
|
|
104
|
-
);
|
|
105
|
-
}
|
|
93
|
+
async function lawspecFiles(root,entries){return collectSources(root,entries,configRoot);}
|
|
106
94
|
// A package directory holds lawspec-package.json: its name, version, source
|
|
107
95
|
// directories and dependency ranges. The compiler checks names, versions,
|
|
108
96
|
// namespaces and which units may import which.
|
|
@@ -136,12 +124,31 @@ async function packageInput(owner, root) {
|
|
|
136
124
|
...(owner.dependencies !== undefined ? { dependencies: owner.dependencies } : {}),
|
|
137
125
|
};
|
|
138
126
|
}
|
|
127
|
+
async function formatCommand() {
|
|
128
|
+
const config = positional.length ? null : JSON.parse(await readFile(configFile, "utf8"));
|
|
129
|
+
if(config&&(config.version!==2||config.languageProfile!=="1.0-rc.2"))
|
|
130
|
+
throw new Error("Formatting a project requires configuration version 2 and languageProfile 1.0-rc.2");
|
|
131
|
+
const root = positional.length ? process.cwd() : configRoot;
|
|
132
|
+
const files = await collectSources(root, positional.length ? positional : config.sources);
|
|
133
|
+
const compiler = await createCompiler();
|
|
134
|
+
const result = diagnostics(await compiler.format({
|
|
135
|
+
sources: files, ...(config ? await packageInput(config, configRoot) : {}),
|
|
136
|
+
languageProfile: "1.0-rc.2", verification: { layers: [] },
|
|
137
|
+
}));
|
|
138
|
+
const changed = result.formattedSources.filter((file, index) => file.content !== files[index].content);
|
|
139
|
+
if (!options.check) for (const file of changed) await atomicWrite(path.resolve(root, file.path), file.content);
|
|
140
|
+
output(options.json ? { changed: changed.map(file => file.path), check: !!options.check }
|
|
141
|
+
: changed.length ? `${changed.length} source file(s) ${options.check ? "need formatting" : "formatted"}.` : "All sources are formatted.");
|
|
142
|
+
if (options.check && changed.length) process.exitCode = 1;
|
|
143
|
+
}
|
|
144
|
+
|
|
139
145
|
async function packageCommand() {
|
|
140
146
|
const directory = path.resolve(options.project || ".");
|
|
141
147
|
const { manifest, package: own } = await loadPackage(directory);
|
|
142
148
|
const compiler = await createCompiler();
|
|
143
149
|
const result = diagnostics(
|
|
144
150
|
await compiler.check({
|
|
151
|
+
languageProfile: '1.0-rc.2', verification: {layers: []},
|
|
145
152
|
sources: own.sources,
|
|
146
153
|
package: { name: own.name, version: own.version },
|
|
147
154
|
...(await packageInput(manifest, directory)),
|
|
@@ -181,8 +188,10 @@ async function init() {
|
|
|
181
188
|
const current = await readOptional(configFile);
|
|
182
189
|
const config =
|
|
183
190
|
current === null
|
|
184
|
-
? { version: 1, sources: ["laws"], targets: [] }
|
|
191
|
+
? { version: 2, languageProfile: "1.0-rc.2", verification: { layers: [] }, sources: ["laws"], targets: [] }
|
|
185
192
|
: JSON.parse(current);
|
|
193
|
+
if(config.version!==2||config.languageProfile!=='1.0-rc.2')
|
|
194
|
+
throw new Error('Existing projects require configuration version 2 and languageProfile 1.0-rc.2');
|
|
186
195
|
if (
|
|
187
196
|
config.targets.some(
|
|
188
197
|
(t) =>
|
|
@@ -228,7 +237,7 @@ async function init() {
|
|
|
228
237
|
if (current === null)
|
|
229
238
|
await atomicWrite(
|
|
230
239
|
starter,
|
|
231
|
-
await readFile(new URL("../starter.lawspec", import.meta.url), "utf8"),
|
|
240
|
+
await readFile(new URL("../starter-rc1.lawspec", import.meta.url), "utf8"),
|
|
232
241
|
true,
|
|
233
242
|
);
|
|
234
243
|
if (options.machineBits !== undefined) config.machineBits = options.machineBits;
|
|
@@ -290,7 +299,7 @@ async function lastRuns() {
|
|
|
290
299
|
const known = runs.get(law) ?? {};
|
|
291
300
|
const latest = (known.passed ?? "") > (run.passed ?? "") ? known : run;
|
|
292
301
|
runs.set(law, { flaky: known.flaky || run.flaky, adequacy: run.adequacy ?? known.adequacy,
|
|
293
|
-
passed: latest.passed, environment: latest.environment });
|
|
302
|
+
passed: latest.passed, seed: latest.seed, environment: latest.environment });
|
|
294
303
|
}
|
|
295
304
|
}
|
|
296
305
|
return { runs, attestations };
|
|
@@ -401,11 +410,19 @@ async function runTests(compiler, input, selected, roots, config) {
|
|
|
401
410
|
}));
|
|
402
411
|
// The laws the attestation touches, each with how its dependencies
|
|
403
412
|
// were wired (the run's id and times aside).
|
|
404
|
-
const attested =
|
|
405
|
-
|
|
413
|
+
const attested = attestedKeys(planned);
|
|
414
|
+
if(!planned.tests.length&&!options.benchmarks){
|
|
415
|
+
summaries.push({target:target.language,root:target.root,seed:nativeSeed(seed),ran:[],unchanged:0,
|
|
416
|
+
ok:true,testsExecuted:0,selection:'no-selected-native-checks'});
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
406
419
|
const pending = await planWrites(root, planned.files);
|
|
407
420
|
if (pending.changes.length)
|
|
408
421
|
throw new Error(`${target.language}: generated files are out of date; run lawspec generate${options.minify ? " --minify" : ""}`);
|
|
422
|
+
for(const preparation of configurationInvocations(target)){
|
|
423
|
+
const result=await spawned(preparation.command,preparation.args,root,process.env);
|
|
424
|
+
if(!result.ok)throw new Error(`${target.language}: native build metadata preparation failed`);
|
|
425
|
+
}
|
|
409
426
|
const report_ = await doctor(target, root, planned.files);
|
|
410
427
|
if (!report_.ok) throw new Error(`${target.language}: ${report_.message}\n${report_.instructions}`);
|
|
411
428
|
const generated = new Set(planned.files.filter((f) => f.ownership === "generated").map((f) => f.path));
|
|
@@ -420,6 +437,7 @@ async function runTests(compiler, input, selected, roots, config) {
|
|
|
420
437
|
const identity = projectKey(root);
|
|
421
438
|
const resultsFile = path.join(configRoot, ".lawspec", "results", `${target.language}-${identity}.json`);
|
|
422
439
|
const previous = JSON.parse((await readOptional(resultsFile)) ?? '{"version":1,"laws":{}}');
|
|
440
|
+
const attempts = {...(previous.attempts ?? {})};
|
|
423
441
|
const {directory: failures, file: databaseFile, database} = await failureDatabase(configRoot, target.language, root);
|
|
424
442
|
// Recording again runs every law, so each records what it sees now.
|
|
425
443
|
const chosen = selectByTags(planned.tests, options.tag ?? [], options["exclude-tag"] ?? []);
|
|
@@ -431,10 +449,23 @@ async function runTests(compiler, input, selected, roots, config) {
|
|
|
431
449
|
// databases beside it (Hypothesis, proptest).
|
|
432
450
|
const replayed = options.seed === undefined ? stale.filter((entry) => database[entry.law]) : [];
|
|
433
451
|
const batches = [
|
|
434
|
-
...[...new Set(replayed.map((entry) => database[entry.law].seed))].map((s) =>
|
|
435
|
-
({ seed: String(s), entries: replayed.filter((entry) => database[entry.law].seed === s) })),
|
|
452
|
+
...[...new Set(replayed.map((entry) => nativeSeed(database[entry.law].seed)))].map((s) =>
|
|
453
|
+
({ seed: String(s), entries: replayed.filter((entry) => nativeSeed(database[entry.law].seed) === s) })),
|
|
436
454
|
{ seed, entries: stale.filter((entry) => !replayed.includes(entry)) },
|
|
437
455
|
].filter((batch) => batch.entries.length);
|
|
456
|
+
const profile = {target:target.language,root,machineBits:input.machineBits,
|
|
457
|
+
minify:options.minify===true,build};
|
|
458
|
+
// Persist pending attempts before starting a native process. Interrupted or
|
|
459
|
+
// failed setup cannot leave an older passing cache entry looking completed.
|
|
460
|
+
for(const entry of stale){
|
|
461
|
+
Object.assign(attempts,recordNativeAttempts({laws:[entry],command:null},[],
|
|
462
|
+
{keys,seed,ok:false,profile,allEntries:planned.tests}));
|
|
463
|
+
}
|
|
464
|
+
const pendingLaws=Object.fromEntries(Object.entries(previous.laws??{})
|
|
465
|
+
.filter(([id])=>!stale.some(entry=>entry.law===id)));
|
|
466
|
+
await mkdir(path.dirname(resultsFile),{recursive:true});
|
|
467
|
+
await writeFile(path.join(path.dirname(resultsFile),".gitignore"),"*\n");
|
|
468
|
+
await atomicWrite(resultsFile,JSON.stringify({...previous,version:1,laws:pendingLaws,attempts},null,2)+"\n");
|
|
438
469
|
const passed = [];
|
|
439
470
|
const unrun = [];
|
|
440
471
|
let failed = false;
|
|
@@ -477,21 +508,26 @@ async function runTests(compiler, input, selected, roots, config) {
|
|
|
477
508
|
batches: for (const batch of batches) {
|
|
478
509
|
for (const run of invocations(target, batch.entries, { offline, scratch, coverage: useCoverage ? coverage : null,
|
|
479
510
|
xdist, root, coverageConfig: report_.coverage })) {
|
|
480
|
-
const since = Date.now()
|
|
511
|
+
const since = Date.now();
|
|
481
512
|
const { ok, output } = await spawned(run.command, run.args, root,
|
|
482
513
|
{ ...process.env, ...run.env, LAWSPEC_SEED: batch.seed, HSPEC_SEED: batch.seed,
|
|
483
514
|
LAWSPEC_STATS: stats, LAWSPEC_FAILURES: failures, LAWSPEC_RECORDED: recordedFolder,
|
|
484
515
|
...(options["update-recorded"] ? { LAWSPEC_UPDATE_RECORDED: "1" } : {}) }, run.report?.kind === "go-json");
|
|
485
516
|
if (run.coverage) coverageRuns.push(run.coverage);
|
|
486
517
|
const executed = await executedTests(run.report, output, root, since);
|
|
518
|
+
const observed=recordNativeAttempts(run,executed,{keys,seed:batch.seed,ok,profile,output,allEntries:planned.tests});
|
|
519
|
+
if(!ok&&!run.laws.length)Object.assign(attempts,recordNativeAttempts({laws:batch.entries,command:run.command},[],
|
|
520
|
+
{keys,seed:batch.seed,ok:false,profile,output,allEntries:planned.tests}));
|
|
521
|
+
Object.assign(attempts,observed);
|
|
487
522
|
for (const law of run.laws) seedOf.set(law.law, batch.seed);
|
|
523
|
+
// A completed combined model method remains scoped to its own checks,
|
|
524
|
+
// even if another selected method in this invocation failed.
|
|
525
|
+
passed.push(...run.laws.filter(entry=>['passed','known-failing'].includes(observed[entry.law]?.outcome)||!expected(entry)));
|
|
488
526
|
if (report) junit.push({ target: `${target.language} (${target.root})`, xml: await junitOf(run, executed, root, since) });
|
|
489
527
|
if (!ok || executed.some((test) => test.status === "failed")) { failed = true; break batches; }
|
|
490
528
|
// A runner whose filter matched nothing reports success, so a law
|
|
491
529
|
// counts as passed only if the runner's report shows its tests ran.
|
|
492
|
-
|
|
493
|
-
passed.push(...run.laws.filter((law) => ran.has(law) || !expected(law)));
|
|
494
|
-
unrun.push(...run.laws.filter((law) => !ran.has(law) && expected(law)));
|
|
530
|
+
unrun.push(...run.laws.filter(entry=>!passed.includes(entry)&&expected(entry)));
|
|
495
531
|
}
|
|
496
532
|
}
|
|
497
533
|
if (unrun.length) failed = true;
|
|
@@ -523,7 +559,7 @@ async function runTests(compiler, input, selected, roots, config) {
|
|
|
523
559
|
for (const entry of passed) {
|
|
524
560
|
const label = entry.label;
|
|
525
561
|
const observed = statistics.filter((s) => s.law === label);
|
|
526
|
-
laws[entry.law] = { key: keys.get(entry.law), seed:
|
|
562
|
+
laws[entry.law] = { key: keys.get(entry.law), seed: nativeSeed(seedOf.get(entry.law) ?? seed), passed: new Date().toISOString(),
|
|
527
563
|
// A law the attestation touches names the run it passed in.
|
|
528
564
|
...(attestation && attested.has(entry.law) ? { environment: attestation.run.id } : {}),
|
|
529
565
|
...(observed.some((s) => s.outcome === "flaky") ? { flaky: true } : {}),
|
|
@@ -533,9 +569,10 @@ async function runTests(compiler, input, selected, roots, config) {
|
|
|
533
569
|
// A law that failed is recorded with its seed; one that passed leaves.
|
|
534
570
|
for (const entry of stale) {
|
|
535
571
|
if (passed.includes(entry)) delete database[entry.law];
|
|
536
|
-
else
|
|
572
|
+
else {
|
|
537
573
|
delete laws[entry.law];
|
|
538
|
-
|
|
574
|
+
if(!seedOf.has(entry.law))continue;
|
|
575
|
+
database[entry.law] = { seed: nativeSeed(seedOf.get(entry.law)), failed: new Date().toISOString() };
|
|
539
576
|
}
|
|
540
577
|
}
|
|
541
578
|
await writeFile(path.join(configRoot, ".lawspec", "failures", ".gitignore"), "*\n");
|
|
@@ -546,14 +583,14 @@ async function runTests(compiler, input, selected, roots, config) {
|
|
|
546
583
|
const attestations = Object.fromEntries(Object.entries({ ...(previous.attestations ?? {}),
|
|
547
584
|
...(attestation ? { [attestation.run.id]: attestation } : {}) })
|
|
548
585
|
.filter(([id]) => Object.values(laws).some((run) => run.environment === id)));
|
|
549
|
-
await
|
|
586
|
+
await atomicWrite(resultsFile, JSON.stringify({ version: 1, laws, attempts,
|
|
550
587
|
...(Object.keys(attestations).length ? { attestations } : {}) }, null, 2) + "\n");
|
|
551
588
|
const flaky = statistics.filter((s) => s.outcome === "flaky").map((s) => s.law);
|
|
552
589
|
const unmet = statistics.flatMap((s) => (s.cover ?? []).filter((c) => !c.met).map((c) => `${s.law}: cover ${c.required}% "${c.label}" (${c.observed}%)`));
|
|
553
590
|
const benchmarks = statistics.filter((s) => s.benchmark);
|
|
554
591
|
// How each parallel unit's tests actually ran at the same time.
|
|
555
592
|
const parallelism = statistics.filter((s) => s.parallel).map(({ parallel, mode, workers }) => ({ unit: parallel, mode, workers }));
|
|
556
|
-
summaries.push({ target: target.language, root: target.root, seed:
|
|
593
|
+
summaries.push({ target: target.language, root: target.root, seed: nativeSeed(seed), ran: stale.map((e) => e.law),
|
|
557
594
|
...(attestation ? { environment: attestation.environment } : {}),
|
|
558
595
|
unchanged: chosen.length - stale.length, ok: !failed,
|
|
559
596
|
...(chosen.length !== planned.tests.length ? { deselected: planned.tests.length - chosen.length } : {}),
|
|
@@ -571,7 +608,8 @@ async function runTests(compiler, input, selected, roots, config) {
|
|
|
571
608
|
}
|
|
572
609
|
output(options.json ? summaries : summaries.map((s) =>
|
|
573
610
|
`${s.target}${summaries.filter(other => other.target === s.target).length > 1 ? ` (${s.root})` : ""}: ${s.ran.length ? `ran ${s.ran.length} law(s) with seed ${s.seed}${s.environment ? ` in environment ${s.environment}` : ""}` : "nothing to run"}` +
|
|
574
|
-
|
|
611
|
+
(s.selection==='no-selected-native-checks'?'; no native checks selected; intrinsic definition checks passed.':
|
|
612
|
+
`, ${s.unchanged} unchanged since their last passing run.${s.ok ? "" : " FAILED"}`) +
|
|
575
613
|
(s.deselected ? `\n${s.deselected} law(s) not selected by --tag or --exclude-tag.` : "") +
|
|
576
614
|
(s.unrun ? `\nNo tests ran for ${s.unrun.join(", ")}; the runner matched none of their tests.` : "") +
|
|
577
615
|
(s.flaky ? `\nFlaky (failed, then passed on a retry): ${s.flaky.join(", ")}` : "") +
|
|
@@ -672,7 +710,7 @@ async function main() {
|
|
|
672
710
|
}
|
|
673
711
|
if (!verb || ["help", "--help", "-h"].includes(verb)) {
|
|
674
712
|
output(
|
|
675
|
-
"LawSpec " + VERSION + "\nUsage: lawspec init --target <language> [--project <directory>] [--minify]\n lawspec check | doctor | explain <unit>::<law> | 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 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: " +
|
|
713
|
+
"LawSpec " + VERSION + "\nUsage: lawspec init --target <language> [--project <directory>] [--minify]\n lawspec fmt [paths...] [--check]\n lawspec lsp --stdio\n lawspec prove [--solver <z3-executable>] [--proof-timeout <ms>] [--json]\n lawspec check [--warn-matches] | doctor | explain [<unit>::<law>] [--view developer|business|formal|evidence] | 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 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: " +
|
|
676
714
|
targets.join(", "),
|
|
677
715
|
);
|
|
678
716
|
return;
|
|
@@ -681,7 +719,7 @@ async function main() {
|
|
|
681
719
|
output(VERSION);
|
|
682
720
|
return;
|
|
683
721
|
}
|
|
684
|
-
if (positional.length > (["explain", "evidence"].includes(verb) ? 1 : 0))
|
|
722
|
+
if (verb !== "fmt" && positional.length > (["explain", "evidence"].includes(verb) ? 1 : 0))
|
|
685
723
|
throw new Error(`Unexpected argument: ${positional.join(" ")}`);
|
|
686
724
|
if (verb === "examples") {
|
|
687
725
|
if (
|
|
@@ -712,6 +750,9 @@ async function main() {
|
|
|
712
750
|
);
|
|
713
751
|
return;
|
|
714
752
|
}
|
|
753
|
+
if (["solver","proof-timeout","proof-memory","proof-rlimit","proof-seed"].some(key => options[key] !== undefined) && verb !== "prove")
|
|
754
|
+
throw new Error("Z3 options apply to prove");
|
|
755
|
+
if (options.view && verb !== "explain") throw new Error("--view applies to explain");
|
|
715
756
|
if (options.output) throw new Error("--output is only supported by examples");
|
|
716
757
|
if (options.example) throw new Error("--example is only supported by examples");
|
|
717
758
|
if (options.minify && !["init", "generate", "examples", "test"].includes(verb))
|
|
@@ -723,23 +764,32 @@ async function main() {
|
|
|
723
764
|
throw new Error("--attestation applies to evidence and test");
|
|
724
765
|
if (options.seed !== undefined && !/^[0-9]+$/.test(options.seed))
|
|
725
766
|
throw new Error("--seed must be a whole number");
|
|
767
|
+
if (options["warn-matches"] && verb !== "check") throw new Error("--warn-matches applies to check");
|
|
768
|
+
if (options.stdio && verb !== "lsp") throw new Error("--stdio applies to lsp");
|
|
769
|
+
if (verb === "lsp") {
|
|
770
|
+
if (!options.stdio) throw new Error("lsp requires --stdio");
|
|
771
|
+
return serveLanguage();
|
|
772
|
+
}
|
|
773
|
+
if (verb === "fmt") return formatCommand();
|
|
726
774
|
if (verb === "init") return init();
|
|
727
775
|
if (verb === "package") return packageCommand();
|
|
728
|
-
if (!["check", "doctor", "evidence", "explain", "generate", "test"].includes(verb))
|
|
776
|
+
if (!["check", "doctor", "evidence", "explain", "generate", "test", "prove"].includes(verb))
|
|
729
777
|
throw new Error(`Unknown command: ${verb}`);
|
|
730
778
|
const config = JSON.parse(await readFile(configFile, "utf8"));
|
|
731
779
|
if (
|
|
732
|
-
config.version
|
|
780
|
+
config.version!==2 ||
|
|
733
781
|
!Array.isArray(config.sources) ||
|
|
734
782
|
!Array.isArray(config.targets)
|
|
735
783
|
)
|
|
736
784
|
throw new Error(
|
|
737
|
-
"Expected lawspec.json version
|
|
785
|
+
"Expected lawspec.json version 2 with languageProfile 1.0-rc.2, sources and targets arrays",
|
|
738
786
|
);
|
|
787
|
+
if (config.languageProfile !== "1.0-rc.2") throw new Error("Configuration version 2 requires languageProfile 1.0-rc.2");
|
|
739
788
|
const selected = config.targets.filter(
|
|
740
789
|
(t) => !options.target || t.language === options.target,
|
|
741
790
|
);
|
|
742
|
-
if (["doctor", "generate", "test"].includes(verb) && !selected.length
|
|
791
|
+
if (["doctor", "generate", "test"].includes(verb) && !selected.length &&
|
|
792
|
+
!(verb === "test" && !options.benchmarks && config.version === 2 && !(config.verification?.layers ?? []).some(layer => ["exhaustive", "property", "examples", "model"].includes(layer))))
|
|
743
793
|
throw new Error("No matching configured target");
|
|
744
794
|
const roots = selected.map((t) => path.resolve(configRoot, t.root));
|
|
745
795
|
if (new Set(roots).size !== roots.length)
|
|
@@ -769,11 +819,28 @@ async function main() {
|
|
|
769
819
|
const input = {
|
|
770
820
|
...(cache === undefined ? {} : { cacheDirectory: cache }),
|
|
771
821
|
sources: await sources(config),
|
|
822
|
+
languageProfile: config.languageProfile, verification: config.verification ?? { layers: [] },
|
|
772
823
|
...(await packageInput(config, configRoot)),
|
|
773
824
|
generation: config.generation,
|
|
774
825
|
machineBits: options.machineBits ?? config.machineBits ?? 64,
|
|
775
826
|
};
|
|
776
827
|
const compiler = await createCompiler();
|
|
828
|
+
if (verb === "prove") {
|
|
829
|
+
if (config.version !== 2) throw new Error("prove requires configuration version 2 and languageProfile 1.0-rc.2");
|
|
830
|
+
const result = diagnostics(await proveWithZ3(compiler, input, {
|
|
831
|
+
...(options.solver !== undefined ? {binary: options.solver} : {}),
|
|
832
|
+
...Object.fromEntries([["proof-timeout","timeoutMs"],["proof-memory","memoryMb"],
|
|
833
|
+
["proof-rlimit","resourceLimit"],["proof-seed","seed"]]
|
|
834
|
+
.filter(([name]) => options[name] !== undefined).map(([name,key]) => [key,Number(options[name])])),
|
|
835
|
+
}));
|
|
836
|
+
output(options.json ? result : result.solverEvidence.length
|
|
837
|
+
? result.solverEvidence.map(row => `${row.declaration}: ${row.status} (${row.outcome}). ${row.reason}`).join("\n")
|
|
838
|
+
: (input.verification?.layers.includes("proof")
|
|
839
|
+
? "No source law obligations are available. No solver was invoked."
|
|
840
|
+
: "No proof layer selected. Intrinsic definition checks passed; no solver was invoked."));
|
|
841
|
+
if (result.solverEvidence.some(row => row.status !== "proved")) process.exitCode = 2;
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
777
844
|
// Each obligation reports how it is discharged, strongest first.
|
|
778
845
|
const statuses = [
|
|
779
846
|
["proved", "PROVED"],
|
|
@@ -788,6 +855,10 @@ async function main() {
|
|
|
788
855
|
["known-failing", "KNOWN FAILING"],
|
|
789
856
|
["flaky", "FLAKY"],
|
|
790
857
|
["skipped", "SKIPPED"],
|
|
858
|
+
["planned", "PLANNED"],
|
|
859
|
+
["not-verified", "NOT VERIFIED"],
|
|
860
|
+
["incomplete", "INCOMPLETE"],
|
|
861
|
+
["unsupported", "UNSUPPORTED"],
|
|
791
862
|
];
|
|
792
863
|
const evidenceSummary = (evidence) => {
|
|
793
864
|
if (!evidence.length) return "";
|
|
@@ -800,7 +871,9 @@ async function main() {
|
|
|
800
871
|
};
|
|
801
872
|
const obligationName = (item) => item.declaration.replace("::law::", "::");
|
|
802
873
|
if (verb === "check") {
|
|
803
|
-
const result = diagnostics(await compiler.check(input));
|
|
874
|
+
const result = diagnostics(await compiler.check({...input, ...(options["warn-matches"] ? {warnMatches:true} : {})}));
|
|
875
|
+
if (!options.json) for (const warning of result.warnings ?? [])
|
|
876
|
+
console.error(`${warning.at ? `${warning.at.file}:${warning.at.line}:${warning.at.column}: ` : ""}warning ${warning.code}: ${warning.message}`);
|
|
804
877
|
for (const target of selected) {
|
|
805
878
|
if (target.nativeBindings !== undefined)
|
|
806
879
|
diagnostics(await compiler.check({...input, nativeBindings: target.nativeBindings}));
|
|
@@ -808,7 +881,9 @@ async function main() {
|
|
|
808
881
|
output(
|
|
809
882
|
options.json
|
|
810
883
|
? result
|
|
811
|
-
: `
|
|
884
|
+
: `Compiled ${result.laws.length} law(s). Intrinsic definition checks passed.` +
|
|
885
|
+
(result.verification?.selection === "no-selected-checks"
|
|
886
|
+
? " No law checks selected." : evidenceSummary(result.evidence ?? [])),
|
|
812
887
|
);
|
|
813
888
|
return;
|
|
814
889
|
}
|
|
@@ -817,18 +892,20 @@ async function main() {
|
|
|
817
892
|
// ran; otherwise each law shows the attested run it last passed in.
|
|
818
893
|
const named = await readAttestation(config);
|
|
819
894
|
const result = diagnostics(await compiler.check({ ...input, ...(named ? { attestation: named } : {}) }));
|
|
820
|
-
let evidence = result.evidence
|
|
895
|
+
let evidence = attachNativeEvidence(result.evidence,await readNativeObservations({compiler,input,selected,roots,
|
|
896
|
+
configRoot,build:await buildDigest(),evidence:result.evidence,attestation:named}));
|
|
821
897
|
const { runs, attestations } = await lastRuns();
|
|
822
898
|
const environments = named ? [result.attestation] : [];
|
|
823
899
|
if (!named) for (const [id, attestation] of attestations) {
|
|
824
900
|
const laws = new Set([...runs].filter(([, run]) => run.environment === id).map(([law]) => law));
|
|
825
901
|
if (!laws.size) continue;
|
|
826
902
|
const attested = diagnostics(await compiler.check({ ...input, attestation }));
|
|
827
|
-
const fields = new Map(attested.evidence.filter((item) => item.against && laws.has(item.declaration))
|
|
828
|
-
.map(
|
|
903
|
+
const fields = new Map(attested.evidence.filter((item) => (item.against || item.plannedAgainst) && laws.has(item.declaration))
|
|
904
|
+
.map(item => [item.declaration, {environment: item.environment ?? item.plannedEnvironment,
|
|
905
|
+
environmentRun: item.environmentRun ?? item.plannedEnvironmentRun, against: item.against ?? item.plannedAgainst}]));
|
|
829
906
|
evidence = evidence.map((item) => item.stage === "law" && fields.has(item.declaration) ? { ...item, ...fields.get(item.declaration) } : item);
|
|
830
907
|
environments.push({ ...attested.attestation, dependencies: attested.attestation.dependencies
|
|
831
|
-
.map((d) => ({ ...d, obligations: d.obligations.filter((law) => laws.has(law)) })) });
|
|
908
|
+
.map((d) => ({ ...d, obligations: [...new Set([...d.obligations, ...(d.plannedObligations ?? [])])].filter((law) => laws.has(law)), plannedObligations: [] })) });
|
|
832
909
|
}
|
|
833
910
|
// Native bindings are configured per target; their obligations are added.
|
|
834
911
|
for (const target of selected) {
|
|
@@ -844,9 +921,10 @@ async function main() {
|
|
|
844
921
|
// The last run's outcome (lawspec test): a law that failed, then passed
|
|
845
922
|
// on a retry, is flaky; what its generated cases covered is its adequacy.
|
|
846
923
|
evidence = evidence.map((item) => {
|
|
924
|
+
if(item.nativeEvidence)return item;
|
|
847
925
|
const run = item.stage === "law" ? runs.get(item.declaration) : undefined;
|
|
848
926
|
if (!run) return item;
|
|
849
|
-
return { ...item, ...(run.adequacy ? { adequacy: run.adequacy } : {}),
|
|
927
|
+
return { ...item, lastNativeRun: {passed: run.passed, seed: run.seed}, ...(run.adequacy ? { adequacy: run.adequacy } : {}),
|
|
850
928
|
...(run.flaky && ["property-tested", "exhaustively-checked"].includes(item.status)
|
|
851
929
|
? { status: "flaky", reason: `${item.reason}; its last run failed, then passed on a retry` } : {}) };
|
|
852
930
|
});
|
|
@@ -861,7 +939,9 @@ async function main() {
|
|
|
861
939
|
return `${label} (${items.length})\n` + items.map((item) =>
|
|
862
940
|
` ${item.stage} ${obligationName(item)}${item.target ? ` [${item.target}]` : ""}` +
|
|
863
941
|
(item.claim ? `: ${item.claim.text}` : "") + `\n ${item.reason}` +
|
|
864
|
-
(item.
|
|
942
|
+
(item.nativeEvidence ? `\n ${nativeEvidenceText(item).replaceAll("\n","\n ")}` : "") +
|
|
943
|
+
(item.lastNativeRun ? `\n last native run passed at ${item.lastNativeRun.passed} (seed ${item.lastNativeRun.seed})` : "") +
|
|
944
|
+
(item.against ? `\n last recorded passing run in environment ${item.environment} (run ${item.environmentRun.id}) against ` +
|
|
865
945
|
item.against.map(dependencyText).join("; ") : "")).join("\n");
|
|
866
946
|
})
|
|
867
947
|
.filter((section) => section !== null),
|
|
@@ -871,7 +951,8 @@ async function main() {
|
|
|
871
951
|
// Where the tests ran: reporting only, so no status above changes.
|
|
872
952
|
...environments.map((e) => `ENVIRONMENT ${e.environment} (run ${e.run.id}, recorded ${e.run.recordedAt})\n` +
|
|
873
953
|
e.dependencies.map((d) => ` ${dependencyText(d)}; ` + (d.obligations.length
|
|
874
|
-
? `${d.obligations.length} tested obligation(s)` :
|
|
954
|
+
? `${d.obligations.length} tested obligation(s)` :
|
|
955
|
+
d.plannedObligations?.length ? `${d.plannedObligations.length} planned obligation(s); no completed run linked` : "no tested obligation relies on it")).join("\n"))]
|
|
875
956
|
.join("\n\n"),
|
|
876
957
|
);
|
|
877
958
|
return;
|
|
@@ -884,17 +965,19 @@ async function main() {
|
|
|
884
965
|
({ e }) => !positional[0] || `${e.owner}::${e.name}` === positional[0],
|
|
885
966
|
);
|
|
886
967
|
if (!indices.length) throw new Error("No matching law");
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
);
|
|
968
|
+
const view = options.view ?? "developer";
|
|
969
|
+
if (!explanationViews.includes(view)) throw new Error(`Choose --view ${explanationViews.join("|")}`);
|
|
970
|
+
const observed={...result,evidence:attachNativeEvidence(result.evidence,await readNativeObservations({
|
|
971
|
+
compiler,input,selected,roots,configRoot,build:await buildDigest(),evidence:result.evidence,
|
|
972
|
+
attestation:await readAttestation(config)}))};
|
|
973
|
+
const explanations = indices.map(({e}) => explainLaw(e, observed, view));
|
|
974
|
+
output(options.json ? explanations : explanations.map(e => e.text).join("\n\n"));
|
|
975
|
+
return;
|
|
976
|
+
}
|
|
977
|
+
if (verb === "test" && !options.benchmarks && config.version === 2 && !(config.verification?.layers ?? []).some(layer => ["exhaustive", "property", "examples", "model"].includes(layer))) {
|
|
978
|
+
const checked = diagnostics(await compiler.check(input));
|
|
979
|
+
output(options.json ? { verification: checked.verification, evidence: checked.evidence, testsExecuted: 0 }
|
|
980
|
+
: (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."));
|
|
898
981
|
return;
|
|
899
982
|
}
|
|
900
983
|
if (verb === "test") return runTests(compiler, input, selected, roots, config);
|