fix(setup): reconcile client plans and native registration fields
This commit is contained in:
@@ -366,16 +366,11 @@ it("rejects overlapping ZIP member data ranges through artifact inventory", asyn
|
||||
bytes.writeUInt32LE(firstLocalOffset, second + 42);
|
||||
await writeFile(path, bytes);
|
||||
|
||||
const target = await parseBinaryTarget(path);
|
||||
if (!target.ok) throw target.error;
|
||||
const result = await withArtifactClient(target.value, (client) =>
|
||||
client.execute("inventory_artifact", {}),
|
||||
await expectInventoryFailure(
|
||||
path,
|
||||
"format",
|
||||
"ZIP archive is malformed: Overlapping entry found",
|
||||
);
|
||||
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "ArtifactOperationError", reason: "io" },
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves encrypted-member and corrupt-CRC observations", async () => {
|
||||
@@ -438,16 +433,11 @@ it("preserves encrypted-member and corrupt-CRC observations", async () => {
|
||||
bytes[dataOffset] = firstByte ^ 1;
|
||||
await writeFile(corruptPath, bytes);
|
||||
|
||||
const corruptTarget = await parseBinaryTarget(corruptPath);
|
||||
if (!corruptTarget.ok) throw corruptTarget.error;
|
||||
const corruptResult = await withArtifactClient(
|
||||
corruptTarget.value,
|
||||
(client) => client.execute("inventory_artifact", {}),
|
||||
await expectInventoryFailure(
|
||||
corruptPath,
|
||||
"format",
|
||||
"ZIP archive is malformed: Invalid compressed data",
|
||||
);
|
||||
expect(corruptResult).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "ArtifactOperationError", reason: "io" },
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects a truncated ZIP through artifact inventory", async () => {
|
||||
@@ -455,17 +445,51 @@ it("rejects a truncated ZIP through artifact inventory", async () => {
|
||||
const path = join(root, "truncated.zip");
|
||||
await writeFile(path, Buffer.from([0x50, 0x4b, 0x03, 0x04]));
|
||||
|
||||
await expectInventoryFailure(
|
||||
path,
|
||||
"format",
|
||||
"ZIP archive is malformed: File format is not recognized",
|
||||
);
|
||||
});
|
||||
|
||||
it("reports an unsupported ZIP compression method as unavailable", async () => {
|
||||
const root = await createTestTempDirectory("rea-zip-method-");
|
||||
const path = join(root, "lzma.zip");
|
||||
const writer = new ZipWriter(new Uint8ArrayWriter());
|
||||
await writer.add("data.txt", new TextReader("member bytes"), { level: 0 });
|
||||
const bytes = Buffer.from(await writer.close());
|
||||
// Declare LZMA (14) in both headers; REA reads only stored and Deflate data.
|
||||
const localHeader = bytes.indexOf(Buffer.from([0x50, 0x4b, 0x03, 0x04]));
|
||||
const centralHeader = bytes.indexOf(Buffer.from([0x50, 0x4b, 0x01, 0x02]));
|
||||
if (localHeader < 0 || centralHeader < 0)
|
||||
throw new Error("Expected ZIP local and central headers");
|
||||
bytes.writeUInt16LE(14, localHeader + 8);
|
||||
bytes.writeUInt16LE(14, centralHeader + 10);
|
||||
await writeFile(path, bytes);
|
||||
|
||||
await expectInventoryFailure(
|
||||
path,
|
||||
"unavailable",
|
||||
"ZIP archive uses an unsupported feature: Compression method not supported",
|
||||
);
|
||||
});
|
||||
|
||||
/** Inventory one archive through the provider and expect a typed failure. */
|
||||
const expectInventoryFailure = async (
|
||||
path: string,
|
||||
reason: string,
|
||||
detail: string,
|
||||
): Promise<void> => {
|
||||
const target = await parseBinaryTarget(path);
|
||||
if (!target.ok) throw target.error;
|
||||
const result = await withArtifactClient(target.value, (client) =>
|
||||
client.execute("inventory_artifact", {}),
|
||||
);
|
||||
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "ArtifactOperationError", reason: "io" },
|
||||
error: { _tag: "ArtifactOperationError", reason, detail },
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const writeSingleEntryZip = async (
|
||||
path: string,
|
||||
|
||||
@@ -118,14 +118,21 @@ it("reuses only scheduled qualification and preserves every explicit full reques
|
||||
).toBe("fast");
|
||||
});
|
||||
|
||||
it("keeps every translated root README and authored guide on the documentation lane", async () => {
|
||||
it("keeps every translated README and authored guide on the documentation lane", async () => {
|
||||
const { directory, base } = await fixture();
|
||||
const readmes = (await readdir(new URL("../../../", import.meta.url))).filter(
|
||||
(name) => /^README(?:_.*)?\.md$/u.test(name),
|
||||
);
|
||||
const translated = (
|
||||
await readdir(new URL("../../../docs/readme/", import.meta.url))
|
||||
)
|
||||
.filter((name) => /^README_.*\.md$/u.test(name))
|
||||
.map((name) => `docs/readme/${name}`);
|
||||
expect(readmes).toContain("README.md");
|
||||
expect(translated.length).toBeGreaterThan(0);
|
||||
const head = await change(directory, [
|
||||
...readmes,
|
||||
...translated,
|
||||
"docs/guide.md",
|
||||
"AGENTS.md",
|
||||
"CONTRIBUTING.md",
|
||||
@@ -198,7 +205,7 @@ it("emits an observational owner proposal without changing ordinary or full port
|
||||
it("does not charge a documentation PR for unrelated implementation updates on main", async () => {
|
||||
const { directory, base } = await fixture();
|
||||
await git(directory, ["switch", "-c", "docs/change"]);
|
||||
const head = await change(directory, ["README_zh-TW.md"]);
|
||||
const head = await change(directory, ["docs/readme/README_zh-TW.md"]);
|
||||
await git(directory, ["switch", "main"]);
|
||||
const advancedBase = await change(directory, ["src/anotherProvider.ts"]);
|
||||
expect(advancedBase).not.toBe(base);
|
||||
@@ -240,7 +247,7 @@ it("retains complete checks when implementation is renamed into documentation",
|
||||
|
||||
it("keeps main pushes scoped when a successful ancestor baseline is available", async () => {
|
||||
const { directory, base } = await fixture();
|
||||
const head = await change(directory, ["README_ja.md"]);
|
||||
const head = await change(directory, ["docs/readme/README_ja.md"]);
|
||||
expect(await classify(directory, base, head, "push")).toMatchObject({
|
||||
tier: "fast",
|
||||
code: false,
|
||||
@@ -449,6 +456,10 @@ it.each([
|
||||
sqlite: false,
|
||||
},
|
||||
],
|
||||
[
|
||||
"scripts/verify-solidity-metadata.mjs",
|
||||
{ code: true, evm: true, browser: false, package: false },
|
||||
],
|
||||
[
|
||||
"src/browser/execution/evaluate.ts",
|
||||
{
|
||||
@@ -470,7 +481,10 @@ it.each([
|
||||
{ code: false, website: true, package: false },
|
||||
],
|
||||
["scripts/website_i18n.py", { code: false, website: true, package: false }],
|
||||
["README_ja.md", { code: false, docs: true, website: true, package: false }],
|
||||
[
|
||||
"docs/readme/README_ja.md",
|
||||
{ code: false, docs: true, website: true, package: false },
|
||||
],
|
||||
[
|
||||
".github/workflows/website-pages.yml",
|
||||
{ code: false, website: true, package: false },
|
||||
@@ -515,6 +529,10 @@ it.each([
|
||||
"src/windows/Example.ts",
|
||||
{ code: true, runtime: true, package: true, apple: false, evm: false },
|
||||
],
|
||||
[
|
||||
"src/domain/javascript/javascriptRuntimeStaticCandidates.ts",
|
||||
{ code: true, runtime: true, package: true, javascript_recovery: true },
|
||||
],
|
||||
["install.sh", { code: true, runtime: true, package: true, evm: false }],
|
||||
[
|
||||
".agents/skills/reverse-engineer-anything/SKILL.md",
|
||||
@@ -920,7 +938,7 @@ it.each(["workflow_dispatch", "schedule"])(
|
||||
it("honors ci:full for successive PR revisions", async () => {
|
||||
const { directory, base } = await fixture();
|
||||
const first = await change(directory, ["README.md"]);
|
||||
const second = await change(directory, ["README_ja.md"]);
|
||||
const second = await change(directory, ["docs/readme/README_ja.md"]);
|
||||
for (const head of [first, second]) {
|
||||
expect(
|
||||
await classify(directory, base, head, "pull_request", true),
|
||||
|
||||
@@ -262,8 +262,8 @@ it("binds provider build reuse to the current run while keeping standalone dispa
|
||||
),
|
||||
),
|
||||
);
|
||||
const download = action.runs.steps.find(
|
||||
(step) => step.uses === "actions/download-artifact@v4",
|
||||
const download = action.runs.steps.find((step) =>
|
||||
step.uses?.startsWith("actions/download-artifact@"),
|
||||
);
|
||||
expect(download?.with).toEqual({
|
||||
name: "${{ inputs.build_cache_artifact }}",
|
||||
|
||||
@@ -0,0 +1,412 @@
|
||||
import {
|
||||
access,
|
||||
mkdir,
|
||||
readFile,
|
||||
rm,
|
||||
symlink,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { CLAUDE_DESKTOP_PACKAGE_FAMILY } from "../../../src/application/ClaudeDesktopConfigLocation.js";
|
||||
import { readClientRegistrationStatuses } from "../../../src/application/ClientRegistrationStatus.js";
|
||||
import { npxRegistrationCommand } from "../../../src/application/ClientRegistrationIdentity.js";
|
||||
import {
|
||||
configureClientConfiguration,
|
||||
inspectClientConfiguration,
|
||||
} from "../../../src/application/SetupClientConfiguration.js";
|
||||
import { detectClients } from "../../../src/application/SetupHost.js";
|
||||
import {
|
||||
supportedClients,
|
||||
type SetupClient,
|
||||
} from "../../../src/application/SupportedClients.js";
|
||||
import {
|
||||
runUninstall,
|
||||
systemUninstallHost,
|
||||
} from "../../../src/application/Uninstall.js";
|
||||
import { clearClientLocationEnvironment } from "../../fixtures/clientEnvironment.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
/** The Windows registration setup writes, independent of the test host. */
|
||||
const command = npxRegistrationCommand("win32");
|
||||
const CONFIG = "claude_desktop_config.json";
|
||||
|
||||
const roots: string[] = [];
|
||||
beforeEach(clearClientLocationEnvironment);
|
||||
afterEach(async () => {
|
||||
vi.unstubAllEnvs();
|
||||
await Promise.all(
|
||||
roots.splice(0).map((root) => rm(root, { recursive: true, force: true })),
|
||||
);
|
||||
});
|
||||
|
||||
/** A Windows profile with separate roaming and local AppData roots. */
|
||||
const windowsProfile = async () => {
|
||||
const home = await createTestTempDirectory("rea-claude-desktop-");
|
||||
roots.push(home);
|
||||
const env = {
|
||||
APPDATA: join(home, "AppData", "Roaming"),
|
||||
LOCALAPPDATA: join(home, "AppData", "Local"),
|
||||
};
|
||||
const appDataConfig = join(env.APPDATA, "Claude", CONFIG);
|
||||
const container = join(
|
||||
env.LOCALAPPDATA,
|
||||
"Packages",
|
||||
CLAUDE_DESKTOP_PACKAGE_FAMILY,
|
||||
);
|
||||
const privateConfig = join(
|
||||
container,
|
||||
"LocalCache",
|
||||
"Roaming",
|
||||
"Claude",
|
||||
CONFIG,
|
||||
);
|
||||
return { home, env, appDataConfig, container, privateConfig };
|
||||
};
|
||||
|
||||
const claudeDesktop = (
|
||||
home: string,
|
||||
env: Readonly<Record<string, string>>,
|
||||
): SetupClient => {
|
||||
const client = supportedClients(home, "win32", env).find(
|
||||
({ name }) => name === "claude_desktop",
|
||||
);
|
||||
if (client === undefined) throw new Error("claude_desktop is not supported");
|
||||
return client;
|
||||
};
|
||||
|
||||
const writeJson = async (path: string, value: unknown): Promise<void> => {
|
||||
await mkdir(dirname(path), { recursive: true });
|
||||
await writeFile(path, `${JSON.stringify(value, null, 2)}\n`);
|
||||
};
|
||||
|
||||
const readJson = async (path: string): Promise<Record<string, unknown>> =>
|
||||
JSON.parse(await readFile(path, "utf8")) as Record<string, unknown>;
|
||||
|
||||
const reaEntry = { command: command[0], args: command.slice(1) };
|
||||
|
||||
describe("Windows Claude Desktop configuration location", () => {
|
||||
it("uses AppData when no MSIX package storage exists", async () => {
|
||||
const { home, env, appDataConfig } = await windowsProfile();
|
||||
await mkdir(
|
||||
join(env.LOCALAPPDATA, "Packages", "Contoso.App_8wekyb3d8bbwe"),
|
||||
{
|
||||
recursive: true,
|
||||
},
|
||||
);
|
||||
|
||||
const client = claudeDesktop(home, env);
|
||||
|
||||
expect(client.configPath).toBe(appDataConfig);
|
||||
expect(client.markerPath).toBe(dirname(appDataConfig));
|
||||
expect(client.msixPackage).toBeUndefined();
|
||||
expect(client.quitBeforeSetup).toBe(true);
|
||||
});
|
||||
|
||||
it("uses the package-private copy that the MSIX package reads", async () => {
|
||||
const { home, env, appDataConfig, container, privateConfig } =
|
||||
await windowsProfile();
|
||||
await writeJson(privateConfig, { preferences: { theme: "dark" } });
|
||||
await writeJson(appDataConfig, { mcpServers: {} });
|
||||
|
||||
const client = claudeDesktop(home, env);
|
||||
|
||||
expect(client.configPath).toBe(privateConfig);
|
||||
expect(client.markerPath).toBe(container);
|
||||
expect(client.msixPackage).toEqual({
|
||||
packageFamilyName: CLAUDE_DESKTOP_PACKAGE_FAMILY,
|
||||
privateConfigPath: privateConfig,
|
||||
appDataConfigPath: appDataConfig,
|
||||
virtualizedRoots: [env.APPDATA, env.LOCALAPPDATA],
|
||||
processView: "direct",
|
||||
});
|
||||
expect(
|
||||
(await detectClients(home, "win32", env)).map(({ name }) => name),
|
||||
).toContain("claude_desktop");
|
||||
});
|
||||
|
||||
it("uses AppData while the MSIX package has no private copy", async () => {
|
||||
const { home, env, appDataConfig, container, privateConfig } =
|
||||
await windowsProfile();
|
||||
await mkdir(container, { recursive: true });
|
||||
await writeJson(appDataConfig, { preferences: {} });
|
||||
|
||||
const client = claudeDesktop(home, env);
|
||||
|
||||
expect(client.configPath).toBe(appDataConfig);
|
||||
expect(client.msixPackage).toMatchObject({
|
||||
privateConfigPath: privateConfig,
|
||||
processView: "unknown",
|
||||
});
|
||||
// No private file shows whether the running package started this process.
|
||||
const inspection = await inspectClientConfiguration(client, {}, command);
|
||||
expect(inspection.status).toBe("invalid");
|
||||
expect(inspection.status === "invalid" && inspection.remediation).toContain(
|
||||
"Open Claude Desktop once if it has never run, quit it fully, then rerun setup",
|
||||
);
|
||||
});
|
||||
|
||||
it("creates the private copy when the MSIX package has no configuration", async () => {
|
||||
const { home, env, privateConfig } = await windowsProfile();
|
||||
await writeJson(join(dirname(privateConfig), "Local State"), {});
|
||||
|
||||
const client = claudeDesktop(home, env);
|
||||
expect(client.configPath).toBe(privateConfig);
|
||||
expect(client.msixPackage?.processView).toBe("direct");
|
||||
await expect(
|
||||
inspectClientConfiguration(client, {}, command),
|
||||
).resolves.toEqual({ status: "create" });
|
||||
await expect(
|
||||
configureClientConfiguration(client, {}, command),
|
||||
).resolves.toEqual({ status: "configured" });
|
||||
expect(await readJson(privateConfig)).toEqual({
|
||||
mcpServers: { rea: reaEntry },
|
||||
});
|
||||
});
|
||||
|
||||
it("reports an unrecognized Claude package instead of falling back to AppData", async () => {
|
||||
const { home, env, appDataConfig } = await windowsProfile();
|
||||
const foreign = join(env.LOCALAPPDATA, "Packages", "Claude_abcdefghjkmnp");
|
||||
await mkdir(foreign, { recursive: true });
|
||||
await writeJson(appDataConfig, { mcpServers: {} });
|
||||
|
||||
const client = claudeDesktop(home, env);
|
||||
|
||||
expect(client.configPath).toBe(foreign);
|
||||
expect(client.configPathError).toContain("unrecognized publisher");
|
||||
expect(client.configPathError).toContain(CLAUDE_DESKTOP_PACKAGE_FAMILY);
|
||||
expect(
|
||||
(await detectClients(home, "win32", env)).map(({ name }) => name),
|
||||
).not.toContain("claude_desktop");
|
||||
const status = (
|
||||
await readClientRegistrationStatuses(home, "unused", {
|
||||
platform: "win32",
|
||||
environment: env,
|
||||
})
|
||||
).find(({ client: name }) => name === "claude_desktop");
|
||||
expect(status).toMatchObject({ state: "invalid", config_path: foreign });
|
||||
await expect(
|
||||
inspectClientConfiguration(client, {}, command),
|
||||
).resolves.toMatchObject({ status: "invalid" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("MSIX Claude Desktop registration lifecycle", () => {
|
||||
it("registers in the private copy and reports an AppData-only entry as missing", async () => {
|
||||
const { home, env, appDataConfig, privateConfig } = await windowsProfile();
|
||||
const privateOriginal = {
|
||||
coworkUserFilesPath: "C:\\Users\\a\\Claude",
|
||||
preferences: { menuBarEnabled: false },
|
||||
mcpServers: { other: { command: "other", args: ["serve"] } },
|
||||
};
|
||||
await writeJson(privateConfig, privateOriginal);
|
||||
// Earlier setups wrote AppData, which the package never reads.
|
||||
await writeJson(appDataConfig, { mcpServers: { rea: reaEntry } });
|
||||
const appDataOriginal = await readFile(appDataConfig, "utf8");
|
||||
const status = async () =>
|
||||
(
|
||||
await readClientRegistrationStatuses(home, "unused", {
|
||||
platform: "win32",
|
||||
environment: env,
|
||||
})
|
||||
).find(({ client }) => client === "claude_desktop");
|
||||
|
||||
expect(await status()).toMatchObject({
|
||||
state: "missing",
|
||||
config_path: privateConfig,
|
||||
});
|
||||
expect((await status())?.remediation).toContain(
|
||||
"Quit Claude Desktop fully",
|
||||
);
|
||||
|
||||
const client = claudeDesktop(home, env);
|
||||
await expect(
|
||||
inspectClientConfiguration(client, {}, command),
|
||||
).resolves.toEqual({
|
||||
status: "update",
|
||||
backupPath: `${privateConfig}.rea.backup`,
|
||||
});
|
||||
await expect(
|
||||
configureClientConfiguration(client, {}, command),
|
||||
).resolves.toEqual({
|
||||
status: "configured",
|
||||
backupPath: `${privateConfig}.rea.backup`,
|
||||
});
|
||||
|
||||
expect(await readJson(privateConfig)).toEqual({
|
||||
...privateOriginal,
|
||||
mcpServers: {
|
||||
...privateOriginal.mcpServers,
|
||||
rea: reaEntry,
|
||||
},
|
||||
});
|
||||
expect(await readJson(`${privateConfig}.rea.backup`)).toEqual(
|
||||
privateOriginal,
|
||||
);
|
||||
expect(await readFile(appDataConfig, "utf8")).toBe(appDataOriginal);
|
||||
expect(await status()).toMatchObject({
|
||||
state: "aligned",
|
||||
config_path: privateConfig,
|
||||
});
|
||||
await expect(
|
||||
configureClientConfiguration(client, {}, command),
|
||||
).resolves.toEqual({ status: "unchanged" });
|
||||
});
|
||||
|
||||
it("refuses to write from a process the running package started", async () => {
|
||||
const { home, env, privateConfig } = await windowsProfile();
|
||||
await writeJson(privateConfig, { preferences: {} });
|
||||
const resolved = claudeDesktop(home, env);
|
||||
if (resolved.msixPackage === undefined)
|
||||
throw new Error("expected MSIX package storage");
|
||||
// Only a packaged process sees AppData redirected; model that observation.
|
||||
const client: SetupClient = {
|
||||
...resolved,
|
||||
msixPackage: { ...resolved.msixPackage, processView: "redirected" },
|
||||
};
|
||||
|
||||
const inspection = await inspectClientConfiguration(client, {}, command);
|
||||
|
||||
expect(inspection.status).toBe("invalid");
|
||||
expect(inspection.status === "invalid" && inspection.remediation).toContain(
|
||||
"Quit Claude Desktop fully, then rerun setup from a terminal that Claude Desktop did not start",
|
||||
);
|
||||
expect(await readJson(privateConfig)).toEqual({ preferences: {} });
|
||||
|
||||
await configureClientConfiguration(resolved, {}, command);
|
||||
await expect(
|
||||
inspectClientConfiguration(client, {}, command),
|
||||
).resolves.toEqual({ status: "already_current" });
|
||||
});
|
||||
|
||||
it("refuses a write once the package reads a newer private copy", async () => {
|
||||
const { home, env, appDataConfig, privateConfig } = await windowsProfile();
|
||||
await writeJson(join(dirname(privateConfig), "Preferences"), {});
|
||||
await writeJson(appDataConfig, { preferences: {} });
|
||||
const client = claudeDesktop(home, env);
|
||||
expect(client.configPath).toBe(appDataConfig);
|
||||
// Quitting the app after the plan was shown can save its private copy.
|
||||
await writeJson(privateConfig, { preferences: {} });
|
||||
|
||||
await expect(
|
||||
configureClientConfiguration(client, {}, command),
|
||||
).resolves.toEqual({ status: "failed", reason: "target_changed" });
|
||||
expect(await readJson(appDataConfig)).toEqual({ preferences: {} });
|
||||
expect(await readJson(privateConfig)).toEqual({ preferences: {} });
|
||||
});
|
||||
|
||||
it("registers in AppData while the package has no private copy", async () => {
|
||||
const { home, env, appDataConfig, privateConfig } = await windowsProfile();
|
||||
await writeJson(join(dirname(privateConfig), "Preferences"), {});
|
||||
await writeJson(appDataConfig, { preferences: { theme: "light" } });
|
||||
|
||||
const client = claudeDesktop(home, env);
|
||||
expect(client.configPath).toBe(appDataConfig);
|
||||
expect(client.msixPackage?.processView).toBe("direct");
|
||||
await expect(
|
||||
configureClientConfiguration(client, {}, command),
|
||||
).resolves.toMatchObject({ status: "configured" });
|
||||
|
||||
expect(await readJson(appDataConfig)).toEqual({
|
||||
preferences: { theme: "light" },
|
||||
mcpServers: { rea: reaEntry },
|
||||
});
|
||||
await expect(access(privateConfig)).rejects.toMatchObject({
|
||||
code: "ENOENT",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("MSIX Claude Desktop uninstall", () => {
|
||||
it("refuses uninstall when the package view is unknown", async () => {
|
||||
const { home, env, appDataConfig, container } = await windowsProfile();
|
||||
await mkdir(container, { recursive: true });
|
||||
await writeJson(appDataConfig, { mcpServers: { rea: reaEntry } });
|
||||
|
||||
const result = await runUninstall(
|
||||
false,
|
||||
systemUninstallHost(home, undefined, env, "win32"),
|
||||
);
|
||||
|
||||
expect(result.status).toBe("failed");
|
||||
expect(result.items).toContainEqual(
|
||||
expect.objectContaining({
|
||||
name: "claude_desktop",
|
||||
status: "failed",
|
||||
detail: expect.stringContaining("rerun uninstall"),
|
||||
}),
|
||||
);
|
||||
expect(await readJson(appDataConfig)).toEqual({
|
||||
mcpServers: { rea: reaEntry },
|
||||
});
|
||||
});
|
||||
|
||||
it("retains an unrelated rea-named entry when the package view is unknown", async () => {
|
||||
const { home, env, appDataConfig, container } = await windowsProfile();
|
||||
await mkdir(container, { recursive: true });
|
||||
const unrelated = { mcpServers: { rea: { command: "unrelated-server" } } };
|
||||
await writeJson(appDataConfig, unrelated);
|
||||
const result = await runUninstall(
|
||||
false,
|
||||
systemUninstallHost(home, undefined, env, "win32"),
|
||||
);
|
||||
expect(result.status).toBe("complete");
|
||||
expect(await readJson(appDataConfig)).toEqual(unrelated);
|
||||
});
|
||||
|
||||
it("blocks managed skill removal through redirected AppData before any removal", async () => {
|
||||
const { home, env, appDataConfig, privateConfig } = await windowsProfile();
|
||||
await writeJson(join(dirname(privateConfig), "Preferences"), {});
|
||||
await mkdir(dirname(dirname(appDataConfig)), { recursive: true });
|
||||
await symlink(dirname(privateConfig), dirname(appDataConfig), "dir");
|
||||
const agents = join(env.APPDATA, "dsh", "agents");
|
||||
const manifest = join(
|
||||
agents,
|
||||
"skills",
|
||||
"reverse-engineer-anything",
|
||||
"SKILL.md",
|
||||
);
|
||||
await mkdir(dirname(manifest), { recursive: true });
|
||||
await writeFile(
|
||||
manifest,
|
||||
"---\nname: reverse-engineer-anything\n---\nmanaged fixture\n",
|
||||
);
|
||||
const environment = { ...env, DSH_AGENTS_HOME: agents };
|
||||
const result = await runUninstall(
|
||||
false,
|
||||
systemUninstallHost(home, undefined, environment, "win32"),
|
||||
);
|
||||
expect(result.status).toBe("failed");
|
||||
expect(result.items).toContainEqual(
|
||||
expect.objectContaining({
|
||||
name: "skill",
|
||||
status: "failed",
|
||||
detail: expect.stringContaining("redirects its writes"),
|
||||
}),
|
||||
);
|
||||
expect(await readFile(manifest, "utf8")).toContain("managed fixture");
|
||||
});
|
||||
|
||||
it("removes REA from both the private copy and AppData on uninstall", async () => {
|
||||
const { home, env, appDataConfig, privateConfig } = await windowsProfile();
|
||||
await writeJson(privateConfig, {
|
||||
preferences: {},
|
||||
mcpServers: { other: { command: "other" }, rea: reaEntry },
|
||||
});
|
||||
await writeJson(appDataConfig, { mcpServers: { rea: reaEntry } });
|
||||
|
||||
const result = await runUninstall(
|
||||
false,
|
||||
systemUninstallHost(home, undefined, env, "win32"),
|
||||
);
|
||||
|
||||
expect(result.status).toBe("complete");
|
||||
expect(await readJson(privateConfig)).toEqual({
|
||||
preferences: {},
|
||||
mcpServers: { other: { command: "other" } },
|
||||
});
|
||||
expect(await readJson(appDataConfig)).toEqual({ mcpServers: {} });
|
||||
});
|
||||
});
|
||||
@@ -71,6 +71,7 @@ describe("client configuration filesystem lifecycle", () => {
|
||||
"pi",
|
||||
"hermes",
|
||||
"qoder",
|
||||
"droid",
|
||||
"zcode",
|
||||
"dsh",
|
||||
"grok_bot",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { parseConfig } from "../../../src/config/parseConfig.js";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { symlink, writeFile } from "node:fs/promises";
|
||||
import { basename, dirname, join } from "node:path";
|
||||
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
@@ -14,7 +14,7 @@ import type {
|
||||
import type { DirectAnalysisDependencies } from "../../../src/application/DirectAnalysisDependencies.js";
|
||||
import { createAnalysisProfile } from "../../../src/domain/analysisProfile.js";
|
||||
import { createAnalysisExecution } from "../../../src/application/AnalysisProvider.js";
|
||||
import { ok } from "../../../src/domain/result.js";
|
||||
import { err, ok } from "../../../src/domain/result.js";
|
||||
import {
|
||||
readAnalysisSnapshot,
|
||||
writeAnalysisSnapshot,
|
||||
@@ -40,6 +40,7 @@ import {
|
||||
} from "../../fixtures/binarySession.js";
|
||||
import { BinarySession } from "../../../src/application/binary/BinarySession.js";
|
||||
import { OwnedStagedOutput } from "../../../src/filesystem/OwnedStagedOutput.js";
|
||||
import { ProviderAdapterError } from "../../../src/domain/providerAdapterError.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import {
|
||||
CAPABILITIES as GHIDRA_CAPABILITIES,
|
||||
@@ -396,7 +397,85 @@ describe("snapshot output cleanup lifecycle", () => {
|
||||
});
|
||||
});
|
||||
|
||||
const verifyWindowsSnapshotAdmission = async (
|
||||
selectedPath: "direct" | "junction",
|
||||
): Promise<void> => {
|
||||
const fixture = await createSnapshotReplayFixture(
|
||||
"rea-direct-snapshot-junction-",
|
||||
);
|
||||
const rawPath = join(dirname(fixture.path), "image.bin");
|
||||
await writeFile(rawPath, Buffer.from("a92a60", "hex"));
|
||||
const linked = join(dirname(fixture.path), "linked");
|
||||
const linkedPath = join(linked, basename(rawPath));
|
||||
const identity = { ...GHIDRA_PROVIDER_IDENTITY, version: "12.1.4" };
|
||||
const profile = createAnalysisProfile(identity, {
|
||||
fixture: true,
|
||||
});
|
||||
const baseProvider = fixture.createProvider({
|
||||
identity,
|
||||
profile,
|
||||
supportedOperations: ["search_strings"],
|
||||
});
|
||||
let rejectAdmission = false;
|
||||
const provider: AnalysisProvider = {
|
||||
...baseProvider,
|
||||
createClient: (target, profile, context) => {
|
||||
const client = baseProvider.createClient(target, profile, context);
|
||||
return {
|
||||
...client,
|
||||
execute: (operation, parameters, options) =>
|
||||
rejectAdmission && operation === "search_strings"
|
||||
? Promise.resolve(
|
||||
err(new ProviderAdapterError("ghidra", operation)),
|
||||
)
|
||||
: client.execute(operation, parameters, options),
|
||||
};
|
||||
},
|
||||
};
|
||||
const dependencies = fixture.dependencies(provider);
|
||||
const arguments_ = { pattern: "fixture", document: "fixture" };
|
||||
const options = {
|
||||
snapshotPath: fixture.snapshotPath,
|
||||
formatHint: "raw-binary" as const,
|
||||
architecture: "6502" as const,
|
||||
entryPoint: "0x8001",
|
||||
};
|
||||
const first = await runDirectAnalysis(
|
||||
dependencies,
|
||||
rawPath,
|
||||
"search_strings",
|
||||
arguments_,
|
||||
options,
|
||||
);
|
||||
expect(first).toMatchObject({ operation: "search_strings" });
|
||||
expect(fixture.starts).toHaveLength(1);
|
||||
if (selectedPath === "junction")
|
||||
await symlink(dirname(fixture.path), linked, "junction");
|
||||
rejectAdmission = true;
|
||||
const second = await runDirectAnalysis(
|
||||
dependencies,
|
||||
selectedPath === "junction" ? linkedPath : rawPath,
|
||||
"search_strings",
|
||||
arguments_,
|
||||
options,
|
||||
);
|
||||
expect(second).toMatchObject({ error: "Analysis failed" });
|
||||
expect(fixture.starts).toHaveLength(2);
|
||||
expect(
|
||||
fixture.calls.filter((call) => call === "search_strings"),
|
||||
).toHaveLength(1);
|
||||
};
|
||||
|
||||
describe("direct analysis composed snapshot replay", () => {
|
||||
it.skipIf(process.platform !== "win32")(
|
||||
"does not replay a CLI snapshot through a Windows junction",
|
||||
() => verifyWindowsSnapshotAdmission("junction"),
|
||||
);
|
||||
it.skipIf(process.platform !== "win32")(
|
||||
"does not replay a CLI snapshot before native admission on a canonical path",
|
||||
() => verifyWindowsSnapshotAdmission("direct"),
|
||||
);
|
||||
|
||||
it.each([
|
||||
{
|
||||
tool: "search_strings",
|
||||
@@ -516,7 +595,7 @@ describe("Ghidra composed workflow snapshot replay", () => {
|
||||
{ tool: "inspect_native_api", arguments: { procedure: "0x1000" } },
|
||||
{ tool: "trace_feature", arguments: { query: "fixture" } },
|
||||
] as const)(
|
||||
"persists and replays $tool with production Ghidra capability policies",
|
||||
"persists $tool with production Ghidra capability policies",
|
||||
async ({ tool, arguments: parameters }) => {
|
||||
const fixture = await createSnapshotReplayFixture("rea-ghidra-workflow-");
|
||||
const profile = createAnalysisProfile(
|
||||
@@ -554,8 +633,14 @@ describe("Ghidra composed workflow snapshot replay", () => {
|
||||
{ snapshotPath: fixture.snapshotPath },
|
||||
);
|
||||
expect(replay).toEqual(first);
|
||||
expect(fixture.starts).toHaveLength(1);
|
||||
expect(fixture.calls).toEqual(initialCalls);
|
||||
if (process.platform === "win32") {
|
||||
// The first provider call in a new CLI session admits its source.
|
||||
expect(fixture.starts).toHaveLength(2);
|
||||
expect(fixture.calls.length).toBeGreaterThan(initialCalls.length);
|
||||
} else {
|
||||
expect(fixture.starts).toHaveLength(1);
|
||||
expect(fixture.calls).toEqual(initialCalls);
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { readClientRegistrationStatuses } from "../../../src/application/ClientRegistrationStatus.js";
|
||||
import { npxRegistrationCommand } from "../../../src/application/ClientRegistrationIdentity.js";
|
||||
import { configureClientConfiguration } from "../../../src/application/SetupClientConfiguration.js";
|
||||
import { skillDestinations } from "../../../src/application/SetupSkill.js";
|
||||
import { supportedClients } from "../../../src/application/SupportedClients.js";
|
||||
import { systemUninstallHost } from "../../../src/application/Uninstall.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { clearClientLocationEnvironment } from "../../fixtures/clientEnvironment.js";
|
||||
|
||||
/**
|
||||
* The registration command setup writes on the host running the tests. Windows
|
||||
* wraps it in `cmd.exe /d /c`, so the expected entry follows the host too.
|
||||
*/
|
||||
const command = npxRegistrationCommand(process.platform);
|
||||
|
||||
beforeEach(clearClientLocationEnvironment);
|
||||
afterEach(() => vi.unstubAllEnvs());
|
||||
|
||||
const droidPath = (
|
||||
home: string,
|
||||
platform: NodeJS.Platform = "linux",
|
||||
env: Parameters<typeof supportedClients>[2] = {},
|
||||
) => supportedClients(home, platform, env).find(({ name }) => name === "droid");
|
||||
|
||||
describe("Factory Droid configuration paths", () => {
|
||||
it("resolves the user MCP config file and marker directory", () => {
|
||||
expect(droidPath("/home/a")).toEqual({
|
||||
name: "droid",
|
||||
displayName: "Factory Droid",
|
||||
configPath: join("/home/a", ".factory", "mcp.json"),
|
||||
markerPath: join("/home/a", ".factory"),
|
||||
format: "json",
|
||||
});
|
||||
expect(droidPath("/Users/a", "darwin")?.configPath).toBe(
|
||||
join("/Users/a", ".factory", "mcp.json"),
|
||||
);
|
||||
expect(droidPath("C:\\Users\\a", "win32")?.configPath).toBe(
|
||||
join("C:\\Users\\a", ".factory", "mcp.json"),
|
||||
);
|
||||
});
|
||||
|
||||
it("resolves the personal skills directory beside the config root", () => {
|
||||
expect(
|
||||
skillDestinations("/home/a", ["droid"]).map(({ path }) => path),
|
||||
).toEqual([
|
||||
join("/home/a", ".factory", "skills", "reverse-engineer-anything"),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Factory Droid JSON registration", () => {
|
||||
const droidClient = async () => {
|
||||
const home = await createTestTempDirectory("rea-droid-");
|
||||
const client = droidPath(home, process.platform);
|
||||
if (client?.markerPath === undefined)
|
||||
throw new Error("missing Factory Droid client");
|
||||
await mkdir(client.markerPath, { recursive: true });
|
||||
return { home, client };
|
||||
};
|
||||
|
||||
it("upserts rea into mcpServers while preserving unrelated servers and permissions", async () => {
|
||||
const { home, client } = await droidClient();
|
||||
await writeFile(
|
||||
client.configPath,
|
||||
`{
|
||||
"mcpServers": {
|
||||
"other": {
|
||||
"type": "stdio",
|
||||
"command": "other",
|
||||
"args": [],
|
||||
"disabled": false
|
||||
}
|
||||
},
|
||||
"persistentPermissions": {
|
||||
"servers": {
|
||||
"other": { "approvedAt": "2026-01-01T00:00:00.000Z" }
|
||||
}
|
||||
}
|
||||
}`,
|
||||
);
|
||||
|
||||
expect(
|
||||
(await configureClientConfiguration(client, {}, command)).status,
|
||||
).toBe("configured");
|
||||
const parsed = JSON.parse(await readFile(client.configPath, "utf8"));
|
||||
expect(parsed.mcpServers.other).toEqual({
|
||||
type: "stdio",
|
||||
command: "other",
|
||||
args: [],
|
||||
disabled: false,
|
||||
});
|
||||
expect(parsed.persistentPermissions).toEqual({
|
||||
servers: { other: { approvedAt: "2026-01-01T00:00:00.000Z" } },
|
||||
});
|
||||
expect(parsed.mcpServers.rea).toEqual({
|
||||
command: command[0],
|
||||
args: command.slice(1),
|
||||
});
|
||||
|
||||
expect(await configureClientConfiguration(client, {}, command)).toEqual({
|
||||
status: "unchanged",
|
||||
});
|
||||
expect(
|
||||
(
|
||||
await readClientRegistrationStatuses(home, undefined, {
|
||||
platform: process.platform,
|
||||
environment: {},
|
||||
})
|
||||
).find(({ client }) => client === "droid"),
|
||||
).toMatchObject({ state: "aligned", command });
|
||||
});
|
||||
|
||||
it("creates the mcpServers table in an existing config file without servers", async () => {
|
||||
const { client } = await droidClient();
|
||||
await writeFile(
|
||||
client.configPath,
|
||||
JSON.stringify({ persistentPermissions: { servers: {} } }, null, 2),
|
||||
);
|
||||
expect(
|
||||
(await configureClientConfiguration(client, {}, command)).status,
|
||||
).toBe("configured");
|
||||
const parsed = JSON.parse(await readFile(client.configPath, "utf8"));
|
||||
expect(parsed.persistentPermissions).toEqual({ servers: {} });
|
||||
expect(parsed.mcpServers.rea).toEqual({
|
||||
command: command[0],
|
||||
args: command.slice(1),
|
||||
});
|
||||
});
|
||||
|
||||
it("registers into an empty config file", async () => {
|
||||
const { client } = await droidClient();
|
||||
await writeFile(client.configPath, "");
|
||||
expect(
|
||||
(await configureClientConfiguration(client, {}, command)).status,
|
||||
).toBe("configured");
|
||||
const parsed = JSON.parse(await readFile(client.configPath, "utf8"));
|
||||
expect(parsed.mcpServers.rea).toEqual({
|
||||
command: command[0],
|
||||
args: command.slice(1),
|
||||
});
|
||||
});
|
||||
|
||||
it("removes only the rea entry on uninstall", async () => {
|
||||
const { home, client } = await droidClient();
|
||||
await writeFile(
|
||||
client.configPath,
|
||||
JSON.stringify(
|
||||
{ mcpServers: { other: { command: "other-server" } } },
|
||||
null,
|
||||
2,
|
||||
),
|
||||
);
|
||||
await configureClientConfiguration(client, {}, command);
|
||||
|
||||
expect((await systemUninstallHost(home).removeClient(client)).status).toBe(
|
||||
"removed",
|
||||
);
|
||||
const parsed = JSON.parse(await readFile(client.configPath, "utf8"));
|
||||
expect(parsed.mcpServers.other).toEqual({ command: "other-server" });
|
||||
expect(parsed.mcpServers.rea).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { join, resolve } from "node:path";
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
@@ -37,28 +37,76 @@ const dshClient = (
|
||||
env: Parameters<typeof supportedClients>[2],
|
||||
platform: NodeJS.Platform = "linux",
|
||||
) =>
|
||||
supportedClients(join("/home/a"), platform, env).find(
|
||||
supportedClients(resolve("/home/a"), platform, env).find(
|
||||
({ name }) => name === "dsh",
|
||||
);
|
||||
|
||||
describe("DeepSeek Harness configuration paths", () => {
|
||||
it.each([
|
||||
[undefined, ".dsh", ".agents", "shared"],
|
||||
["", ".dsh", ".agents", "shared"],
|
||||
[" \t ", ".dsh", ".agents", "shared"],
|
||||
["~", "", "", "dsh"],
|
||||
["~/selected home", "selected home", "selected home", "dsh"],
|
||||
["~\\selected home", "selected home", "selected home", "dsh"],
|
||||
] as const)(
|
||||
"resolves Harness and agents roots for %j",
|
||||
(override, dshRoot, agentsRoot, client) => {
|
||||
const home = resolve("/home/a");
|
||||
const environment = { DSH_HOME: override, DSH_AGENTS_HOME: override };
|
||||
expect(
|
||||
supportedClients(home, process.platform, environment).find(
|
||||
({ name }) => name === "dsh",
|
||||
),
|
||||
).toMatchObject({
|
||||
configPath: join(home, dshRoot, "cordis.patch.yml"),
|
||||
markerPath: join(home, dshRoot),
|
||||
});
|
||||
expect(clientSkillDirectories(home, ["dsh"], environment)).toEqual([
|
||||
{ client, directory: join(home, agentsRoot, "skills") },
|
||||
]);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["relative home", " literal home ", "~someone"])(
|
||||
"resolves a literal root %j relative to cwd without trimming it",
|
||||
(override) => {
|
||||
const home = resolve("/home/a");
|
||||
const root = resolve(override);
|
||||
const environment = { DSH_HOME: override, DSH_AGENTS_HOME: override };
|
||||
expect(
|
||||
supportedClients(home, process.platform, environment).find(
|
||||
({ name }) => name === "dsh",
|
||||
),
|
||||
).toMatchObject({
|
||||
configPath: join(root, "cordis.patch.yml"),
|
||||
markerPath: root,
|
||||
});
|
||||
expect(clientSkillDirectories(home, ["dsh"], environment)).toEqual([
|
||||
{ client: "dsh", directory: join(root, "skills") },
|
||||
]);
|
||||
},
|
||||
);
|
||||
|
||||
it("resolves the home Cordis patch under the Harness home", () => {
|
||||
expect(dshClient({})).toEqual({
|
||||
name: "dsh",
|
||||
displayName: "DeepSeek Harness",
|
||||
configPath: join("/home/a", ".dsh", "cordis.patch.yml"),
|
||||
markerPath: join("/home/a", ".dsh"),
|
||||
configPath: resolve("/home/a", ".dsh", "cordis.patch.yml"),
|
||||
markerPath: resolve("/home/a", ".dsh"),
|
||||
format: "dsh",
|
||||
});
|
||||
// The home patch applies to every profile; DSH_HOME relocates it.
|
||||
expect(dshClient({ DSH_HOME: "/custom/harness" })?.configPath).toBe(
|
||||
join("/custom/harness", "cordis.patch.yml"),
|
||||
resolve("/custom/harness", "cordis.patch.yml"),
|
||||
);
|
||||
expect(
|
||||
clientSkillDirectories(join("/home/a"), ["dsh"], {
|
||||
DSH_AGENTS_HOME: "/custom/agents",
|
||||
}),
|
||||
).toEqual([{ client: "dsh", directory: join("/custom/agents", "skills") }]);
|
||||
).toEqual([
|
||||
{ client: "dsh", directory: resolve("/custom/agents", "skills") },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createReadStream } from "node:fs";
|
||||
import { open, readFile, rm, stat, utimes, writeFile } from "node:fs/promises";
|
||||
import { createServer } from "node:net";
|
||||
import { join } from "node:path";
|
||||
import { Readable } from "node:stream";
|
||||
import { Uint8ArrayReader, Uint8ArrayWriter, ZipWriter } from "@zip.js/zip.js";
|
||||
@@ -1122,11 +1123,16 @@ it.each(["identify_flutter_build", "inspect_dart_aot"] as const)(
|
||||
if (result.ok) throw new Error("Duplicate libraries must be refused");
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
issues: [
|
||||
{
|
||||
message: expect.stringContaining(
|
||||
`duplicate Flutter library members: ${path}:`,
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
expect(JSON.stringify(projectAnalysisError(result.error))).toContain(
|
||||
"duplicate Flutter library members",
|
||||
);
|
||||
expect(JSON.stringify(projectAnalysisError(result.error))).toContain(path);
|
||||
expect(extract).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
@@ -1171,6 +1177,69 @@ it.each(["identify_flutter_build", "inspect_dart_aot"] as const)(
|
||||
},
|
||||
);
|
||||
|
||||
const expectSelectionIssue = async (
|
||||
provider: FlutterBuildProvider,
|
||||
path: string,
|
||||
message: string,
|
||||
): Promise<void> => {
|
||||
for (const operation of [
|
||||
"identify_flutter_build",
|
||||
"inspect_dart_aot",
|
||||
] as const) {
|
||||
const result = await provider.execute({ operation, input: { path } });
|
||||
if (result.ok) throw new Error("A non-file APK selection must fail");
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
issues: [
|
||||
{
|
||||
path: ["path"],
|
||||
reason: "invalid_format",
|
||||
message: `${message}: ${path}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
it("names a missing or non-file APK selection instead of blaming package bytes", async () => {
|
||||
const root = await createTestTempDirectory("rea-flutter-selection-");
|
||||
const provider = new FlutterBuildProvider();
|
||||
onTestFinished(() => provider.close());
|
||||
await expectSelectionIssue(
|
||||
provider,
|
||||
join(root, "absent.apk"),
|
||||
"Selected APK does not exist",
|
||||
);
|
||||
await expectSelectionIssue(
|
||||
provider,
|
||||
root,
|
||||
"Selected APK is not a regular file",
|
||||
);
|
||||
});
|
||||
|
||||
// Windows listens on named pipes rather than filesystem sockets.
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"names an unopenable Unix socket APK selection as a non-file",
|
||||
async () => {
|
||||
const root = await createTestTempDirectory("rea-flutter-socket-");
|
||||
const socketPath = join(root, "s.sock");
|
||||
const socket = createServer();
|
||||
await new Promise<void>((resolve) => socket.listen(socketPath, resolve));
|
||||
onTestFinished(
|
||||
() => new Promise<void>((resolve) => socket.close(() => resolve())),
|
||||
);
|
||||
const provider = new FlutterBuildProvider();
|
||||
onTestFinished(() => provider.close());
|
||||
await expectSelectionIssue(
|
||||
provider,
|
||||
socketPath,
|
||||
"Selected APK is not a regular file",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["EACCES", "EPERM"] as const)(
|
||||
"preserves %s at the shared source admission boundary",
|
||||
async (code) => {
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import { open, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { expect, it, vi } from "vitest";
|
||||
import { readElfBuildIds } from "../../../src/flutter/ElfBuildId.js";
|
||||
import {
|
||||
appendElfRanges,
|
||||
engineFixtureImage,
|
||||
} from "../../../src/flutter/FlutterBuild.fixture.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const note = Buffer.from(
|
||||
"040000000800000003000000474e55000123456789abcdef",
|
||||
"hex",
|
||||
);
|
||||
|
||||
it.each([
|
||||
{ bits: 32, table: "program" },
|
||||
{ bits: 64, table: "section" },
|
||||
] as const)(
|
||||
"bounds dense $bits-bit $table note ranges while retaining examined IDs",
|
||||
async ({ bits, table }) => {
|
||||
const count = 30_000;
|
||||
const image = appendElfRanges(
|
||||
engineFixtureImage({
|
||||
bits,
|
||||
notes: Buffer.concat([note, Buffer.alloc(count)]),
|
||||
ownership: "both",
|
||||
}),
|
||||
table,
|
||||
Array.from({ length: count }, (_, index) => ({
|
||||
type: table === "program" ? 4 : 7,
|
||||
offset: 0x400 + note.length + index,
|
||||
size: 1,
|
||||
})),
|
||||
);
|
||||
const root = await createTestTempDirectory("rea-flutter-notes-");
|
||||
const path = join(root, "engine.so");
|
||||
await writeFile(path, image);
|
||||
const file = await open(path, "r");
|
||||
const read = vi.spyOn(file, "read");
|
||||
try {
|
||||
const result = await readElfBuildIds(file, image.length, undefined);
|
||||
expect(result.candidates).toEqual(["0123456789abcdef"]);
|
||||
expect(result.failures).toContainEqual({
|
||||
reason: expect.stringContaining("note-range"),
|
||||
});
|
||||
expect(read.mock.calls.length).toBeLessThanOrEqual(1027);
|
||||
} finally {
|
||||
await file.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("deduplicates shared program/section notes and skips empty ranges before charging inventory", async () => {
|
||||
const ranges = Array.from({ length: 2000 }, (_, index) => ({
|
||||
type: 7,
|
||||
offset: index % 2 === 0 ? 0x400 : index,
|
||||
size: index % 2 === 0 ? note.length : 0,
|
||||
}));
|
||||
const image = appendElfRanges(
|
||||
engineFixtureImage({ notes: note, ownership: "both" }),
|
||||
"section",
|
||||
ranges,
|
||||
);
|
||||
const root = await createTestTempDirectory("rea-flutter-notes-");
|
||||
const path = join(root, "engine.so");
|
||||
await writeFile(path, image);
|
||||
const file = await open(path, "r");
|
||||
const read = vi.spyOn(file, "read");
|
||||
try {
|
||||
expect(await readElfBuildIds(file, image.length, undefined)).toEqual({
|
||||
candidates: ["0123456789abcdef"],
|
||||
failures: [],
|
||||
});
|
||||
expect(read.mock.calls.length).toBe(4);
|
||||
} finally {
|
||||
await file.close();
|
||||
}
|
||||
});
|
||||
@@ -87,3 +87,43 @@ it.each([
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("bounds the Java version probe and reports an over-budget probe as a failed Java check", async () => {
|
||||
const root = await createTestTempDirectory("rea-java-probe-bound-");
|
||||
const configuredHome = join(root, "selected-jdk");
|
||||
const installDir = join(root, "ghidra");
|
||||
await mkdir(join(installDir, "Ghidra"), { recursive: true });
|
||||
await writeFile(
|
||||
join(installDir, "Ghidra", "application.properties"),
|
||||
`application.version=${SUPPORTED_GHIDRA_VERSION}\napplication.java.min=17\n`,
|
||||
);
|
||||
// A chatty or hostile JVM that overruns the capture budget: spawnSync reports
|
||||
// ENOBUFS, which the probe already treats as a failed observation.
|
||||
mockSpawnSync.mockReturnValue({
|
||||
stdout: "",
|
||||
stderr: "java.version = 21.0.11\n",
|
||||
status: null,
|
||||
error: Object.assign(new Error("spawnSync /java ENOBUFS"), {
|
||||
code: "ENOBUFS",
|
||||
}),
|
||||
});
|
||||
|
||||
const inspection = inspectGhidraInstallation({
|
||||
environment: {},
|
||||
installDir,
|
||||
javaHome: configuredHome,
|
||||
});
|
||||
|
||||
const [, , options] = mockSpawnSync.mock.calls[0] as [
|
||||
string,
|
||||
readonly string[],
|
||||
{ readonly maxBuffer?: number },
|
||||
];
|
||||
expect(options.maxBuffer).toBe(1024 * 1024);
|
||||
expect(inspection.javaVersion).toBeNull();
|
||||
expect(inspection.javaHome).toBe(configuredHome);
|
||||
expect(inspection.checks.find(({ name }) => name === "java")).toMatchObject({
|
||||
status: "failed",
|
||||
code: "runtime_missing",
|
||||
});
|
||||
});
|
||||
|
||||
@@ -237,6 +237,38 @@ mcp_servers:
|
||||
expect(await readFile(client.configPath, "utf8")).toBe(original);
|
||||
});
|
||||
|
||||
it("keeps unrelated numbers as written, including Discord IDs", async () => {
|
||||
const { home, client } = await hermesClient();
|
||||
// Hermes reads these exactly: two IDs one apart, an octal mode, a float.
|
||||
const original = `discord:
|
||||
free_response_channels:
|
||||
- 1187654321098765432
|
||||
channel_prompts:
|
||||
1187654321098765433: Build questions.
|
||||
1187654321098765434: Release questions.
|
||||
mode: 0600
|
||||
min_score: 0.0000001
|
||||
mcp_servers:
|
||||
other:
|
||||
command: other-server
|
||||
`;
|
||||
await writeFile(client.configPath, original);
|
||||
expect(
|
||||
(await configureClientConfiguration(client, {}, command)).status,
|
||||
).toBe("configured");
|
||||
const text = await readFile(client.configPath, "utf8");
|
||||
expect(text.startsWith(original)).toBe(true);
|
||||
expect(parseYaml(text, { intAsBigInt: true })).toMatchObject({
|
||||
mcp_servers: {
|
||||
rea: { command: command[0], args: command.slice(1), enabled: true },
|
||||
},
|
||||
});
|
||||
expect((await systemUninstallHost(home).removeClient(client)).status).toBe(
|
||||
"removed",
|
||||
);
|
||||
expect(await readFile(client.configPath, "utf8")).toBe(original);
|
||||
});
|
||||
|
||||
it("creates config.yaml when Hermes has no configuration yet", async () => {
|
||||
const { client } = await hermesClient();
|
||||
expect(
|
||||
|
||||
@@ -696,6 +696,49 @@ describe("NIB projection byte amplification", () => {
|
||||
});
|
||||
});
|
||||
|
||||
cliTest(
|
||||
"compiled CLI preserves distinct NIB keys and class identity",
|
||||
async ({ cli }) => {
|
||||
const root = await createTestTempDirectory("rea-nib-name-identity-");
|
||||
const bundle = join(root, "Example.app");
|
||||
const resources = join(bundle, "Contents", "Resources");
|
||||
await mkdir(resources, { recursive: true });
|
||||
await mkdir(join(bundle, "Contents", "MacOS"), { recursive: true });
|
||||
await writeFile(
|
||||
join(bundle, "Contents", "MacOS", "App"),
|
||||
thinMach(0xfeedfacf, 0x0100000c),
|
||||
);
|
||||
await writeFile(
|
||||
join(bundle, "Contents", "Info.plist"),
|
||||
"<plist><dict><key>CFBundleExecutable</key><string>App</string></dict></plist>",
|
||||
);
|
||||
await writeFile(
|
||||
join(resources, "Identity.nib"),
|
||||
encodeNibArchiveFixture({
|
||||
classes: ["\uFEFFWidget"],
|
||||
objects: [{ classIndex: 0, values: { count: 1, "\uFEFFcount": 2 } }],
|
||||
}),
|
||||
);
|
||||
const output = await cli.run({
|
||||
arguments: ["decode-interface-builder", bundle, "--json"],
|
||||
environment: { REA_LOG_LEVEL: "silent", REA_ANALYSIS_PROVIDER: "auto" },
|
||||
});
|
||||
expect(output.exitCode, output.stderr).toBe(0);
|
||||
const result = interfaceBuilderAnalysisSchema.parse(
|
||||
parseEvidence(output.json).normalized_result,
|
||||
);
|
||||
expect(result.graph.nodes).toContainEqual(
|
||||
expect.objectContaining({
|
||||
attributes: expect.objectContaining({
|
||||
class_name: "\uFEFFWidget",
|
||||
nibValues: { count: 1, "\uFEFFcount": 2 },
|
||||
}),
|
||||
}),
|
||||
);
|
||||
expect(JSON.stringify(result)).toContain("\uFEFFWidget");
|
||||
},
|
||||
);
|
||||
|
||||
cliTest(
|
||||
"compiled CLI preserves a good archive and reports repeated key and data omissions",
|
||||
async ({ cli }) => {
|
||||
@@ -1060,6 +1103,142 @@ describe("NIBArchive UIKit event connections", () => {
|
||||
"UIRuntimeEventConnection",
|
||||
);
|
||||
});
|
||||
|
||||
it("reports a runtime connection with no resolvable owner as an omission", async () => {
|
||||
const root = await createTestTempDirectory("rea-ib-ownerless-");
|
||||
const bundle = join(root, "Example.app");
|
||||
await mkdir(bundle, { recursive: true });
|
||||
// The connector is recognized by class, but carries no UISource reference,
|
||||
// so no connection can be projected from it.
|
||||
await writeFile(
|
||||
join(bundle, "Cell.nib"),
|
||||
encodeNibArchiveFixture({
|
||||
classes: [
|
||||
"UIProxyObject",
|
||||
"UIClassSwapper",
|
||||
"UIButton",
|
||||
"UIRuntimeEventConnection",
|
||||
"NSString",
|
||||
],
|
||||
objects: [
|
||||
{ classIndex: 0, values: { UIProxiedObjectIdentifier: { ref: 5 } } },
|
||||
{ classIndex: 1, values: { UIClassName: { ref: 6 } } },
|
||||
{ classIndex: 2, values: {} },
|
||||
{
|
||||
classIndex: 3,
|
||||
values: { UIDestination: { ref: 1 }, UIEventMask: 64 },
|
||||
},
|
||||
{ classIndex: 2, values: {} },
|
||||
{ classIndex: 4, values: { "NS.bytes": "IBFilesOwner" } },
|
||||
{ classIndex: 4, values: { "NS.bytes": "BuildCell" } },
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
const analysis = await analyzeInterfaceBuilderBundle({
|
||||
bundlePath: bundle,
|
||||
targetSha256: "e".repeat(64),
|
||||
});
|
||||
|
||||
expect(analysis.graph.coverage).toContainEqual(
|
||||
expect.objectContaining({
|
||||
facet: "connections:Cell.nib",
|
||||
status: "partial",
|
||||
reason: "connection_unresolved",
|
||||
examined: 0,
|
||||
omitted: 1,
|
||||
}),
|
||||
);
|
||||
// The keyed-archive producer counts a recognized connector it cannot emit,
|
||||
// so this producer has to report the same document total for the same
|
||||
// connector rather than zero.
|
||||
expect(analysis.documents).toContainEqual(
|
||||
expect.objectContaining({
|
||||
relative_path: "Cell.nib",
|
||||
connection_count: 1,
|
||||
}),
|
||||
);
|
||||
expect(analysis.graph.truncated).toBe(true);
|
||||
expect(analysis.limitations).toContain(
|
||||
"Some recognized NIBArchive connectors declare no resolvable owner; they carry no connection evidence and are reported as omissions.",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("NIBArchive ownerless connector accounting", () => {
|
||||
it("keeps a connection dropped by the limit reported as a limit", async () => {
|
||||
const root = await createTestTempDirectory("rea-ib-ownerless-limit-");
|
||||
const bundle = join(root, "Example.app");
|
||||
await mkdir(bundle, { recursive: true });
|
||||
// Two resolvable connectors and one ownerless connector with the limit
|
||||
// below the resolvable count, so this facet has both causes at once. Only a
|
||||
// higher limit recovers the dropped connection, so that is the reason the
|
||||
// caller needs, exactly as the keyed-archive producer reports it.
|
||||
await writeFile(
|
||||
join(bundle, "Cell.nib"),
|
||||
encodeNibArchiveFixture({
|
||||
classes: [
|
||||
"UIProxyObject",
|
||||
"UIClassSwapper",
|
||||
"UIButton",
|
||||
"UIRuntimeEventConnection",
|
||||
"NSString",
|
||||
],
|
||||
objects: [
|
||||
{ classIndex: 0, values: { UIProxiedObjectIdentifier: { ref: 5 } } },
|
||||
{ classIndex: 1, values: { UIClassName: { ref: 6 } } },
|
||||
{ classIndex: 2, values: {} },
|
||||
{
|
||||
classIndex: 3,
|
||||
values: {
|
||||
UISource: { ref: 2 },
|
||||
UIDestination: { ref: 1 },
|
||||
UILabel: { ref: 7 },
|
||||
UIEventMask: 64,
|
||||
},
|
||||
},
|
||||
{ classIndex: 2, values: {} },
|
||||
{ classIndex: 4, values: { "NS.bytes": "IBFilesOwner" } },
|
||||
{ classIndex: 4, values: { "NS.bytes": "BuildCell" } },
|
||||
{ classIndex: 4, values: { "NS.bytes": "buildTapped:" } },
|
||||
{
|
||||
classIndex: 3,
|
||||
values: {
|
||||
UISource: { ref: 4 },
|
||||
UIDestination: { ref: 1 },
|
||||
UILabel: { ref: 7 },
|
||||
},
|
||||
},
|
||||
{
|
||||
classIndex: 3,
|
||||
values: { UIDestination: { ref: 1 }, UIEventMask: 64 },
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
const analysis = await analyzeInterfaceBuilderBundle({
|
||||
bundlePath: bundle,
|
||||
targetSha256: "e".repeat(64),
|
||||
limits: { max_connections: 1 },
|
||||
});
|
||||
|
||||
expect(analysis.graph.coverage).toContainEqual(
|
||||
expect.objectContaining({
|
||||
facet: "connections:Cell.nib",
|
||||
status: "partial",
|
||||
reason: "connection_limit_reached",
|
||||
examined: 1,
|
||||
omitted: 2,
|
||||
}),
|
||||
);
|
||||
expect(analysis.documents).toContainEqual(
|
||||
expect.objectContaining({
|
||||
relative_path: "Cell.nib",
|
||||
connection_count: 3,
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// This exact file is already selected by the unchanged native Apple CI lane.
|
||||
|
||||
+68
-2
@@ -9,7 +9,10 @@ import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js
|
||||
import { javascriptApplicationAnalysisResultSchema } from "../../../../src/domain/javascript/javascriptApplicationAnalysis.js";
|
||||
import { matchJavaScriptApplicationVersions } from "../../../../src/domain/javascript/javascriptApplicationVersionKeys.js";
|
||||
import { findApplicationFeatureSeeds } from "../../../../src/domain/javascript/javascriptFeatureSeed.js";
|
||||
import { traceApplicationFeatureInputSchema } from "../../../../src/domain/javascript/javascriptFeatureTraceSchemas.js";
|
||||
import {
|
||||
applicationFeatureSeedSchema,
|
||||
traceApplicationFeatureInputSchema,
|
||||
} from "../../../../src/domain/javascript/javascriptFeatureTraceSchemas.js";
|
||||
import { analyzeJavaScriptApplication } from "../../../support/javascriptApplicationScope.js";
|
||||
|
||||
const analyzeSource = async (
|
||||
@@ -76,6 +79,59 @@ it("retains empty literal evidence across the application boundary surfaces", as
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps bridge entry paths stable through worker validation and API seed matching", async () => {
|
||||
const output = await analyzeSource(`
|
||||
const { contextBridge, ipcRenderer } = require("electron");
|
||||
const literal = () => ipcRenderer.send("literal");
|
||||
const nested = () => ipcRenderer.send("nested");
|
||||
contextBridge.exposeInMainWorld("desktop", {
|
||||
"nested.write": literal,
|
||||
nested: { write: nested },
|
||||
});
|
||||
`);
|
||||
const semanticPathIds = new Set(
|
||||
(output.semantic_graph?.nodes ?? [])
|
||||
.map(({ properties }) => properties.path_id)
|
||||
.filter((pathId): pathId is string => typeof pathId === "string"),
|
||||
);
|
||||
const applicationPathIds = new Set(
|
||||
output.graph.nodes.flatMap(({ observations }) =>
|
||||
observations
|
||||
.map(({ properties }) => properties.path_id)
|
||||
.filter((pathId): pathId is string => typeof pathId === "string"),
|
||||
),
|
||||
);
|
||||
expect(semanticPathIds).toEqual(applicationPathIds);
|
||||
|
||||
const matches = findApplicationFeatureSeeds(
|
||||
output.graph.nodes,
|
||||
applicationFeatureSeedSchema.parse({
|
||||
kind: "api",
|
||||
value: "desktop.nested.write",
|
||||
entry_path: ["desktop", "nested.write"],
|
||||
}),
|
||||
);
|
||||
expect(matches).toHaveLength(1);
|
||||
expect(
|
||||
output.graph.nodes
|
||||
.find(({ node_id: nodeId }) => nodeId === matches[0]?.node_id)
|
||||
?.observations.some(
|
||||
({ properties }) =>
|
||||
Array.isArray(properties.entry_path) &&
|
||||
properties.entry_path.join("\0") === "desktop\0nested.write",
|
||||
),
|
||||
).toBe(true);
|
||||
expect(
|
||||
findApplicationFeatureSeeds(
|
||||
output.graph.nodes,
|
||||
applicationFeatureSeedSchema.parse({
|
||||
kind: "api",
|
||||
value: "desktop.nested.write",
|
||||
}),
|
||||
),
|
||||
).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("analyzes a plain long-line loader without package metadata", async () => {
|
||||
const output = await analyzeSource(
|
||||
`var Module = {}; fetch(""); new Worker(""); var payload = "${"x".repeat(65_536)}";`,
|
||||
@@ -240,8 +296,18 @@ it.each([
|
||||
[{ kind: "channel", value: "" }, false],
|
||||
[{ kind: "channel", value: "", match: "contains" }, false],
|
||||
[{ kind: "node-id", value: "", match: "exact" }, false],
|
||||
[{ kind: "api", value: "desktop.nested.write" }, true],
|
||||
[
|
||||
{
|
||||
kind: "api",
|
||||
value: "desktop.nested.write",
|
||||
entry_path: ["desktop", "nested.write"],
|
||||
},
|
||||
true,
|
||||
],
|
||||
[{ kind: "channel", value: "channel", entry_path: ["channel"] }, false],
|
||||
] as const)(
|
||||
"validates empty seed %j at runtime and in the advertised schema",
|
||||
"validates seed %j at runtime and in the advertised schema",
|
||||
(seed, accepted) => {
|
||||
expect(seedSchema.safeParse(seed).success).toBe(accepted);
|
||||
expect(validateAdvertisedSeed(seed)).toBe(accepted);
|
||||
|
||||
+3
-3
@@ -388,7 +388,7 @@ it("produces deterministic ASAR graphs with unpacked native linkage and complete
|
||||
await mkdir(source);
|
||||
await writeJavaScriptArtifactFixture(source);
|
||||
const archive = join(root, "app.asar");
|
||||
await createPackageWithOptions(source, archive, { unpack: "**/*.node" });
|
||||
await createPackageWithOptions(source, archive, { unpack: "*.node" });
|
||||
|
||||
const first = await reconstructJavaScriptArtifact({
|
||||
input_path: archive,
|
||||
@@ -487,7 +487,7 @@ it("keeps ASAR analysis usable when unpacked native companion bytes are absent",
|
||||
await mkdir(source);
|
||||
await writeJavaScriptArtifactFixture(source);
|
||||
const archive = join(root, "app.asar");
|
||||
await createPackageWithOptions(source, archive, { unpack: "**/*.node" });
|
||||
await createPackageWithOptions(source, archive, { unpack: "*.node" });
|
||||
await rm(join(`${archive}.unpacked`, "native", "addon.node"));
|
||||
|
||||
const snapshot = await scanArtifactInventory(archive);
|
||||
@@ -515,7 +515,7 @@ it("recurses into filesystem-backed ASAR containers without losing container-rel
|
||||
const resources = join(outer, "resources");
|
||||
await mkdir(resources, { recursive: true });
|
||||
await createPackageWithOptions(source, join(resources, "app.asar"), {
|
||||
unpack: "**/*.node",
|
||||
unpack: "*.node",
|
||||
});
|
||||
|
||||
const result = await reconstructJavaScriptArtifact({
|
||||
|
||||
@@ -444,73 +444,97 @@ describe("JavaScript application workflow error diagnostics", () => {
|
||||
});
|
||||
});
|
||||
|
||||
const RUNTIME_PATH_CASES = [
|
||||
{
|
||||
name: "case-sensitive POSIX input root",
|
||||
root: null,
|
||||
path: "/applications/Example.app/Contents/Resources/app/renderer.js",
|
||||
status: "unknown",
|
||||
basis: "none",
|
||||
},
|
||||
{
|
||||
name: "case-sensitive POSIX mapping root",
|
||||
root: "/runtime/App",
|
||||
path: "/runtime/app/renderer.js",
|
||||
status: "unknown",
|
||||
basis: "none",
|
||||
},
|
||||
{
|
||||
name: "matching POSIX mapping root",
|
||||
root: "/runtime/App",
|
||||
path: "/runtime/App/renderer.js",
|
||||
status: "matched",
|
||||
basis: "operator-file-mapping",
|
||||
},
|
||||
{
|
||||
name: "case-insensitive Windows mapping root",
|
||||
root: String.raw`C:\runtime\App`,
|
||||
path: String.raw`c:\runtime\app\renderer.js`,
|
||||
status: "matched",
|
||||
basis: "operator-file-mapping",
|
||||
},
|
||||
] as const;
|
||||
|
||||
describe("JavaScript runtime reconciliation local paths", () => {
|
||||
it.each([
|
||||
{
|
||||
name: "case-sensitive POSIX input root",
|
||||
root: null,
|
||||
path: "/applications/Example.app/Contents/Resources/app/renderer.js",
|
||||
status: "unknown",
|
||||
},
|
||||
{
|
||||
name: "case-sensitive POSIX mapping root",
|
||||
root: "/runtime/App",
|
||||
path: "/runtime/app/renderer.js",
|
||||
status: "unknown",
|
||||
},
|
||||
{
|
||||
name: "matching POSIX mapping root",
|
||||
root: "/runtime/App",
|
||||
path: "/runtime/App/renderer.js",
|
||||
status: "matched",
|
||||
},
|
||||
{
|
||||
name: "case-insensitive Windows mapping root",
|
||||
root: String.raw`C:\runtime\App`,
|
||||
path: String.raw`c:\runtime\app\renderer.js`,
|
||||
status: "matched",
|
||||
},
|
||||
])("uses $name on every host", ({ root, path, status }) => {
|
||||
const base = JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE;
|
||||
const original = base.runtime_observations[0]!;
|
||||
const inspection = electronPageInspectionSchema.parse(
|
||||
original.normalized_result,
|
||||
);
|
||||
const runtime = createEvidence(undefined, original.provider, {
|
||||
predicateType: original.predicate_type,
|
||||
operation: original.operation,
|
||||
parameters: { ...original.parameters, include_script_sources: false },
|
||||
result: {
|
||||
...inspection,
|
||||
scripts: {
|
||||
...inspection.scripts,
|
||||
items: inspection.scripts.items.map((script) => ({
|
||||
...script,
|
||||
file_path: path,
|
||||
source: { included: false, reason: "not-requested" },
|
||||
})),
|
||||
it.each(RUNTIME_PATH_CASES)(
|
||||
"uses $name on every host",
|
||||
({ root, path, status, basis }) => {
|
||||
const base = JAVASCRIPT_RUNTIME_RECONCILIATION_EXAMPLE;
|
||||
const original = base.runtime_observations[0]!;
|
||||
const inspection = electronPageInspectionSchema.parse(
|
||||
original.normalized_result,
|
||||
);
|
||||
// Keep target and script coordinates consistent so an unrelated target
|
||||
// cannot activate the static layer after its script mapping was rejected.
|
||||
const runtime = createEvidence(undefined, original.provider, {
|
||||
predicateType: original.predicate_type,
|
||||
operation: original.operation,
|
||||
parameters: { ...original.parameters, include_script_sources: false },
|
||||
result: {
|
||||
...inspection,
|
||||
target: { ...inspection.target, file_path: path },
|
||||
scripts: {
|
||||
...inspection.scripts,
|
||||
items: inspection.scripts.items.map((script) => ({
|
||||
...script,
|
||||
file_path: path,
|
||||
source: { included: false, reason: "not-requested" },
|
||||
})),
|
||||
},
|
||||
},
|
||||
},
|
||||
confidence: original.confidence,
|
||||
authority: original.authority,
|
||||
});
|
||||
const reconciled = reconcileJavaScriptRuntimeEvidence({
|
||||
static_layers: base.static_layers.map((layer) => ({
|
||||
...layer,
|
||||
runtime_mappings: root === null ? [] : [{ kind: "file-root", root }],
|
||||
})),
|
||||
runtime_observations: [runtime],
|
||||
});
|
||||
if (!reconciled.ok) throw reconciled.error;
|
||||
const result = javascriptRuntimeReconciliationResultSchema.parse(
|
||||
reconciled.value.normalized_result,
|
||||
);
|
||||
expect(
|
||||
result.reconciliations.find(
|
||||
({ entity_kind }) => entity_kind === "script",
|
||||
),
|
||||
).toMatchObject({ status });
|
||||
});
|
||||
confidence: original.confidence,
|
||||
authority: original.authority,
|
||||
});
|
||||
const reconciled = reconcileJavaScriptRuntimeEvidence({
|
||||
static_layers: base.static_layers.map((layer) => ({
|
||||
...layer,
|
||||
runtime_mappings: root === null ? [] : [{ kind: "file-root", root }],
|
||||
})),
|
||||
runtime_observations: [runtime],
|
||||
});
|
||||
if (!reconciled.ok) throw reconciled.error;
|
||||
const result = javascriptRuntimeReconciliationResultSchema.parse(
|
||||
reconciled.value.normalized_result,
|
||||
);
|
||||
expect(
|
||||
result.reconciliations.find(
|
||||
({ entity_kind }) => entity_kind === "script",
|
||||
),
|
||||
).toMatchObject({ status, basis });
|
||||
expect(
|
||||
result.static_load_states.find(
|
||||
({ kind }) => kind === "javascript-asset",
|
||||
),
|
||||
).toMatchObject(
|
||||
status === "matched"
|
||||
? { status: "loaded", reason: "runtime-script-correspondence" }
|
||||
: { status: "unknown", reason: "layer-outside-runtime-scope" },
|
||||
);
|
||||
expect(result.static_layers[0]?.runtime_mappings).toEqual(
|
||||
root === null ? [] : [{ kind: "file-root", root, artifact_prefix: "" }],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("resolves relative file mapping roots before deriving result Evidence", () => {
|
||||
const absoluteRoot = resolve(process.cwd(), "runtime-cache-fixture");
|
||||
|
||||
@@ -105,6 +105,34 @@ it("keeps a contradicted nested ASAR opaque during JavaScript reconstruction", a
|
||||
expect(result.graph.coverage.omitted_count).toBeNull();
|
||||
});
|
||||
|
||||
it("keeps an ASAR-named file without an ASAR header opaque during JavaScript reconstruction", async () => {
|
||||
const root = await createTestTempDirectory("rea-opaque-asar-name-");
|
||||
await writeFile(join(root, "main.js"), "export const outer = true;\n");
|
||||
// Inventory records this file as ordinary bytes and does not expand it.
|
||||
await writeFile(join(root, "ordinary.asar"), "ordinary bytes");
|
||||
|
||||
const snapshot = await scanCanonicalArtifactInventory(root, {});
|
||||
const reader = createJavaScriptArtifactReader(root, "directory");
|
||||
try {
|
||||
const read = await readJavaScriptArtifactFiles(reader, snapshot);
|
||||
expect(read.files.map(({ path }) => path)).toEqual(["main.js"]);
|
||||
expect(read.containers).toEqual([]);
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
|
||||
const analyzed = await analyzeJavaScriptApplication({
|
||||
input_path: root,
|
||||
format: "directory",
|
||||
});
|
||||
if (!analyzed.ok) throw analyzed.error;
|
||||
const result = javascriptApplicationAnalysisResultSchema.parse(
|
||||
analyzed.value.normalized_result,
|
||||
);
|
||||
expect(result.statistics.nested_asar_containers).toBe(0);
|
||||
expect(result.integrity_contradictions).toEqual([]);
|
||||
});
|
||||
|
||||
it("retains semantic resource limits alongside recorded integrity contradictions", async () => {
|
||||
const { archive } = await createStrippedAsarAddon([
|
||||
{ path: "app.js", contents: primitiveCandidateExpansionSource() },
|
||||
|
||||
@@ -37,6 +37,53 @@ import {
|
||||
const root = fileURLToPath(new URL("../../..", import.meta.url));
|
||||
const temporaryRoots: string[] = [];
|
||||
|
||||
const README_FACT_FIXTURE_PATHS = [
|
||||
"README.md",
|
||||
"docs/readme/README_zh.md",
|
||||
"docs/readme/README_ja.md",
|
||||
"docs/readme/README_ko.md",
|
||||
"docs/readme/README_ar.md",
|
||||
"website/locales/languages.json",
|
||||
"docs/installation.md",
|
||||
"AGENTS.md",
|
||||
".github/pull_request_template.md",
|
||||
] as const;
|
||||
|
||||
const README_LINK_DRIFT_MUTATIONS = [
|
||||
[
|
||||
"(../installation.md#supported-agents)",
|
||||
"(../installation.md#missing-agents)",
|
||||
],
|
||||
[
|
||||
"https://rea.tools/zh-CN/guides/native/",
|
||||
"https://rea.tools/zh-CN/missing/",
|
||||
],
|
||||
[
|
||||
"https://rea.tools/zh-CN/guides/native/",
|
||||
"https://rea.tools/zh-TW/guides/native/",
|
||||
],
|
||||
[
|
||||
"https://rea.tools/zh-CN/guides/native/",
|
||||
"https://rea.tools/zh-CN/guides/native/?other=1",
|
||||
],
|
||||
[
|
||||
'src="../assets/rea-hopper-analysis.png"',
|
||||
'src="../assets/missing-hopper.png"',
|
||||
],
|
||||
['href="https://discord.gg/GkcryMnJDM"', 'href="https://discord.gg/missing"'],
|
||||
] as const;
|
||||
|
||||
const seedReadmeFactFixture = async (directory: string) => {
|
||||
for (const path of README_FACT_FIXTURE_PATHS) {
|
||||
const destination = join(directory, path);
|
||||
await mkdir(dirname(destination), { recursive: true });
|
||||
await copyFile(join(root, path), destination);
|
||||
}
|
||||
await mkdir(join(directory, "skills/reverse-engineer-anything"), {
|
||||
recursive: true,
|
||||
});
|
||||
};
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
temporaryRoots
|
||||
@@ -176,49 +223,14 @@ describe("canonical product catalog drift", () => {
|
||||
it("keeps translated readmes linked to canonical setup and tool details", async () => {
|
||||
const directory = await createTestTempDirectory("rea-readme-facts-");
|
||||
temporaryRoots.push(directory);
|
||||
const paths = [
|
||||
"README.md",
|
||||
"README_zh.md",
|
||||
"README_ja.md",
|
||||
"README_ko.md",
|
||||
"README_ar.md",
|
||||
"website/locales/languages.json",
|
||||
"docs/installation.md",
|
||||
"AGENTS.md",
|
||||
".github/pull_request_template.md",
|
||||
];
|
||||
for (const path of paths) {
|
||||
const destination = join(directory, path);
|
||||
await mkdir(dirname(destination), { recursive: true });
|
||||
await copyFile(join(root, path), destination);
|
||||
}
|
||||
await mkdir(join(directory, "skills/reverse-engineer-anything"), {
|
||||
recursive: true,
|
||||
});
|
||||
const translatedPath = join(directory, "README_zh.md");
|
||||
await seedReadmeFactFixture(directory);
|
||||
const translatedPath = join(directory, "docs/readme/README_zh.md");
|
||||
const translated = await readFile(translatedPath, "utf8");
|
||||
const catalog = await createProductCatalog(root);
|
||||
await expect(documentationFactIssues(directory, catalog)).resolves.toEqual(
|
||||
[],
|
||||
);
|
||||
for (const [original, changed] of [
|
||||
[
|
||||
"(docs/installation.md#supported-agents)",
|
||||
"(docs/installation.md#missing-agents)",
|
||||
],
|
||||
[
|
||||
"https://rea.tools/zh-CN/guides/native/",
|
||||
"https://rea.tools/zh-CN/missing/",
|
||||
],
|
||||
[
|
||||
"https://rea.tools/zh-CN/guides/native/",
|
||||
"https://rea.tools/zh-TW/guides/native/",
|
||||
],
|
||||
[
|
||||
"https://rea.tools/zh-CN/guides/native/",
|
||||
"https://rea.tools/zh-CN/guides/native/?other=1",
|
||||
],
|
||||
] as const) {
|
||||
for (const [original, changed] of README_LINK_DRIFT_MUTATIONS) {
|
||||
expect(translated).toContain(original);
|
||||
await writeFile(
|
||||
translatedPath,
|
||||
@@ -228,11 +240,10 @@ describe("canonical product catalog drift", () => {
|
||||
await expect(
|
||||
documentationFactIssues(directory, catalog),
|
||||
).resolves.toEqual([
|
||||
"README_zh.md: documentation links differ from README.md",
|
||||
"docs/readme/README_zh.md: documentation links differ from README.md",
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
it("fails check mode without rewriting a stale generated artifact", async () => {
|
||||
const directory = await createTestTempDirectory("rea-generated-check-");
|
||||
temporaryRoots.push(directory);
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import {
|
||||
mkdir,
|
||||
readFile,
|
||||
realpath,
|
||||
symlink,
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
@@ -7,6 +13,37 @@ import { parseBinaryTarget } from "../../../src/application/BinaryTargetResolver
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
describe("raw-binary admission", () => {
|
||||
it("preserves the requested raw path for Windows reparse admission", async () => {
|
||||
const directory = await createTestTempDirectory("rea-raw-linked-");
|
||||
const actual = join(directory, "actual");
|
||||
const linked = join(directory, "linked");
|
||||
await mkdir(actual);
|
||||
const bytes = Buffer.from("a90160", "hex");
|
||||
await writeFile(join(actual, "fixture.bin"), bytes);
|
||||
await symlink(
|
||||
actual,
|
||||
linked,
|
||||
process.platform === "win32" ? "junction" : "dir",
|
||||
);
|
||||
const requested = join(linked, "fixture.bin");
|
||||
const canonical = await realpath(requested);
|
||||
const target = await parseBinaryTarget("linked/fixture.bin", {
|
||||
cwd: directory,
|
||||
formatHint: "raw-binary",
|
||||
architecture: "6502",
|
||||
entryPoint: "0x8000",
|
||||
});
|
||||
expect(target).toMatchObject({
|
||||
ok: true,
|
||||
value: {
|
||||
path: canonical,
|
||||
sourcePath: process.platform === "win32" ? requested : canonical,
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
format: "raw-binary",
|
||||
architecture: "6502",
|
||||
},
|
||||
});
|
||||
});
|
||||
it("requires explicit architecture and entry even with a misleading suffix", async () => {
|
||||
const directory = await createTestTempDirectory("rea-raw-target-");
|
||||
const path = join(directory, "fixture.js");
|
||||
|
||||
@@ -4,9 +4,35 @@ import { describe, expect, it } from "vitest";
|
||||
import { systemDoctorHost } from "../../../src/application/Doctor.js";
|
||||
import { parseBinaryTarget } from "../../../src/application/BinaryTargetResolver.js";
|
||||
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
|
||||
import { pe } from "../../../src/domain/binaryTarget.fixture.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
describe("executable format refusal diagnostics", () => {
|
||||
it.each([
|
||||
[0x01a6, "0x01a6"],
|
||||
[0x0000, "0x0000"],
|
||||
[0xffff, "0xffff"],
|
||||
] as const)(
|
||||
"retains unsupported PE machine %i in the refusal",
|
||||
async (machine, expectedMachine) => {
|
||||
const directory = await createTestTempDirectory("rea-target-pe-machine-");
|
||||
const path = join(directory, "unsupported.exe");
|
||||
const bytes = pe(0x014c);
|
||||
bytes.writeUInt16LE(machine, 0x44);
|
||||
await writeFile(path, bytes);
|
||||
|
||||
const result = await parseBinaryTarget(path);
|
||||
if (result.ok) throw new Error("unsupported PE target was admitted");
|
||||
const reason = `unsupported PE architecture (COFF machine ${expectedMachine})`;
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "target_unavailable",
|
||||
category: "unsupported_target",
|
||||
message: `Cannot open artifact: ${reason}.`,
|
||||
details: { reason, constraint: "file_format_rejected" },
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["NE", "LE", "LX"] as const)(
|
||||
"reports unsupported %s executables without path advice",
|
||||
async (signature) => {
|
||||
|
||||
Reference in New Issue
Block a user