- Capabilities: all 14 registered (AO: inventory.query, download.plan/submit, organize.plan/execute,
policy.preview/apply; agent: task.inspect/retry/cancel); startup asserts count == 14.
Registry injects server-side authorize (automation_grant by action/scope/policy version/budget,
one-shot approval bound to plan id + payload hash + revision + expiry; model claims ignored;
automation switch), audit_event, server idempotency keys and a capability_invocation op ledger
(migration 0021) used for crash reconciliation. download.plan creates draft plans only;
download.submit promotes draft -> reserved after authorization.
- Agent session API: POST/GET /agent/runs, GET /agent/runs/{id} (events by seq, messages, report),
POST .../messages (wake), POST .../abort; automation-grants, approvals, capabilities invoke, tasks.
- runAgent task: Pi or fake provider from settings (apiKey via secrets), events persisted to
agent_run_event then published, resume + ledger reconciliation when pendingOperations > 0,
waits for goal-linked downloads/imports and reports from business tables (submitted != imported).
- Background triggers: decision.created -> bounded plan_only investigation (dedupe per decision);
decision.updated(resolved) -> resolveDecision executes chosen option.
- W2 closure: all OpenAPI routes registered in contracts api.ts (+ subset test); TMDB key from
settings secret_ref with env fallback; PUT /sites/{id}/credentials documented as alias of
/site-accounts; completion events documented as existing status events.
- e2e (real PG + OpenWorkflow + testkit mocks): RSS->library, agent delegation with grant/deny,
background continuation, worker kill -9 recovery (single qB add), auto investigation dedupe.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
39 lines
1.8 KiB
TypeScript
39 lines
1.8 KiB
TypeScript
import { API_PREFIX, listEndpoints } from "@umt/contracts";
|
|
import { describe, expect, it } from "vitest";
|
|
import { createApp } from "../src/http/app.ts";
|
|
import { EventBus } from "../src/http/sse.ts";
|
|
import { SERVER_MODULES } from "../src/modules/index.ts";
|
|
import type { ServerContext } from "../src/modules/types.ts";
|
|
import { DEV_KEY, json, memoryLogger } from "./helpers.ts";
|
|
|
|
// OpenAPI 里出现的每条 /api/v1 路由都必须登记在 @umt/contracts 的 Api 注册表(web 与测试都从那里取路径/schema)。
|
|
|
|
describe("Api 注册表覆盖", () => {
|
|
it("OpenAPI 文档中的每条路由都在 listEndpoints() 里", async () => {
|
|
const app = createApp({
|
|
config: { NODE_ENV: "development", DEV_ADMIN_KEY: DEV_KEY },
|
|
logger: memoryLogger().logger,
|
|
bus: new EventBus(5),
|
|
role: "all",
|
|
version: "0.0.0-test",
|
|
modules: SERVER_MODULES,
|
|
ctx: { role: "all" } as unknown as ServerContext,
|
|
});
|
|
const res = await app.request("/api/openapi.json");
|
|
expect(res.status).toBe(200);
|
|
const doc = (await json(res)) as { paths: Record<string, Record<string, unknown>> };
|
|
|
|
const served: string[] = [];
|
|
for (const [path, ops] of Object.entries(doc.paths)) {
|
|
if (!path.startsWith(`${API_PREFIX}/`)) continue; // /api/openapi.json 等非业务路由
|
|
const rel = path.slice(API_PREFIX.length);
|
|
for (const method of Object.keys(ops)) served.push(`${method.toUpperCase()} ${rel}`);
|
|
}
|
|
expect(served.length).toBeGreaterThan(0);
|
|
|
|
const registered = new Set(listEndpoints().map((e) => `${e.method.toUpperCase()} ${e.path}`));
|
|
const missing = served.filter((k) => !registered.has(k)).sort();
|
|
expect(missing, `以下路由未登记到 packages/contracts/src/api.ts:\n${missing.join("\n")}`).toEqual([]);
|
|
});
|
|
});
|