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.
- package/CHANGELOG.md +89 -2
- package/README.md +85 -9
- package/api.mjs +14 -9
- package/authoring.mjs +899 -0
- package/beam-coverage.mjs +190 -65
- package/beam-doctor.mjs +343 -124
- package/bin/lawspec.mjs +1949 -661
- package/build.json +134 -128
- package/component-packages.mjs +662 -176
- package/component.d.ts +82 -20
- package/component.mjs +317 -94
- package/core.wasm +2 -2
- package/core_jsffi.js +5 -5
- package/doctor.mjs +558 -299
- package/examples-command.mjs +44 -23
- package/failure-database.mjs +60 -17
- package/files.mjs +122 -62
- package/index.d.ts +585 -312
- package/input-files.mjs +90 -25
- package/launcher.mjs +72 -31
- package/learn/coverage.json +184 -112
- package/learn/curriculum.json +4 -1
- package/learn/vendor/fantomas/{LawSpec.Learn.Formatter.5arcua4vy0.wasm → LawSpec.Learn.Formatter.poiijdbsl9.wasm} +0 -0
- package/learn/vendor/fantomas/dotnet.js +3 -3
- package/learn/vendor/manifest.json +4 -8
- package/lsp.mjs +444 -133
- package/mcp.mjs +250 -0
- package/native-evidence.mjs +668 -182
- package/native-examples.mjs +56 -19
- package/native-host.mjs +136 -42
- package/native-parsers/clojure.LICENSE +121 -0
- package/native-parsers/clojure.wasm +0 -0
- package/native-parsers/csharp.LICENSE +21 -0
- package/native-parsers/csharp.wasm +0 -0
- package/native-parsers/elixir.LICENSE +176 -0
- package/native-parsers/elixir.wasm +0 -0
- package/native-parsers/erlang.LICENSE +201 -0
- package/native-parsers/erlang.wasm +0 -0
- package/native-parsers/fsharp.LICENSE +21 -0
- package/native-parsers/fsharp.wasm +0 -0
- package/native-parsers/gleam.LICENSE +202 -0
- package/native-parsers/gleam.wasm +0 -0
- package/native-parsers/go.LICENSE +21 -0
- package/native-parsers/go.wasm +0 -0
- package/native-parsers/groovy.LICENSE +21 -0
- package/native-parsers/groovy.wasm +0 -0
- package/native-parsers/haskell.LICENSE +21 -0
- package/native-parsers/haskell.wasm +0 -0
- package/native-parsers/java.LICENSE +21 -0
- package/native-parsers/java.wasm +0 -0
- package/native-parsers/javascript.LICENSE +21 -0
- package/native-parsers/javascript.wasm +0 -0
- package/native-parsers/kotlin.LICENSE +9 -0
- package/native-parsers/kotlin.wasm +0 -0
- package/native-parsers/lock.json +114 -0
- package/native-parsers/prolog.LICENSE +21 -0
- package/native-parsers/prolog.wasm +0 -0
- package/native-parsers/python.LICENSE +21 -0
- package/native-parsers/python.wasm +0 -0
- package/native-parsers/rust.LICENSE +21 -0
- package/native-parsers/rust.wasm +0 -0
- package/native-parsers/scala.LICENSE +21 -0
- package/native-parsers/scala.wasm +0 -0
- package/native-parsers/swift.LICENSE +21 -0
- package/native-parsers/swift.wasm +0 -0
- package/native-parsers/typescript.LICENSE +21 -0
- package/native-parsers/typescript.wasm +0 -0
- package/node-events-reporter.mjs +41 -17
- package/package.json +4 -3
- package/project.mjs +338 -0
- package/proof.d.ts +93 -19
- package/proof.mjs +1538 -447
- package/read-only-hpack.mjs +6 -5
- package/scala-build-state.mjs +131 -41
- package/scala-coverage.mjs +57 -34
- package/scalars.mjs +23 -8
- package/templates.mjs +566 -617
- package/test-command.mjs +1671 -521
- package/learn/vendor/fantomas/LawSpec.Learn.Formatter.u1ne3a6xd2.wasm +0 -0
package/native-evidence.mjs
CHANGED
|
@@ -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 {
|
|
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 =>
|
|
19
|
+
export const obligationTargets = entry =>
|
|
20
|
+
entry.obligations ?? [{declaration: entry.law, stage: 'law'}];
|
|
13
21
|
|
|
14
|
-
export function nativeSeed(value)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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) =>
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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=>
|
|
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({
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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=>
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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=[
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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)
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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);
|
|
361
|
+
contexts.set(key, result);
|
|
362
|
+
return result;
|
|
131
363
|
}
|
|
132
|
-
for(const [id,baseline]of expected)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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&¤t.stale)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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({
|
|
179
|
-
...
|
|
180
|
-
|
|
181
|
-
|
|
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))
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const
|
|
207
|
-
row.
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
...summary.
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
}
|