aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers/lsp_sandbox.js
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-14 07:28:39 +0000
committerGravatar zinc <zinc@downsta.ir> 2026-10-14 07:28:39 +0000
commit7451eb090d890fb5ea5e4d40627a1b4df15a49de (patch)
tree357bdf4b528e860bffa688865306f656b788d2c2 /tests/drivers/lsp_sandbox.js
parentanalyzer: close the ownership gaps that stopped the compiler compiling itself (diff)
build: embed images with #embed, keep everything generated in build/
the cores take their genome in with c23 #embed through src/core/genome.h, so images are plain little-endian word files (genome.bin) instead of generated c headers. zc0 writes that format, mkgenome checks an image against its map and shows a compiler's diagnostics when it gets them, and the javascript vm and the editor's vm host read the same files. src/tools/findcc.sh picks a compiler with #embed (clang 19 or gcc 15). zc gets an embed declaration, embed "file" as [type] name, for globals and locals: a byte string by default, char*, numbers read little-endian, and arrays of numbers. the compiler and language server carry their library and source texts through it, so embed.sh and the text it spliced into compiler.zc are gone. make writes executables to build/bin, the default map to build/core/map, the web page to build/web and the extension staging to build/vsix, and the genome now rebuilds when its sources change. the test suite lays out its own map and bootstrap and reads nothing from build/. also: rt.put_s of a byte string in zc0 images, retained function sources no longer count as live objects, a missing include no longer cascades into undefined-name errors, consecutive comment lines join into one hover paragraph, and stale test fixtures follow the include format.
Diffstat (limited to 'tests/drivers/lsp_sandbox.js')
-rw-r--r--tests/drivers/lsp_sandbox.js6
1 files changed, 4 insertions, 2 deletions
diff --git a/tests/drivers/lsp_sandbox.js b/tests/drivers/lsp_sandbox.js
index 14bc1e3..41523cc 100644
--- a/tests/drivers/lsp_sandbox.js
+++ b/tests/drivers/lsp_sandbox.js
@@ -2,10 +2,12 @@
// (immediate functions). the server must not let that code write files, so a file that
// tries to leaves nothing behind and the server still answers.
// usage: node tests/drivers/lsp_sandbox.js path/to/zclsp
+// interpreted hosts (no jit) are far slower; ZC_TEST_TIMEOUT_SCALE stretches every deadline
+const TIMEOUT_SCALE = Number(process.env.ZC_TEST_TIMEOUT_SCALE) || 1;
const cp = require('child_process'), fs = require('fs'), os = require('os'), path = require('path');
const target = path.join(os.tmpdir(), 'zc-sandbox-' + process.pid);
try { fs.unlinkSync(target); } catch (e) {}
-const src = 'immediate fn evil() { let fd = syscall(1, "' + target + '", 1, 0); syscall(4, fd, 65, 1); syscall(2, fd, 0, 0); return 0; }\nevil\nfn main() { return 0; }\n';
+const src = 'include rt, run;\nimmediate fn evil() { run.next(); let fd = rt.syscall(1, "' + target + '", 1, 0); rt.syscall(4, fd, 65, 1); rt.syscall(2, fd, 0, 0); return 0; }\nevil\nfn main() { return 0; }\n';
const frame = m => { const b = Buffer.from(JSON.stringify(m)); return Buffer.concat([Buffer.from('Content-Length: ' + b.length + '\r\n\r\n'), b]); };
const input = Buffer.concat([
frame({ jsonrpc: '2.0', id: 1, method: 'initialize', params: { processId: 1, capabilities: {} } }),
@@ -13,7 +15,7 @@ const input = Buffer.concat([
frame({ jsonrpc: '2.0', id: 3, method: 'textDocument/semanticTokens/full', params: { textDocument: { uri: 'file:///evil.zc' } } }),
frame({ jsonrpc: '2.0', method: 'exit' }),
]);
-const r = cp.spawnSync(process.argv[2], [], { input, timeout: 20000 });
+const r = cp.spawnSync(process.argv[2], [], { input, timeout: 20000 * TIMEOUT_SCALE });
const wrote = fs.existsSync(target);
if (wrote) fs.unlinkSync(target);
const answered = r.stdout && r.stdout.includes('"id":3');