72 lines
4.3 KiB
TypeScript
72 lines
4.3 KiB
TypeScript
import { codexSubmitRoutingRecommendationForTest } from "./src/code-queue";
|
|
|
|
type JsonRecord = Record<string, unknown>;
|
|
|
|
function assertCondition(condition: unknown, message: string, detail: unknown = {}): void {
|
|
if (!condition) throw new Error(`${message}: ${JSON.stringify(detail)}`);
|
|
}
|
|
|
|
function asRecord(value: unknown): JsonRecord {
|
|
assertCondition(typeof value === "object" && value !== null && !Array.isArray(value), "expected JSON object", { value });
|
|
return value as JsonRecord;
|
|
}
|
|
|
|
const lowRiskPrompt = `
|
|
目标:更新 docs/reference/code-queue-supervision.md 中的 MiniMax 派单规则。
|
|
范围:只改中文长期文档和一个轻量 dry-run contract test,不触碰 runtime 调度核心。
|
|
禁止:不要重启服务,不要读取密钥,不要写数据库,不要部署 prod。
|
|
验证:运行 bun scripts/code-queue-submit-routing-contract-test.ts,并在 final response 给出验证证据、commit 和风险。
|
|
背景:本 prompt 是完整需求来源,GitHub issue 只能作为辅助引用,不能作为唯一来源。需要 dry-run/preflight 输出帮助指挥官判断 runner/model。请保持改动低风险、可审阅、可回滚,并让指挥官完成后审阅未读任务。
|
|
`;
|
|
|
|
const runtimePrompt = `
|
|
目标:修复 Code Queue runtime scheduler 的 active run 状态机。
|
|
范围:src/components/microservices/code-queue/src/index.ts 和 runtime-preflight。
|
|
禁止:不要部署 prod。
|
|
验证:需要证明 scheduler heartbeat、active run、OpenCode session recovery 都正确。
|
|
`;
|
|
|
|
const commanderOnlyPrompt = `
|
|
目标:在 production 上 deploy apply 并 restart code-queue,必要时读取 secret token 和写 PostgreSQL 修复任务状态。
|
|
验证:live health。
|
|
`;
|
|
|
|
export function runCodeQueueSubmitRoutingContract(): JsonRecord {
|
|
const lowRisk = codexSubmitRoutingRecommendationForTest(lowRiskPrompt);
|
|
assertCondition(lowRisk.route === "minimax-opencode", "low-risk self-contained prompt should be a MiniMax candidate", lowRisk);
|
|
assertCondition(lowRisk.recommendedRunner === "opencode", "MiniMax candidate should recommend OpenCode", lowRisk);
|
|
assertCondition(lowRisk.recommendedModel === "minimax-m2.7", "MiniMax candidate should recommend minimax-m2.7", lowRisk);
|
|
assertCondition(asRecord(lowRisk.riskControls).promptSelfContained === true, "low-risk prompt should be self-contained", lowRisk);
|
|
assertCondition(asRecord(lowRisk.riskControls).issueIsNotOnlySource === true, "issue must not be the only source", lowRisk);
|
|
|
|
const runtime = codexSubmitRoutingRecommendationForTest(runtimePrompt);
|
|
assertCondition(runtime.route === "gpt-5.5-codex", "runtime/core work should stay on GPT-5.5", runtime);
|
|
assertCondition(runtime.recommendedRunner === "codex", "runtime/core work should recommend Codex runner", runtime);
|
|
assertCondition(runtime.recommendedModel === "gpt-5.5", "runtime/core work should recommend GPT-5.5", runtime);
|
|
|
|
const commanderOnly = codexSubmitRoutingRecommendationForTest(commanderOnlyPrompt);
|
|
assertCondition(commanderOnly.route === "commander-human-only", "prod restart/secrets/DB work should be commander-only", commanderOnly);
|
|
assertCondition(commanderOnly.recommendedRunner === "commander", "commander-only work should not recommend a runner", commanderOnly);
|
|
assertCondition(commanderOnly.recommendedModel === null, "commander-only work should not recommend a model", commanderOnly);
|
|
|
|
const explicitGpt = codexSubmitRoutingRecommendationForTest(lowRiskPrompt, "gpt-5.5");
|
|
const explicitRequest = asRecord(explicitGpt.explicitRequest);
|
|
assertCondition(explicitRequest.runner === "codex", "explicit gpt model should map to Codex", explicitGpt);
|
|
assertCondition(String(explicitRequest.note ?? "").includes("differs"), "explicit model mismatch should be visible", explicitGpt);
|
|
assertCondition(asRecord(explicitGpt.routingPolicy).doesNotChangeSubmittedPayload === true, "dry-run recommendation must not rewrite payload", explicitGpt);
|
|
|
|
return {
|
|
ok: true,
|
|
checks: [
|
|
"low-risk self-contained prompts recommend minimax-m2.7/OpenCode",
|
|
"runtime/core work recommends GPT-5.5/Codex",
|
|
"prod/restart/secret/DB work is commander-only",
|
|
"explicit --model mismatch is visible and payload is unchanged",
|
|
],
|
|
};
|
|
}
|
|
|
|
if (import.meta.main) {
|
|
process.stdout.write(`${JSON.stringify(runCodeQueueSubmitRoutingContract(), null, 2)}\n`);
|
|
}
|