mirror of
https://github.com/morluto/rea.git
synced 2026-11-18 04:34:13 +00:00
* fix(adb): run adb commands under owned supervision and start the adb server explicitly The adb version probe and device commands now run through runOwnedCommand in their own process group, keeping adb's SIGTERM-first stop through the termination policy. A device command's escaped descendants are swept with its cleanup, and cleanup that fails stays owned by the provider, which retries it before its next operation. Device operations start the adb server with an explicit `adb start-server` first. The server is an external shared service: REA may start it but never stops it, so a device command never forks it into its own cleanup. runOwnedCommand gains a byte-limited stdout collector: output beyond maxStdoutBytes is an output-limit failure, like an exceeded diagnostic budget, and the collected bytes are kept exactly for binary protocols such as screencap. Ownership preparation that cannot start its own helper for lack of host capacity is reported as the command's host-capacity launch failure. * fix(adb): preserve completed refusals, server startup facts, and lazy server start * fix(adb): scope runtime-root command cleanup and preserve incomplete command cleanup * fix(adb): preserve completed bugreports and staging directories across command cleanup failures * fix(adb): preserve bugreport command cleanup across readback failures and project live cleanup resources
93 lines
2.9 KiB
TypeScript
93 lines
2.9 KiB
TypeScript
import { vi } from "vitest";
|
|
|
|
import type { AdbRunOutcome } from "../../../src/adb/AdbProcess.js";
|
|
import { OwnedCommandFailure } from "../../../src/process/OwnedCommand.js";
|
|
|
|
/** What a scripted adb run printed and how it exited (0 unless given). */
|
|
export interface AdbDoubleRun {
|
|
readonly stdout?: Buffer | string;
|
|
readonly stderr?: Buffer | string;
|
|
readonly exitCode?: number;
|
|
}
|
|
|
|
type AdbDoubleCommand = (
|
|
arguments_: readonly string[],
|
|
) => Promise<AdbDoubleRun>;
|
|
|
|
/**
|
|
* Scripted adb runs for provider tests that exercise publication, snapshot
|
|
* and cleanup ownership rather than process supervision. `version` answers
|
|
* the client probe; `device` answers every device command. A rejection is a
|
|
* run that failed without exiting.
|
|
*/
|
|
export const adbDouble = {
|
|
version: vi.fn<AdbDoubleCommand>(),
|
|
device: vi.fn<AdbDoubleCommand>(),
|
|
};
|
|
|
|
const bytes = (value: Buffer | string | undefined): Buffer =>
|
|
Buffer.isBuffer(value) ? value : Buffer.from(value ?? "");
|
|
|
|
/** Replaces `runAdbProcess` through `vi.mock` of `src/adb/AdbProcess.js`. */
|
|
export const runAdbProcessDouble = async (
|
|
_host: unknown,
|
|
arguments_: readonly string[],
|
|
): Promise<AdbRunOutcome> => {
|
|
const command =
|
|
arguments_[0] === "version" ? adbDouble.version : adbDouble.device;
|
|
try {
|
|
const run = await command(arguments_);
|
|
const stdout = bytes(run.stdout);
|
|
const stderr = bytes(run.stderr);
|
|
const exitCode = run.exitCode ?? 0;
|
|
return {
|
|
ok: true,
|
|
run: {
|
|
stdout,
|
|
stderr: stderr.toString("utf8"),
|
|
exitCode,
|
|
capturedOutput: {
|
|
stdout: stdout.toString("utf8"),
|
|
stderr: stderr.toString("utf8"),
|
|
stdout_bytes: stdout.byteLength,
|
|
stderr_bytes: stderr.byteLength,
|
|
exit_code: exitCode,
|
|
signal: null,
|
|
truncated: false,
|
|
},
|
|
},
|
|
};
|
|
} catch (cause: unknown) {
|
|
const commandFailure =
|
|
cause instanceof OwnedCommandFailure ? cause : undefined;
|
|
const exited =
|
|
commandFailure?.snapshot?.exitCode !== null &&
|
|
commandFailure?.snapshot?.exitCode !== undefined
|
|
? {
|
|
stdout: Buffer.from(commandFailure.snapshot.stdout.text),
|
|
stderr: commandFailure.snapshot.stderr.text,
|
|
exitCode: commandFailure.snapshot.exitCode,
|
|
capturedOutput: {
|
|
stdout: commandFailure.snapshot.stdout.text,
|
|
stderr: commandFailure.snapshot.stderr.text,
|
|
stdout_bytes: commandFailure.snapshot.stdout.observedBytes,
|
|
stderr_bytes: commandFailure.snapshot.stderr.observedBytes,
|
|
exit_code: commandFailure.snapshot.exitCode,
|
|
signal: null,
|
|
truncated: false,
|
|
},
|
|
}
|
|
: undefined;
|
|
return {
|
|
ok: false,
|
|
failure: {
|
|
cause,
|
|
command: commandFailure,
|
|
launch: undefined,
|
|
capturedOutput: exited?.capturedOutput,
|
|
exited,
|
|
},
|
|
};
|
|
}
|
|
};
|