Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

refactor(setup): reuse desired registration per document snapshot

morluto20bf7d957f26
diff --git a/src/application/SetupClientConfiguration.ts b/src/application/SetupClientConfiguration.ts
index 3bd09e7a4..2ce8c10fb 100644
--- a/src/application/SetupClientConfiguration.ts
+++ b/src/application/SetupClientConfiguration.ts
@@ -405,36 +405,20 @@ export const clientConfigurationAligned = async (
}
const original = await readRegularFileText(client.configPath);
const parsed = parseClientConfiguration(original, client.format);
- const policy = await readClientPolicyBlock(
+ const desired = await clientConfigurationDesired(
client,
+ providerEnvironment,
+ command,
parsed,
- await clientConfigurationDesired(
- client,
- providerEnvironment,
- command,
- parsed,
- files.value,
- resolveProviderRequestBudget,
- ),
+ files.value,
+ resolveProviderRequestBudget,
);
+ const policy = await readClientPolicyBlock(client, parsed, desired);
if (!policy.ok) {
throwCleanupFailure(policy.error);
return false;
}
- return (
- policy.value === undefined &&
- registrationCurrent(
- parsed,
- await clientConfigurationDesired(
- client,
- providerEnvironment,
- command,
- parsed,
- files.value,
- resolveProviderRequestBudget,
- ),
- )
- );
+ return policy.value === undefined && registrationCurrent(parsed, desired);
} catch (cause: unknown) {
if (cause instanceof RegularFileCleanupFailure) throw cause;
// Unreadable configuration is treated as not aligned so setup repairs it.
@@ -544,18 +528,15 @@ const inspectClientDocument = async (
}
try {
const parsed = parseClientConfiguration(original, client.format);
- const policy = await readClientPolicyBlock(
+ const desired = await clientConfigurationDesired(
client,
+ providerEnvironment,
+ command,
parsed,
- await clientConfigurationDesired(
- client,
- providerEnvironment,
- command,
- parsed,
- files.value,
- resolveProviderRequestBudget,
- ),
+ files.value,
+ resolveProviderRequestBudget,
);
+ const policy = await readClientPolicyBlock(client, parsed, desired);
if (!policy.ok) {
throwCleanupFailure(policy.error);
return {
@@ -565,14 +546,6 @@ const inspectClientDocument = async (
}
if (policy.value !== undefined)
return { status: "invalid", remediation: policy.value };
- const desired = await clientConfigurationDesired(
- client,
- providerEnvironment,
- command,
- parsed,
- files.value,
- resolveProviderRequestBudget,
- );
if (registrationCurrent(parsed, desired))
return { status: "already_current" };
const fallback = await readZcodeFallbackServers(client, parsed);
diff --git a/tests/boundary/filesystem/clientConfigurationEnvironment.test.ts b/tests/boundary/filesystem/clientConfigurationEnvironment.test.ts
index 637b200d8..84043cc20 100644
--- a/tests/boundary/filesystem/clientConfigurationEnvironment.test.ts
+++ b/tests/boundary/filesystem/clientConfigurationEnvironment.test.ts
@@ -23,6 +23,7 @@ import {
import { snapshotEnvironment } from "../../../src/process/snapshotEnvironment.js";
import { npxRegistrationCommand } from "../../../src/application/ClientRegistrationIdentity.js";
import { ok } from "../../../src/domain/result.js";
+import { MCP_STARTUP_POLICY } from "../../../src/mcpStartupPolicy.js";
it("awaits the owner-parsed provider request budget without changing caller strings", async () => {
const parsed = parseClientConfiguration(
@@ -58,6 +59,55 @@ it("awaits the owner-parsed provider request budget without changing caller stri
});
});
+it("reuses desired registration facts within a snapshot and revalidates later inspections", async () => {
+ const home = await createTestTempDirectory("rea-registration-snapshot-");
+ const configPath = join(home, "mcp.json");
+ const environment = {
+ REA_ANALYSIS_PROVIDER: "ida",
+ REA_IDA_MCP_CONFIG: "/tmp/rea-registration.json/",
+ REA_MCP_INPUT_SCHEMA_PROFILE: "compact",
+ };
+ const original = JSON.stringify({
+ mcpServers: {
+ rea: {
+ command: "rea",
+ args: ["mcp"],
+ env: environment,
+ startupTimeoutMs: MCP_STARTUP_POLICY.kimiStartupTimeoutMs,
+ toolTimeoutMs: 450_000,
+ },
+ },
+ });
+ await writeFile(configPath, original);
+ const client = { name: "kimi", format: "kimi", configPath } as const;
+ const observations: string[] = [];
+ const resolveBudget = async (
+ provider: string,
+ observedEnvironment: Readonly<Record<string, string>>,
+ ) => {
+ expect(observedEnvironment.REA_IDA_MCP_CONFIG).toBe(
+ environment.REA_IDA_MCP_CONFIG,
+ );
+ observations.push(provider);
+ return ok(17);
+ };
+
+ expect(
+ await clientConfigurationAligned(client, {}, ["rea", "mcp"], resolveBudget),
+ ).toBe(true);
+ expect(observations).toEqual(["ida"]);
+
+ expect(
+ await inspectClientConfiguration(client, {}, ["rea", "mcp"], resolveBudget),
+ ).toEqual({ status: "already_current" });
+ // Inspection checks both the layered preflight and the freshly read document.
+ expect(observations).toEqual(["ida", "ida", "ida"]);
+ expect(await readFile(configPath, "utf8")).toBe(original);
+ await expect(access(`${configPath}.rea.backup`)).rejects.toMatchObject({
+ code: "ENOENT",
+ });
+});
+
it.each(["win32", "linux"] as const)(
"uses the selected %s identity when inspecting lowercase registration settings",
async (platform) => {