feat(setup): verify installed skill catalog identity
This commit is contained in:
+33
-1
@@ -1,5 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { runDoctor, type DoctorHost } from "../src/application/Doctor.js";
|
||||
import { CATALOG_IDENTITY } from "../src/catalogIdentity.js";
|
||||
import { PRODUCT_IDENTITY } from "../src/identity.js";
|
||||
|
||||
const host = (overrides: Partial<DoctorHost> = {}): DoctorHost => ({
|
||||
platform: "darwin",
|
||||
@@ -12,6 +14,12 @@ const host = (overrides: Partial<DoctorHost> = {}): DoctorHost => ({
|
||||
linuxDemoRuntimeReady: () => Promise.resolve(true),
|
||||
brewHopperPath: () => Promise.resolve(undefined),
|
||||
manualHopperPaths: () => Promise.resolve([]),
|
||||
installedSkillIdentity: () =>
|
||||
Promise.resolve({
|
||||
version: PRODUCT_IDENTITY.skillVersion,
|
||||
toolCount: CATALOG_IDENTITY.counts.mcp_tools,
|
||||
catalogDigest: CATALOG_IDENTITY.digests.combined_sha256,
|
||||
}),
|
||||
...overrides,
|
||||
});
|
||||
|
||||
@@ -85,7 +93,12 @@ describe("doctor", () => {
|
||||
host({
|
||||
installationPaths: () =>
|
||||
Promise.resolve(["/usr/local/bin/rea", "/home/user/bin/rea"]),
|
||||
installedSkillVersion: () => Promise.resolve("10"),
|
||||
installedSkillIdentity: () =>
|
||||
Promise.resolve({
|
||||
version: "10",
|
||||
toolCount: null,
|
||||
catalogDigest: null,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -99,6 +112,25 @@ describe("doctor", () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
it("reports a missing installed skill as unhealthy", async () => {
|
||||
const result = await runDoctor(
|
||||
undefined,
|
||||
host({ installedSkillIdentity: () => Promise.resolve(undefined) }),
|
||||
);
|
||||
|
||||
expect(result.healthy).toBe(false);
|
||||
expect(result.identity?.skill).toMatchObject({
|
||||
state: "missing",
|
||||
remediation: "Run rea setup to update the installed REA skill.",
|
||||
});
|
||||
expect(result.checks).toContainEqual({
|
||||
name: "skill:identity",
|
||||
ok: false,
|
||||
classification: "config_drift",
|
||||
detail: "Installed REA skill identity is missing.",
|
||||
remediation: "Run rea setup to update the installed REA skill.",
|
||||
});
|
||||
});
|
||||
it("reports stale client registration paths without claiming live state", async () => {
|
||||
const result = await runDoctor(
|
||||
undefined,
|
||||
|
||||
@@ -7,6 +7,8 @@ import {
|
||||
type GhidraInstallationInspection,
|
||||
} from "../src/ghidra/GhidraInstallation.js";
|
||||
import { projectGhidraDoctorInspection } from "../src/ghidra/GhidraDoctor.js";
|
||||
import { CATALOG_IDENTITY } from "../src/catalogIdentity.js";
|
||||
import { PRODUCT_IDENTITY } from "../src/identity.js";
|
||||
|
||||
const INSTALL = "/opt/ghidra_12.1.2_PUBLIC";
|
||||
const installationHost = (
|
||||
@@ -65,6 +67,12 @@ const doctorHost = (
|
||||
manualHopperPaths: () => Promise.resolve([]),
|
||||
providerInspections: () =>
|
||||
Promise.resolve([projectGhidraDoctorInspection(ghidra)]),
|
||||
installedSkillIdentity: () =>
|
||||
Promise.resolve({
|
||||
version: PRODUCT_IDENTITY.skillVersion,
|
||||
toolCount: CATALOG_IDENTITY.counts.mcp_tools,
|
||||
catalogDigest: CATALOG_IDENTITY.digests.combined_sha256,
|
||||
}),
|
||||
});
|
||||
|
||||
describe("Ghidra doctor integration", () => {
|
||||
|
||||
@@ -14,7 +14,8 @@ describe("package identity", () => {
|
||||
scripts: z.object({
|
||||
start: z.string(),
|
||||
prepare: z.string(),
|
||||
prepack: z.string().optional(),
|
||||
prepack: z.string(),
|
||||
prepublishOnly: z.string(),
|
||||
}),
|
||||
})
|
||||
.parse(
|
||||
@@ -30,6 +31,11 @@ describe("package identity", () => {
|
||||
expect(PRODUCT_IDENTITY.mcpCommand).toBe(`npx -y ${packageJson.name} mcp`);
|
||||
expect(packageJson.scripts.start).toBe("node scripts/rea.mjs mcp");
|
||||
expect(packageJson.scripts.prepare).toBe("npm run build && husky");
|
||||
expect(packageJson.scripts.prepack).toBeUndefined();
|
||||
expect(packageJson.scripts.prepack).toBe(
|
||||
"npm run deps:check && node scripts/generate-skill-metadata.mjs --check",
|
||||
);
|
||||
expect(packageJson.scripts.prepublishOnly).toBe(
|
||||
"npm run deps:check && node scripts/generate-skill-metadata.mjs --check",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
ENHANCED_TOOL_CONTRACTS,
|
||||
OFFICIAL_TOOL_CONTRACTS,
|
||||
SESSION_TOOL_CONTRACTS,
|
||||
TOOL_CONTRACTS,
|
||||
} from "../src/contracts/toolContracts.js";
|
||||
import { NATIVE_TOOL_CONTRACTS } from "../src/contracts/nativeToolContracts.js";
|
||||
import { ARTIFACT_TOOL_CONTRACTS } from "../src/contracts/artifactToolContracts.js";
|
||||
@@ -39,30 +38,18 @@ const expectedToolCounts = [
|
||||
|
||||
const toolCountsFromReadme = (content: string, path: string): number[] => {
|
||||
const lines = content.split(/\r?\n/u);
|
||||
const headingIndex = lines.findIndex((line) =>
|
||||
new RegExp(`^## .*${String(TOOL_CONTRACTS.length)}`, "u").test(line),
|
||||
);
|
||||
if (headingIndex === -1)
|
||||
throw new Error(
|
||||
`Missing ${String(TOOL_CONTRACTS.length)}-tool heading in ${path}`,
|
||||
);
|
||||
|
||||
const counts: number[] = [];
|
||||
for (const line of lines.slice(headingIndex + 1)) {
|
||||
if (line.startsWith("## ")) break;
|
||||
if (!line.trim().startsWith("|") || /^\|\s*-/.test(line)) continue;
|
||||
const cells = line.split("|").map((cell) => cell.trim());
|
||||
const countCell = cells[2];
|
||||
if (countCell === undefined)
|
||||
throw new Error(`Malformed table row in ${path}`);
|
||||
const count = Number(countCell);
|
||||
if (!Number.isInteger(count)) {
|
||||
if (counts.length === 0) continue;
|
||||
throw new Error(`Non-numeric tool count in ${path}`);
|
||||
for (const [index, line] of lines.entries()) {
|
||||
if (!/^\|\s*-/u.test(line)) continue;
|
||||
const counts: number[] = [];
|
||||
for (const row of lines.slice(index + 1)) {
|
||||
if (!row.trim().startsWith("|")) break;
|
||||
const count = Number(row.split("|")[2]?.trim());
|
||||
if (!Number.isInteger(count)) break;
|
||||
counts.push(count);
|
||||
}
|
||||
counts.push(count);
|
||||
if (counts.length === expectedToolCounts.length) return counts;
|
||||
}
|
||||
return counts;
|
||||
throw new Error(`Missing tool-family inventory table in ${path}`);
|
||||
};
|
||||
|
||||
describe("localized README product facts", () => {
|
||||
@@ -87,7 +74,7 @@ describe("localized README product facts", () => {
|
||||
expect(content).toContain(client.displayName);
|
||||
if (path === "README_ar.md")
|
||||
expect(content).toContain("Windows غير مدعوم حاليًا");
|
||||
expect(content).toContain(`MCP_tools-${String(TOOL_CONTRACTS.length)}`);
|
||||
expect(content).toContain("MCP-tool_catalog");
|
||||
expect(toolCountsFromReadme(content, path)).toEqual(expectedToolCounts);
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user