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.
Files changed (79) hide show
  1. package/CHANGELOG.md +89 -2
  2. package/README.md +85 -9
  3. package/api.mjs +14 -9
  4. package/authoring.mjs +899 -0
  5. package/beam-coverage.mjs +190 -65
  6. package/beam-doctor.mjs +343 -124
  7. package/bin/lawspec.mjs +1949 -661
  8. package/build.json +134 -128
  9. package/component-packages.mjs +662 -176
  10. package/component.d.ts +82 -20
  11. package/component.mjs +317 -94
  12. package/core.wasm +2 -2
  13. package/core_jsffi.js +5 -5
  14. package/doctor.mjs +558 -299
  15. package/examples-command.mjs +44 -23
  16. package/failure-database.mjs +60 -17
  17. package/files.mjs +122 -62
  18. package/index.d.ts +585 -312
  19. package/input-files.mjs +90 -25
  20. package/launcher.mjs +72 -31
  21. package/learn/coverage.json +184 -112
  22. package/learn/curriculum.json +4 -1
  23. package/learn/vendor/fantomas/{LawSpec.Learn.Formatter.5arcua4vy0.wasm → LawSpec.Learn.Formatter.poiijdbsl9.wasm} +0 -0
  24. package/learn/vendor/fantomas/dotnet.js +3 -3
  25. package/learn/vendor/manifest.json +4 -8
  26. package/lsp.mjs +444 -133
  27. package/mcp.mjs +250 -0
  28. package/native-evidence.mjs +668 -182
  29. package/native-examples.mjs +56 -19
  30. package/native-host.mjs +136 -42
  31. package/native-parsers/clojure.LICENSE +121 -0
  32. package/native-parsers/clojure.wasm +0 -0
  33. package/native-parsers/csharp.LICENSE +21 -0
  34. package/native-parsers/csharp.wasm +0 -0
  35. package/native-parsers/elixir.LICENSE +176 -0
  36. package/native-parsers/elixir.wasm +0 -0
  37. package/native-parsers/erlang.LICENSE +201 -0
  38. package/native-parsers/erlang.wasm +0 -0
  39. package/native-parsers/fsharp.LICENSE +21 -0
  40. package/native-parsers/fsharp.wasm +0 -0
  41. package/native-parsers/gleam.LICENSE +202 -0
  42. package/native-parsers/gleam.wasm +0 -0
  43. package/native-parsers/go.LICENSE +21 -0
  44. package/native-parsers/go.wasm +0 -0
  45. package/native-parsers/groovy.LICENSE +21 -0
  46. package/native-parsers/groovy.wasm +0 -0
  47. package/native-parsers/haskell.LICENSE +21 -0
  48. package/native-parsers/haskell.wasm +0 -0
  49. package/native-parsers/java.LICENSE +21 -0
  50. package/native-parsers/java.wasm +0 -0
  51. package/native-parsers/javascript.LICENSE +21 -0
  52. package/native-parsers/javascript.wasm +0 -0
  53. package/native-parsers/kotlin.LICENSE +9 -0
  54. package/native-parsers/kotlin.wasm +0 -0
  55. package/native-parsers/lock.json +114 -0
  56. package/native-parsers/prolog.LICENSE +21 -0
  57. package/native-parsers/prolog.wasm +0 -0
  58. package/native-parsers/python.LICENSE +21 -0
  59. package/native-parsers/python.wasm +0 -0
  60. package/native-parsers/rust.LICENSE +21 -0
  61. package/native-parsers/rust.wasm +0 -0
  62. package/native-parsers/scala.LICENSE +21 -0
  63. package/native-parsers/scala.wasm +0 -0
  64. package/native-parsers/swift.LICENSE +21 -0
  65. package/native-parsers/swift.wasm +0 -0
  66. package/native-parsers/typescript.LICENSE +21 -0
  67. package/native-parsers/typescript.wasm +0 -0
  68. package/node-events-reporter.mjs +41 -17
  69. package/package.json +4 -3
  70. package/project.mjs +338 -0
  71. package/proof.d.ts +93 -19
  72. package/proof.mjs +1538 -447
  73. package/read-only-hpack.mjs +6 -5
  74. package/scala-build-state.mjs +131 -41
  75. package/scala-coverage.mjs +57 -34
  76. package/scalars.mjs +23 -8
  77. package/templates.mjs +566 -617
  78. package/test-command.mjs +1671 -521
  79. package/learn/vendor/fantomas/LawSpec.Learn.Formatter.u1ne3a6xd2.wasm +0 -0
@@ -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 { 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"))) {
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
- "LawSpec doctor requires an existing .cabal file. Run stack build --test --no-run-tests first.",
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
  }
@@ -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 {mkdir,readFile,readdir,realpath,stat,writeFile} from 'node:fs/promises';
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(output);
16
+ /error compiling project|compilation failed|unexpected error when (?:compiling|copying)/i.test(
17
+ output,
18
+ );
10
19
 
