feat: add pluggable multi-CLI backend system
Implement BackendAdapter interface with four CLI backends: - ClaudeCodeBackend (extracted from AgentRuntime) - CodexBackend (OpenAI Codex CLI) - GeminiBackend (Google Gemini CLI) - OpenCodeBackend (OpenCode CLI) Add BackendRegistry for resolution/creation via AGENT_BACKEND env var. Refactor AgentRuntime to delegate to BackendAdapter instead of hardcoding Claude CLI. Update GatewayConfig with new env vars (AGENT_BACKEND, BACKEND_CLI_PATH, BACKEND_MODEL, BACKEND_MAX_TURNS). Includes 10 property-based test files and unit tests for edge cases.
This commit is contained in:
94
tests/property/opencode-backend.property.test.ts
Normal file
94
tests/property/opencode-backend.property.test.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
import { describe, it } from "vitest";
|
||||
import fc from "fast-check";
|
||||
import { OpenCodeBackend } from "../../src/backends/opencode-backend.js";
|
||||
import type { BackendAdapterConfig } from "../../src/backends/types.js";
|
||||
|
||||
// Feature: multi-cli-backend, Property 4: OpenCode backend required flags
|
||||
// **Validates: Requirements 5.2, 5.3, 5.5**
|
||||
|
||||
/**
|
||||
* Arbitrary for non-empty strings that won't break CLI arg parsing.
|
||||
*/
|
||||
const nonEmptyString = fc.string({ minLength: 1, maxLength: 200 });
|
||||
|
||||
/**
|
||||
* Arbitrary for model strings (provider/model format).
|
||||
*/
|
||||
const modelString = fc.stringMatching(/^[a-z]{1,20}\/[a-z0-9-]{1,40}$/);
|
||||
|
||||
function createBackend(model?: string): OpenCodeBackend {
|
||||
const config: BackendAdapterConfig = {
|
||||
cliPath: "opencode",
|
||||
workingDir: "/tmp",
|
||||
queryTimeoutMs: 60000,
|
||||
allowedTools: [],
|
||||
maxTurns: 25,
|
||||
model,
|
||||
};
|
||||
return new OpenCodeBackend(config);
|
||||
}
|
||||
|
||||
describe("Property 4: OpenCode backend required flags", () => {
|
||||
it("generated args always start with the run subcommand", () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
nonEmptyString,
|
||||
(prompt) => {
|
||||
const backend = createBackend();
|
||||
const args = backend.buildArgs(prompt);
|
||||
|
||||
return args[0] === "run";
|
||||
},
|
||||
),
|
||||
{ numRuns: 100 },
|
||||
);
|
||||
});
|
||||
|
||||
it("generated args always contain --format json", () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
nonEmptyString,
|
||||
(prompt) => {
|
||||
const backend = createBackend();
|
||||
const args = backend.buildArgs(prompt);
|
||||
|
||||
const formatIndex = args.indexOf("--format");
|
||||
return formatIndex !== -1 && args[formatIndex + 1] === "json";
|
||||
},
|
||||
),
|
||||
{ numRuns: 100 },
|
||||
);
|
||||
});
|
||||
|
||||
it("generated args contain --model when a model is configured", () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
nonEmptyString,
|
||||
modelString,
|
||||
(prompt, model) => {
|
||||
const backend = createBackend(model);
|
||||
const args = backend.buildArgs(prompt);
|
||||
|
||||
const modelIndex = args.indexOf("--model");
|
||||
return modelIndex !== -1 && args[modelIndex + 1] === model;
|
||||
},
|
||||
),
|
||||
{ numRuns: 100 },
|
||||
);
|
||||
});
|
||||
|
||||
it("generated args do not contain --model when no model is configured", () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
nonEmptyString,
|
||||
(prompt) => {
|
||||
const backend = createBackend(undefined);
|
||||
const args = backend.buildArgs(prompt);
|
||||
|
||||
return !args.includes("--model");
|
||||
},
|
||||
),
|
||||
{ numRuns: 100 },
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user