mirror of
https://github.com/block/buzz.git
synced 2026-11-01 06:51:17 +00:00
CRITICAL: Fix Rust gpt5-base short-version guard to mirror TS regex semantics.
The old 4-char window check diverged from TS /^\d{1,3}(?:[^a-z\d]|$)/i for
inputs like gpt-5-10-preview (10 digits). Replaced with find(non-digit) approach
that exactly matches the TS digit-run semantics. Add left-boundary guards (start
or preceded by '-'/'.') to both gpt5_token_matches_rs and gpt5_base_matches_rs
to prevent sgpt-model-class false-positives.
IMPORTANT: Add exact_records validation to generator — enum checks for all
optional override axes, non-empty override check, canonical-order enforcement,
default_effort-in-override check, match_priority non-negative-int check
(injected into source comments, treated as injection surface). Add 9 schema-
negative tests in test-manifest-validator.mjs.
IMPORTANT: Restrict DBv2 gpt segment rule from starts_with("gpt") to exact
segment match ("gpt" or "gpt5"). Raise priority 5->6 to restore old dual-marker
OpenAI-before-Claude contract. Add left-boundary guards to token helpers. Add
collision-negative corpus vectors: gptoss-model, gptj-6b, gpt-neox,
customgpt-5-5-endpoint.
MINOR: Restore .trim() on model string before resolveModelCapabilities call in
buzzAgentConfig.ts. Make exact-record lookup case-insensitive (lowercase keys at
build + lookup). Extend run-corpus.mjs to compare all 6 axes including
normalization_policy and registry_label. Add positive corpus vectors: opus-5
rule, dbv2 gpt-segment, sol/luna/terra, gpt-5-4-nano exact record, openrouter/
unknown/legacy-databricks fallbacks, case-insensitive lookup vectors. Fix Rust
corpus test harness provider lowercasing to handle vectors like provider=OpenAI.
HYGIENE: Fix "Generated 3 files" -> "Generated 2 files" message. Remove dead
$schema pointer from manifest. Add module doc to generated_model_capabilities_tests.rs
noting hand-maintained status. Switch PROVIDER_ALIASES from plain object to Map
in formatAgentModelLabel.ts and run-corpus.mjs. Align CI node-version to 24.
Tighten python SAFE_NAME_RE from * to + to reject empty display names.
luna/terra: models.dev confirms databricks-gpt-5-6-luna and -terra advertise
[low,medium,high] (differs from sol's [low,medium,high,max]). Added two exact
records with supported_efforts=[low,medium,high], default_effort=medium.
Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
97 lines
3.4 KiB
JavaScript
97 lines
3.4 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Normative corpus runner — validates the generated TS interpreter against
|
|
* scripts/normative-corpus.json.
|
|
*
|
|
* This is the JS side of the two-interpreter corpus check. The runner imports
|
|
* resolveModelCapabilities() directly from the generated TypeScript module via
|
|
* Node's --experimental-strip-types flag. The Rust side lives in
|
|
* crates/buzz-agent/src/generated_model_capabilities.rs (shared corpus harness).
|
|
*
|
|
* Usage: node --experimental-strip-types scripts/run-corpus.mjs [--verbose]
|
|
* Exits 0 on all pass, 1 on any failure.
|
|
*/
|
|
|
|
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 the generated TypeScript interpreter directly.
|
|
// Node 22+ --experimental-strip-types strips type annotations at load time; no build step needed.
|
|
const { resolveModelCapabilities } = await import(
|
|
join(repoRoot, "desktop", "src", "features", "agents", "ui", "modelCapabilities.ts")
|
|
);
|
|
|
|
const corpus = JSON.parse(
|
|
readFileSync(join(repoRoot, "scripts", "normative-corpus.json"), "utf8"),
|
|
);
|
|
|
|
// ----- Provider alias canonicalization -----
|
|
// Mirrors production canonicalizeProvider() in desktop/src/features/agents/lib/formatAgentModelLabel.ts.
|
|
// Applied before every generated lookup so alias vectors (e.g. "openai-compat") pass both interpreters.
|
|
const PROVIDER_ALIASES = new Map([
|
|
["databricks-v2", "databricks_v2"],
|
|
["openai-compat", "openai"],
|
|
]);
|
|
|
|
function canonicalizeProvider(provider) {
|
|
const normalized = (provider ?? "").trim().toLowerCase();
|
|
return PROVIDER_ALIASES.get(normalized) ?? normalized;
|
|
}
|
|
|
|
// ----- Run corpus -----
|
|
|
|
let passed = 0;
|
|
let failed = 0;
|
|
|
|
for (const entry of corpus) {
|
|
// Skip group header entries
|
|
if (entry._group) continue;
|
|
if (!entry.expect) continue;
|
|
|
|
// resolveModelCapabilities returns camelCase keys (registryLabel, thinkingMode, etc.)
|
|
const result = resolveModelCapabilities(canonicalizeProvider(entry.provider), entry.raw_model_id);
|
|
const expect = entry.expect;
|
|
|
|
const failures = [];
|
|
|
|
for (const [key, expectedVal] of Object.entries(expect)) {
|
|
// Corpus uses snake_case; generated TS uses camelCase — convert for lookup.
|
|
const camelKey = key.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
|
|
const actualVal = camelKey in result ? result[camelKey] : result[key];
|
|
|
|
if (Array.isArray(expectedVal)) {
|
|
// Order-sensitive comparison for effort arrays
|
|
const actualArr = Array.isArray(actualVal) ? actualVal : [];
|
|
if (JSON.stringify(actualArr) !== JSON.stringify(expectedVal)) {
|
|
failures.push(
|
|
` ${key}: expected [${expectedVal.join(", ")}] got [${actualArr.join(", ")}]`,
|
|
);
|
|
}
|
|
} else {
|
|
if (actualVal !== expectedVal) {
|
|
failures.push(` ${key}: expected ${JSON.stringify(expectedVal)} got ${JSON.stringify(actualVal)}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (failures.length === 0) {
|
|
passed++;
|
|
if (VERBOSE) {
|
|
console.log(` PASS ${entry.id}`);
|
|
}
|
|
} else {
|
|
failed++;
|
|
console.error(` FAIL ${entry.id} (${entry.provider} / "${entry.raw_model_id}")`);
|
|
for (const f of failures) console.error(f);
|
|
if (entry._note) console.error(` note: ${entry._note}`);
|
|
}
|
|
}
|
|
|
|
console.log(`\nCorpus: ${passed} passed, ${failed} failed`);
|
|
process.exit(failed > 0 ? 1 : 0);
|