11
- export async function captureScalaBuildFailure({root,command,args,output,phase='native'}) {
12
- try {
13
- root=await realpath(root);
14
- if(!(await stat(root)).isDirectory())return null;
15
- const directory=path.join(root,'.lawspec','scala-build-failures',randomUUID());
16
- await mkdir(directory,{recursive:true});
17
- const inventory=[],configurations=[],errors=[];
18
- const build=path.join(root,'.scala-build');
19
- async function visit(folder) {
20
- const entries=await readdir(folder,{withFileTypes:true}).catch(error=>{
21
- if(error.code!=='ENOENT')errors.push({path:path.relative(root,folder),code:error.code});
22
- return [];
23
- });
24
- for(const entry of entries.sort((a,b)=>a.name.localeCompare(b.name))) {
25
- const file=path.join(folder,entry.name),relative=path.relative(root,file);
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()){inventory.push({path:relative,kind:'symlink'});continue;}
29
- if(entry.isDirectory()){await visit(file);continue;}
30
- if(!entry.isFile())continue;
31
- if(/\.(?:class|tasty|betasty|sig)$/.test(entry.name)) {
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(path.basename(folder)==='.bloop'&&entry.name.endsWith('.json')) {
36
- const raw=await readFile(file,'utf8').catch(error=>{errors.push({path:relative,code:error.code});return null;});
37
- if(raw!==null) {
38
- await writeFile(path.join(directory,entry.name),raw);
39
- try {
40
- const {project}=JSON.parse(raw);
41
- configurations.push({file:relative,name:project?.name,directory:project?.directory,
42
- workspaceDir:project?.workspaceDir,classesDir:project?.classesDir,
43
- sources:project?.sources,dependencies:project?.dependencies,classpath:project?.classpath});
44
- }catch{errors.push({path:relative,code:'invalid-json'});}
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=>/\[error\]|error:/i.test(line));
52
- const state={version:1,capturedAt:new Date().toISOString(),root,phase,
53
- command,args,firstCompilerError:first<0?[]:lines.slice(Math.max(0,first-2),first+18),
54
- configurations,inventory,errors};
55
- await writeFile(path.join(directory,'state.json'),JSON.stringify(state,null,2)+'\n');
56
- await writeFile(path.join(directory,'compiler.log'),output);
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
- }catch{return null;} // Capture failure must never replace the compiler result.
143
+ }
144
+ catch
145
+ {
146
+ return null;
147
+ }
148
+ // Capture failure must never replace the compiler result.
59
149
  }
@@ -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 "node:fs/promises";
6
- import {spawn} from "node:child_process";
7
- import path from "node:path";
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 = "2.5.2";
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
- "//> using scala 3.9.0",
13
+ '//> using scala 3.9.0',
14
14
  `//> using dep org.scoverage::scalac-scoverage-reporter:${scoverageReporter}`,
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
- ""].join("\n");
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
- return path.join(directory, "data");
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({root, directory, command = "scala", offline = false}) {
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("scoverage.coverage")) return false;
45
- const script = path.join(directory, "reporter", "Report.scala");
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 = ["run", ...(offline ? ["--offline"] : []), script, "--", data, root, path.join(directory, "report")];
49
- const status = await new Promise((resolve, reject) => {
50
- const child = spawn(command, args, {cwd: path.dirname(script), stdio: ["ignore", "inherit", "inherit"]});
51
- child.on("error", reject);
52
- child.on("close", resolve);
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) throw new Error(`the scoverage reporter failed (${command} ${args.join(" ")})`);
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
- if (!v || typeof v !== 'object') throw new TypeError('Expected an API v2 scalar');
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) return `${v.type === 'Float32' ? 'float32Bits' : 'float64Bits'}(${JSON.stringify(v.bits)})`;
8
- if ('real' in v) return `${v.type}(${showScalar(v.real)}, ${showScalar(v.imaginary)})`;
9
- if ('units' in v) return v.type === 'Text' ? JSON.stringify(v.units.map(c => String.fromCodePoint(c)).join('')) : `${v.type}([${v.units.join(', ')}])`;
10
- if (v.type === 'Symbol') return `symbol(${JSON.stringify(v.id)}, ${JSON.stringify(v.description)})`;
11
- if (v.type === 'Optional' || v.type === 'Nullable') return v.value === null ? (v.type === 'Optional' ? 'undefined' : 'null') : `${v.type.toLowerCase()}(${showScalar(v.value)})`;
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 {Unit:'unitValue', Null:'null', Undefined:'undefined'}[v.type] ?? v.type;
26
+ return (
27
+ {Unit: 'unitValue', Null: 'null', Undefined: 'undefined'}[v.type] ?? v.type
28
+ );
14
29
  }