Skip to content

Commit 1e9df55

Browse files
npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7wpfleger96
andcommitted
fix(manifest): enforce registry_label exclusion on family rules; test fileOverrides boundary
Rule (a) is now structurally unexpressible: the generator rejects any family rule carrying registry_label (exit non-zero), removes the dead reads from resolveFamilyRules() and both emitters, and adds a schema-negative test to catch reintroduction. The fileOverrides integration test is replaced with a real temporary- repository runFileSizeCheck() call: proves the named path passes under its raised ceiling, proves a second governed path at the same size still fails (no leak), and restores process.exitCode and console.error in cleanup for test isolation. Co-authored-by: Will Pfleger <[email protected]> Signed-off-by: Will Pfleger <[email protected]>
1 parent 0e6aacf commit 1e9df55

3 files changed

Lines changed: 79 additions & 19 deletions

File tree

‎scripts/check-file-sizes-core.test.mjs‎

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assert from "node:assert/strict";
2-
import { execFileSync } from "node:child_process";
3-
import { mkdtempSync } from "node:fs";
2+
import { execFileSync, spawnSync } from "node:child_process";
3+
import { mkdtempSync, writeFileSync, mkdirSync } from "node:fs";
44
import { tmpdir } from "node:os";
55
import path from "node:path";
66
import test from "node:test";
@@ -10,6 +10,7 @@ import {
1010
evaluateFileSize,
1111
parseChangedFiles,
1212
resolveBaseRef,
13+
runFileSizeCheck,
1314
} from "./check-file-sizes-core.mjs";
1415

1516
function git(repo, ...args) {
@@ -108,16 +109,57 @@ test("an inherited oversized file may hold or shrink but not grow", () => {
108109
);
109110
});
110111

