lawspec 0.31.1 → 0.31.3

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 +89 -2
  2. package/README.md +85 -9
  3. package/api.mjs +14 -9
  4. package/authoring.mjs +899 -0
  5. package/beam-coverage.mjs +190 -65
  6. package/beam-doctor.mjs +343 -124
  7. package/bin/lawspec.mjs +1949 -661
  8. package/build.json +134 -128
  9. package/component-packages.mjs +662 -176
  10. package/component.d.ts +82 -20
  11. package/component.mjs +317 -94
  12. package/core.wasm +2 -2
  13. package/core_jsffi.js +5 -5
  14. package/doctor.mjs +558 -299
  15. package/examples-command.mjs +44 -23
  16. package/failure-database.mjs +60 -17
  17. package/files.mjs +122 -62
  18. package/index.d.ts +585 -312
  19. package/input-files.mjs +90 -25
  20. package/launcher.mjs +72 -31
  21. package/learn/coverage.json +184 -112
  22. package/learn/curriculum.json +4 -1
  23. package/learn/vendor/fantomas/{LawSpec.Learn.Formatter.5arcua4vy0.wasm → LawSpec.Learn.Formatter.poiijdbsl9.wasm} +0 -0
  24. package/learn/vendor/fantomas/dotnet.js +3 -3
  25. package/learn/vendor/manifest.json +4 -8
  26. package/lsp.mjs +444 -133
  27. package/mcp.mjs +250 -0
  28. package/native-evidence.mjs +668 -182
  29. package/native-examples.mjs +56 -19
  30. package/native-host.mjs +136 -42
  31. package/native-parsers/clojure.LICENSE +121 -0
  32. package/native-parsers/clojure.wasm +0 -0
  33. package/native-parsers/csharp.LICENSE +21 -0
  34. package/native-parsers/csharp.wasm +0 -0
  35. package/native-parsers/elixir.LICENSE +176 -0
  36. package/native-parsers/elixir.wasm +0 -0
  37. package/native-parsers/erlang.LICENSE +201 -0
  38. package/native-parsers/erlang.wasm +0 -0
  39. package/native-parsers/fsharp.LICENSE +21 -0
  40. package/native-parsers/fsharp.wasm +0 -0
  41. package/native-parsers/gleam.LICENSE +202 -0
  42. package/native-parsers/gleam.wasm +0 -0
  43. package/native-parsers/go.LICENSE +21 -0
  44. package/native-parsers/go.wasm +0 -0
  45. package/native-parsers/groovy.LICENSE +21 -0
  46. package/native-parsers/groovy.wasm +0 -0
  47. package/native-parsers/haskell.LICENSE +21 -0
  48. package/native-parsers/haskell.wasm +0 -0
  49. package/native-parsers/java.LICENSE +21 -0
  50. package/native-parsers/java.wasm +0 -0
  51. package/native-parsers/javascript.LICENSE +21 -0
  52. package/native-parsers/javascript.wasm +0 -0
  53. package/native-parsers/kotlin.LICENSE +9 -0
  54. package/native-parsers/kotlin.wasm +0 -0
  55. package/native-parsers/lock.json +114 -0
  56. package/native-parsers/prolog.LICENSE +21 -0
  57. package/native-parsers/prolog.wasm +0 -0
  58. package/native-parsers/python.LICENSE +21 -0
  59. package/native-parsers/python.wasm +0 -0
  60. package/native-parsers/rust.LICENSE +21 -0
  61. package/native-parsers/rust.wasm +0 -0
  62. package/native-parsers/scala.LICENSE +21 -0
  63. package/native-parsers/scala.wasm +0 -0
  64. package/native-parsers/swift.LICENSE +21 -0
  65. package/native-parsers/swift.wasm +0 -0
  66. package/native-parsers/typescript.LICENSE +21 -0
  67. package/native-parsers/typescript.wasm +0 -0
  68. package/node-events-reporter.mjs +41 -17
  69. package/package.json +4 -3
  70. package/project.mjs +338 -0
  71. package/proof.d.ts +93 -19
  72. package/proof.mjs +1538 -447
  73. package/read-only-hpack.mjs +6 -5
  74. package/scala-build-state.mjs +131 -41
  75. package/scala-coverage.mjs +57 -34
  76. package/scalars.mjs +23 -8
  77. package/templates.mjs +566 -617
  78. package/test-command.mjs +1671 -521
  79. package/learn/vendor/fantomas/LawSpec.Learn.Formatter.u1ne3a6xd2.wasm +0 -0
@@ -5,235 +5,721 @@ 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,presentationDigest,environmentDigest,recordedDigest,projectDigest,invocations} from './test-command.mjs';
8
+ import {
9
+ lawKeys,
10
+ presentationDigest,
11
+ environmentDigest,
12
+ recordedDigest,
13
+ projectDigest,
14
+ invocations,
15
+ } from './test-command.mjs';
9
16
 
10
17
  // Native execution observations are scoped to actual completed test slots.
11
18
  // They never establish a universal model proof or a witness-search completeness claim.
12
- export const obligationTargets = entry => entry.obligations ?? [{declaration:entry.law,stage:'law'}];
19
+ export const obligationTargets = entry =>
20
+ entry.obligations ?? [{declaration: entry.law, stage: 'law'}];
13
21
 
