mirror of
https://github.com/morluto/rea.git
synced 2026-11-17 04:04:25 +00:00
Run ordinary CLI commands through REA's registry, argv parser and result owner. Remove Incur, the second admission parse, SDK error middleware, output capture and redundant command traversal. Preserve explicit redaction, publication receipts, incremental output, terminal notice eligibility and drain ownership. Migrate fixtures to real registrations and retain the derived-source notices. Validation includes unchanged public parity goldens, public and lifecycle regressions, repaired fixture consumers, real TTY base comparisons, exports beyond the engine string limit, four schema catalogs and final static/docs checks. Native provider and optional validator coverage limits are in the PR. Fixes #11654. Fixes #10583. Refs #11682, #11476 and #10511. BREAKING CHANGE: Markdown argument diagnostics use REA's literal escaping, table widths and token counts. Flag-shaped unknown MCP subcommands honor the selected format. Completion --schema/--version routes use the canonical REA-owned hook rather than the retired SDK generator. Refresh affected literal snapshots and regenerate completion hooks with rea completions <shell>. Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
261 lines
8.0 KiB
TypeScript
261 lines
8.0 KiB
TypeScript
import { createCommandCli } from "../../support/cli/commandCli.js";
|
|
import { createCatalogIdentity } from "../../../src/contracts/catalog/catalogIdentity.js";
|
|
import { contractsForToolFamilies } from "../../../src/contracts/toolFamilies.js";
|
|
import { promptsForToolFamilies } from "../../../src/contracts/promptToolFamilyScope.js";
|
|
import { expect, it, vi } from "vitest";
|
|
import { runSessionStatus } from "../../../src/application/DirectAnalysisStatus.js";
|
|
import { registerUtilityCommands } from "../../../src/cli/utilityCommands.js";
|
|
import { parseConfig } from "../../../src/config/parseConfig.js";
|
|
import { isCliOperationFailure } from "../../../src/cliLogging.js";
|
|
import { ProviderCleanupError } from "../../../src/domain/providerCleanupError.js";
|
|
import { err, ok } from "../../../src/domain/result.js";
|
|
import { silentLogger } from "../../../src/logger.js";
|
|
import { createTestBinarySession } from "../../fixtures/binarySession.js";
|
|
import { observed } from "../../fixtures/analysisExecution.js";
|
|
|
|
const createStatusSession = () =>
|
|
createTestBinarySession(() => ({
|
|
close: async () => ok(null),
|
|
execute: async () => observed(null),
|
|
}));
|
|
|
|
it.each(["capabilities", "providers"])(
|
|
"reports failed %s finalization with the completed status",
|
|
async (command) => {
|
|
const session = createStatusSession();
|
|
const cleanup = new ProviderCleanupError(
|
|
"fixture",
|
|
["retained profile reader"],
|
|
{ reason: "profile reader close failed" },
|
|
{ remediationAction: "Retry the retained profile reader cleanup." },
|
|
);
|
|
const close = vi
|
|
.spyOn(session, "close")
|
|
.mockResolvedValueOnce(err(cleanup));
|
|
const cli = createCommandCli();
|
|
registerUtilityCommands(
|
|
cli,
|
|
silentLogger,
|
|
{},
|
|
{
|
|
runSessionStatus: () =>
|
|
runSessionStatus({
|
|
readConfiguration: () => parseConfig({}),
|
|
createBinarySession: () => session,
|
|
}),
|
|
runProviderAnalysis: async () => ({ ok: false, error: null }),
|
|
},
|
|
);
|
|
let stdout = "";
|
|
try {
|
|
await cli.serve([command, "--json"], {
|
|
env: {},
|
|
stdout: (text) => {
|
|
stdout += text;
|
|
},
|
|
exit: () => {},
|
|
});
|
|
const output: unknown = JSON.parse(stdout);
|
|
expect(output).toMatchObject({
|
|
code: "cleanup_incomplete",
|
|
remediation: { action: "Retry the retained profile reader cleanup." },
|
|
details: {
|
|
resources: ["retained profile reader"],
|
|
partial_observation: {
|
|
capabilities: expect.any(Array),
|
|
server_identity: expect.any(Object),
|
|
},
|
|
},
|
|
});
|
|
expect(isCliOperationFailure(output)).toBe(true);
|
|
expect(close).toHaveBeenCalledTimes(1);
|
|
} finally {
|
|
close.mockRestore();
|
|
await session.close();
|
|
}
|
|
},
|
|
);
|
|
|
|
it.each([false, true])(
|
|
"keeps status failure when final cleanup also fails: %s",
|
|
async (cleanupFails) => {
|
|
const session = createStatusSession();
|
|
const failure = new Error("status observation failed");
|
|
const cleanup = new ProviderCleanupError("fixture", ["reader"], {});
|
|
const status = vi.spyOn(session, "status").mockRejectedValueOnce(failure);
|
|
const close = vi
|
|
.spyOn(session, "close")
|
|
.mockResolvedValueOnce(cleanupFails ? err(cleanup) : ok(null));
|
|
try {
|
|
const result = runSessionStatus({
|
|
readConfiguration: () => parseConfig({}),
|
|
createBinarySession: () => session,
|
|
});
|
|
if (cleanupFails)
|
|
await expect(result).rejects.toMatchObject({
|
|
cause: failure,
|
|
errors: [failure, cleanup],
|
|
});
|
|
else await expect(result).rejects.toBe(failure);
|
|
expect(close).toHaveBeenCalledTimes(1);
|
|
} finally {
|
|
status.mockRestore();
|
|
close.mockRestore();
|
|
await session.close();
|
|
}
|
|
},
|
|
);
|
|
|
|
it.each(["capabilities", "providers"])(
|
|
"reports the configured family scope through %s",
|
|
async (command) => {
|
|
const session = createStatusSession();
|
|
const families = new Set(["session"]);
|
|
const expected = createCatalogIdentity({
|
|
contracts: contractsForToolFamilies(families),
|
|
promptContracts: promptsForToolFamilies(families),
|
|
outputSchemaProfile: "compact",
|
|
});
|
|
const cli = createCommandCli();
|
|
registerUtilityCommands(
|
|
cli,
|
|
silentLogger,
|
|
{},
|
|
{
|
|
runSessionStatus: () =>
|
|
runSessionStatus({
|
|
readConfiguration: () =>
|
|
parseConfig({
|
|
REA_MCP_TOOL_FAMILIES: " session,session ",
|
|
REA_MCP_OUTPUT_SCHEMA_PROFILE: "compact",
|
|
}),
|
|
createBinarySession: () => session,
|
|
}),
|
|
runProviderAnalysis: async () => ({ ok: false, error: null }),
|
|
},
|
|
);
|
|
let stdout = "";
|
|
await cli.serve([command, "--json"], {
|
|
env: {},
|
|
stdout: (text) => {
|
|
stdout += text;
|
|
},
|
|
exit: () => {},
|
|
});
|
|
expect(JSON.parse(stdout)).toMatchObject({
|
|
server_identity: { catalog: expected },
|
|
});
|
|
},
|
|
);
|
|
|
|
it.each(["capabilities", "providers"])(
|
|
"exposes each candidate's selection source and rejections through %s",
|
|
async (command) => {
|
|
const session = createStatusSession();
|
|
const status = vi.spyOn(session, "status").mockResolvedValueOnce({
|
|
open: false,
|
|
capabilities: [],
|
|
analysis_provider_binding: null,
|
|
analysis_provider_candidates: [
|
|
{
|
|
provider: { id: "fixture", name: "Fixture", version: "1" },
|
|
availability: {
|
|
status: "available",
|
|
code: null,
|
|
reason: null,
|
|
diagnostics: {},
|
|
},
|
|
target_support: {
|
|
status: "unknown",
|
|
code: null,
|
|
reason: "No target is open.",
|
|
diagnostics: {},
|
|
},
|
|
selected: true,
|
|
selection_source: "auto-single-candidate",
|
|
rejections: [],
|
|
capabilities: [],
|
|
},
|
|
{
|
|
provider: { id: "other", name: "Other", version: null },
|
|
availability: {
|
|
status: "unavailable",
|
|
code: "not_configured",
|
|
reason: "OTHER_HOME is not set.",
|
|
remediation: "Set OTHER_HOME.",
|
|
diagnostics: { checks: [] },
|
|
},
|
|
target_support: {
|
|
status: "unknown",
|
|
code: null,
|
|
reason: "No target is open.",
|
|
diagnostics: {},
|
|
},
|
|
selected: false,
|
|
selection_source: null,
|
|
rejections: [
|
|
{
|
|
provider_id: "other",
|
|
origin: "availability",
|
|
code: "not_configured",
|
|
reason: "OTHER_HOME is not set.",
|
|
remediation: "Set OTHER_HOME.",
|
|
diagnostics: { checks: [] },
|
|
},
|
|
],
|
|
capabilities: [],
|
|
},
|
|
],
|
|
});
|
|
const cli = createCommandCli();
|
|
registerUtilityCommands(
|
|
cli,
|
|
silentLogger,
|
|
{},
|
|
{
|
|
runSessionStatus: () =>
|
|
runSessionStatus({
|
|
readConfiguration: () => parseConfig({}),
|
|
createBinarySession: () => session,
|
|
}),
|
|
runProviderAnalysis: async () => ({ ok: false, error: null }),
|
|
},
|
|
);
|
|
let stdout = "";
|
|
try {
|
|
await cli.serve([command, "--json"], {
|
|
env: {},
|
|
stdout: (text) => {
|
|
stdout += text;
|
|
},
|
|
exit: () => {},
|
|
});
|
|
expect(JSON.parse(stdout)).toMatchObject({
|
|
analysis_provider_candidates: [
|
|
{
|
|
provider: { id: "fixture" },
|
|
selection_source: "auto-single-candidate",
|
|
rejections: [],
|
|
},
|
|
{
|
|
provider: { id: "other" },
|
|
selection_source: null,
|
|
rejections: [
|
|
{
|
|
provider_id: "other",
|
|
origin: "availability",
|
|
code: "not_configured",
|
|
reason: "OTHER_HOME is not set.",
|
|
remediation: "Set OTHER_HOME.",
|
|
},
|
|
],
|
|
},
|
|
],
|
|
});
|
|
} finally {
|
|
status.mockRestore();
|
|
await session.close();
|
|
}
|
|
},
|
|
);
|