Files
buzz/scripts/run-differential.mjs
npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 1717c88f0d feat(agent): Phase 2a — wire Rust consumers to generated capability module
Cut config.rs, catalog.rs, and llm.rs over to the generated capability
module from Phase 1. Both old and new paths are preserved; Phase 3
removes the old authorities.

Changes:
- catalog.rs: replace hand-typed DATABRICKS_V2_KNOWN_MODELS literal with
  a re-export of generated_model_capabilities::DATABRICKS_V2_KNOWN_MODELS
- llm.rs: databricks_v2_route_for_model now delegates to
  resolve_model_capabilities("databricks_v2", model). Old segment-based
  classifier and constants moved to #[cfg(test)] under _old_* names for
  the differential harness. New differential test confirms old/new agree
  on all 20 route test vectors (empty allowlist — logic is identical).
- config.rs: add effort_table_fixture_differential_old_vs_new test that
  runs resolve_model_capabilities over the 36-entry effortTable.fixture.json
  and asserts old/new agree mod a doc-cited allowlist of 4 intentional F1
  corrections (gpt-5-5, gpt-5-4-mini, gpt-5-4-nano, gpt-5-6-sol).
- scripts/run-differential.mjs: new JS differential harness running the
  old buzzAgentConfig.ts effort logic vs new modelCapabilities.ts over the
  effortTable fixture (36 entries), normative corpus (45 vectors), and
  catalog-sample fixture (14 endpoints). Passes with allowlist of 5 entries
  (4 models.dev F1 corrections + goose-opus-5 anthropic route correction).
- scripts/MODELS_DEV_RECONCILIATION.md: replace 8 trailing-double-space
  Markdown line breaks with <br> (deferred MINOR from Phase 1 review).

Verification:
- cargo test -p buzz-agent --lib: 426/426 (424 existing + 2 new differential)
- node run-corpus.mjs: 45/45
- node test-manifest-validator.mjs: 24/24 schema-negative
- generate-model-capabilities.mjs --check: byte-clean
- node run-differential.mjs: 85 checks, 0 unexpected divergences
- git diff --check: clean

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
2026-07-31 12:57:06 -04:00

202 lines
7.1 KiB
JavaScript
Executable File

