functionalscript 0.38.0 → 0.40.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 (137) hide show
  1. package/README.md +1 -1
  2. package/fjs/bnf/descent/module.f.d.ts +43 -2
  3. package/fjs/bnf/descent/module.f.js +37 -12
  4. package/fjs/bnf/descent/proof.f.d.ts +1 -0
  5. package/fjs/bnf/descent/proof.f.js +73 -32
  6. package/fjs/bnf/ll1/module.f.js +2 -2
  7. package/fjs/bnf/token_symbol/module.f.d.ts +38 -0
  8. package/fjs/bnf/token_symbol/module.f.js +48 -0
  9. package/fjs/bnf/token_symbol/proof.f.d.ts +10 -0
  10. package/fjs/bnf/token_symbol/proof.f.js +37 -0
  11. package/fjs/cas/cli/module.f.js +6 -9
  12. package/fjs/cas/evo/module.f.d.ts +77 -13
  13. package/fjs/cas/evo/module.f.js +130 -18
  14. package/fjs/cas/evo/proof.f.d.ts +7 -0
  15. package/fjs/cas/evo/proof.f.js +120 -1
  16. package/fjs/cas/module.f.js +64 -37
  17. package/fjs/cas/proof.f.d.ts +3 -9
  18. package/fjs/cas/proof.f.js +94 -74
  19. package/fjs/ci/bun/module.f.js +3 -3
  20. package/fjs/ci/common/module.f.d.ts +1 -2
  21. package/fjs/ci/common/module.f.js +1 -5
  22. package/fjs/ci/config/module.f.d.ts +11 -8
  23. package/fjs/ci/config/module.f.js +24 -9
  24. package/fjs/ci/deno/module.f.js +3 -3
  25. package/fjs/ci/module.f.js +13 -7
  26. package/fjs/ci/nix/module.f.d.ts +61 -0
  27. package/fjs/ci/nix/module.f.js +92 -0
  28. package/fjs/ci/nix/proof.f.d.ts +23 -0
  29. package/fjs/ci/nix/proof.f.js +109 -0
  30. package/fjs/ci/node/module.f.d.ts +23 -1
  31. package/fjs/ci/node/module.f.js +58 -12
  32. package/fjs/ci/proof.f.d.ts +2 -0
  33. package/fjs/ci/proof.f.js +49 -9
  34. package/fjs/cli/module.f.js +2 -2
  35. package/fjs/common/monoid/module.f.d.ts +46 -2
  36. package/fjs/common/monoid/module.f.js +44 -0
  37. package/fjs/common/monoid/proof.f.d.ts +5 -0
  38. package/fjs/common/monoid/proof.f.js +27 -1
  39. package/fjs/dev/module.f.d.ts +1 -0
  40. package/fjs/dev/module.f.js +38 -27
  41. package/fjs/dev/update/module.f.d.ts +11 -0
  42. package/fjs/dev/update/module.f.js +20 -0
  43. package/fjs/dev/update/proof.f.d.ts +7 -0
  44. package/fjs/dev/update/proof.f.js +35 -0
  45. package/fjs/djs/ast/module.f.d.ts +47 -0
  46. package/fjs/djs/ast/module.f.js +9 -0
  47. package/fjs/djs/module.f.js +5 -8
  48. package/fjs/djs/parser/module.f.d.ts +3 -0
  49. package/fjs/djs/parser/module.f.js +17 -0
  50. package/fjs/djs/tokenizer/module.f.js +2 -2
  51. package/fjs/djs/tokenizer/proof.f.d.ts +1 -0
  52. package/fjs/djs/tokenizer/proof.f.js +70 -16
  53. package/fjs/djs/transpiler/module.f.js +6 -6
  54. package/fjs/effects/eff/module.f.d.ts +72 -0
  55. package/fjs/effects/eff/module.f.js +46 -0
  56. package/fjs/effects/eff/proof.f.d.ts +11 -0
  57. package/fjs/effects/eff/proof.f.js +58 -0
  58. package/fjs/effects/list/module.f.d.ts +11 -5
  59. package/fjs/effects/list/module.f.js +2 -1
  60. package/fjs/effects/memory/proof.f.js +7 -8
  61. package/fjs/effects/module.f.d.ts +334 -52
  62. package/fjs/effects/module.f.js +253 -45
  63. package/fjs/effects/node/memory/proof.js +3 -2
  64. package/fjs/effects/node/module.d.ts +3 -3
  65. package/fjs/effects/node/module.f.d.ts +18 -8
  66. package/fjs/effects/node/module.f.js +31 -11
  67. package/fjs/effects/node/module.js +12 -12
  68. package/fjs/effects/node/proof.f.d.ts +1 -0
  69. package/fjs/effects/node/proof.f.js +32 -11
  70. package/fjs/effects/node/virtual/module.f.js +1 -1
  71. package/fjs/effects/proof.f.d.ts +32 -6
  72. package/fjs/effects/proof.f.js +131 -39
  73. package/fjs/emergent_testing/all.test.js +2 -1
  74. package/fjs/emergent_testing/module.f.d.ts +3 -3
  75. package/fjs/emergent_testing/module.f.js +63 -49
  76. package/fjs/emergent_testing/proof.f.d.ts +4 -0
  77. package/fjs/emergent_testing/proof.f.js +54 -21
  78. package/fjs/emergent_testing/scenarios/thenable.pass.js +1 -1
  79. package/fjs/fsc/module.f.js +4 -4
  80. package/fjs/fsm/module.f.js +1 -1
  81. package/fjs/js/tokenizer/module.f.d.ts +1 -0
  82. package/fjs/js/tokenizer/module.f.js +13 -6
  83. package/fjs/{cas/mcp → mcp/cas}/module.f.d.ts +3 -25
  84. package/fjs/{cas/mcp → mcp/cas}/module.f.js +26 -64
  85. package/fjs/mcp/evo/module.f.d.ts +27 -0
  86. package/fjs/mcp/evo/module.f.js +94 -0
  87. package/fjs/{cas/evo/mcp → mcp/evo}/proof.f.d.ts +2 -0
  88. package/fjs/{cas/evo/mcp → mcp/evo}/proof.f.js +40 -9
  89. package/fjs/mcp/module.f.d.ts +54 -237
  90. package/fjs/mcp/module.f.js +55 -258
  91. package/fjs/mcp/proof.f.d.ts +43 -32
  92. package/fjs/mcp/proof.f.js +509 -200
  93. package/fjs/media/nix/module.f.d.ts +30 -0
  94. package/fjs/media/nix/module.f.js +166 -0
  95. package/fjs/media/nix/proof.f.d.ts +32 -0
  96. package/fjs/media/nix/proof.f.js +127 -0
  97. package/fjs/media/type/module.f.js +2 -2
  98. package/fjs/media/type/proof.f.js +7 -10
  99. package/fjs/module.f.js +5 -9
  100. package/fjs/protocol/json_rpc/module.f.d.ts +114 -0
  101. package/fjs/{media/json/rpc → protocol/json_rpc}/module.f.js +3 -3
  102. package/fjs/{media/json/rpc → protocol/json_rpc}/proof.f.js +3 -3
  103. package/fjs/protocol/mcp/module.f.d.ts +239 -0
  104. package/fjs/protocol/mcp/module.f.js +272 -0
  105. package/fjs/protocol/mcp/proof.f.d.ts +34 -0
  106. package/fjs/protocol/mcp/proof.f.js +208 -0
  107. package/fjs/{mcp → protocol/mcp}/stdio/module.f.d.ts +7 -7
  108. package/fjs/{mcp → protocol/mcp}/stdio/module.f.js +22 -22
  109. package/fjs/{mcp → protocol/mcp}/stdio/proof.f.js +9 -9
  110. package/fjs/types/bigint/module.f.js +4 -3
  111. package/fjs/types/bit_vec/module.f.js +5 -15
  112. package/fjs/types/btree/remove/module.f.d.ts +5 -0
  113. package/fjs/types/btree/remove/module.f.js +12 -0
  114. package/fjs/types/list/module.f.d.ts +21 -0
  115. package/fjs/types/list/module.f.js +17 -0
  116. package/fjs/types/list/proof.f.d.ts +1 -0
  117. package/fjs/types/list/proof.f.js +24 -1
  118. package/fjs/types/number/module.f.js +2 -1
  119. package/fjs/types/range_map/module.f.d.ts +14 -13
  120. package/fjs/types/range_map/module.f.js +18 -13
  121. package/fjs/types/range_map/proof.f.js +26 -39
  122. package/fjs/types/range_set/module.f.d.ts +5 -0
  123. package/fjs/types/range_set/module.f.js +16 -0
  124. package/fjs/types/range_set/proof.f.d.ts +1 -0
  125. package/fjs/types/range_set/proof.f.js +19 -0
  126. package/fjs/types/string/module.f.js +10 -2
  127. package/fjs/website/module.f.js +2 -3
  128. package/package.json +5 -5
  129. package/fjs/cas/evo/mcp/module.f.d.ts +0 -19
  130. package/fjs/cas/evo/mcp/module.f.js +0 -56
  131. package/fjs/cas/mcp/proof.f.d.ts +0 -45
  132. package/fjs/cas/mcp/proof.f.js +0 -545
  133. package/fjs/ci/playwright/module.f.d.ts +0 -2
  134. package/fjs/ci/playwright/module.f.js +0 -25
  135. package/fjs/media/json/rpc/module.f.d.ts +0 -114
  136. /package/fjs/{media/json/rpc → protocol/json_rpc}/proof.f.d.ts +0 -0
  137. /package/fjs/{mcp → protocol/mcp}/stdio/proof.f.d.ts +0 -0
