- Tool interface declares required permissions via requires field - scoped-context builds a least-privileged ToolContext per call - ToolAuditLogger appends each tool invocation to a Garnet stream - Operations CLI gains tool-audit:list and tool-audit:show commands - All onboarding and moderation tools annotated with explicit requires
108 lines
2.8 KiB
TypeScript
108 lines
2.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
formatReviewList,
|
|
formatReviewShow,
|
|
formatReviewStats,
|
|
formatToolAuditList,
|
|
formatToolAuditShow,
|
|
} from "./cli.js";
|
|
|
|
describe("operations review CLI formatters", () => {
|
|
it("formats review list rows as tab-separated output", () => {
|
|
expect(
|
|
formatReviewList([
|
|
{
|
|
chatroomId: "room-1",
|
|
id: "1-0",
|
|
queuedAt: "2026-05-18T00:00:00.000Z",
|
|
reason: "low-confidence",
|
|
requestId: "request-1",
|
|
target: "human-review",
|
|
userId: "user-1",
|
|
},
|
|
]),
|
|
).toContain("1-0\t2026-05-18T00:00:00.000Z\tlow-confidence");
|
|
});
|
|
|
|
it("formats packet details for show output", () => {
|
|
expect(
|
|
formatReviewShow(
|
|
{
|
|
chatroomId: "room-1",
|
|
id: "1-0",
|
|
packet: {
|
|
constraints: [],
|
|
currentState: {},
|
|
evidence: [
|
|
{
|
|
id: "e1",
|
|
kind: "message",
|
|
summary: "unclear message",
|
|
},
|
|
],
|
|
expectedOutputSchema: "text",
|
|
handoffReason: "low-confidence",
|
|
sourceChain: ["onboarding", "supervisor"],
|
|
summary: "needs review",
|
|
userGoal: "의도 확인",
|
|
},
|
|
queuedAt: "2026-05-18T00:00:00.000Z",
|
|
reason: "low-confidence",
|
|
requestId: "request-1",
|
|
target: "human-review",
|
|
userId: "user-1",
|
|
},
|
|
[
|
|
{
|
|
action: "manual-reply",
|
|
note: "handled",
|
|
resolvedAt: "2026-05-18T01:00:00.000Z",
|
|
resolvedBy: "operator@example.com",
|
|
},
|
|
],
|
|
),
|
|
).toContain("sourceChain: onboarding > supervisor");
|
|
});
|
|
|
|
it("formats aggregate stats", () => {
|
|
expect(
|
|
formatReviewStats({
|
|
averagePendingAgeMs: 60_000,
|
|
byReason: {
|
|
"low-confidence": {
|
|
pending: 1,
|
|
resolved: 2,
|
|
total: 3,
|
|
},
|
|
},
|
|
pending: 1,
|
|
resolved: 2,
|
|
topSourceChains: [{ chain: "onboarding>supervisor", count: 3 }],
|
|
total: 3,
|
|
}),
|
|
).toContain("low-confidence\ttotal=3\tpending=1\tresolved=2");
|
|
});
|
|
|
|
it("formats tool audit rows", () => {
|
|
const entry = {
|
|
argsHash: "abc123",
|
|
calledAt: "2026-05-18T00:00:00.000Z",
|
|
chatroomId: "room-1",
|
|
durationMs: 12,
|
|
id: "1-0",
|
|
ok: true,
|
|
resultSummary: "{\"ok\":true}",
|
|
skill: "onboarding",
|
|
toolName: "validate-nickname",
|
|
type: "tool-call" as const,
|
|
userId: "user-1",
|
|
};
|
|
|
|
expect(formatToolAuditList([entry])).toContain(
|
|
"1-0\t2026-05-18T00:00:00.000Z\tonboarding\tvalidate-nickname\tyes\t12",
|
|
);
|
|
expect(formatToolAuditShow(entry)).toContain("argsHash: abc123");
|
|
});
|
|
});
|