tslaws 0.10.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -2
- package/bin/tslaws.js +8 -2
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +25 -5
- package/dist/bundled.js +2 -2
- package/dist/bundlerPlugins.d.ts +2 -0
- package/dist/bundlerPlugins.js +7 -0
- package/dist/certificates.d.ts +139 -0
- package/dist/certificates.js +433 -0
- package/dist/chc.d.ts +85 -0
- package/dist/chc.js +298 -0
- package/dist/check.d.ts +13 -1
- package/dist/check.js +211 -27
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +175 -34
- package/dist/compile.d.ts +15 -5
- package/dist/compile.js +198 -69
- package/dist/coverage.d.ts +38 -1
- package/dist/coverage.js +94 -12
- package/dist/e2eApi.js +3 -1
- package/dist/generators.js +12 -2
- package/dist/github.d.ts +49 -5
- package/dist/github.js +107 -24
- package/dist/githubCli.d.ts +28 -0
- package/dist/githubCli.js +1039 -211
- package/dist/hints.js +2 -1
- package/dist/init.js +42 -0
- package/dist/isolate.d.ts +28 -0
- package/dist/isolate.js +262 -0
- package/dist/isolatedCheck.d.ts +1 -0
- package/dist/isolatedCheck.js +16 -0
- package/dist/lawHost.d.ts +50 -0
- package/dist/lawHost.js +199 -0
- package/dist/lawRuntime.d.ts +39 -0
- package/dist/lawRuntime.js +242 -0
- package/dist/lock.d.ts +49 -9
- package/dist/lock.js +132 -21
- package/dist/mcp.js +28 -7
- package/dist/mutate.d.ts +4 -0
- package/dist/mutate.js +7 -1
- package/dist/plan.d.ts +1 -0
- package/dist/plan.js +4 -0
- package/dist/pluginHooks.d.ts +16 -0
- package/dist/pluginHooks.js +48 -0
- package/dist/pluginHost.d.ts +5 -0
- package/dist/pluginHost.js +43 -0
- package/dist/pluginWorker.d.ts +1 -0
- package/dist/pluginWorker.js +40 -0
- package/dist/plural.d.ts +2 -0
- package/dist/plural.js +4 -0
- package/dist/pool.d.ts +80 -7
- package/dist/pool.js +222 -11
- package/dist/projects.d.ts +43 -1
- package/dist/projects.js +283 -11
- package/dist/promote.d.ts +56 -2
- package/dist/promote.js +429 -13
- package/dist/property.js +5 -1
- package/dist/propertyWorker.js +7 -0
- package/dist/proposals.d.ts +52 -4
- package/dist/proposals.js +484 -21
- package/dist/reporters.js +5 -1
- package/dist/runtimeEnv.d.ts +13 -5
- package/dist/runtimeEnv.js +48 -10
- package/dist/sandbox.d.ts +98 -0
- package/dist/sandbox.js +673 -0
- package/dist/sandboxGuard.d.ts +56 -0
- package/dist/sandboxGuard.js +249 -0
- package/dist/seal.d.ts +9 -0
- package/dist/seal.js +426 -0
- package/dist/security/cli.d.ts +6 -0
- package/dist/security/cli.js +39 -0
- package/dist/security/cwe.d.ts +14 -0
- package/dist/security/cwe.js +40 -0
- package/dist/security/deps/cache.d.ts +28 -0
- package/dist/security/deps/cache.js +107 -0
- package/dist/security/deps/config.d.ts +16 -0
- package/dist/security/deps/config.js +43 -0
- package/dist/security/deps/imports.d.ts +4 -0
- package/dist/security/deps/imports.js +33 -0
- package/dist/security/deps/lockfiles.d.ts +23 -0
- package/dist/security/deps/lockfiles.js +153 -0
- package/dist/security/deps/osv.d.ts +66 -0
- package/dist/security/deps/osv.js +137 -0
- package/dist/security/deps/run.d.ts +54 -0
- package/dist/security/deps/run.js +135 -0
- package/dist/security/deps/severity.d.ts +26 -0
- package/dist/security/deps/severity.js +78 -0
- package/dist/security/generators.d.ts +9 -0
- package/dist/security/generators.js +36 -0
- package/dist/security/index.d.ts +27 -0
- package/dist/security/index.js +18 -0
- package/dist/security/integers.d.ts +31 -0
- package/dist/security/integers.js +105 -0
- package/dist/security/law.d.ts +54 -0
- package/dist/security/law.js +54 -0
- package/dist/security/pathTraversal.d.ts +29 -0
- package/dist/security/pathTraversal.js +146 -0
- package/dist/security/prototypePollution.d.ts +30 -0
- package/dist/security/prototypePollution.js +142 -0
- package/dist/security/redirect.d.ts +21 -0
- package/dist/security/redirect.js +154 -0
- package/dist/security/redos.d.ts +21 -0
- package/dist/security/redos.js +93 -0
- package/dist/security/validation.d.ts +25 -0
- package/dist/security/validation.js +89 -0
- package/dist/security/xss.d.ts +21 -0
- package/dist/security/xss.js +90 -0
- package/dist/settings.d.ts +20 -0
- package/dist/settings.js +32 -0
- package/dist/smt.d.ts +29 -1
- package/dist/smt.js +239 -107
- package/dist/smtWorker.d.ts +1 -0
- package/dist/smtWorker.js +26 -0
- package/dist/solvers.d.ts +9 -0
- package/dist/solvers.js +11 -5
- package/dist/symbolic.d.ts +54 -1
- package/dist/symbolic.js +239 -13
- package/dist/tsconfigResolve.d.ts +28 -0
- package/dist/tsconfigResolve.js +141 -0
- package/dist/types.d.ts +28 -0
- package/hooks/claude-hook.mjs +2 -0
- package/package.json +18 -6
package/dist/check.js
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
|
-
import { resolve } from 'node:path';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
3
|
import ts from 'typescript';
|
|
4
4
|
import { build, readManifest } from "./compile.js";
|
|
5
|
+
import { withResolution } from "./lawRuntime.js";
|
|
5
6
|
import { compilerOptions, declarationFiles, isDiscard, jsPath, runLawGuarded, warmWorkers, typesOf, } from "./property.js";
|
|
6
7
|
import { analyzeCoverage, coverFiles, lawEnv, readConfig } from "./coverage.js";
|
|
8
|
+
import { parseGithubConfig } from "./github.js";
|
|
7
9
|
import { derivedStore } from "./derived.js";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
+
import { budget, configureJobs } from "./pool.js";
|
|
11
|
+
import { hostConfig, LawLoadError, Sandbox, useSandbox, warnE2e, warmSandbox } from "./sandbox.js";
|
|
12
|
+
import { bindingOf, certificateFailure, hashOf, noCertificate, recordOf, staleRecord, verifyRecord, writeRecords, readRecords, } from "./certificates.js";
|
|
13
|
+
import { compareLock, lawHash, lawKey, lockFormat, proofStatus, readLock, scopeOf } from "./lock.js";
|
|
10
14
|
import { crossCheck, disagreement } from "./propertyRun.js";
|
|
11
15
|
import { prepareRuntime } from "./runtimeEnv.js";
|
|
12
|
-
import { proveLaw } from "./smt.js";
|
|
16
|
+
import { problemTexts, proveLaw } from "./smt.js";
|
|
13
17
|
import { decodeExample, loadExamples, regressionMessage, saveExample } from "./regressions.js";
|
|
14
18
|
import { closeBrowser, runBrowserLaw } from "./browser.js";
|
|
15
19
|
import { ensureServer, runE2eLaw, stopServer } from "./e2e.js";
|
|
@@ -17,7 +21,7 @@ import { inProposals } from "./lawFiles.js";
|
|
|
17
21
|
import { classifyLawFile } from "./lawKinds.js";
|
|
18
22
|
import { normaliseProposal } from "./proposals.js";
|
|
19
23
|
import { declarationOf, exercisesOf, markFailing, Sources } from "./exercises.js";
|
|
20
|
-
/** Runs at most `limit` tasks at once. */
|
|
24
|
+
/** Runs at most `limit` tasks at once. The CPU limit is the process-wide budget (pool.ts); this holds the single page. */
|
|
21
25
|
class Semaphore {
|
|
22
26
|
free;
|
|
23
27
|
queue = [];
|
|
@@ -46,7 +50,7 @@ export function exemptionsOf(options) {
|
|
|
46
50
|
const covered = coverFiles(options.cwd, readConfig(options.cwd).cover ?? []);
|
|
47
51
|
const compiled = [...new Set([...options.files, ...covered])];
|
|
48
52
|
const built = build(options.compiler, compiled, options.cwd);
|
|
49
|
-
const program = ts.createProgram(declarationFiles(built.outDir), compilerOptions);
|
|
53
|
+
const program = ts.createProgram(declarationFiles(built.outDir), withResolution(built.outDir, compilerOptions));
|
|
50
54
|
return analyzeCoverage({
|
|
51
55
|
cwd: options.cwd,
|
|
52
56
|
outDir: built.outDir,
|
|
@@ -55,6 +59,80 @@ export function exemptionsOf(options) {
|
|
|
55
59
|
program,
|
|
56
60
|
}).exempt;
|
|
57
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* The hash of each SMT-LIB problem the prover would send for each law now, rebuilt from the compiled code without
|
|
64
|
+
* running a solver. A certificate is for a law only while its problem hash is one of these.
|
|
65
|
+
*/
|
|
66
|
+
export function problemHashesOf(options, laws) {
|
|
67
|
+
const covered = coverFiles(options.cwd, readConfig(options.cwd).cover ?? []);
|
|
68
|
+
const built = build(options.compiler, [...new Set([...options.files, ...covered])], options.cwd);
|
|
69
|
+
const program = built.program ?? ts.createProgram(declarationFiles(built.outDir), withResolution(built.outDir, compilerOptions));
|
|
70
|
+
const sourceCwd = built.program === undefined ? undefined : options.cwd;
|
|
71
|
+
const hashes = new Map();
|
|
72
|
+
for (const law of laws) {
|
|
73
|
+
if (law.problems.length > 0)
|
|
74
|
+
continue;
|
|
75
|
+
try {
|
|
76
|
+
const types = typesOf(program, built.outDir, law, sourceCwd);
|
|
77
|
+
const texts = problemTexts({
|
|
78
|
+
law,
|
|
79
|
+
shapes: types.shapes,
|
|
80
|
+
jsFile: jsPath(built.outDir, law.file),
|
|
81
|
+
bound: options.bound,
|
|
82
|
+
timeoutMs: options.proofTimeoutMs,
|
|
83
|
+
holds: () => true,
|
|
84
|
+
});
|
|
85
|
+
hashes.set(lawKey(law.file, law.name), new Set(texts.map(hashOf)));
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// A law whose types cannot be read has no problem to match.
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return hashes;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* The certificates `tslaws accept` writes into the lock. The ones in the old lock stay only while their law and their
|
|
95
|
+
* problem are unchanged. The ones `tslaws check --certify` left in the sidecar file enter only after `verifyRecord`
|
|
96
|
+
* passes: the file is not trusted. Every record turned away is reported through `say`.
|
|
97
|
+
*/
|
|
98
|
+
export async function certificatesToAccept(options, laws, held, say) {
|
|
99
|
+
const fresh = readRecords(options.cwd);
|
|
100
|
+
const accepted = {};
|
|
101
|
+
if (Object.keys(held ?? {}).length === 0 && Object.keys(fresh).length === 0)
|
|
102
|
+
return accepted;
|
|
103
|
+
const now = new Map(laws.map((law) => [lawKey(law.file, law.name), lawHash(law)]));
|
|
104
|
+
const problems = problemHashesOf(options, laws);
|
|
105
|
+
const drop = (key, why) => say(`certificate dropped for ${key}: ${why}
|
|
106
|
+
`);
|
|
107
|
+
let toolsMissing = false;
|
|
108
|
+
// The sidecar file is only a candidate: its records enter after `verifyRecord` passes.
|
|
109
|
+
for (const [key, record] of Object.entries(fresh)) {
|
|
110
|
+
const hash = now.get(key);
|
|
111
|
+
if (hash === undefined)
|
|
112
|
+
continue;
|
|
113
|
+
const why = await verifyRecord(options.cwd, key, record, hash, problems.get(key) ?? new Set());
|
|
114
|
+
if (why === undefined)
|
|
115
|
+
accepted[key] = record;
|
|
116
|
+
else {
|
|
117
|
+
drop(key, why);
|
|
118
|
+
if (why.includes('binary was not found'))
|
|
119
|
+
toolsMissing = true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// A record the lock holds stays while its law and problem match, unless a verified fresh record replaced it, so a
|
|
123
|
+
// failed candidate never costs the lock a certificate that is still current.
|
|
124
|
+
for (const [key, record] of Object.entries(held ?? {})) {
|
|
125
|
+
if (accepted[key] !== undefined)
|
|
126
|
+
continue;
|
|
127
|
+
if (now.get(key) === record?.law && problems.get(key)?.has(bindingOf(record)))
|
|
128
|
+
accepted[key] = record;
|
|
129
|
+
else
|
|
130
|
+
drop(key, 'the law or its proof problem changed since it was certified');
|
|
131
|
+
}
|
|
132
|
+
if (toolsMissing)
|
|
133
|
+
say('no new certificates were recorded: cvc5 and Carcara are needed to check them again when accepting\n');
|
|
134
|
+
return accepted;
|
|
135
|
+
}
|
|
58
136
|
export async function check(options, enforceLock) {
|
|
59
137
|
// A proposal placed in .tslaws/proposals by hand may write its imports from the project root; store them where they resolve.
|
|
60
138
|
for (const file of options.files)
|
|
@@ -66,11 +144,19 @@ export async function check(options, enforceLock) {
|
|
|
66
144
|
const notices = [];
|
|
67
145
|
// The level of a laws file comes from its name (the default) or its imports (`levels: "imports"`); looked at once per file.
|
|
68
146
|
const config = readConfig(options.cwd);
|
|
147
|
+
configureJobs({ config: config.jobs });
|
|
69
148
|
const levelsMode = config.levels ?? 'names';
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
149
|
+
const certifyMode = options.certify ?? config.certify ?? false;
|
|
150
|
+
// The certificate each law proved this run got, or undefined when its proof was not certified.
|
|
151
|
+
const records = new Map();
|
|
152
|
+
// Who records a law in the lock: a person locally, or the tslaws workflow on merge when "github" is configured. A
|
|
153
|
+
// project that leaves "github.local" on lets a person accept by hand as well.
|
|
154
|
+
const github = readConfig(options.cwd).github;
|
|
155
|
+
const acceptor = github === undefined
|
|
156
|
+
? 'a person must run `tslaws accept`'
|
|
157
|
+
: parseGithubConfig(github).local
|
|
158
|
+
? 'a person can run `tslaws accept`, or the tslaws workflow accepts it when the pull request merges'
|
|
159
|
+
: 'it is accepted by the tslaws workflow when the pull request merges';
|
|
74
160
|
const verdicts = new Map();
|
|
75
161
|
const verdictOf = (file) => {
|
|
76
162
|
let verdict = verdicts.get(file);
|
|
@@ -124,6 +210,7 @@ export async function check(options, enforceLock) {
|
|
|
124
210
|
method,
|
|
125
211
|
...(extra.counterexample === undefined ? {} : { counterexample: extra.counterexample }),
|
|
126
212
|
...(extra.message === undefined ? {} : { message: extra.message }),
|
|
213
|
+
...(extra.certificate === undefined ? {} : { certificate: extra.certificate }),
|
|
127
214
|
},
|
|
128
215
|
...(exercises.length > 0 ? { exercises } : {}),
|
|
129
216
|
};
|
|
@@ -138,14 +225,21 @@ export async function check(options, enforceLock) {
|
|
|
138
225
|
lock = readLock(options.lockFile);
|
|
139
226
|
lockMissing = lock === undefined;
|
|
140
227
|
const byKey = new Map(laws.map((l) => [lawKey(l.file, l.name), l]));
|
|
141
|
-
// With levels from imports
|
|
228
|
+
// With levels from imports, the resolved level of each laws file is part of the lock. A lock that recorded levels
|
|
229
|
+
// while the project no longer resolves any (levels went back to names) is tampered until accepted again.
|
|
142
230
|
const levels = levelsMode === 'imports' || lock?.levels !== undefined
|
|
143
231
|
? {
|
|
144
232
|
locked: lock?.levels,
|
|
145
|
-
now:
|
|
233
|
+
now: levelsMode === 'imports'
|
|
234
|
+
? Object.fromEntries([...new Set(laws.map((l) => l.file.replaceAll('\\', '/')))].map((f) => [f, verdictOf(f).kind]))
|
|
235
|
+
: undefined,
|
|
146
236
|
}
|
|
147
237
|
: undefined;
|
|
148
|
-
|
|
238
|
+
// A lock from before the hashes covered helpers, imports and run settings: every law differs from it by the format.
|
|
239
|
+
const outdated = (lock?.version ?? lockFormat) < lockFormat;
|
|
240
|
+
if (outdated)
|
|
241
|
+
notices.push(`lock format upgraded: the lock was written in format ${lock?.version ?? 0} and tslaws now hashes helpers, imported code and run settings too (format ${lockFormat}); run \`tslaws accept\` to record the laws again`);
|
|
242
|
+
for (const violation of compareLock(lock?.laws, laws, levels, options.partial === true ? scopeOf(options.files) : undefined)) {
|
|
149
243
|
const law = byKey.get(violation.key);
|
|
150
244
|
if (law === undefined) {
|
|
151
245
|
const [file, name] = violation.key.split('::');
|
|
@@ -166,7 +260,9 @@ export async function check(options, enforceLock) {
|
|
|
166
260
|
? `law is not in the lock; ${acceptor}`
|
|
167
261
|
: violation.reason === 'level'
|
|
168
262
|
? `the level this laws file runs at (node, browser or e2e) changed since the lock was accepted; ${acceptor}`
|
|
169
|
-
:
|
|
263
|
+
: outdated
|
|
264
|
+
? `lock format upgraded: this lock hashes only the law's own text; ${acceptor} to record it in the new format`
|
|
265
|
+
: 'law changed since the lock was accepted',
|
|
170
266
|
});
|
|
171
267
|
}
|
|
172
268
|
}
|
|
@@ -177,13 +273,29 @@ export async function check(options, enforceLock) {
|
|
|
177
273
|
}
|
|
178
274
|
const covered = coverFiles(options.cwd, readConfig(options.cwd).cover ?? []);
|
|
179
275
|
const compiled = [...new Set([...options.files, ...covered])];
|
|
180
|
-
|
|
276
|
+
const nodeLaws = laws.filter((law) => law.problems.length === 0 && verdictOf(law.file).kind === 'node').length;
|
|
277
|
+
const runsHere = laws.filter((law) => law.problems.length === 0 && verdictOf(law.file).kind !== 'browser').length;
|
|
278
|
+
// The sandbox is on unless the person turned it off with `sandbox: false` (`--no-sandbox`), and a Node that cannot
|
|
279
|
+
// enforce it is an error here, never a quiet fallback. End-to-end laws are no exception: see `allowE2e`.
|
|
280
|
+
const sandboxed = runsHere > 0 && useSandbox(options);
|
|
281
|
+
if (sandboxed)
|
|
282
|
+
warmSandbox(options.cwd, nodeLaws);
|
|
283
|
+
else
|
|
284
|
+
warmWorkers(nodeLaws);
|
|
181
285
|
const built = build(options.compiler, compiled, options.cwd);
|
|
286
|
+
// What the sandbox may load: the build's output, what the seals of the laws cover (the lock digests the same files), and
|
|
287
|
+
// the packages the manifests declare. Reviewed once, after the build.
|
|
288
|
+
const sandbox = sandboxed
|
|
289
|
+
? new Sandbox(options.cwd, hostConfig(options.cwd, compiled, built.outDir, laws.filter((law) => law.problems.length === 0)))
|
|
290
|
+
: undefined;
|
|
182
291
|
// What the type checker works out is kept with the build it came from, so an unchanged project skips the checker.
|
|
183
292
|
const derived = derivedStore(options.cwd, built.key);
|
|
184
293
|
let programOf;
|
|
185
|
-
const program = () => (programOf ??=
|
|
294
|
+
const program = () => (programOf ??=
|
|
295
|
+
built.program ?? ts.createProgram(declarationFiles(built.outDir), withResolution(built.outDir, compilerOptions)));
|
|
186
296
|
const sourceCwd = built.program === undefined ? undefined : options.cwd;
|
|
297
|
+
// Compiled laws are CommonJS (see `build` in compile.ts): the one place a law is loaded, so `require` is unavoidable here
|
|
298
|
+
// (`import()` would cache the module for good, and a recompiled law must load again).
|
|
187
299
|
const require = createRequire(import.meta.url);
|
|
188
300
|
// Laws that run here (end to end) and the code they load read `import.meta.env` and extensionless imports as bundled.
|
|
189
301
|
prepareRuntime(lawEnv(options.cwd, 'node'));
|
|
@@ -220,10 +332,25 @@ export async function check(options, enforceLock) {
|
|
|
220
332
|
}
|
|
221
333
|
const browser = verdict.kind === 'browser';
|
|
222
334
|
const e2e = verdict.kind === 'e2e';
|
|
335
|
+
// An end-to-end law needs processes (a browser, the app's server) that the sandbox refuses, so it would run in this
|
|
336
|
+
// process with every permission it has. A law says for itself that it is end to end, so that is never taken as leave
|
|
337
|
+
// to do so: the person must ask for it.
|
|
338
|
+
if (e2e && sandboxed && options.allowE2e !== true) {
|
|
339
|
+
add(law, 'error', 'e2e', {
|
|
340
|
+
message: 'end-to-end laws run outside the sandbox, with full access to this machine; run them with --allow-e2e (allowE2e) ' +
|
|
341
|
+
'once you have reviewed them, or with --no-sandbox to turn the sandbox off',
|
|
342
|
+
});
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (e2e && sandboxed)
|
|
346
|
+
warnE2e();
|
|
223
347
|
const method = browser ? 'browser' : e2e ? 'e2e' : 'property';
|
|
224
348
|
let fn;
|
|
225
|
-
// A browser law touches the DOM when it loads, so only the browser loads it.
|
|
226
|
-
|
|
349
|
+
// A browser law touches the DOM when it loads, so only the browser loads it. A node law loads in its sandbox, not here
|
|
350
|
+
// (an end-to-end law runs in this process once `allowE2e` lets it: it drives a browser, which needs processes the
|
|
351
|
+
// sandbox refuses).
|
|
352
|
+
let isAsync = false;
|
|
353
|
+
if (!browser && (!sandboxed || e2e)) {
|
|
227
354
|
try {
|
|
228
355
|
fn = require(jsPath(built.outDir, law.file))[law.symbol ?? law.name];
|
|
229
356
|
}
|
|
@@ -235,7 +362,20 @@ export async function check(options, enforceLock) {
|
|
|
235
362
|
add(law, 'error', 'load', { message: 'compiled module does not export the law' });
|
|
236
363
|
return;
|
|
237
364
|
}
|
|
365
|
+
isAsync = fn.constructor.name === 'AsyncFunction';
|
|
238
366
|
}
|
|
367
|
+
// One property run of the law: in the sandbox, or in a worker of this process when it is off or the law is end to end.
|
|
368
|
+
const execute = async (runOptions) => {
|
|
369
|
+
if (!sandboxed || e2e)
|
|
370
|
+
return runLawGuarded(built.outDir, law, runOptions, types.plans);
|
|
371
|
+
if (sandbox === undefined)
|
|
372
|
+
throw new Error('the law sandbox is on but was not set up');
|
|
373
|
+
const ran = await sandbox.run(built.outDir, law, runOptions, types.plans);
|
|
374
|
+
if (ran === 'timeout')
|
|
375
|
+
return ran;
|
|
376
|
+
isAsync = ran.async;
|
|
377
|
+
return ran.outcome;
|
|
378
|
+
};
|
|
239
379
|
let details;
|
|
240
380
|
// Counterexamples found before are tried first.
|
|
241
381
|
let lawOptions = options.noRegressions
|
|
@@ -261,10 +401,13 @@ export async function check(options, enforceLock) {
|
|
|
261
401
|
jsFile: jsPath(built.outDir, law.file),
|
|
262
402
|
generators: types.generators,
|
|
263
403
|
}, lawOptions)
|
|
264
|
-
: await
|
|
404
|
+
: await execute(lawOptions);
|
|
265
405
|
}
|
|
266
406
|
catch (error) {
|
|
267
|
-
|
|
407
|
+
if (error instanceof LawLoadError)
|
|
408
|
+
add(law, 'error', 'load', { message: `cannot load compiled law: ${error.message}` });
|
|
409
|
+
else
|
|
410
|
+
add(law, 'error', method, { message: error.message });
|
|
268
411
|
return;
|
|
269
412
|
}
|
|
270
413
|
if (details === 'timeout') {
|
|
@@ -299,7 +442,7 @@ export async function check(options, enforceLock) {
|
|
|
299
442
|
return;
|
|
300
443
|
}
|
|
301
444
|
// Browser and async laws are tested, never proved: the prover cannot model a DOM or an await.
|
|
302
|
-
const unprovable = browser || e2e ? 'runs in a browser' :
|
|
445
|
+
const unprovable = browser || e2e ? 'runs in a browser' : isAsync ? 'is async' : undefined;
|
|
303
446
|
if (options.noProve || unprovable !== undefined) {
|
|
304
447
|
add(law, law.proved ? 'open' : 'tested', method, {
|
|
305
448
|
runs: details.numRuns,
|
|
@@ -313,6 +456,10 @@ export async function check(options, enforceLock) {
|
|
|
313
456
|
return;
|
|
314
457
|
}
|
|
315
458
|
const holds = (inputs) => {
|
|
459
|
+
if (sandboxed && sandbox === undefined)
|
|
460
|
+
return false;
|
|
461
|
+
if (sandbox !== undefined)
|
|
462
|
+
return sandbox.holds(built.outDir, law, inputs, limitMs);
|
|
316
463
|
try {
|
|
317
464
|
return fn(...inputs) !== false;
|
|
318
465
|
}
|
|
@@ -328,12 +475,33 @@ export async function check(options, enforceLock) {
|
|
|
328
475
|
timeoutMs: options.proofTimeoutMs,
|
|
329
476
|
holds,
|
|
330
477
|
solvers: config.solvers,
|
|
478
|
+
certify: certifyMode === false
|
|
479
|
+
? undefined
|
|
480
|
+
: { mode: certifyMode, dir: join(options.cwd, '.tslaws', 'certificates'), root: options.cwd },
|
|
331
481
|
});
|
|
482
|
+
const certified = (certificate) => certificate === undefined ? {} : { certificate };
|
|
332
483
|
const assumed = (list) => (list.length > 0 ? { assumptions: list } : {});
|
|
484
|
+
if (proof.kind === 'proved' || proof.kind === 'bounded') {
|
|
485
|
+
// With certifying on, every proof has a certificate; one that is missing counts as uncertified, so `require`
|
|
486
|
+
// cannot pass a proof nobody checked.
|
|
487
|
+
if (certifyMode !== false)
|
|
488
|
+
proof.certificate ??= noCertificate;
|
|
489
|
+
if (proof.certificate !== undefined) {
|
|
490
|
+
records.set(lawKey(law.file, law.name), recordOf(lawHash(law), proof.certificate));
|
|
491
|
+
const required = certificateFailure(certifyMode, proof.certificate);
|
|
492
|
+
if (required !== undefined) {
|
|
493
|
+
add(law, 'error', 'smt', { certificate: proof.certificate, message: required });
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
// A lock certificate for a different problem than the one proved now no longer vouches for the law.
|
|
497
|
+
if (lock !== undefined && staleRecord(lock.certificates?.[lawKey(law.file, law.name)], proof.certificate))
|
|
498
|
+
notices.push(`${lawKey(law.file, law.name)}: the certificate in the lock is for a different proof problem; run \`tslaws accept --certify\` to record the new one`);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
333
501
|
if (proof.kind === 'proved') {
|
|
334
502
|
// The property run above used generators inside the proved domain; a short one is topped up before the proof stands.
|
|
335
503
|
const passed = details;
|
|
336
|
-
const rerun = (runs) =>
|
|
504
|
+
const rerun = (runs) => execute({ ...lawOptions, runs, seed: passed.seed });
|
|
337
505
|
let disagrees;
|
|
338
506
|
try {
|
|
339
507
|
disagrees = await crossCheck(details, types.plans.length, rerun);
|
|
@@ -358,7 +526,12 @@ export async function check(options, enforceLock) {
|
|
|
358
526
|
});
|
|
359
527
|
}
|
|
360
528
|
else
|
|
361
|
-
add(law, 'proved', 'smt', {
|
|
529
|
+
add(law, 'proved', 'smt', {
|
|
530
|
+
runs: details.numRuns,
|
|
531
|
+
seed: details.seed,
|
|
532
|
+
...assumed(proof.assumptions),
|
|
533
|
+
...certified(proof.certificate),
|
|
534
|
+
});
|
|
362
535
|
}
|
|
363
536
|
else if (proof.kind === 'bounded') {
|
|
364
537
|
// `law proved` promises every input; a bounded proof is the most Z3 could show.
|
|
@@ -375,6 +548,7 @@ export async function check(options, enforceLock) {
|
|
|
375
548
|
seed: details.seed,
|
|
376
549
|
message,
|
|
377
550
|
...assumed(proof.assumptions),
|
|
551
|
+
...certified(proof.certificate),
|
|
378
552
|
});
|
|
379
553
|
}
|
|
380
554
|
else if (proof.kind === 'error')
|
|
@@ -400,8 +574,9 @@ export async function check(options, enforceLock) {
|
|
|
400
574
|
nextToFlush += 1;
|
|
401
575
|
}
|
|
402
576
|
};
|
|
403
|
-
//
|
|
404
|
-
|
|
577
|
+
// Every law takes a slot of the process-wide CPU budget, and what it starts (a proof, a solver, a law process) runs on
|
|
578
|
+
// that slot. Browser and end-to-end laws also share one page and one server, so they queue for it first.
|
|
579
|
+
const page = new Semaphore(1);
|
|
405
580
|
await Promise.all(laws.map(async (law, index) => {
|
|
406
581
|
const skipped = (options.only !== undefined && !options.only.includes(law.name)) || blocked.has(lawKey(law.file, law.name));
|
|
407
582
|
if (skipped) {
|
|
@@ -409,8 +584,8 @@ export async function check(options, enforceLock) {
|
|
|
409
584
|
flush();
|
|
410
585
|
return;
|
|
411
586
|
}
|
|
412
|
-
const
|
|
413
|
-
await
|
|
587
|
+
const inSlot = () => budget.run(() => runOne(law, index));
|
|
588
|
+
await (verdictOf(law.file).kind !== 'node' ? page.run(inSlot) : inSlot());
|
|
414
589
|
}));
|
|
415
590
|
if (enforceLock) {
|
|
416
591
|
const coverage = derived.coverage(() => analyzeCoverage({
|
|
@@ -448,6 +623,15 @@ export async function check(options, enforceLock) {
|
|
|
448
623
|
}
|
|
449
624
|
await closeBrowser();
|
|
450
625
|
await stopServer();
|
|
626
|
+
// Records for `tslaws accept` to consider; a law that did not end proved or bounded keeps no certificate.
|
|
627
|
+
if (certifyMode !== false && enforceLock && records.size > 0) {
|
|
628
|
+
// A law the lock does not record yet is reported `tampered`; its proof counts through the proposal it carries.
|
|
629
|
+
const held = new Set(results.filter((r) => proofStatus(r) !== undefined).map((r) => lawKey(r.file, r.name)));
|
|
630
|
+
for (const key of records.keys())
|
|
631
|
+
if (!held.has(key))
|
|
632
|
+
records.set(key, undefined);
|
|
633
|
+
writeRecords(options.cwd, records);
|
|
634
|
+
}
|
|
451
635
|
const ok = built.ok &&
|
|
452
636
|
!lockMissing &&
|
|
453
637
|
results.every((r) => r.status === 'proved' || r.status === 'bounded' || r.status === 'tested');
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { CheckReport } from './check.ts';
|
|
2
|
+
export declare function totals(report: CheckReport): string;
|
|
1
3
|
export declare function watched(filename: string | null): boolean;
|
|
2
4
|
/** What a command needs from its caller. `home` is for unit tests; the CLI never sets it. */
|
|
3
5
|
export interface CommandContext {
|