lawspec 0.21.0 → 0.23.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 (39) hide show
  1. package/CHANGELOG.md +322 -2
  2. package/README.md +3 -3
  3. package/beam-coverage.mjs +160 -0
  4. package/beam-doctor.mjs +306 -0
  5. package/bin/lawspec.mjs +150 -41
  6. package/build.json +359 -101
  7. package/compatibility.json +25 -0
  8. package/core.wasm +2 -2
  9. package/doctor.mjs +29 -2
  10. package/examples/native-payments/csharp/lawspec.json +51 -0
  11. package/examples/native-payments/csharp/src/Domain/Payments.cs +19 -0
  12. package/examples/native-payments/csharp/tests/Native/PaymentGenerators.cs +14 -0
  13. package/examples/native-payments/elixir/lawspec.json +149 -0
  14. package/examples/native-payments/elixir/lib/payments_domain.ex +54 -0
  15. package/examples/native-payments/elixir/test/support/payment_generators.ex +9 -0
  16. package/examples/native-payments/erlang/include/payments_domain.hrl +2 -0
  17. package/examples/native-payments/erlang/lawspec.json +148 -0
  18. package/examples/native-payments/erlang/src/payments_domain.erl +21 -0
  19. package/examples/native-payments/erlang/test/payment_generators.erl +10 -0
  20. package/examples/native-payments/fsharp/lawspec.json +167 -0
  21. package/examples/native-payments/fsharp/src/Native/Types/PaymentsDomain.fs +23 -0
  22. package/examples/native-payments/fsharp/tests/Native/PaymentGenerators.fs +11 -0
  23. package/examples/native-payments/gleam/lawspec.json +149 -0
  24. package/examples/native-payments/gleam/prepare.mjs +48 -0
  25. package/examples/native-payments/gleam/src/payments_domain.gleam +32 -0
  26. package/examples/native-payments/gleam/test/payment_generators.gleam +13 -0
  27. package/examples/specs/collections.lawspec +44 -0
  28. package/examples/specs/composition.lawspec +110 -0
  29. package/examples/specs/contracts.lawspec +124 -0
  30. package/examples/specs/generation.lawspec +11 -0
  31. package/examples/specs/records.lawspec +191 -0
  32. package/examples/specs/records_inner.lawspec +10 -0
  33. package/examples/specs/sequences.lawspec +86 -0
  34. package/failure-database.mjs +46 -0
  35. package/index.d.ts +45 -1
  36. package/native-examples.mjs +7 -2
  37. package/package.json +2 -2
  38. package/templates.mjs +134 -3
  39. package/test-command.mjs +188 -17
