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
package/input-files.mjs CHANGED
@@ -2,46 +2,111 @@
2
2
  // Native implementations may depend on declared files outside their target
3
3
  // directory. Component descriptions and native result keys share this walker.
4
4
  import {createHash} from 'node:crypto';
5
- import {lstat,readFile,readdir} from 'node:fs/promises';
5
+ import {lstat, readFile, readdir} from 'node:fs/promises';
6
6
  import path from 'node:path';
7
7
 
8
- export const buildDirectories = new Set(['.git','.lawspec','node_modules','dist','build','target','out','.gradle','bin','obj','TestResults',
9
- '.stack-work','_build','deps','.elixir_ls','__pycache__','.hypothesis','.pytest_cache','.venv','venv','.idea','.vscode',
10
- '.scala-build','.bsp','.bloop','.metals','.build','.swiftpm','.cpcache']);
8
+ export const buildDirectories = new Set([
9
+ '.git',
10
+ '.lawspec',
11
+ 'node_modules',
12
+ 'dist',
13
+ 'build',
14
+ 'target',
15
+ 'out',
16
+ '.gradle',
17
+ 'bin',
18
+ 'obj',
19
+ 'TestResults',
20
+ '.stack-work',
21
+ '_build',
22
+ 'deps',
23
+ '.elixir_ls',
24
+ '__pycache__',
25
+ '.hypothesis',
26
+ '.pytest_cache',
27
+ '.venv',
28
+ 'venv',
29
+ '.idea',
30
+ '.vscode',
31
+ '.scala-build',
32
+ '.bsp',
33
+ '.bloop',
34
+ '.metals',
35
+ '.build',
36
+ '.swiftpm',
37
+ '.cpcache',
38
+ ]);
11
39
 
12
40
  // These outputs belong to the generated crypto builder; its sources and
13
41
  // other priv/ assets still contribute to the native implementation identity.
14
- export const cryptoBuildOutput = file => /(?:^|\/)priv\/lawspec_crypto_native\.(?:so|dll)(?:\.build|\.\d+\.tmp)?$/.test(file);
42
+ export const cryptoBuildOutput = file =>
43
+ /(?:^|\/)priv\/lawspec_crypto_native\.(?:so|dll)(?:\.build|\.\d+\.tmp)?$/.test(
44
+ file,
45
+ );
15
46
 
16
47
  // Execution reports are observations, independent of implementation inputs.
17
48
  // ref:DEC-completed-run-attestation
