lawspec 0.30.0 → 0.31.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.
Files changed (78) hide show
  1. package/CHANGELOG.md +377 -1
  2. package/README.md +9 -3
  3. package/api.mjs +1 -0
  4. package/beam-doctor.mjs +2 -2
  5. package/bin/lawspec.mjs +93 -95
  6. package/build.json +497 -405
  7. package/component-packages.mjs +339 -0
  8. package/component.d.ts +46 -0
  9. package/component.mjs +208 -0
  10. package/core.wasm +2 -2
  11. package/core_jsffi.js +5 -5
  12. package/examples/native-payments/clojure/lawspec.edn +48 -0
  13. package/examples/native-payments/clojure/src/domain/payments.clj +1 -1
  14. package/examples/native-payments/clojure/test/domain/payment_generators.clj +1 -1
  15. package/examples/native-payments/csharp/lawspec.edn +48 -0
  16. package/examples/native-payments/elixir/lawspec.edn +123 -0
  17. package/examples/native-payments/erlang/lawspec.edn +128 -0
  18. package/examples/native-payments/fsharp/lawspec.edn +123 -0
  19. package/examples/native-payments/gleam/lawspec.edn +123 -0
  20. package/examples/native-payments/go/lawspec.edn +123 -0
  21. package/examples/native-payments/groovy/lawspec.edn +123 -0
  22. package/examples/native-payments/haskell/lawspec.edn +123 -0
  23. package/examples/native-payments/java/lawspec.edn +123 -0
  24. package/examples/native-payments/javascript/lawspec.edn +123 -0
  25. package/examples/native-payments/kotlin/lawspec.edn +123 -0
  26. package/examples/native-payments/prolog/lawspec.edn +48 -0
  27. package/examples/native-payments/python/lawspec.edn +123 -0
  28. package/examples/native-payments/rust/lawspec.edn +124 -0
  29. package/examples/native-payments/scala/lawspec.edn +123 -0
  30. package/examples/native-payments/swift/lawspec.edn +123 -0
  31. package/examples/native-payments/typescript/lawspec.edn +123 -0
  32. package/examples/packages/orders/lawspec.edn +25 -0
  33. package/examples/packages/shop-domain/lawspec.edn +13 -0
  34. package/examples/packages/shop-tax-1/lawspec.edn +9 -0
  35. package/examples/packages/shop-tax-2/lawspec.edn +9 -0
  36. package/examples/specs/handler_bindings.lawspec +2 -2
  37. package/files.mjs +2 -1
  38. package/go.mod +4 -0
  39. package/index.d.ts +135 -2
  40. package/input-files.mjs +47 -0
  41. package/launcher.mjs +33 -13
  42. package/lsp.mjs +10 -5
  43. package/native-evidence.mjs +50 -15
  44. package/native-examples.mjs +8 -7
  45. package/native-host.mjs +71 -0
  46. package/package.json +8 -3
  47. package/proof.d.ts +8 -2
  48. package/proof.mjs +183 -31
  49. package/scala-build-state.mjs +59 -0
  50. package/templates.mjs +242 -2
  51. package/test-command.mjs +192 -60
  52. package/builtin-data-names.mjs +0 -73
  53. package/examples/native-payments/clojure/lawspec.json +0 -62
  54. package/examples/native-payments/csharp/lawspec.json +0 -62
  55. package/examples/native-payments/elixir/lawspec.json +0 -160
  56. package/examples/native-payments/erlang/lawspec.json +0 -159
  57. package/examples/native-payments/fsharp/lawspec.json +0 -178
  58. package/examples/native-payments/gleam/lawspec.json +0 -160
  59. package/examples/native-payments/go/lawspec.json +0 -147
  60. package/examples/native-payments/groovy/lawspec.json +0 -176
  61. package/examples/native-payments/haskell/lawspec.json +0 -160
  62. package/examples/native-payments/java/lawspec.json +0 -176
  63. package/examples/native-payments/javascript/lawspec.json +0 -160
  64. package/examples/native-payments/kotlin/lawspec.json +0 -176
  65. package/examples/native-payments/prolog/lawspec.json +0 -20
  66. package/examples/native-payments/python/lawspec.json +0 -160
  67. package/examples/native-payments/rust/lawspec.json +0 -178
  68. package/examples/native-payments/scala/lawspec.json +0 -176
  69. package/examples/native-payments/swift/lawspec.json +0 -165
  70. package/examples/native-payments/typescript/lawspec.json +0 -160
  71. package/examples/packages/orders/lawspec.json +0 -27
  72. package/examples/packages/shop-domain/lawspec-package.json +0 -7
  73. package/examples/packages/shop-tax-1/lawspec-package.json +0 -5
  74. package/examples/packages/shop-tax-2/lawspec-package.json +0 -5
  75. package/explain.mjs +0 -114
  76. package/expression-presentation.mjs +0 -333
  77. package/positional-fields.mjs +0 -13
  78. package/typed-presentation.mjs +0 -165
