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/beam-coverage.mjs
CHANGED
|
@@ -1,17 +1,39 @@
|
|
|
1
1
|
// Generated from templates/npm/beam-coverage.mjs by lawspec-dev generate. Do not edit.
|
|
2
|
-
import {execFile} from
|
|
3
|
-
import {createHash} from
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import {execFile} from 'node:child_process';
|
|
3
|
+
import {createHash} from 'node:crypto';
|
|
4
|
+
import {
|
|
5
|
+
mkdir,
|
|
6
|
+
mkdtemp,
|
|
7
|
+
readFile,
|
|
8
|
+
readdir,
|
|
9
|
+
rm,
|
|
10
|
+
stat,
|
|
11
|
+
writeFile,
|
|
12
|
+
} from 'node:fs/promises';
|
|
13
|
+
import os from 'node:os';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
import {promisify} from 'node:util';
|
|
8
16
|
|
|
9
17
|
const exec = promisify(execFile);
|
|
10
|
-
export function beamCoverageRequirement(target, report)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
export function beamCoverageRequirement(target, report)
|
|
19
|
+
{
|
|
20
|
+
if (
|
|
21
|
+
target.language === 'gleam' &&
|
|
22
|
+
Number(report?.versions?.gleam?.split('.')[1] ?? 0) < 19
|
|
23
|
+
)
|
|
24
|
+
return {
|
|
25
|
+
tool: 'Gleam 1.19 for source coverage',
|
|
26
|
+
install:
|
|
27
|
+
'upgrade Gleam to 1.19 so native counters refer to the original source lines',
|
|
28
|
+
};
|
|
29
|
+
if (
|
|
30
|
+
target.language === 'elixir' &&
|
|
31
|
+
report?.coverage?.tool !== 'Mix.Tasks.Test.Coverage'
|
|
32
|
+
)
|
|
33
|
+
return {
|
|
34
|
+
tool: 'Mix.Tasks.Test.Coverage',
|
|
35
|
+
install: 'set test_coverage[:tool] to Mix.Tasks.Test.Coverage in mix.exs',
|
|
36
|
+
};
|
|
15
37
|
return null;
|
|
16
38
|
}
|
|
17
39
|
|
|
@@ -60,101 +82,204 @@ source(Module, Beam) ->
|
|
|
60
82
|
text(Value) -> unicode:characters_to_list(Value).
|
|
61
83
|
`;
|
|
62
84
|
|
|
63
|
-
const escape =
|
|
64
|
-
(
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
85
|
+
const escape = value =>
|
|
86
|
+
String(value).replace(
|
|
87
|
+
/[&<>"']/g,
|
|
88
|
+
c =>
|
|
89
|
+
({'&': '&', '<': '<', '>': '>', '"': '"', "'": '''})[
|
|
90
|
+
c
|
|
91
|
+
],
|
|
92
|
+
);
|
|
93
|
+
const totals = lines => ({
|
|
94
|
+
covered: lines.filter(({hits}) => hits > 0).length,
|
|
95
|
+
total: lines.length,
|
|
96
|
+
});
|
|
97
|
+
const percentage = ({covered, total}) =>
|
|
98
|
+
total ? `${((100 * covered) / total).toFixed(1)}%` : 'no executable lines';
|
|
99
|
+
const page = (
|
|
100
|
+
title,
|
|
101
|
+
body,
|
|
102
|
+
) => `<!doctype html><html lang="en"><meta charset="utf-8"><title>${escape(title)}</title>
|
|
68
103
|
<style>body{font:16px system-ui;margin:2rem;color:#222}table{border-collapse:collapse;width:100%}td,th{padding:.3rem .7rem;text-align:left;border-bottom:1px solid #ddd}pre{margin:0;tab-size:4}.hit{background:#e4f5e9}.miss{background:#ffe6e6}.line,.count{width:4rem;text-align:right;color:#555}a{color:#174da8}</style>
|
|
69
104
|
<h1>${escape(title)}</h1>${body}</html>\n`;
|
|
70
105
|
|
|
71
106
|
// Only exports explicitly returned by this run's invocations are imported.
|
|
72
107
|
// A missing export is an error even if the native runner exited successfully.
|
|
73
|
-
export async function collectBeamCoverage({root, directory, runs})
|
|
108
|
+
export async function collectBeamCoverage({root, directory, runs})
|
|
109
|
+
{
|
|
74
110
|
if (!runs.length) return null;
|
|
75
111
|
root = path.resolve(root);
|
|
76
112
|
directory = path.resolve(directory);
|
|
77
|
-
const temporary = await mkdtemp(
|
|
78
|
-
|
|
113
|
+
const temporary = await mkdtemp(
|
|
114
|
+
path.join(os.tmpdir(), 'lawspec-beam-coverage-'),
|
|
115
|
+
);
|
|
116
|
+
try
|
|
117
|
+
{
|
|
79
118
|
const inputs = [];
|
|
80
119
|
const seen = new Set();
|
|
81
120
|
let rebarDirectories;
|
|
82
|
-
for (const run of runs)
|
|
83
|
-
|
|
84
|
-
|
|
121
|
+
for (const run of runs)
|
|
122
|
+
{
|
|
123
|
+
if (
|
|
124
|
+
!run.run ||
|
|
125
|
+
seen.has(run.run) ||
|
|
126
|
+
path.basename(run.file) !== `${run.run}.coverdata`
|
|
127
|
+
)
|
|
128
|
+
throw new Error('Invalid or duplicate BEAM coverage invocation');
|
|
85
129
|
seen.add(run.run);
|
|
86
130
|
const info = await stat(run.file).catch(() => null);
|
|
87
|
-
if (!info?.isFile() || !info.size)
|
|
131
|
+
if (!info?.isFile() || !info.size)
|
|
132
|
+
throw new Error(
|
|
133
|
+
`Native runner did not export coverage for ${run.run}: ${run.file}`,
|
|
134
|
+
);
|
|
88
135
|
let beams;
|
|
89
|
-
if (run.tool ===
|
|
136
|
+
if (run.tool === 'rebar3' && !rebarDirectories)
|
|
137
|
+
{
|
|
90
138
|
// Before the first compile Rebar only knows dependency ebin paths.
|
|
91
139
|
// Ask after the test run so fresh and relocated applications are found.
|
|
92
|
-
const result = await exec(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
140
|
+
const result = await exec(
|
|
141
|
+
'rebar3',
|
|
142
|
+
['as', 'test', 'path', '--ebin', '--separator', '\n'],
|
|
143
|
+
{cwd: root},
|
|
144
|
+
);
|
|
145
|
+
rebarDirectories = result.stdout.trim().split('\n').filter(Boolean);
|
|
146
|
+
if (
|
|
147
|
+
!rebarDirectories.length ||
|
|
148
|
+
!rebarDirectories.every(item => path.isAbsolute(item))
|
|
149
|
+
)
|
|
150
|
+
throw new Error(
|
|
151
|
+
"Cannot resolve Rebar's application beam directories after coverage",
|
|
152
|
+
);
|
|
96
153
|
}
|
|
97
|
-
const directories =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
154
|
+
const directories =
|
|
155
|
+
run.tool === 'rebar3'
|
|
156
|
+
? rebarDirectories
|
|
157
|
+
: (run.beamDirectories ??
|
|
158
|
+
(run.beamDirectory ? [run.beamDirectory] : []));
|
|
159
|
+
for (const directory of directories)
|
|
160
|
+
{
|
|
161
|
+
const entries = (await readdir(directory)).filter(name =>
|
|
162
|
+
name.endsWith('.beam'),
|
|
163
|
+
);
|
|
164
|
+
beams = {
|
|
165
|
+
...beams,
|
|
166
|
+
...Object.fromEntries(
|
|
167
|
+
entries.map(name => [
|
|
168
|
+
name.slice(0, -5),
|
|
169
|
+
path.resolve(directory, name),
|
|
170
|
+
]),
|
|
171
|
+
),
|
|
172
|
+
};
|
|
102
173
|
}
|
|
103
|
-
if (run.metadata)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
174
|
+
if (run.metadata)
|
|
175
|
+
{
|
|
176
|
+
const metadata = JSON.parse(await readFile(run.metadata, 'utf8'));
|
|
177
|
+
if (
|
|
178
|
+
metadata.run !== run.run ||
|
|
179
|
+
metadata.file !== run.file ||
|
|
180
|
+
!metadata.modules?.length
|
|
181
|
+
)
|
|
182
|
+
throw new Error(
|
|
183
|
+
`Gleam coverage metadata does not match invocation ${run.run}`,
|
|
184
|
+
);
|
|
185
|
+
beams = Object.fromEntries(
|
|
186
|
+
metadata.modules.map(({name, beam}) => [name, beam]),
|
|
187
|
+
);
|
|
108
188
|
}
|
|
109
189
|
inputs.push({file: path.resolve(run.file), ...(beams ? {beams} : {})});
|
|
110
190
|
}
|
|
111
191
|
// Assemble all pages off to the side. A failed import or source mapping
|
|
112
192
|
// cannot leave an apparently complete index behind.
|
|
113
|
-
const pages = path.join(temporary,
|
|
193
|
+
const pages = path.join(temporary, 'modules');
|
|
114
194
|
await mkdir(pages);
|
|
115
|
-
const input = path.join(temporary,
|
|
116
|
-
|
|
195
|
+
const input = path.join(temporary, 'input.json'),
|
|
196
|
+
output = path.join(temporary, 'output.json');
|
|
197
|
+
const script = path.join(temporary, 'collect.escript');
|
|
117
198
|
await writeFile(script, collector);
|
|
118
199
|
await writeFile(input, JSON.stringify({runs: inputs, directory: pages}));
|
|
119
|
-
await exec(
|
|
120
|
-
|
|
121
|
-
|
|
200
|
+
await exec('escript', [script, input, output], {
|
|
201
|
+
cwd: root,
|
|
202
|
+
maxBuffer: 8 * 1024 * 1024,
|
|
203
|
+
});
|
|
204
|
+
const modules = JSON.parse(await readFile(output, 'utf8'));
|
|
205
|
+
for (const module of modules)
|
|
206
|
+
{
|
|
122
207
|
module.summary = totals(module.lines);
|
|
123
208
|
if (!module.source) continue;
|
|
124
209
|
let source = path.resolve(root, module.source);
|
|
125
|
-
const text = await readFile(source,
|
|
210
|
+
const text = await readFile(source, 'utf8');
|
|
126
211
|
// Gleam copies foreign Erlang sources into its build tree. Prefer the
|
|
127
212
|
// original when it is byte-for-byte the source that was compiled.
|
|
128
213
|
const marker = `${path.sep}_gleam_artefacts${path.sep}`;
|
|
129
|
-
if (source.includes(marker))
|
|
130
|
-
|
|
131
|
-
|
|
214
|
+
if (source.includes(marker))
|
|
215
|
+
{
|
|
216
|
+
const original = path.join(root, 'src', source.split(marker).at(-1));
|
|
217
|
+
if ((await readFile(original, 'utf8').catch(() => null)) === text)
|
|
218
|
+
source = original;
|
|
132
219
|
}
|
|
133
220
|
module.source = path.relative(root, source);
|
|
134
221
|
const sourceLines = text.split(/\r?\n/);
|
|
135
222
|
if (module.lines.some(({line}) => line > sourceLines.length))
|
|
136
223
|
throw new Error(`Coverage lines do not match source ${module.source}`);
|
|
137
224
|
const hits = new Map(module.lines.map(({line, hits}) => [line, hits]));
|
|
138
|
-
module.report =
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
225
|
+
module.report =
|
|
226
|
+
createHash('sha256').update(module.name).digest('hex') + '.html';
|
|
227
|
+
const rows = sourceLines
|
|
228
|
+
.map((line, index) =>
|
|
229
|
+
{
|
|
230
|
+
const count = hits.get(index + 1);
|
|
231
|
+
return `<tr class="${count === undefined ? '' : count ? 'hit' : 'miss'}" id="L${index + 1}"><td class="line">${index + 1}</td><td class="count">${count ?? ''}</td><td><pre>${escape(line)}</pre></td></tr>`;
|
|
232
|
+
})
|
|
233
|
+
.join('\n');
|
|
234
|
+
await writeFile(
|
|
235
|
+
path.join(pages, module.report),
|
|
236
|
+
page(
|
|
237
|
+
module.name,
|
|
238
|
+
`<p>${escape(module.source)} — ${percentage(module.summary)}</p><table>${rows}</table>`,
|
|
239
|
+
),
|
|
240
|
+
);
|
|
145
241
|
}
|
|
146
|
-
const summary = modules.reduce(
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
242
|
+
const summary = modules.reduce(
|
|
243
|
+
(sum, module) => ({
|
|
244
|
+
covered: sum.covered + module.summary.covered,
|
|
245
|
+
total: sum.total + module.summary.total,
|
|
246
|
+
}),
|
|
247
|
+
{covered: 0, total: 0},
|
|
248
|
+
);
|
|
249
|
+
const result = {
|
|
250
|
+
version: 1,
|
|
251
|
+
root,
|
|
252
|
+
runs: runs.map(({run}) => run),
|
|
253
|
+
summary,
|
|
254
|
+
modules,
|
|
255
|
+
};
|
|
256
|
+
const rows = modules
|
|
257
|
+
.map(
|
|
258
|
+
module =>
|
|
259
|
+
`<tr><td><a href="modules/${module.report}">${escape(module.name)}</a></td><td>${module.summary.covered}/${module.summary.total}</td><td>${percentage(module.summary)}</td></tr>`,
|
|
260
|
+
)
|
|
261
|
+
.join('\n');
|
|
262
|
+
await mkdir(path.join(directory, 'modules'), {recursive: true});
|
|
151
263
|
for (const module of modules)
|
|
152
|
-
await writeFile(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
264
|
+
await writeFile(
|
|
265
|
+
path.join(directory, 'modules', module.report),
|
|
266
|
+
await readFile(path.join(pages, module.report)),
|
|
267
|
+
);
|
|
268
|
+
await writeFile(
|
|
269
|
+
path.join(directory, 'coverage.json'),
|
|
270
|
+
JSON.stringify(result, null, 2) + '\n',
|
|
271
|
+
);
|
|
272
|
+
await writeFile(
|
|
273
|
+
path.join(directory, 'index.html'),
|
|
274
|
+
page(
|
|
275
|
+
'BEAM line coverage',
|
|
276
|
+
`<p>${summary.covered}/${summary.total} executable lines covered (${percentage(summary)}); ${runs.length} native run(s).</p><table><thead><tr><th>Module</th><th>Lines</th><th>Coverage</th></tr></thead><tbody>${rows}</tbody></table>`,
|
|
277
|
+
),
|
|
278
|
+
);
|
|
156
279
|
return result;
|
|
157
|
-
}
|
|
280
|
+
}
|
|
281
|
+
finally
|
|
282
|
+
{
|
|
158
283
|
await rm(temporary, {recursive: true, force: true});
|
|
159
284
|
}
|
|
160
285
|
}
|