@@ -0,0 +1,124 @@
1
+ unit example.contracts
2
+
3
+ -- Shapes contract importers write: handlers whose clauses fail, handlers
4
+ -- over Bytes and Text, refined records, and handlers named like their
5
+ -- abilities.
6
+
7
+ type Refusal is | Negative | Empty end
8
+
9
+ definition bump (n :: Int64) (total :: Int64) :: Pair Int64 Int64 fails with Refusal is
10
+ if n < 0 then raise Negative else
11
+ if total > 1000000 || n > 1000000 then Pair total total else Pair (prelude.Int64 (total + n)) (prelude.Int64 (total + n))
12
+ end
13
+
14
+ -- A definition that may fail but does not.
15
+ definition peek (total :: Int64) :: Pair Int64 Int64 fails with Refusal is Pair total total end
16
+
17
+ ability Counter is
18
+ add :: Int64 -> Int64 fails with Refusal
19
+ current :: Int64 fails with Refusal
20
+ end
21
+
22
+ -- Named like its ability.
23
+ handler counter for Counter with state total :: Int64 start 0 is
24
+ add by bump
25
+ current by peek
26
+ end
27
+
28
+ -- A state with no typed form keeps this handler on the dynamic path.
29
+ type Scaled is Scaled count :: Int64 scale :: Float64 end
30
+
31
+ definition bumpScaled (n :: Int64) (s :: Scaled) :: Pair Int64 Scaled fails with Refusal is
32
+ if n < 0 then raise Negative else
33
+ if s.count > 1000000 || n > 1000000 then Pair s.count s else
34
+ Pair (prelude.Int64 (s.count + n)) (s with count = prelude.Int64 (s.count + n))
35
+ end
36
+
37
+ definition peekScaled (s :: Scaled) :: Pair Int64 Scaled fails with Refusal is Pair s.count s end
38
+
39
+ handler scaledCounter for Counter with state s :: Scaled start Scaled 0 1.0 is
40
+ add by bumpScaled
41
+ current by peekScaled
42
+ end
43
+
44
+ -- Bytes and Text inside handler clauses, on both paths.
45
+ ability Codec is
46
+ octetCount :: Text -> Int64
47
+ label :: Text -> Int32 -> Text
48
+ end
49
+
50
+ handler codec for Codec is
51
+ octetCount t is prelude.length (prelude.octets (prelude.utf8 t)) end
52
+ label t n is prelude.join "-" [t, prelude.textOf n] ++ prelude.slice 0 0 t end
53
+ end
54
+
55
+ handler scaledCodec for Codec with state s :: Float64 start 1.0 is
56
+ octetCount t is prelude.length (prelude.bytesOf (prelude.octets (prelude.utf8 t))) end
57
+ label t n is prelude.take (prelude.length t + 9) (t ++ "-" ++ prelude.textOf n) end
58
+ end
59
+
60
+ -- A failed operation leaves the handler's state as it was, on the typed
61
+ -- path (counter) and the dynamic one (scaledCounter).
62
+ law `a refused add changes nothing` using counter is
63
+ definition is
64
+ `for all` (n :: Int64 where n >= 0 && n <= 1000) .
65
+ (let refused = prelude.attempt (add (0 - 1)) in add n) = n
66
+ end
67
+ end
68
+
69
+ law `a refused add changes nothing, dynamically` using scaledCounter is
70
+ definition is
71
+ `for all` (n :: Int64 where n >= 0 && n <= 1000) .
72
+ (let refused = prelude.attempt (add (0 - 1)) in add n) = n
73
+ end
74
+ end
75
+
76
+ law `a text's octets count its UTF-8 bytes` using codec is
77
+ definition is
78
+ `for all` (n :: Int32 where n >= 0 && n <= 1000) .
79
+ octetCount (prelude.textOf n ++ "é") = prelude.length (prelude.textOf n) + 2
80
+ end
81
+ end
82
+
83
+ law `a text's octets count its UTF-8 bytes, dynamically` using scaledCodec is
84
+ definition is
85
+ `for all` (n :: Int32 where n >= 0 && n <= 1000) .
86
+ octetCount (prelude.textOf n ++ "é") = prelude.length (prelude.textOf n) + 2
87
+ end
88
+ end
89
+
90
+ law `a label joins its parts` using codec is
91
+ definition is label "member" 3 = "member-3" end
92
+ end
93
+
94
+ law `a label joins its parts, dynamically` using scaledCodec is
95
+ definition is label "member" 3 = "member-3" end
96
+ end
97
+
98
+ -- Refined records.
99
+ type Pet is
100
+ Pet
101
+ id :: Maybe Int64
102
+ name :: (v :: Text where v matches regex "[a-z]+")
103
+ end
104
+
105
+ definition validName (name :: Text) :: Bool is name matches regex "[a-z]+" end
106
+
107
+ type Badge is
108
+ Badge
109
+ label :: (v :: Text where validName v)
110
+ end
111
+
112
+ definition withId (body :: Pet) (key :: Int64) :: Pet is body with id = Just key end
113
+
114
+ definition validPet (p :: Pet) :: Bool is p.name matches regex "[a-z]{2,8}" end
115
+
116
+ law `an id is set by a record update` is
117
+ definition is
118
+ `for all` (p :: Pet where validPet p) (key :: Int64) . (withId p key).id = Just key and (withId p key).name = p.name
119
+ end
120
+ end
121
+
122
+ law `a badge keeps its label` is
123
+ definition is `for all` (t :: Badge) . validName t.label = true end
124
+ end
@@ -162,3 +162,14 @@ law `a share is at most the total` is
162
162
  expect share t n = 2
163
163
  end
164
164
  end
