lawspec 0.23.0 → 0.24.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.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,105 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.24.0] - 2026-10-13
10
+
11
+ ### Added
12
+
13
+ - A Scala target (`--target scala`): Scala 3.9 over the shared JVM runtime,
14
+ built and tested with Scala CLI (`scala test .`) in sbt's source layout.
15
+ Data types are case classes and enums, and the built-in types are Scala's
16
+ own: `List`, `Option`, `Either`, `Set`, `Map`, `Queue`, `Vector`, `BigInt`,
17
+ exact `BigDecimal`, `FiniteDuration` and `IArray`. Abilities are traits,
18
+ and an adapter or operation that fails with `E` returns `Either[E, R]`;
19
+ async adapters return `Future`. Laws are ScalaTest suites whose properties
20
+ run on ScalaCheck 1.20.0 with LawSpec's shrink-tree generators, so shrinks
21
+ stay inside refinements and `LAWSPEC_SEED` replays a run
22
+ (DEC-scala-property-library). Checked definitions run on the shared JVM
23
+ bodies, typed where the plan allows; actors, supervisors, sessions,
24
+ mailboxes, remote evaluation, the secure network, post-quantum crypto, the
25
+ built-in abilities' default handlers, native bindings and every harness
26
+ feature (strategies, cover, targeted search, the failure database, retries,
27
+ timeouts, order random, parallel units, benchmarks and JUnit reports) are
28
+ supported. `lawspec test --coverage` measures Scala with Scala 3's own
29
+ instrumentation and the scoverage reporter, with nothing to install.
30
+ - Typed BEAM code: on Erlang, Elixir and Gleam, a checked definition whose
31
+ values all have native forms, and a spec handler whose clauses are all
32
+ typed, run as native Erlang in `lawspec_typed`, over each language's own
33
+ tuples, structs or custom types, with `KeyVal` as maps and `Set` as
34
+ version 2 `sets` whose entries and items come out in the portable order.
35
+ Integers are checked where their type bounds them, raise and attempt fail
36
+ as the dynamic code does, and definitions that perform other abilities'
37
+ operations take the handler context. A typed handler keeps its state in
38
+ its cell's process and runs each operation there, so an operation copies
39
+ only its arguments and result; `cluster_typed_state` and
40
+ `cluster_set_typed_state` read and replace that state without
41
+ conversion. `lawspec-dev bench kafka` has Erlang, Elixir and Gleam
42
+ drivers: at 10,000 produces the workload took 34 to 36 seconds on the
43
+ dynamic path and 0.02 to 0.03 seconds typed, and a million produces now
44
+ run at 400,000 to 770,000 operations a second. `--typed` reports the BEAM
45
+ plan too.
46
+ - Groovy target (`--target groovy`) on Groovy 5.0, Gradle and Spock 2.5. Groovy
47
+ runs over the Java model: the data types (records and sealed interfaces),
48
+ codecs, ability interfaces, checked definitions, actors, sessions, mailboxes,
49
+ the network and the secure handler are the Java target's, compiled jointly
50
+ with the Groovy sources. Adapters and bound application code are Groovy
51
+ classes checked with `@CompileStatic`, and each unit's laws are a Spock
52
+ specification with a feature per test, named in words. Properties run on
53
+ JetCheck with LawSpec's generators, so shrinks stay inside refinements, and
54
+ `LAWSPEC_SEED` replays a run; `order random` and `parallel` become a seeded
55
+ feature order and Spock's concurrent execution. The surveys behind the
56
+ property libraries are DEC-groovy-property-library and
57
+ DEC-clojure-property-library.
58
+ - Clojure target (`--target clojure`) on Clojure 1.12 with deps.edn,
59
+ `clojure.test` and test.check. Clojure runs over the Java model too, which
60
+ `lawspec.build` compiles with the JDK's compiler. Each unit's adapters are
61
+ functions of a namespace, called through a generated Java bridge, and
62
+ values cross as Clojure data: tagged maps (`{:lawspec/tag
63
+ :payment/approved, :cents 500}`) or a tag alone for a constructor without
64
+ fields, vectors, sets, maps, nil for Maybe's nothing, `[:left e]` and
65
+ `[:right a]`, and failures as ex-info. Native handlers are maps of
66
+ operations. `lawspec.json` binds functions, handle constructors and
67
+ methods, handlers and failures (an ex-info's `:type`) to Clojure.
68
+ Properties run on test.check: LawSpec's generators make rose trees whose
69
+ shrinks stay inside refinements, and `LAWSPEC_SEED` replays a run; a
70
+ namespace's `test-ns-hook` gives `order random` and `parallel`.
71
+ - A Swift target (`--target swift`) on Swift 6.2 and later, with SwiftPM and
72
+ `swift test`. Its runtime is written for Swift 6 with strict concurrency:
73
+ structs and enums with associated values (`indirect` where recursive) in
74
+ LawSpec's order, exact integers, persistent lists (`PersistentList`) and
75
+ sorted collections, typed throws for failures, abilities as protocols,
76
+ `async` adapters, supervised actors whose messages also have `async`
77
+ overloads, single-use session ends, mailboxes, a virtual clock, workflow
78
+ policies, remote evaluation and the secure network on the shared wire
79
+ format, and post-quantum crypto from CryptoKit (macOS 26), with the
80
+ runtime's own SHAKE256 and SLH-DSA where CryptoKit has none. Tests are Swift
81
+ Testing functions; no maintained Swift property library shrinks inside
82
+ refinements and replays from a seed, so properties run on a small
83
+ shrink-tree engine in `LawSpecTesting`, with `LAWSPEC_SEED` replay. Models,
84
+ linearizability, scenarios and the whole harness run around it.
85
+ Definitions whose values all have native types run typed, with self tail
86
+ calls as loops, and each spec handler is a native class with its state to
87
+ read or restore. `lawspec test`, `lawspec doctor` and `lawspec examples`
88
+ support it. See [Set up Swift](docs/how-to/targets/swift.md).
89
+
90
+ ### Fixed
91
+
92
+ - Erlang and Elixir: a data type named after a built-in type that a module
93
+ may redefine, such as `Record`, no longer makes `lawspec_data` warn. The
94
+ type takes its qualified name, and its constructors keep their tags.
95
+ - Erlang and Elixir: EUnit and ExUnit now allow a law, model check or
96
+ benchmark ten minutes on top of its own timeouts. This is a guard against
97
+ hangs, not a budget. Before, the limit was 60 s, and a law that retries
98
+ over a lossy network on the real clock could run past it on a loaded
99
+ machine.
100
+ - BEAM parallel model checks pause with a run of yields instead of a 1 ms
101
+ timer, which a loaded machine stretches across hundreds of runs.
102
+ - Refined record fields are now generated instead of filtered. On Python, a
103
+ constructor field refined by a regex also draws samples of that regex. On
104
+ every target, a data input whose refinement matches one of its fields
105
+ against a regex (`validPet p`) now starts from values whose field matches.
106
+ This stops Hypothesis's `filter_too_much` health check from failing.
107
+
9
108
  ## [0.23.0] - 2026-10-12
10
109
 
11
110
  ### Added
@@ -1535,7 +1634,8 @@ A maintenance release. The language, generated code and API are unchanged from
1535
1634
  machine-sized bindings reject an architecture mismatch. Rust adapters take
1536
1635
  owned values.
1537
1636
 
1538
- [Unreleased]: https://github.com/brain-fuel/lawspec/compare/v0.23.0...HEAD
1637
+ [Unreleased]: https://github.com/brain-fuel/lawspec/compare/v0.24.0...HEAD
1638
+ [0.24.0]: https://github.com/brain-fuel/lawspec/compare/v0.23.0...v0.24.0
1539
1639
  [0.23.0]: https://github.com/brain-fuel/lawspec/compare/v0.22.0...v0.23.0
1540
1640
  [0.22.0]: https://github.com/brain-fuel/lawspec/compare/v0.21.0...v0.22.0
1541
1641
  [0.21.0]: https://github.com/brain-fuel/lawspec/compare/v0.20.1...v0.21.0
package/README.md CHANGED
@@ -30,7 +30,7 @@ Node 22+ and the selected target's build tools are required. No Haskell
30
30
  toolchain is needed. The reference platforms are macOS and Linux.
31
31
 
32
32
  ```sh
33
- npm install --save-dev lawspec@0.23.0
33
+ npm install --save-dev lawspec@0.24.0
34
34
  npx lawspec --version
35
35
  ```
36
36
 
@@ -40,8 +40,8 @@ LawSpec can create `package.json` and its test script:
40
40
  ```sh
41
41
  mkdir lawspec-example
42
42
  cd lawspec-example
43
- npm exec --package=lawspec@0.23.0 -- lawspec init --target javascript
44
- npm install --save-dev lawspec@0.23.0
43
+ npm exec --package=lawspec@0.24.0 -- lawspec init --target javascript
44
+ npm install --save-dev lawspec@0.24.0
45
45
  npx lawspec check
46
46
  npx lawspec explain 'example.atoi_codec::itoa and then atoi yields a'
47
47
  npx lawspec doctor
package/bin/lawspec.mjs CHANGED
@@ -9,6 +9,7 @@ import { generateExamples } from "../examples-command.mjs";
9
9
  import { showScalar } from "../scalars.mjs";
10
10
  import { doctor } from "../doctor.mjs";
11
11
  import { beamCoverageRequirement, collectBeamCoverage } from "../beam-coverage.mjs";
12
+ import { collectScalaCoverage } from "../scala-coverage.mjs";
12
13
  import { failureDatabase, projectKey } from "../failure-database.mjs";
13
14
  import { spawn, spawnSync } from "node:child_process";
14
15
  import { benchmarkInvocations, preparationInvocations, environmentDigest, executedTests, invocations, lawKeys, projectDigest, recordedDigest, selectByTags, mergeJunit,
@@ -20,7 +21,7 @@ import {
20
21
  atomicWrite,
21
22
  safePath,
22
23
  } from "../files.mjs";
23
- const VERSION = "0.23.0";
24
+ const VERSION = "0.24.0";
24
25
  const args = process.argv.slice(2);
25
26
  const verb = args.shift();
26
27
  const options = {};
@@ -58,6 +59,8 @@ function testCommand(target, root) {
58
59
  command = `${shellQuote(target.maven || "mvn")} test`;
59
60
  if (target.language === "kotlin")
60
61
  command = `${shellQuote(target.gradle || "gradle")} test`;
62
+ if (target.language === "scala")
63
+ command = `${shellQuote(target.scala || "scala")} test .`;
61
64
  if (target.language === "javascript")
62
65
  command = `node --test ${shellQuote(testDir)}/*.test.mjs`;
63
66
  if (target.language === "typescript")
@@ -450,7 +453,7 @@ async function runTests(compiler, input, selected, roots, config) {
450
453
  if (missingCoverage)
451
454
  console.error(`${target.language}: --coverage needs ${missingCoverage.tool}, which is not available; ${missingCoverage.install}. Running without coverage.`);
452
455
  if (useCoverage) {
453
- if (beam) await rm(coverage, {recursive: true, force: true});
456
+ if (beam || target.language === "scala") await rm(coverage, {recursive: true, force: true});
454
457
  await mkdir(beam ? path.join(coverage, "runs") : coverage, { recursive: true });
455
458
  }
456
459
  // parallel on Python needs pytest-xdist; without it the tests run one
@@ -492,6 +495,14 @@ async function runTests(compiler, input, selected, roots, config) {
492
495
  }
493
496
  }
494
497
  if (unrun.length) failed = true;
498
+ if (useCoverage && target.language === "scala" && !failed) {
499
+ try {
500
+ coverageWritten = await collectScalaCoverage({root, directory: coverage, command: target.scala || "scala", offline});
501
+ } catch (error) {
502
+ failed = true;
503
+ coverageError = error.message;
504
+ }
505
+ }
495
506
  if (useCoverage && beam) {
496
507
  try {
497
508
  coverageWritten = !!(await collectBeamCoverage({root, directory: coverage, runs: coverageRuns}));
@@ -552,7 +563,7 @@ async function runTests(compiler, input, selected, roots, config) {
552
563
  ...(benchmarks.length ? { benchmarks } : {}),
553
564
  ...(parallelism.length ? { parallelism } : {}),
554
565
  ...(coverageError ? {coverageError} : {}),
555
- ...(useCoverage && (!beam || coverageWritten) ? { coverage: path.relative(process.cwd(), coverage) || "." } : {}) });
566
+ ...(useCoverage && ((!beam && target.language !== "scala") || coverageWritten) ? { coverage: path.relative(process.cwd(), coverage) || "." } : {}) });
556
567
  }
557
568
  if (report) {
558
569
  await mkdir(path.dirname(path.resolve(report.path)), { recursive: true });
@@ -618,6 +629,7 @@ async function coverageMissing(target, root, report) {
618
629
  const build = await readFile(path.join(root, "build.gradle.kts"), "utf8").catch(() => "");
619
630
  return build.includes("kover") ? null : tool;
620
631
  }
632
+ if (target.language === "scala") return null;
621
633
  return null;
622
634
  }
623
635
  // Run a native test command, showing its output (on stderr with --json) and