111-
test("fileOverrides raises the ceiling for a named path", () => {
112-
// Verify that the evaluateFileSize helper still uses the standard maxLines
113-
// when no override applies, and that runFileSizeCheck accepts fileOverrides
114-
// without breaking existing behavior.
115-
assert.deepEqual(
116-
evaluateFileSize({ baseLines: null, candidateLines: 1048, maxLines: 1000 }),
117-
{ limit: 1000, violates: true },
118-
);
119-
assert.deepEqual(
120-
evaluateFileSize({ baseLines: null, candidateLines: 1048, maxLines: 1200 }),
121-
{ limit: 1200, violates: false },
122-
);
112+
test("fileOverrides raises the ceiling for a named path without leaking to other files", async () => {
113+
// Build a minimal temp git repo:
114+
// repo/
115+
// desktop/ ← projectRoot
116+
// src/
117+
// governed.ts ← 1 line over the 1000-line default ceiling
118+
// exempted.ts ← same size, but named in fileOverrides (ceiling 1200)
119+
// origin/main at the initial empty commit ← base for diff
120+
const repoRoot = mkdtempSync(path.join(tmpdir(), "file-size-override-"));
121+
const projectRoot = path.join(repoRoot, "desktop");
122+
const srcDir = path.join(projectRoot, "src");
123+
mkdirSync(srcDir, { recursive: true });
124+
125+
function gitRepo(...args) {
126+
return execFileSync("git", args, { cwd: repoRoot, encoding: "utf8" });
127+
}
128+
129+
gitRepo("init", "-b", "main");
130+
gitRepo("config", "user.name", "Test");
131+
gitRepo("config", "user.email", "[email protected]");
132+
gitRepo("commit", "--allow-empty", "-m", "base");
133+
gitRepo("remote", "add", "origin", repoRoot);
134+
gitRepo("fetch", "origin", "main:refs/remotes/origin/main");
135+
136+
// Write both files: 1001 lines each (1 over the 1000-line default ceiling)
137+
const content = "x\n".repeat(1001);
138+
writeFileSync(path.join(srcDir, "governed.ts"), content);
139+
writeFileSync(path.join(srcDir, "exempted.ts"), content);
140+
gitRepo("add", ".");
141+
142+
const prevExitCode = process.exitCode;
143+
const errors = [];
144+
const origConsoleError = console.error;
145+
console.error = (...args) => errors.push(args.join(" "));
146+
147+
try {
148+
await runFileSizeCheck({
149+
projectRoot,
150+
rules: [{ root: "src", extensions: new Set([".ts"]), maxLines: 1000 }],
151+
label: "test",
152+
fileOverrides: { "src/exempted.ts": 1200 },
153+
});
154+
155+
// governed.ts (1001 lines, ceiling 1000) must violate
156+
assert.equal(process.exitCode, 1, "governed.ts over default ceiling should fail");
157+
const combined = errors.join("\n");
158+
assert.ok(combined.includes("governed.ts"), "violation message should name governed.ts");
159+
// exempted.ts (1001 lines, override ceiling 1200) must NOT be in the violation list
160+
assert.ok(!combined.includes("exempted.ts"), "exempted.ts under override ceiling should not appear");
161+
} finally {
162+
process.exitCode = prevExitCode;
163+
console.error = origConsoleError;
164+
}
123165
});

‎scripts/generate-model-capabilities.mjs‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,12 @@ for (const rule of manifest.family_rules) {
344344
VALID_NORM_POLICIES,
345345
`rule ${rule.id} normalization_policy`,
346346
);
347+
if (Object.prototype.hasOwnProperty.call(rule, "registry_label")) {
348+
throw new Error(
349+
`rule ${rule.id}: registry_label is not allowed on family rules; ` +
350+
`registry_label is exact-record-only (display rule (a))`,
351+
);
352+
}
347353
}
348354

349355
// Validate provider_fallbacks
@@ -612,7 +618,7 @@ function resolve(provider, rawModelId) {
612618
_provenance: {
613619
source: "exact",
614620
exact_key: `${provider}::${rawModelId}`,
615-
registry_label: labelFromExact ? "exact_record" : (familyProv ? `family:${familyProv.rule_id}@${familyProv.rule_priority}` : "absent"),
621+
registry_label: labelFromExact ? "exact_record" : "absent",
616622
supported_efforts: effortsFromExact ? "exact_record" : (familyProv ? `family:${familyProv.rule_id}@${familyProv.rule_priority}` : "fallback"),
617623
databricks_v2_wire_route: routeFromExact ? "exact_record" : (familyProv ? `family:${familyProv.rule_id}@${familyProv.rule_priority}` : "fallback"),
618624
thinking_mode: modeFromExact ? "exact_record" : (familyProv ? `family:${familyProv.rule_id}@${familyProv.rule_priority}` : "fallback"),
@@ -625,7 +631,7 @@ function resolve(provider, rawModelId) {
625631
// Step 2: provider-scoped family rules on normalized alias
626632
const normalizedAlias = stripCatalogPrefix(rawModelId ?? "");
627633
const familyResult = resolveFamilyRules(provider, normalizedAlias, rawModelId);
628-
if (familyResult) return familyResult;
634+
if (familyResult) return { ...familyResult, registry_label: null };
629635

630636
// Step 3: provider fallback
631637
const fallback = getProviderFallback(provider, isBlank);
@@ -645,7 +651,6 @@ function resolveFamilyRules(provider, normalizedAlias, rawModelId) {
645651
? rule.databricks_v2_wire_route
646652
: "not-applicable";
647653
return {
648-
registry_label: rule.registry_label ?? null,
649654
thinking_mode: rule.thinking_mode,
650655
supported_efforts: rule.supported_efforts,
651656
default_effort: rule.default_effort,
@@ -1083,7 +1088,7 @@ function emitRustFamilyResolverFn() {
10831088
arms.push(
10841089
` // rule: ${rule.id}, provider: ${provider}, priority: ${rule.match_priority}\n if provider == "${provider}" && (${matchExpr}) {\n return Some(\n${emitRustCapabilityResult(
10851090
{
1086-
registry_label: rule.registry_label ?? null,
1091+
registry_label: null,
10871092
thinking_mode: rule.thinking_mode,
10881093
supported_efforts: rule.supported_efforts,
10891094
default_effort: rule.default_effort,
@@ -1323,7 +1328,7 @@ function emitTsFamilyResolver() {
13231328
? rule.databricks_v2_wire_route
13241329
: "not-applicable";
13251330
const clean = {
1326-
registry_label: rule.registry_label ?? null,
1331+
registry_label: null,
13271332
thinking_mode: rule.thinking_mode,
13281333
supported_efforts: rule.supported_efforts,
13291334
default_effort: rule.default_effort,

‎scripts/test-manifest-validator.mjs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,19 @@ test("schema-negative: duplicate family rule id is rejected", () => {
183183
);
184184
});
185185

186+
// ---------------------------------------------------------------------------
187+
// Rule: registry_label on a family rule is rejected (display rule (a))
188+
// ---------------------------------------------------------------------------
189+
test("schema-negative: registry_label on a family rule is rejected", () => {
190+
assertRejects(
191+
"family rule registry_label forbidden",
192+
mutate((m) => {
193+
m.family_rules[0].registry_label = "Family Masquerade";
194+
}),
195+
"registry_label is not allowed on family rules",
196+
);
197+
});
198+
186199
// ---------------------------------------------------------------------------
187200
// Rule: duplicate exact_record (provider, raw_model_id) key
188201
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)