mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-01 17:24:48 +00:00
Rotation on every surface: desktop rotator, Rotation page + run queue, MCP tools (CLI 0.15.0) (#269)
- method "desktop": dashboard-only keys (OpenAI, ElevenLabs, Brave Search, Civitai, Cloudflare Global API Key roll, Anthropic/Claude OAuth report-only) rotated by an agent on a W3BS Agentic Desktop Layer host (--desktop / LOGICSRC_DESKTOP_HOST). Agent browser only, old key by its last 4 chars, DOM-to-file capture (wl-paste fallback), two-phase revoke after health, rollback deletes the new key, remote file shredded. needs-login and busy are waits, not failures. Roll needs --allow-roll plus a capture self-test. - app.logicsrc.com: /teams/:slug/rotation plan page + rotation run queue (migration 010), API routes; runner: rotate-keys --from-queue. - MCP: rotation_plan, rotation_set, rotate_keys (dry run default), rotation_runs. - docs/rotation.md: desktop rotators and every surface. Co-authored-by: Anthony Ettinger <anthony@profullstack.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
aec3e5f5fa
commit
87bbc50423
23 changed files with 2191 additions and 35 deletions
63
packages/logicsrc-mcp/src/rotation.test.ts
Normal file
63
packages/logicsrc-mcp/src/rotation.test.ts
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
||||
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
||||
import { createLogicSrcMcpServer } from "./server.js";
|
||||
|
||||
const text = (r: unknown) => ((r as { content: Array<{ text: string }> }).content[0]?.text ?? "");
|
||||
|
||||
async function connect(o: { cli?: string[][]; fetched?: Array<{ url: string; method: string; body: unknown }> } = {}) {
|
||||
const runCli = async (args: string[]) => {
|
||||
o.cli?.push(args);
|
||||
return { code: 0, stdout: JSON.stringify([{ key: "OPENAI_API_KEY", status: "would-rotate" }]), stderr: "Dry run. Apply with --approve." };
|
||||
};
|
||||
const fetchFn = (async (input: string | URL | Request, init?: RequestInit) => {
|
||||
o.fetched?.push({ url: String(input), method: init?.method ?? "GET", body: init?.body ? JSON.parse(String(init.body)) : undefined });
|
||||
return new Response(JSON.stringify({ ok: true }), { status: 200 });
|
||||
}) as typeof fetch;
|
||||
const [c, s] = InMemoryTransport.createLinkedPair();
|
||||
const server = createLogicSrcMcpServer({ apiKeys: { env: { LOGICSRC_API_KEY: "lsk_person" }, fetch: fetchFn }, rotation: { runCli } });
|
||||
const client = new Client({ name: "t", version: "0.1.0" });
|
||||
await server.connect(s);
|
||||
await client.connect(c);
|
||||
return { client, close: async () => { await client.close(); await server.close(); } };
|
||||
}
|
||||
|
||||
describe("rotation tools", () => {
|
||||
it("rotate_keys is a dry run by default and passes desktop/propagate through to the CLI", async () => {
|
||||
const cli: string[][] = [];
|
||||
const { client, close } = await connect({ cli });
|
||||
const names = (await client.listTools()).tools.map((t) => t.name);
|
||||
expect(names).toEqual(expect.arrayContaining(["rotation_plan", "rotation_set", "rotate_keys", "rotation_runs"]));
|
||||
const out = text(await client.callTool({ name: "rotate_keys", arguments: { team: "profullstack", keys: ["OPENAI_API_KEY"], desktop: "bonita", propagate: true } }));
|
||||
expect(out).toContain("would-rotate");
|
||||
expect(cli[0]).toEqual(["teams", "rotate-keys", "profullstack", "--key", "OPENAI_API_KEY", "--propagate", "--desktop", "bonita", "--format", "json"]);
|
||||
await client.callTool({ name: "rotate_keys", arguments: { team: "profullstack", project: "b1dz", env: "prod", approve: true } });
|
||||
expect(cli[1]).toEqual(["teams", "rotate-keys", "profullstack", "b1dz", "prod", "--approve", "--format", "json"]);
|
||||
await close();
|
||||
});
|
||||
|
||||
it("rejects shell-ish arguments", async () => {
|
||||
const cli: string[][] = [];
|
||||
const { client, close } = await connect({ cli });
|
||||
const r = await client.callTool({ name: "rotate_keys", arguments: { team: "profullstack", desktop: "bonita; rm -rf ~" } });
|
||||
expect((r as { isError?: boolean }).isError).toBe(true);
|
||||
expect(cli).toEqual([]);
|
||||
await close();
|
||||
});
|
||||
|
||||
it("rotation_plan and rotation_set go through the CLI; queue and server plan go to the API", async () => {
|
||||
const cli: string[][] = [];
|
||||
const fetched: Array<{ url: string; method: string; body: unknown }> = [];
|
||||
const { client, close } = await connect({ cli, fetched });
|
||||
await client.callTool({ name: "rotation_plan", arguments: { team: "profullstack", project: "b1dz" } });
|
||||
expect(cli[0]).toEqual(["teams", "rotation", "profullstack", "b1dz", "--format", "json"]);
|
||||
await client.callTool({ name: "rotation_set", arguments: { team: "profullstack", project: "b1dz", env: "prod", key: "OPENAI_API_KEY", spec: { method: "desktop", recipe: "openai" } } });
|
||||
expect(cli[1]).toEqual(["teams", "rotation-set", "profullstack", "b1dz", "prod", "OPENAI_API_KEY", "--json", '{"method":"desktop","recipe":"openai"}', "--output", "json"]);
|
||||
await client.callTool({ name: "rotation_plan", arguments: { team: "profullstack", source: "server", keys: ["A"] } });
|
||||
expect(fetched[0]!.url).toBe("https://app.logicsrc.com/api/credshare/teams/profullstack/rotation?key=A");
|
||||
await client.callTool({ name: "rotate_keys", arguments: { team: "profullstack", keys: ["OPENAI_API_KEY"], queue: true, desktop: "bonita" } });
|
||||
expect(fetched[1]).toMatchObject({ method: "POST", url: "https://app.logicsrc.com/api/credshare/teams/profullstack/rotation/runs", body: { keys: ["OPENAI_API_KEY"], approve: false, desktop: "bonita" } });
|
||||
expect(cli.length).toBe(2);
|
||||
await close();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue