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.
Files changed (79) hide show
  1. package/CHANGELOG.md +407 -1
  2. package/README.md +9 -3
  3. package/api.mjs +1 -0
  4. package/beam-doctor.mjs +2 -2
  5. package/bin/lawspec.mjs +100 -102
  6. package/build.json +503 -411
  7. package/component-packages.mjs +339 -0
  8. package/component.d.ts +46 -0
  9. package/component.mjs +208 -0
  10. package/core.wasm +2 -2
  11. package/core_jsffi.js +5 -5
  12. package/examples/native-payments/clojure/lawspec.edn +48 -0
  13. package/examples/native-payments/clojure/src/domain/payments.clj +1 -1
  14. package/examples/native-payments/clojure/test/domain/payment_generators.clj +1 -1
  15. package/examples/native-payments/csharp/lawspec.edn +48 -0
  16. package/examples/native-payments/elixir/lawspec.edn +123 -0
  17. package/examples/native-payments/erlang/lawspec.edn +128 -0
  18. package/examples/native-payments/fsharp/lawspec.edn +123 -0
  19. package/examples/native-payments/gleam/lawspec.edn +123 -0
  20. package/examples/native-payments/go/lawspec.edn +123 -0
  21. package/examples/native-payments/groovy/lawspec.edn +123 -0
  22. package/examples/native-payments/haskell/lawspec.edn +123 -0
  23. package/examples/native-payments/java/lawspec.edn +123 -0
  24. package/examples/native-payments/javascript/lawspec.edn +123 -0
  25. package/examples/native-payments/kotlin/lawspec.edn +123 -0
  26. package/examples/native-payments/prolog/lawspec.edn +48 -0
  27. package/examples/native-payments/python/lawspec.edn +123 -0
  28. package/examples/native-payments/rust/lawspec.edn +124 -0
  29. package/examples/native-payments/scala/lawspec.edn +123 -0
  30. package/examples/native-payments/swift/lawspec.edn +123 -0
  31. package/examples/native-payments/typescript/lawspec.edn +123 -0
  32. package/examples/packages/orders/lawspec.edn +25 -0
  33. package/examples/packages/shop-domain/lawspec.edn +13 -0
  34. package/examples/packages/shop-tax-1/lawspec.edn +9 -0
  35. package/examples/packages/shop-tax-2/lawspec.edn +9 -0
  36. package/examples/specs/handler_bindings.lawspec +2 -2
  37. package/examples/specs/harness_testing.lawspec +1 -1
  38. package/files.mjs +2 -1
  39. package/go.mod +4 -0
  40. package/index.d.ts +145 -8
  41. package/input-files.mjs +47 -0
  42. package/launcher.mjs +33 -13
  43. package/lsp.mjs +10 -5
  44. package/native-evidence.mjs +58 -19
  45. package/native-examples.mjs +8 -7
  46. package/native-host.mjs +71 -0
  47. package/package.json +8 -3
  48. package/proof.d.ts +8 -2
  49. package/proof.mjs +186 -34
  50. package/scala-build-state.mjs +59 -0
  51. package/templates.mjs +242 -2
  52. package/test-command.mjs +193 -61
  53. package/builtin-data-names.mjs +0 -73
  54. package/examples/native-payments/clojure/lawspec.json +0 -62
  55. package/examples/native-payments/csharp/lawspec.json +0 -62
  56. package/examples/native-payments/elixir/lawspec.json +0 -160
  57. package/examples/native-payments/erlang/lawspec.json +0 -159
  58. package/examples/native-payments/fsharp/lawspec.json +0 -178
  59. package/examples/native-payments/gleam/lawspec.json +0 -160
  60. package/examples/native-payments/go/lawspec.json +0 -147
  61. package/examples/native-payments/groovy/lawspec.json +0 -176
  62. package/examples/native-payments/haskell/lawspec.json +0 -160
  63. package/examples/native-payments/java/lawspec.json +0 -176
  64. package/examples/native-payments/javascript/lawspec.json +0 -160
  65. package/examples/native-payments/kotlin/lawspec.json +0 -176
  66. package/examples/native-payments/prolog/lawspec.json +0 -20
  67. package/examples/native-payments/python/lawspec.json +0 -160
  68. package/examples/native-payments/rust/lawspec.json +0 -178
  69. package/examples/native-payments/scala/lawspec.json +0 -176
  70. package/examples/native-payments/swift/lawspec.json +0 -165
  71. package/examples/native-payments/typescript/lawspec.json +0 -160
  72. package/examples/packages/orders/lawspec.json +0 -27
  73. package/examples/packages/shop-domain/lawspec-package.json +0 -7
  74. package/examples/packages/shop-tax-1/lawspec-package.json +0 -5
  75. package/examples/packages/shop-tax-2/lawspec-package.json +0 -5
  76. package/explain.mjs +0 -114
  77. package/expression-presentation.mjs +0 -333
  78. package/positional-fields.mjs +0 -13
  79. package/typed-presentation.mjs +0 -165
