Files
buzz/scripts/run-mutation-evidence.mjs
Will Pfleger 4d47f48143 feat(agent): Phase 1 — model-capability manifest, generator, and test oracle (#3821)
## What this does

Introduces the model-capability manifest infrastructure (Phase 1 of the
Model-Capability Manifest plan v4, Thufir-approved 9/9/9). No consumer
cutover — `config.rs`, `llm.rs`, `catalog.rs`, and `buzzAgentConfig.ts`
are unchanged. Phase 2 wires them.

**Single source of truth** replaces hand-mirrored metadata across four
files:

```
scripts/model-capabilities.json         → hand-curated manifest
scripts/generate-model-capabilities.mjs → emits Rust + TS artifacts
crates/buzz-agent/src/generated_model_capabilities.rs
desktop/src/features/agents/ui/modelCapabilities.ts
```

## Resolver contract (plan v4 §Resolver contract)

Total function `resolve(provider, raw_model_id) → CapabilityResult`.
Three ordered steps:

1. Provider-qualified raw exact lookup — key is `(provider,
raw_model_id)`, matched before any prefix stripping. A prefixed alias
never inherits an exact record.
2. Provider-scoped ordered family rules — on normalized
(prefix-stripped) alias, by `match_priority` desc.
3. Per-axis provider fallback — `blank` vs `concrete_unknown`, per
provider.

Result is complete — every axis populated, runtime consumers never
compose fields.

## Boundaries the manifest does NOT own

- Transport for pure OpenAI, legacy Databricks, OpenRouter:
`OpenAiApi`/`openai_request()` remain authoritative.
`databricks_v2_wire_route` is DBv2-only (all other providers emit
`not-applicable`).
- Final display labels: `resolveModelLabel()` three-tier precedence
unchanged. `registry_label` feeds only the static registry tier.
- `llm.rs` scope: only `databricks_v2_route_for_model` (Phase 2).

## Test oracle (three independent layers)

1. Generated full-table coverage —
`scripts/generated-model-capabilities-coverage.json`: every manifest
entry + provider fallbacks.
2. Hand-authored normative corpus — `scripts/normative-corpus.json` (44
vectors): Anthropic manual-budget/adaptive families, OpenAI gpt-5
adversarial boundary cases, DBv2 segment-routing collision tests, P2-A
resolver-contract vectors, P2-B blank/concrete-unknown per provider.
Runs against JS resolver (`run-corpus.mjs`) and mirrored in Rust
(`generated_model_capabilities_tests.rs`).
3. Schema-negative tests — `scripts/test-manifest-validator.mjs` (17
tests): every validator rule has a failing-input test.

## Reconciliation table

`scripts/MODELS_DEV_RECONCILIATION.md` — all models.dev divergences
dispositioned. `databricks-gpt-5-4-mini` and `databricks-gpt-5-4-nano`
adopt models.dev `[low,medium,high]` (family rule adds `none+xhigh` the
endpoint doesn't advertise).

## CI

`.github/workflows/model-capability-regen-diff.yml`: triggers on
manifest/generator/artifact changes; regenerates and fails if stale;
runs JS corpus + schema-negative tests.

## Acceptance criteria (plan v4 Phase 1)

- Byte-clean regen: `node scripts/generate-model-capabilities.mjs
--check` passes
- Rust compiles: `cargo check -p buzz-agent`
- TS typechecks: `pnpm tsc --noEmit --strict`
- 44/44 normative corpus vectors pass (JS interpreter)
- 41/41 Rust corpus tests pass
- 17/17 schema-negative tests pass (every validator rule)
- Reconciliation table complete with doc citations
- No consumer changes (config.rs, llm.rs, catalog.rs, buzzAgentConfig.ts
untouched)

---------

Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
2026-07-31 12:39:37 -04:00

262 lines
11 KiB
JavaScript
Executable File

#!/usr/bin/env node
/**
* Per-interpreter mutation evidence runner.
*
* Introduces deliberate resolver faults into the manifest, regenerates artifacts,
* and verifies the shared normative corpus detects every fault in BOTH the generated
* TypeScript interpreter (via --experimental-strip-types import) and the Rust
* interpreter (via cargo test shared-corpus harness). Exits 0 if all mutations are
* killed in both interpreters; exits 1 if any survive.
*
* Usage:
* node --experimental-strip-types scripts/run-mutation-evidence.mjs [--verbose]
*
* This script is non-CI (run manually to generate MUTATION_EVIDENCE.md). It writes
* its findings to stdout in a format suitable for copy-paste into the evidence doc.
*
* Mutations applied (each in isolation, manifest restored after each run):
* M1: Swap anthropic-adaptive-xhigh-opus-4-7 efforts from [low,medium,high,xhigh,max]
* to [low,medium,high] — kills corpus vectors that check xhigh/max.
* M2: Change gpt5-base supported_efforts to include "xhigh" — kills vectors that
* check gpt5-base resolves minimal-only, not xhigh.
* M3: Change openai-gpt5-1 default_effort to "high" instead of "none" — kills
* the gpt5.1 corpus vector that checks default_effort=none.
* M4: Swap databricks_v2_wire_route in dbv2-claude-code-names-segment from
* "anthropic-messages" to "openai-responses" — kills segment-route corpus vectors.
* M5: Remove all three DBv2 segment rules — kills goose-opus-5 and terraform/consolidated
* segment collision vectors.
* M6: Change databricks_v2 concrete_unknown fallback route from "mlflow-chat" to
* "openai-responses" — kills dbv2-concrete-unknown-mlflow-no-max vector.
* M7: Change gpt5-4 supported_efforts to remove "xhigh" — kills
* resolver-prefixed-alias-misses-exact vector.
*/
import { readFileSync, writeFileSync } from "node:fs";
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { execSync, spawnSync } from "node:child_process";
const __dirname = dirname(fileURLToPath(import.meta.url));
const repoRoot = join(__dirname, "..");
const VERBOSE = process.argv.includes("--verbose");
const manifestPath = join(repoRoot, "scripts", "model-capabilities.json");
const generatorPath = join(repoRoot, "scripts", "generate-model-capabilities.mjs");
const jsRunnerPath = join(repoRoot, "scripts", "run-corpus.mjs");
const originalManifest = readFileSync(manifestPath, "utf8");
/**
* Run the TS corpus and return:
* { kind: "passed" } — all vectors pass (mutation survived)
* { kind: "killed", output } — nonzero exit AND at least one expectedKiller ID
* appears in stdout/stderr ("FAIL <id>" line)
* { kind: "error", output } — nonzero exit but NO expected corpus output
* (import error, missing file, syntax error, etc.)
*/
function runTsCorpus(expectedKillers) {
let result;
try {
result = spawnSync(
process.execPath,
["--experimental-strip-types", jsRunnerPath],
{ cwd: repoRoot, encoding: "utf8" },
);
} catch (e) {
return { kind: "error", output: `spawn error: ${e.message}` };
}
if (result.status === 0) return { kind: "passed" };
const output = (result.stdout ?? "") + (result.stderr ?? "");
// A genuine corpus kill produces "FAIL <vector-id>" lines.
// An infrastructure failure (import error, syntax error) produces no such lines.
const hasCorpusFailure = expectedKillers.some((id) => output.includes(`FAIL ${id}`));
if (hasCorpusFailure) return { kind: "killed", output };
return { kind: "error", output };
}
/**
* Run the Rust corpus and return:
* { kind: "passed" } — all vectors pass
* { kind: "killed", output } — nonzero exit AND at least one expectedKiller ID
* appears in the panic output ("[<id>]" format)
* { kind: "error", output } — nonzero exit but NO expected corpus output
* (compile error, missing cargo, linker error, etc.)
*/
function runRustCorpus(expectedKillers) {
let result;
try {
result = spawnSync(
"cargo",
[
"test",
"-p", "buzz-agent",
"--",
"generated_model_capabilities::tests::shared_corpus_tests",
"--nocapture",
],
{ cwd: repoRoot, encoding: "utf8", env: { ...process.env, RUST_BACKTRACE: "0" } },
);
} catch (e) {
return { kind: "error", output: `spawn error: ${e.message}` };
}
if (result.status === 0) return { kind: "passed" };
const output = (result.stdout ?? "") + (result.stderr ?? "");
// The Rust corpus runner panics with "[<vector-id>] <axis>: got..." messages.
const hasCorpusFailure = expectedKillers.some((id) => output.includes(`[${id}]`));
if (hasCorpusFailure) return { kind: "killed", output };
return { kind: "error", output };
}
function regen() {
execSync(`"${process.execPath}" "${generatorPath}"`, {
cwd: repoRoot,
stdio: VERBOSE ? "inherit" : "pipe",
});
}
function restore() {
writeFileSync(manifestPath, originalManifest, "utf8");
}
function applyMutation(mutFn) {
const manifest = JSON.parse(originalManifest);
mutFn(manifest);
writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + "\n", "utf8");
}
const mutations = [
{
id: "M1",
description: "Reduce claude-opus-4-7 supported_efforts to [low,medium,high] (drops xhigh+max)",
expectedKillers: ["anthropic-claude-opus-4-7", "dbv2-claude-prefix-stripped", "dbv2-claude-route-anthropic-messages"],
mutate(manifest) {
const rule = manifest.family_rules.find(r => r.id === "anthropic-adaptive-xhigh-opus-4-7");
rule.supported_efforts = ["low", "medium", "high"];
},
},
{
id: "M2",
description: "Add xhigh to gpt5-base supported_efforts [minimal,low,medium,high,xhigh]",
expectedKillers: ["openai-gpt5-base", "openai-gpt5-1106-should-not-match-base", "openai-gpt5-4o-matches-base", "openai-gpt5-date-suffix"],
mutate(manifest) {
const rule = manifest.family_rules.find(r => r.id === "openai-gpt5-base");
rule.supported_efforts = ["minimal", "low", "medium", "high", "xhigh"];
},
},
{
id: "M3",
description: "Change gpt5-1 default_effort to 'high' instead of 'none'",
expectedKillers: ["openai-gpt5.1"],
mutate(manifest) {
const rule = manifest.family_rules.find(r => r.id === "openai-gpt5-1");
rule.default_effort = "high";
},
},
{
id: "M4",
description: "Swap dbv2-claude-code-names-segment route from anthropic-messages to openai-responses",
expectedKillers: ["dbv2-goose-opus-5-is-anthropic"],
mutate(manifest) {
const rule = manifest.family_rules.find(r => r.id === "dbv2-claude-code-names-segment");
rule.databricks_v2_wire_route = "openai-responses";
},
},
{
id: "M5",
description: "Remove all three DBv2 segment rules (dbv2-claude-code-names-segment, dbv2-gpt-code-names-segment, dbv2-sol-luna-terra-segment)",
expectedKillers: ["dbv2-goose-opus-5-is-anthropic", "dbv2-consolidated-llama-not-sol", "dbv2-terraform-coder-not-terra"],
mutate(manifest) {
manifest.family_rules = manifest.family_rules.filter(
r => !["dbv2-claude-code-names-segment", "dbv2-gpt-code-names-segment", "dbv2-sol-luna-terra-segment"].includes(r.id)
);
},
},
{
id: "M6",
description: "Change databricks_v2 concrete_unknown fallback route from mlflow-chat to openai-responses",
expectedKillers: ["dbv2-concrete-unknown-mlflow-no-max"],
mutate(manifest) {
manifest.provider_fallbacks.databricks_v2.concrete_unknown.databricks_v2_wire_route = "openai-responses";
},
},
{
id: "M7",
description: "Remove xhigh from gpt5-4 supported_efforts [none,low,medium,high]",
expectedKillers: ["resolver-prefixed-alias-misses-exact"],
mutate(manifest) {
const rule = manifest.family_rules.find(r => r.id === "openai-gpt5-4");
rule.supported_efforts = ["none", "low", "medium", "high"];
},
},
];
let allKilled = true;
const results = [];
for (const mut of mutations) {
process.stdout.write(` ${mut.id}: ${mut.description}\n`);
try {
applyMutation(mut.mutate);
regen();
// TS interpreter
process.stdout.write(` TS ... `);
const tsResult = runTsCorpus(mut.expectedKillers);
const tsKilled = tsResult.kind === "killed";
const tsError = tsResult.kind === "error";
if (tsKilled) {
process.stdout.write("killed ✓\n");
} else if (tsError) {
process.stdout.write(`ERROR (infrastructure failure — not a corpus kill)\n`);
if (VERBOSE) process.stdout.write(` ${tsResult.output}\n`);
} else {
process.stdout.write("SURVIVED ✗\n");
if (VERBOSE) process.stdout.write(` ${tsResult.output ?? ""}\n`);
}
// Rust interpreter
process.stdout.write(` Rust... `);
const rustResult = runRustCorpus(mut.expectedKillers);
const rustKilled = rustResult.kind === "killed";
const rustError = rustResult.kind === "error";
if (rustKilled) {
process.stdout.write("killed ✓\n");
} else if (rustError) {
process.stdout.write(`ERROR (infrastructure failure — not a corpus kill)\n`);
if (VERBOSE) process.stdout.write(` ${rustResult.output}\n`);
} else {
process.stdout.write("SURVIVED ✗\n");
if (VERBOSE) process.stdout.write(` ${rustResult.output ?? ""}\n`);
}
const killed = tsKilled && rustKilled;
if (!killed) allKilled = false;
results.push({ ...mut, killed, tsKilled, rustKilled, tsError, rustError });
} catch (e) {
process.stdout.write(` ERROR: ${e.message}\n`);
allKilled = false;
results.push({ ...mut, killed: false, tsKilled: false, rustKilled: false, tsError: true, rustError: true, output: e.message });
} finally {
restore();
regen(); // restore generated files
}
}
console.log("");
const killed = results.filter(r => r.killed).length;
const errored = results.filter(r => r.tsError || r.rustError).length;
console.log(`Mutation results: ${killed}/${results.length} killed (both interpreters)` +
(errored > 0 ? `, ${errored} ERROR (infrastructure failure — see output above)` : ""));
if (!allKilled) {
const hasErrors = results.some(r => r.tsError || r.rustError);
if (hasErrors) {
console.error("ERROR: Infrastructure failures prevented some mutations from being verified as killed.");
console.error(" Run with --verbose to see the full output for ERROR entries.");
}
console.error("ERROR: Some mutations survived — corpus does not kill all resolver faults.");
process.exit(1);
}
console.log("All mutations killed in both TS and Rust interpreters.");