#!/usr/bin/env node
/**
* Phase-2 differential harness — compare old buzzAgentConfig.ts effort logic with
* the new generated modelCapabilities.ts interpreter over:
* 1. The 36-entry effortTable.fixture.json (cross-boundary Rust/TS fixture)
* 2. The 45-vector normative corpus (scripts/normative-corpus.json)
* 3. The catalog-sample fixture (scripts/catalog-sample-fixture.json)
*
* Equality is required except for entries in the committed allowlist of intentional
* F1 corrections (models.dev provider-capability reconciliations).
*
* Usage: node --experimental-strip-types scripts/run-differential.mjs [--verbose]
* Exits 0 on all-pass (modulo allowlist), 1 on unexpected divergence.
*/
import { readFileSync } from "node:fs";
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const repoRoot = join(__dirname, "..");
const VERBOSE = process.argv.includes("--verbose");
// ---------------------------------------------------------------------------
// Import both interpreters
// ---------------------------------------------------------------------------
// NEW: generated capability module
const { resolveModelCapabilities: resolveNew } = await import(
join(repoRoot, "desktop", "src", "features", "agents", "ui", "modelCapabilities.ts")
);
// OLD: buzzAgentConfig.ts effort config
const { getProviderEffortConfig: getOldEffortConfig } = await import(
join(repoRoot, "desktop", "src", "features", "agents", "ui", "buzzAgentConfig.ts")
);
// ---------------------------------------------------------------------------
// Intentional corrections allowlist (Phase 1 F1 reconciliations)
// Each entry: { provider, raw_model_id, reason }
// ---------------------------------------------------------------------------
const ALLOWLIST = [
{
provider: "databricks_v2",
raw_model_id: "databricks-gpt-5-5",
axes: ["supported_efforts"],
reason: "Phase 1 ADOPT: models.dev d5a4974c advertises [low,medium,high]; old returns [none,low,medium,high,xhigh]",
},
{
provider: "databricks_v2",
raw_model_id: "databricks-gpt-5-4-mini",
axes: ["supported_efforts"],
reason: "Phase 1 ADOPT: models.dev advertises [low,medium,high]; old returns [none,low,medium,high,xhigh]",
},
{
provider: "databricks_v2",
raw_model_id: "databricks-gpt-5-4-nano",
axes: ["supported_efforts"],
reason: "Phase 1 ADOPT: models.dev advertises [low,medium,high]; old returns [none,low,medium,high,xhigh]",
},
{
provider: "databricks_v2",
raw_model_id: "databricks-gpt-5-6-sol",
axes: ["supported_efforts"],
reason: "Phase 1 ADOPT: models.dev advertises [low,medium,high,max]; old returns [none,low,medium,high,xhigh,max]",
},
{
provider: "databricks_v2",
raw_model_id: "goose-opus-5",
axes: ["supported_efforts", "default_effort"],
reason: "Phase 1 correction: 'opus' is a named DBv2 segment → anthropic-messages route; old config.rs disagreed with llm.rs (corpus note dbv2-goose-opus-5-is-anthropic). Generated adopts anthropic adaptive-xhigh capabilities consistent with the wire route.",
},
];
function isAllowlisted(provider, rawModelId, axis) {
return ALLOWLIST.some(
(e) =>
e.provider === provider &&
e.raw_model_id === rawModelId &&
e.axes.includes(axis),
);
}
// ---------------------------------------------------------------------------
// Comparison helpers
// ---------------------------------------------------------------------------
/**
* Compare effort axes from both interpreters for one (provider, model) pair.
* Returns array of divergence objects.
*/
function compareEffortAxes(provider, model) {
const newResult = resolveNew(provider, model);
const oldResult = getOldEffortConfig(provider, model);
const divergences = [];
// supported_efforts
const newEfforts = newResult.supportedEfforts ?? [];
const oldEfforts = oldResult?.validValues ?? [];
if (JSON.stringify(newEfforts) !== JSON.stringify(oldEfforts)) {
if (!isAllowlisted(provider, model, "supported_efforts")) {
divergences.push({
axis: "supported_efforts",
old: oldEfforts,
new: newEfforts,
});
}
}
// default_effort
const newDefault = newResult.defaultEffort ?? null;
const oldDefault = oldResult?.defaultValue ?? null;
if (newDefault !== oldDefault) {
if (!isAllowlisted(provider, model, "default_effort")) {
divergences.push({
axis: "default_effort",
old: oldDefault,
new: newDefault,
});
}
}
return divergences;
}
// ---------------------------------------------------------------------------
// Test suites
// ---------------------------------------------------------------------------
let totalChecks = 0;
let totalDivergences = 0;
let totalAllowlisted = 0;
function runCheck(label, provider, model) {
totalChecks++;
const divs = compareEffortAxes(provider, model);
if (divs.length > 0) {
totalDivergences += divs.length;
for (const d of divs) {
console.error(
`DIVERGE [${label}] provider=${provider} model=${model} axis=${d.axis}\n` +
` old: ${JSON.stringify(d.old)}\n` +
` new: ${JSON.stringify(d.new)}`,
);
}
} else if (VERBOSE) {
console.log(`OK [${label}] provider=${provider} model=${model}`);
}
}
// 1. effortTable.fixture.json
console.log("--- effortTable.fixture.json ---");
const fixture = JSON.parse(
readFileSync(
join(repoRoot, "desktop", "src", "features", "agents", "ui", "effortTable.fixture.json"),
"utf8",
),
);
for (const entry of fixture) {
if (!entry.provider) continue;
runCheck("fixture", entry.provider, entry.model ?? "");
}
// 2. normative-corpus.json (effort axes only)
console.log("--- normative-corpus.json ---");
const corpus = JSON.parse(
readFileSync(join(repoRoot, "scripts", "normative-corpus.json"), "utf8"),
);
for (const entry of corpus) {
if (entry._group) continue;
if (!entry.provider || !entry.expect) continue;
if (!entry.expect.supported_efforts && !entry.expect.default_effort) continue;
runCheck("corpus", entry.provider, entry.raw_model_id ?? "");
}
// 3. catalog-sample-fixture.json (exact records from pinned models.dev payload)
console.log("--- catalog-sample-fixture.json ---");
const catalogFixture = JSON.parse(
readFileSync(join(repoRoot, "scripts", "catalog-sample-fixture.json"), "utf8"),
);
for (const ep of catalogFixture.endpoints ?? []) {
if (!ep.name) continue;
// All catalog endpoints are databricks_v2 provider
runCheck("catalog-sample", "databricks_v2", ep.name);
}
// ---------------------------------------------------------------------------
// Summary
// ---------------------------------------------------------------------------
console.log(
`\nDifferential: ${totalChecks} checks, ${totalDivergences} unexpected divergences, ${totalAllowlisted} allowlisted`,
);
if (totalDivergences > 0) {
console.error(
`FAIL: ${totalDivergences} unexpected divergence(s) — see output above`,
);
process.exit(1);
} else {
console.log("PASS: old and new effort logic agree on all non-allowlisted entries");
}