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/read-only-hpack.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Generated from templates/npm/read-only-hpack.mjs by lawspec-dev generate. Do not edit.
|
|
3
|
-
import {
|
|
4
|
-
if (process.argv.some(
|
|
5
|
-
console.log(
|
|
6
|
-
else if (!readdirSync(process.cwd()).some(
|
|
3
|
+
import {readdirSync} from 'node:fs';
|
|
4
|
+
if (process.argv.some(a => a === '--numeric-version' || a === '--version'))
|
|
5
|
+
console.log('0.38.1');
|
|
6
|
+
else if (!readdirSync(process.cwd()).some(f => f.endsWith('.cabal')))
|
|
7
|
+
{
|
|
7
8
|
console.error(
|
|
8
|
-
|
|
9
|
+
'LawSpec doctor requires an existing .cabal file. Run stack build --test --no-run-tests first.',
|
|
9
10
|
);
|
|
10
11
|
process.exitCode = 1;
|
|
11
12
|
}
|
package/scala-build-state.mjs
CHANGED
|
@@ -1,59 +1,149 @@
|
|
|
1
1
|
// Generated from templates/npm/scala-build-state.mjs by lawspec-dev generate. Do not edit.
|
|
2
2
|
// Preserve failed compiler state before an adapter restore or another build
|
|
3
3
|
// changes it. These diagnostics are not completed native execution evidence.
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
mkdir,
|
|
6
|
+
readFile,
|
|
7
|
+
readdir,
|
|
8
|
+
realpath,
|
|
9
|
+
stat,
|
|
10
|
+
writeFile,
|
|
11
|
+
} from 'node:fs/promises';
|
|
5
12
|
import {randomUUID} from 'node:crypto';
|
|
6
13
|
import path from 'node:path';
|
|
7
14
|
|
|
8
15
|
export const isScalaCompilationFailure = output =>
|
|
9
|
-
/error compiling project|compilation failed|unexpected error when (?:compiling|copying)/i.test(
|
|
16
|
+
/error compiling project|compilation failed|unexpected error when (?:compiling|copying)/i.test(
|
|
17
|
+
output,
|
|
18
|
+
);
|
|
10
19
|
|
|
11
|
-
export async function captureScalaBuildFailure({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
export async function captureScalaBuildFailure({
|
|
21
|
+
root,
|
|
22
|
+
command,
|
|
23
|
+
args,
|
|
24
|
+
output,
|
|
25
|
+
phase = 'native',
|
|
26
|
+
})
|
|
27
|
+
{
|
|
28
|
+
try
|
|
29
|
+
{
|
|
30
|
+
root = await realpath(root);
|
|
31
|
+
if (!(await stat(root)).isDirectory()) return null;
|
|
32
|
+
const directory = path.join(
|
|
33
|
+
root,
|
|
34
|
+
'.lawspec',
|
|
35
|
+
'scala-build-failures',
|
|
36
|
+
randomUUID(),
|
|
37
|
+
);
|
|
38
|
+
await mkdir(directory, {recursive: true});
|
|
39
|
+
const inventory = [],
|
|
40
|
+
configurations = [],
|
|
41
|
+
errors = [];
|
|
42
|
+
const build = path.join(root, '.scala-build');
|
|
43
|
+
async function visit(folder)
|
|
44
|
+
{
|
|
45
|
+
const entries = await readdir(folder, {withFileTypes: true}).catch(
|
|
46
|
+
error =>
|
|
47
|
+
{
|
|
48
|
+
if (error.code !== 'ENOENT')
|
|
49
|
+
errors.push({path: path.relative(root, folder), code: error.code});
|
|
50
|
+
return [];
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
for (const entry of entries.sort((a, b) =>
|
|
54
|
+
a.name.localeCompare(b.name),
|
|
55
|
+
))
|
|
56
|
+
{
|
|
57
|
+
const file = path.join(folder, entry.name),
|
|
58
|
+
relative = path.relative(root, file);
|
|
26
59
|
// A symlink may point to another client's output or outside this
|
|
27
60
|
// project. Record its presence without walking through it.
|
|
28
|
-
if(entry.isSymbolicLink())
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const info=await stat(file).catch(error=>{errors.push({path:relative,code:error.code});return null;});
|
|
33
|
-
if(info)inventory.push({path:relative,bytes:info.size,modified:info.mtime.toISOString()});
|
|
61
|
+
if (entry.isSymbolicLink())
|
|
62
|
+
{
|
|
63
|
+
inventory.push({path: relative, kind: 'symlink'});
|
|
64
|
+
continue;
|
|
34
65
|
}
|
|
35
|
-
if(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
66
|
+
if (entry.isDirectory())
|
|
67
|
+
{
|
|
68
|
+
await visit(file);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (!entry.isFile()) continue;
|
|
72
|
+
if (/\.(?:class|tasty|betasty|sig)$/.test(entry.name))
|
|
73
|
+
{
|
|
74
|
+
const info = await stat(file).catch(error =>
|
|
75
|
+
{
|
|
76
|
+
errors.push({path: relative, code: error.code});
|
|
77
|
+
return null;
|
|
78
|
+
});
|
|
79
|
+
if (info)
|
|
80
|
+
inventory.push({
|
|
81
|
+
path: relative,
|
|
82
|
+
bytes: info.size,
|
|
83
|
+
modified: info.mtime.toISOString(),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (
|
|
87
|
+
path.basename(folder) === '.bloop' &&
|
|
88
|
+
entry.name.endsWith('.json')
|
|
89
|
+
)
|
|
90
|
+
{
|
|
91
|
+
const raw = await readFile(file, 'utf8').catch(error =>
|
|
92
|
+
{
|
|
93
|
+
errors.push({path: relative, code: error.code});
|
|
94
|
+
return null;
|
|
95
|
+
});
|
|
96
|
+
if (raw !== null)
|
|
97
|
+
{
|
|
98
|
+
await writeFile(path.join(directory, entry.name), raw);
|
|
99
|
+
try
|
|
100
|
+
{
|
|
101
|
+
const {project} = JSON.parse(raw);
|
|
102
|
+
configurations.push({
|
|
103
|
+
file: relative,
|
|
104
|
+
name: project?.name,
|
|
105
|
+
directory: project?.directory,
|
|
106
|
+
workspaceDir: project?.workspaceDir,
|
|
107
|
+
classesDir: project?.classesDir,
|
|
108
|
+
sources: project?.sources,
|
|
109
|
+
dependencies: project?.dependencies,
|
|
110
|
+
classpath: project?.classpath,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
catch
|
|
114
|
+
{
|
|
115
|
+
errors.push({path: relative, code: 'invalid-json'});
|
|
116
|
+
}
|
|
45
117
|
}
|
|
46
118
|
}
|
|
47
119
|
}
|
|
48
120
|
}
|
|
49
121
|
await visit(build);
|
|
50
|
-
const lines=output.replace(/\x1b\[[0-9;]*m/g,'').split('\n');
|
|
51
|
-
const first=lines.findIndex(line
|
|
52
|
-
const state={
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
122
|
+
const lines = output.replace(/\x1b\[[0-9;]*m/g, '').split('\n');
|
|
123
|
+
const first = lines.findIndex(line => /\[error\]|error:/i.test(line));
|
|
124
|
+
const state = {
|
|
125
|
+
version: 1,
|
|
126
|
+
capturedAt: new Date().toISOString(),
|
|
127
|
+
root,
|
|
128
|
+
phase,
|
|
129
|
+
command,
|
|
130
|
+
args,
|
|
131
|
+
firstCompilerError:
|
|
132
|
+
first < 0 ? [] : lines.slice(Math.max(0, first - 2), first + 18),
|
|
133
|
+
configurations,
|
|
134
|
+
inventory,
|
|
135
|
+
errors,
|
|
136
|
+
};
|
|
137
|
+
await writeFile(
|
|
138
|
+
path.join(directory, 'state.json'),
|
|
139
|
+
JSON.stringify(state, null, 2) + '\n',
|
|
140
|
+
);
|
|
141
|
+
await writeFile(path.join(directory, 'compiler.log'), output);
|
|
57
142
|
return directory;
|
|
58
|
-
}
|
|
143
|
+
}
|
|
144
|
+
catch
|
|
145
|
+
{
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
// Capture failure must never replace the compiler result.
|
|
59
149
|
}
|
package/scala-coverage.mjs
CHANGED
|
@@ -2,55 +2,78 @@
|
|
|
2
2
|
// lawspec test --coverage on Scala: Scala 3 instruments the code itself
|
|
3
3
|
// (-coverage-out, in scoverage's format) and the scoverage reporter, which
|
|
4
4
|
// Scala CLI fetches, writes Cobertura, scoverage XML and HTML reports.
|
|
5
|
-
import {mkdir, readdir, writeFile} from
|
|
6
|
-
import {spawn} from
|
|
7
|
-
import path from
|
|
5
|
+
import {mkdir, readdir, writeFile} from 'node:fs/promises';
|
|
6
|
+
import {spawn} from 'node:child_process';
|
|
7
|
+
import path from 'node:path';
|
|
8
8
|
|
|
9
|
-
export const scoverageReporter =
|
|
9
|
+
export const scoverageReporter = '2.5.2';
|
|
10
10
|
|
|
11
11
|
// The report script, run by Scala CLI on its own (not as part of the project).
|
|
12
12
|
const reportScript = [
|
|
13
|
-
|
|
13
|
+
'//> using scala 3.9.0',
|
|
14
14
|
`//> using dep org.scoverage::scalac-scoverage-reporter:${scoverageReporter}`,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
15
|
+
'//> using javaOpt --sun-misc-unsafe-memory-access=allow',
|
|
16
|
+
'import java.io.File',
|
|
17
|
+
'import scoverage.reporter.{CoberturaXmlWriter, IOUtils, ScoverageHtmlWriter, ScoverageXmlWriter}',
|
|
18
|
+
'import scoverage.serialize.Serializer',
|
|
19
|
+
'',
|
|
20
|
+
'@main def report(data: String, sources: String, output: String): Unit = {',
|
|
21
|
+
' val dataDir = File(data)',
|
|
22
|
+
' val root = File(sources)',
|
|
23
|
+
' val coverage = Serializer.deserialize(Serializer.coverageFile(dataDir), root)',
|
|
24
|
+
' coverage.apply(IOUtils.invoked(IOUtils.findMeasurementFiles(dataDir).toIndexedSeq))',
|
|
25
|
+
' val out = File(output)',
|
|
26
|
+
' out.mkdirs()',
|
|
27
|
+
' CoberturaXmlWriter(Seq(root), out, None).write(coverage)',
|
|
28
|
+
' ScoverageXmlWriter(Seq(root), out, false, None).write(coverage)',
|
|
29
|
+
' ScoverageHtmlWriter(Seq(root), out, None).write(coverage)',
|
|
30
|
+
' println(f"Statement coverage: ${coverage.statementCoveragePercent}%.2f%%")',
|
|
31
|
+
'}',
|
|
32
|
+
'',
|
|
33
|
+
].join('\n');
|
|
33
34
|
|
|
34
35
|
// Where the instrumented runs write their data, under the coverage directory.
|
|
35
|
-
export function scalaCoverageData(directory)
|
|
36
|
-
|
|
36
|
+
export function scalaCoverageData(directory)
|
|
37
|
+
{
|
|
38
|
+
return path.join(directory, 'data');
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
// Writes the reports into directory from the runs' data; false when no run
|
|
40
42
|
// was measured.
|
|
41
|
-
export async function collectScalaCoverage({
|
|
43
|
+
export async function collectScalaCoverage({
|
|
44
|
+
root,
|
|
45
|
+
directory,
|
|
46
|
+
command = 'scala',
|
|
47
|
+
offline = false,
|
|
48
|
+
})
|
|
49
|
+
{
|
|
42
50
|
const data = scalaCoverageData(directory);
|
|
43
51
|
const files = await readdir(data).catch(() => []);
|
|
44
|
-
if (!files.includes(
|
|
45
|
-
const script = path.join(directory,
|
|
52
|
+
if (!files.includes('scoverage.coverage')) return false;
|
|
53
|
+
const script = path.join(directory, 'reporter', 'Report.scala');
|
|
46
54
|
await mkdir(path.dirname(script), {recursive: true});
|
|
47
55
|
await writeFile(script, reportScript);
|
|
48
|
-
const args = [
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
56
|
+
const args = [
|
|
57
|
+
'run',
|
|
58
|
+
...(offline ? ['--offline'] : []),
|
|
59
|
+
script,
|
|
60
|
+
'--',
|
|
61
|
+
data,
|
|
62
|
+
root,
|
|
63
|
+
path.join(directory, 'report'),
|
|
64
|
+
];
|
|
65
|
+
const status = await new Promise((resolve, reject) =>
|
|
66
|
+
{
|
|
67
|
+
const child = spawn(command, args, {
|
|
68
|
+
cwd: path.dirname(script),
|
|
69
|
+
stdio: ['ignore', 'inherit', 'inherit'],
|
|
70
|
+
});
|
|
71
|
+
child.on('error', reject);
|
|
72
|
+
child.on('close', resolve);
|
|
53
73
|
});
|
|
54
|
-
if (status !== 0)
|
|
74
|
+
if (status !== 0)
|
|
75
|
+
throw new Error(
|
|
76
|
+
`the scoverage reporter failed (${command} ${args.join(' ')})`,
|
|
77
|
+
);
|
|
55
78
|
return true;
|
|
56
79
|
}
|
package/scalars.mjs
CHANGED
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
// Generated from templates/npm/scalars.mjs by lawspec-dev generate. Do not edit.
|
|
2
2
|
// Human-readable, lossless API v2 scalar display.
|
|
3
|
-
export function showScalar(v)
|
|
4
|
-
|
|
3
|
+
export function showScalar(v)
|
|
4
|
+
{
|
|
5
|
+
if (!v || typeof v !== 'object')
|
|
6
|
+
throw new TypeError('Expected an API v2 scalar');
|
|
5
7
|
if ('coefficient' in v) return `${v.coefficient}e${v.exponent}`;
|
|
6
8
|
if ('numerator' in v) return `rational(${v.numerator}, ${v.denominator})`;
|
|
7
|
-
if ('bits' in v)
|
|
8
|
-
|
|
9
|
-
if ('
|
|
10
|
-
|
|
11
|
-
if (
|
|
9
|
+
if ('bits' in v)
|
|
10
|
+
return `${v.type === 'Float32' ? 'float32Bits' : 'float64Bits'}(${JSON.stringify(v.bits)})`;
|
|
11
|
+
if ('real' in v)
|
|
12
|
+
return `${v.type}(${showScalar(v.real)}, ${showScalar(v.imaginary)})`;
|
|
13
|
+
if ('units' in v)
|
|
14
|
+
return v.type === 'Text'
|
|
15
|
+
? JSON.stringify(v.units.map(c => String.fromCodePoint(c)).join(''))
|
|
16
|
+
: `${v.type}([${v.units.join(', ')}])`;
|
|
17
|
+
if (v.type === 'Symbol')
|
|
18
|
+
return `symbol(${JSON.stringify(v.id)}, ${JSON.stringify(v.description)})`;
|
|
19
|
+
if (v.type === 'Optional' || v.type === 'Nullable')
|
|
20
|
+
return v.value === null
|
|
21
|
+
? v.type === 'Optional'
|
|
22
|
+
? 'undefined'
|
|
23
|
+
: 'null'
|
|
24
|
+
: `${v.type.toLowerCase()}(${showScalar(v.value)})`;
|
|
12
25
|
if ('value' in v) return String(v.value);
|
|
13
|
-
return
|
|
26
|
+
return (
|
|
27
|
+
{Unit: 'unitValue', Null: 'null', Undefined: 'undefined'}[v.type] ?? v.type
|
|
28
|
+
);
|
|
14
29
|
}
|