lawspec 0.25.0 → 0.27.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/NORMALIZATION-LICENSES.txt +296 -0
- package/README.md +13 -4
- package/api.mjs +0 -8
- package/bin/lawspec.mjs +114 -79
- package/build.json +99 -117
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -0
- package/doctor.mjs +14 -4
- package/examples/native-payments/clojure/lawspec.json +1 -1
- package/examples/native-payments/csharp/lawspec.json +1 -1
- package/examples/native-payments/elixir/lawspec.json +1 -1
- package/examples/native-payments/erlang/lawspec.json +1 -1
- package/examples/native-payments/fsharp/lawspec.json +1 -1
- package/examples/native-payments/gleam/lawspec.json +1 -1
- package/examples/native-payments/go/lawspec.json +1 -1
- package/examples/native-payments/groovy/lawspec.json +1 -1
- package/examples/native-payments/haskell/lawspec.json +1 -1
- package/examples/native-payments/java/lawspec.json +1 -1
- package/examples/native-payments/javascript/lawspec.json +1 -1
- package/examples/native-payments/kotlin/lawspec.json +1 -1
- package/examples/native-payments/prolog/lawspec.json +20 -0
- package/examples/native-payments/prolog/src/domain/payments.pl +23 -0
- package/examples/native-payments/prolog/tests/domain/payment_generators.pl +17 -0
- package/examples/native-payments/python/lawspec.json +1 -1
- package/examples/native-payments/rust/lawspec.json +1 -1
- package/examples/native-payments/scala/lawspec.json +1 -1
- package/examples/native-payments/swift/lawspec.json +1 -1
- package/examples/native-payments/typescript/lawspec.json +1 -1
- package/examples/packages/orders/lawspec.json +1 -1
- package/examples/packages/orders/orders.lawspec +27 -25
- package/examples/packages/shop-domain/src/domain.lawspec +15 -14
- package/examples/packages/shop-tax-1/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-1/src/rates.lawspec +1 -0
- package/examples/packages/shop-tax-2/src/api.lawspec +1 -0
- package/examples/packages/shop-tax-2/src/rates.lawspec +1 -0
- package/examples/rc1/authorization-snapshots.lawspec +24 -23
- package/examples/rc1/banner-filenames.lawspec +7 -6
- package/examples/rc1/bit-codec.lawspec +12 -11
- package/examples/rc1/bounded-witness-search.lawspec +52 -45
- package/examples/rc1/conflicting-requirements.lawspec +8 -7
- package/examples/rc1/constructive-witnesses.lawspec +40 -33
- package/examples/rc1/documentary-review.lawspec +9 -8
- package/examples/rc1/empty-domains.lawspec +16 -15
- package/examples/rc1/finite-integer-domains.lawspec +24 -23
- package/examples/rc1/law-metadata.lawspec +6 -5
- package/examples/rc1/native-payments.lawspec +17 -16
- package/examples/rc1/nesting/rrr.lawspec +4 -3
- package/examples/rc1/nesting/rru.lawspec +7 -6
- package/examples/rc1/nesting/rur.lawspec +7 -6
- package/examples/rc1/nesting/ruu.lawspec +10 -9
- package/examples/rc1/nesting/urr.lawspec +7 -6
- package/examples/rc1/nesting/uru.lawspec +10 -9
- package/examples/rc1/nesting/uur.lawspec +10 -9
- package/examples/rc1/nesting/uuu.lawspec +13 -12
- package/examples/rc1/order-workflow.lawspec +18 -17
- package/examples/rc1/parcel-measurements.lawspec +14 -13
- package/examples/rc1/picture-records.lawspec +6 -5
- package/examples/rc1/picture-tuples.lawspec +6 -5
- package/examples/rc1/record-payloads.lawspec +12 -11
- package/examples/rc1/recursive-records.lawspec +11 -10
- package/examples/rc1/refund-conformance.lawspec +7 -6
- package/examples/rc1/refund-policy.lawspec +15 -14
- package/examples/rc1/requirement-composition.lawspec +26 -25
- package/examples/rc1/structural-records.lawspec +13 -12
- package/examples/rc1-authoring.lawspec +6 -5
- 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 +19 -18
- 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 +68 -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 +7 -6
- 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 +161 -160
- 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 +7 -7
- package/explain.mjs +6 -4
- package/expression-presentation.mjs +8 -8
- package/files.mjs +1 -1
- package/index.d.ts +10 -528
- package/launcher.mjs +9 -2
- package/lsp.mjs +10 -6
- package/native-evidence.mjs +25 -12
- package/native-examples.mjs +3 -3
- package/package.json +2 -1
- package/starter-rc1.lawspec +6 -5
- package/starter.lawspec +16 -15
- package/templates.mjs +88 -5
- package/test-command.mjs +40 -4
- package/migrate.mjs +0 -135
- package/migration-bindings.mjs +0 -86
- package/migration-cases.mjs +0 -45
- package/migration-collections.mjs +0 -54
- package/migration-correspondence.mjs +0 -275
- package/migration-generation.mjs +0 -99
- package/migration-laws.mjs +0 -102
- package/migration-records.mjs +0 -166
- package/migration-source.mjs +0 -247
- package/migration-write.mjs +0 -156
package/lsp.mjs
CHANGED
|
@@ -46,8 +46,8 @@ export async function serveLanguage(input = process.stdin, output = process.stdo
|
|
|
46
46
|
let config;
|
|
47
47
|
try { config = JSON.parse(await readFile(path.join(workspace, 'lawspec.json'), 'utf8')); }
|
|
48
48
|
catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
49
|
-
if(config&&(config.version!==2||config.languageProfile!=='1.0-rc.
|
|
50
|
-
throw new Error('The language server requires configuration version 2 and languageProfile 1.0-rc.
|
|
49
|
+
if(config&&(config.version!==2||config.languageProfile!=='1.0-rc.2'))
|
|
50
|
+
throw new Error('The language server requires configuration version 2 and languageProfile 1.0-rc.2.');
|
|
51
51
|
for (const entry of config?.sources ?? []) await visit(path.resolve(workspace, entry));
|
|
52
52
|
for (const [uri, document] of documents) sources.set(fileURLToPath(uri), { path: fileURLToPath(uri), content: document.text });
|
|
53
53
|
return [...sources.values()];
|
|
@@ -63,7 +63,7 @@ export async function serveLanguage(input = process.stdin, output = process.stdo
|
|
|
63
63
|
}
|
|
64
64
|
async function check() {
|
|
65
65
|
const sources = await projectSources();
|
|
66
|
-
const result = await compiler.check({ sources, languageProfile: '1.0-rc.
|
|
66
|
+
const result = await compiler.check({ sources, languageProfile: '1.0-rc.2', verification: { layers: [] }, ...(warnMatches ? {warnMatches:true} : {}) });
|
|
67
67
|
last = { sources, result };
|
|
68
68
|
for (const [uri, document] of documents) {
|
|
69
69
|
const file = fileURLToPath(uri);
|
|
@@ -72,7 +72,11 @@ export async function serveLanguage(input = process.stdin, output = process.stdo
|
|
|
72
72
|
const content = document.text.split('\n')[start.line] ?? '';
|
|
73
73
|
const end = { ...start, character: Math.min(content.length, start.character + ([...content.slice(start.character)][0]?.length ?? 0)) };
|
|
74
74
|
const range = d.span ? span(d.span)?.range ?? {start,end} : {start,end};
|
|
75
|
-
return { range, severity: d.severity === 'warning' ? 2 : 1, code: d.code, source: 'LawSpec', message: d.message
|
|
75
|
+
return { range, severity: d.severity === 'warning' ? 2 : 1, code: d.code, source: 'LawSpec', message: d.message,
|
|
76
|
+
...(d.related?.length ? {relatedInformation: d.related.flatMap(item => {
|
|
77
|
+
const origin = span(item.span);
|
|
78
|
+
return origin ? [{location: {uri: origin.uri, range: origin.range}, message: item.message}] : [];
|
|
79
|
+
})} : {}) };
|
|
76
80
|
});
|
|
77
81
|
send({ jsonrpc: '2.0', method: 'textDocument/publishDiagnostics', params: { uri, version: document.version, diagnostics } });
|
|
78
82
|
}
|
|
@@ -143,7 +147,7 @@ export async function serveLanguage(input = process.stdin, output = process.stdo
|
|
|
143
147
|
workspace = params.rootUri ? fileURLToPath(params.rootUri) : params.rootPath ?? workspace;
|
|
144
148
|
result = { capabilities: { textDocumentSync: 1, positionEncoding: 'utf-16', documentFormattingProvider: true,
|
|
145
149
|
documentSymbolProvider: true, hoverProvider: true, definitionProvider: true, referencesProvider: true },
|
|
146
|
-
serverInfo: { name: 'LawSpec', version: '1.0-rc.
|
|
150
|
+
serverInfo: { name: 'LawSpec', version: '1.0-rc.2' } };
|
|
147
151
|
break;
|
|
148
152
|
case 'initialized': break;
|
|
149
153
|
case 'workspace/didChangeConfiguration': {
|
|
@@ -168,7 +172,7 @@ export async function serveLanguage(input = process.stdin, output = process.stdo
|
|
|
168
172
|
const document = documents.get(params.textDocument.uri);
|
|
169
173
|
if (!document) { result = []; break; }
|
|
170
174
|
const sourcePath = fileURLToPath(params.textDocument.uri);
|
|
171
|
-
const response = await compiler.format({ sources: await projectSources(), languageProfile: '1.0-rc.
|
|
175
|
+
const response = await compiler.format({ sources: await projectSources(), languageProfile: '1.0-rc.2', verification: { layers: [] } });
|
|
172
176
|
if (response.diagnostics?.length) { result = []; break; }
|
|
173
177
|
const formatted = response.formattedSources.find(s => s.path === sourcePath);
|
|
174
178
|
result = formatted && formatted.content !== document.text
|
package/native-evidence.mjs
CHANGED
|
@@ -25,6 +25,7 @@ export function recordNativeAttempts(run, tests, {keys,seed,ok,profile,output,al
|
|
|
25
25
|
const model=(entry.obligations?.length??0)>0;
|
|
26
26
|
const complete=matched.length>0&&matched.every(test=>test.status==='passed')&&(ok||model);
|
|
27
27
|
const outcome=matched.some(test=>test.status==='failed')?'failed':
|
|
28
|
+
matched.some(test=>test.status==='incomplete')?'incomplete':
|
|
28
29
|
entry.skip?'skipped':complete?(entry.knownFailing?'known-failing':'passed'):
|
|
29
30
|
matched.length&&matched.every(test=>test.status==='skipped')?'skipped':'incomplete';
|
|
30
31
|
return [entry.law,{key:keys.get(entry.law),planKey:entry.key,seed:nativeSeed(seed),at,outcome,
|
|
@@ -41,10 +42,16 @@ export function recordNativeAttempts(run, tests, {keys,seed,ok,profile,output,al
|
|
|
41
42
|
}));
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
// A law an attestation touches is keyed by how its dependencies were wired:
|
|
46
|
+
// endpoint, kind, and a stand-in's product, version and conformance. What the
|
|
47
|
+
// run observed (reached, history digests, completion) and the identities
|
|
48
|
+
// reported beside it are not inputs, so they change no key.
|
|
44
49
|
export function attestedKeys(result) {
|
|
50
|
+
const wiring=d=>[d.dependency,d.endpoint,d.kind,
|
|
51
|
+
...(d.standIn?[d.standIn.identity,d.standIn.version,d.standIn.conformance]:[])];
|
|
45
52
|
return new Map((result.evidence??[]).filter(item=>item.against||item.plannedAgainst)
|
|
46
53
|
.map(item=>[item.declaration,JSON.stringify([
|
|
47
|
-
item.environment??item.plannedEnvironment,item.against??item.plannedAgainst])]));
|
|
54
|
+
item.environment??item.plannedEnvironment,(item.against??item.plannedAgainst).map(wiring)])]));
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
const subject = (entry,item) => obligationTargets(entry).some(target=>
|
|
@@ -60,17 +67,22 @@ export async function readNativeObservations({compiler,input,selected,roots,conf
|
|
|
60
67
|
const record=JSON.parse(await readFile(file,'utf8').catch(error=>{
|
|
61
68
|
if(error.code==='ENOENT')return '{}';throw error;
|
|
62
69
|
}));
|
|
63
|
-
return {target,root,attempts:record.attempts??{},runs:record.laws??{}};
|
|
70
|
+
return {target,root,attempts:record.attempts??{},runs:record.laws??{},attestations:record.attestations??{}};
|
|
64
71
|
}));
|
|
65
72
|
if(!records.some(record=>Object.keys(record.attempts).length))return [];
|
|
66
73
|
const observations=[];
|
|
67
|
-
for(const {target,root,attempts,runs}of records){
|
|
74
|
+
for(const {target,root,attempts,runs,attestations}of records){
|
|
68
75
|
const plans=new Map(),contexts=new Map();
|
|
69
|
-
|
|
70
|
-
|
|
76
|
+
// An attempt is keyed by the wiring of the attestation it ran under: the
|
|
77
|
+
// one named now, or else the one lawspec test stored for its run.
|
|
78
|
+
const wiredBy=attempt=>attestation??(attempt?.environment?attestations[attempt.environment]:undefined);
|
|
79
|
+
const slot=(minify,wired)=>`${minify}\0${wired?.run?.id??''}`;
|
|
80
|
+
async function plan(minify,wired=attestation){
|
|
81
|
+
const key=slot(minify,wired);
|
|
82
|
+
if(!plans.has(key))plans.set(key,await compiler.planGeneration({...input,target:target.language,
|
|
71
83
|
sourceDir:target.sourceDir,testDir:target.testDir,nativeBindings:target.nativeBindings,minify,
|
|
72
|
-
...(
|
|
73
|
-
return plans.get(
|
|
84
|
+
...(wired?{attestation:wired}:{})}));
|
|
85
|
+
return plans.get(key);
|
|
74
86
|
}
|
|
75
87
|
const modes=[...new Set(Object.values(attempts).map(attempt=>attempt.profile?.minify)
|
|
76
88
|
.filter(mode=>typeof mode==='boolean'))];
|
|
@@ -83,9 +95,10 @@ export async function readNativeObservations({compiler,input,selected,roots,conf
|
|
|
83
95
|
continue;
|
|
84
96
|
}
|
|
85
97
|
const expected=new Map(base.tests.map(entry=>[entry.law,entry]));
|
|
86
|
-
async function context(minify){
|
|
87
|
-
|
|
88
|
-
|
|
98
|
+
async function context(minify,wired){
|
|
99
|
+
const key=slot(minify,wired);
|
|
100
|
+
if(contexts.has(key))return contexts.get(key);
|
|
101
|
+
const generated=await plan(minify,wired);
|
|
89
102
|
let result;
|
|
90
103
|
if(generated.diagnostics.length)result={reason:'Native generation is unavailable for the recorded layout'};
|
|
91
104
|
else {
|
|
@@ -103,7 +116,7 @@ export async function readNativeObservations({compiler,input,selected,roots,conf
|
|
|
103
116
|
}
|
|
104
117
|
}
|
|
105
118
|
}
|
|
106
|
-
contexts.set(
|
|
119
|
+
contexts.set(key,result);return result;
|
|
107
120
|
}
|
|
108
121
|
for(const [id,baseline]of expected){
|
|
109
122
|
const attempt=attempts[id];
|
|
@@ -115,7 +128,7 @@ export async function readNativeObservations({compiler,input,selected,roots,conf
|
|
|
115
128
|
typeof profile.minify!=='boolean'){
|
|
116
129
|
observations.push({...row,freshness:'stale',reason:'Compiler, target or machine profile differs'});continue;
|
|
117
130
|
}
|
|
118
|
-
const current=await context(profile.minify);
|
|
131
|
+
const current=await context(profile.minify,wiredBy(attempt));
|
|
119
132
|
if(current.reason){observations.push({...row,freshness:current.stale?'stale':'unavailable',reason:current.reason});continue;}
|
|
120
133
|
const entry=current.generated.tests.find(entry=>entry.law===id);
|
|
121
134
|
if(!entry||attempt.key!==current.keys.get(id)||attempt.planKey!==entry.key||
|
package/native-examples.mjs
CHANGED
|
@@ -31,8 +31,8 @@ export async function exportNativePayments(options, selected) {
|
|
|
31
31
|
'laws/payments.lawspec': law,
|
|
32
32
|
};
|
|
33
33
|
const config = JSON.parse(files['lawspec.json']);
|
|
34
|
-
if(config.version!==2||config.languageProfile!=='1.0-rc.
|
|
35
|
-
throw new Error(`Bundled native payments configuration for ${target} must use version 2 and languageProfile 1.0-rc.
|
|
34
|
+
if(config.version!==2||config.languageProfile!=='1.0-rc.2')
|
|
35
|
+
throw new Error(`Bundled native payments configuration for ${target} must use version 2 and languageProfile 1.0-rc.2`);
|
|
36
36
|
config.machineBits = options.machineBits ?? 64;
|
|
37
37
|
files['lawspec.json'] = JSON.stringify(config, null, options.minify ? undefined : 2) + '\n';
|
|
38
38
|
const instructions = target === 'gleam' ? setup[target].replace(
|
|
@@ -46,7 +46,7 @@ archive preserves distinct present and absent payments.
|
|
|
46
46
|
|
|
47
47
|
The specification uses the canonical language profile. The version 2 project
|
|
48
48
|
configuration selects its verification layers explicitly. Most targets bind
|
|
49
|
-
application-owned domain types; C
|
|
49
|
+
application-owned domain types; C#, Clojure and Prolog use the generated model data
|
|
50
50
|
and bind the application's functions and generators.
|
|
51
51
|
|
|
52
52
|
## Run
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lawspec",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "State the law once. Check it everywhere.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"CHANGELOG.md",
|
|
38
38
|
"LICENSE",
|
|
39
39
|
"UNICODE-LICENSE.txt",
|
|
40
|
+
"NORMALIZATION-LICENSES.txt",
|
|
40
41
|
"starter.lawspec",
|
|
41
42
|
"starter-rc1.lawspec",
|
|
42
43
|
"examples"
|
package/starter-rc1.lawspec
CHANGED
|
@@ -7,13 +7,13 @@ atoi of type Text -> Int32
|
|
|
7
7
|
law codec is
|
|
8
8
|
description:
|
|
9
9
|
"Converting an integer to decimal text and reading it back preserves it."
|
|
10
|
-
end
|
|
10
|
+
end description
|
|
11
11
|
|
|
12
12
|
definition:
|
|
13
13
|
for all (x of type Int32) =>
|
|
14
14
|
atoi (itoa x) must be x
|
|
15
|
-
end
|
|
16
|
-
end
|
|
15
|
+
end for all
|
|
16
|
+
end definition
|
|
17
17
|
|
|
18
18
|
expect itoa x = encoded
|
|
19
19
|
expect atoi encoded = x
|
|
@@ -21,5 +21,6 @@ law codec is
|
|
|
21
21
|
row -42, "-42"
|
|
22
22
|
row 0, "0"
|
|
23
23
|
row 42, "42"
|
|
24
|
-
end
|
|
25
|
-
end
|
|
24
|
+
end table
|
|
25
|
+
end law
|
|
26
|
+
end unit
|
package/starter.lawspec
CHANGED
|
@@ -3,33 +3,34 @@ unit example.atoi_codec
|
|
|
3
3
|
itoa :: Int32 -> Text
|
|
4
4
|
atoi :: Text -> Int32
|
|
5
5
|
|
|
6
|
-
law
|
|
7
|
-
definition
|
|
8
|
-
|
|
9
|
-
end
|
|
6
|
+
law "|itoa and then atoi yields a| is
|
|
7
|
+
definition :
|
|
8
|
+
apply law "|round trip identity is preserved| itoa atoi
|
|
9
|
+
end definition
|
|
10
10
|
|
|
11
|
-
description
|
|
11
|
+
description :
|
|
12
12
|
"converting an Int32 to Text with {itoa} and then back with {atoi} yields the original Int32"
|
|
13
|
-
end
|
|
13
|
+
end description
|
|
14
14
|
|
|
15
|
-
rationale
|
|
15
|
+
rationale :
|
|
16
16
|
"representing an Int32 as Text must not change its value"
|
|
17
|
-
end
|
|
17
|
+
end rationale
|
|
18
18
|
|
|
19
|
-
example
|
|
19
|
+
example "|negative integers use a minus sign and round-trip unchanged| :
|
|
20
20
|
x = -42
|
|
21
21
|
expect itoa x = "-42"
|
|
22
22
|
expect atoi (itoa x) = -42
|
|
23
|
-
end
|
|
23
|
+
end example
|
|
24
24
|
|
|
25
|
-
example
|
|
25
|
+
example "|zero renders as 0 and round-trips unchanged| :
|
|
26
26
|
x = 0
|
|
27
27
|
expect itoa x = "0"
|
|
28
28
|
expect atoi (itoa x) = 0
|
|
29
|
-
end
|
|
29
|
+
end example
|
|
30
30
|
|
|
31
|
-
references
|
|
31
|
+
references :
|
|
32
32
|
"left inverse"
|
|
33
33
|
"round-trip property"
|
|
34
|
-
end
|
|
35
|
-
end
|
|
34
|
+
end references
|
|
35
|
+
end law
|
|
36
|
+
end unit
|
package/templates.mjs
CHANGED
|
@@ -18,8 +18,39 @@ export const targets = [
|
|
|
18
18
|
"scala",
|
|
19
19
|
"groovy",
|
|
20
20
|
"clojure",
|
|
21
|
-
"swift"
|
|
21
|
+
"swift",
|
|
22
|
+
"prolog",
|
|
23
|
+
"hcl",
|
|
24
|
+
"yaml",
|
|
25
|
+
"antlr4",
|
|
26
|
+
"make"
|
|
22
27
|
];
|
|
28
|
+
export const programTargets = [
|
|
29
|
+
"java",
|
|
30
|
+
"python",
|
|
31
|
+
"javascript",
|
|
32
|
+
"typescript",
|
|
33
|
+
"go",
|
|
34
|
+
"haskell",
|
|
35
|
+
"kotlin",
|
|
36
|
+
"rust",
|
|
37
|
+
"erlang",
|
|
38
|
+
"elixir",
|
|
39
|
+
"gleam",
|
|
40
|
+
"fsharp",
|
|
41
|
+
"csharp",
|
|
42
|
+
"scala",
|
|
43
|
+
"groovy",
|
|
44
|
+
"clojure",
|
|
45
|
+
"swift",
|
|
46
|
+
"prolog"
|
|
47
|
+
];
|
|
48
|
+
export const artifactTargets = [
|
|
49
|
+
"hcl",
|
|
50
|
+
"yaml",
|
|
51
|
+
"antlr4",
|
|
52
|
+
"make"
|
|
53
|
+
];
|
|
23
54
|
export const targetLabels = [
|
|
24
55
|
[
|
|
25
56
|
"java",
|
|
@@ -88,6 +119,26 @@ export const targetLabels = [
|
|
|
88
119
|
[
|
|
89
120
|
"swift",
|
|
90
121
|
"Swift"
|
|
122
|
+
],
|
|
123
|
+
[
|
|
124
|
+
"prolog",
|
|
125
|
+
"Prolog"
|
|
126
|
+
],
|
|
127
|
+
[
|
|
128
|
+
"hcl",
|
|
129
|
+
"HCL"
|
|
130
|
+
],
|
|
131
|
+
[
|
|
132
|
+
"yaml",
|
|
133
|
+
"YAML"
|
|
134
|
+
],
|
|
135
|
+
[
|
|
136
|
+
"antlr4",
|
|
137
|
+
"ANTLR"
|
|
138
|
+
],
|
|
139
|
+
[
|
|
140
|
+
"make",
|
|
141
|
+
"Make"
|
|
91
142
|
]
|
|
92
143
|
];
|
|
93
144
|
|
|
@@ -108,7 +159,8 @@ export const commands = {
|
|
|
108
159
|
"scala": "scala test .",
|
|
109
160
|
"groovy": "gradle test",
|
|
110
161
|
"clojure": "clojure -M:test",
|
|
111
|
-
"swift": "swift test"
|
|
162
|
+
"swift": "swift test",
|
|
163
|
+
"prolog": "python lawspec_test.py"
|
|
112
164
|
};
|
|
113
165
|
|
|
114
166
|
export const setup = {
|
|
@@ -128,7 +180,12 @@ export const setup = {
|
|
|
128
180
|
"scala": "Use JDK 25 and Scala CLI 1.16 (the scala command), with Scala 3.9.0, ScalaCheck 1.20.0 and ScalaTest 3.2.20 (scalatest-funsuite) as test dependencies in project.scala; a program that imports lawspec.crypto or lawspec.network also needs Bouncy Castle bcprov-jdk18on 1.86. Run scala compile --test .",
|
|
129
181
|
"groovy": "Use JDK 25, Gradle 9.3.0 with the groovy plugin, Groovy 5.0.8 (org.apache.groovy:groovy), Spock 2.5-groovy-5.0, JetCheck 0.3.0 and JUnit Jupiter's API 5.14.0, and useJUnitPlatform(); the Java model compiles jointly with the Groovy sources, so src/main/java and src/test/java are Groovy source directories. A program that imports lawspec.crypto or lawspec.network also needs Bouncy Castle bcprov-jdk18on 1.86. Run gradle testClasses.",
|
|
130
182
|
"clojure": "Use JDK 25 and the Clojure CLI 1.12 with Clojure 1.12.5 and, for tests, test.check 1.1.3 (the :test alias). The Java model in java/src compiles with the JDK's compiler into target/classes, which lawspec.build does before the tests run (clojure -M:build compiles it alone). A program that imports lawspec.crypto or lawspec.network also needs Bouncy Castle bcprov-jdk18on 1.86. Run clojure -M:test.",
|
|
131
|
-
"swift": "Use Swift 6.2 or later (Xcode 26 on macOS 26, where CryptoKit has ML-KEM and ML-DSA) and SwiftPM. The generated runtime and test support are local targets under lawspec/ with no package dependencies; tests run on Swift Testing, from the toolchain, with LawSpec's own property engine. Package.swift declares the targets LawSpecRuntime, LawSpecTesting, App (src) and AppTests (tests), as lawspec init writes it. Run swift build --build-tests."
|
|
183
|
+
"swift": "Use Swift 6.2 or later (Xcode 26 on macOS 26, where CryptoKit has ML-KEM and ML-DSA) and SwiftPM. The generated runtime and test support are local targets under lawspec/ with no package dependencies; tests run on Swift Testing, from the toolchain, with LawSpec's own property engine. Package.swift declares the targets LawSpecRuntime, LawSpecTesting, App (src) and AppTests (tests), as lawspec init writes it. Run swift build --build-tests.",
|
|
184
|
+
"prolog": "Use SWI-Prolog 10.0+ and Python 3.13+ with janus-swi 1.5.3, pytest 8.4.x and Hypothesis 6.x. Install the generated project with python -m pip install -e \".[test]\". Run python lawspec_test.py (PLUnit with the checked Python model), or lawspec test. Set the target python field to the selected interpreter.",
|
|
185
|
+
"hcl": "Generate Terraform variables and checked tfvars using lawspec generate. Run tofu init -backend=false, tofu validate and tofu plan -var-file=configuration.tfvars.json. Artifact generation does not execute application laws.",
|
|
186
|
+
"yaml": "Generate YAML 1.2 configuration and a JSON Schema 2020-12 schema using lawspec generate. Validate edited YAML with a JSON Schema validator. Artifact generation does not execute application laws.",
|
|
187
|
+
"antlr4": "Compile LawSpecData.g4 with ANTLR 4. The grammar checks data syntax; numeric ranges and field predicates require the companion JSON Schema after decoding. Artifact generation does not execute application laws.",
|
|
188
|
+
"make": "Run make to check the project, generate its configured targets and execute its program target tests using the installed lawspec CLI."
|
|
132
189
|
};
|
|
133
190
|
|
|
134
191
|
// Each target's build files in the readable and the compact (minified) layout.
|
|
@@ -178,22 +235,24 @@ const scaffolds = {
|
|
|
178
235
|
"haskell": {
|
|
179
236
|
"readable": {
|
|
180
237
|
"stack.yaml": "snapshot: lts-24.58\npackages: [.]\n",
|
|
181
|
-
"package.yaml": "name: lawspec-example\nversion: 0.1.0\ndependencies: [base, text, bytestring, containers, network, directory, time]\nlibrary:\n source-dirs: src\ntests:\n laws:\n main: Spec.hs\n source-dirs: test\n dependencies: [lawspec-example, hspec, hedgehog, hspec-hedgehog, containers, mtl]\n ghc-options: [-threaded, -rtsopts, \"-with-rtsopts=-N\"]\n build-tools: [hspec-discover]\n",
|
|
238
|
+
"package.yaml": "name: lawspec-example\nversion: 0.1.0\ndependencies: [base, text, bytestring, containers, network, directory, time]\nlibrary:\n source-dirs: src\ntests:\n laws:\n main: Spec.hs\n source-dirs: test\n dependencies: [lawspec-example, hspec, hedgehog, hspec-hedgehog, containers, mtl]\n ghc-options: [-O0, -threaded, -rtsopts, \"-with-rtsopts=-N\"]\n build-tools: [hspec-discover]\n",
|
|
182
239
|
"test/Spec.hs": "{-# OPTIONS_GHC -F -pgmF hspec-discover #-}\n"
|
|
183
240
|
},
|
|
184
241
|
"compact": {
|
|
185
242
|
"stack.yaml": "snapshot: lts-24.58\npackages: [.]\n",
|
|
186
|
-
"package.yaml": "name: lawspec-example\nversion: 0.1.0\ndependencies: [base, text, bytestring, containers, network, directory, time]\nlibrary:\n source-dirs: src\ntests:\n laws:\n main: Spec.hs\n source-dirs: test\n dependencies: [lawspec-example, hspec, hedgehog, hspec-hedgehog, containers, mtl]\n ghc-options: [-threaded, -rtsopts, \"-with-rtsopts=-N\"]\n build-tools: [hspec-discover]\n",
|
|
243
|
+
"package.yaml": "name: lawspec-example\nversion: 0.1.0\ndependencies: [base, text, bytestring, containers, network, directory, time]\nlibrary:\n source-dirs: src\ntests:\n laws:\n main: Spec.hs\n source-dirs: test\n dependencies: [lawspec-example, hspec, hedgehog, hspec-hedgehog, containers, mtl]\n ghc-options: [-O0, -threaded, -rtsopts, \"-with-rtsopts=-N\"]\n build-tools: [hspec-discover]\n",
|
|
187
244
|
"test/Spec.hs": "{-# OPTIONS_GHC -F -pgmF hspec-discover #-}\n"
|
|
188
245
|
}
|
|
189
246
|
},
|
|
190
247
|
"kotlin": {
|
|
191
248
|
"readable": {
|
|
192
249
|
"settings.gradle.kts": "rootProject.name = \"lawspec-example\"\n",
|
|
250
|
+
"gradle.properties": "kotlin.daemon.jvmargs=-Xmx2g\n",
|
|
193
251
|
"build.gradle.kts": "plugins {\n kotlin(\"jvm\") version \"2.3.21\"\n}\n\nrepositories {\n mavenCentral()\n}\n\nkotlin {\n jvmToolchain(25)\n}\n\ndependencies {\n implementation(\"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0\")\n testImplementation(\"io.kotest:kotest-runner-junit5:5.9.1\")\n testImplementation(\"io.kotest:kotest-assertions-core:5.9.1\")\n testImplementation(\"io.kotest:kotest-property:5.9.1\")\n}\n\ntasks.test {\n useJUnitPlatform()\n}\n"
|
|
194
252
|
},
|
|
195
253
|
"compact": {
|
|
196
254
|
"settings.gradle.kts": "rootProject.name = \"lawspec-example\"\n",
|
|
255
|
+
"gradle.properties": "kotlin.daemon.jvmargs=-Xmx2g\n",
|
|
197
256
|
"build.gradle.kts": "plugins { kotlin(\"jvm\") version \"2.3.21\" }\nrepositories { mavenCentral() }\nkotlin { jvmToolchain(25) }\ndependencies { implementation(\"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.0\"); testImplementation(\"io.kotest:kotest-runner-junit5:5.9.1\"); testImplementation(\"io.kotest:kotest-assertions-core:5.9.1\"); testImplementation(\"io.kotest:kotest-property:5.9.1\") }\ntasks.test { useJUnitPlatform() }\n"
|
|
198
257
|
}
|
|
199
258
|
},
|
|
@@ -302,6 +361,30 @@ const scaffolds = {
|
|
|
302
361
|
"compact": {
|
|
303
362
|
"Package.swift": "// swift-tools-version: 6.2\nimport PackageDescription\nlet package = Package(\n name: \"Example\",\n platforms: [.macOS(.v26)],\n targets: [\n .target(name: \"LawSpecRuntime\", path: \"lawspec/LawSpecRuntime\"),\n .target(name: \"LawSpecTesting\", dependencies: [\"LawSpecRuntime\"], path: \"lawspec/LawSpecTesting\"),\n .target(name: \"App\", dependencies: [\"LawSpecRuntime\"], path: \"src\"),\n .testTarget(name: \"AppTests\", dependencies: [\"App\", \"LawSpecRuntime\", \"LawSpecTesting\"], path: \"tests\"),\n ]\n)\n"
|
|
304
363
|
}
|
|
364
|
+
},
|
|
365
|
+
"prolog": {
|
|
366
|
+
"readable": {
|
|
367
|
+
"pyproject.toml": "[build-system]\nrequires = [\"setuptools==80.9.0\"]\nbuild-backend = \"setuptools.build_meta\"\n\n[project]\nname = \"lawspec-example\"\nversion = \"0.1.0\"\nrequires-python = \">=3.13\"\ndependencies = [\"janus-swi==1.5.3\"]\n\n[project.optional-dependencies]\ntest = [\"pytest==8.4.2\", \"hypothesis==6.135.26\"]\n\n[tool.setuptools.packages.find]\nwhere = [\"src\"]\n\n[tool.pytest.ini_options]\npythonpath = [\"src\"]\ntestpaths = [\"tests\"]\n"
|
|
368
|
+
},
|
|
369
|
+
"compact": {
|
|
370
|
+
"pyproject.toml": "[build-system]\nrequires = [\"setuptools==80.9.0\"]\nbuild-backend = \"setuptools.build_meta\"\n\n[project]\nname = \"lawspec-example\"\nversion = \"0.1.0\"\nrequires-python = \">=3.13\"\ndependencies = [\"janus-swi==1.5.3\"]\n\n[project.optional-dependencies]\ntest = [\"pytest==8.4.2\", \"hypothesis==6.135.26\"]\n\n[tool.setuptools.packages.find]\nwhere = [\"src\"]\n\n[tool.pytest.ini_options]\npythonpath = [\"src\"]\ntestpaths = [\"tests\"]\n"
|
|
371
|
+
}
|
|
372
|
+
},
|
|
373
|
+
"hcl": {
|
|
374
|
+
"readable": {},
|
|
375
|
+
"compact": {}
|
|
376
|
+
},
|
|
377
|
+
"yaml": {
|
|
378
|
+
"readable": {},
|
|
379
|
+
"compact": {}
|
|
380
|
+
},
|
|
381
|
+
"antlr4": {
|
|
382
|
+
"readable": {},
|
|
383
|
+
"compact": {}
|
|
384
|
+
},
|
|
385
|
+
"make": {
|
|
386
|
+
"readable": {},
|
|
387
|
+
"compact": {}
|
|
305
388
|
}
|
|
306
389
|
};
|
|
307
390
|
|
package/test-command.mjs
CHANGED
|
@@ -29,7 +29,22 @@ const digest = (value) => createHash("sha256").update(value).digest("hex");
|
|
|
29
29
|
// contribute to the adapter digest; rebuilding the NIF cannot invalidate a pass.
|
|
30
30
|
const cryptoBuildOutput = (file) => /^priv\/lawspec_crypto_native\.(?:so|dll)(?:\.build|\.\d+\.tmp)?$/.test(file);
|
|
31
31
|
|
|
32
|
-
//
|
|
32
|
+
// An environment attestation records where a run's dependencies were wired
|
|
33
|
+
// and what was observed; it is reporting only, never an input of the
|
|
34
|
+
// project, so one written inside the project is not digested. It is known by
|
|
35
|
+
// its content, whatever its name or whichever tool wrote it.
|
|
36
|
+
// ref:DEC-completed-run-attestation
|
|
37
|
+
export function isAttestation(content) {
|
|
38
|
+
try {
|
|
39
|
+
const value = JSON.parse(content);
|
|
40
|
+
return value !== null && typeof value === "object" && value.format === "environment-attestation";
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Every file in a project that LawSpec did not generate, by content, except
|
|
47
|
+
// environment attestations.
|
|
33
48
|
export async function projectDigest(root, generated) {
|
|
34
49
|
const hash = createHash("sha256");
|
|
35
50
|
async function walk(folder) {
|
|
@@ -40,7 +55,9 @@ export async function projectDigest(root, generated) {
|
|
|
40
55
|
if (entry.isDirectory()) {
|
|
41
56
|
if (!skipped.has(entry.name) && !relative.endsWith("testdata/rapid")) await walk(relative);
|
|
42
57
|
} else if (entry.isFile() && !generated.has(relative) && !cryptoBuildOutput(relative)) {
|
|
43
|
-
|
|
58
|
+
const content = await readFile(path.join(root, relative));
|
|
59
|
+
if (relative.endsWith(".json") && isAttestation(content.toString("utf8"))) continue;
|
|
60
|
+
hash.update(relative + "\0").update(content).update("\0");
|
|
44
61
|
}
|
|
45
62
|
}
|
|
46
63
|
}
|
|
@@ -121,6 +138,9 @@ export function preparationInvocations(target, files) {
|
|
|
121
138
|
export function benchmarkInvocations(target, entries, { offline = false } = {}) {
|
|
122
139
|
if (!entries.length) return [];
|
|
123
140
|
const language = target.language;
|
|
141
|
+
if (language === "prolog")
|
|
142
|
+
return [{command: target.python || "python3", args: ["lawspec_test.py",
|
|
143
|
+
...entries.flatMap(entry => ["--select", `${entry.file}::${entry.name}`])]}];
|
|
124
144
|
const testDir = target.testDir;
|
|
125
145
|
const relativeTo = (file, defaultDir) => {
|
|
126
146
|
const directory = testDir || defaultDir;
|
|
@@ -214,6 +234,16 @@ function nativeInvocations(target, entries, { offline = false, scratch = ".", co
|
|
|
214
234
|
root = process.cwd(), coverageConfig } = {}) {
|
|
215
235
|
if (!entries.length) return [];
|
|
216
236
|
const language = target.language;
|
|
237
|
+
if (language === "prolog") {
|
|
238
|
+
if (coverage) throw new Error("Prolog coverage instrumentation is not integrated");
|
|
239
|
+
const report = path.join(scratch, "prolog.xml");
|
|
240
|
+
const matching = test => entries.filter(entry => entry.kind === "model"
|
|
241
|
+
? test.name === entry.name : test.name.startsWith(`${entry.name}__`));
|
|
242
|
+
const selections = [...new Set(entries.map(entry => `${entry.file}::${entry.name}`))];
|
|
243
|
+
return [{laws: entries, command: target.python || "python3",
|
|
244
|
+
args: ["lawspec_test.py", ...selections.flatMap(slot => ["--select", slot]), "--junitxml", report],
|
|
245
|
+
report: {kind: "junit", files: [report]}, ran: matching}];
|
|
246
|
+
}
|
|
217
247
|
const testDir = target.testDir;
|
|
218
248
|
const relativeTo = (file, defaultDir) => {
|
|
219
249
|
const directory = testDir || defaultDir;
|
|
@@ -587,7 +617,11 @@ export async function executedTests(report, output, root, since) {
|
|
|
587
617
|
const values=attributes(element.opening);
|
|
588
618
|
const native=junitElements(element.xml,["failure","error","skipped"]);
|
|
589
619
|
const failure=native.filter(element=>element.name!=="skipped");
|
|
590
|
-
const
|
|
620
|
+
const incomplete=junitElements(element.xml,["property"]).some(property=>{
|
|
621
|
+
const value=attributes(property.opening);
|
|
622
|
+
return value.name==='lawspec.status'&&value.value==='incomplete';
|
|
623
|
+
});
|
|
624
|
+
const status=incomplete?"incomplete":failure.length?"failed":native.length?"skipped":"passed";
|
|
591
625
|
const detail=element=>[attributes(element.opening).message,
|
|
592
626
|
unescapeXml(element.xml.slice(element.opening.length).replace(/<\/(failure|error|skipped)>\s*$/,"")
|
|
593
627
|
.replace(/<!\[CDATA\[([\s\S]*?)\]\]>/g,(_,text)=>text))].filter(Boolean).join("\n");
|
|
@@ -631,6 +665,7 @@ export async function executedTests(report, output, root, since) {
|
|
|
631
665
|
// JUnit XML for a runner that writes none, from the tests it printed.
|
|
632
666
|
export function junitFromTests(tests) {
|
|
633
667
|
const failures = tests.filter((t) => t.status === "failed").length;
|
|
668
|
+
const errors = tests.filter((t) => t.status === "incomplete").length;
|
|
634
669
|
const skipped = tests.filter((t) => t.status === "skipped").length;
|
|
635
670
|
// A BEAM scheduler wraps native functions from several units. Its module
|
|
636
671
|
// is not the declaring class: retain the unit from the validated identity.
|
|
@@ -638,10 +673,11 @@ export function junitFromTests(tests) {
|
|
|
638
673
|
const separator = typeof test.identity === "string" ? test.identity.lastIndexOf("::") : -1;
|
|
639
674
|
return separator > 0 ? test.identity.slice(0, separator) : test.classname ?? "";
|
|
640
675
|
};
|
|
641
|
-
return `<testsuite name="lawspec" tests="${tests.length}" failures="${failures}"${skipped ? ` skipped="${skipped}"` : ""}>\n` +
|
|
676
|
+
return `<testsuite name="lawspec" tests="${tests.length}" failures="${failures}"${errors ? ` errors="${errors}"` : ""}${skipped ? ` skipped="${skipped}"` : ""}>\n` +
|
|
642
677
|
tests.map((t) => ` <testcase classname="${escapeXml(classname(t))}" name="${escapeXml(t.name)}"` +
|
|
643
678
|
(Number.isFinite(t.time) ? ` time="${t.time}"` : "") +
|
|
644
679
|
(t.status === "failed" ? `><failure message="${escapeXml(t.failure ?? "failed")}"/></testcase>` :
|
|
680
|
+
t.status === "incomplete" ? `><properties><property name="lawspec.status" value="incomplete"/></properties><error message="${escapeXml(t.failure ?? t.reason ?? "incomplete execution")}"/></testcase>` :
|
|
645
681
|
t.status === "skipped" ? `><skipped message="${escapeXml(t.reason ?? "skipped")}"/></testcase>` : "/>")).join("\n") + "\n</testsuite>";
|
|
646
682
|
}
|
|
647
683
|
|