14
- export function nativeSeed(value){
15
- const text=String(value),number=Number(text);
16
- if(!/^[0-9]+$/.test(text))throw new Error('A native seed must be a whole number');
17
- if(typeof value==='number'&&!Number.isSafeInteger(value))
18
- throw new Error('The recorded numeric seed lost precision; rerun with an explicit exact seed');
19
- return Number.isSafeInteger(number)?number:text;
22
+ export function nativeSeed(value)
23
+ {
24
+ const text = String(value),
25
+ number = Number(text);
26
+ if (!/^[0-9]+$/.test(text))
27
+ throw new Error('A native seed must be a whole number');
28
+ if (typeof value === 'number' && !Number.isSafeInteger(value))
29
+ throw new Error(
30
+ 'The recorded numeric seed lost precision; rerun with an explicit exact seed',
31
+ );
32
+ return Number.isSafeInteger(number) ? number : text;
20
33
  }
21
34
 
22
- export function recordNativeAttempts(run, tests, {keys,seed,ok,profile,output,allEntries=run.laws,at=new Date().toISOString()}) {
23
- return Object.fromEntries((run.laws??[]).map(entry=>{
24
- const matched=tests.filter(test=>(run.matches?.(test)??[]).includes(entry));
25
- const model=(entry.obligations?.length??0)>0;
26
- const complete=matched.length>0&&matched.every(test=>test.status==='passed')&&(ok||model);
27
- const outcome=matched.some(test=>test.status==='failed')?'failed':
28
- matched.some(test=>test.status==='incomplete')?'incomplete':
29
- entry.skip?'skipped':complete?(entry.knownDiscrepancy?'known-discrepancy':'passed'):
30
- matched.length&&matched.every(test=>test.status==='skipped')?'skipped':'incomplete';
31
- return [entry.law,{key:keys.get(entry.law),planKey:entry.key,seed:nativeSeed(seed),at,outcome,
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,
33
- ...(entry.scope?{scope:entry.scope}:{}),obligations:obligationTargets(entry),
34
- nativeGroup:(allEntries??[]).filter(other=>other.file===entry.file&&other.name===entry.name&&other.scope===entry.scope)
35
- .map(other=>other.law)},
36
- // A passed combined method covers all its logical model aliases. A failed
37
- // combined method completes none successfully, even if another method passed.
38
- tests:matched,invocation:{ok,command:run.command,
39
- ...(!ok&&['failed','incomplete'].includes(outcome)&&output&&
40
- !matched.some(test=>test.status==='failed'&&(test.failure||test.reason||test.message))?{output}: {})},
41
- verification:'native-execution',searchCompleteness:'not-established'}];
42
- }));
35
+ export function recordNativeAttempts(
36
+ run,
37
+ tests,
38
+ {
39
+ keys,
40
+ seed,
41
+ ok,
42
+ profile,
43
+ output,
44
+ allEntries = run.laws,
45
+ at = new Date().toISOString(),
46
+ },
47
+ )
48
+ {
49
+ return Object.fromEntries(
50
+ (run.laws ?? []).map(entry =>
51
+ {
52
+ const matched = tests.filter(test =>
53
+ (run.matches?.(test) ?? []).includes(entry),
54
+ );
55
+ const model = (entry.obligations?.length ?? 0) > 0;
56
+ const complete =
57
+ matched.length > 0 &&
58
+ matched.every(test => test.status === 'passed') &&
59
+ (ok || model);
60
+ const outcome = matched.some(test => test.status === 'failed')
61
+ ? 'failed'
62
+ : matched.some(test => test.status === 'incomplete')
63
+ ? 'incomplete'
64
+ : entry.skip
65
+ ? 'skipped'
66
+ : complete
67
+ ? entry.knownDiscrepancy
68
+ ? 'known-discrepancy'
69
+ : 'passed'
70
+ : matched.length &&
71
+ matched.every(test => test.status === 'skipped')
72
+ ? 'skipped'
73
+ : 'incomplete';
74
+ return [
75
+ entry.law,
76
+ {
77
+ key: keys.get(entry.law),
78
+ planKey: entry.key,
79
+ seed: nativeSeed(seed),
80
+ at,
81
+ outcome,
82
+ profile,
83
+ coverage: entry.coverage ?? {
84
+ kind: 'sampled',
85
+ scopedQuantifiers: true,
86
+ },
87
+ check: {
88
+ id: entry.law,
89
+ unit: entry.unit,
90
+ file: entry.file,
91
+ name: entry.name,
92
+ label: entry.label,
93
+ ...(entry.scope ? {scope: entry.scope} : {}),
94
+ obligations: obligationTargets(entry),
95
+ nativeGroup: (allEntries ?? [])
96
+ .filter(
97
+ other =>
98
+ other.file === entry.file &&
99
+ other.name === entry.name &&
100
+ other.scope === entry.scope,
101
+ )
102
+ .map(other => other.law),
103
+ },
104
+ // A passed combined method covers all its logical model aliases. A failed
105
+ // combined method completes none successfully, even if another method passed.
106
+ tests: matched,
107
+ invocation: {
108
+ ok,
109
+ command: run.command,
110
+ ...(!ok &&
111
+ ['failed', 'incomplete'].includes(outcome) &&
112
+ output &&
113
+ !matched.some(
114
+ test =>
115
+ test.status === 'failed' &&
116
+ (test.failure || test.reason || test.message),
117
+ )
118
+ ? {output}
119
+ : {}),
120
+ },
121
+ verification: 'native-execution',
122
+ searchCompleteness: 'not-established',
123
+ },
124
+ ];
125
+ }),
126
+ );
43
127
  }
44
128
 
45
129
  // A law an attestation touches is keyed by how its dependencies were wired:
46
130
  // endpoint, kind, and a stand-in's product, version and conformance. What the
47
131
  // run observed (reached, history digests, completion) and the identities
48
132
  // reported beside it are not inputs, so they change no key.
49
- export function attestedKeys(result) {
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]]:[]),
53
- ...(d.standIn?[d.standIn.identity,d.standIn.version,d.standIn.conformance]:[])];
54
- return new Map((result.evidence??[]).filter(item=>item.against||item.plannedAgainst)
55
- .map(item=>[item.declaration,JSON.stringify([
56
- item.environment??item.plannedEnvironment,(item.against??item.plannedAgainst).map(wiring)])]));
133
+ export function attestedKeys(result)
134
+ {
135
+ const wiring = d => [
136
+ d.dependency,
137
+ d.endpoint,
138
+ d.kind,
139
+ ...(d.implementation
140
+ ? [
141
+ [
142
+ d.implementation.kind,
143
+ d.implementation.product,
144
+ d.implementation.version,
145
+ d.implementation.commit ?? null,
146
+ d.implementation.digest ?? null,
147
+ ],
148
+ ]
149
+ : []),
150
+ ...(d.standIn
151
+ ? [d.standIn.identity, d.standIn.version, d.standIn.conformance]
152
+ : []),
153
+ ];
154
+ return new Map(
155
+ (result.evidence ?? [])
156
+ .filter(item => item.against || item.plannedAgainst)
157
+ .map(item => [
158
+ item.declaration,
159
+ JSON.stringify([
160
+ item.environment ?? item.plannedEnvironment,
161
+ (item.against ?? item.plannedAgainst).map(wiring),
162
+ ]),
163
+ ]),
164
+ );
57
165
  }