18
- export function isAttestation(content) {
19
- try {
49
+ export function isAttestation(content)
50
+ {
51
+ try
52
+ {
20
53
  const value = JSON.parse(content);
21
- return value !== null && typeof value === 'object' && value.format === 'environment-attestation';
22
- } catch { return false; }
54
+ return (
55
+ value !== null &&
56
+ typeof value === 'object' &&
57
+ value.format === 'environment-attestation'
58
+ );
59
+ }
60
+ catch
61
+ {
62
+ return false;
63
+ }
23
64
  }
24
65
 
25
- export async function fingerprintInputs(root,inputs,{generated=new Set()}={}) {
26
- if(!Array.isArray(inputs)||inputs.some(entry=>typeof entry!=='string'||!entry))
66
+ export async function fingerprintInputs(
67
+ root,
68
+ inputs,
69
+ {generated = new Set()} = {},
70
+ )
71
+ {
72
+ if (
73
+ !Array.isArray(inputs) ||
74
+ inputs.some(entry => typeof entry !== 'string' || !entry)
75
+ )
27
76
  throw new Error('Component inputs must be an array of nonempty paths');
28
77
  const rows = new Map();
29
- async function visit(file,relative) {
78
+ async function visit(file, relative)
79
+ {
30
80
  const info = await lstat(file);
31
- if(info.isSymbolicLink())throw new Error(`Symbolic links are not supported in component inputs: ${relative}`);
32
- if(info.isDirectory()) {
33
- for(const entry of (await readdir(file)).sort()) {
34
- if(buildDirectories.has(entry))continue;
35
- const next=relative+'/'+entry;
36
- if(next.endsWith('testdata/rapid'))continue;
37
- await visit(path.join(file,entry),next);
81
+ if (info.isSymbolicLink())
82
+ throw new Error(
83
+ `Symbolic links are not supported in component inputs: ${relative}`,
84
+ );
85
+ if (info.isDirectory())
86
+ {
87
+ for (const entry of (await readdir(file)).sort())
88
+ {
89
+ if (buildDirectories.has(entry)) continue;
90
+ const next = relative + '/' + entry;
91
+ if (next.endsWith('testdata/rapid')) continue;
92
+ await visit(path.join(file, entry), next);
38
93
  }
39
- } else if(info.isFile()&&!generated.has(path.resolve(file))&&!cryptoBuildOutput(relative)) {
40
- const content=await readFile(file);
41
- if(relative.endsWith('.json')&&isAttestation(content.toString('utf8')))return;
42
- rows.set(relative,createHash('sha256').update(content).digest('hex'));
94
+ }
95
+ else if (
96
+ info.isFile() &&
97
+ !generated.has(path.resolve(file)) &&
98
+ !cryptoBuildOutput(relative)
99
+ )
100
+ {
101
+ const content = await readFile(file);
102
+ if (relative.endsWith('.json') && isAttestation(content.toString('utf8')))
103
+ return;
104
+ rows.set(relative, createHash('sha256').update(content).digest('hex'));
43
105
  }
44
106
  }
45
- for(const entry of inputs)await visit(path.resolve(root,entry),entry.split(path.sep).join('/'));
46
- return [...rows].sort(([left],[right])=>left<right?-1:left>right?1:0);
107
+ for (const entry of inputs)
108
+ await visit(path.resolve(root, entry), entry.split(path.sep).join('/'));
109
+ return [...rows].sort(([left], [right]) =>
110
+ left < right ? -1 : left > right ? 1 : 0,
111
+ );
47
112
  }
package/launcher.mjs CHANGED
@@ -1,20 +1,21 @@
1
1
  // Generated from templates/npm/launcher.mjs by lawspec-dev generate. Do not edit.
2
- import { mkdir, readFile } from "node:fs/promises";
3
- import { createHash } from "node:crypto";
4
- import path from "node:path";
2
+ import {mkdir, readFile} from 'node:fs/promises';
3
+ import {createHash} from 'node:crypto';
4
+ import path from 'node:path';
5
5
  let compiled;
6
6
 
7
7
  // GHC's JSFFI reactor reads these WASI arguments during initialization. Bound
8
8
  // the heap below wasm32's address ceiling and compact the oldest generation
9
9
  // in place instead of reserving a second copy near that ceiling.
10
10
  // -with-rtsopts has no effect on this -no-hs-main reactor build.
11
- const coreArguments = ["lawspec", "+RTS", "-M3584m", "-c", "-RTS"];
11
+ const coreArguments = ['lawspec', '+RTS', '-M3584m', '-c', '-RTS'];
12
12
 
13
13
  // Instantiate the compiler core with a platform's WASI preview1 imports and
14
14
  // serialize calls: the core handles one JSON request at a time.
15
- async function instantiateCore(module, wasiImports, initialize) {
15
+ async function instantiateCore(module, wasiImports, initialize)
16
+ {
16
17
  const exports = {};
17
- const jsffi = (await import("./core_jsffi.js")).default;
18
+ const jsffi = (await import('./core_jsffi.js')).default;
18
19
  const instance = await WebAssembly.instantiate(module, {
19
20
  wasi_snapshot_preview1: wasiImports,
20
21
  ghc_wasm_jsffi: jsffi(exports),
@@ -22,48 +23,88 @@ async function instantiateCore(module, wasiImports, initialize) {
22
23
  Object.assign(exports, instance.exports);
23
24
  initialize(instance);
24
25
  let pending = Promise.resolve();
25
- return (input) => {
26
+ return input =>
27
+ {
26
28
  const result = pending.then(async () =>
27
29
  JSON.parse(await instance.exports.lawspec_call(JSON.stringify(input))),
28
30
  );
29
31
  // The queue needs completion only, not the previous generated project DTO.
30
- pending = result.then(() => {}, () => {});
32
+ pending = result.then(
33
+ () =>
34
+ {},
35
+ () =>
36
+ {},
37
+ );
31
38
  return result;
32
39
  };
33
40
  }
34
41
 
35
- export async function loadCore() {
36
- const { WASI } = await import("node:wasi");
37
- if (Number(process.versions.node.split(".")[0]) < 22)
38
- throw new Error("LawSpec requires Node 22+");
39
- compiled ??= readFile(new URL("./core.wasm", import.meta.url)).then(async bytes => ({
40
- module: await WebAssembly.compile(bytes),
41
- build: createHash("sha256").update(bytes).digest("hex"),
42
- }));
43
- const {module,build}=await compiled;
42
+ export async function loadCore()
43
+ {
44
+ const {WASI} = await import('node:wasi');
45
+ if (Number(process.versions.node.split('.')[0]) < 22)
46
+ throw new Error('LawSpec requires Node 22+');
47
+ compiled ??= readFile(new URL('./core.wasm', import.meta.url)).then(
48
+ async bytes => ({
49
+ module: await WebAssembly.compile(bytes),
50
+ build: createHash('sha256').update(bytes).digest('hex'),
51
+ }),
52
+ );
53
+ const {module, build} = await compiled;
44
54
  let activeRoot, invoke;
45
- let pending=Promise.resolve();
46
- const request=async input=>{
47
- const validCache=typeof input.cacheDirectory==='string';
48
- let root=validCache&&input.cacheDirectory?path.resolve(input.cacheDirectory):null;
49
- if(root)try{await mkdir(root,{recursive:true});}catch{root=null;}
55
+ let pending = Promise.resolve();
56
+ const request = async input =>
57
+ {
58
+ const validCache = typeof input.cacheDirectory === 'string';
59
+ let root =
60
+ validCache && input.cacheDirectory
61
+ ? path.resolve(input.cacheDirectory)
62
+ : null;
63
+ if (root)
64
+ try
65
+ {
66
+ await mkdir(root, {recursive: true});
67
+ }
68
+ catch
69
+ {
70
+ root = null;
71
+ }
50
72
  // The requested host directory is an explicit mount, rather than an
51
73
  // absolute WASI path accidentally interpreted below cwd. The binary
52
74
  // identity separates persisted memos even within one package version.
53
- if(!invoke||root!==activeRoot){
75
+ if (!invoke || root !== activeRoot)
76
+ {
54
77
  const wasi = new WASI({
55
- version: "preview1", args: coreArguments, env: { PWD: "/" },
56
- preopens: { "/": process.cwd(), ...(root?{"/lawspec-cache":root}:{}) },
78
+ version: 'preview1',
79
+ args: coreArguments,
80
+ env: {PWD: '/'},
81
+ preopens: {
82
+ '/': process.cwd(),
83
+ ...(root ? {'/lawspec-cache': root} : {}),
84
+ },
57
85
  });
58
- invoke=await instantiateCore(module,wasi.wasiImport,instance=>wasi.initialize(instance));
59
- activeRoot=root;
86
+ invoke = await instantiateCore(module, wasi.wasiImport, instance =>
87
+ wasi.initialize(instance),
88
+ );
89
+ activeRoot = root;
60
90
  }
61
- return invoke({...input,...(validCache?{cacheDirectory:root?`/lawspec-cache/${build}`:undefined}:{})});
91
+ return invoke({
92
+ ...input,
93
+ ...(validCache
94
+ ? {cacheDirectory: root ? `/lawspec-cache/${build}` : undefined}
95
+ : {}),
96
+ });
62
97
  };
63
98
  // Cache-root changes are serialized with calls on the active instance.
64
- return input=>{
65
- const result=pending.then(()=>request(input));
66
- pending=result.then(()=>{},()=>{});
99
+ return input =>
100
+ {
101
+ const result = pending.then(() => request(input));
102
+ pending = result.then(
103
+ () =>
104
+ {},
105
+ () =>
106
+ {},
107
+ );
67
108
  return result;
68
109
  };
69
110
  }