@@ -0,0 +1,59 @@
1
+ // Generated from templates/npm/scala-build-state.mjs by lawspec-dev generate. Do not edit.
2
+ // Preserve failed compiler state before an adapter restore or another build
3
+ // changes it. These diagnostics are not completed native execution evidence.
4
+ import {mkdir,readFile,readdir,realpath,stat,writeFile} from 'node:fs/promises';
5
+ import {randomUUID} from 'node:crypto';
6
+ import path from 'node:path';
7
+
8
+ export const isScalaCompilationFailure = output =>
9
+ /error compiling project|compilation failed|unexpected error when (?:compiling|copying)/i.test(output);
10
+
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);
26
+ // A symlink may point to another client's output or outside this
27
+ // 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()});
34
+ }
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'});}
45
+ }
46
+ }
47
+ }
48
+ }
49
+ 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);
57
+ return directory;
58
+ }catch{return null;} // Capture failure must never replace the compiler result.
59
+ }
package/templates.mjs CHANGED
@@ -142,6 +142,246 @@ export const targetLabels = [
142
142
  ]
143
143
  ];
144
144
 
145
+ export const presentationChecks = {
146
+ "java": [
147
+ {
148
+ "command": "mvn",
149
+ "args": [
150
+ "-q",
151
+ "test-compile"
152
+ ],
153
+ "suffix": null,
154
+ "each": false,
155
+ "environment": {}
156
+ }
157
+ ],
158
+ "python": [
159
+ {
160
+ "command": "python3",
161
+ "args": [
162
+ "-B",
163
+ "-c",
164
+ "import ast,pathlib,sys; [ast.parse(pathlib.Path(p).read_text(),filename=p) for p in sys.argv[1:]]"
165
+ ],
166
+ "suffix": ".py",
167
+ "each": false,
168
+ "environment": {}
169
+ }
170
+ ],
171
+ "javascript": [
172
+ {
173
+ "command": "node",
174
+ "args": [
175
+ "--check"
176
+ ],
177
+ "suffix": ".mjs",
178
+ "each": true,
179
+ "environment": {}
180
+ }
181
+ ],
182
+ "typescript": [
183
+ {
184
+ "command": "npm",
185
+ "args": [
186
+ "exec",
187
+ "--",
188
+ "tsc",
189
+ "-p",
190
+ "tsconfig.json"
191
+ ],
192
+ "suffix": null,
193
+ "each": false,
194
+ "environment": {}
195
+ }
196
+ ],
197
+ "go": [
198
+ {
199
+ "command": "go",
200
+ "args": [
201
+ "test",
202
+ "./...",
203
+ "-run",
204
+ "^$"
205
+ ],
206
+ "suffix": null,
207
+ "each": false,
208
+ "environment": {}
209
+ }
210
+ ],
211
+ "haskell": [
212
+ {
213
+ "command": "stack",
214
+ "args": [
215
+ "--no-terminal",
216
+ "build",
217
+ "--test",
218
+ "--no-run-tests"
219
+ ],
220
+ "suffix": null,
221
+ "each": false,
222
+ "environment": {}
223
+ }
224
+ ],
225
+ "kotlin": [
226
+ {
227
+ "command": "gradle",
228
+ "args": [
229
+ "testClasses",
230
+ "--console=plain"
231
+ ],
232
+ "suffix": null,
233
+ "each": false,
234
+ "environment": {}
235
+ }
236
+ ],
237
+ "rust": [
238
+ {
239
+ "command": "cargo",
240
+ "args": [
241
+ "test",
242
+ "--no-run"
243
+ ],
244
+ "suffix": null,
245
+ "each": false,
246
+ "environment": {}
247
+ }
248
+ ],
249
+ "erlang": [
250
+ {
251
+ "command": "rebar3",
252
+ "args": [
253
+ "as",
254
+ "test",
255
+ "compile"
256
+ ],
257
+ "suffix": null,
258
+ "each": false,
259
+ "environment": {}
260
+ }
261
+ ],
262
+ "elixir": [
263
+ {
264
+ "command": "mix",
265
+ "args": [
266
+ "compile"
267
+ ],
268
+ "suffix": null,
269
+ "each": false,
270
+ "environment": {
271
+ "MIX_ENV": "test"
272
+ }
273
+ }
274
+ ],
275
+ "gleam": [
276
+ {
277
+ "command": "gleam",
278
+ "args": [
279
+ "build"
280
+ ],
281
+ "suffix": null,
282
+ "each": false,
283
+ "environment": {}
284
+ }
285
+ ],
286
+ "fsharp": [
287
+ {
288
+ "command": "dotnet",
289
+ "args": [
290
+ "build"
291
+ ],
292
+ "suffix": null,
293
+ "each": false,
294
+ "environment": {}
295
+ }
296
+ ],
297
+ "csharp": [
298
+ {
299
+ "command": "dotnet",
300
+ "args": [
301
+ "build"
302
+ ],
303
+ "suffix": null,
304
+ "each": false,
305
+ "environment": {}
306
+ }
307
+ ],
308
+ "scala": [
309
+ {
310
+ "command": "scala",
311
+ "args": [
312
+ "compile",
313
+ "--test",
314
+ "."
315
+ ],
316
+ "suffix": null,
317
+ "each": false,
318
+ "environment": {}
319
+ }
320
+ ],
321
+ "groovy": [
322
+ {
323
+ "command": "gradle",
324
+ "args": [
325
+ "testClasses",
326
+ "--console=plain"
327
+ ],
328
+ "suffix": null,
329
+ "each": false,
330
+ "environment": {}
331
+ }
332
+ ],
333
+ "clojure": [
334
+ {
335
+ "command": "clojure",
336
+ "args": [
337
+ "-M",
338
+ "-e",
339
+ "(require 'lawspec.build) (lawspec.build/compile-java! true) (shutdown-agents)"
340
+ ],
341
+ "suffix": null,
342
+ "each": false,
343
+ "environment": {}
344
+ }
345
+ ],
346
+ "swift": [
347
+ {
348
+ "command": "swift",
349
+ "args": [
350
+ "build",
351
+ "--build-tests"
352
+ ],
353
+ "suffix": null,
354
+ "each": false,
355
+ "environment": {}
356
+ }
357
+ ],
358
+ "prolog": [
359
+ {
360
+ "command": "python3",
361
+ "args": [
362
+ "-B",
363
+ "-c",
364
+ "import ast,pathlib,sys; [ast.parse(pathlib.Path(p).read_text(),filename=p) for p in sys.argv[1:]]"
365
+ ],
366
+ "suffix": ".py",
367
+ "each": false,
368
+ "environment": {}
369
+ },
370
+ {
371
+ "command": "swipl",
372
+ "args": [
373
+ "-q",
374
+ "-g",
375
+ "halt",
376
+ "-s"
377
+ ],
378
+ "suffix": ".pl",
379
+ "each": true,
380
+ "environment": {}
381
+ }
382
+ ]
383
+ };
384
+
145
385
  export const commands = {
146
386
  "java": "mvn test",
147
387
  "python": "python -m pytest",
@@ -356,10 +596,10 @@ const scaffolds = {
356
596
  },
357
597
  "swift": {
358
598
  "readable": {
359
- "Package.swift": "// swift-tools-version: 6.2\nimport PackageDescription\n\nlet package = Package(\n name: \"Example\",\n platforms: [.macOS(.v26)],\n targets: [\n .target(name: \"LawSpecRuntime\", path: \"lawspec/LawSpecRuntime\"),\n .target(name: \"LawSpecTesting\", dependencies: [\"LawSpecRuntime\"], path: \"lawspec/LawSpecTesting\"),\n .target(name: \"App\", dependencies: [\"LawSpecRuntime\"], path: \"src\"),\n .testTarget(name: \"AppTests\", dependencies: [\"App\", \"LawSpecRuntime\", \"LawSpecTesting\"], path: \"tests\"),\n ]\n)\n"
599
+ "Package.swift": "// swift-tools-version: 6.2\nimport PackageDescription\n\nlet package = Package(\n name: \"Example\",\n platforms: [.macOS(.v26)],\n targets: [\n .target(name: \"LawSpecRuntime\", path: \"lawspec/LawSpecRuntime\"),\n .target(\n name: \"LawSpecTesting\", dependencies: [\"LawSpecRuntime\"], path: \"lawspec/LawSpecTesting\"),\n .target(name: \"App\", dependencies: [\"LawSpecRuntime\"], path: \"src\"),\n .testTarget(\n name: \"AppTests\", dependencies: [\"App\", \"LawSpecRuntime\", \"LawSpecTesting\"], path: \"tests\"),\n ]\n)\n"
360
600
  },
361
601
  "compact": {
362
- "Package.swift": "// swift-tools-version: 6.2\nimport PackageDescription\nlet package = Package(\n name: \"Example\",\n platforms: [.macOS(.v26)],\n targets: [\n .target(name: \"LawSpecRuntime\", path: \"lawspec/LawSpecRuntime\"),\n .target(name: \"LawSpecTesting\", dependencies: [\"LawSpecRuntime\"], path: \"lawspec/LawSpecTesting\"),\n .target(name: \"App\", dependencies: [\"LawSpecRuntime\"], path: \"src\"),\n .testTarget(name: \"AppTests\", dependencies: [\"App\", \"LawSpecRuntime\", \"LawSpecTesting\"], path: \"tests\"),\n ]\n)\n"
602
+ "Package.swift": "// swift-tools-version: 6.2\nimport PackageDescription\nlet package = Package(\n name: \"Example\",\n platforms: [.macOS(.v26)],\n targets: [\n .target(name: \"LawSpecRuntime\", path: \"lawspec/LawSpecRuntime\"),\n .target(\n name: \"LawSpecTesting\", dependencies: [\"LawSpecRuntime\"], path: \"lawspec/LawSpecTesting\"),\n .target(name: \"App\", dependencies: [\"LawSpecRuntime\"], path: \"src\"),\n .testTarget(\n name: \"AppTests\", dependencies: [\"App\", \"LawSpecRuntime\", \"LawSpecTesting\"], path: \"tests\"),\n ]\n)\n"
363
603
  }
364
604
  },
365
605
  "prolog": {