refactor: simplify pass (trekexecute)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kjell Tore Guttormsen 2026-11-02 10:58:35 +01:00
commit cc277c476c
Signed by: ktg
SSH key fingerprint: SHA256:JakMjO6FTBBzN0Bhfj9saOoEjaFxlSdYuZQQpM/lF9Q
2 changed files with 15 additions and 12 deletions

View file

@ -26,6 +26,7 @@ import { dirname, join } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { runHook, runHookWithEnv } from '../helpers/hook-helper.mjs';
import { tmp, pluginCopy } from './guard-helpers.mjs';
import { fastestWithin } from '../helpers/timing.mjs';
const HERE = dirname(fileURLToPath(import.meta.url));
const ROOT = join(HERE, '..', '..');
@ -305,9 +306,12 @@ test('part-A scan: a long command with many escaped < is read in linear time', a
// scan resumes where its last call stopped, so the text is read once.
const many = ('\\<' + 'x'.repeat(40) + ' ').repeat(20000);
const command = `echo ${many}<<'${D}'\nbrief.md\n${D}`;
const started = Date.now();
const { code, stderr } = await runHook(PRE_BASH, bashInput(command));
const elapsed = Date.now() - started;
assert.strictEqual(code, 0, `the guard did not pass the long command (exit ${code}): ${stderr.slice(0, 300)}`);
assert.ok(elapsed < 15000, `the guard took ${elapsed} ms on ${command.length} characters (limit 15000 ms)`);
let last = { code: null, stderr: '' };
const timing = await fastestWithin(15000, async () => {
const started = Date.now();
last = await runHook(PRE_BASH, bashInput(command));
return Date.now() - started;
});
assert.strictEqual(last.code, 0, `the guard did not pass the long command (exit ${last.code}): ${last.stderr.slice(0, 300)}`);
assert.ok(timing.ok, `the guard took ${timing.fastest} ms at best (runs ${timing.runs.join(', ')}) on ${command.length} characters (limit 15000 ms)`);
});