aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers/fuzz_lsp.js
diff options
context:
space:
mode:
authorGravatar Moon Flower <moonflower@elhenney.local> 2026-10-14 08:29:46 +0330
committerGravatar Moon Flower <moonflower@elhenney.local> 2026-10-14 08:29:46 +0330
commit1c53304d03414890af0da7432d1aea87e754a14a (patch)
tree97190d86cf548c9bc63f68c86a4d2a4f09809713 /tests/drivers/fuzz_lsp.js
parenta (diff)
feat: grow memory limits, add icon/actor libraries, overhaul LSP diagnostics
Compiler and VM - make every memory map limit dynamic and adjustable at both build time and runtime, including compiler tables, stacks, and every execution region - reserve and grow tables, operand and return stacks, frame segments, and image-building output without relocating live code or globals - rename i/o and string helpers consistently (puts -> put_s, putn -> put_n, scat -> cat_s) across compiler, runtime, examples, tests, and docs - recast and consume values assigned to globals from inside functions - allow fixed and const together, add typed closure returns (fn:t(...)), multi-include syntax (include rt, run, core;), and recurse type inference - never infer string literals as word, anywhere, as argument, variable, or return type - draft docs/BORROW.md: a borrow checker less intrusive than Rust's but more intelligent LSP and editor integration - require explicit includes and give every toolchain area its own namespace (rt, lsp, run, core) - hover for built-in types, inferred types, values known at hover time, array and pointer lifetime/size, library names in include statements, and inferred lifetimes with explanations - honor /* */ comments as documentation for variables and arguments, and stop misattributing section headers or trailing comments as variable hints - stream diagnostics and cancel stale requests on change - jump to definition and references, including cross-file - quick fixes with automatic library import, and namespace completion Hints and diagnostics - render hints as blue squigglies by default, with hints on/small/off per file - suppress magic-number hints via a preceding /* */ comment, and say so - warn on unused arguments; allow multiple _ discards in parameters, pattern matching, and tagged enums, warning if a _ is actually used - rewrite hint and comment prose in professional compiler-doc register Libraries - add icon.zc: run-time self-modification, find/replace syntax, type and block edits, and step-through inspection of locals and globals - add actor.zc: async actors with Actor<I,O>, implicit this, spawn/recv/send, injected into the compiler machinery at include time rather than built in Tooling and docs - reorganize sources, tests, and designs into subdirectories - unify windows entry points in tinyvm.bat and add a matching tinyvm.sh - add --help across the toolchain - polish the learning guide, stdlib docs, and design notes Tests - add accept, reject, and regression coverage across the compiler, LSP, - runtime, icon, actors, threads, formatting, and the toolchain contracts, plus fuzzers and property tests
Diffstat (limited to 'tests/drivers/fuzz_lsp.js')
-rw-r--r--tests/drivers/fuzz_lsp.js89
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/drivers/fuzz_lsp.js b/tests/drivers/fuzz_lsp.js
new file mode 100644
index 0000000..e22a44b
--- /dev/null
+++ b/tests/drivers/fuzz_lsp.js
@@ -0,0 +1,89 @@
+// Deterministic source/protocol fuzzing for diagnostics, caching, and recovery.
+// Usage: node tests/drivers/fuzz_lsp.js path/to/zclsp
+const { spawnSync } = require('child_process');
+const server = process.argv[2] || 'bin/zclsp';
+let state = 0x5a17;
+function next() { state = (Math.imul(state, 1664525) + 1013904223) >>> 0; return state; }
+function frame(m) {
+ const body = Buffer.from(JSON.stringify(m), 'utf8');
+ return Buffer.concat([Buffer.from('Content-Length: ' + body.length + '\r\n\r\n'), body]);
+}
+function parse(buf) {
+ const out = []; let at = 0;
+ while (at < buf.length) {
+ const end = buf.indexOf('\r\n\r\n', at);
+ if (end < 0) throw new Error('truncated LSP header');
+ const match = /Content-Length: (\d+)/.exec(buf.slice(at, end).toString());
+ if (!match) throw new Error('missing Content-Length');
+ const size = Number(match[1]), start = end + 4;
+ if (start + size > buf.length) throw new Error('truncated LSP body');
+ out.push(JSON.parse(buf.slice(start, start + size).toString('utf8')));
+ at = start + size;
+ }
+ return out;
+}
+const msgs = [{ jsonrpc: '2.0', id: 1, method: 'initialize', params: {} }];
+const docs = [];
+for (let i = 0; i < 32; i++) {
+ const uri = `file:///fuzz-${i}.zc`, n = next() % 1000;
+ const broken = i % 3 === 0;
+ const initial = `fn calc_${i}(x) { return (x + ${n}) * 2; }\nfn main() { let y = calc_${i}(${n})${broken ? '' : ';'} return y; }\n`;
+ const fixed = `fn calc_${i}(x) { return (x + ${n}) * 2; }\nfn main() { let y = calc_${i}(${n}); return y; }\n`;
+ docs.push({ uri, broken });
+ msgs.push({ jsonrpc: '2.0', method: 'textDocument/didOpen', params: { textDocument: { uri, languageId: 'zc', version: 1, text: initial } } });
+ msgs.push({ jsonrpc: '2.0', id: 100 + i, method: 'textDocument/semanticTokens/full', params: { textDocument: { uri } } });
+ msgs.push({ jsonrpc: '2.0', method: 'textDocument/didChange', params: { textDocument: { uri, version: 2 }, contentChanges: [{ text: fixed }] } });
+}
+const stdUri = 'file:///fuzz-std.zc';
+msgs.push({ jsonrpc: '2.0', method: 'textDocument/didOpen', params: { textDocument: { uri: stdUri, languageId: 'zc', version: 1, text: 'include std;\nfn main() { return Text.starts("alpha", "al"); }\n' } } });
+
+// Keep one server alive while documents are repeatedly opened, made malformed,
+// repaired, closed, and reopened at a new version. This exercises cache
+// invalidation and stale-diagnostic cleanup across a long-lived editor session.
+const churn = new Map();
+for (let i = 0; i < 96; i++) {
+ const slot = i % 4, uri = `file:///churn-${slot}.zc`, n = next() % 10000;
+ const malformed = `fn churn_${slot}(x) { let y = (x + ${n}); return y; }\nfn main() { return churn_${slot}(${n}) }\n`;
+ const valid = `fn churn_${slot}(x) { let y = (x + ${n}); return y; }\nfn main() { return churn_${slot}(${n}); }\n`;
+ const version = Math.floor(i / 4) * 3 + 1;
+ msgs.push({ jsonrpc: '2.0', method: 'textDocument/didOpen', params: { textDocument: { uri, languageId: 'zc', version, text: malformed } } });
+ msgs.push({ jsonrpc: '2.0', id: 1000 + i, method: 'textDocument/semanticTokens/full', params: { textDocument: { uri } } });
+ msgs.push({ jsonrpc: '2.0', method: 'textDocument/didChange', params: { textDocument: { uri, version: version + 1 }, contentChanges: [{ text: valid }] } });
+ msgs.push({ jsonrpc: '2.0', method: 'textDocument/didClose', params: { textDocument: { uri } } });
+ churn.set(uri, valid);
+}
+let churnVersion = 100;
+for (const [uri, text] of churn) {
+ msgs.push({ jsonrpc: '2.0', method: 'textDocument/didOpen', params: { textDocument: { uri, languageId: 'zc', version: churnVersion++, text } } });
+}
+msgs.push({ jsonrpc: '2.0', method: 'exit' });
+const run = spawnSync(server, [], { input: Buffer.concat(msgs.map(frame)), timeout: 60000, maxBuffer: 1 << 28 });
+if (run.error || run.status !== 0) throw run.error || new Error(`server exit ${run.status}: ${run.stderr}`);
+const out = parse(run.stdout);
+const diagnostics = new Map();
+for (const m of out) {
+ if (m.method === 'textDocument/publishDiagnostics') {
+ const items = diagnostics.get(m.params.uri) || [];
+ items.push(m.params.diagnostics);
+ diagnostics.set(m.params.uri, items);
+ }
+}
+for (let i = 0; i < docs.length; i++) {
+ const { uri, broken } = docs[i], batches = diagnostics.get(uri) || [];
+ if (batches.length < 2) throw new Error(`${uri}: expected diagnostics for open and change`);
+ if (broken && !batches[0].some(d => d.severity === 1)) throw new Error(`${uri}: malformed source was not diagnosed`);
+ if (batches[batches.length - 1].some(d => d.severity === 1)) throw new Error(`${uri}: valid edit retained an error`);
+ const response = out.find(m => m.id === 100 + i);
+ if (!response || response.error || !response.result || response.result.data.length % 5) throw new Error(`${uri}: semantic tokens response was malformed`);
+}
+for (let i = 0; i < 96; i++) {
+ const response = out.find(m => m.id === 1000 + i);
+ if (!response || response.error || !response.result || response.result.data.length % 5) throw new Error(`churn request ${i}: malformed semantic tokens response`);
+}
+const stdDiag = diagnostics.get(stdUri) || [];
+if (!stdDiag.length || stdDiag[stdDiag.length - 1].some(d => d.severity === 1)) throw new Error('stdlib include failed LSP source analysis');
+for (const uri of churn.keys()) {
+ const batches = diagnostics.get(uri) || [];
+ if (!batches.length || batches[batches.length - 1].some(d => d.severity === 1)) throw new Error(`${uri}: reopened document retained stale diagnostics`);
+}
+console.log(`ok lsp fuzz: ${docs.length} deterministic open/change sequences, 96 long-session cache churns, semantic tokens, and include std`);