- POST /approvals and PATCH /approvals/{id} require a console admin session
(EndpointDef auth:"session"); API keys incl. admin scope get 403, so an
organize.execute key can no longer approve its own plan (S1)
- tests for single-use approval checks: expired, revision/payload hash
mismatch, consumed, revoked, pending/rejected, plan mismatch; re-approve
after plan change succeeds once and cannot be replayed (S4)
- one redact key table in @umt/contracts shared by server logger and agent
redactForModel: rsskey, torrent_pass, authkey, downhash, c_secure_pass,
passkey variants, x-api-key, cookie headers, nested objects/arrays (S2)
- TMDB network errors: message and cause redacted via redactUrl (S3)
- web Agent ?mock=1 only in DEV builds or when pi.provider is fake (S7)
- EndpointDef auth annotations for /auth/*, asserted against
PUBLIC_AUTH_PATHS (S10); doc drift fixes (S11)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
42 lines
1.7 KiB
TypeScript
42 lines
1.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { agentMockAllowed, resolveAgentMock } from "./agent.ts";
|
|
|
|
class MemStore {
|
|
m = new Map<string, string>();
|
|
getItem(k: string) {
|
|
return this.m.get(k) ?? null;
|
|
}
|
|
setItem(k: string, v: string) {
|
|
this.m.set(k, v);
|
|
}
|
|
removeItem(k: string) {
|
|
this.m.delete(k);
|
|
}
|
|
}
|
|
|
|
// 验收 S7:生产构建里 ?mock=1 不得把演示数据当真实运行展示
|
|
describe("Agent 演示开关", () => {
|
|
it("只在开发构建或后端 provider=fake 时允许", () => {
|
|
expect(agentMockAllowed({ dev: true })).toBe(true);
|
|
expect(agentMockAllowed({ dev: false, provider: "fake" })).toBe(true);
|
|
expect(agentMockAllowed({ dev: false, provider: "anthropic" })).toBe(false);
|
|
expect(agentMockAllowed({ dev: false })).toBe(false);
|
|
});
|
|
|
|
it("生产 + 真实模型:?mock=1 与 VITE_AGENT_MOCK 都被忽略,并清掉记住的开关", () => {
|
|
const storage = new MemStore();
|
|
storage.setItem("umt-agent-mock", "1");
|
|
expect(resolveAgentMock({ allowed: false, envFlag: "1", search: "?mock=1", storage })).toBe(false);
|
|
expect(storage.getItem("umt-agent-mock")).toBeNull();
|
|
});
|
|
|
|
it("允许时:?mock=1 记住,?mock=0 退出,构建期开关直接打开", () => {
|
|
const storage = new MemStore();
|
|
expect(resolveAgentMock({ allowed: true, search: "?mock=1", storage })).toBe(true);
|
|
expect(resolveAgentMock({ allowed: true, search: "", storage })).toBe(true);
|
|
expect(resolveAgentMock({ allowed: true, search: "?mock=0", storage })).toBe(false);
|
|
expect(resolveAgentMock({ allowed: true, envFlag: "1", search: "", storage })).toBe(true);
|
|
expect(resolveAgentMock({ allowed: true, search: "?mock=1", storage: null })).toBe(true);
|
|
});
|
|
});
|