165
+
166
+ -- A text refined to be non-empty is drawn from its refinement, at every
167
+ -- size: four of them, one also unlike another, are met at the first case,
168
+ -- not filtered out of draws that are mostly empty while the size is small.
169
+ law `several non-empty texts are drawn` is
170
+ definition is
171
+ `for all` (a :: Text where a != "") (b :: Text where b != "") (c :: Text where c != "")
172
+ (d :: Text where d != "" && d != c) .
173
+ prelude.length a + prelude.length b + prelude.length c + prelude.length d >= 4
174
+ end
175
+ end
@@ -0,0 +1,191 @@
1
+ unit example.records
2
+
3
+ import example.records.inner as inner
4
+
5
+ -- Records: a type with one constructor has fields that code reads by name
6
+ -- (account.balance) and replaces by name (account with balance = 0).
7
+
8
+ type Account is
9
+ Account
10
+ owner :: Text
11
+ balance :: Int64
12
+ holds :: List Int64
13
+ end
14
+
15
+ type Ledger is
16
+ Ledger
17
+ account :: Account
18
+ entries :: Int32
19
+ end
20
+
21
+ definition deposit (a :: Account) (amount :: Int64 where amount >= 0 && amount <= 1000000) :: Account is
22
+ if a.balance >= 0 && a.balance <= 1000000000 then a with balance = prelude.Int64 (a.balance + amount) else a
23
+ end
24
+
25
+ definition rename (l :: Ledger) (name :: Text) :: Ledger is
26
+ l with account = (l.account with owner = name), entries = 0
27
+ end
28
+
29
+ law `a deposit adds to the balance` is
30
+ definition is
31
+ `for all` (owner :: Text) (start :: Int64 where start >= 0 && start <= 1000000000) (amount :: Int64 where amount >= 0 && amount <= 1000000) .
32
+ (deposit (Account owner start []) amount).balance = start + amount
33
+ end
34
+ end
35
+
36
+ law `a deposit keeps the owner and holds` is
37
+ definition is
38
+ `for all` (a :: Account) (amount :: Int64 where amount >= 0 && amount <= 1000000) .
39
+ (deposit a amount).owner = a.owner and (deposit a amount).holds = a.holds
40
+ end
41
+ end
42
+
43
+ law `renaming reads back` is
44
+ definition is
45
+ `for all` (l :: Ledger) (name :: Text) . (rename l name).account.owner = name and (rename l name).entries = 0
46
+ end
47
+ end
48
+
49
+ -- A definition may fail without any ability, and another may attempt it.
50
+ type Refusal is | Overdrawn | Unfunded end
51
+
52
+ definition withdraw (a :: Account) (amount :: Int64) :: Account fails with Refusal is
53
+ if amount < 0 then raise Unfunded else
54
+ if amount > a.balance then raise Overdrawn else a with balance = prelude.Int64 (a.balance - amount)
55
+ end
56
+
57
+ definition settled (a :: Account) (amount :: Int64) :: Either Refusal Int64 is
58
+ match prelude.attempt (withdraw a amount) with
59
+ | Left refusal -> Left refusal
60
+ | Right after -> Right after.balance
61
+ end
62
+ end
63
+
64
+ law `a withdrawal within the balance leaves the rest` is
65
+ definition is
66
+ `for all` (owner :: Text) (start :: Int64 where start >= 0) (amount :: Int64 where amount >= 0 && amount <= start) .
67
+ settled (Account owner start []) amount = Right (prelude.Int64 (start - amount))
68
+ end
69
+ end
70
+
71
+ law `a withdrawal beyond the balance is refused` is
72
+ definition is
73
+ `for all` (owner :: Text) (start :: Int64 where start >= 0 && start < 1000) (amount :: Int64 where amount >= 1000) .
74
+ settled (Account owner start []) amount = Left Overdrawn and settled (Account owner start []) (0 - amount) = Left Unfunded
75
+ end
76
+ end
77
+
78
+ -- A refinement through a definition still guides generation: sample
79
+ -- names come from the pattern, so the law does not starve its filter.
80
+ definition validOwner (name :: Text) :: Bool is
81
+ prelude.length name == 9 && name matches regex "acct-[0-9]{4}"
82
+ end
83
+
84
+ law `a renamed ledger keeps a valid owner` is
85
+ definition is
86
+ `for all` (l :: Ledger) (name :: Text where validOwner name) . validOwner (rename l name).account.owner
87
+ end
88
+ end
89
+
90
+ -- A literal takes its type from where it is used: 0 is an Int64 here.
91
+ definition opening (a :: Maybe Account) :: Int64 is
92
+ let start = (match a with | Nothing -> 0 | Just account -> account.balance end) in
93
+ if start < 0 then 0 else start
94
+ end
95
+
96
+ law `an absent account opens at zero` is
97
+ definition is opening Nothing = 0 end
98
+ end
99
+
100
+ -- Recursion on an integer that moves toward a bound is total.
101
+ definition countdown (n :: Natural) :: List Natural is
102
+ if n == 0 then [] else Cons n (countdown (n - 1))
103
+ end
104
+
105
+ definition evensBelow (i :: Int32) (n :: Int32) :: List Int32 is
106
+ if i >= n || i < 0 then [] else
107
+ (if prelude.rem i 2 == 0 then Cons i (evensBelow (prelude.Int32 (i + 1)) n) else evensBelow (prelude.Int32 (i + 1)) n)
108
+ end
109
+
110
+ law `a countdown has n items` is
111
+ definition is `for all` (n :: Natural where n <= 50) . prelude.length (countdown n) = n end
112
+ end
113
+
114
+ law `the evens below n are half of the range` is
115
+ definition is
116
+ `for all` (n :: Int32 where n >= 0 && n <= 40) .
117
+ prelude.length (evensBelow 0 n) = prelude.quot (n + 1) 2
118
+ end
119
+ end
120
+
121
+ law `range counts from the first up to the last` is
122
+ definition is
123
+ `for all` (n :: Int32 where n >= 0 && n <= 40) . prelude.length (prelude.range 0 n) = n
124
+ end
125
+ example `three` is
126
+ n = 3
127
+ expect prelude.range 0 n = [0, 1, 2]
128
+ end
129
+ end
130
+
131
+ -- The prover keeps what guards say about calls, lengths and remainders.
132
+ definition clip (xs :: List Int32) :: Int32 is
133
+ if prelude.length xs <= 100 then prelude.Int32 (prelude.length xs) else 100
134
+ end
135
+
136
+ definition owner (p :: Int32) (k :: Int32) :: Int32 is
137
+ if k >= 1 && p >= 0 then prelude.Int32 (prelude.rem p k) else 0
138
+ end
139
+
140
+ law `a clipped length is at most 100` is
141
+ definition is `for all` (xs :: List Int32) . (clip xs <= 100 && clip xs >= 0) = true end
142
+ end
143
+
144
+ law `an owner is one of the k` is
145
+ definition is
146
+ `for all` (p :: Int32 where p >= 0) (k :: Int32 where k >= 1 && k <= 64) . (owner p k >= 0 && owner p k < k) = true
147
+ end
148
+ end
149
+
150
+ -- Arithmetic into a bounded type, by name.
151
+ definition nextEpoch (e :: Int16) :: Int16 is prelude.wrapping (e + 1) end
152
+ definition topUp (level :: UInt8) :: UInt8 is prelude.saturating (level + 10) end
153
+ definition total (a :: Int32) (b :: Int32) :: Maybe Int32 is prelude.bounded (a + b) end
154
+
155
+ law `epochs wrap around` is
156
+ definition is
157
+ `for all` (e :: Int16) . nextEpoch e = (if e == Int16.max then Int16.min else prelude.Int16 (e + 1))
158
+ end
159
+ end
160
+
161
+ law `a top up stops at the top` is
162
+ definition is
163
+ `for all` (level :: UInt8) . topUp level = (if level >= 245 then 255 else prelude.UInt8 (level + 10))
164
+ end
165
+ end
166
+
167
+ law `a total that overflows is Nothing` is
168
+ definition is
169
+ `for all` (a :: Int32) (b :: Int32) .
170
+ total a b = (if a + b > Int32.max || a + b < Int32.min then Nothing else Just (prelude.Int32 (a + b)))
171
+ end
172
+ end
173
+
174
+ -- A refinement shapes generation: texts a regex must match are drawn from
175
+ -- the regex, through the definition that says so, not filtered from any
176
+ -- text.
177
+ definition validTopic (name :: Text) :: Bool is
178
+ let n = prelude.length name in
179
+ n >= 1 && n <= 249 && name != "." && name != ".." && name matches regex "[a-zA-Z0-9._-]+"
180
+ end
181
+
182
+ law `a valid topic name keeps to its characters` is
183
+ definition is
184
+ `for all` (t :: Text where validTopic t) (n :: Int32 where n >= 1 && n <= 64) .
185
+ (prelude.length t >= 1 && prelude.length t <= 249 && n <= 64) = true
186
+ end
187
+ end
188
+
189
+ law `a unit may sit above its package's other units` is
190
+ definition is `for all` (x :: Int32) . inner.doubled x = x + x end
191
+ end
@@ -0,0 +1,10 @@
1
+ unit example.records.inner
2
+
3
+ -- A unit inside another unit's name: on Python, example.records is then its
4
+ -- package's __init__.py, and this unit is example/records/inner.py.
5
+
6
+ definition doubled (x :: Int32) :: Integer is x * 2 end
7
+
8
+ law `doubling is even` is
9
+ definition is `for all` (x :: Int32) . prelude.rem (doubled x) 2 = 0 end
10
+ end
@@ -0,0 +1,86 @@
1
+ unit example.sequences
2
+
3
+ -- Text, Bytes and List are sequences: joined with ++, sliced, and read by
4
+ -- index. Bytes give their octets, and Text its UTF-8 encoding.
5
+
6
+ -- A record key's hash: FNV-1a over the key's octets, in 32 bits.
7
+ definition fnv (octets :: List UInt8) (hash :: UInt32) :: UInt32 is
8
+ match octets with
9
+ | Nil -> hash
10
+ | Cons o rest -> fnv rest (prelude.wrapping ((xorByte hash o) * 16777619))
11
+ end
12
+ end
13
+
14
+ -- hash xor o, for an octet o, by its low eight bits.
15
+ definition xorByte (hash :: UInt32) (o :: UInt8) :: Integer is
16
+ let low = prelude.rem hash 256 in
17
+ hash - low + xorBits low o 128
18
+ end
19
+
20
+ definition xorBits (a :: Integer) (b :: Integer) (bit :: Integer) :: Integer is
21
+ if bit <= 0 || a < 0 || b < 0 then 0 else
22
+ (if prelude.quot a bit != prelude.quot b bit then bit else 0)
23
+ + xorBits (prelude.rem a bit) (prelude.rem b bit) (prelude.quot bit 2)
24
+ end
25
+
26
+ definition keyHash (key :: Bytes) :: UInt32 is fnv (prelude.octets key) 2166136261 end
27
+
28
+ definition partitionFor (key :: Bytes) (n :: Int32) :: Int32 is
29
+ if n >= 1 then prelude.Int32 (prelude.rem (keyHash key) n) else 0
30
+ end
31
+
32
+ law `a key's partition exists` is
33
+ definition is
34
+ `for all` (key :: Bytes) (n :: Int32 where n >= 1 && n <= 64) .
35
+ (partitionFor key n >= 0 && partitionFor key n < n) = true
36
+ end
37
+ end
38
+
39
+ law `the hash follows FNV-1a` is
40
+ definition is keyHash (prelude.utf8 "a") = 3826002220 and keyHash (prelude.utf8 "") = 2166136261 end
41
+ end
42
+
43
+ -- Member ids, made by the coordinator from a client id and a counter.
44
+ definition memberId (client :: Text) (n :: Int32) :: Text is client ++ "-" ++ prelude.textOf n end
45
+
46
+ law `a member id starts with its client` is
47
+ definition is
48
+ `for all` (client :: Text) (n :: Int32) . memberId client n starts with client
49
+ end
50
+ example `the third` is
51
+ client = "consumer"
52
+ n = 3
53
+ expect memberId client n = "consumer-3"
54
+ end
55
+ end
56
+
57
+ law `joining text adds lengths` is
58
+ definition is
59
+ `for all` (a :: Text) (b :: Text) . prelude.length (a ++ b) = prelude.length a + prelude.length b
60
+ end
61
+ end
62
+
63
+ law `octets and bytes round trip` is
64
+ definition is `for all` (b :: Bytes) . prelude.bytesOf (prelude.octets b) = b end
65
+ end
66
+
67
+ law `a slice is a part` is
68
+ definition is
69
+ `for all` (xs :: List Int32) (k :: Int32 where k >= 0 && k <= 10) .
70
+ prelude.take k xs ++ prelude.drop k xs = xs
71
+ end
72
+ end
73
+
74
+ law `at reads the item an index names` is
75
+ definition is
76
+ `for all` (x :: Int32) (xs :: List Int32) . prelude.at 0 (Cons x xs) = Just x and prelude.at (prelude.length xs + 1) (Cons x xs) = Nothing
77
+ end
78
+ end
79
+
80
+ law `texts join with a separator` is
81
+ definition is prelude.join ", " ["a", "b", "c"] = "a, b, c" and prelude.slice 1 3 "kafka" = "af" end
82
+ end
83
+
84
+ law `utf8 encodes code points` is
85
+ definition is prelude.utf8 "é" = prelude.bytesOf [195, 169] and prelude.length (prelude.utf8 "é") = 2 end
86
+ end
@@ -0,0 +1,46 @@
1
+ // Generated from templates/npm/failure-database.mjs by lawspec-dev generate. Do not edit.
2
+ // Failed seeds and framework counterexamples belong to one project root.
3
+ import {createHash} from 'node:crypto';
4
+ import {cp, mkdir, mkdtemp, readFile, rename, rm, writeFile} from 'node:fs/promises';
5
+ import path from 'node:path';
6
+ import {readOptional} from './files.mjs';
7
+
8
+ export const projectKey = root => createHash('sha256').update(path.resolve(root)).digest('hex').slice(0, 12);
9
+
10
+ function parseDatabase(text) {
11
+ const database = JSON.parse(text);
12
+ if (!database || typeof database !== 'object' || Array.isArray(database))
13
+ throw new Error('The failure database must contain a map of law identities to failures');
14
+ return database;
15
+ }
16
+
17
+ export async function failureDatabase(configRoot, language, root) {
18
+ const legacy = path.join(configRoot, '.lawspec/failures', language);
19
+ const directory = path.join(legacy, projectKey(root));
20
+ const file = path.join(directory, 'laws.json');
21
+ const current = await readOptional(file);
22
+ if (current !== null) return {directory, file, database: parseDatabase(current)};
23
+
24
+ // Old databases identify only the language. Preserve them and copy their
25
+ // failures once into each project's initial state so no counterexample is
26
+ // lost. Subsequent passes and failures change only that project's copy.
27
+ const database = parseDatabase((await readOptional(path.join(legacy, 'laws.json'))) ?? '{}');
28
+ await mkdir(legacy, {recursive: true});
29
+ const temporary = await mkdtemp(path.join(legacy, '.migrate-'));
30
+ try {
31
+ for (const name of ['inputs', 'hypothesis', 'proptest-regressions.txt']) {
32
+ try { await cp(path.join(legacy, name), path.join(temporary, name), {recursive: true}); }
33
+ catch (error) { if (error.code !== 'ENOENT') throw error; }
34
+ }
35
+ await writeFile(path.join(temporary, 'laws.json'), JSON.stringify(database, null, 2) + '\n');
36
+ try { await rename(temporary, directory); }
37
+ catch (error) {
38
+ // Another invocation may have initialized the same project while this
39
+ // one copied the legacy data. Its complete database takes precedence.
40
+ if (!['EEXIST', 'ENOTEMPTY'].includes(error.code) || await readOptional(file) === null) throw error;
41
+ }
42
+ } finally {
43
+ await rm(temporary, {recursive: true, force: true});
44
+ }
45
+ return {directory, file, database: parseDatabase(await readFile(file, 'utf8'))};
46
+ }
package/index.d.ts CHANGED
@@ -7,7 +7,12 @@ export type Target =
7
7
  'go' |