@@ -1,545 +0,0 @@
1
- import { assert, assertEq } from '../../asserts/module.f.js';
2
- import { pure } from '../../effects/module.f.js';
3
- import { run } from '../../effects/mock/module.f.js';
4
- import { asBase, asNominal, create } from '../../effects/memory/module.f.js';
5
- import { msb, u8ListToVec, vec8, repeat, length, maxLengthBytes } from '../../types/bit_vec/module.f.js';
6
- import { vecToCBase32 } from '../../basen/cbase32/module.f.js';
7
- import { encode as base64Encode } from '../../basen/base64/module.f.js';
8
- import { utf8 } from '../../text/module.f.js';
9
- import { fileCas } from '../module.f.js';
10
- import { dialect as revisionDialect, mediaType as revisionMediaType } from '../../media/revision/module.f.js';
11
- import { sha256 } from '../../crypto/sha2/module.f.js';
12
- import { nonEmpty, empty as elEmpty } from '../../effects/list/module.f.js';
13
- import { mcpStep, uninitializedState, } from '../../mcp/module.f.js';
14
- import { emptyState, virtual } from '../../effects/node/virtual/module.f.js';
15
- import { casConfig, casMcpHandlers } from './module.f.js';
16
- import { ok as resultOk } from '../../types/result/module.f.js';
17
- import { stdioTransport } from '../../mcp/stdio/module.f.js';
18
- import { fromVec } from '../../types/uint8array/module.f.js';
19
- import { initEvo } from '../evo/module.f.js';
20
- const initialTestState = { memory: { next: 0, values: {} } };
21
- const mock = {
22
- memCreate: value => state => {
23
- const id = `k${state.memory.next}`;
24
- const key = asNominal(id);
25
- return [
26
- { ...state, memory: { next: state.memory.next + 1, values: { ...state.memory.values, [id]: value } } },
27
- key,
28
- ];
29
- },
30
- memRead: key => state => [state, state.memory.values[asBase(key)]],
31
- memWrite: (key, value) => state => {
32
- const id = asBase(key);
33
- return [{ ...state, memory: { ...state.memory, values: { ...state.memory.values, [id]: value } } }, undefined];
34
- },
35
- mkdir: (_path, _opts) => state => [state, resultOk(undefined)],
36
- rename: (_src, _dst) => _ => { throw new Error('rename not supported in memory mock'); },
37
- readBytes: (_path, _offset, _size) => _ => { throw new Error('readBytes not supported in memory mock'); },
38
- randomInt: () => _ => { throw new Error('randomInt not supported in memory mock'); },
39
- now: () => state => [state, 0],
40
- access: (_path) => _ => { throw new Error('access not supported in memory mock'); },
41
- createExclusive: (_path) => _ => { throw new Error('createExclusive not supported in memory mock'); },
42
- readdir: (_path, _opts) => _ => { throw new Error('readdir not supported in memory mock'); },
43
- rm: (_path) => _ => { throw new Error('rm not supported in memory mock'); },
44
- stat: (_path) => _ => { throw new Error('stat not supported in memory mock'); },
45
- writeBytes: (_path, _offset, _data) => _ => { throw new Error('writeBytes not supported in memory mock'); },
46
- };
47
- const runMem = (effect) => run(mock)(initialTestState)(effect)[1];
48
- // ── Session driver ──────────────────────────────────────────────────────────────
49
- // Feeds each message to `step` in order, collecting every response.
50
- const feed = (step) => (msgs) => {
51
- const go = (i, acc) => i === msgs.length
52
- ? pure(acc)
53
- : step(msgs[i]).step(r => go(i + 1, [...acc, r]));
54
- return go(0, []);
55
- };
56
- // Runs a session backed by the virtual node runner (for cas_upload which uses
57
- // Rename/ReadBytes/RandomInt/Mkdir). Uses fileKvStore so upload and get share
58
- // the same filesystem-backed CAS.
59
- const runSessionVirtual = (root, home = '/home/user') => (msgs) => {
60
- const effect = initEvo(fileCas(sha256)(home)).step(cacheKey => create(uninitializedState).step(sessionKey => {
61
- const step = mcpStep(casConfig)(casMcpHandlers(home)(cacheKey))(sessionKey);
62
- return feed(step)(msgs);
63
- }));
64
- return virtual({ ...emptyState, root })(effect)[1];
65
- };
66
- // Seeds a blob directly into the virtual store via `c.write`, bypassing the
67
- // MCP `cas_add` tool entirely — used by tests that need a stored blob larger
68
- // than `cas_add`'s inline limit, now that the removed `type:'url'` path is no
69
- // longer available to stage one through MCP. Returns the resulting root
70
- // `Dir` (with the new shard written) and the blob's cBase32 hash so a
71
- // subsequent `runSessionVirtual` call can read it back via `cas_get`.
72
- const seedBlob = (root, home = '/home/user') => (chunks) => {
73
- const c = fileCas(sha256)(home);
74
- const stream = chunks.reduceRight((tail, chunk) => nonEmpty(resultOk(chunk), tail), elEmpty());
75
- const [state, result] = virtual({ ...emptyState, root })(c.write(stream));
76
- assert(result[0] === 'ok', result);
77
- return [state.root, vecToCBase32(result[1])];
78
- };
79
- // ── Messages ────────────────────────────────────────────────────────────────────
80
- const init = { jsonrpc: '2.0', method: 'initialize', id: 1,
81
- params: { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'c', version: '0' } } };
82
- const initialized = { jsonrpc: '2.0', method: 'notifications/initialized' };
83
- const call = (id, name, args) => ({ jsonrpc: '2.0', method: 'tools/call', id, params: { name, arguments: args } });
84
- const list = (id) => ({ jsonrpc: '2.0', method: 'tools/list', id });
85
- // Runs `init`, `notifications/initialized`, then `msgs`; returns the tool responses.
86
- const session = (...msgs) => runSessionVirtual({}, '/home/user')([init, initialized, ...msgs]).slice(2);
87
- // UTF-8 bytes of `s` as a plain array — the virtual stdin byte stream.
88
- const toBytes = (s) => [...fromVec(utf8(s))];
89
- // Runs `init`, `notifications/initialized`, then `msgs` through the *real*
90
- // stdio pipeline — `mcpStep` wrapped in `stdioTransport`, driving
91
- // `writeResponse`'s `tryUtf8` encode over actual stdin/stdout bytes. Unlike
92
- // `session`/`runSessionVirtual`, which collect `mcpStep`'s `Response` values
93
- // as plain JS objects and never serialize/encode them, this is the only
94
- // helper that can observe the transport's oversized-response fallback (see
95
- // `fjs/mcp/stdio/module.f.ts` `writeResponse`).
96
- const runStdio = (root, home = '/home/user') => (msgs) => {
97
- const input = [init, initialized, ...msgs].map(m => JSON.stringify(m)).join('\n') + '\n';
98
- const effect = initEvo(fileCas(sha256)(home)).step(cacheKey => create(uninitializedState).step(sessionKey => stdioTransport(mcpStep(casConfig)(casMcpHandlers(home)(cacheKey))(sessionKey))));
99
- const stdout = virtual({ ...emptyState, root, stdin: toBytes(input) })(effect)[0].stdout;
100
- // Only requests get a written line (notifications, like `initialized`,
101
- // write nothing) — drop the `init` response, keep one line per `msgs` entry.
102
- return stdout.split('\n').filter(line => line.length > 0).slice(1).map(line => JSON.parse(line));
103
- };
104
- const resultOf = (resp) => resp.result;
105
- const item0 = (resp) => resultOf(resp).content[0];
106
- const textOf = (resp) => item0(resp).text;
107
- // A plain text sample for text add→get round-trips.
108
- const textSample = 'hello, world!';
109
- // A valid `vnd.fjs.revision` blob: every required field present, including the
110
- // explicit `snapshot` and `generation` the format now mandates.
111
- const revisionSample = `{"dialect":"${revisionDialect}","subject":"8","parents":[],"snapshot":"8","generation":0}`;
112
- // A base64-encoded binary payload for binary add→get round-trips.
113
- const binarySample = base64Encode(vec8(0x2an));
114
- // A base64 blob whose leading bytes are the PNG magic-byte signature, so
115
- // `cas_get` detects its type and returns base64 with mimeType image/png.
116
- const pngSample = base64Encode(u8ListToVec(msb)([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x01]));
117
- // Returns the RFC 4648 base64 encoding of `n` zero bytes, computed directly
118
- // without bigint arithmetic — independent of `base64.encode` so these tests
119
- // don't rely on the correctness of the function they're indirectly exercising
120
- // (`cas_add` decodes the string via `base64.decode`). Handles every n%3
121
- // residue: rem=0 → no padding, rem=1 → 'AA==', rem=2 → 'AAA='.
122
- const base64OfA = (n) => {
123
- const groups = Number(n / 3n);
124
- const rem = Number(n % 3n);
125
- const body = 'AAAA'.repeat(groups);
126
- if (rem === 0) {
127
- return body;
128
- }
129
- if (rem === 1) {
130
- return body + 'AA==';
131
- }
132
- return body + 'AAA=';
133
- };
134
- // ── Tests ───────────────────────────────────────────────────────────────────────
135
- // A blob larger than one read chunk (> 128 KiB) used to fail metadata-only
136
- // cas_get because `collectRead` overflowed `maxLength`. With `detectStream`,
137
- // content:false returns correct metadata regardless of size. Each chunk is
138
- // exactly `maxLengthBytes` (the largest single `Vec` the runtime allows), so the
139
- // two-chunk blob spans two read chunks without any one `Vec` exceeding the cap.
140
- const largeMultiChunkBlobMeta = (chunk0, chunk1, expectedType, expectedMime) => () => {
141
- const [root, hash] = seedBlob({})([chunk0, chunk1]);
142
- const [metaResp] = runSessionVirtual(root)([
143
- init, initialized,
144
- call(2, 'cas_get', { hash }),
145
- ]).slice(2);
146
- assert(!resultOf(metaResp).isError);
147
- const meta = JSON.parse(textOf(metaResp));
148
- assertEq(meta.type, expectedType);
149
- assertEq(meta.mimeType, expectedMime);
150
- assertEq(meta.length, Number((length(chunk0) + length(chunk1)) / 8n));
151
- assertEq(meta.text, undefined);
152
- assertEq(meta.blob, undefined);
153
- };
154
- // A full `maxLengthBytes`-long chunk of repeated ASCII 'a' — valid UTF-8.
155
- const asciiChunk = repeat(maxLengthBytes)(vec8(0x61n));
156
- // The same length, but repeated 2-byte "é" (C3 A9) — valid UTF-8 of multi-byte symbols.
157
- const symbolChunk = repeat(maxLengthBytes / 2n)(u8ListToVec(msb)([0xc3, 0xa9]));
158
- // A full chunk of 0xFF — an invalid UTF-8 lead byte, so binary (no magic match).
159
- const binaryChunk = repeat(maxLengthBytes)(vec8(0xffn));
160
- // 100,000 raw bytes of 0xFF: comfortably under `maxLengthBytes` (so `cas_get`'s
161
- // own `length > maxLengthBytes` guard does not fire), but base64 inflates it to
162
- // ceil(100_000/3)*4 = 133,336 chars — already past `maxLength` (131,072 bytes)
163
- // before the JSON-RPC envelope adds anything.
164
- const oversizedBase64Chunk = repeat(100000n)(vec8(0xffn));
165
- // 90,000 raw bytes: base64 inflates to 120,000 chars, leaving ~11 KiB of margin
166
- // under `maxLength` once the envelope is added — the paired "still succeeds" case.
167
- const boundaryBase64Chunk = repeat(90000n)(vec8(0xffn));
168
- // 33,000 `"` bytes (0x22): valid UTF-8, so `cas_get` classifies it as text and
169
- // takes the double-JSON-escaping path (`toJson` builds the inner CAS JSON, then
170
- // the outer `stringifyJson` embeds that as the `text` field). Each quote costs
171
- // 4 final bytes (2 on each escaping pass), so 33,000 of them alone push the
172
- // encoded line past `maxLength` (131,072 bytes) — well above the strict 32,769
173
- // minimum needed, without approaching any other size-related edge case.
174
- const quotesChunk = repeat(33000n)(vec8(0x22n));
175
- export const proof = {
176
- // Both chunks repeated ASCII → text/plain, no error on a > 128 KiB blob.
177
- getMetaLargeMultiChunkBlobNoError: largeMultiChunkBlobMeta(asciiChunk, asciiChunk, 'text', 'text/plain'),
178
- // Both chunks valid UTF-8 sequences of multi-byte symbols → text/plain.
179
- getMetaLargeMultiChunkUtf8Symbols: largeMultiChunkBlobMeta(symbolChunk, symbolChunk, 'text', 'text/plain'),
180
- // First chunk valid UTF-8, second chunk binary → base64/octet-stream. The
181
- // streaming validator must see the trailing binary chunk to reject text.
182
- getMetaLargeMultiChunkTextThenBinary: largeMultiChunkBlobMeta(asciiChunk, binaryChunk, 'base64', 'application/octet-stream'),
183
- // content:true on a present blob larger than `maxLength` reports a distinct
184
- // "too large" error, not "no such hash" — the blob exists, it just can't be
185
- // buffered inline. The metadata-only path (above) still returns its size/type.
186
- getContentLargeBlobTooLargeError: () => {
187
- const [root, hash] = seedBlob({})([asciiChunk, asciiChunk]);
188
- const [getResp] = runSessionVirtual(root)([
189
- init, initialized,
190
- call(2, 'cas_get', { hash, content: true }),
191
- ]).slice(2);
192
- assertEq(resultOf(getResp).isError, true);
193
- const text = textOf(getResp);
194
- assert(text.includes('too large'));
195
- assert(!text.includes('no such hash'));
196
- },
197
- // content:true on a genuinely absent hash still reports "no such hash" — the
198
- // oversized branch above must not absorb the absent case.
199
- getContentMissingHashIsError: () => {
200
- const absent = vecToCBase32(vec8(0x55n));
201
- const [resp] = session(call(2, 'cas_get', { hash: absent, content: true }));
202
- assertEq(resultOf(resp).isError, true);
203
- assert(textOf(resp).includes('no such hash'));
204
- },
205
- // A blob at exactly `maxLengthBytes` passes cas_get's own raw-length guard
206
- // (it checks the *stored* size, not the encoded response), but base64
207
- // inflation of a 100,000-byte blob alone already exceeds `maxLength` before
208
- // the JSON-RPC envelope is even added. The transport's `writeResponse`
209
- // (`tryUtf8`) must catch this and write a JSON-RPC internal-error response —
210
- // carrying the *original request's* `id` — instead of crashing the process.
211
- // See `fjs/mcp/stdio/module.f.ts` `writeResponse`.
212
- //
213
- // This test originally timed out under `bun test`'s native 5s per-test
214
- // limit (12-14s observed in CI on PR #1201) — the cost was in
215
- // `base64Encode`, quadratic before the `baseN.vecToString` fix (see
216
- // `fjs/basen/base64/proof.f.ts` `encodeLargeVecIsSlow`). Now well under budget on
217
- // both engines.
218
- getContentBase64InflationOverflowWritesInternalError: () => {
219
- const [root, hash] = seedBlob({})([oversizedBase64Chunk]);
220
- const [getResp] = runStdio(root)([
221
- call(2, 'cas_get', { hash, content: true }),
222
- ]);
223
- const err = getResp;
224
- assertEq(err.error?.code, -32603);
225
- assertEq(err.id, 2);
226
- },
227
- // The paired boundary case: a blob whose base64 inflation leaves enough
228
- // margin under `maxLength` for the envelope — confirms the fallback above
229
- // only triggers on genuine overflow, not on every `content:true` binary read.
230
- getContentBase64NearBoundarySucceeds: () => {
231
- const [root, hash] = seedBlob({})([boundaryBase64Chunk]);
232
- const [getResp] = runStdio(root)([
233
- call(2, 'cas_get', { hash, content: true }),
234
- ]);
235
- assert(!resultOf(getResp).isError);
236
- const result = JSON.parse(textOf(getResp));
237
- assertEq(result.type, 'base64');
238
- assertEq(result.length, 90_000);
239
- },
240
- // A text blob made entirely of `"` characters keeps the *raw* content
241
- // (33,000 bytes) well under `maxLengthBytes`, but each quote costs 2 bytes on
242
- // the inner CAS-JSON escape and 4 bytes once the outer JSON-RPC envelope
243
- // re-escapes that backslash-quote pair — no `cas_get`-level size guard could
244
- // see this coming, only the transport's real encode attempt can. Seeded
245
- // directly into the store via `seedBlob` (not an inlined `cas_add` JSON
246
- // string) so the test exercises `cas_get`'s response-side escaping without
247
- // also paying for parsing a huge inline `content` argument on the request
248
- // side. Confirms `writeResponse`'s
249
- // `tryUtf8` fallback (not a crash) handles double-escaping overflow, again
250
- // preserving the request's `id`.
251
- getContentDoubleEscapedOverflowWritesInternalError: () => {
252
- const [root, hash] = seedBlob({})([quotesChunk]);
253
- const [getResp] = runStdio(root)([
254
- call(2, 'cas_get', { hash, content: true }),
255
- ]);
256
- const err = getResp;
257
- assertEq(err.error?.code, -32603);
258
- assertEq(err.id, 2);
259
- },
260
- toolsListAdvertisesSixTools: () => {
261
- const [resp] = runSessionVirtual({})([init, initialized, list(2)]).slice(2);
262
- const tools = resp.result.tools;
263
- assertEq(tools.length, 6);
264
- assertEq(tools.map(t => t.name).join(','), 'cas_add,cas_get,cas_list,evo_list,evo_head,evo_add');
265
- const add = resp.result.tools[0];
266
- assertEq(add.inputSchema.type, 'object');
267
- },
268
- // The same server also exposes Evo (fjs/cas/evo): add a revision, then
269
- // find it via evo_list/evo_head — one process, one store, one cache.
270
- evoAddListHeadRoundTripsThroughCasServer: () => {
271
- const [addResp, listResp, headResp] = session(call(2, 'evo_add', { parents: [], subject: 'doc', snapshot: vecToCBase32(vec8(0x1n)) }), call(3, 'evo_list', {}), call(4, 'evo_head', { subject: 'doc' }));
272
- assert(!resultOf(addResp).isError);
273
- const hash = textOf(addResp);
274
- assert(hash.length > 0);
275
- assertEq(textOf(listResp), '["doc"]');
276
- assertEq(textOf(headResp), hash);
277
- },
278
- evoAddDomainErrorIsErrorThroughCasServer: () => {
279
- // Valid arguments, but the domain rule fails: `subject` is required
280
- // unless there is exactly one parent.
281
- const [resp] = session(call(2, 'evo_add', { parents: [] }));
282
- assertEq(resultOf(resp).isError, true);
283
- assert(textOf(resp).includes('subject is required'));
284
- },
285
- // A plain `cas_add` of `vnd.fjs.revision` content is folded into the Evo
286
- // cache too (`syncRevision`), not just `evo_add` — `cas_add`/`evo_add`
287
- // are two ways to reach the same store and cache.
288
- casAddSyncsEvoCacheForRevisionContent: () => {
289
- const [addResp, listResp, headResp] = session(call(2, 'cas_add', { content: revisionSample }), call(3, 'evo_list', {}), call(4, 'evo_head', { subject: '8' }));
290
- assert(!resultOf(addResp).isError);
291
- const hash = textOf(addResp);
292
- assertEq(textOf(listResp), '["8"]');
293
- assertEq(textOf(headResp), hash);
294
- },
295
- addReturnsHash: () => {
296
- const [resp] = session(call(2, 'cas_add', { content: textSample }));
297
- assert(!resultOf(resp).isError);
298
- assert(textOf(resp).length > 0);
299
- },
300
- // Text add→get round-trip: store as UTF-8 text, retrieve metadata.
301
- textAddGetMetaRoundTrips: () => {
302
- const [addResp] = session(call(2, 'cas_add', { content: textSample }));
303
- const hash = textOf(addResp);
304
- const [, getResp] = session(call(2, 'cas_add', { content: textSample }), call(3, 'cas_get', { hash }));
305
- assert(!resultOf(getResp).isError);
306
- const result = JSON.parse(textOf(getResp));
307
- assertEq(result.mimeType, 'text/plain');
308
- assertEq(result.type, 'text');
309
- assertEq(result.length, textSample.length);
310
- assertEq(result.text, undefined);
311
- },
312
- // cas_get with content:true returns inline content.
313
- textAddGetContentRoundTrips: () => {
314
- const [addResp] = session(call(2, 'cas_add', { content: textSample }));
315
- const hash = textOf(addResp);
316
- const [, getResp] = session(call(2, 'cas_add', { content: textSample }), call(3, 'cas_get', { hash, content: true }));
317
- assert(!resultOf(getResp).isError);
318
- const result = JSON.parse(textOf(getResp));
319
- assertEq(result.type, 'text');
320
- assertEq(result.mimeType, 'text/plain');
321
- assertEq(result.text, textSample);
322
- },
323
- // Binary add→get round-trip: store as base64, retrieve metadata without content.
324
- binaryAddGetMetaRoundTrips: () => {
325
- const [addResp] = session(call(2, 'cas_add', { content: binarySample, type: 'base64' }));
326
- const hash = textOf(addResp);
327
- const [, getResp] = session(call(2, 'cas_add', { content: binarySample, type: 'base64' }), call(3, 'cas_get', { hash }));
328
- assert(!resultOf(getResp).isError);
329
- const result = JSON.parse(textOf(getResp));
330
- assertEq(result.text, undefined);
331
- assertEq(result.type, 'text');
332
- assertEq(result.mimeType, 'text/plain');
333
- },
334
- // Binary add→get with content:true returns inline base64 content.
335
- binaryAddGetContentRoundTrips: () => {
336
- const [addResp] = session(call(2, 'cas_add', { content: binarySample, type: 'base64' }));
337
- const hash = textOf(addResp);
338
- const [, getResp] = session(call(2, 'cas_add', { content: binarySample, type: 'base64' }), call(3, 'cas_get', { hash, content: true }));
339
- assert(!resultOf(getResp).isError);
340
- const result = JSON.parse(textOf(getResp));
341
- assertEq(result.type, 'text');
342
- assertEq(result.text, '*');
343
- },
344
- addGetRoundTrips: () => {
345
- const [addResp] = session(call(2, 'cas_add', { content: textSample }));
346
- const hash = textOf(addResp);
347
- const [, getResp] = session(call(2, 'cas_add', { content: textSample }), call(3, 'cas_get', { hash, content: true }));
348
- assert(!resultOf(getResp).isError);
349
- const result = JSON.parse(textOf(getResp));
350
- assertEq(result.text, textSample);
351
- },
352
- // Text content (no magic-byte match, valid UTF-8) comes back with type:'text' when content requested.
353
- getUntypedReturnsText: () => {
354
- const [addResp] = session(call(2, 'cas_add', { content: textSample }));
355
- const hash = textOf(addResp);
356
- const [, getResp] = session(call(2, 'cas_add', { content: textSample }), call(3, 'cas_get', { hash, content: true }));
357
- assertEq(item0(getResp) === null ? null : item0(getResp).type, 'text');
358
- const result = JSON.parse(textOf(getResp));
359
- assertEq(result.type, 'text');
360
- assertEq(result.mimeType, 'text/plain');
361
- },
362
- // Bytes with a recognised PNG signature come back as base64 with mimeType image/png when content requested.
363
- getTypedReturnsBinaryJson: () => {
364
- const [addResp] = session(call(2, 'cas_add', { content: pngSample, type: 'base64' }));
365
- const hash = textOf(addResp);
366
- const [, getResp] = session(call(2, 'cas_add', { content: pngSample, type: 'base64' }), call(3, 'cas_get', { hash, content: true }));
367
- assert(!resultOf(getResp).isError);
368
- assertEq(item0(getResp).type, 'text');
369
- const result = JSON.parse(textOf(getResp));
370
- assertEq(result.type, 'base64');
371
- assertEq(result.mimeType, 'image/png');
372
- assertEq(result.blob, pngSample);
373
- },
374
- // A stored `vnd.fjs.revision` blob is recognized by metadata-only
375
- // `cas_get` (content:false, the default) — the CAS read path routes the
376
- // bounded, whole-blob-text case through the dialect-aware detector rather
377
- // than only reporting the streaming text/plain verdict.
378
- getMetaRecognizesRevisionDialect: () => {
379
- const [addResp] = session(call(2, 'cas_add', { content: revisionSample }));
380
- const hash = textOf(addResp);
381
- const [, metaResp] = session(call(2, 'cas_add', { content: revisionSample }), call(3, 'cas_get', { hash }));
382
- assert(!resultOf(metaResp).isError);
383
- const meta = JSON.parse(textOf(metaResp));
384
- assertEq(meta.mimeType, revisionMediaType);
385
- assertEq(meta.type, 'text');
386
- },
387
- // Same dialect recognition on the `content: true` path, alongside the
388
- // inline text payload.
389
- getContentRecognizesRevisionDialect: () => {
390
- const [addResp] = session(call(2, 'cas_add', { content: revisionSample }));
391
- const hash = textOf(addResp);
392
- const [, getResp] = session(call(2, 'cas_add', { content: revisionSample }), call(3, 'cas_get', { hash, content: true }));
393
- assert(!resultOf(getResp).isError);
394
- const result = JSON.parse(textOf(getResp));
395
- assertEq(result.mimeType, revisionMediaType);
396
- assertEq(result.type, 'text');
397
- assertEq(result.text, revisionSample);
398
- },
399
- listEnumeratesStoredHashes: () => {
400
- const [addResp, listResp] = session(call(2, 'cas_add', { content: textSample }), call(3, 'cas_list', {}));
401
- const hash = textOf(addResp);
402
- assert(!resultOf(listResp).isError);
403
- assertEq(textOf(listResp), hash);
404
- },
405
- addInvalidContentIsError: () => {
406
- const [resp] = session(call(2, 'cas_add', { content: 'not valid!', type: 'base64' }));
407
- assertEq(resultOf(resp).isError, true);
408
- },
409
- addBadLengthContentIsError: () => {
410
- const [resp] = session(call(2, 'cas_add', { content: 'A', type: 'base64' }));
411
- assertEq(resultOf(resp).isError, true);
412
- },
413
- // 174_764 'A' chars × 6 bits = 1_048_584 bits, 8 over maxLength — base64Decode
414
- // returns null and cas_add surfaces an error.
415
- addBase64OverLimitIsError: () => {
416
- const [resp] = session(call(2, 'cas_add', { content: 'A'.repeat(174_764), type: 'base64' }));
417
- assertEq(resultOf(resp).isError, true);
418
- assert(textOf(resp).includes('too large or malformed'));
419
- assert(textOf(resp).includes('cas add'));
420
- },
421
- // One ASCII byte past maxLengthBytes — tryUtf8 returns null and cas_add
422
- // surfaces an error.
423
- addTextOverLimitIsError: () => {
424
- const [resp] = session(call(2, 'cas_add', { content: 'a'.repeat(Number(maxLengthBytes) + 1) }));
425
- assertEq(resultOf(resp).isError, true);
426
- assert(textOf(resp).includes('too large or malformed'));
427
- assert(textOf(resp).includes('cas add'));
428
- },
429
- // Exactly maxLengthBytes (131,072) ASCII bytes — tryUtf8 returns a non-null
430
- // Vec (len === maxLength, not over), so cas_add stores cleanly.
431
- addTextAtLimitSucceeds: () => {
432
- const [resp] = session(call(2, 'cas_add', { content: 'a'.repeat(Number(maxLengthBytes)) }));
433
- assert(!resultOf(resp).isError);
434
- assert(textOf(resp).length > 0);
435
- },
436
- // base64 of exactly maxLengthBytes — base64Decode trims the encoding's
437
- // padding bits from the last character before measuring the result
438
- // against maxLength, so a payload landing exactly at the limit decodes
439
- // and stores cleanly.
440
- addBase64AtLimitSucceeds: () => {
441
- const [resp] = session(call(2, 'cas_add', { content: base64OfA(maxLengthBytes), type: 'base64' }));
442
- assert(!resultOf(resp).isError);
443
- assert(textOf(resp).length > 0);
444
- },
445
- getUnterminatedHashIsError: () => {
446
- const [resp] = session(call(2, 'cas_get', { hash: '0' }));
447
- assertEq(resultOf(resp).isError, true);
448
- },
449
- addMissingContentIsError: () => {
450
- const [resp] = session(call(2, 'cas_add', {}));
451
- assertEq(resultOf(resp).isError, true);
452
- },
453
- getMissingHashArgumentIsError: () => {
454
- const [resp] = session(call(2, 'cas_get', {}));
455
- assertEq(resultOf(resp).isError, true);
456
- },
457
- getInvalidHashIsError: () => {
458
- const [resp] = session(call(2, 'cas_get', { hash: 'not valid!' }));
459
- assertEq(resultOf(resp).isError, true);
460
- },
461
- getMissingHashIsError: () => {
462
- const absent = vecToCBase32(vec8(0x99n));
463
- const [resp] = session(call(2, 'cas_get', { hash: absent }));
464
- assertEq(resultOf(resp).isError, true);
465
- },
466
- unknownToolIsError: () => {
467
- const [resp] = session(call(2, 'cas_remove', { hash: binarySample }));
468
- assertEq(resultOf(resp).isError, true);
469
- },
470
- toolErrorIsNotJsonRpcError: () => {
471
- const [resp] = session(call(2, 'cas_add', { content: 'not valid!', type: 'base64' }));
472
- assert(!('error' in resp));
473
- assert('result' in resp);
474
- },
475
- // cas_get without content:true returns only metadata.
476
- getMetaReturnsLengthAndMimeType: () => {
477
- const [addResp] = session(call(2, 'cas_add', { content: 'text content' }));
478
- const hash = textOf(addResp);
479
- const [, metaResp] = session(call(2, 'cas_add', { content: 'text content' }), call(3, 'cas_get', { hash }));
480
- assert(!resultOf(metaResp).isError);
481
- const meta = JSON.parse(textOf(metaResp));
482
- assertEq(meta.mimeType, 'text/plain');
483
- assertEq(meta.type, 'text');
484
- assertEq(meta.length, 12);
485
- assertEq(meta.text, undefined);
486
- },
487
- getMetaBinaryBlob: () => {
488
- const [addResp] = session(call(2, 'cas_add', { content: pngSample, type: 'base64' }));
489
- const hash = textOf(addResp);
490
- const [, metaResp] = session(call(2, 'cas_add', { content: pngSample, type: 'base64' }), call(3, 'cas_get', { hash }));
491
- assert(!resultOf(metaResp).isError);
492
- const meta = JSON.parse(textOf(metaResp));
493
- assertEq(meta.mimeType, 'image/png');
494
- assertEq(meta.type, 'base64');
495
- assertEq(meta.length, 10);
496
- assertEq(meta.blob, undefined);
497
- },
498
- getMetaOctetStreamForUnknownBinary: () => {
499
- const binaryContent = u8ListToVec(msb)([0xFF, 0xFE, 0x00, 0x01]);
500
- const binaryB64 = base64Encode(binaryContent);
501
- const [addResp] = session(call(2, 'cas_add', { content: binaryB64, type: 'base64' }));
502
- const hash = textOf(addResp);
503
- const [, metaResp] = session(call(2, 'cas_add', { content: binaryB64, type: 'base64' }), call(3, 'cas_get', { hash }));
504
- assert(!resultOf(metaResp).isError);
505
- const meta = JSON.parse(textOf(metaResp));
506
- assertEq(meta.mimeType, 'application/octet-stream');
507
- assertEq(meta.type, 'base64');
508
- assertEq(meta.blob, undefined);
509
- },
510
- // A NUL-bearing blob is valid UTF-8 yet binary: cas_get must report
511
- // base64/octet-stream, not text/plain.
512
- getMetaOctetStreamForNulBlob: () => {
513
- const nulContent = u8ListToVec(msb)([0x00, 0x00, 0x00]);
514
- const nulB64 = base64Encode(nulContent);
515
- const [addResp] = session(call(2, 'cas_add', { content: nulB64, type: 'base64' }));
516
- const hash = textOf(addResp);
517
- const [, metaResp] = session(call(2, 'cas_add', { content: nulB64, type: 'base64' }), call(3, 'cas_get', { hash }));
518
- assert(!resultOf(metaResp).isError);
519
- const meta = JSON.parse(textOf(metaResp));
520
- assertEq(meta.mimeType, 'application/octet-stream');
521
- assertEq(meta.type, 'base64');
522
- },
523
- getMetaMissingHashIsError: () => {
524
- const absent = vecToCBase32(vec8(0x77n));
525
- const [resp] = session(call(2, 'cas_get', { hash: absent }));
526
- assertEq(resultOf(resp).isError, true);
527
- },
528
- getMetaInvalidHashIsError: () => {
529
- const [resp] = session(call(2, 'cas_get', { hash: 'bad!' }));
530
- assertEq(resultOf(resp).isError, true);
531
- },
532
- // cas_get with content:true on octet-stream (no magic bytes, not UTF-8) returns inline base64.
533
- getOctetStreamWithContentIncludesBase64: () => {
534
- const binaryContent = u8ListToVec(msb)([0xFF, 0xFE, 0x00, 0x01]);
535
- const binaryB64 = base64Encode(binaryContent);
536
- const [addResp] = session(call(2, 'cas_add', { content: binaryB64, type: 'base64' }));
537
- const hash = textOf(addResp);
538
- const [, getResp] = session(call(2, 'cas_add', { content: binaryB64, type: 'base64' }), call(3, 'cas_get', { hash, content: true }));
539
- assert(!resultOf(getResp).isError);
540
- const result = JSON.parse(textOf(getResp));
541
- assertEq(result.mimeType, 'application/octet-stream');
542
- assertEq(result.type, 'base64');
543
- assertEq(result.blob, binaryB64);
544
- },
545
- };
@@ -1,2 +0,0 @@
1
- import { type Job } from '../common/module.f.ts';
2
- export declare const playwrightJob: Job;
@@ -1,25 +0,0 @@
1
- /**
2
- * CI job that installs Playwright (with a browser-cache step) and runs the
3
- * test suite against Chromium, Firefox, and WebKit.
4
- *
5
- * @module
6
- */
7
- import { images, node, playwright } from '../config/module.f.js';
8
- import { install, test, toSteps, uses } from '../common/module.f.js';
9
- import { basicNode } from '../node/module.f.js';
10
- const playwrightImage = images.ubuntu.arm;
11
- export const playwrightJob = {
12
- 'runs-on': playwrightImage,
13
- steps: toSteps(basicNode(node.default)([
14
- install(uses('actions/cache', {
15
- path: '~/.cache/ms-playwright',
16
- key: `${playwrightImage}-playwright-${playwright}`,
17
- })),
18
- install({ run: `npm install -g playwright@${playwright}` }),
19
- install({ run: 'playwright install-deps' }),
20
- install({ run: 'playwright install' }),
21
- // we have to use `npx` to make sure that we respect `@playwright/test` version from
22
- // the `package.json`.
23
- ...['chromium', 'firefox', 'webkit'].map(browser => test({ run: `npx playwright test --browser=${browser}` })),
24
- ]))
25
- };