mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-23 21:24:45 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - A responsibility shows the skills of the agents doing its work. People cannot say which skills a responsibility needs. > - The maintainer chose to file skills under responsibilities like projects, tasks and routines. > - Agents also need to set a skill's catalog details without rewriting its SKILL.md. > - This pull request lets people and agents file, move and remove company skills under a responsibility, and adds `update_skill_details`. > - The benefit is that a responsibility lists the skills it needs, beside the skills its agents already hold. ## Linked Issues or Issue Description Refs #22253, #22261 and #22274; this pull request is stacked on them. **Subsystem affected** Database (`responsibility_links`), shared types and validators, server responsibility service and routes, Dashboard versions, native runner tools, and the responsibility page UI. **Problem or motivation** Skills under a responsibility are only computed from the agents doing its work. A person cannot record that "Hiring needs interviewing", and an agent cannot file a skill when it maps work for a person. **Proposed solution** Add a nullable `skill_id` to `responsibility_links` and allow it as the one target of a link. Show filed and computed skills together. Let the file, unfile, lookup and link routes and tools take skills. Keep filed skills in Dashboard versions so undo covers them. Add a small live tool for a skill's tagline and categories. **Alternatives considered** Keeping skills computed only, and giving the skill to the agent that runs the responsibility, was the other option. It was not chosen. Extending `update_skill` would change its scenario contract, whose mock needs `markdown`, so the details tool is separate. ## What Changed - Review fixes: the default responsibility view's Skills "+" adds an existing skill, removes a filed one, or opens an agent's skills page. A newest Dashboard version without a skill list is upgraded in place, so the first skill filed after it is undone. Undo files again, or removes, only skills the restoring person can see. A read scope without a skill condition sees no filed skill. `update_skill_details` with only `skillId` is a no-op, as its schema allows. - Migration `0499`: add `responsibility_links.skill_id` (FK to `company_skills`, on delete cascade). Widen the single-target check to four targets. Add a unique `(responsibility_id, skill_id)` index and a `skill_id` index. The migration is idempotent and online-compatible (NOT VALID then VALIDATE, and the indexes are built CONCURRENTLY). It is listed in `MIGRATIONS_WITH_TOP_LEVEL_STATEMENTS`. - Shared: `ResponsibilityLink.skillId`; `ResponsibilitySkillSummary.linkId` and `computed`; `skillId` in the link and lookup schemas; `skill` in `RESPONSIBILITY_FILE_ITEM_KINDS`; optional `skillIds` in Dashboard snapshot links. - Server: filing checks the reader's skill visibility (`skillAccessService`). The detail merges filed and computed skills into one card each. Lookup accepts `skillId`. Dashboard capture, restore and summary include filed skills. A version without `skillIds` leaves filed skills as they are when it is restored. - Tools: `file_under_responsibility`, `remove_from_responsibility` and `find_responsibilities_for` accept `kind: "skill"`. `get_responsibility` returns `linkId` and `computed` for each skill. Add `update_skill_details` (tagline and categories). - UI: the responsibility page has "Add existing skill". A filed skill shows "Filed here" and a remove button. Computed skills keep their holders. ## Verification - Server: the `responsibilit*` tests (new: file, find, move and unfile a skill; one card for a skill that is both filed and computed; undo of a filed skill from the Dashboard history), `skill-tools.test.ts` (new `update_skill_details` cases), `responsibility-tools`, `routine-tools`, `routines-routes`, `paperclip-runner-tool-authority`, `runner-api` and `openapi-routes`: 24 files, 2723 tests passed. - UI: responsibility page and component tests (16 files, 158 tests, including a new filed-skill test) pass. `pnpm --filter @paperclipai/ui typecheck` passed. - `@paperclipai/db` `check:migrations` passes and reports the override. The snapshot drift test passes. `tsc` passes for `db`, `shared` and the server layers. - Runner: catalog and semantic-tool tests (317) pass. All generator checks pass. ## Risks - The migration changes a check constraint on `responsibility_links`. The replacement accepts every row that the old check accepted. It is swapped as NOT VALID and then validated. The previous release never sets `skill_id`. - Deleting a company skill removes its links (cascade). - Filed skills follow the reader's skill visibility. A skill the reader may not see is not listed. ## Model Used Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use and code execution. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Paperclip <noreply@paperclip.ing>
405 lines
19 KiB
TypeScript
405 lines
19 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import type { CapabilityFixtureSeed } from "../mock-core/capability-control-plane-types.js";
|
|
import { CapabilityMockControlPlaneAdapter } from "../mock-core/capability-mock-control-plane-adapter.js";
|
|
import { CAPABILITY_SEMANTIC_TOOL_CATALOG } from "./catalog.js";
|
|
import { CAPABILITY_DISCOVERY_GATEWAY_DEFINITIONS } from "./discovery.js";
|
|
import { CapabilitySemanticDispatcher } from "./dispatcher.js";
|
|
import { createCapabilityProviderNeutralBinding } from "./provider-neutral.js";
|
|
|
|
const OPEN = {
|
|
identity: {
|
|
runId: "run-semantic-1",
|
|
sessionId: "session-semantic-1",
|
|
companyId: "company-1",
|
|
issueId: "task-1",
|
|
agentId: "actor-1",
|
|
},
|
|
backendKind: "mock" as const,
|
|
sourceInstanceId: "semantic-test",
|
|
};
|
|
|
|
async function running(
|
|
claims: string[] = [],
|
|
seed: CapabilityFixtureSeed = {},
|
|
) {
|
|
const adapter = new CapabilityMockControlPlaneAdapter({
|
|
...seed,
|
|
actors: seed.actors ?? [
|
|
{
|
|
id: "actor-1",
|
|
companyId: "company-1",
|
|
name: "Semantic Engineer",
|
|
role: "engineer",
|
|
status: "active",
|
|
budgetId: "budget-actor-1",
|
|
capabilityGrants: claims,
|
|
},
|
|
],
|
|
});
|
|
await adapter.start();
|
|
await adapter.openFixtureRun({ ...OPEN, capabilities: claims });
|
|
return adapter;
|
|
}
|
|
|
|
describe("Capability semantic catalog and authorization", () => {
|
|
it("updates an existing skill once, rejects a stale version, and denies an ungranted capability", async () => {
|
|
const adapter = await running();
|
|
const dispatcher = new CapabilitySemanticDispatcher(adapter);
|
|
const markdown = "---\nname: release-review\ndescription: Review release notes.\n---\n# Review\nCheck each note.";
|
|
const created = await dispatcher.dispatch({ runId: OPEN.identity.runId, callId: "create", operationId: "create_skill",
|
|
input: { name: "release-review", description: "Review release notes.", markdown, idempotencyKey: "create" } });
|
|
expect(created.ok).toBe(true);
|
|
if (!created.ok) return;
|
|
const args = { skillId: (created.result as { id: string }).id, expectedVersionId: (created.result as { versionId: string }).versionId,
|
|
markdown: markdown + " Inspect tests.", idempotencyKey: "update-once" };
|
|
const call = { runId: OPEN.identity.runId, callId: "update", operationId: "update_skill" as const, input: args };
|
|
const first = await dispatcher.dispatch(call);
|
|
expect(first).toMatchObject({ ok: true, result: { skillId: args.skillId, path: "SKILL.md", versionId: expect.any(String) } });
|
|
expect(await dispatcher.dispatch({ ...call, callId: "retry" })).toMatchObject({ ok: true, result: first.ok ? first.result : {} });
|
|
expect(await dispatcher.dispatch({ ...call, callId: "stale", input: { ...args, idempotencyKey: "next" } })).toMatchObject({ ok: false });
|
|
const denied = new CapabilitySemanticDispatcher(adapter, { scenario: { id: "no-update", claims: [], denyOperations: ["update_skill"] } });
|
|
expect(await denied.dispatch({ ...call, callId: "denied", input: { ...args, idempotencyKey: "denied" } })).toMatchObject({ ok: false, denial: { code: "scenario_denied" } });
|
|
});
|
|
|
|
it("creates a durable skill once and returns its reference on retry", async () => {
|
|
const adapter = await running();
|
|
const dispatcher = new CapabilitySemanticDispatcher(adapter);
|
|
const input = { name: "release-review", description: "Review release notes.",
|
|
markdown: "---\nname: release-review\ndescription: Review release notes.\n---\n# Review\nCheck each note.", idempotencyKey: "create-skill-once" };
|
|
const call = { runId: OPEN.identity.runId, callId: "skill-1", operationId: "create_skill" as const, input };
|
|
const first = await dispatcher.dispatch(call);
|
|
expect(first).toMatchObject({ ok: true, result: { name: input.name, slug: input.name, versionId: expect.any(String) } });
|
|
expect(await dispatcher.dispatch({ ...call, callId: "skill-retry" })).toMatchObject({ ok: true, result: first.ok ? first.result : {} });
|
|
expect(adapter.snapshot().skills).toEqual([expect.objectContaining({ markdown: input.markdown })]);
|
|
expect(await dispatcher.dispatch({ ...call, callId: "skill-conflict", input: { ...input, markdown: input.markdown + " changed" } })).toMatchObject({ ok: false });
|
|
expect(adapter.snapshot().skills).toHaveLength(1);
|
|
});
|
|
|
|
it.each([
|
|
["missing frontmatter", "# Review\nCheck each note."],
|
|
["mismatched frontmatter name", "---\nname: other-skill\ndescription: Review release notes.\n---\n# Review\nCheck each note."],
|
|
["mismatched frontmatter description", "---\nname: release-review\ndescription: Other description.\n---\n# Review\nCheck each note."],
|
|
["empty body", "---\nname: release-review\ndescription: Review release notes.\n---\n "],
|
|
["invalid YAML", "---\nname: [\ndescription: Review release notes.\n---\n# Review\nCheck each note."],
|
|
["slug conflict", "---\nname: release-review\ndescription: Review release notes.\n---\n# Review\nCheck each note."],
|
|
])("rejects %s without mutating the skill library", async (label, markdown) => {
|
|
const adapter = await running();
|
|
const dispatcher = new CapabilitySemanticDispatcher(adapter);
|
|
const input = {
|
|
name: label === "mismatched frontmatter name" ? "release-review" : "release-review",
|
|
slug: label === "slug conflict" ? "other-slug" : undefined,
|
|
description: "Review release notes.", markdown, idempotencyKey: `invalid-${label}`,
|
|
};
|
|
const result = await dispatcher.dispatch({ runId: OPEN.identity.runId, callId: `invalid-${label}`, operationId: "create_skill", input });
|
|
expect(result).toMatchObject({ ok: false });
|
|
expect(adapter.snapshot().skills ?? []).toHaveLength(0);
|
|
});
|
|
|
|
it("denies skill creation when the scenario policy forbids it", async () => {
|
|
const adapter = await running();
|
|
const dispatcher = new CapabilitySemanticDispatcher(adapter, { scenario: { id: "restricted-skills", claims: [], denyOperations: ["create_skill"] } });
|
|
expect(await dispatcher.dispatch({ runId: OPEN.identity.runId, callId: "denied-skill", operationId: "create_skill", input: { name: "no-create", description: "Denied", markdown: "Denied", idempotencyKey: "deny" } })).toMatchObject({ ok: false, denial: { code: "scenario_denied" } });
|
|
expect(adapter.snapshot().skills ?? []).toHaveLength(0);
|
|
});
|
|
|
|
it("accepts the conventional ten-result capability discovery limit", () => {
|
|
expect(
|
|
CAPABILITY_DISCOVERY_GATEWAY_DEFINITIONS[0].inputSchema.properties.limit
|
|
.maximum,
|
|
).toBe(10);
|
|
});
|
|
|
|
it("publishes a stable narrow catalog without credentials or control-plane-owned tools", () => {
|
|
const names = CAPABILITY_SEMANTIC_TOOL_CATALOG.map((tool) => tool.operationId);
|
|
expect(new Set(names).size).toBe(names.length);
|
|
expect(names).toHaveLength(72);
|
|
expect(names).toContain("send_chat_message");
|
|
expect(names).toEqual(expect.arrayContaining(["list_workflows", "read_workflow", "create_workflow", "update_workflow"]));
|
|
expect(names).toContain("set_task_monitor");
|
|
expect(names).toEqual(expect.arrayContaining(["submit_complaint", "submit_suggestion"]));
|
|
expect(names).toContain("get_task_context");
|
|
expect(names).toContain("finish_task");
|
|
expect(names).not.toContain("checkout_task");
|
|
expect(names).not.toContain("record_budget_usage");
|
|
expect(names).not.toContain("resolve_human_input");
|
|
expect(CAPABILITY_SEMANTIC_TOOL_CATALOG.find((tool) => tool.operationId === "generic_api_request"))
|
|
.toMatchObject({ exposure: "optional", disabledByDefault: true });
|
|
const schemaKeys = CAPABILITY_SEMANTIC_TOOL_CATALOG.flatMap((tool) =>
|
|
Object.keys(tool.inputSchema.properties ?? {}),
|
|
);
|
|
expect(schemaKeys.join(" ")).not.toMatch(
|
|
/authorization|password|credential|api.?key|access.?token|secret/i,
|
|
);
|
|
});
|
|
|
|
it("exposes always tools while optional tools require actor, scenario, and explicit run claims", async () => {
|
|
const adapter = await running();
|
|
const dispatcher = new CapabilitySemanticDispatcher(adapter);
|
|
const names = dispatcher.listTools(OPEN.identity.runId).map((tool) => tool.name);
|
|
expect(names).toContain("get_task_context");
|
|
expect(names).toContain("report_progress");
|
|
expect(names).not.toContain("set_dependencies");
|
|
expect(names).not.toContain("generic_api_request");
|
|
|
|
const before = adapter.snapshot().revision;
|
|
const denied = await dispatcher.dispatch({
|
|
runId: OPEN.identity.runId,
|
|
callId: "denied-dependencies",
|
|
operationId: "set_dependencies",
|
|
input: { idempotencyKey: "deps-1", blockedByTaskIds: [] },
|
|
});
|
|
expect(denied).toMatchObject({
|
|
ok: false,
|
|
denial: { code: "required_claim_missing", retryable: false },
|
|
});
|
|
expect(adapter.snapshot().revision).toBe(before);
|
|
});
|
|
|
|
it("discovers only authorized optional tools and returns trusted schemas", async () => {
|
|
const claims = ["discovery:agents:read", "governance:approvals:read"];
|
|
const adapter = await running(claims);
|
|
const dispatcher = new CapabilitySemanticDispatcher(adapter, {
|
|
scenario: { id: "lazy-search", claims }, explicitClaims: claims,
|
|
});
|
|
const found = dispatcher.discoverTools(OPEN.identity.runId, "find company agents", { namespace: "discovery" });
|
|
expect(found.operations.map((tool) => tool.name)).toEqual(["list_agents", "get_agent"]);
|
|
expect(found.operations.every((tool) => tool.annotations.semanticContract === "paperclip.semantic-tool.v1")).toBe(true);
|
|
expect(JSON.stringify(found)).not.toContain("list_approvals");
|
|
});
|
|
|
|
it("supports unnamespaced discovery and finds both feedback tools", async () => {
|
|
const claims = ["discovery:agents:read"];
|
|
const adapter = await running(claims);
|
|
const dispatcher = new CapabilitySemanticDispatcher(adapter, {
|
|
scenario: { id: "feedback-discovery", claims }, explicitClaims: claims,
|
|
});
|
|
const agents = dispatcher.discoverTools(OPEN.identity.runId, "find company agents");
|
|
expect(agents.operations.map((tool) => tool.name)).toEqual(expect.arrayContaining(["list_agents", "get_agent"]));
|
|
for (const options of [{}, { namespace: "feedback" }]) {
|
|
const feedback = dispatcher.discoverTools(OPEN.identity.runId, "feedback", options);
|
|
expect(feedback.operations.map((tool) => tool.name)).toEqual(["submit_complaint", "submit_suggestion"]);
|
|
}
|
|
});
|
|
|
|
it("does not disclose optional tools that current authority cannot invoke", async () => {
|
|
const adapter = await running();
|
|
const dispatcher = new CapabilitySemanticDispatcher(adapter);
|
|
const found = dispatcher.discoverTools(OPEN.identity.runId, "create child task approval secret admin", { namespace: "delegation" });
|
|
expect(found.operations).toEqual([]);
|
|
expect(JSON.stringify(found.operations)).not.toMatch(/create_task|approval|secret|administer_company/);
|
|
const before = adapter.snapshot().revision;
|
|
for (const operationId of ["create_project", "list_project_repositories", "list_projects", "get_workspace", "list_workspaces", "select_workspace", "prepare_repository", "handoff_case", "create_case", "read_case", "update_case"] as const) {
|
|
expect(dispatcher.listTools(OPEN.identity.runId).map((tool) => tool.name)).not.toContain(operationId);
|
|
expect(await dispatcher.dispatch({
|
|
runId: OPEN.identity.runId, callId: `unbound-${operationId}`, operationId,
|
|
input: operationId === "create_project" ? { name: "Unbound", idempotencyKey: "unbound-project" } : {},
|
|
})).toMatchObject({ ok: false, denial: { code: "scenario_denied" } });
|
|
}
|
|
expect(adapter.snapshot().revision).toBe(before);
|
|
});
|
|
|
|
it("executes a granted optional operation through the mock port", async () => {
|
|
const claim = "dependencies:write";
|
|
const adapter = await running([claim], {
|
|
tasks: [
|
|
{
|
|
id: "task-1",
|
|
companyId: "company-1",
|
|
identifier: "MCK-1",
|
|
title: "Active task",
|
|
description: null,
|
|
status: "todo",
|
|
priority: "medium",
|
|
workMode: "standard",
|
|
parentId: null,
|
|
assigneeActorId: "actor-1",
|
|
checkoutRunId: null,
|
|
executionRunId: null,
|
|
startedAt: null,
|
|
completedAt: null,
|
|
},
|
|
{
|
|
id: "task-2",
|
|
companyId: "company-1",
|
|
identifier: "MCK-2",
|
|
title: "Blocking task",
|
|
description: null,
|
|
status: "todo",
|
|
priority: "high",
|
|
workMode: "standard",
|
|
parentId: null,
|
|
assigneeActorId: null,
|
|
checkoutRunId: null,
|
|
executionRunId: null,
|
|
startedAt: null,
|
|
completedAt: null,
|
|
},
|
|
],
|
|
});
|
|
const dispatcher = new CapabilitySemanticDispatcher(adapter, {
|
|
scenario: { id: "dependency-manager", claims: [claim] },
|
|
explicitClaims: [claim],
|
|
});
|
|
expect(dispatcher.listTools(OPEN.identity.runId).map((tool) => tool.name))
|
|
.toContain("set_dependencies");
|
|
const result = await dispatcher.dispatch({
|
|
runId: OPEN.identity.runId,
|
|
callId: "set-dependencies",
|
|
operationId: "set_dependencies",
|
|
input: { idempotencyKey: "deps-1", blockedByTaskIds: ["task-2"] },
|
|
});
|
|
expect(result).toMatchObject({ ok: true, result: { disposition: "applied" } });
|
|
expect(adapter.snapshot().blockers).toEqual([
|
|
expect.objectContaining({ taskId: "task-1", blockedByTaskId: "task-2" }),
|
|
]);
|
|
});
|
|
|
|
it("rechecks policy immediately before every operation", async () => {
|
|
const claim = "dependencies:write";
|
|
const adapter = await running([claim]);
|
|
let exposeClaim = true;
|
|
const port = {
|
|
snapshot: () => adapter.snapshot(),
|
|
tryApplyCommand: adapter.tryApplyCommand.bind(adapter),
|
|
context: (runId: string) => {
|
|
const context = structuredClone(adapter.context(runId));
|
|
context.capabilities = exposeClaim ? [claim] : [];
|
|
return context;
|
|
},
|
|
};
|
|
const dispatcher = new CapabilitySemanticDispatcher(port, {
|
|
scenario: { id: "revocation", claims: [claim] },
|
|
explicitClaims: [claim],
|
|
});
|
|
expect(dispatcher.listTools(OPEN.identity.runId).map((tool) => tool.name))
|
|
.toContain("set_dependencies");
|
|
exposeClaim = false;
|
|
const before = adapter.snapshot().revision;
|
|
const result = await dispatcher.dispatch({
|
|
runId: OPEN.identity.runId,
|
|
callId: "revoked-call",
|
|
operationId: "set_dependencies",
|
|
input: { idempotencyKey: "revoked-1", blockedByTaskIds: [] },
|
|
});
|
|
expect(result).toMatchObject({ ok: false, denial: { code: "required_claim_missing" } });
|
|
expect(adapter.snapshot().revision).toBe(before);
|
|
});
|
|
|
|
it("returns typed denials for absent, mode-denied, and generic escape-hatch tools", async () => {
|
|
const adapter = await running([], {
|
|
tasks: [{
|
|
id: "task-1",
|
|
companyId: "company-1",
|
|
identifier: "MCK-1",
|
|
title: "Ask-only task",
|
|
description: null,
|
|
status: "todo",
|
|
priority: "medium",
|
|
workMode: "ask",
|
|
parentId: null,
|
|
assigneeActorId: "actor-1",
|
|
checkoutRunId: null,
|
|
executionRunId: null,
|
|
startedAt: null,
|
|
completedAt: null,
|
|
}],
|
|
});
|
|
const dispatcher = new CapabilitySemanticDispatcher(adapter);
|
|
const names = dispatcher.listTools(OPEN.identity.runId).map((tool) => tool.name);
|
|
expect(names).not.toContain("write_document");
|
|
expect(names).not.toContain("finish_task");
|
|
await expect(dispatcher.dispatch({
|
|
runId: OPEN.identity.runId,
|
|
callId: "unknown",
|
|
operationId: "paperclipApiRequest",
|
|
input: {},
|
|
})).resolves.toMatchObject({ ok: false, denial: { code: "tool_not_exposed" } });
|
|
await expect(dispatcher.dispatch({
|
|
runId: OPEN.identity.runId,
|
|
callId: "mode-denied",
|
|
operationId: "write_document",
|
|
input: {},
|
|
})).resolves.toMatchObject({ ok: false, denial: { code: "task_mode_denied" } });
|
|
});
|
|
|
|
it("preserves credential payloads for execution while redacting authorization records", async () => {
|
|
const claim = "governance:approvals:request";
|
|
const adapter = await running([claim]);
|
|
const dispatcher = new CapabilitySemanticDispatcher(adapter, {
|
|
scenario: { id: "approval", claims: [claim] },
|
|
explicitClaims: [claim],
|
|
});
|
|
const secret = "Bearer secret-value-123456";
|
|
const before = adapter.snapshot().revision;
|
|
const result = await dispatcher.dispatch({
|
|
runId: OPEN.identity.runId,
|
|
callId: "protected-approval",
|
|
operationId: "request_approval",
|
|
input: {
|
|
idempotencyKey: "approval-secret",
|
|
approvalType: "request_board_approval",
|
|
payload: { authorization: secret },
|
|
},
|
|
});
|
|
expect(result).toMatchObject({ ok: true });
|
|
expect(adapter.snapshot().revision).toBeGreaterThan(before);
|
|
expect(adapter.snapshot().approvals).toEqual([expect.objectContaining({ payload: { authorization: secret } })]);
|
|
const serialized = JSON.stringify(dispatcher.authorizationRecords());
|
|
expect(serialized).not.toContain(secret);
|
|
expect(serialized).toContain("[REDACTED]");
|
|
});
|
|
|
|
it("redacts protected mock state from read results", async () => {
|
|
const secret = "Bearer mock-secret-123456";
|
|
const adapter = await running([], {
|
|
comments: [{
|
|
id: "comment-secret",
|
|
taskId: "task-1",
|
|
authorActorId: "actor-1",
|
|
body: `diagnostic ${secret}`,
|
|
createdAt: "2026-08-09T00:00:00.000Z",
|
|
}],
|
|
});
|
|
const dispatcher = new CapabilitySemanticDispatcher(adapter);
|
|
const result = await dispatcher.dispatch({
|
|
runId: OPEN.identity.runId,
|
|
callId: "history",
|
|
operationId: "get_task_history",
|
|
input: {},
|
|
});
|
|
expect(JSON.stringify(result)).not.toContain(secret);
|
|
expect(JSON.stringify(result)).toContain("[REDACTED]");
|
|
});
|
|
|
|
it("applies always-tool commands and records authorization for every invocation", async () => {
|
|
const adapter = await running();
|
|
const dispatcher = new CapabilitySemanticDispatcher(adapter);
|
|
const progress = await dispatcher.dispatch({
|
|
runId: OPEN.identity.runId,
|
|
callId: "progress",
|
|
operationId: "report_progress",
|
|
input: { idempotencyKey: "progress-1", body: "Semantic catalog is active." },
|
|
});
|
|
expect(progress).toMatchObject({ ok: true });
|
|
expect(JSON.stringify(progress)).not.toContain("commandKind");
|
|
expect(adapter.snapshot().comments).toEqual([
|
|
expect.objectContaining({ body: "Semantic catalog is active." }),
|
|
]);
|
|
const records = dispatcher.authorizationRecords().filter((record) => record.phase === "invocation");
|
|
expect(records).toHaveLength(1);
|
|
expect(records[0]).toMatchObject({ allowed: true, operationId: "report_progress", callId: "progress" });
|
|
});
|
|
|
|
it("keeps generated contracts identical across fake and live Codex bindings", () => {
|
|
const fake = createCapabilityProviderNeutralBinding("fake");
|
|
const live = createCapabilityProviderNeutralBinding("live_codex");
|
|
expect(fake.bindingKind).toBe("fake");
|
|
expect(live.bindingKind).toBe("live_codex");
|
|
expect(live.contracts).toEqual(fake.contracts);
|
|
expect(live.contracts.map((tool) => tool.name)).toEqual(
|
|
CAPABILITY_SEMANTIC_TOOL_CATALOG.map((tool) => tool.operationId),
|
|
);
|
|
});
|
|
});
|