import test from 'node:test'; import assert from 'node:assert/strict'; import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { localTools } from '../local-tools.js'; test('native shell bounds output and reports timeout as a failed tool', async t => { const work = fs.mkdtempSync(path.join(os.tmpdir(), 'pi-local-')); t.after(() => fs.rmSync(work, { recursive: true, force: true })); const bash = localTools(work).find(tool => tool.name === 'bash')!; await assert.rejects(bash.execute('sdk_output', { command: "python3 -c 'import sys; sys.stdout.write(\"x\"*2000000)'" }), /capped at 1 MiB/); await assert.rejects(bash.execute('sdk_timeout', { command: 'sleep 10', timeout: 0.05 }), /timed out/); }); test('native reads reject large and nonregular files without blocking', async t => { const work = fs.mkdtempSync(path.join(os.tmpdir(), 'pi-read-')); t.after(() => fs.rmSync(work, { recursive: true, force: true })); const read = localTools(work).find(tool => tool.name === 'read')!; fs.writeFileSync(path.join(work, 'large'), ''); fs.truncateSync(path.join(work, 'large'), 17 * 1024 * 1024); await assert.rejects(read.execute('sdk_large', { path: path.join(work, 'large') }), /at most 16 MiB/); await assert.rejects(read.execute('sdk_special', { path: '/dev/zero' }), /regular file/); });