// preserve long request identifiers and ignore deeply nested unknown json fields. // 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 assert = require('assert'); const cp = require('child_process'); const target = process.argv[2]; const id = 'request_' + 'x'.repeat(500); let nested = { ['unknown_' + 'y'.repeat(100)]: 1 }; for (let i = 0; i < 40; i++) nested = { child: nested }; const frame = message => { const body = Buffer.from(JSON.stringify(message)); return Buffer.concat([Buffer.from('Content-Length: ' + body.length + '\r\nX-Extra: ' + 'z'.repeat(500) + '\r\n\r\n'), body]); }; const messages = [{ jsonrpc: '2.0', id, method: 'initialize', extra: nested, params: {} }]; for (let i = 0; i < 24; i++) messages.push({ jsonrpc: '2.0', method: 'textDocument/didOpen', params: { textDocument: { uri: 'file:///enum_' + i + '.zc', version: 1, languageId: 'zc', text: 'enum choice { item { int value; }, empty };\nfn main() { choice*.m p = choice.item(7); return p.item_value; }\n', } } }); messages.push({ jsonrpc: '2.0', id: 'finish', method: 'shutdown', params: null }, { jsonrpc: '2.0', method: 'exit' }); const result = cp.spawnSync(target, [], { input: Buffer.concat(messages.map(frame)), timeout: 20000 * TIMEOUT_SCALE, maxBuffer: 8 << 20 }); assert.strictEqual(result.status, 0, String(result.stderr)); const responses = []; let data = result.stdout; while (data.length) { const end = data.indexOf('\r\n\r\n'); assert.ok(end >= 0); const length = Number(/Content-Length:\s*(\d+)/i.exec(data.subarray(0, end).toString())[1]); responses.push(JSON.parse(data.subarray(end + 4, end + 4 + length).toString())); data = data.subarray(end + 4 + length); } assert.ok(responses.some(message => message.id === id && message.result.capabilities), 'the full request id is echoed'); assert.ok(responses.some(message => message.id === 'finish'), 'the next request is parsed'); const diagnostics = responses.filter(message => message.method === 'textDocument/publishDiagnostics'); assert.strictEqual(diagnostics.length, 24); assert.ok(diagnostics.every(message => !message.params.diagnostics.some(diagnostic => diagnostic.severity === 1)), JSON.stringify(diagnostics)); console.log('ok long protocol fields, deep json, and tagged enums across document checks');