@@ -5,7 +5,7 @@ import path from 'node:path';
5
5
  import {doctor} from './doctor.mjs';
6
6
  import {planWrites} from './files.mjs';
7
7
  import {projectKey} from './failure-database.mjs';
8
- import {lawKeys,environmentDigest,recordedDigest,projectDigest,invocations} from './test-command.mjs';
8
+ import {lawKeys,presentationDigest,environmentDigest,recordedDigest,projectDigest,invocations} from './test-command.mjs';
9
9
 
10
10
  // Native execution observations are scoped to actual completed test slots.
11
11
  // They never establish a universal model proof or a witness-search completeness claim.
@@ -26,7 +26,7 @@ export function recordNativeAttempts(run, tests, {keys,seed,ok,profile,output,al
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
28
  matched.some(test=>test.status==='incomplete')?'incomplete':
29
- entry.skip?'skipped':complete?(entry.knownFailing?'known-failing':'passed'):
29
+ entry.skip?'skipped':complete?(entry.knownDiscrepancy?'known-discrepancy':'passed'):
30
30
  matched.length&&matched.every(test=>test.status==='skipped')?'skipped':'incomplete';
31
31
  return [entry.law,{key:keys.get(entry.law),planKey:entry.key,seed:nativeSeed(seed),at,outcome,
32
32
  profile,coverage:entry.coverage??{kind:'sampled',scopedQuantifiers:true},check:{id:entry.law,unit:entry.unit,file:entry.file,name:entry.name,label:entry.label,
@@ -48,6 +48,8 @@ export function recordNativeAttempts(run, tests, {keys,seed,ok,profile,output,al
48
48
  // reported beside it are not inputs, so they change no key.
49
49
  export function attestedKeys(result) {
50
50
  const wiring=d=>[d.dependency,d.endpoint,d.kind,
51
+ ...(d.implementation?[[d.implementation.kind,d.implementation.product,d.implementation.version,
52
+ d.implementation.commit??null,d.implementation.digest??null]]:[]),
51
53
  ...(d.standIn?[d.standIn.identity,d.standIn.version,d.standIn.conformance]:[])];
52
54
  return new Map((result.evidence??[]).filter(item=>item.against||item.plannedAgainst)
53
55
  .map(item=>[item.declaration,JSON.stringify([
@@ -59,19 +61,23 @@ const subject = (entry,item) => obligationTargets(entry).some(target=>
59
61
  const runtimeStages=new Set(['law','model','linearizable','sequentially consistent','causally consistent',
60
62
  'eventually consistent','restart','scenario','supervision']);
61
63
 
64
+ // Display archived observations in the current vocabulary; retain their raw
65
+ // attempts and use those original values for freshness and completion checks.
66
+ const observationOutcome=outcome=>outcome==='known-failing'?'known-discrepancy':outcome;
67
+
62
68
  // Only observations with matching current compiler/configuration/source/native
63
69
  // inputs are eligible for completed evidence. A stored timestamp alone is not.
64
- export async function readNativeObservations({compiler,input,selected,roots,configRoot,build,evidence,attestation}) {
70
+ export async function readNativeObservations({compiler,input,selected,roots,configRoot,config={},build,evidence,attestation}) {
65
71
  const records=await Promise.all(selected.map(async(target,index)=>{
66
72
  const root=roots[index],file=path.join(configRoot,'.lawspec/results',`${target.language}-${projectKey(root)}.json`);
67
73
  const record=JSON.parse(await readFile(file,'utf8').catch(error=>{
68
74
  if(error.code==='ENOENT')return '{}';throw error;
69
75
  }));
70
- return {target,root,attempts:record.attempts??{},runs:record.laws??{},attestations:record.attestations??{}};
76
+ return {target,root,attempts:record.attempts??{},runs:record.laws??{},presentation:record.presentation,attestations:record.attestations??{}};
71
77
  }));
72
78
  if(!records.some(record=>Object.keys(record.attempts).length))return [];
73
79
  const observations=[];
74
- for(const {target,root,attempts,runs,attestations}of records){
80
+ for(const {target,root,attempts,runs,presentation,attestations}of records){
75
81
  const plans=new Map(),contexts=new Map();
76
82
  // An attempt is keyed by the wiring of the attestation it ran under: the
77
83
  // one named now, or else the one lawspec test stored for its run.
@@ -108,10 +114,15 @@ export async function readNativeObservations({compiler,input,selected,roots,conf
108
114
  const report=await doctor(target,root,generated.files);
109
115
  if(!report.ok)result={reason:'The current native environment could not be checked: '+report.message};
110
116
  else {
117
+ const environment=await environmentDigest(root,report,target.language);
118
+ if(presentation!==presentationDigest(generated.files,environment)){
119
+ result={reason:'Current generated presentation has not passed native validation; run lawspec test'};
120
+ contexts.set(key,result);return result;
121
+ }
111
122
  const owned=new Set(generated.files.filter(file=>file.ownership==='generated').map(file=>file.path));
112
123
  const keys=lawKeys({build,target,machineBits:input.machineBits,minify,tests:generated.tests,files:generated.files,
113
- environment:await environmentDigest(root,report)+await recordedDigest(path.join(configRoot,'recorded')),
114
- project:await projectDigest(root,owned),attested:attestedKeys(generated)});
124
+ environment,recorded:await recordedDigest(path.join(configRoot,'recorded')),
125
+ project:await projectDigest(root,owned,target.language,{inputRoot:configRoot,inputs:config.inputs??[]}),attested:attestedKeys(generated)});
115
126
  result={generated,keys};
116
127
  }
117
128
  }
@@ -119,41 +130,58 @@ export async function readNativeObservations({compiler,input,selected,roots,conf
119
130
  contexts.set(key,result);return result;
120
131
  }
121
132
  for(const [id,baseline]of expected){
122
- const attempt=attempts[id];
133
+ let attempt=attempts[id],reuse;
134
+ if(!attempt)for(const original of Object.values(attempts)){
135
+ // Only a single ordinary-law observation can be re-associated here.
136
+ // Combined model methods keep their exact group identities.
137
+ if(original.outcome!=='passed'||original.check?.nativeGroup?.length!==1||
138
+ !isDeepStrictEqual(original.check.obligations,[{declaration:original.check.id,stage:'law'}])||
139
+ !isDeepStrictEqual(obligationTargets(baseline),[{declaration:id,stage:'law'}]))continue;
140
+ let candidate=await context(original.profile?.minify??false,wiredBy(original));
141
+ if(candidate.reason&&candidate.stale)candidate=await context(!original.profile?.minify,wiredBy(original));
142
+ if(!candidate.reason&&candidate.keys.get(id)===original.key&&baseline.key===original.planKey){
143
+ attempt=original;reuse={check:original.check.id,key:original.key,at:original.at};break;
144
+ }
145
+ }
123
146
  const row={target:target.language,root,check:{id,obligations:obligationTargets(baseline)},
124
- outcome:attempt?.outcome??'not-run',coverage:baseline.coverage,attempt};
147
+ outcome:observationOutcome(attempt?.outcome??'not-run'),coverage:baseline.coverage,attempt};
125
148
  if(!attempt){observations.push({...row,freshness:'not-run',reason:'No completed native observation was recorded'});continue;}
126
149
  const profile=attempt.profile??{};
127
150
  if(profile.target!==target.language||profile.root!==root||profile.machineBits!==input.machineBits||profile.build!==build||
128
151
  typeof profile.minify!=='boolean'){
129
152
  observations.push({...row,freshness:'stale',reason:'Compiler, target or machine profile differs'});continue;
130
153
  }
131
- const current=await context(profile.minify,wiredBy(attempt));
154
+ let current=await context(profile.minify,wiredBy(attempt));
155
+ // Layout belongs to the artifact, not to the meaning of its old run.
156
+ // Accept the other canonical layout only when it exactly matches disk.
157
+ if(current.reason&&current.stale)current=await context(!profile.minify,wiredBy(attempt));
132
158
  if(current.reason){observations.push({...row,freshness:current.stale?'stale':'unavailable',reason:current.reason});continue;}
133
159
  const entry=current.generated.tests.find(entry=>entry.law===id);
134
160
  if(!entry||attempt.key!==current.keys.get(id)||attempt.planKey!==entry.key||
135
- !isDeepStrictEqual(attempt.check?.obligations,obligationTargets(entry))||
161
+ (!reuse&&!isDeepStrictEqual(attempt.check?.obligations,obligationTargets(entry)))||
136
162
  !isDeepStrictEqual(attempt.coverage,entry.coverage)){
137
163
  observations.push({...row,freshness:'stale',reason:'Specification, selection, bindings, native source or toolchain inputs differ'});continue;
138
164
  }
139
- const invocation=invocations(target,[entry],{root}).find(run=>run.laws?.includes(entry));
165
+ const observedEntry=reuse?{...entry,...attempt.check,law:attempt.check.id,key:attempt.planKey}:entry;
166
+ const invocation=invocations(target,[observedEntry],{root}).find(run=>run.laws?.includes(observedEntry));
167
+ const observedKeys=reuse?new Map([[observedEntry.law,attempt.key]]):current.keys;
140
168
  const validSeed=(typeof attempt.seed==='number'&&Number.isSafeInteger(attempt.seed)&&attempt.seed>=0)||
141
169
  (typeof attempt.seed==='string'&&/^[0-9]+$/.test(attempt.seed));
142
170
  const recomputed=validSeed&&Number.isFinite(Date.parse(attempt.at))&&invocation&&Array.isArray(attempt.tests)&&recordNativeAttempts(invocation,attempt.tests,
143
- {keys:current.keys,seed:attempt.seed,ok:attempt.invocation?.ok===true,profile,at:attempt.at,
144
- allEntries:current.generated.tests})[id];
171
+ {keys:observedKeys,seed:attempt.seed,ok:attempt.invocation?.ok===true,profile,at:attempt.at,
172
+ allEntries:reuse?[observedEntry]:current.generated.tests})[observedEntry.law];
145
173
  if(!recomputed||recomputed.outcome!==attempt.outcome||
146
174
  !isDeepStrictEqual(recomputed.check.nativeGroup,attempt.check?.nativeGroup)){
147
175
  observations.push({...row,freshness:'unavailable',reason:'The stored observation does not establish the current native completion'});continue;
148
176
  }
149
177
  const run=runs[id];
150
- observations.push({...row,freshness:'matching-inputs',
178
+ observations.push({...row,freshness:'matching-inputs',...(reuse?{reused:reuse}:{}),
151
179
  ...(attempt.outcome==='passed'&&run?.key===attempt.key&&(run.flaky||run.adequacy)?
152
180
  {harness:{...(run.flaky?{flaky:true}:{}),...(run.adequacy?{adequacy:run.adequacy}:{})}}:{}),
153
- reason:attempt.outcome==='passed'?'Recorded native completion matches the current inputs':'Recorded native attempt matches the current inputs'});
181
+ reason:reuse?'Original native completion reused for the current semantic law; no fresh invocation is claimed':attempt.outcome==='passed'?'Recorded native completion matches the current inputs':'Recorded native attempt matches the current inputs'});
154
182
  }
155
183
  for(const [id,attempt]of Object.entries(attempts))if(!expected.has(id)&&Array.isArray(attempt.check?.obligations))
156
- observations.push({target:target.language,root,check:attempt.check,attempt,outcome:attempt.outcome,
184
+ observations.push({target:target.language,root,check:attempt.check,attempt,outcome:observationOutcome(attempt.outcome),
157
185
  coverage:attempt.coverage,freshness:'not-selected',reason:'This native check is not selected by the current configuration'});
158
186
  }
159
187
  return observations;
@@ -170,7 +198,7 @@ export function attachNativeEvidence(evidence,observations){
170
198
  const status=failed.length?(combinedFailure?'incomplete':'failed'):
171
199
  current.length===rows.length&&current.every(row=>row.outcome==='passed')?'passed':
172
200
  current.length===rows.length&&current.every(row=>row.outcome==='skipped')?'skipped':
173
- current.length===rows.length&&current.every(row=>row.outcome==='known-failing')?'known-failing':
201
+ current.length===rows.length&&current.every(row=>row.outcome==='known-discrepancy')?'known-discrepancy':
174
202
  current.some(row=>row.outcome==='passed')?'partial':
175
203
  current.some(row=>['incomplete','not-run'].includes(row.outcome))?'incomplete':
176
204
  rows.every(row=>row.freshness==='not-selected')?'not-selected':
@@ -197,4 +225,15 @@ export function attachNativeEvidence(evidence,observations){
197
225
  });
198
226
  }
199
227
 
200
- export {nativeEvidenceText} from './explain.mjs';
228
+ // Native conformance a law's evidence row carries, for lawspec evidence.
229
+ export function nativeEvidenceText(item){
230
+ if(!item.nativeEvidence)return '';
231
+ const summary=item.nativeEvidence;
232
+ return [`Native conformance: ${summary.status}; search completeness: ${summary.searchCompleteness}`,
233
+ ...summary.observations.map(row=>`${row.target} (${row.root}): ${row.outcome}; ${row.freshness}`+
234
+ (row.attempt?`; seed ${row.attempt.seed}; ${row.attempt.at}`:'')+`; ${row.reason}`),
235
+ ...summary.observations.flatMap(row=>(row.attempt?.tests??[]).filter(test=>test.status==='failed')
236
+ .map(test=>`${test.name}: ${test.reason??test.failure??test.message??'native test failed'}`)),
237
+ ...summary.observations.filter(row=>row.attempt?.invocation.output)
238
+ .map(row=>'Native invocation output (scoped to that invocation):\n'+row.attempt.invocation.output)].join('\n');
239
+ }
@@ -3,6 +3,7 @@ import {readFile, readdir, mkdir} from 'node:fs/promises';
3
3
  import path from 'node:path';
4
4
  import {templates, commands, setup} from './templates.mjs';
5
5
  import {safePath, planWrites, applyWrites} from './files.mjs';
6
+ import {parseManifest, writeManifest} from './component.mjs';
6
7
 
7
8
  async function projectFiles(directory, prefix = '') {
8
9
  const files = {};
@@ -30,11 +31,11 @@ export async function exportNativePayments(options, selected) {
30
31
  ...await projectFiles(new URL(`./examples/native-payments/${target}/`, import.meta.url)),
31
32
  'laws/payments.lawspec': law,
32
33
  };
33
- const config = JSON.parse(files['lawspec.json']);
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`);
34
+ const config = parseManifest(files['lawspec.edn']);
35
+ if(config.manifestVersion!==1||config.languageProfile!=='1.0-rc.2')
36
+ throw new Error(`Bundled native payments configuration for ${target} must use lawspec.edn and languageProfile 1.0-rc.2`);
36
37
  config.machineBits = options.machineBits ?? 64;
37
- files['lawspec.json'] = JSON.stringify(config, null, options.minify ? undefined : 2) + '\n';
38
+ files['lawspec.edn'] = writeManifest(config, {compact: options.minify === true});
38
39
  const instructions = target === 'gleam' ? setup[target].replace(
39
40
  'Prepare dependencies with gleam build, then run gleam test.',
40
41
  'Prepare dependencies with node prepare.mjs before generation, then run gleam test.') : setup[target];
@@ -44,8 +45,8 @@ This project checks application-owned payment types against the shared LawSpec
44
45
  model. Money maps to Price, currency variants have application names, and the
45
46
  archive preserves distinct present and absent payments.
46
47
 
47
- The specification uses the canonical language profile. The version 2 project
48
- configuration selects its verification layers explicitly. Most targets bind
48
+ The specification uses the canonical language profile. The component manifest
49
+ selects its verification layers explicitly. Most targets bind
49
50
  application-owned domain types; C#, Clojure and Prolog use the generated model data
50
51
  and bind the application's functions and generators.
51
52
 
@@ -77,7 +78,7 @@ the application so that runtime support is present.
77
78
 
78
79
  Edit the domain implementation or generator, then run the native tests again.
79
80
  For example, change the fee from 0.2 to 0.3: the exact-decimal law must fail.
80
- Edit \`lawspec.json\` to change native bindings and rerun \`lawspec generate\`.
81
+ Edit \`lawspec.edn\` to change native bindings and rerun \`lawspec generate\`.
81
82
 
82
83
  All exported project files are user-owned. Re-exporting preserves your edits;
83
84
  it reports changed bundled versions for review. Compiler-generated files use a
@@ -0,0 +1,71 @@
1
+ // Generated from templates/npm/native-host.mjs by lawspec-dev generate. Do not edit.
2
+ // Native execution identity is separate from the WebAssembly compiler cache
3
+ // and from the solver host. Conservatively bind the executable SDK bundle,
4
+ // its installed dependency closure, and the Node binary which runs it.
5
+ import {createHash} from 'node:crypto';
6
+ import {createRequire} from 'node:module';
7
+ import {readFile,readdir,realpath} from 'node:fs/promises';
8
+ import {fileURLToPath} from 'node:url';
9
+ import path from 'node:path';
10
+
11
+ const sdkRoot=fileURLToPath(new URL('.',import.meta.url));
12
+ // These modules only render explanations, serve editors, create examples or
13
+ // execute optional proofs. They do not select or certify native completion.
14
+ const separate=new Set(['proof.mjs','lsp.mjs','explain.mjs','scalars.mjs','examples-command.mjs']);
15
+ let nodeIdentityValue;
16
+ async function nodeIdentity(){
17
+ nodeIdentityValue??=(async()=>createHash('sha256').update(await readFile(process.execPath)).digest('hex'))();
18
+ return nodeIdentityValue;
19
+ }
20
+
21
+ export async function fingerprintNativeHost(root=sdkRoot){
22
+ const hash=createHash('sha256').update('lawspec-native-host-v1\0');
23
+ hash.update(JSON.stringify([await nodeIdentity(),process.version,process.platform,process.arch,process.execArgv,process.env.NODE_OPTIONS??'']));
24
+ const add=async(file,label)=>hash.update(label+'\0').update(await readFile(file)).update('\0');
25
+ // New SDK helper modules enter the identity automatically. Project output,
26
+ // declarations, documentation and core.wasm are deliberately outside it.
27
+ for(const entry of (await readdir(root,{withFileTypes:true})).sort((a,b)=>a.name<b.name?-1:a.name>b.name?1:0))
28
+ if(entry.isFile()&&((entry.name.endsWith('.mjs')&&!separate.has(entry.name))||entry.name==='core_jsffi.js'))
29
+ await add(path.join(root,entry.name),entry.name);
30
+ for(const entry of (await readdir(path.join(root,'bin'),{withFileTypes:true})).sort((a,b)=>a.name<b.name?-1:a.name>b.name?1:0))
31
+ if(entry.isFile()&&entry.name.endsWith('.mjs'))await add(path.join(root,'bin',entry.name),'bin/'+entry.name);
32
+ const manifest=JSON.parse(await readFile(path.join(root,'package.json'),'utf8'));
33
+ await add(path.join(root,'package.json'),'package.json');
34
+ const seen=new Set();
35
+ async function packageRoot(name,from){
36
+ let directory=path.dirname(createRequire(path.join(from,'package.json')).resolve(name));
37
+ while(true){
38
+ const candidate=path.join(directory,'package.json');
39
+ const value=await readFile(candidate,'utf8').then(JSON.parse,error=>{if(error.code==='ENOENT')return null;throw error;});
40
+ if(value?.name===name)return {directory:await realpath(directory),value};
41
+ const parent=path.dirname(directory);if(parent===directory)throw new Error('Cannot identify native host dependency '+name);
42
+ directory=parent;
43
+ }
44
+ }
45
+ async function dependency(name,from,optional=false){
46
+ let selected;
47
+ try{selected=await packageRoot(name,from);}catch(error){
48
+ if(optional&&error.code==='MODULE_NOT_FOUND'){hash.update('absent-optional:'+name+'\0');return;}throw error;
49
+ }
50
+ const {directory,value}=selected,label=path.relative(root,directory).split(path.sep).join('/');
51
+ hash.update('dependency:'+name+'\0'+label+'\0');
52
+ if(seen.has(directory))return;seen.add(directory);
53
+ async function walk(folder,relative=''){
54
+ for(const entry of (await readdir(folder,{withFileTypes:true})).sort((a,b)=>a.name<b.name?-1:a.name>b.name?1:0)){
55
+ const next=relative?relative+'/'+entry.name:entry.name;
56
+ if(entry.isSymbolicLink())throw new Error('Cannot fingerprint symbolic-link content in native host dependency: '+label+'/'+next);
57
+ if(entry.isDirectory()&&!['node_modules','.git'].includes(entry.name))await walk(path.join(folder,entry.name),next);
58
+ else if(entry.isFile())await add(path.join(folder,entry.name),label+'/'+next);
59
+ }
60
+ }
61
+ await walk(directory);
62
+ for(const child of Object.keys({...value.dependencies,...value.optionalDependencies}).sort())
63
+ await dependency(child,directory,Object.hasOwn(value.optionalDependencies??{},child));
64
+ }
65
+ for(const name of Object.keys({...manifest.dependencies,...manifest.optionalDependencies}).sort())
66
+ await dependency(name,root,Object.hasOwn(manifest.optionalDependencies??{},name));
67
+ return hash.digest('hex');
68
+ }
69
+
70
+ let identity;
71
+ export function nativeHostIdentity(){return identity??=fingerprintNativeHost();}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lawspec",
3
- "version": "0.29.2",
3
+ "version": "0.31.0",
4
4
  "description": "State the law once. Check it everywhere.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -22,17 +22,22 @@
22
22
  "./proof": {
23
23
  "types": "./proof.d.ts",
24
24
  "import": "./proof.mjs"
25
+ },
26
+ "./component": {
27
+ "types": "./component.d.ts",
28
+ "import": "./component.mjs"
25
29
  }
26
30
  },
27
31
  "types": "index.d.ts",
32
+ "dependencies": {"edn-data": "1.2.2", "tar": "7.5.22"},
28
33
  "files": [
29
34
  "*.mjs",
30
35
  "*.json",
31
- "index.d.ts",
32
- "proof.d.ts",
36
+ "*.d.ts",
33
37
  "bin",
34
38
  "core.wasm",
35
39
  "core_jsffi.js",
40
+ "go.mod",
36
41
  "README.md",
37
42
  "CHANGELOG.md",
38
43
  "LICENSE",
package/proof.d.ts CHANGED
@@ -11,6 +11,10 @@ export interface Z3Options {
11
11
  }
12
12
  /** How a solver run went: shared by law and law-set evidence. */
13
13
  interface SolverRun {
14
+ /** Current task binding when a semantic result reuses an earlier execution. */
15
+ currentTaskFingerprint?: string;
16
+ /** Provenance of the completed execution reused; no fresh solver run occurred. */
17
+ reused?: {key:string; owner:string; declaration:string; taskFingerprint:string; runFingerprint:string};
14
18
  outcome: 'unsat' | 'sat' | 'unknown' | 'timeout' | 'resource-limit' | 'out-of-memory' | 'unavailable' | 'failed' | 'unsupported';
15
19
  reason: string;
16
20
  stdout?: string;
@@ -30,8 +34,10 @@ export interface LawSolverEvidence extends SolverRun {
30
34
  at: Location;
31
35
  encoding: 'lawspec-smtlib-v1' | 'lawspec-smtlib-v2';
32
36
  machineBits: 32 | 64;
33
- programFingerprint: string;
37
+ lawFingerprint: string;
34
38
  taskFingerprint?: string;
39
+ /** Current names for the same semantic induction plan; original cases remain in induction. */
40
+ currentInduction?: {on:string; using:string[]};
35
41
  status: 'proved' | 'refuted' | 'incomplete' | 'unsupported';
36
42
  model?: string;
37
43
  modelValidated?: boolean;
@@ -76,5 +82,5 @@ export interface ModelSolverEvidence extends SolverRun {
76
82
  counterexample?: undefined;
77
83
  }
78
84
  export type SolverEvidence = LawSolverEvidence | AnalysisSolverEvidence | ModelSolverEvidence;
79
- export function proofTaskFingerprint(task: {encoding:string;programFingerprint:string;machineBits:number;owner:string;declaration:string;script:string}):string;
85
+ export function proofTaskFingerprint(task: {encoding:string;lawFingerprint:string;machineBits:number;owner:string;declaration:string;script:string}):string;
80
86
  export function proveWithZ3(compiler:Compiler,request:CheckRequest,options?:Z3Options):Promise<Result & {solverEvidence:SolverEvidence[]}>;