Files
plugins/packages/agent-console/test/v1/store.test.ts
T
qingnian108 a431798fe1 agent-console 1.0.0: a page plugin that drives the local Agent CLIs (#535)
Adds Agent Console (@magpie-community/page-agent-console 1.0.0), a community page plugin that drives the Agent CLIs on this computer (Claude Code, Codex, ACP agents) through a local daemon on 127.0.0.1, with its source in packages/agent-console and a registry entry. Claude Code is the user's own `claude` CLI driven over stream-json (daemon/src/providers/claude/cli.ts); no Anthropic SDK is installed, bundled or in the branch's history. Cold install ~45 MB (node-pty ~26 MB), stated in the README and registry summary in en and zh.

By qingnian108 (#535).

What was run at 8e8f910 (mote, macOS, throwaway HOME, no real accounts):
- packages/agent-console: `npm ci --ignore-scripts --workspaces=false`; `node scripts/verify-build.mjs`: all five bundles byte-identical (daemon/dist/main.js 08c95aa3…, app/app.js 9a6911f3…); `vitest run`: 45 files, 254 passed, 17 skipped; `npm run check` clean.
- Real Claude Code 2.1.316 (npm @anthropic-ai/claude-code, sandbox HOME/CLAUDE_CONFIG_DIR, local fake Messages API): `AC_REAL_CLAUDE=… vitest run --config vitest.real.config.ts test/real/claude-cli.real.test.ts`: 4 of 4 (initialize lists 51 slash commands, streaming turn, Bash permission approved and denied, interrupt, --resume with set_model).
- Probe: the driver's exact argv with `--permission-mode bypassPermissions --allow-dangerously-skip-permissions`: the tool runs with no can_use_tool request.
- Repo root: `HOME=$(mktemp -d) bun test`: 4006 tests, 0 fail; `bun scripts/check.mjs` exit 0.
- Install as magpie does: `npm pack --ignore-scripts` (552 KB) then `bun add --ignore-scripts`: 45 MB node_modules, no @anthropic-ai/*, index.mjs imports.
- Read every changed line since 41c7a94: argv values limited to SAFE_ARG tokens (no cmd.exe metacharacters reach the shim path), no new network hosts, no install scripts, no eval; no commit in main..8e8f910 contains claude-agent-sdk.

Not tried: magpie's desktop window loading the page; a Windows .cmd/.ps1 claude shim end to end.
2026-10-31 20:11:22 +08:00

66 lines
2.5 KiB
TypeScript

// store basics: atomic writes, corrupt JSONL lines skipped, attachment save/load
import { describe, it, expect } from "vitest";
import { mkdtempSync, writeFileSync, readFileSync, rmSync, existsSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { writeJsonAtomic } from "../../daemon/src/util/atomic.js";
import { readJsonl, appendJsonl } from "../../daemon/src/util/jsonl.js";
import { AttachmentStore } from "../../daemon/src/store/attachments.js";
import { validId, isInside } from "../../daemon/src/util/paths.js";
function tmp(): string {
return mkdtempSync(join(tmpdir(), "ac-store-"));
}
describe("util", () => {
it("writeJsonAtomic writes and reads back", async () => {
const d = tmp();
const f = join(d, "a.json");
await writeJsonAtomic(f, { x: 1 });
expect(JSON.parse(readFileSync(f, "utf8")).x).toBe(1);
rmSync(d, { recursive: true, force: true });
});
it("jsonl append + corrupt lines skipped", async () => {
const d = tmp();
const f = join(d, "e.jsonl");
await appendJsonl(f, { a: 1 });
await appendJsonl(f, { b: 2 });
writeFileSync(f, readFileSync(f, "utf8") + "not-json{{{\n" + JSON.stringify({ c: 3 }) + "\n");
const rows = await readJsonl<{ a?: number; b?: number; c?: number }>(f);
expect(rows.length).toBe(3);
expect(rows[2].c).toBe(3);
rmSync(d, { recursive: true, force: true });
});
it("concurrent jsonl appends keep order and lose nothing", async () => {
const d = tmp();
const f = join(d, "c.jsonl");
await Promise.all(Array.from({ length: 30 }, (_, i) => appendJsonl(f, { i })));
const rows = await readJsonl<{ i: number }>(f);
expect(rows.length).toBe(30);
rmSync(d, { recursive: true, force: true });
});
it("validId / isInside", () => {
expect(validId("t_abc-123")).toBe(true);
expect(validId("../evil")).toBe(false);
expect(validId("a".repeat(81))).toBe(false);
expect(isInside(join("a", "b", "c.txt"), join("a", "b"))).toBe(true);
expect(isInside(join("a", "x.txt"), join("a", "b"))).toBe(false);
});
});
describe("attachments", () => {
it("save/read/invalid id", async () => {
const d = tmp();
const s = new AttachmentStore(join(d, "att"));
const a = await s.save("pic.png", Buffer.from([1, 2, 3]));
expect(a.id).toMatch(/^a_/);
expect(existsSync(a.path)).toBe(true);
expect((await s.get(a.id))?.size).toBe(3);
expect(await s.get("../etc")).toBeNull();
rmSync(d, { recursive: true, force: true });
});
});