58
166
 
59
- const subject = (entry,item) => obligationTargets(entry).some(target=>
60
- target.declaration===item.declaration&&target.stage===item.stage);
61
- const runtimeStages=new Set(['law','model','linearizable','sequentially consistent','causally consistent',
62
- 'eventually consistent','restart','scenario','supervision']);
167
+ const subject = (entry, item) =>
168
+ obligationTargets(entry).some(
169
+ target =>
170
+ target.declaration === item.declaration && target.stage === item.stage,
171
+ );
172
+ const runtimeStages = new Set([
173
+ 'law',
174
+ 'model',
175
+ 'linearizable',
176
+ 'sequentially consistent',
177
+ 'causally consistent',
178
+ 'eventually consistent',
179
+ 'restart',
180
+ 'scenario',
181
+ 'supervision',
182
+ ]);
63
183
 
64
184
  // Display archived observations in the current vocabulary; retain their raw
65
185
  // attempts and use those original values for freshness and completion checks.
66
- const observationOutcome=outcome=>outcome==='known-failing'?'known-discrepancy':outcome;
186
+ const observationOutcome = outcome =>
187
+ outcome === 'known-failing' ? 'known-discrepancy' : outcome;
67
188
 
68
189
  // Only observations with matching current compiler/configuration/source/native
69
190
  // inputs are eligible for completed evidence. A stored timestamp alone is not.
