Scope chat throughput routing to reviewed OpenCode profile

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip committed 2026-11-06 04:58:45 -06:00
1 parent 253fdfe742
commit c7aa5f6a3c
2 files changed
+58 -1

No files matched your search

+7 -1
View File
@@ -60,10 +60,16 @@ export function chatFeatureProfile(profile: RunnerProfileFixture): RunnerProfile
const { instructionsBundle: _manual, ...payload } = profile.buildAgent(input);
const config = payload.adapterConfig as Record<string, unknown>;
const { codexPermissionMode: _permission, ...adapterConfig } = config;
const throughputRouting = profile.id === "runner-opencode" && profile.provider === "opencode"
&& profile.model === CHAT_FEATURE_OPENCODE_MODEL && profile.adapterType === "paperclip_runner" && profile.credential === "OPENROUTER_API_KEY";
return { ...payload, name: "CEO", title: "CEO", role: "ceo",
capabilities: "Coordinates company work and delegates tasks to the team.",
budgetMonthlyCents: CHAT_FEATURE_BUDGET_CENTS,
adapterConfig: { ...adapterConfig, timeoutSec: profile.id === "runner-opencode" ? CHAT_NATIVE_TIMEOUT_POLICY.savedAgentTimeoutSec : 120, ...(profile.provider === "codex" ? { modelReasoningEffort: "low" } : {}) },
adapterConfig: { ...adapterConfig, ...(throughputRouting ? { env: { ...(adapterConfig.env as Record<string, unknown>),
OPENCODE_CONFIG_CONTENT: JSON.stringify({ provider: { openrouter: { models: {
"deepseek/deepseek-v4.1-flash-1017": { options: { provider: { sort: "throughput" } } },
} } } }),
} } : {}), timeoutSec: profile.id === "runner-opencode" ? CHAT_NATIVE_TIMEOUT_POLICY.savedAgentTimeoutSec : 120, ...(profile.provider === "codex" ? { modelReasoningEffort: "low" } : {}) },
runtimeConfig: { ...(payload.runtimeConfig as Record<string, unknown>),
heartbeat: { enabled: false, maxConcurrentRuns: 1, maxDailyRuns: 3, maxDailyCostCents: CHAT_FEATURE_BUDGET_CENTS } },
};
@@ -1,6 +1,11 @@
import { expect, it } from "vitest";
import { CHAT_OPENCODE_MODEL, reviewedChatProfile, reviewedChatExecutionIds } from "./chat-runtime-profile.js";
import { runnerMatrix, runnerProfiles } from "./catalog.js";
import { CHAT_NATIVE_TIMEOUT_POLICY } from "./chat-native-timeout-policy.js";
import { chatFeatureProfile } from "./chat-feature-cases.js";
import type { RunnerProfileFixture } from "./types.js";
import { setupLiveFixtures } from "./live-fixtures.js";
import type { RunnerApi } from "./api.js";
import { missingTeamAccountEnvironment } from "./chat-catalog-domains/external-team-configure.js";
const profile = { id: "runner-opencode", provider: "opencode", model: CHAT_OPENCODE_MODEL, adapterType: "paperclip_runner", credential: "OPENROUTER_API_KEY" };
it("pins the new controller identity and rejects model/provider/credential substitution", () => {
@@ -19,8 +24,54 @@ it("changes the complete chat matrix without relabeling the existing global qual
expect(payload.adapterConfig).toMatchObject({ provider: "opencode", model: CHAT_OPENCODE_MODEL });
expect(payload.adapterConfig).not.toHaveProperty("modelReasoningEffort");
expect(payload.adapterConfig).not.toHaveProperty("codexPermissionMode");
expect(payload.adapterConfig).toMatchObject({ opencodePermissionMode: "allow", env: {
OPENROUTER_API_KEY: { type: "secret_ref", secretId: "22222222-2222-4222-8222-222222222222", version: "latest" },
} });
const env = (payload.adapterConfig as { env: Record<string, string> }).env;
expect(JSON.parse(env.OPENCODE_CONFIG_CONTENT!)).toEqual({ provider: { openrouter: { models: {
"deepseek/deepseek-v4.1-flash-1017": { options: { provider: { sort: "throughput" } } },
} } } });
expect(Object.keys(env).sort()).toEqual(["OPENCODE_CONFIG_CONTENT", "OPENROUTER_API_KEY"]);
});
it("withholds only the selected account from the missing OpenRouter member", () => {
expect(missingTeamAccountEnvironment(false, "/owned/empty")).toEqual({ OPENROUTER_API_KEY: "" });
expect(missingTeamAccountEnvironment(true, "/owned/empty")).toEqual({ CODEX_HOME: "/owned/empty", OPENAI_API_KEY: "", CODEX_API_KEY: "" });
});
it("scopes routing preference to the reviewed chat profile while preserving its configured environment", () => {
const input = { environmentId: "environment", environmentFixtureId: "local" as const, workspacePath: "/owned", secretRefs: {}, executionId: "owned" };
const config = { provider: "opencode", model: CHAT_OPENCODE_MODEL, opencodePermissionMode: "ask", env: { CUSTOM_SETTING: "kept" } };
const base = { ...runnerProfiles.find(row => row.id === "runner-opencode")!, ...profile,
buildAgent: () => ({ adapterConfig: structuredClone(config), runtimeConfig: {} }) } as RunnerProfileFixture;
const selected = chatFeatureProfile(base).buildAgent(input);
expect(selected.adapterConfig).toMatchObject(config);
expect((selected.adapterConfig as {env: Record<string,string>}).env.OPENCODE_CONFIG_CONTENT).toBeDefined();
for (const patch of [{id:"runner-opencode-deepseek-1017"},{provider:"codex"},{model:"openrouter/other/model"},{adapterType:"opencode_local"},{credential:"OPENAI_API_KEY"}]) {
const excluded = chatFeatureProfile({...base,...patch} as RunnerProfileFixture).buildAgent(input);
expect(excluded.adapterConfig).toEqual({...config,timeoutSec:patch.id ? 120 : CHAT_NATIVE_TIMEOUT_POLICY.savedAgentTimeoutSec,...(patch.provider === "codex" ? {modelReasoningEffort:"low"} : {})});
}
const global = runnerProfiles.find(row => row.id === "runner-opencode")!;
const payload = global.buildAgent({...input,secretRefs:{OPENROUTER_API_KEY:{type:"secret_ref",secretId:"22222222-2222-4222-8222-222222222222",version:"latest"}}});
expect(payload.adapterConfig).not.toHaveProperty("env.OPENCODE_CONFIG_CONTENT");
});
it("posts the reviewed routing configuration through the ordinary agent fixture boundary", async () => {
const execution = runnerMatrix.find(cell => cell.suite.id === "chat-features" && cell.profile.id === "runner-opencode")!;
let saved: Record<string, unknown> | undefined;
const api = {
async get() { return [{id:"local",driver:"local"}]; },
async postSensitive() { return {id:"encrypted-account"}; },
async post(url: string, body: Record<string, unknown>) {
if (url === "/api/companies") return {id:"company",name:"Fixture"};
if (url === "/api/companies/company/agents") { saved=body; return {id:"ceo",...body}; }
throw new Error("Unexpected fixture route");
},
} as unknown as RunnerApi;
const fixtures = await setupLiveFixtures({api,execution,executionNonce:"routing",workspacePath:"/owned",credentials:{OPENROUTER_API_KEY:"synthetic-account-input"}});
try {
const config=saved!.adapterConfig as {provider:string;model:string;env:Record<string,unknown>};
expect(config).toMatchObject({provider:"opencode",model:CHAT_OPENCODE_MODEL});
expect(config.env.OPENROUTER_API_KEY).toEqual({type:"secret_ref",secretId:"encrypted-account",version:"latest"});
expect(JSON.parse(config.env.OPENCODE_CONFIG_CONTENT as string)).toEqual({provider:{openrouter:{models:{"deepseek/deepseek-v4.1-flash-1017":{options:{provider:{sort:"throughput"}}}}}}});
} finally { await fixtures.teardown(); }
});