* fix(application): retain completed evidence through cancellation Validate completed provider reports before classifying cancellation and preserve Evidence and captured diagnostics. Share MCP recording and delivery across custom observation handlers. Add source-owned completion and public SDK recording controls. Refs #3923, #3927, #4261. * fix(wasm): retain final observations through cancellation Keep completed Evidence after finalization and through CLI/MCP delivery. Preserve output and cleanup failure precedence. Refs #4254. * fix(browser): retain final observations and forward cancellation Classify final CDP detach and completed scenario cleanup at the provider boundary. Translate completed partials into canonical Evidence for MCP recording, and forward CLI cancellation to passive Electron tools. Refs #4255, #4256, #4257. * fix(ghidra): isolate cancellation of shared startup waiters Keep startup group-owned while each caller has an independent abortable wait. Await final-owner cleanup and preserve cleanup facts before retrying. Reuse the shared abortable promise helper. Refs #3983. * fix(mcp): keep shutdown registrations until cleanup succeeds Retain repeated event requests while unresolved owners need cleanup, and unregister only after success. Verify coalescing and failed-owner retry. Refs #4253. * fix(adb): own transfer snapshots and stage screen publication Bind transfer digests to the exact private input bytes and preserve caller APK names. Retain failed descriptors and private-root owners with typed cleanup evidence; publish captures exclusively after the cancellation cutoff. Refs #4251, #4252. * fix(verification): report ADB cleanup failures Always close after attempted verification and keep unexpected primary failures and cleanup details visible. Exercise the production script with controlled imports, including null and undefined throws. Refs #4260. * fix(runner): stop owned Windows commands on cancellation Use the retained ChildProcess handle for IPC cancellation and parent disconnection. Keep the SQLite lock until observed child close, and include native Windows regressions in the curated CI lane. Native Windows results remain pending. Refs #4258. * fix(website): canonicalize link containment boundaries Compare resolved targets with resolved repository and site roots. Accept directory aliases while preserving escape checks and keep fixtures within their temporary owner. Refs #4264. * docs(testing): cover completion races and cleanup retry Clarify validation-before-cancellation, independent startup waiter controls, producer and adapter coverage, and repeated shutdown events. * fix(filesystem): retain file owners and completed reads after close failure * fix(session): report retained snapshot staging in cleanup status Fixes #4277. Include both snapshot and profile file-resource scopes in the owning status fact, preserving publication receipts and cleanup retry. * docs(mcp): clarify recovery of raw partial observations Document the observed SDK cancellation boundary and the open design decision in #4276 without promoting raw errors to Evidence. * fix(kuna): own the complete installation inspection lifetime * test(kuna): cover session cleanup of shared cache resources * fix(hopper): isolate publisher operation resource admission * fix(hopper): preserve launcher cleanup failure classification * fix(adb): retain ordered cleanup and screen publication outcomes * fix(runner): retain Windows job ownership through cleanup retries * docs: clarify inspection admission and ordered cleanup regressions * fix(ghidra): preserve startup cleanup and request deadlines * fix(runner): supervise stdin errors and bootstrap native controls * docs: require queued lifecycle controls to survive admission * fix(cli): leave cleanup resolution with resource owners * test(adb): verify owned install snapshots through CLI * fix(errors): exclude resolved primary cleanup resources * fix(adb): resolve publication cleanup after its handle closes * fix(android): resolve JADX hash cleanup after owned close * refactor(android): share hash failure cause options * fix(kuna): gate commands on retained descriptor cleanup * docs: cover cleanup admission and owner-confirmed recovery * refactor(artifacts): bind cleanup errors to confirmed release * fix(adb): resolve recovered cleanup at retained owners * fix(kuna): resolve installation cleanup after owned close * fix(kuna): gate cache reads on retained hash cleanup * fix(setup): preserve publisher cleanup admission failures * fix(android): resolve the reported retirement cleanup error * test(runner): scope post-spawn fault control to POSIX * test(adb): cover persistent snapshot owner retirement * fix(kuna): preserve file outcomes with explicit cleanup ownership * fix(artifacts): resolve errors through retained cleanup owners * docs(lifecycle): carry cleanup ownership in typed outcomes * fix(adb): bind staged screen errors to their cleanup lease * fix(kuna): bind profile cleanup through a close capability * fix(artifacts): retain descriptor resources in cleanup errors * fix(pcap): bind existing errors to snapshot retirement * fix(windows): load source owner through its file URL * test(build): copy the command runner helper into fixtures * fix(mcp): own shared observation providers in the transport * fix(jadx): resolve every retained cleanup retry error * fix(kuna): bind retry errors to every retained cleanup owner * fix(adb): bind admission and shutdown errors to exact cleanup leases * fix(windows): resolve command paths before native ownership * test(publisher): assert exact descriptor recovery without release metadata * docs(lifecycle): require every retry error to follow its owners * fix(kuna): keep hash cleanup state stable across concurrent retries * test(windows): exercise surviving descendants with scoped shutdown deadlines * fix(uninstall): preserve primary read errors through cleanup failure * test(publisher): assert cleanup Result and exact owner recovery * test(windows): observe supervisor resources through IPC disconnect * fix(browser): retain typed cancellation after interrupted actions * test(publisher): assert ownership phases without retry-count coupling * fix(lifecycle): preserve abort reasons through shared provider execution * fix(jadx): preserve execution and late hash cancellation causes * fix(adb): compose late cancellation with exact cleanup failures * test(mcp): use the shared budget for session workflows
133 lines
5.3 KiB
TypeScript
133 lines
5.3 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { mkdtemp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { afterEach, expect, it } from "vitest";
|
|
|
|
const roots: string[] = [];
|
|
afterEach(async () => {
|
|
await Promise.all(
|
|
roots.splice(0).map((root) => rm(root, { recursive: true, force: true })),
|
|
);
|
|
});
|
|
|
|
const runVerifier = async (
|
|
settings: { closeFails?: boolean; thrown?: "undefined" | "null" } = {},
|
|
) => {
|
|
const root = await mkdtemp(join(tmpdir(), "rea-adb-verifier-test-"));
|
|
roots.push(root);
|
|
await mkdir(join(root, "scripts", "lib"), { recursive: true });
|
|
await mkdir(join(root, "dist", "application", "adb"), { recursive: true });
|
|
await mkdir(join(root, "dist", "composition"), { recursive: true });
|
|
await writeFile(
|
|
join(root, "scripts", "verify-adb.mjs"),
|
|
await readFile(new URL("../../../scripts/verify-adb.mjs", import.meta.url)),
|
|
);
|
|
await writeFile(
|
|
join(root, "scripts", "lib", "verifier-cleanup.mjs"),
|
|
await readFile(
|
|
new URL("../../../scripts/lib/verifier-cleanup.mjs", import.meta.url),
|
|
),
|
|
);
|
|
await writeFile(
|
|
join(root, "dist", "composition", "adb.js"),
|
|
`import { writeFile } from "node:fs/promises";
|
|
export const createAdbDeviceAnalysisProvider = () => ({
|
|
async close() {
|
|
await writeFile(process.env.REA_ADB_CLOSE_MARKER, "closed");
|
|
if (process.env.REA_ADB_CLOSE_FAIL === "1") {
|
|
const error = new Error("provider cleanup refused");
|
|
error.cleanupResources = ["fixture/private-root"];
|
|
error.diagnostics = { reason: "retry remains possible" };
|
|
throw error;
|
|
}
|
|
},
|
|
});\n`,
|
|
);
|
|
await writeFile(
|
|
join(root, "dist", "application", "adb", "AdbDeviceAnalysisService.js"),
|
|
`export class AdbDeviceAnalysisService {
|
|
async execute(operation, input) {
|
|
if (process.env.REA_ADB_THROW === "undefined") throw undefined;
|
|
if (process.env.REA_ADB_THROW === "null") throw null;
|
|
const result = {
|
|
inspect_adb_client: { client: { version: "1", binary_path: "/tmp/adb" } },
|
|
list_adb_devices: { devices: [{ serial: "test", state: "device", kind: "emulator", kind_basis: "stub" }] },
|
|
inspect_adb_device: { properties: [{ name: "ro.build.version.sdk", value: "35" }], emulator_observed: true },
|
|
list_adb_processes: { processes: [{ name: "probe" }], columns: "pid name" },
|
|
inspect_adb_window: { focused_window: null },
|
|
inspect_adb_display: { physical_size: { width: 2, height: 2 }, physical_density: 1 },
|
|
read_adb_setting: { value: "1" },
|
|
read_adb_logcat: { lines: [], coverage: "complete" },
|
|
list_adb_features: { features: ["feature"], coverage: "complete" },
|
|
list_adb_services: { services: ["service"], coverage: "complete" },
|
|
list_adb_directory: { entries: [], coverage: "complete" },
|
|
list_adb_packages: { packages: input.scope === "all" ? [{ package_name: "com.test" }] : [], coverage: "complete" },
|
|
push_adb_file: { bytes: 3, sha256: "${"a".repeat(64)}", device_sha256: "${"a".repeat(64)}", device_digest_source: "device_sha256sum" },
|
|
pull_adb_file: { bytes: 3, sha256: "${"a".repeat(64)}" },
|
|
capture_adb_screen: { width: 2, height: 2, bytes: 3 },
|
|
}[operation];
|
|
return { ok: true, value: { normalized_result: result } };
|
|
}
|
|
}\n`,
|
|
);
|
|
const marker = join(root, "provider-closed");
|
|
const run = spawnSync(
|
|
process.execPath,
|
|
[join(root, "scripts", "verify-adb.mjs")],
|
|
{
|
|
encoding: "utf8",
|
|
timeout: 10_000,
|
|
env: {
|
|
...process.env,
|
|
REA_ADB_CLOSE_MARKER: marker,
|
|
REA_ADB_CLOSE_FAIL: settings.closeFails ? "1" : "0",
|
|
...(settings.thrown === undefined
|
|
? {}
|
|
: { REA_ADB_THROW: settings.thrown }),
|
|
},
|
|
},
|
|
);
|
|
const closed = await readFile(marker, "utf8").catch(() => null);
|
|
return { ...run, closed };
|
|
};
|
|
|
|
it("runs the production verifier successfully and closes its provider", async () => {
|
|
const result = await runVerifier();
|
|
|
|
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
|
|
expect(result.stdout).toContain("all adb device checks passed");
|
|
expect(result.closed).toBe("closed");
|
|
});
|
|
|
|
it("makes provider cleanup failure fail the production verifier with resource details", async () => {
|
|
const result = await runVerifier({ closeFails: true });
|
|
|
|
expect(result.status).toBe(1);
|
|
expect(result.stderr).toContain("provider cleanup refused");
|
|
expect(result.stderr).toContain("fixture/private-root");
|
|
expect(result.stderr).toContain("retry remains possible");
|
|
expect(result.closed).toBe("closed");
|
|
});
|
|
|
|
it.each(["undefined", "null"] as const)(
|
|
"closes after the verifier throws %s and exits unsuccessfully",
|
|
async (thrown) => {
|
|
const result = await runVerifier({ thrown });
|
|
|
|
expect(result.status).toBe(1);
|
|
expect(result.stderr).toContain(`verifier aborted — ${thrown}`);
|
|
expect(result.closed).toBe("closed");
|
|
},
|
|
);
|
|
|
|
it("reports both an unexpected verifier throw and provider cleanup failure", async () => {
|
|
const result = await runVerifier({ closeFails: true, thrown: "null" });
|
|
|
|
expect(result.status).toBe(1);
|
|
expect(result.stderr).toContain("verifier aborted — null");
|
|
expect(result.stderr).toContain("provider cleanup refused");
|
|
expect(result.stderr).toContain("fixture/private-root");
|
|
expect(result.closed).toBe("closed");
|
|
});
|