Skip to content

Commit 0df51fd

Browse files
committed
fix(grok): preserve retired orphan model tables
1 parent 1a18ace commit 0df51fd

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎src/grok/inject.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,11 @@ export function injectGrokConfig(
395395
// Adopt our own pre-fence entries (#511) BEFORE reserving user aliases, so the stale
396396
// duplicate is replaced instead of routed around forever. Runs inside the normalized
397397
// window so the user's dominant EOL is still restored below.
398-
const orphans = findOpencodexOrphans(originalContent, originalRegion);
398+
// Use the full catalog, not the emitted subset: an explicitly excluded current model must
399+
// still lose its stale unfenced table, or that table would bypass the user's exclusion.
400+
const catalogModelIds = new Set(models.map(model => model.id));
401+
const orphans = findOpencodexOrphans(originalContent, originalRegion)
402+
.filter(orphan => orphan.modelId !== undefined && catalogModelIds.has(orphan.modelId));
399403
const content = removeOrphanTables(originalContent, orphans);
400404
// Removing bytes above the fence MOVES it: recompute rather than adjust arithmetic,
401405
// so the splice below cannot cut the file in the wrong place.

‎tests/grok-orphan-adoption.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ describe("Grok orphan adoption (#511)", () => {
150150
"[models]",
151151
'default = "ocx-retired"',
152152
"",
153+
"[ui]",
154+
'fork_secondary_model = "ocx-retired"',
155+
"",
153156
"[model.ocx-retired]",
154157
'model = "retired/model"',
155158
'base_url = "http://127.0.0.1:10100/v1"',
@@ -160,6 +163,37 @@ describe("Grok orphan adoption (#511)", () => {
160163
injectGrokConfig(10100, MODELS, { grokHome });
161164
const content = readFileSync(configPath, "utf8");
162165
expect(content).toContain('default = "ocx-retired"');
166+
expect(content).toContain('fork_secondary_model = "ocx-retired"');
167+
expect(content).toContain("[model.ocx-retired]");
168+
expect(content).toContain('model = "retired/model"');
169+
170+
const second = injectGrokConfig(10100, MODELS, { grokHome });
171+
expect(second).toMatchObject({ ok: true, changed: false });
172+
expect(readFileSync(configPath, "utf8")).toBe(content);
173+
});
174+
175+
test("keeps an owned-looking orphan whose model id is missing", () => {
176+
writeFileSync(configPath, [
177+
"[model.ocx-unknown]",
178+
'base_url = "http://127.0.0.1:10100/v1"',
179+
'api_key = "opencodex-loopback"',
180+
"",
181+
].join("\n"));
182+
183+
injectGrokConfig(10100, MODELS, { grokHome });
184+
const content = readFileSync(configPath, "utf8");
185+
expect(content).toContain("[model.ocx-unknown]");
186+
expect(content).toContain('api_key = "opencodex-loopback"');
187+
});
188+
189+
test("still removes a catalog orphan when that model is excluded", () => {
190+
writeOrphanedConfig();
191+
192+
injectGrokConfig(10100, MODELS, {
193+
grokHome,
194+
excluded: new Set(["gpt-5.6-sol"]),
195+
});
196+
expect(modelTables(readFileSync(configPath, "utf8"))).toEqual([]);
163197
});
164198

165199
// F7: the sweep must converge, or `changed` is meaningless to callers.

0 commit comments

Comments
 (0)