mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
* test(mcp): check advertised schemas against a portable dialect in every profile * fix(mcp): re-emit advertised patterns in a portable regex grammar * fix(mcp): present discover_tools input through the selected profile The hot-cold catalog registered discover_tools directly with the SDK, so the default compact input profile still advertised its canonical schema, including page-size defaults clients apply on their own (#5322). Route every listed input schema, transport discovery included, through one server-owned presentation, and pass the selected presentation to the deferred server, which serves recorded tool schemas but not discovery. * fix(mcp): keep the Evidence union on described borrowed inputs borrowEvidenceInput installed its advertised projection on one schema instance. A call site's .describe() rebuilds the schema from its definition, so match_native_functions advertised left and right as unconstrained values in every input profile. Install the projection in the borrowed parser's constructor so derived schemas keep it, for both borrowed inputs and borrowed arrays. * fix(mcp): validate advertised dialect by selected profile * fix(mcp): preserve schema widening through references * feat(mcp): project compact input schemas into the portable advertised dialect One projection (advertisedDialectProjection.ts) owns the compact input advertisement: one type per node, items on every array, string literals as enums, oneOf widened to anyOf, allOf merged, tuples as element unions, exclusive bounds made inclusive, and every keyword outside the dialect dropped. Each rewrite is exact or widening; server validation is unchanged. The root description and sentences for dropped cross-field constraints move to the tool description, which Codex and Zed keep. The compact baseline falls to nullable values only (29), which the dialect cannot express without narrowing an input. The gateway shape repairs (typeArrayItemUnions, hasGatewayIncompatibleShape), the second dependentRequired-to-prose copy and the strict-gateway test denylist are removed; the dialect checker gates the inline presentation instead. * feat(mcp): omit output schemas from tools/list by default No surveyed model API reads an output schema, MCP client validators repeat REA's own result validation, and complete output schemas were about 92% of the default tools/list. REA_MCP_OUTPUT_SCHEMA_PROFILE now resolves to off through one owner (resolveMcpOutputSchemaProfile); compact and full remain selectable. structuredContent is still delivered, and the deferred server serves both off and full from the recorded catalog with the matching recorded identity. Tests and artifact verifiers that validate results against complete advertised output contracts select full explicitly. * docs: describe omitted output schemas as the default in README translations * fix(mcp): select schemas in verification workflows * fix(mcp): refuse zero-padded repeat bounds and record host-specific path patterns * fix(mcp): keep projected schemas permissive * fix(mcp): keep references valid when presentation widens their targets * fix(mcp): keep a single union branch's closure scoped to its properties * fix(mcp): select complete output schemas in the Electron verifier * fix(mcp): select complete output schemas in standalone verifier probes * fix(mcp): keep an allOf member's tuple tail with its own positions * fix(mcp): relax references into negations and conditionals presentation may remove * refactor(contracts): declare root discriminators as typed schema annotations * test(mcp): select the borrowed Evidence contract from its family * fix(mcp): keep astral literals and dynamic references widening in every mode * fix(mcp): omit astral literals and relax untracked references when presentation widens * fix(mcp): select complete output schemas in every verifier transport * fix(mcp): read reference pointers by schema position, not segment spelling * fix(mcp): protect references into collapsing boolean unions and keep referencing branches out of the collapse * fix(mcp): keep reduced schemas open when their root admits names by pattern * test(mcp): keep the reduced-schema pattern case outside the size-limited block * fix(mcp): omit patterns whose classes name astral characters * fix(mcp): decide union collapse and pointer protection from canonical branches * docs(mcp): document non-u astral matching and pin BMP agreement across V8 modes * fix(mcp): keep prototype-named properties as own properties in the dialect projection * test(mcp): select full output schemas in packet and signal schema checks * test(mcp): expect the advertised base64 schema to omit the unbounded pad-bit probe * fix(mcp): protect references into unevaluated keywords lost evaluation removes * fix(mcp): validate the doctor probe reply against the canonical output contract (#10655) * fix(mcp): validate the doctor probe reply against the canonical output contract * test(mcp): replay doctor probe validation under every output profile * test(mcp): accept typed-branch nullable unions in the advertised dialect (#10649) * test(mcp): select full output schemas in HTTP session workflows * fix(mcp): emit stack-safe classes with non-ASCII members and protect draft-07 reference siblings * fix(mcp): protect references into literal siblings of relaxed draft-07 references * feat(mcp): omit output schemas from tools/list by default (#10646) * feat(mcp): omit output schemas from tools/list by default No surveyed model API reads an output schema, MCP client validators repeat REA's own result validation, and complete output schemas were about 92% of the default tools/list. REA_MCP_OUTPUT_SCHEMA_PROFILE now resolves to off through one owner (resolveMcpOutputSchemaProfile); compact and full remain selectable. structuredContent is still delivered, and the deferred server serves both off and full from the recorded catalog with the matching recorded identity. Tests and artifact verifiers that validate results against complete advertised output contracts select full explicitly. * fix(mcp): select schemas in verification workflows * fix(mcp): select complete output schemas in the Electron verifier * fix(mcp): select complete output schemas in standalone verifier probes * fix(mcp): select complete output schemas in every verifier transport * test(mcp): select full output schemas in packet and signal schema checks * fix(mcp): validate the doctor probe reply against the canonical output contract (#10655) * fix(mcp): validate the doctor probe reply against the canonical output contract * test(mcp): replay doctor probe validation under every output profile * test(mcp): accept typed-branch nullable unions in the advertised dialect (#10649) * test(mcp): select full output schemas in HTTP session workflows * fix(mcp): keep the Evidence union on described borrowed inputs (#10597) * fix(mcp): keep the Evidence union on described borrowed inputs borrowEvidenceInput installed its advertised projection on one schema instance. A call site's .describe() rebuilds the schema from its definition, so match_native_functions advertised left and right as unconstrained values in every input profile. Install the projection in the borrowed parser's constructor so derived schemas keep it, for both borrowed inputs and borrowed arrays. * test(mcp): select the borrowed Evidence contract from its family * docs(mcp): admit baseline growth only for restored contract declarations * fix(mcp): state reduced multi-type properties as typed branches, not type lists The reduced fallback derived a property's types and emitted them as a type list, which Gemini, Moonshot and Ark reject. A property whose canonical schema is anyOf string and number therefore traded a typed union for a rejected construct when the inline projection fell back. Emit one type, or anyOf typed branches, so [T, null] becomes the dialect's nullable union. * feat(mcp)!: retire the full schema profiles and declare complete observations as a typed annotation (#10718) * refactor(mcp): declare complete observations as a typed annotation applied only on the wire * test(mcp): compare complete-observation declarations with their owning text * refactor(schema): couple Zod checks with their JSON Schema constraint keywords (#10725) * refactor(schema): couple Zod checks with their JSON Schema constraint keywords * refactor(schema): declare pattern approximations and object output roots as typed annotations (#10754) * refactor(schema): declare pattern approximations and object output roots as typed annotations * fix(schema): refuse pattern declarations JSON Schema cannot state * test(schema): select guided_workflows from its contract family * feat(mcp)!: retire the full input and output schema profiles (#10841) * feat(mcp)!: retire the full input and output schema profiles The compact input presentation is now the only advertised input schema, and output schemas are either omitted (`off`, the default) or bounded (`compact`). Catalog identity, the build-recorded digests and the recorded startup catalog collapse to those presentations: two digest profiles instead of six, one recorded catalog instead of two, and no input dialect baseline. Tests and verifiers that validated replies against listed full output schemas now validate against the canonical output contract, which REA already enforces server-side; tests that asserted canonical input restrictions read the canonical input schema instead of a full listing. BREAKING CHANGE: `REA_MCP_INPUT_SCHEMA_PROFILE=full` and `REA_MCP_OUTPUT_SCHEMA_PROFILE=full` are refused at startup and by `rea setup` with a configuration error naming the setting. Remove the setting from the client registration (or rerun setup with `REA_MCP_INPUT_SCHEMA_PROFILE=compact` / `REA_MCP_OUTPUT_SCHEMA_PROFILE=compact`). `REA_MCP_INPUT_SCHEMA_PROFILE` still accepts `compact`. Server-side validation is unchanged. * test(mcp): validate replies against canonical output contracts at every listed-schema reader tools/list omits output schemas by default, so fixtures, verifiers and the Android analysis runners that read a listed outputSchema now bind the canonical contract instead. connectLocalToolsMcp and advertisedMcpToolSchemas hand the SDK a definition carrying the canonical output schema, so the SDK client and caller-supplied validators check every successful reply. * test(mcp): resolve Android runners' output contracts from the selected repository The Android efficiency runners imported the canonical output-schema helper from the harness checkout while --repository selects the revision under test. Import it from the selected repository, as the runners already do for the SDK and Ajv. * test(mcp): let Android runners compare revisions before the canonical output helper A selected revision without scripts/lib/canonical-output-schema.mjs could not start the Android runners. Choose the output contracts in one harness helper: the selected revision's canonical contracts when it has them, otherwise its listed schemas under the full output profile it still supports. * fix(scripts): keep caller launch settings when the real Hopper verifier builds its server environment The verifier deleted REA_VERIFY_SERVER_COMMAND and REA_VERIFY_SERVER_ARGS_JSON from process.env itself before reading them, so a caller selecting an installed REA command silently ran the checkout's dist/main.js. Copy the environment, as main does, so only the child's environment changes. * test(mcp): validate whole replies against canonical output contracts wherever a listed definition is held tools/list omits output schemas by default and the full output profile is gone, so tests that handed the SDK a listed definition no longer checked complete replies. Attach the canonical output schema with withCanonicalOutputSchema at every held REA tool definition. Environment-served tools (not REA contracts), and the deferred-runtime and doctor tests that exercise per-profile listings, keep their listed definitions. * test(mcp): record the advertised catalog summary without the retired full profiles Retiring the full input and output profiles leaves only the compact input and compact output listings, so the summary drops the full-profile digests and every pattern only the full listings carried. Regenerated with npm run verify:advertised-schemas -- --update-summary.
603 lines
19 KiB
TypeScript
603 lines
19 KiB
TypeScript
import { HOST_PLATFORM } from "../../../src/platform/HostPlatform.js";
|
|
import { PRODUCT_IDENTITY } from "../../../src/identity.js";
|
|
import { access, 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 { currentClientRegistrationCommand } from "../../../src/application/ClientRegistrationIdentity.js";
|
|
import { configureClientConfiguration } from "../../../src/application/SetupClientConfiguration.js";
|
|
import {
|
|
clientSkillDirectories,
|
|
supportedClients,
|
|
} from "../../../src/application/SupportedClients.js";
|
|
import { systemUninstallHost } from "../../../src/application/Uninstall.js";
|
|
import { MCP_STARTUP_POLICY } from "../../../src/mcpStartupPolicy.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { clearClientLocationEnvironment } from "../../fixtures/clientEnvironment.js";
|
|
|
|
const command = currentClientRegistrationCommand();
|
|
|
|
beforeEach(clearClientLocationEnvironment);
|
|
afterEach(() => vi.unstubAllEnvs());
|
|
|
|
const kimiPath = (
|
|
home: string,
|
|
platform: NodeJS.Platform,
|
|
env: Parameters<typeof supportedClients>[2] = {},
|
|
) => supportedClients(home, platform, env).find(({ name }) => name === "kimi");
|
|
|
|
const exists = async (path: string): Promise<boolean> => {
|
|
try {
|
|
await access(path);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
const expectedRegistration = (
|
|
launcher: readonly string[],
|
|
profile?: "compact",
|
|
toolTimeoutMs = 450_000,
|
|
) => ({
|
|
command: launcher[0],
|
|
args: launcher.slice(1),
|
|
...(profile === undefined
|
|
? {}
|
|
: { env: { REA_MCP_INPUT_SCHEMA_PROFILE: profile } }),
|
|
startupTimeoutMs: MCP_STARTUP_POLICY.kimiStartupTimeoutMs,
|
|
toolTimeoutMs,
|
|
});
|
|
|
|
describe("Kimi Code configuration paths and skills", () => {
|
|
it.each([
|
|
[undefined, join("/home/a/.kimi-code")],
|
|
["", join("/home/a/.kimi-code")],
|
|
[join("/tmp", "isolated-kimi"), join("/tmp", "isolated-kimi")],
|
|
])("resolves KIMI_CODE_HOME for %j", (override, directory) => {
|
|
const client = kimiPath(
|
|
"/home/a",
|
|
"linux",
|
|
override === undefined ? {} : { KIMI_CODE_HOME: override },
|
|
);
|
|
expect(client).toMatchObject({
|
|
name: "kimi",
|
|
displayName: "Kimi Code",
|
|
configPath: join(directory, "mcp.json"),
|
|
markerPath: directory,
|
|
format: "kimi",
|
|
});
|
|
});
|
|
|
|
it("uses the existing shared skill destination without a separate skill root", () => {
|
|
expect(
|
|
clientSkillDirectories("/home/a", ["kimi"], {}, HOST_PLATFORM.platform)
|
|
.directories,
|
|
).toEqual([{ client: "shared", directory: "/home/a/.agents/skills" }]);
|
|
});
|
|
});
|
|
|
|
describe("Kimi Code registration lifecycle", () => {
|
|
const kimiClient = async () => {
|
|
const home = await createTestTempDirectory("rea-kimi-");
|
|
const client = kimiPath(home, process.platform, {});
|
|
if (client?.markerPath === undefined)
|
|
throw new Error("missing Kimi Code client");
|
|
await mkdir(client.markerPath, { recursive: true });
|
|
return { home, client };
|
|
};
|
|
|
|
it("preserves the caller's enabledTools selection during refresh", async () => {
|
|
const { client } = await kimiClient();
|
|
const enabledTools = ["binary_session", "analyze_javascript_application"];
|
|
await writeFile(
|
|
client.configPath,
|
|
JSON.stringify({
|
|
mcpServers: {
|
|
rea: { command: "rea", args: ["mcp"], enabledTools },
|
|
},
|
|
}),
|
|
);
|
|
expect(
|
|
(await configureClientConfiguration(client, {}, command)).status,
|
|
).toBe("configured");
|
|
expect(
|
|
JSON.parse(await readFile(client.configPath, "utf8")).mcpServers.rea,
|
|
).toEqual({
|
|
...expectedRegistration(command),
|
|
enabledTools,
|
|
});
|
|
expect(
|
|
(await configureClientConfiguration(client, {}, command)).status,
|
|
).toBe("unchanged");
|
|
});
|
|
|
|
it("preserves selected timeout values through refresh and keeps backups idempotent", async () => {
|
|
const { home, client } = await kimiClient();
|
|
const original = JSON.stringify({
|
|
mcpServers: {
|
|
rea: {
|
|
...expectedRegistration(["rea", "mcp"]),
|
|
startupTimeoutMs: 90_000,
|
|
toolTimeoutMs: 300_000,
|
|
},
|
|
},
|
|
});
|
|
await writeFile(client.configPath, original);
|
|
|
|
expect(
|
|
await configureClientConfiguration(client, {}, command),
|
|
).toMatchObject({
|
|
status: "configured",
|
|
backupPath: `${client.configPath}.rea.backup`,
|
|
});
|
|
expect(
|
|
JSON.parse(await readFile(client.configPath, "utf8")).mcpServers.rea,
|
|
).toEqual({
|
|
...expectedRegistration(command),
|
|
startupTimeoutMs: 90_000,
|
|
toolTimeoutMs: 300_000,
|
|
});
|
|
expect(await readFile(`${client.configPath}.rea.backup`, "utf8")).toBe(
|
|
original,
|
|
);
|
|
expect(await configureClientConfiguration(client, {}, command)).toEqual({
|
|
status: "unchanged",
|
|
});
|
|
expect(
|
|
(
|
|
await readClientRegistrationStatuses(home, undefined, {
|
|
platform: HOST_PLATFORM.platform,
|
|
environment: {},
|
|
})
|
|
).find(({ client: name }) => name === "kimi"),
|
|
).toMatchObject({
|
|
state: "aligned",
|
|
advisory: expect.stringContaining("toolTimeoutMs = 450000 ms"),
|
|
});
|
|
});
|
|
|
|
it("derives a client deadline beyond Node's timer ceiling for an alternative provider selector", async () => {
|
|
const { client } = await kimiClient();
|
|
expect(
|
|
await configureClientConfiguration(
|
|
client,
|
|
{
|
|
REA_ANALYSIS_PROVIDER: "ida",
|
|
REA_GHIDRA_STARTUP_TIMEOUT_MS: "2147483647",
|
|
},
|
|
command,
|
|
),
|
|
).toMatchObject({ status: "configured" });
|
|
expect(
|
|
JSON.parse(await readFile(client.configPath, "utf8")).mcpServers.rea
|
|
.toolTimeoutMs,
|
|
).toBe(2_147_603_647);
|
|
});
|
|
|
|
it("registers without type, preserves unrelated settings, backs up, and is idempotent", async () => {
|
|
const { home, client } = await kimiClient();
|
|
const original = `{
|
|
"customSetting": { "enabled": true },
|
|
"mcpServers": {
|
|
"other": { "command": "other-server", "startupTimeoutMs": 5000 }
|
|
}
|
|
}
|
|
`;
|
|
await writeFile(client.configPath, original);
|
|
|
|
expect(await configureClientConfiguration(client, {}, command)).toEqual({
|
|
status: "configured",
|
|
backupPath: `${client.configPath}.rea.backup`,
|
|
});
|
|
const text = await readFile(client.configPath, "utf8");
|
|
expect(JSON.parse(text)).toEqual({
|
|
customSetting: { enabled: true },
|
|
mcpServers: {
|
|
other: { command: "other-server", startupTimeoutMs: 5000 },
|
|
rea: expectedRegistration(command),
|
|
},
|
|
});
|
|
expect(text).not.toContain('"type"');
|
|
expect(text).not.toContain('"transport"');
|
|
expect(await readFile(`${client.configPath}.rea.backup`, "utf8")).toBe(
|
|
original,
|
|
);
|
|
expect(await configureClientConfiguration(client, {}, command)).toEqual({
|
|
status: "unchanged",
|
|
});
|
|
expect(await readFile(client.configPath, "utf8")).toBe(text);
|
|
expect(
|
|
(
|
|
await readClientRegistrationStatuses(home, undefined, {
|
|
platform: HOST_PLATFORM.platform,
|
|
environment: {},
|
|
})
|
|
).find(({ client: name }) => name === "kimi"),
|
|
).toMatchObject({ state: "aligned", command });
|
|
|
|
expect((await systemUninstallHost(home).removeClient(client)).status).toBe(
|
|
"removed",
|
|
);
|
|
expect(JSON.parse(await readFile(client.configPath, "utf8"))).toEqual({
|
|
customSetting: { enabled: true },
|
|
mcpServers: {
|
|
other: { command: "other-server", startupTimeoutMs: 5000 },
|
|
},
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("Kimi Code input-schema profile selection", () => {
|
|
const kimiClient = async () => {
|
|
const home = await createTestTempDirectory("rea-kimi-schema-profile-");
|
|
const client = kimiPath(home, process.platform, {});
|
|
if (client?.markerPath === undefined)
|
|
throw new Error("missing Kimi Code client");
|
|
await mkdir(client.markerPath, { recursive: true });
|
|
return { home, client };
|
|
};
|
|
|
|
it("refuses to preserve a stored removed full profile", async () => {
|
|
const { client } = await kimiClient();
|
|
const stored = JSON.stringify({
|
|
mcpServers: {
|
|
rea: {
|
|
command: "rea",
|
|
args: ["mcp"],
|
|
env: { REA_MCP_INPUT_SCHEMA_PROFILE: "full" },
|
|
},
|
|
},
|
|
});
|
|
await writeFile(client.configPath, stored);
|
|
|
|
// The removed value would fail at server startup, so setup fails closed
|
|
// instead of rewriting a registration that cannot start.
|
|
expect(
|
|
(await configureClientConfiguration(client, {}, command)).status,
|
|
).toBe("failed");
|
|
expect(await readFile(client.configPath, "utf8")).toBe(stored);
|
|
});
|
|
|
|
it("uses the caller's explicit compact profile", async () => {
|
|
const { home, client } = await kimiClient();
|
|
expect(
|
|
(
|
|
await configureClientConfiguration(
|
|
client,
|
|
{ REA_MCP_INPUT_SCHEMA_PROFILE: "compact" },
|
|
command,
|
|
)
|
|
).status,
|
|
).toBe("configured");
|
|
expect(
|
|
JSON.parse(await readFile(client.configPath, "utf8")).mcpServers.rea,
|
|
).toEqual(expectedRegistration(command, "compact"));
|
|
expect(
|
|
(
|
|
await readClientRegistrationStatuses(home, undefined, {
|
|
platform: HOST_PLATFORM.platform,
|
|
environment: {},
|
|
})
|
|
).find(({ client: name }) => name === "kimi"),
|
|
).toMatchObject({ state: "aligned", command });
|
|
});
|
|
|
|
it.each([["compact", "full"]] as const)(
|
|
"lets explicit setup %s replace stored %s",
|
|
async (overrideProfile, storedProfile) => {
|
|
const { client } = await kimiClient();
|
|
await writeFile(
|
|
client.configPath,
|
|
JSON.stringify({
|
|
mcpServers: {
|
|
rea: {
|
|
command: "rea",
|
|
args: ["mcp"],
|
|
env: { REA_MCP_INPUT_SCHEMA_PROFILE: storedProfile },
|
|
},
|
|
},
|
|
}),
|
|
);
|
|
|
|
expect(
|
|
(
|
|
await configureClientConfiguration(
|
|
client,
|
|
{ REA_MCP_INPUT_SCHEMA_PROFILE: overrideProfile },
|
|
command,
|
|
)
|
|
).status,
|
|
).toBe("configured");
|
|
expect(
|
|
JSON.parse(await readFile(client.configPath, "utf8")).mcpServers.rea,
|
|
).toEqual(expectedRegistration(command, overrideProfile));
|
|
},
|
|
);
|
|
|
|
it("reports an omitted-profile registration aligned because compact is the server default", async () => {
|
|
const { home, client } = await kimiClient();
|
|
await writeFile(
|
|
client.configPath,
|
|
JSON.stringify({
|
|
mcpServers: {
|
|
rea: {
|
|
command: command[0],
|
|
args: command.slice(1),
|
|
startupTimeoutMs: MCP_STARTUP_POLICY.kimiStartupTimeoutMs,
|
|
toolTimeoutMs: 120_000,
|
|
},
|
|
},
|
|
}),
|
|
);
|
|
|
|
expect(
|
|
(
|
|
await readClientRegistrationStatuses(home, undefined, {
|
|
platform: HOST_PLATFORM.platform,
|
|
environment: {},
|
|
})
|
|
).find(({ client: name }) => name === "kimi"),
|
|
).toMatchObject({ state: "aligned", command });
|
|
expect(await configureClientConfiguration(client, {}, command)).toEqual({
|
|
status: "unchanged",
|
|
});
|
|
expect(
|
|
JSON.parse(await readFile(client.configPath, "utf8")).mcpServers.rea,
|
|
).toEqual(expectedRegistration(command, undefined, 120_000));
|
|
});
|
|
});
|
|
|
|
describe("Kimi Code package launchers", () => {
|
|
const kimiClient = async () => {
|
|
const home = await createTestTempDirectory("rea-kimi-launcher-");
|
|
const client = kimiPath(home, process.platform, {});
|
|
if (client?.markerPath === undefined)
|
|
throw new Error("missing Kimi Code client");
|
|
await mkdir(client.markerPath, { recursive: true });
|
|
return { home, client } as const;
|
|
};
|
|
|
|
it.each([
|
|
["npx", "linux"],
|
|
["bunx", "linux"],
|
|
["npx", "win32"],
|
|
["bunx", "win32"],
|
|
] as const)(
|
|
"migrates the legacy %s launcher on %s",
|
|
async (runner, platform) => {
|
|
const { home, client } = await kimiClient();
|
|
const pinned = PRODUCT_IDENTITY.registrationPackageSpecifier;
|
|
const previous =
|
|
runner === "npx"
|
|
? ["npx", "-y", pinned, "mcp"]
|
|
: ["bunx", pinned, "mcp"];
|
|
const legacy =
|
|
platform === "win32" ? ["cmd.exe", "/d", "/c", ...previous] : previous;
|
|
expect(
|
|
(await configureClientConfiguration(client, {}, legacy)).status,
|
|
).toBe("configured");
|
|
expect(
|
|
(
|
|
await readClientRegistrationStatuses(home, undefined, {
|
|
platform,
|
|
environment: {},
|
|
})
|
|
).find(({ client: name }) => name === "kimi"),
|
|
).toMatchObject({ state: "stale" });
|
|
const launcher = currentClientRegistrationCommand({ platform });
|
|
expect(
|
|
(await configureClientConfiguration(client, {}, launcher)).status,
|
|
).toBe("configured");
|
|
expect(
|
|
JSON.parse(await readFile(client.configPath, "utf8")).mcpServers.rea,
|
|
).toEqual(expectedRegistration(launcher));
|
|
expect(
|
|
(
|
|
await readClientRegistrationStatuses(home, undefined, {
|
|
platform,
|
|
environment: {},
|
|
})
|
|
).find(({ client: name }) => name === "kimi"),
|
|
).toMatchObject({ state: "aligned", command: launcher });
|
|
expect(await configureClientConfiguration(client, {}, launcher)).toEqual({
|
|
status: "unchanged",
|
|
});
|
|
},
|
|
);
|
|
});
|
|
|
|
describe("Kimi Code transport validation", () => {
|
|
const kimiClient = async () => {
|
|
const home = await createTestTempDirectory("rea-kimi-validation-");
|
|
const client = kimiPath(home, process.platform, {});
|
|
if (client?.markerPath === undefined)
|
|
throw new Error("missing Kimi Code client");
|
|
await mkdir(client.markerPath, { recursive: true });
|
|
return { home, client };
|
|
};
|
|
|
|
it("creates a registration in a zero-byte file and accepts whitespace-only files", async () => {
|
|
const { home, client } = await kimiClient();
|
|
for (const original of ["", " \n\t"]) {
|
|
await writeFile(client.configPath, original);
|
|
expect(
|
|
(await configureClientConfiguration(client, {}, command)).status,
|
|
).toBe("configured");
|
|
expect(
|
|
JSON.parse(await readFile(client.configPath, "utf8")).mcpServers.rea,
|
|
).toEqual(expectedRegistration(command));
|
|
expect(await configureClientConfiguration(client, {}, command)).toEqual({
|
|
status: "unchanged",
|
|
});
|
|
expect(
|
|
(await systemUninstallHost(home).removeClient(client)).status,
|
|
).toBe("removed");
|
|
}
|
|
});
|
|
|
|
it.each([
|
|
'{"mcpServers": {',
|
|
'{/* comment */ "mcpServers": {}}',
|
|
'{"mcpServers": {},}',
|
|
'\uFEFF{"mcpServers": {}}',
|
|
])("rejects invalid strict JSON %j without writes", async (original) => {
|
|
const { client } = await kimiClient();
|
|
await writeFile(client.configPath, original);
|
|
expect(await configureClientConfiguration(client, {}, command)).toEqual({
|
|
status: "failed",
|
|
reason: "readback",
|
|
});
|
|
expect(await readFile(client.configPath, "utf8")).toBe(original);
|
|
expect(await exists(`${client.configPath}.rea.backup`)).toBe(false);
|
|
});
|
|
|
|
it("accepts explicit stdio transport without causing repeated rewrites", async () => {
|
|
const { home, client } = await kimiClient();
|
|
await writeFile(
|
|
client.configPath,
|
|
JSON.stringify({
|
|
mcpServers: {
|
|
rea: {
|
|
transport: "stdio",
|
|
...expectedRegistration(command),
|
|
},
|
|
},
|
|
}),
|
|
);
|
|
expect(
|
|
(
|
|
await readClientRegistrationStatuses(home, undefined, {
|
|
platform: HOST_PLATFORM.platform,
|
|
environment: {},
|
|
})
|
|
).find(({ client: name }) => name === "kimi"),
|
|
).toMatchObject({ state: "aligned", command });
|
|
// The explicit selector already chooses stdio, so setup keeps it and
|
|
// has nothing to rewrite.
|
|
expect(await configureClientConfiguration(client, {}, command)).toEqual({
|
|
status: "unchanged",
|
|
});
|
|
expect(await configureClientConfiguration(client, {}, command)).toEqual({
|
|
status: "unchanged",
|
|
});
|
|
expect(
|
|
JSON.parse(await readFile(client.configPath, "utf8")).mcpServers.rea
|
|
.transport,
|
|
).toBe("stdio");
|
|
expect(
|
|
(
|
|
await readClientRegistrationStatuses(home, undefined, {
|
|
platform: HOST_PLATFORM.platform,
|
|
environment: {},
|
|
})
|
|
).find(({ client: name }) => name === "kimi"),
|
|
).toMatchObject({ state: "aligned", command });
|
|
});
|
|
|
|
it.each(["sse"])(
|
|
"rejects explicit transport %j instead of silently accepting another protocol",
|
|
async (transport) => {
|
|
const { home, client } = await kimiClient();
|
|
await writeFile(
|
|
client.configPath,
|
|
JSON.stringify({
|
|
mcpServers: {
|
|
rea: {
|
|
transport,
|
|
...expectedRegistration(command),
|
|
},
|
|
},
|
|
}),
|
|
);
|
|
expect(
|
|
(
|
|
await readClientRegistrationStatuses(home, undefined, {
|
|
platform: HOST_PLATFORM.platform,
|
|
environment: {},
|
|
})
|
|
).find(({ client: name }) => name === "kimi"),
|
|
).toMatchObject({ state: "invalid", command: [] });
|
|
},
|
|
);
|
|
});
|
|
|
|
describe("Kimi Code timeout alignment", () => {
|
|
const kimiClient = async () => {
|
|
const home = await createTestTempDirectory("rea-kimi-timeout-");
|
|
const client = kimiPath(home, process.platform, {});
|
|
if (client?.markerPath === undefined)
|
|
throw new Error("missing Kimi Code client");
|
|
await mkdir(client.markerPath, { recursive: true });
|
|
return { home, client } as const;
|
|
};
|
|
|
|
it.each([
|
|
["startupTimeoutMs", 1, "aligned"],
|
|
["toolTimeoutMs", 1, "aligned"],
|
|
["startupTimeoutMs", undefined, "stale"],
|
|
["toolTimeoutMs", undefined, "stale"],
|
|
] as const)("reports %s timeout %j as %s", async (field, value, state) => {
|
|
const { home, client } = await kimiClient();
|
|
const registration = {
|
|
...expectedRegistration(command),
|
|
[field]: value,
|
|
};
|
|
await writeFile(
|
|
client.configPath,
|
|
JSON.stringify({ mcpServers: { rea: registration } }),
|
|
);
|
|
expect(
|
|
(
|
|
await readClientRegistrationStatuses(home, undefined, {
|
|
platform: HOST_PLATFORM.platform,
|
|
environment: {},
|
|
})
|
|
).find(({ client: name }) => name === "kimi"),
|
|
).toMatchObject({ state });
|
|
});
|
|
|
|
it("uses a direct installed REA command without requiring a package runner", async () => {
|
|
const { home, client } = await kimiClient();
|
|
const entry = join(home, "scripts", "rea.mjs");
|
|
const launcher = [process.execPath, entry, "mcp"];
|
|
expect(
|
|
(await configureClientConfiguration(client, {}, launcher)).status,
|
|
).toBe("configured");
|
|
expect(
|
|
(
|
|
await readClientRegistrationStatuses(home, entry, {
|
|
platform: HOST_PLATFORM.platform,
|
|
environment: {},
|
|
})
|
|
).find(({ client: name }) => name === "kimi"),
|
|
).toMatchObject({ state: "aligned", command: launcher });
|
|
});
|
|
|
|
it("leaves a foreign rea-key registration out of aligned state", async () => {
|
|
const { home, client } = await kimiClient();
|
|
await writeFile(
|
|
client.configPath,
|
|
JSON.stringify({
|
|
mcpServers: {
|
|
rea: {
|
|
...expectedRegistration(command),
|
|
command: "another-package",
|
|
args: ["mcp"],
|
|
},
|
|
},
|
|
}),
|
|
);
|
|
expect(
|
|
(
|
|
await readClientRegistrationStatuses(home, undefined, {
|
|
platform: HOST_PLATFORM.platform,
|
|
environment: {},
|
|
})
|
|
).find(({ client: name }) => name === "kimi"),
|
|
).toMatchObject({ state: "stale" });
|
|
});
|
|
});
|