Merge remote-tracking branch 'origin/main' into feat/2072-ines-container
This commit is contained in:
@@ -177,6 +177,38 @@ cliTest(
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"managed CLI rejects repeated or empty type selections as invalid input",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-managed-cli-types-");
|
||||
const path = join(root, "fixture.dll");
|
||||
await writeFile(path, buildManagedPeFixture());
|
||||
for (const [types, message] of [
|
||||
[["Fixture.Empty0", "Fixture.Empty0"], "must not repeat a name"],
|
||||
[[""], ">=1 characters"],
|
||||
] as const) {
|
||||
const result = await cli.run({
|
||||
arguments: [
|
||||
"inspect-managed-members",
|
||||
path,
|
||||
...types.flatMap((type) => ["--type", type]),
|
||||
"--json",
|
||||
],
|
||||
});
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.json).toMatchObject({
|
||||
code: "VALIDATION_ERROR",
|
||||
fieldErrors: [
|
||||
expect.objectContaining({
|
||||
path: expect.stringMatching(/^type/u),
|
||||
message: expect.stringContaining(message),
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"managed CLI bounds CIL claims by section virtual ranges",
|
||||
async ({ cli }) => {
|
||||
|
||||
@@ -35,7 +35,9 @@ cliTest(
|
||||
environment,
|
||||
timeoutMs: 15000,
|
||||
});
|
||||
expect(cliResponse.exitCode).toBe(0);
|
||||
expect(cliResponse.exitCode, cliResponse.stdout + cliResponse.stderr).toBe(
|
||||
0,
|
||||
);
|
||||
expect(cliResponse.json).toMatchObject({
|
||||
normalized_result: {
|
||||
engine: null,
|
||||
|
||||
@@ -40,7 +40,7 @@ cliTest(
|
||||
},
|
||||
timeoutMs: 45000,
|
||||
});
|
||||
expect(response.exitCode).toBe(0);
|
||||
expect(response.exitCode, response.stdout + response.stderr).toBe(0);
|
||||
expect(response.json).toMatchObject({
|
||||
normalized_result: {
|
||||
source: { script_index: 0 },
|
||||
|
||||
@@ -14,6 +14,36 @@ import {
|
||||
import { trackBrowser } from "./cdpBrowserProvider.support.js";
|
||||
|
||||
describe("CdpBrowserProvider: cancellation and session events", () => {
|
||||
it("honors cancellation during the final progress callback before publishing inspection", async () => {
|
||||
const browser = await startFakeCdpBrowser();
|
||||
trackBrowser(browser);
|
||||
const controller = new AbortController();
|
||||
const result = await new CdpBrowserProvider().inspectPage(
|
||||
inspectWebPageInputSchema.parse({
|
||||
cdp_endpoint: browser.endpoint,
|
||||
allowed_origins: [browser.allowedOrigin],
|
||||
target_id: "allowed-page",
|
||||
observation_ms: 0,
|
||||
}),
|
||||
{
|
||||
signal: controller.signal,
|
||||
progress: {
|
||||
report(update) {
|
||||
if (update.completed === 3) controller.abort();
|
||||
return Promise.resolve();
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
_tag: "AnalysisCancelledError",
|
||||
operation: "inspect_web_page",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("projects direct-session cancellation onto the requested operation", async () => {
|
||||
const browser = await startFakeCdpBrowser({
|
||||
pageScopedVersionWebSocket: true,
|
||||
|
||||
@@ -131,6 +131,203 @@ it("preserves unavailable response observations and captures completed peers", a
|
||||
).toEqual(["missing-body", "available"]);
|
||||
});
|
||||
|
||||
it("marks JSON response bodies unavailable when their events arrive during body capture", async () => {
|
||||
const browser = await startFakeCdpBrowser({
|
||||
commandEvents(command, origin) {
|
||||
const session =
|
||||
command.sessionId === undefined ? {} : { sessionId: command.sessionId };
|
||||
if (command.method === "Network.enable") {
|
||||
const url = `${origin}/initial.json`;
|
||||
return [
|
||||
{
|
||||
...session,
|
||||
method: "Network.requestWillBeSent",
|
||||
params: {
|
||||
requestId: "initial",
|
||||
request: { url, method: "GET" },
|
||||
initiator: { type: "other" },
|
||||
},
|
||||
},
|
||||
{
|
||||
...session,
|
||||
method: "Network.responseReceived",
|
||||
params: {
|
||||
requestId: "initial",
|
||||
response: { url, status: 200, mimeType: "application/json" },
|
||||
},
|
||||
},
|
||||
{
|
||||
...session,
|
||||
method: "Network.loadingFinished",
|
||||
params: { requestId: "initial", encodedDataLength: 16 },
|
||||
},
|
||||
];
|
||||
}
|
||||
if (command.method !== "Network.getResponseBody") return undefined;
|
||||
const url = `${origin}/late.json`;
|
||||
return [
|
||||
{
|
||||
...session,
|
||||
method: "Network.requestWillBeSent",
|
||||
params: {
|
||||
requestId: "late",
|
||||
request: { url, method: "GET" },
|
||||
initiator: { type: "other" },
|
||||
},
|
||||
},
|
||||
{
|
||||
...session,
|
||||
method: "Network.responseReceived",
|
||||
params: {
|
||||
requestId: "late",
|
||||
response: { url, status: 200, mimeType: "application/json" },
|
||||
},
|
||||
},
|
||||
{
|
||||
...session,
|
||||
method: "Network.loadingFinished",
|
||||
params: { requestId: "late", encodedDataLength: 14 },
|
||||
},
|
||||
];
|
||||
},
|
||||
commandResult(command) {
|
||||
return command.method === "Network.getResponseBody"
|
||||
? { body: '{"initial":true}', base64Encoded: false }
|
||||
: undefined;
|
||||
},
|
||||
});
|
||||
trackBrowser(browser);
|
||||
const result = await new CdpBrowserProvider().inspectPage(
|
||||
inspectWebPageInputSchema.parse({
|
||||
cdp_endpoint: browser.endpoint,
|
||||
allowed_origins: [browser.allowedOrigin],
|
||||
target_id: "allowed-page",
|
||||
observation_ms: 20,
|
||||
include_json_body_shapes: true,
|
||||
}),
|
||||
);
|
||||
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.network.requests).toEqual([
|
||||
expect.objectContaining({
|
||||
request_id: "initial",
|
||||
body_shapes: {
|
||||
status: "included",
|
||||
request: null,
|
||||
response: expect.any(Object),
|
||||
},
|
||||
}),
|
||||
expect.objectContaining({
|
||||
request_id: "late",
|
||||
body_shapes: { status: "unavailable", request: null, response: null },
|
||||
}),
|
||||
]);
|
||||
expect(result.value.completeness.unavailable_sections).toContain(
|
||||
"json_body_shapes",
|
||||
);
|
||||
});
|
||||
|
||||
it("does not attach a redirect response body to the reused request ID", async () => {
|
||||
const browser = await startFakeCdpBrowser({
|
||||
commandEvents(command, origin) {
|
||||
const session =
|
||||
command.sessionId === undefined ? {} : { sessionId: command.sessionId };
|
||||
if (command.method === "Network.enable") {
|
||||
const url = `${origin}/before-redirect.json`;
|
||||
return [
|
||||
{
|
||||
...session,
|
||||
method: "Network.requestWillBeSent",
|
||||
params: {
|
||||
requestId: "reused",
|
||||
request: { url, method: "GET" },
|
||||
initiator: { type: "other" },
|
||||
},
|
||||
},
|
||||
{
|
||||
...session,
|
||||
method: "Network.responseReceived",
|
||||
params: {
|
||||
requestId: "reused",
|
||||
response: { url, status: 302, mimeType: "application/json" },
|
||||
},
|
||||
},
|
||||
{
|
||||
...session,
|
||||
method: "Network.loadingFinished",
|
||||
params: { requestId: "reused", encodedDataLength: 12 },
|
||||
},
|
||||
];
|
||||
}
|
||||
if (command.method !== "Network.getResponseBody") return undefined;
|
||||
const previousUrl = `${origin}/before-redirect.json`;
|
||||
const nextUrl = `${origin}/after-redirect.json`;
|
||||
return [
|
||||
{
|
||||
...session,
|
||||
method: "Network.requestWillBeSent",
|
||||
params: {
|
||||
requestId: "reused",
|
||||
request: { url: nextUrl, method: "GET" },
|
||||
initiator: { type: "other" },
|
||||
redirectResponse: {
|
||||
url: previousUrl,
|
||||
status: 302,
|
||||
mimeType: "application/json",
|
||||
encodedDataLength: 12,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
...session,
|
||||
method: "Network.responseReceived",
|
||||
params: {
|
||||
requestId: "reused",
|
||||
response: {
|
||||
url: nextUrl,
|
||||
status: 200,
|
||||
mimeType: "application/json",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
...session,
|
||||
method: "Network.loadingFinished",
|
||||
params: { requestId: "reused", encodedDataLength: 14 },
|
||||
},
|
||||
];
|
||||
},
|
||||
commandResult(command) {
|
||||
return command.method === "Network.getResponseBody"
|
||||
? { body: '{"belongs":"redirect"}', base64Encoded: false }
|
||||
: undefined;
|
||||
},
|
||||
});
|
||||
trackBrowser(browser);
|
||||
const result = await new CdpBrowserProvider().inspectPage(
|
||||
inspectWebPageInputSchema.parse({
|
||||
cdp_endpoint: browser.endpoint,
|
||||
allowed_origins: [browser.allowedOrigin],
|
||||
target_id: "allowed-page",
|
||||
observation_ms: 20,
|
||||
include_json_body_shapes: true,
|
||||
}),
|
||||
);
|
||||
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.network.requests).toEqual([
|
||||
expect.objectContaining({
|
||||
request_id: "reused",
|
||||
url: `${browser.allowedOrigin}/after-redirect.json`,
|
||||
redirects: [expect.objectContaining({ status: 302 })],
|
||||
body_shapes: { status: "unavailable", request: null, response: null },
|
||||
}),
|
||||
]);
|
||||
expect(result.value.completeness.unavailable_sections).toContain(
|
||||
"json_body_shapes",
|
||||
);
|
||||
});
|
||||
|
||||
it("marks malformed JSON body shapes unavailable while preserving partial request shapes", async () => {
|
||||
const browser = await startFakeCdpBrowser({
|
||||
commandEvents(command, origin) {
|
||||
@@ -301,6 +498,12 @@ it("rejects malformed response-body envelopes and preserves request shapes", asy
|
||||
reason: "invalid_protocol_value",
|
||||
count: 2,
|
||||
});
|
||||
expect(result.value.completeness.excluded).not.toContainEqual(
|
||||
expect.objectContaining({
|
||||
section: "json_body_shapes",
|
||||
reason: "provider_unavailable",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
|
||||
@@ -339,8 +339,10 @@ const captureBody = (source: BodySource, body: string): WebPageInspection => {
|
||||
encodedDataLength: Buffer.byteLength(responseBody),
|
||||
},
|
||||
});
|
||||
expect(events.responseBodyRequestIds()).toEqual(["request-1"]);
|
||||
events.ingestResponseBody("request-1", {
|
||||
const candidate = events.responseBodyRequests()[0];
|
||||
expect(candidate?.requestId).toBe("request-1");
|
||||
expect(candidate).toBeDefined();
|
||||
events.ingestResponseBody(candidate!, {
|
||||
body:
|
||||
source === "base64 response"
|
||||
? Buffer.from(responseBody).toString("base64")
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
} from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { expect } from "vitest";
|
||||
import { PRODUCT_IDENTITY } from "../../../src/identity.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
|
||||
@@ -259,3 +260,39 @@ for (const group of groups) {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
cliTest("uninstall names each retained skill directory", async ({ cli }) => {
|
||||
const home = await createTestTempDirectory("rea-uninstall-skill-paths-");
|
||||
const shared = join(home, ".agents", "skills", PRODUCT_IDENTITY.skillName);
|
||||
const claude = join(home, ".claude", "skills", PRODUCT_IDENTITY.skillName);
|
||||
for (const directory of [shared, claude]) {
|
||||
await mkdir(directory, { recursive: true });
|
||||
await writeFile(join(directory, "SKILL.md"), "---\nname: unrelated\n---\n");
|
||||
}
|
||||
|
||||
const result = await cli.run({
|
||||
arguments: ["uninstall", "--json"],
|
||||
cwd: home,
|
||||
environment: {
|
||||
HOME: home,
|
||||
USERPROFILE: home,
|
||||
CLAUDE_CONFIG_DIR: join(home, ".claude"),
|
||||
},
|
||||
timeoutMs: 20_000,
|
||||
});
|
||||
|
||||
expect(result.exitCode, result.stderr).toBe(0);
|
||||
const report = result.json as {
|
||||
items?: readonly { name: string; status: string; detail: string }[];
|
||||
};
|
||||
const skill = report.items?.find(({ name }) => name === "skill");
|
||||
expect(skill?.status).toBe("retained");
|
||||
for (const directory of [shared, claude]) {
|
||||
expect(skill?.detail).toContain(
|
||||
`${directory}: retained (Skill manifest is not REA-owned.)`,
|
||||
);
|
||||
expect(await readFile(join(directory, "SKILL.md"), "utf8")).toBe(
|
||||
"---\nname: unrelated\n---\n",
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -245,6 +245,17 @@ describe("binary target I/O: package classification", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("classifies a binary plist by its magic under any extension", async () => {
|
||||
const directory = await createTestTempDirectory("rea-bplist-target-");
|
||||
const path = join(directory, "Model.archive");
|
||||
await writeFile(path, buildBinary({ $archiver: "NSKeyedArchiver" }));
|
||||
const result = await parseBinaryTarget(path);
|
||||
expect(result.ok && result.value).toMatchObject({
|
||||
kind: "artifact",
|
||||
format: "plist",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not trust a ZIP-family extension without ZIP magic", async () => {
|
||||
const directory = await createTestTempDirectory("rea-fake-archive-");
|
||||
const path = join(directory, "fake.zip");
|
||||
|
||||
@@ -199,3 +199,38 @@ describe("nested container family", () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("package signature byte identity", () => {
|
||||
it.each([
|
||||
{ extension: "pkg", signature: "xar!", offset: 0, size: 4 },
|
||||
{ extension: "dmg", signature: "koly", offset: 0, size: 512 },
|
||||
])(
|
||||
"rejects high-bit aliases of $extension magic at both admission boundaries",
|
||||
async ({ extension, signature, offset, size }) => {
|
||||
const root = await createTestTempDirectory("rea-package-magic-");
|
||||
const path = join(root, `input.${extension}`);
|
||||
const bytes = Buffer.alloc(size);
|
||||
bytes.write(signature, offset, "ascii");
|
||||
await writeFile(path, bytes);
|
||||
expect(
|
||||
(await classifyAndHashRoot(path, false, await lstat(path))).format,
|
||||
).toBe(extension);
|
||||
expect(await parseBinaryTarget(path)).toMatchObject({
|
||||
ok: true,
|
||||
value: { format: extension },
|
||||
});
|
||||
for (let index = 0; index < signature.length; index += 1) {
|
||||
const changed = Buffer.from(bytes);
|
||||
changed[offset + index] = changed[offset + index]! | 0x80;
|
||||
await writeFile(path, changed);
|
||||
expect(
|
||||
(await classifyAndHashRoot(path, false, await lstat(path))).format,
|
||||
).toBe("file");
|
||||
expect(await parseBinaryTarget(path)).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "BinaryTargetError" },
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -5,7 +5,11 @@ import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import type { AnalysisClient } from "../../../src/application/AnalysisProvider.js";
|
||||
import {
|
||||
createAnalysisExecution,
|
||||
type AnalysisClient,
|
||||
} from "../../../src/application/AnalysisProvider.js";
|
||||
import type { AnalysisProfileCommitment } from "../../../src/domain/analysisProfile.js";
|
||||
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
||||
import { ARTIFACT_COMPARISON_EXAMPLE } from "../../../src/contracts/artifactComparisonExample.js";
|
||||
import { PROCESS_CAPTURE_REFERENCE } from "../../../src/contracts/investigationExamples.js";
|
||||
@@ -29,26 +33,33 @@ afterEach(async () => {
|
||||
describe("guided prompt completion from live analysis", () => {
|
||||
it("reads live documents and complete procedures without ambiguous names", async () => {
|
||||
const requests: Array<Readonly<Record<string, unknown>>> = [];
|
||||
const session = createTestBinarySession(() => client(requests), {
|
||||
resolveAnalysisProfile: () =>
|
||||
Promise.resolve(
|
||||
resultOk({
|
||||
profile: createAnalysisProfile(
|
||||
{
|
||||
id: "fixture",
|
||||
name: "Fixture analysis provider",
|
||||
version: "1",
|
||||
},
|
||||
{ fixture: true },
|
||||
),
|
||||
}),
|
||||
),
|
||||
});
|
||||
const session = createTestBinarySession(
|
||||
(_target, profile) => client(requests, profile),
|
||||
{
|
||||
resolveAnalysisProfile: () =>
|
||||
Promise.resolve(
|
||||
resultOk({
|
||||
profile: createAnalysisProfile(
|
||||
{
|
||||
id: "fixture",
|
||||
name: "Fixture analysis provider",
|
||||
version: "1",
|
||||
},
|
||||
{ fixture: true },
|
||||
),
|
||||
}),
|
||||
),
|
||||
},
|
||||
);
|
||||
directory = await createTestTempDirectory("rea-prompt-completion-");
|
||||
const target = join(directory, "fixture.hop");
|
||||
await writeFile(target, "fixture");
|
||||
expect((await session.open(target)).ok).toBe(true);
|
||||
const completion = createPromptCompletionSource(session, session);
|
||||
expect(await completion.complete("document", "app")).toEqual([]);
|
||||
expect(await completion.complete("procedure", "")).toEqual([]);
|
||||
const warmed = await session.execute("list_documents", {});
|
||||
if (!warmed.ok) throw warmed.error;
|
||||
|
||||
expect(await completion.complete("document", "app")).toEqual([
|
||||
"App",
|
||||
@@ -269,14 +280,23 @@ const fixtureEnvironment = {
|
||||
|
||||
const client = (
|
||||
requests: Array<Readonly<Record<string, unknown>>>,
|
||||
): AnalysisClient => ({
|
||||
execute(operation, parameters) {
|
||||
analysisProfile?: AnalysisProfileCommitment,
|
||||
): AnalysisClient => {
|
||||
const observe = (value: unknown) =>
|
||||
resultOk(
|
||||
createAnalysisExecution(
|
||||
value,
|
||||
analysisProfile?.provider ?? fixtureProvider,
|
||||
analysisProfile === undefined ? {} : { analysisProfile },
|
||||
),
|
||||
);
|
||||
const execute: AnalysisClient["execute"] = (operation, parameters) => {
|
||||
if (operation === "list_documents")
|
||||
return Promise.resolve(observed(["AppTests", "App", "App"]));
|
||||
return Promise.resolve(observe(["AppTests", "App", "App"]));
|
||||
if (operation === "list_procedures") {
|
||||
requests.push(parameters);
|
||||
return Promise.resolve(
|
||||
observed([
|
||||
observe([
|
||||
{ address: "0x1000", value: "duplicate" },
|
||||
{ address: "0x2000", value: "unique" },
|
||||
{ address: "0x3000", value: "duplicate" },
|
||||
@@ -284,7 +304,11 @@ const client = (
|
||||
]),
|
||||
);
|
||||
}
|
||||
return Promise.resolve(observed(null));
|
||||
},
|
||||
close: () => Promise.resolve(resultOk(null)),
|
||||
});
|
||||
return Promise.resolve(observe(null));
|
||||
};
|
||||
return {
|
||||
execute,
|
||||
executeIfReady: execute,
|
||||
close: () => Promise.resolve(resultOk(null)),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -11,7 +11,22 @@ import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
import type { AnalysisClient } from "../../../src/application/AnalysisProvider.js";
|
||||
import {
|
||||
createAnalysisExecution,
|
||||
type AnalysisClient,
|
||||
} from "../../../src/application/AnalysisProvider.js";
|
||||
import type { JsonValue } from "../../../src/domain/jsonValue.js";
|
||||
import type {
|
||||
AnalysisProvider,
|
||||
AnalysisProviderCandidate,
|
||||
CapabilityDescriptor,
|
||||
ProviderIdentity,
|
||||
} from "../../../src/application/AnalysisProvider.js";
|
||||
import { AnalysisProviderRegistry } from "../../../src/application/binary/AnalysisProviderRegistry.js";
|
||||
import { composeBinarySession } from "../../../src/application/binary/BinarySessionComposition.js";
|
||||
import { createAnalysisProfile } from "../../../src/domain/analysisProfile.js";
|
||||
import { AnalysisCancelledError } from "../../../src/domain/analysisErrorCore.js";
|
||||
import { err, ok } from "../../../src/domain/result.js";
|
||||
import {
|
||||
createCacheProvider,
|
||||
createTestBinarySession,
|
||||
@@ -304,6 +319,67 @@ describe("guided prompt completion registry", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("guided prompt completion avoids cold startup and cancels warm lookup on close", async () => {
|
||||
const directory = await createTestTempDirectory("rea-prompt-warm-only-");
|
||||
temporaryDirectories.push(directory);
|
||||
const target = join(directory, "target.hop");
|
||||
await writeFile(target, "fixture target");
|
||||
const fixture = await createWarmCompletionFixture(target);
|
||||
const { client } = fixture;
|
||||
|
||||
const opened = await client.callTool({
|
||||
name: "open_binary",
|
||||
arguments: { path: target },
|
||||
});
|
||||
expect(opened.isError).not.toBe(true);
|
||||
expect(fixture.childrenCreated()).toBe(0);
|
||||
expect(await complete(client, "document", "")).toEqual([]);
|
||||
expect(await complete(client, "procedure", "")).toEqual([]);
|
||||
expect(fixture.childrenCreated()).toBe(0);
|
||||
|
||||
const startup = fixture.holdStartup();
|
||||
const warming = client.callTool({ name: "list_documents", arguments: {} });
|
||||
await startup.started;
|
||||
expect(await complete(client, "document", "")).toEqual([]);
|
||||
expect(await complete(client, "procedure", "")).toEqual([]);
|
||||
expect(fixture.childrenCreated()).toBe(1);
|
||||
startup.finish();
|
||||
const warmed = await warming;
|
||||
expect(warmed.isError, JSON.stringify(warmed)).not.toBe(true);
|
||||
expect(fixture.childrenCreated()).toBe(1);
|
||||
expect(await complete(client, "document", "fixture")).toEqual([
|
||||
"fixture-document",
|
||||
]);
|
||||
|
||||
const cancellation = fixture.holdCompletion();
|
||||
const controller = new AbortController();
|
||||
const cancelled = client.complete(
|
||||
{
|
||||
ref: { type: "ref/prompt", name: "investigate_feature" },
|
||||
argument: { name: "document", value: "" },
|
||||
},
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
await cancellation.started;
|
||||
controller.abort();
|
||||
await expect(cancelled).rejects.toThrow();
|
||||
await cancellation.aborted;
|
||||
|
||||
const lifecycle = fixture.holdCompletion();
|
||||
const pending = client.complete({
|
||||
ref: { type: "ref/prompt", name: "investigate_feature" },
|
||||
argument: { name: "document", value: "" },
|
||||
});
|
||||
await lifecycle.started;
|
||||
const closed = await client.callTool({
|
||||
name: "close_binary",
|
||||
arguments: {},
|
||||
});
|
||||
expect(closed.isError).not.toBe(true);
|
||||
await lifecycle.aborted;
|
||||
expect((await pending).completion.values).toEqual([]);
|
||||
}, 10_000);
|
||||
|
||||
describe("guided prompt completion lifecycle", () => {
|
||||
it("survives a cancelled completion and ignores its late result", async () => {
|
||||
let calls = 0;
|
||||
@@ -410,6 +486,181 @@ describe("guided prompt completion lifecycle", () => {
|
||||
}, 10_000);
|
||||
});
|
||||
|
||||
const createWarmCompletionFixture = async (target: string) => {
|
||||
const identity = {
|
||||
id: "deep-fixture",
|
||||
name: "Deep fixture provider",
|
||||
version: "1",
|
||||
};
|
||||
const analysisProfile = createAnalysisProfile(identity, { fixture: true });
|
||||
const observeCompletion = (result: JsonValue) =>
|
||||
resultOk(createAnalysisExecution(result, identity, { analysisProfile }));
|
||||
let childrenCreated = 0;
|
||||
let ready = false;
|
||||
let startupGate:
|
||||
| {
|
||||
readonly started: () => void;
|
||||
readonly release: Promise<void>;
|
||||
}
|
||||
| undefined;
|
||||
let completionGate:
|
||||
| {
|
||||
readonly started: () => void;
|
||||
readonly aborted: () => void;
|
||||
}
|
||||
| undefined;
|
||||
const deep = deepProvider(identity, {
|
||||
createClient() {
|
||||
childrenCreated += 1;
|
||||
return {
|
||||
execute: async (operation) => {
|
||||
if (operation !== "health") {
|
||||
const gate = startupGate;
|
||||
if (gate !== undefined) {
|
||||
startupGate = undefined;
|
||||
gate.started();
|
||||
await gate.release;
|
||||
}
|
||||
ready = true;
|
||||
}
|
||||
return observeCompletion(
|
||||
operation === "list_documents"
|
||||
? ["fixture-document"]
|
||||
: operation === "list_procedures"
|
||||
? [{ address: "0x1000", value: "fixture-procedure" }]
|
||||
: null,
|
||||
);
|
||||
},
|
||||
executeIfReady(operation, _parameters, options) {
|
||||
if (
|
||||
!ready ||
|
||||
(operation !== "list_documents" && operation !== "list_procedures")
|
||||
)
|
||||
return Promise.resolve(undefined);
|
||||
const gate = completionGate;
|
||||
if (gate === undefined)
|
||||
return Promise.resolve(
|
||||
observeCompletion(
|
||||
operation === "list_documents"
|
||||
? ["fixture-document"]
|
||||
: [{ address: "0x1000", value: "fixture-procedure" }],
|
||||
),
|
||||
);
|
||||
completionGate = undefined;
|
||||
gate.started();
|
||||
return new Promise((resolve) => {
|
||||
const signal = options?.signal;
|
||||
const cancel = (): void => {
|
||||
gate.aborted();
|
||||
resolve(err(new AnalysisCancelledError(operation)));
|
||||
};
|
||||
if (signal?.aborted === true) cancel();
|
||||
else signal?.addEventListener("abort", cancel, { once: true });
|
||||
});
|
||||
},
|
||||
close: () => Promise.resolve(resultOk(null)),
|
||||
};
|
||||
},
|
||||
});
|
||||
const auxiliaryIdentity: ProviderIdentity = {
|
||||
id: "aux-fixture",
|
||||
name: "Aux fixture",
|
||||
version: "1",
|
||||
};
|
||||
const auxiliary: AnalysisProvider = {
|
||||
identity: () => auxiliaryIdentity,
|
||||
capabilities: () => [
|
||||
promptCapability(auxiliaryIdentity, "inspect_artifact"),
|
||||
],
|
||||
createClient: () => ({
|
||||
execute: () => Promise.resolve(observed(null)),
|
||||
close: () => Promise.resolve(resultOk(null)),
|
||||
}),
|
||||
};
|
||||
const session = composeBinarySession(new AnalysisProviderRegistry([deep]), [
|
||||
auxiliary,
|
||||
]);
|
||||
const client = await connect(createServer({ kind: "session", session }));
|
||||
resources.push(session);
|
||||
return {
|
||||
client,
|
||||
childrenCreated: () => childrenCreated,
|
||||
holdStartup: () => {
|
||||
let started = (): void => undefined;
|
||||
let finish = (): void => undefined;
|
||||
const observedStart = new Promise<void>((resolve) => {
|
||||
started = resolve;
|
||||
});
|
||||
const release = new Promise<void>((resolve) => {
|
||||
finish = resolve;
|
||||
});
|
||||
startupGate = { started, release };
|
||||
return { started: observedStart, finish };
|
||||
},
|
||||
holdCompletion: () => {
|
||||
let started = (): void => undefined;
|
||||
let aborted = (): void => undefined;
|
||||
const observedStart = new Promise<void>((resolve) => {
|
||||
started = resolve;
|
||||
});
|
||||
const observedAbort = new Promise<void>((resolve) => {
|
||||
aborted = resolve;
|
||||
});
|
||||
completionGate = { started, aborted };
|
||||
return { started: observedStart, aborted: observedAbort };
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
const deepProvider = (
|
||||
identity: Parameters<typeof createAnalysisProfile>[0],
|
||||
options: {
|
||||
readonly createClient: AnalysisProviderCandidate["createClient"];
|
||||
},
|
||||
): AnalysisProviderCandidate => ({
|
||||
identity: () => identity,
|
||||
capabilities: () => [
|
||||
promptCapability(identity, "list_documents"),
|
||||
promptCapability(identity, "list_procedures"),
|
||||
],
|
||||
inspectAvailability: () => ({
|
||||
status: "available",
|
||||
code: null,
|
||||
reason: null,
|
||||
diagnostics: {},
|
||||
}),
|
||||
inspectTargetSupport: () => ({
|
||||
status: "supported",
|
||||
code: null,
|
||||
reason: null,
|
||||
diagnostics: {},
|
||||
}),
|
||||
resolveAnalysisProfile: async () =>
|
||||
ok({ profile: createAnalysisProfile(identity, { fixture: true }) }),
|
||||
createClient: options.createClient,
|
||||
});
|
||||
|
||||
const promptCapability = (
|
||||
provider: ProviderIdentity,
|
||||
operation: CapabilityDescriptor["operation"],
|
||||
): CapabilityDescriptor => ({
|
||||
provider,
|
||||
operation,
|
||||
available: true,
|
||||
reason: null,
|
||||
cachePolicy: "live",
|
||||
effects: {
|
||||
mutatesArtifact: false,
|
||||
launchesProcess: false,
|
||||
mayShowUi: false,
|
||||
mayAccessNetwork: false,
|
||||
mayWriteFilesystem: false,
|
||||
changesPermissions: false,
|
||||
requiresRoot: false,
|
||||
},
|
||||
limitations: [],
|
||||
});
|
||||
|
||||
const fixtureProvider = { id: "fixture", name: "Fixture", version: "1" };
|
||||
|
||||
const fixtureSession = (
|
||||
@@ -461,6 +712,22 @@ const lifecycleClient = (
|
||||
}
|
||||
return Promise.resolve(observed(null));
|
||||
},
|
||||
executeIfReady(operation, parameters) {
|
||||
if (operation === "list_documents")
|
||||
return Promise.resolve(observed([`${target}-document`]));
|
||||
if (operation === "list_procedures") {
|
||||
requests.push(parameters);
|
||||
return Promise.resolve(
|
||||
observed([
|
||||
{
|
||||
address: target === "first" ? "0x1000" : "0x2000",
|
||||
value: `${target}-procedure`,
|
||||
},
|
||||
]),
|
||||
);
|
||||
}
|
||||
return Promise.resolve(undefined);
|
||||
},
|
||||
close: () => Promise.resolve(resultOk(null)),
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { access, stat } from "node:fs/promises";
|
||||
import { access, stat, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
@@ -57,7 +58,8 @@ describe("provider process runtime and wait primitives", () => {
|
||||
parent: tmpdir(),
|
||||
prefix: "rea-provider-test-",
|
||||
});
|
||||
expect((await stat(runtime.path)).mode & 0o777).toBe(0o700);
|
||||
expect((await stat(runtime.path)).mode & 0o077).toBe(0);
|
||||
await writeFile(join(runtime.path, "owned-scratch"), "fixture");
|
||||
|
||||
const first = runtime.close();
|
||||
const second = runtime.close();
|
||||
|
||||
@@ -150,6 +150,26 @@ afterEach(async () => {
|
||||
await Promise.all(clients.splice(0).map((client) => client.close()));
|
||||
});
|
||||
|
||||
describe("GhidraClient ready-only dispatch", () => {
|
||||
it("does not start cold and preserves the normal result once ready", async () => {
|
||||
const launcher = new FixtureLauncher();
|
||||
const client = clientFor(launcher);
|
||||
|
||||
await expect(client.callToolIfReady("list_strings", {})).resolves.toBe(
|
||||
undefined,
|
||||
);
|
||||
expect(launcher.processes).toEqual([]);
|
||||
|
||||
const started = await client.start();
|
||||
if (!started.ok) throw started.error;
|
||||
await expect(client.callToolIfReady("list_strings", {})).resolves.toEqual({
|
||||
ok: true,
|
||||
value: [expect.objectContaining({ value: "fixture value" })],
|
||||
});
|
||||
expect(launcher.processes).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
it("reports unknown startup work and stops notifications when cancellation releases the process", async () => {
|
||||
vi.useFakeTimers({ toFake: ["setInterval", "clearInterval"] });
|
||||
const launcher = new FixtureLauncher("silent");
|
||||
|
||||
@@ -15,6 +15,26 @@ import {
|
||||
} from "./hopperClient.fixture.js";
|
||||
|
||||
describe("HopperClient protocol", () => {
|
||||
it("does not start cold and preserves normal dispatch once ready", async () => {
|
||||
const launcher = new FixtureLauncher();
|
||||
const client = new HopperClient({ launcher, startupTimeoutMs: 1_000 });
|
||||
onTestFinished(async () => {
|
||||
await client.close();
|
||||
});
|
||||
|
||||
await expect(
|
||||
client.callToolIfReady("echo", { label: "cold" }),
|
||||
).resolves.toBe(undefined);
|
||||
expect(launcher.processes).toEqual([]);
|
||||
|
||||
const started = await client.start();
|
||||
if (!started.ok) throw started.error;
|
||||
await expect(
|
||||
client.callToolIfReady("echo", { label: "warm" }),
|
||||
).resolves.toEqual({ ok: true, value: { label: "warm" } });
|
||||
expect(launcher.processes).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("sanitizes unexpected owned-cleanup exceptions", () => {
|
||||
expect(
|
||||
providerCleanupFailure(
|
||||
|
||||
Vendored
+2
@@ -12,3 +12,5 @@ WABT and compares exact producer output against the public CLI/MCP surfaces.
|
||||
`custom-names.wat` covers newlines, quotes, Unicode, backslashes, embedded
|
||||
section markers and NUL in custom names; objdump displays those names without
|
||||
escaping and ends each at its first NUL.
|
||||
It also covers leading U+FEFF, including a name distinct from the special `name`
|
||||
section, and distinguishes a U+FEFF-only name from an empty name.
|
||||
|
||||
Vendored
+5
-1
@@ -2,4 +2,8 @@
|
||||
(@custom "test\0aline" "payload")
|
||||
(@custom "fake\22\0aSection Details:\0a Type start=0x0000000a end=0x0000000b (size=0x00000001) count: 0\0a\22end" "payload")
|
||||
(@custom "unicode-\c3\a9\\\t" "payload")
|
||||
(@custom "visible\00hidden" "payload"))
|
||||
(@custom "visible\00hidden" "payload")
|
||||
(@custom "\ef\bb\bfsection" "payload")
|
||||
(@custom "\ef\bb\bfname" "payload")
|
||||
(@custom "\ef\bb\bf" "payload")
|
||||
(@custom "" "payload"))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { resolve } from "node:path";
|
||||
import { tmpdir } from "node:os";
|
||||
|
||||
import {
|
||||
createTestWorkspace,
|
||||
@@ -58,6 +59,15 @@ export const createTestCli = (
|
||||
cwd: cwd ?? process.cwd(),
|
||||
env: {
|
||||
PATH: process.env.PATH ?? "",
|
||||
// Native Windows APIs need the system root and a writable temporary
|
||||
// directory even when the command's application environment is empty.
|
||||
...(process.platform === "win32"
|
||||
? {
|
||||
SystemRoot: process.env.SystemRoot,
|
||||
TEMP: tmpdir(),
|
||||
TMP: tmpdir(),
|
||||
}
|
||||
: {}),
|
||||
...(compileCache === undefined ||
|
||||
environment?.NODE_V8_COVERAGE !== undefined
|
||||
? {}
|
||||
|
||||
Reference in New Issue
Block a user