docs: preserve relative guide links through README relocation
This commit is contained in:
@@ -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 },
|
||||
@@ -924,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),
|
||||
|
||||
@@ -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: {} });
|
||||
});
|
||||
});
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
@@ -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 }) => {
|
||||
|
||||
+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);
|
||||
|
||||
@@ -37,6 +37,48 @@ 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 = [
|
||||
["(../native-investigation.md)", "(../native-investigation.md?other=1)"],
|
||||
[
|
||||
"(../installation.md#supported-agents)",
|
||||
"(../installation.md#missing-agents)",
|
||||
],
|
||||
["(../native-investigation.md)", "(../missing-native.md)"],
|
||||
["https://rea.tools/zh-CN/guides/", "https://rea.tools/zh-TW/guides/"],
|
||||
[
|
||||
"https://rea.tools/zh-CN/guides/",
|
||||
"https://rea.tools/zh-CN/guides/?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,47 +218,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)",
|
||||
],
|
||||
["(docs/native-investigation.md)", "(docs/missing-native.md)"],
|
||||
[
|
||||
"(docs/native-investigation.md)",
|
||||
"(docs/native-investigation.md?other=1)",
|
||||
],
|
||||
["https://rea.tools/zh-CN/guides/", "https://rea.tools/zh-TW/guides/"],
|
||||
[
|
||||
"https://rea.tools/zh-CN/guides/",
|
||||
"https://rea.tools/zh-CN/guides/?other=1",
|
||||
],
|
||||
] as const) {
|
||||
for (const [original, changed] of README_LINK_DRIFT_MUTATIONS) {
|
||||
expect(translated).toContain(original);
|
||||
await writeFile(
|
||||
translatedPath,
|
||||
@@ -226,11 +235,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);
|
||||
|
||||
Reference in New Issue
Block a user