Browse Source

fix: clarify strip orchestrator model guard

Alvin Unreal 1 month ago
parent
commit
a12dc73aff

+ 15 - 1
src/config/strip-orchestrator-model.test.ts

@@ -72,7 +72,7 @@ describe('applyOrchestratorModelConfig', () => {
     expect(agents.orchestrator).toEqual({});
   });
 
-  test('retains an explicit runtime preset model over the file preset', () => {
+  test('skips stripping when the active runtime preset sets the orchestrator model', () => {
     const agents = {
       orchestrator: { model: 'openai/gpt-5', variant: 'high' },
     };
@@ -94,6 +94,20 @@ describe('applyOrchestratorModelConfig', () => {
     });
   });
 
+  test('leaves a primitive orchestrator config unchanged', () => {
+    const agents: Record<string, unknown> = { orchestrator: 'invalid' };
+
+    applyOrchestratorModelConfig({
+      agents,
+      enabled: true,
+      presets: undefined,
+      configPreset: undefined,
+      runtimePreset: null,
+    });
+
+    expect(agents.orchestrator).toBe('invalid');
+  });
+
   test('allows TUI state to capture the configured model and variant before stripping', () => {
     const agents = {
       orchestrator: { model: 'openai/gpt-5', variant: 'high' },

+ 6 - 4
src/config/strip-orchestrator-model.ts

@@ -1,5 +1,9 @@
 import type { PluginConfig, Preset } from './schema';
 
+function isRecord(value: unknown): value is Record<string, unknown> {
+  return typeof value === 'object' && value !== null && !Array.isArray(value);
+}
+
 export function stripOrchestratorModel(
   agents: Record<string, unknown>,
   enabled: boolean | undefined,
@@ -7,10 +11,8 @@ export function stripOrchestratorModel(
 ): void {
   if (enabled !== true || preset?.orchestrator?.model !== undefined) return;
 
-  const orchestrator = agents.orchestrator as
-    | Record<string, unknown>
-    | undefined;
-  if (!orchestrator) return;
+  const orchestrator = agents.orchestrator;
+  if (!isRecord(orchestrator)) return;
 
   delete orchestrator.model;
   delete orchestrator.variant;