8
8
  'haskell' |
9
9
  'kotlin' |
10
- 'rust';
10
+ 'rust' |
11
+ 'erlang' |
12
+ 'elixir' |
13
+ 'gleam' |
14
+ 'fsharp' |
15
+ 'csharp';
11
16
 
12
17
  export interface Source {
13
18
  path: string;
@@ -207,12 +212,18 @@ export interface NativeGoImport {
207
212
  path: string;
208
213
  }
209
214
 
215
+ export interface NativeErlangInclude {
216
+ path: string;
217
+ library?: boolean;
218
+ }
219
+
210
220
  export interface NativeBindings {
211
221
  types?: NativeTypeBinding[];
212
222
  generators?: NativeGeneratorBinding[];
213
223
  functions?: NativeFunctionBinding[];
214
224
  rustCrate?: string;
215
225
  goImports?: NativeGoImport[];
226
+ erlangIncludes?: NativeErlangInclude[];
216
227
  }
217
228
 
218
229
  export type DischargeStatus =
@@ -231,6 +242,37 @@ export interface ObligationEvidence {
231
242
  status: DischargeStatus;
232
243
  reason: string;
233
244
  claim: Expr | null;
245
+ environment?: string;
246
+ environmentRun?: AttestedRun;
247
+ against?: AttestedDependency[];
248
+ }
249
+
250
+ export interface AttestedRun {
251
+ id: string;
252
+ startedAt: string;
253
+ recordedAt: string;
254
+ }
255
+
256
+ export interface AttestedStandIn {
257
+ identity: string;
258
+ version: string;
259
+ conformance: string;
260
+ historyDigest?: string;
261
+ }
262
+
263
+ export interface AttestedDependency {
264
+ dependency: string;
265
+ endpoint: string;
266
+ reached: boolean;
267
+ kind: 'real' | 'stand-in';
268
+ standIn?: AttestedStandIn;
269
+ }
270
+
271
+ export interface AttestationView {
272
+ environment: string;
273
+ run: AttestedRun;
274
+ producer?: PackageVersion;
275
+ dependencies: (AttestedDependency & {obligations: string[]})[];
234
276
  }
235
277
 
236
278
  export interface PackageVersion {
@@ -262,6 +304,7 @@ export interface CheckRequest {
262
304
  dependencies?: Record<string, string>;
263
305
  packages?: Package[];
264
306
  cacheDirectory?: string;
307
+ attestation?: unknown;
265
308
  }
266
309
 
267
310
  export interface GenerationRequest extends CheckRequest {
@@ -285,6 +328,7 @@ export interface Result {
285
328
  expansions?: string[];
286
329
  files?: Artifact[];
287
330
  evidence?: ObligationEvidence[];
331
+ attestation?: AttestationView;
288
332
  packages?: PackageView[];
289
333
  project?: {package?: PackageVersion; dependencies: Record<string, string>;};
290
334
  }
@@ -33,6 +33,9 @@ export async function exportNativePayments(options, selected) {
33
33
  const config = JSON.parse(files['lawspec.json']);
34
34
  config.machineBits = options.machineBits ?? 64;
35
35
  files['lawspec.json'] = JSON.stringify(config, null, options.minify ? undefined : 2) + '\n';
36
+ const instructions = target === 'gleam' ? setup[target].replace(
37
+ 'Prepare dependencies with gleam build, then run gleam test.',
38
+ 'Prepare dependencies with node prepare.mjs before generation, then run gleam test.') : setup[target];
36
39
  files['README.md'] = `# Native payments: ${target}
37
40
 
38
41
  This project checks application-owned payment types against the shared LawSpec
@@ -45,11 +48,13 @@ Install LawSpec and the native dependencies described below, then run:
45
48
 
46
49
  \`\`\`sh
47
50
  lawspec check
48
- lawspec generate
51
+ ${target === 'gleam' ? 'node prepare.mjs\n' : ''}lawspec generate
49
52
  ${commands[target]}
50
53
  \`\`\`
51
54
 
52
- ${setup[target]}
55
+ ${instructions}
56
+
57
+ ${target === 'gleam' ? 'The preparation command compiles dependencies in a temporary project using\nyour dependency requirements and lock file. It leaves application sources in\nplace, so their imports can be resolved after LawSpec generates the runtime.\n' : ''}
53
58
 
54
59
  JavaScript and TypeScript projects require \`npm install\` before testing.
55
60
  The specification includes exact decimal arithmetic and explicit USD/GBP examples.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lawspec",
3
- "version": "0.21.0",
3
+ "version": "0.23.0",
4
4
  "description": "State the law once. Check it everywhere.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -35,7 +35,7 @@
35
35
  "examples"
36
36
  ],
37
37
  "scripts": {
38
- "prepack": "cp ../README.md ../CHANGELOG.md .",
38
+ "prepack": "for f in README.md CHANGELOG.md; do cmp -s ../$f $f || { cp ../$f .$f.$$ && mv -f .$f.$$ $f; }; done",
39
39
  "test": "node --test test/*.test.mjs"
40
40
  }
41
41
  }