feat(runtime): default to passthrough and persist execution permissions
This commit is contained in:
@@ -5,7 +5,7 @@ import { readOwnedProcessTree } from './owned-process-tree.mjs';
|
||||
|
||||
// Both checks and dependency preparation use this direct, shell-free process
|
||||
// owner. Callers choose fixed invocations and interpret their own evidence.
|
||||
export async function runOwnedCommand(invocation, { cwd, env, signal, onSpawn = null, input = null, timeoutMs = 180000, onOutput = null } = {}) {
|
||||
export async function runOwnedCommand(invocation, { cwd, env, signal, onSpawn = null, input = null, timeoutMs = 180000, unlimitedOutput = false, onOutput = null } = {}) {
|
||||
const started = Date.now(), at = () => new Date().toISOString();
|
||||
if (signal.aborted) return { status: 'cancelled', exitCode: null, durationMs: 0, stdout: '', stderr: '', process: null };
|
||||
return new Promise(resolve => {
|
||||
@@ -16,10 +16,10 @@ export async function runOwnedCommand(invocation, { cwd, env, signal, onSpawn =
|
||||
const processInfo = { pid: child.pid ?? null, hostPid: process.pid, executable: invocation.executable,
|
||||
argsSha256: createHash('sha256').update(JSON.stringify(invocation.args)).digest('hex'), cwd, startedAt: at() };
|
||||
const append = (name, text) => { const value = streams[name]; value.characters += text.length;
|
||||
value.head = (value.head + text).slice(0, 240000); value.tail = (value.tail + text).slice(-240000);
|
||||
value.head = unlimitedOutput ? value.head + text : (value.head + text).slice(0, 240000); value.tail = unlimitedOutput ? '' : (value.tail + text).slice(-240000);
|
||||
if (onOutput && !settled) { try { onOutput(name, text); } catch (error) { ownershipError = error; terminate(); } }
|
||||
};
|
||||
const captured = name => { const value = streams[name]; return value.characters <= 240000 ? value.head
|
||||
const captured = name => { const value = streams[name]; return unlimitedOutput || value.characters <= 240000 ? value.head
|
||||
: value.characters <= 480000 ? value.head + value.tail.slice(value.head.length - value.characters)
|
||||
: value.head + '\n[中间日志超出保存上限,保留开头和结尾]\n' + value.tail; };
|
||||
const captureTree = async (publish = true) => {
|
||||
@@ -47,7 +47,7 @@ export async function runOwnedCommand(invocation, { cwd, env, signal, onSpawn =
|
||||
resolve({ status: unknown ? 'unknown' : signal.aborted ? 'cancelled' : timedOut || error || ownershipError || code !== 0 ? 'failed' : 'passed',
|
||||
exitCode: code, durationMs: Date.now() - started, stdout: captured('stdout'),
|
||||
stderr: captured('stderr') + (error ? '\n' + error.message : '') + (ownershipError ? '\n' + ownershipError.message : ''),
|
||||
timedOut, truncated: streams.stdout.characters > 480000 || streams.stderr.characters > 480000,
|
||||
timedOut, truncated: !unlimitedOutput && (streams.stdout.characters > 480000 || streams.stderr.characters > 480000),
|
||||
...(onSpawn ? { process: { ...processInfo, rootExited: rootClosed, treeTermination: terminating ? unknown ? 'unknown' : 'confirmed' : 'not_requested' } } : {}),
|
||||
reason: unknown ? '进程结束未得到确认,需要核对实际副作用。' : timedOut ? '命令超过时间上限,已请求终止所属进程树。' : error?.message ?? ownershipError?.message ?? null });
|
||||
};
|
||||
@@ -64,7 +64,7 @@ export async function runOwnedCommand(invocation, { cwd, env, signal, onSpawn =
|
||||
}
|
||||
killTimer = setTimeout(() => { void finish(null, null, true); }, 5000);
|
||||
};
|
||||
const timeout = setTimeout(() => { timedOut = true; terminate(); }, timeoutMs);
|
||||
const timeout = timeoutMs > 0 ? setTimeout(() => { timedOut = true; terminate(); }, timeoutMs) : null;
|
||||
signal.addEventListener('abort', terminate, { once: true });
|
||||
for (const name of ['stdout', 'stderr']) {
|
||||
child[name].on('data', bytes => append(name, streams[name].decoder.write(bytes)));
|
||||
|
||||
Reference in New Issue
Block a user