@bytewaveco/pudding 0.0.0-stage → 0.1.0-beta.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/LICENSE +21 -0
- package/README.md +363 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +143 -0
- package/dist/crosscheck.d.ts +63 -0
- package/dist/crosscheck.js +164 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +72 -0
- package/dist/install.d.ts +25 -0
- package/dist/install.js +192 -0
- package/dist/ir.d.ts +93 -0
- package/dist/ir.js +331 -0
- package/dist/lean.d.ts +56 -0
- package/dist/lean.js +438 -0
- package/dist/report.d.ts +7 -0
- package/dist/report.js +74 -0
- package/dist/runner.d.ts +79 -0
- package/dist/runner.js +672 -0
- package/dist/search.d.ts +24 -0
- package/dist/search.js +137 -0
- package/dist/translate.d.ts +247 -0
- package/dist/translate.js +1938 -0
- package/dist/vitest.d.ts +8 -0
- package/dist/vitest.js +96 -0
- package/package.json +77 -4
package/dist/vitest.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type Modifier = "run" | "skip" | "only" | "todo";
|
|
2
|
+
/**
|
|
3
|
+
* Whether Vitest is collecting a test file right now. The `VITEST` variable
|
|
4
|
+
* alone does not say so: every process a test starts inherits it.
|
|
5
|
+
*/
|
|
6
|
+
export declare function collecting(): boolean;
|
|
7
|
+
export declare function defineLaw(modifier: Modifier, name: string): void;
|
|
8
|
+
export declare function defineGroup(modifier: Exclude<Modifier, "todo">, name: string, body: () => void): void;
|
package/dist/vitest.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// The bridge to Vitest. When a law file is collected by Vitest, each law
|
|
2
|
+
// becomes a test whose result is the law's proof. Pudding runs once per file,
|
|
3
|
+
// when the file's first test starts.
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
import { describe as suite, expect as vitestExpect, test } from "vitest";
|
|
6
|
+
/** A whole file is proved in one run, and proving starts cold, so allow far longer than a unit test gets. */
|
|
7
|
+
const TIMEOUT_MS = 120_000;
|
|
8
|
+
const groups = [];
|
|
9
|
+
// Keyed by the file's task, which Vitest makes anew each time it collects the
|
|
10
|
+
// file, so a rerun in the same worker proves the file again.
|
|
11
|
+
const runs = new WeakMap();
|
|
12
|
+
function root() {
|
|
13
|
+
const worker = globalThis.__vitest_worker__;
|
|
14
|
+
return worker?.config?.root ?? process.cwd();
|
|
15
|
+
}
|
|
16
|
+
function proofs(file) {
|
|
17
|
+
let pending = runs.get(file);
|
|
18
|
+
if (!pending) {
|
|
19
|
+
pending = import("./runner.js").then(({ run }) => run({ cwd: root(), lawFiles: [file.filepath] }));
|
|
20
|
+
runs.set(file, pending);
|
|
21
|
+
}
|
|
22
|
+
return pending;
|
|
23
|
+
}
|
|
24
|
+
const path = (task) => (task.suite && task.suite !== task.file ? [...path(task.suite), task.name] : [task.name]);
|
|
25
|
+
const tests = (task) => (task.tasks ?? []).flatMap(child => (child.type === "test" ? [child] : tests(child)));
|
|
26
|
+
/**
|
|
27
|
+
* Whether Vitest is collecting a test file right now. The `VITEST` variable
|
|
28
|
+
* alone does not say so: every process a test starts inherits it.
|
|
29
|
+
*/
|
|
30
|
+
export function collecting() {
|
|
31
|
+
try {
|
|
32
|
+
return typeof vitestExpect.getState().testPath === "string";
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** An error that reads like Pudding's own report and points at the line in the law file. */
|
|
39
|
+
function failure(entry) {
|
|
40
|
+
const lines = [];
|
|
41
|
+
for (const finding of entry.findings) {
|
|
42
|
+
lines.push(finding.message);
|
|
43
|
+
if (finding.text)
|
|
44
|
+
lines.push(` ${finding.text}`);
|
|
45
|
+
if (finding.inputs && Object.keys(finding.inputs).length) {
|
|
46
|
+
lines.push(` with ${Object.entries(finding.inputs).map(([name, value]) => `${name} = ${value}`).join(", ")}`);
|
|
47
|
+
}
|
|
48
|
+
if (finding.detail)
|
|
49
|
+
lines.push(...finding.detail.split("\n").map(line => ` ${line}`));
|
|
50
|
+
}
|
|
51
|
+
const error = new Error(lines.join("\n"));
|
|
52
|
+
error.name = "LawFailed";
|
|
53
|
+
const at = entry.findings[0] ?? entry;
|
|
54
|
+
error.stack = `${error.name}: ${error.message}\n at ${at.file}:${at.line}:${at.column}`;
|
|
55
|
+
return error;
|
|
56
|
+
}
|
|
57
|
+
export function defineLaw(modifier, name) {
|
|
58
|
+
if (modifier === "todo")
|
|
59
|
+
return void test.todo(name);
|
|
60
|
+
const full = [...groups, name].join(" > ");
|
|
61
|
+
const define = modifier === "skip" ? test.skip : modifier === "only" ? test.only : test;
|
|
62
|
+
define(name, async (context) => {
|
|
63
|
+
const task = context.task;
|
|
64
|
+
const report = await proofs(task.file);
|
|
65
|
+
if (report.errors.length)
|
|
66
|
+
throw new Error(report.errors.join("\n"));
|
|
67
|
+
// Laws are matched to the report by name, and by order among laws that share one.
|
|
68
|
+
const occurrence = tests(task.file).filter(other => path(other).join(" > ") === full).indexOf(task);
|
|
69
|
+
const entry = report.laws.filter(law => resolve(law.file) === resolve(task.file.filepath) && law.name === full)[occurrence];
|
|
70
|
+
if (!entry)
|
|
71
|
+
throw new Error(`Pudding did not read a law named "${full}" in this file`);
|
|
72
|
+
if (entry.status === "failed")
|
|
73
|
+
throw failure(entry);
|
|
74
|
+
const annotate = context.annotate;
|
|
75
|
+
if (annotate) {
|
|
76
|
+
if (entry.status === "checked")
|
|
77
|
+
await annotate.call(context, "executed for every input, not proved");
|
|
78
|
+
if (entry.status === "sampled")
|
|
79
|
+
await annotate.call(context, "executed on sampled inputs, not proved");
|
|
80
|
+
for (const note of entry.notes)
|
|
81
|
+
await annotate.call(context, note);
|
|
82
|
+
}
|
|
83
|
+
}, TIMEOUT_MS);
|
|
84
|
+
}
|
|
85
|
+
export function defineGroup(modifier, name, body) {
|
|
86
|
+
const define = modifier === "skip" ? suite.skip : modifier === "only" ? suite.only : suite;
|
|
87
|
+
define(name, () => {
|
|
88
|
+
groups.push(name);
|
|
89
|
+
try {
|
|
90
|
+
body();
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
groups.pop();
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,79 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bytewaveco/pudding",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0-beta.0",
|
|
4
|
+
"description": "Prove laws about existing TypeScript functions, with Lean doing the checking",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/bytewaveco/pudding.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/bytewaveco/pudding#readme",
|
|
11
|
+
"bugs": "https://github.com/bytewaveco/pudding/issues",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=24"
|
|
15
|
+
},
|
|
16
|
+
"bin": {
|
|
17
|
+
"pudding": "./dist/cli.js"
|
|
18
|
+
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./runner": {
|
|
25
|
+
"types": "./dist/runner.d.ts",
|
|
26
|
+
"default": "./dist/runner.js"
|
|
27
|
+
},
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"README.md",
|
|
33
|
+
"LICENSE"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public",
|
|
37
|
+
"tag": "beta"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -p tsconfig.build.json",
|
|
41
|
+
"typecheck": "tsc --noEmit",
|
|
42
|
+
"proof": "npm run build --silent && node dist/cli.js",
|
|
43
|
+
"test": "npm run build --silent && node --test test/*.test.ts",
|
|
44
|
+
"prepack": "npm run build --silent",
|
|
45
|
+
"test:package": "npm run build --silent && node scripts/smoke-package.mjs",
|
|
46
|
+
"fuzz": "npm run build --silent && node scripts/fuzz.mjs",
|
|
47
|
+
"pack:runtime": "npm run build --silent && node scripts/pack-runtime.mjs"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"typescript": "7.0.2"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"vitest": ">=3"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"vitest": {
|
|
57
|
+
"optional": true
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@types/node": "^26.6.6",
|
|
62
|
+
"vitest": "^5.1.1"
|
|
63
|
+
},
|
|
64
|
+
"keywords": [
|
|
65
|
+
"typescript",
|
|
66
|
+
"proof",
|
|
67
|
+
"lean",
|
|
68
|
+
"verification",
|
|
69
|
+
"laws",
|
|
70
|
+
"property",
|
|
71
|
+
"testing"
|
|
72
|
+
],
|
|
73
|
+
"optionalDependencies": {
|
|
74
|
+
"@bytewaveco/pudding-lean-darwin-arm64": "4.36.0",
|
|
75
|
+
"@bytewaveco/pudding-lean-darwin-x64": "4.36.0",
|
|
76
|
+
"@bytewaveco/pudding-lean-linux-arm64": "4.36.0",
|
|
77
|
+
"@bytewaveco/pudding-lean-linux-x64": "4.36.0"
|
|
78
|
+
}
|
|
79
|
+
}
|