70
- export async function readNativeObservations({compiler,input,selected,roots,configRoot,config={},build,evidence,attestation}) {
71
- const records=await Promise.all(selected.map(async(target,index)=>{
72
- const root=roots[index],file=path.join(configRoot,'.lawspec/results',`${target.language}-${projectKey(root)}.json`);
73
- const record=JSON.parse(await readFile(file,'utf8').catch(error=>{
74
- if(error.code==='ENOENT')return '{}';throw error;
75
- }));
76
- return {target,root,attempts:record.attempts??{},runs:record.laws??{},presentation:record.presentation,attestations:record.attestations??{}};
77
- }));
78
- if(!records.some(record=>Object.keys(record.attempts).length))return [];
79
- const observations=[];
80
- for(const {target,root,attempts,runs,presentation,attestations}of records){
81
- const plans=new Map(),contexts=new Map();
191
+ export async function readNativeObservations({
192
+ compiler,
193
+ input,
194
+ selected,
195
+ roots,
196
+ configRoot,
197
+ config = {},
198
+ build,
199
+ evidence,
200
+ attestation,
201
+ })
202
+ {
203
+ const records = await Promise.all(
204
+ selected.map(async (target, index) =>
205
+ {
206
+ const root = roots[index],
207
+ file = path.join(
208
+ configRoot,
209
+ '.lawspec/results',
210
+ `${target.language}-${projectKey(root)}.json`,
211
+ );
212
+ const record = JSON.parse(
213
+ await readFile(file, 'utf8').catch(error =>
214
+ {
215
+ if (error.code === 'ENOENT') return '{}';
216
+ throw error;
217
+ }),
218
+ );
219
+ return {
220
+ target,
221
+ root,
222
+ attempts: record.attempts ?? {},
223
+ runs: record.laws ?? {},
224
+ presentation: record.presentation,
225
+ attestations: record.attestations ?? {},
226
+ };
227
+ }),
228
+ );
229
+ if (!records.some(record => Object.keys(record.attempts).length)) return [];
230
+ const observations = [];
231
+ for (const {
232
+ target,
233
+ root,
234
+ attempts,
235
+ runs,
236
+ presentation,
237
+ attestations,
238
+ } of records)
239
+ {
240
+ const plans = new Map(),
241
+ contexts = new Map();
82
242
  // An attempt is keyed by the wiring of the attestation it ran under: the
83
243
  // one named now, or else the one lawspec test stored for its run.
84
- const wiredBy=attempt=>attestation??(attempt?.environment?attestations[attempt.environment]:undefined);
85
- const slot=(minify,wired)=>`${minify}\0${wired?.run?.id??''}`;
86
- async function plan(minify,wired=attestation){
87
- const key=slot(minify,wired);
88
- if(!plans.has(key))plans.set(key,await compiler.planGeneration({...input,target:target.language,
89
- sourceDir:target.sourceDir,testDir:target.testDir,nativeBindings:target.nativeBindings,minify,
90
- ...(wired?{attestation:wired}:{})}));
244
+ const wiredBy = attempt =>
245
+ attestation ??
246
+ (attempt?.environment ? attestations[attempt.environment] : undefined);
247
+ const slot = (minify, wired) => `${minify}\0${wired?.run?.id ?? ''}`;
248
+ async function plan(minify, wired = attestation)
249
+ {
250
+ const key = slot(minify, wired);
251
+ if (!plans.has(key))
252
+ plans.set(
253
+ key,
254
+ await compiler.planGeneration({
255
+ ...input,
256
+ target: target.language,
257
+ sourceDir: target.sourceDir,
258
+ testDir: target.testDir,
259
+ nativeBindings: target.nativeBindings,
260
+ minify,
261
+ ...(wired ? {attestation: wired} : {}),
262
+ }),
263
+ );
91
264
  return plans.get(key);
92
265
  }
93
- const modes=[...new Set(Object.values(attempts).map(attempt=>attempt.profile?.minify)
94
- .filter(mode=>typeof mode==='boolean'))];
95
- if(!modes.length)modes.push(false);
96
- const base=await plan(modes[0]);
97
- if(base.diagnostics.length){
98
- observations.push({target:target.language,root,freshness:'unavailable',outcome:'incomplete',
99
- obligations:evidence.filter(item=>runtimeStages.has(item.stage)).map(({declaration,stage})=>({declaration,stage})),
100
- reason:'Native generation is unavailable: '+base.diagnostics.map(diagnostic=>diagnostic.message).join('; ')});
266
+ const modes = [
267
+ ...new Set(
268
+ Object.values(attempts)
269
+ .map(attempt => attempt.profile?.minify)
270
+ .filter(mode => typeof mode === 'boolean'),
271
+ ),
272
+ ];
273
+ if (!modes.length) modes.push(false);
274
+ const base = await plan(modes[0]);
275
+ if (base.diagnostics.length)
276
+ {
277
+ observations.push({
278
+ target: target.language,
279
+ root,
280
+ freshness: 'unavailable',
281
+ outcome: 'incomplete',
282
+ obligations: evidence
283
+ .filter(item => runtimeStages.has(item.stage))
284
+ .map(({declaration, stage}) => ({declaration, stage})),
285
+ reason:
286
+ 'Native generation is unavailable: ' +
287
+ base.diagnostics.map(diagnostic => diagnostic.message).join('; '),
288
+ });
101
289
  continue;
102
290
  }
103
- const expected=new Map(base.tests.map(entry=>[entry.law,entry]));
104
- async function context(minify,wired){
105
- const key=slot(minify,wired);
106
- if(contexts.has(key))return contexts.get(key);
107
- const generated=await plan(minify,wired);
291
+ const expected = new Map(base.tests.map(entry => [entry.law, entry]));
292
+ async function context(minify, wired)
293
+ {
294
+ const key = slot(minify, wired);
295
+ if (contexts.has(key)) return contexts.get(key);
296
+ const generated = await plan(minify, wired);
108
297
  let result;
109
- if(generated.diagnostics.length)result={reason:'Native generation is unavailable for the recorded layout'};
110
- else {
111
- const pending=await planWrites(root,generated.files);
112
- if(pending.changes.length)result={stale:true,reason:'Generated files differ from the recorded/current plan'};
113
- else {
114
- const report=await doctor(target,root,generated.files);
115
- if(!report.ok)result={reason:'The current native environment could not be checked: '+report.message};
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;
298
+ if (generated.diagnostics.length)
299
+ result = {
300
+ reason: 'Native generation is unavailable for the recorded layout',
301
+ };
302
+ else
303
+ {
304
+ const pending = await planWrites(root, generated.files);
305
+ if (pending.changes.length)
306
+ result = {
307
+ stale: true,
308
+ reason: 'Generated files differ from the recorded/current plan',
309
+ };
310
+ else
311
+ {
312
+ const report = await doctor(target, root, generated.files);
313
+ if (!report.ok)
314
+ result = {
315
+ reason:
316
+ 'The current native environment could not be checked: ' +
317
+ report.message,
318
+ };
319
+ else
320
+ {
321
+ const environment = await environmentDigest(
322
+ root,
323
+ report,
324
+ target.language,
325
+ );
326
+ if (
327
+ presentation !== presentationDigest(generated.files, environment)
328
+ )
329
+ {
330
+ result = {
331
+ reason:
332
+ 'Current generated presentation has not passed native validation; run lawspec test',
333
+ };
334
+ contexts.set(key, result);
335
+ return result;
121
336
  }
122
- const owned=new Set(generated.files.filter(file=>file.ownership==='generated').map(file=>file.path));
123
- const keys=lawKeys({build,target,machineBits:input.machineBits,minify,tests:generated.tests,files:generated.files,
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)});
126
- result={generated,keys};
337
+ const owned = new Set(
338
+ generated.files
339
+ .filter(file => file.ownership === 'generated')
340
+ .map(file => file.path),
341
+ );
342
+ const keys = lawKeys({
343
+ build,
344
+ target,
345
+ machineBits: input.machineBits,
346
+ minify,
347
+ tests: generated.tests,
348
+ files: generated.files,
349
+ environment,
350
+ recorded: await recordedDigest(path.join(configRoot, 'recorded')),
351
+ project: await projectDigest(root, owned, target.language, {
352
+ inputRoot: configRoot,
353
+ inputs: config.inputs ?? [],
354
+ }),
355
+ attested: attestedKeys(generated),
356
+ });
357
+ result = {generated, keys};
127
358
  }
128
359
  }
129
360
  }
130
- contexts.set(key,result);return result;
361
+ contexts.set(key, result);
362
+ return result;
131
363
  }
132
- for(const [id,baseline]of expected){
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;
364
+ for (const [id, baseline] of expected)
365
+ {
366
+ let attempt = attempts[id],
367
+ reuse;
368
+ if (!attempt)
369
+ for (const original of Object.values(attempts))
370
+ {
371
+ // Only a single ordinary-law observation can be re-associated here.
372
+ // Combined model methods keep their exact group identities.
373
+ if (
374
+ original.outcome !== 'passed' ||
375
+ original.check?.nativeGroup?.length !== 1 ||
376
+ !isDeepStrictEqual(original.check.obligations, [
377
+ {declaration: original.check.id, stage: 'law'},
378
+ ]) ||
379
+ !isDeepStrictEqual(obligationTargets(baseline), [
380
+ {declaration: id, stage: 'law'},
381
+ ])
382
+ )
383
+ continue;
384
+ let candidate = await context(
385
+ original.profile?.minify ?? false,
386
+ wiredBy(original),
387
+ );
388
+ if (candidate.reason && candidate.stale)
389
+ candidate = await context(
390
+ !original.profile?.minify,
391
+ wiredBy(original),
392
+ );
393
+ if (
394
+ !candidate.reason &&
395
+ candidate.keys.get(id) === original.key &&
396
+ baseline.key === original.planKey
397
+ )
398
+ {
399
+ attempt = original;
400
+ reuse = {
401
+ check: original.check.id,
402
+ key: original.key,
403
+ at: original.at,
404
+ };
405
+ break;
406
+ }
144
407
  }
408
+ const row = {
409
+ target: target.language,
410
+ root,
411
+ check: {id, obligations: obligationTargets(baseline)},
412
+ outcome: observationOutcome(attempt?.outcome ?? 'not-run'),
413
+ coverage: baseline.coverage,
414
+ attempt,
415
+ };
416
+ if (!attempt)
417
+ {
418
+ observations.push({
419
+ ...row,
420
+ freshness: 'not-run',
421
+ reason: 'No completed native observation was recorded',
422
+ });
423
+ continue;
145
424
  }
146
- const row={target:target.language,root,check:{id,obligations:obligationTargets(baseline)},
147
- outcome:observationOutcome(attempt?.outcome??'not-run'),coverage:baseline.coverage,attempt};
148
- if(!attempt){observations.push({...row,freshness:'not-run',reason:'No completed native observation was recorded'});continue;}
149
- const profile=attempt.profile??{};
150
- if(profile.target!==target.language||profile.root!==root||profile.machineBits!==input.machineBits||profile.build!==build||
151
- typeof profile.minify!=='boolean'){
152
- observations.push({...row,freshness:'stale',reason:'Compiler, target or machine profile differs'});continue;
425
+ const profile = attempt.profile ?? {};
426
+ if (
427
+ profile.target !== target.language ||
428
+ profile.root !== root ||
429
+ profile.machineBits !== input.machineBits ||
430
+ profile.build !== build ||
431
+ typeof profile.minify !== 'boolean'
432
+ )
433
+ {
434
+ observations.push({
435
+ ...row,
436
+ freshness: 'stale',
437
+ reason: 'Compiler, target or machine profile differs',
438
+ });
439
+ continue;
153
440
  }
154
- let current=await context(profile.minify,wiredBy(attempt));
441
+ let current = await context(profile.minify, wiredBy(attempt));
155
442
  // Layout belongs to the artifact, not to the meaning of its old run.
156
443
  // Accept the other canonical layout only when it exactly matches disk.
157
- if(current.reason&&current.stale)current=await context(!profile.minify,wiredBy(attempt));
158
- if(current.reason){observations.push({...row,freshness:current.stale?'stale':'unavailable',reason:current.reason});continue;}
159
- const entry=current.generated.tests.find(entry=>entry.law===id);
160
- if(!entry||attempt.key!==current.keys.get(id)||attempt.planKey!==entry.key||
161
- (!reuse&&!isDeepStrictEqual(attempt.check?.obligations,obligationTargets(entry)))||
162
- !isDeepStrictEqual(attempt.coverage,entry.coverage)){
163
- observations.push({...row,freshness:'stale',reason:'Specification, selection, bindings, native source or toolchain inputs differ'});continue;
444
+ if (current.reason && current.stale)
445
+ current = await context(!profile.minify, wiredBy(attempt));
446
+ if (current.reason)
447
+ {
448
+ observations.push({
449
+ ...row,
450
+ freshness: current.stale ? 'stale' : 'unavailable',
451
+ reason: current.reason,
452
+ });
453
+ continue;
454
+ }
455
+ const entry = current.generated.tests.find(entry => entry.law === id);
456
+ if (
457
+ !entry ||
458
+ attempt.key !== current.keys.get(id) ||
459
+ attempt.planKey !== entry.key ||
460
+ (!reuse &&
461
+ !isDeepStrictEqual(
462
+ attempt.check?.obligations,
463
+ obligationTargets(entry),
464
+ )) ||
465
+ !isDeepStrictEqual(attempt.coverage, entry.coverage)
466
+ )
467
+ {
468
+ observations.push({
469
+ ...row,
470
+ freshness: 'stale',
471
+ reason:
472
+ 'Specification, selection, bindings, native source or toolchain inputs differ',
473
+ });
474
+ continue;
164
475
  }
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;
168
- const validSeed=(typeof attempt.seed==='number'&&Number.isSafeInteger(attempt.seed)&&attempt.seed>=0)||
169
- (typeof attempt.seed==='string'&&/^[0-9]+$/.test(attempt.seed));
170
- const recomputed=validSeed&&Number.isFinite(Date.parse(attempt.at))&&invocation&&Array.isArray(attempt.tests)&&recordNativeAttempts(invocation,attempt.tests,
171
- {keys:observedKeys,seed:attempt.seed,ok:attempt.invocation?.ok===true,profile,at:attempt.at,
172
- allEntries:reuse?[observedEntry]:current.generated.tests})[observedEntry.law];
173
- if(!recomputed||recomputed.outcome!==attempt.outcome||
174
- !isDeepStrictEqual(recomputed.check.nativeGroup,attempt.check?.nativeGroup)){
175
- observations.push({...row,freshness:'unavailable',reason:'The stored observation does not establish the current native completion'});continue;
476
+ const observedEntry = reuse
477
+ ? {
478
+ ...entry,
479
+ ...attempt.check,
480
+ law: attempt.check.id,
481
+ key: attempt.planKey,
482
+ }
483
+ : entry;
484
+ const invocation = invocations(target, [observedEntry], {root}).find(
485
+ run => run.laws?.includes(observedEntry),
486
+ );
487
+ const observedKeys = reuse
488
+ ? new Map([[observedEntry.law, attempt.key]])
489
+ : current.keys;
490
+ const validSeed =
491
+ (typeof attempt.seed === 'number' &&
492
+ Number.isSafeInteger(attempt.seed) &&
493
+ attempt.seed >= 0) ||
494
+ (typeof attempt.seed === 'string' && /^[0-9]+$/.test(attempt.seed));
495
+ const recomputed =
496
+ validSeed &&
497
+ Number.isFinite(Date.parse(attempt.at)) &&
498
+ invocation &&
499
+ Array.isArray(attempt.tests) &&
500
+ recordNativeAttempts(invocation, attempt.tests, {
501
+ keys: observedKeys,
502
+ seed: attempt.seed,
503
+ ok: attempt.invocation?.ok === true,
504
+ profile,
505
+ at: attempt.at,
506
+ allEntries: reuse ? [observedEntry] : current.generated.tests,
507
+ })[observedEntry.law];
508
+ if (
509
+ !recomputed ||
510
+ recomputed.outcome !== attempt.outcome ||
511
+ !isDeepStrictEqual(
512
+ recomputed.check.nativeGroup,
513
+ attempt.check?.nativeGroup,
514
+ )
515
+ )
516
+ {
517
+ observations.push({
518
+ ...row,
519
+ freshness: 'unavailable',
520
+ reason:
521
+ 'The stored observation does not establish the current native completion',
522
+ });
523
+ continue;
176
524
  }
177
- const run=runs[id];
178
- observations.push({...row,freshness:'matching-inputs',...(reuse?{reused:reuse}:{}),
179
- ...(attempt.outcome==='passed'&&run?.key===attempt.key&&(run.flaky||run.adequacy)?
180
- {harness:{...(run.flaky?{flaky:true}:{}),...(run.adequacy?{adequacy:run.adequacy}:{})}}:{}),
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'});
525
+ const run = runs[id];
526
+ observations.push({
527
+ ...row,
528
+ freshness: 'matching-inputs',
529
+ ...(reuse ? {reused: reuse} : {}),
530
+ ...(attempt.outcome === 'passed' &&
531
+ run?.key === attempt.key &&
532
+ (run.flaky || run.adequacy)
533
+ ? {
534
+ harness: {
535
+ ...(run.flaky ? {flaky: true} : {}),
536
+ ...(run.adequacy ? {adequacy: run.adequacy} : {}),
537
+ },
538
+ }
539
+ : {}),
540
+ reason: reuse
541
+ ? 'Original native completion reused for the current semantic law; no fresh invocation is claimed'
542
+ : attempt.outcome === 'passed'
543
+ ? 'Recorded native completion matches the current inputs'
544
+ : 'Recorded native attempt matches the current inputs',
545
+ });
182
546
  }
183
- for(const [id,attempt]of Object.entries(attempts))if(!expected.has(id)&&Array.isArray(attempt.check?.obligations))
184
- observations.push({target:target.language,root,check:attempt.check,attempt,outcome:observationOutcome(attempt.outcome),
185
- coverage:attempt.coverage,freshness:'not-selected',reason:'This native check is not selected by the current configuration'});
547
+ for (const [id, attempt] of Object.entries(attempts))
548
+ if (!expected.has(id) && Array.isArray(attempt.check?.obligations))
549
+ observations.push({
550
+ target: target.language,
551
+ root,
552
+ check: attempt.check,
553
+ attempt,
554
+ outcome: observationOutcome(attempt.outcome),
555
+ coverage: attempt.coverage,
556
+ freshness: 'not-selected',
557
+ reason:
558
+ 'This native check is not selected by the current configuration',
559
+ });
186
560
  }
187
561
  return observations;
188
562
  }
189
563
 
190
- export function attachNativeEvidence(evidence,observations){
191
- return evidence.map(item=>{
192
- const rows=observations.filter(row=>row.check?subject({obligations:row.check.obligations},item):
193
- row.obligations?.some(target=>target.declaration===item.declaration&&target.stage===item.stage));
194
- if(!rows.length)return item;
195
- const current=rows.filter(row=>row.freshness==='matching-inputs');
196
- const failed=current.filter(row=>row.outcome==='failed');
197
- const combinedFailure=failed.some(row=>(row.attempt?.check.nativeGroup?.length??0)>1);
198
- const status=failed.length?(combinedFailure?'incomplete':'failed'):
199
- current.length===rows.length&&current.every(row=>row.outcome==='passed')?'passed':
200
- current.length===rows.length&&current.every(row=>row.outcome==='skipped')?'skipped':
201
- current.length===rows.length&&current.every(row=>row.outcome==='known-discrepancy')?'known-discrepancy':
202
- current.some(row=>row.outcome==='passed')?'partial':
203
- current.some(row=>['incomplete','not-run'].includes(row.outcome))?'incomplete':
204
- rows.every(row=>row.freshness==='not-selected')?'not-selected':
205
- rows.some(row=>row.freshness==='stale')?'stale':'unavailable';
206
- const completeFinite=status==='passed'&&rows.every(row=>row.coverage?.kind==='finite-inputs'&&
207
- row.coverage.scopedQuantifiers===false);
208
- const nativeEvidence={kind:'native-conformance',status,
209
- searchCompleteness:completeFinite?'complete-finite-inputs':'not-established',observations:rows};
210
- const adequacy=current.flatMap(row=>row.harness?.adequacy??[]);
211
- const enriched={...item,nativeEvidence,...(adequacy.length?{adequacy}:{})};
212
- if(item.status!=='planned')return enriched;
213
- const flaky=current.some(row=>row.harness?.flaky);
214
- if(status==='passed')return {...enriched,plannedEvidence:{status:item.status,reason:item.reason},
215
- status:flaky?'flaky':completeFinite?'exhaustively-checked':'property-tested',
216
- reason:`Recorded native checks completed for ${new Set(rows.map(row=>row.target+'\0'+row.root)).size} requested target(s); `+
217
- (completeFinite?'every finite input was checked.':'this is scoped native execution evidence, not a universal model or search proof.')+
218
- (flaky?' Its last run failed, then passed on a retry.':'')};
219
- if(['failed','incomplete'].includes(status))return {...enriched,
220
- plannedEvidence:{status:item.status,reason:item.reason},status:'incomplete',
221
- reason:combinedFailure?'A combined native method failed; the specific included logical check is not identified, and no successful conformance result is established.':
222
- status==='failed'?'A recorded native implementation check failed; no successful conformance result is established.':
223
- 'Native execution did not complete all selected checks; no successful conformance result is established.'};
564
+ export function attachNativeEvidence(evidence, observations)
565
+ {
566
+ return evidence.map(item =>
567
+ {
568
+ const rows = observations.filter(row =>
569
+ row.check
570
+ ? subject({obligations: row.check.obligations}, item)
571
+ : row.obligations?.some(
572
+ target =>
573
+ target.declaration === item.declaration &&
574
+ target.stage === item.stage,
575
+ ),
576
+ );
577
+ if (!rows.length) return item;
578
+ const current = rows.filter(row => row.freshness === 'matching-inputs');
579
+ const failed = current.filter(row => row.outcome === 'failed');
580
+ const combinedFailure = failed.some(
581
+ row => (row.attempt?.check?.nativeGroup?.length ?? 0) > 1,
582
+ );
583
+ const status = failed.length
584
+ ? combinedFailure
585
+ ? 'incomplete'
586
+ : 'failed'
587
+ : current.length === rows.length &&
588
+ current.every(row => row.outcome === 'passed')
589
+ ? 'passed'
590
+ : current.length === rows.length &&
591
+ current.every(row => row.outcome === 'skipped')
592
+ ? 'skipped'
593
+ : current.length === rows.length &&
594
+ current.every(row => row.outcome === 'known-discrepancy')
595
+ ? 'known-discrepancy'
596
+ : current.some(row => row.outcome === 'passed')
597
+ ? 'partial'
598
+ : current.some(row =>
599
+ ['incomplete', 'not-run'].includes(row.outcome),
600
+ )
601
+ ? 'incomplete'
602
+ : rows.every(row => row.freshness === 'not-selected')
603
+ ? 'not-selected'
604
+ : rows.some(row => row.freshness === 'stale')
605
+ ? 'stale'
606
+ : 'unavailable';
607
+ const completeFinite =
608
+ status === 'passed' &&
609
+ rows.every(
610
+ row =>
611
+ row.coverage?.kind === 'finite-inputs' &&
612
+ row.coverage.scopedQuantifiers === false,
613
+ );
614
+ const measurements =
615
+ item.executionKind === 'measurement'
616
+ ? current.flatMap(row =>
617
+ (row.attempt?.tests ?? []).flatMap(test =>
618
+ Number.isFinite(test.time) && test.time >= 0
619
+ ? [
620
+ {
621
+ kind: 'native-check-duration',
622
+ target: row.target,
623
+ root: row.root,
624
+ test: test.name,
625
+ seconds: test.time,
626
+ },
627
+ ]
628
+ : [],
629
+ ),
630
+ )
631
+ : [];
632
+ const nativeEvidence = {
633
+ kind: 'native-conformance',
634
+ status,
635
+ searchCompleteness: completeFinite
636
+ ? 'complete-finite-inputs'
637
+ : 'not-established',
638
+ observations: rows,
639
+ ...(item.executionKind === 'measurement'
640
+ ? {
641
+ measurements,
642
+ measurementScope:
643
+ 'Reported durations cover the native check, including harness overhead; exact operation timings are not exported by these runners.',
644
+ }
645
+ : {}),
646
+ };
647
+ const adequacy = current.flatMap(row => row.harness?.adequacy ?? []);
648
+ const enriched = {
649
+ ...item,
650
+ nativeEvidence,
651
+ ...(adequacy.length ? {adequacy} : {}),
652
+ };
653
+ if (item.status !== 'planned') return enriched;
654
+ const flaky = current.some(row => row.harness?.flaky);
655
+ if (status === 'passed')
656
+ return {
657
+ ...enriched,
658
+ plannedEvidence: {status: item.status, reason: item.reason},
659
+ status: flaky
660
+ ? 'flaky'
661
+ : item.executionKind === 'measurement'
662
+ ? 'measured'
663
+ : completeFinite
664
+ ? 'exhaustively-checked'
665
+ : 'property-tested',
666
+ reason:
667
+ `Recorded native checks completed for ${new Set(rows.map(row => row.target + '\0' + row.root)).size} requested target(s); ` +
668
+ (item.executionKind === 'measurement'
669
+ ? 'the performance budget was checked against the real clock. This is measurement evidence, not proof. ' +
670
+ nativeEvidence.measurementScope
671
+ : completeFinite
672
+ ? 'every finite input was checked.'
673
+ : 'this is scoped native execution evidence, not a universal model or search proof.') +
674
+ (flaky ? ' Its last run failed, then passed on a retry.' : ''),
675
+ };
676
+ if (['failed', 'incomplete'].includes(status))
677
+ return {
678
+ ...enriched,
679
+ plannedEvidence: {status: item.status, reason: item.reason},
680
+ status: 'incomplete',
681
+ reason: combinedFailure
682
+ ? 'A combined native method failed; the specific included logical check is not identified, and no successful conformance result is established.'
683
+ : status === 'failed'
684
+ ? 'A recorded native implementation check failed; no successful conformance result is established.'
685
+ : 'Native execution did not complete all selected checks; no successful conformance result is established.',
686
+ };
224
687
  return enriched;
225
688
  });
226
689
  }
227
690
 
228
691
  // 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');
692
+ export function nativeEvidenceText(item)
693
+ {
694
+ if (!item.nativeEvidence) return '';
695
+ const summary = item.nativeEvidence;
696
+ return [
697
+ `Native conformance: ${summary.status}; search completeness: ${summary.searchCompleteness}`,
698
+ ...(summary.measurements ?? []).map(
699
+ item =>
700
+ `Native check duration: ${item.test} [${item.target}] ${item.seconds} s`,
701
+ ),
702
+ ...(summary.measurementScope ? [summary.measurementScope] : []),
703
+ ...summary.observations.map(
704
+ row =>
705
+ `${row.target} (${row.root}): ${row.outcome}; ${row.freshness}` +
706
+ (row.attempt ? `; seed ${row.attempt.seed}; ${row.attempt.at}` : '') +
707
+ `; ${row.reason}`,
708
+ ),
709
+ ...summary.observations.flatMap(row =>
710
+ (row.attempt?.tests ?? [])
711
+ .filter(test => test.status === 'failed')
712
+ .map(
713
+ test =>
714
+ `${test.name}: ${test.reason ?? test.failure ?? test.message ?? 'native test failed'}`,
715
+ ),
716
+ ),
717
+ ...summary.observations
718
+ .filter(row => row.attempt?.invocation?.output)
719
+ .map(
720
+ row =>
721
+ 'Native invocation output (scoped to that invocation):\n' +
722
+ row.attempt.invocation.output,
723
+ ),
724
+ ].join('\n');
239
725
  }