- root deno.json workspace (nodeModulesDir auto), npm versions registered once in imports, deno.lock; remove pnpm-lock/pnpm-workspace/root package.json; members keep minimal package.json (name/type/exports) - tasks: dev, typecheck (tsc 7.0.2 per member + deno check), lint/fmt (biome, useImportExtensions), test (vitest via deno), check:tokens, build (web + deno compile), ci, db:migrate/reset, gen:types - tsconfig base moved to config/ (no root tsconfig.json); deno types -> types/deno.d.ts; web drops baseUrl - server: Deno.serve entry with graceful shutdown, --role migrate|preflight|probe, WEB_ROOT static SPA hosting; drop @hono/node-server, tsx, esbuild build.mjs - logger: redact child() bindings and serialize err by message/stack; sync stdout destination; tests - relative imports get explicit extensions (sites/mp-sync paths left for follow-up) - crash-recovery tests spawn `deno run -A`; tasks tests use unique per-file schemas - single-container Dockerfile + entrypoint (migrate -> preflight -> api+worker watchdog), docker-compose.yml - docs: README, runbook, ADR-001 superseded, plan §1 validation row Co-Authored-By: Claude Fable 5.1 <[email protected]>
47 lines
2.1 KiB
TypeScript
47 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { describeSettings, resolveAgentSettings } from "../src/index.ts";
|
|
import { compactionFromSettings, resolveModelFromSettings } from "../src/pi/model.ts";
|
|
|
|
describe("AgentSettings → pi-ai", () => {
|
|
it("anthropic:baseUrl 去掉 /v1,上下文预算即 contextWindow,apiKey 只在 resolve 时给出", async () => {
|
|
const s = resolveAgentSettings({
|
|
provider: "anthropic",
|
|
baseUrl: "https://proxy.local/v1/",
|
|
apiKey: "sk-ant-secret-value",
|
|
model: "claude-sonnet-4-5",
|
|
thinkingLevel: "high",
|
|
contextBudgetTokens: 100_000,
|
|
});
|
|
const { models, model } = resolveModelFromSettings(s);
|
|
expect(model).toMatchObject({
|
|
api: "anthropic-messages",
|
|
baseUrl: "https://proxy.local",
|
|
id: "claude-sonnet-4-5",
|
|
contextWindow: 100_000,
|
|
reasoning: true,
|
|
});
|
|
expect(JSON.stringify(model)).not.toContain("sk-ant-secret-value");
|
|
const auth = await models.getAuth(model);
|
|
expect(JSON.stringify(auth)).toContain("sk-ant-secret-value");
|
|
expect(JSON.stringify(describeSettings(s))).not.toContain("sk-ant-secret-value");
|
|
expect(s.subagentsEnabled).toBe(false);
|
|
});
|
|
|
|
it("openai-compatible 需要带 /v1 的 baseUrl;压缩模式映射", () => {
|
|
const base = { provider: "openai-compatible" as const, apiKey: "k", model: "qwen3" };
|
|
expect(() => resolveModelFromSettings(resolveAgentSettings(base))).toThrow(/baseUrl/);
|
|
const s = resolveAgentSettings({
|
|
...base,
|
|
baseUrl: "http://llm.local/v1",
|
|
contextBudgetTokens: 32_000,
|
|
compaction: { mode: "threshold", threshold: 0.75 },
|
|
});
|
|
const { model } = resolveModelFromSettings(s);
|
|
expect(model).toMatchObject({ api: "openai-completions", baseUrl: "http://llm.local/v1", reasoning: false });
|
|
expect(compactionFromSettings(s, 32_000)).toEqual({ enabled: true, reserveTokens: 8000, keepRecentTokens: 8000 });
|
|
const manual = resolveAgentSettings({ ...s, compaction: { mode: "manual", threshold: 0.8 } });
|
|
expect(compactionFromSettings(manual, 32_000).enabled).toBe(false);
|
|
expect(() => resolveAgentSettings({ ...base, model: "" })).toThrow();
|
|
});
|
|
});
|