Add adapter environment testing infrastructure

Introduce testEnvironment() on ServerAdapterModule with structured
pass/warn/fail diagnostics for all four adapter types (claude_local,
codex_local, process, http). Adds POST test-environment endpoint,
shared types/validators, adapter test implementations, and UI API
client. Includes asset type foundations used by related features.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Forgotten
2026-02-20 12:50:23 -06:00
parent de3efdd16b
commit f80a802592
26 changed files with 720 additions and 6 deletions

View File

@@ -0,0 +1,63 @@
import { afterEach, describe, expect, it } from "vitest";
import { testEnvironment } from "@paperclip/adapter-claude-local/server";
const ORIGINAL_ANTHROPIC = process.env.ANTHROPIC_API_KEY;
afterEach(() => {
if (ORIGINAL_ANTHROPIC === undefined) {
delete process.env.ANTHROPIC_API_KEY;
} else {
process.env.ANTHROPIC_API_KEY = ORIGINAL_ANTHROPIC;
}
});
describe("claude_local environment diagnostics", () => {
it("returns a warning (not an error) when ANTHROPIC_API_KEY is set in host environment", async () => {
process.env.ANTHROPIC_API_KEY = "sk-test-host";
const result = await testEnvironment({
companyId: "company-1",
adapterType: "claude_local",
config: {
command: process.execPath,
cwd: process.cwd(),
},
});
expect(result.status).toBe("warn");
expect(
result.checks.some(
(check) =>
check.code === "claude_anthropic_api_key_overrides_subscription" &&
check.level === "warn",
),
).toBe(true);
expect(result.checks.some((check) => check.level === "error")).toBe(false);
});
it("returns a warning (not an error) when ANTHROPIC_API_KEY is set in adapter env", async () => {
delete process.env.ANTHROPIC_API_KEY;
const result = await testEnvironment({
companyId: "company-1",
adapterType: "claude_local",
config: {
command: process.execPath,
cwd: process.cwd(),
env: {
ANTHROPIC_API_KEY: "sk-test-config",
},
},
});
expect(result.status).toBe("warn");
expect(
result.checks.some(
(check) =>
check.code === "claude_anthropic_api_key_overrides_subscription" &&
check.level === "warn",
),
).toBe(true);
expect(result.checks.some((check) => check.level === "error")).toBe(false);
});
});