Files
rea/tests/boundary/process/fridaVerifier.test.ts
morluto 7bcefead69 test: strengthen and prune audited test coverage (#8573)
* test: strengthen and prune audited test coverage

* test: require delivered DeepSeek skill instructions

* test: keep schema fixture types private

* test: verify Gemini receives skill instructions

* test: bind Qwen skill evidence to its tool result

* test: report NativeAOT verifier checks precisely

* fix: verify Ghidra cleanup paths reliably

* fix: verify Command Code skill activation

* test: tighten cleanup and fixture checks

* test: verify packet capture evidence is recorded

* fix: report HTTP3 capture provenance accurately

* test: preserve resource coverage through MCP

* test: prune repeated assertions and retain cancellation identity

* fix: validate client verifier fixture paths

* test: skip Copilot verifier cases on Windows

* test: keep verifier setup target relative
2026-11-02 02:13:32 +08:00

71 lines
2.7 KiB
TypeScript

import { execFile } from "node:child_process";
import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { promisify } from "node:util";
import { expect, it } from "vitest";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
const execute = promisify(execFile);
it("loads the Frida verifier help without starting instrumentation", async () => {
const result = await execute(process.execPath, [
"scripts/verify-frida.mjs",
"--help",
]);
expect(result.stdout).toContain(
"Without flags, verifies a local Node.js process",
);
});
it("requires marker identity to match the selected target", async () => {
const root = await createTestTempDirectory("rea-frida-verifier-");
const preload = join(root, "provider.mjs");
await writeFile(
preload,
`
import { registerHooks } from 'node:module';
const service = \`
export class FridaInstrumentationService {
async listProcesses() { return { ok: true, value: { processes: [{ pid: 41, name: 'selected' }] } }; }
async instrument() {
const pid = process.env.REA_PROBE_KIND === 'missing' ? undefined : process.env.REA_PROBE_KIND === 'correct' ? 41 : 42;
return { ok: true, value: { cleanupError: null, evidence: { normalized_result: { pid, messages: [{ type: 'send', payload: { rea_frida_verification: 'ok', pid } }] } } } };
}
}\`;
const manager = \`export class FridaInstrumentationManager { async closeAll() {} }\`;
registerHooks({ resolve(specifier, context, next) {
if (context.parentURL?.endsWith('/scripts/verify-frida.mjs')) {
if (specifier.endsWith('/FridaInstrumentationService.js')) return { shortCircuit: true, url: 'data:text/javascript,' + encodeURIComponent(service) };
if (specifier.endsWith('/FridaInstrumentationManager.js')) return { shortCircuit: true, url: 'data:text/javascript,' + encodeURIComponent(manager) };
}
return next(specifier, context);
}});
`,
);
const invoke = (kind: string, remote: boolean) =>
execute(
process.execPath,
[
"--import",
preload,
"scripts/verify-frida.mjs",
...(remote ? ["--address", "127.0.0.1:27042", "--pid", "41"] : []),
],
{ env: { ...process.env, REA_PROBE_KIND: kind }, timeout: 10_000 },
);
for (const [kind, remote, message] of [
["missing", false, "Frida returned no valid target PID"],
["wrong", true, "Frida observed a different target PID"],
] as const) {
await expect(invoke(kind, remote)).rejects.toMatchObject({
stderr: expect.stringContaining(message),
});
}
const result = await invoke("correct", true);
expect(JSON.parse(result.stdout)).toMatchObject({
ok: true,
target_pid: 41,
script_message_observed: true,
});
});