diff --git a/web/packages/agenta-entity-ui/src/DrillInView/SchemaControls/agentTemplate/useModelHarness.tsx b/web/packages/agenta-entity-ui/src/DrillInView/SchemaControls/agentTemplate/useModelHarness.tsx index 2b0c32a775..20e5e38037 100644 --- a/web/packages/agenta-entity-ui/src/DrillInView/SchemaControls/agentTemplate/useModelHarness.tsx +++ b/web/packages/agenta-entity-ui/src/DrillInView/SchemaControls/agentTemplate/useModelHarness.tsx @@ -85,6 +85,12 @@ function isPermissionPolicy(value: unknown): value is PermissionPolicy { return typeof value === "string" && PERMISSION_POLICY_VALUES.has(value) } +export function resolveHarnessKindValue(harness: {kind?: string} | null | undefined): string { + // default to the pi_core harness when none is set + const kind = harness?.kind + return typeof kind === "string" ? kind : "pi_core" +} + export function useModelHarness({ schema, config, @@ -171,7 +177,7 @@ export function useModelHarness({ // carries through extra keys (e.g. `extras`) so a form edit never silently drops them. The picker // is harness-filtered: selecting a model sets BOTH the model id and its provider, fed by the // `/inspect` capability map below. - const harnessValue = typeof harness.kind === "string" ? (harness.kind as string) : null + const harnessValue = resolveHarnessKindValue(harness) const isPiHarness = harnessValue === "pi_core" || harnessValue === "pi_agenta" const llm = config.llm const modelId = useMemo(() => modelIdFromConfig(llm), [llm]) @@ -368,7 +374,7 @@ export function useModelHarness({ // names the model the way the picker did. const modelSummary = [ - enumLabel(harnessProps.kind, harness.kind), + enumLabel(harnessProps.kind, resolveHarnessKindValue(harness)), modelLabel(capabilities, harnessValue, modelId) ?? enumLabel(props.llm, modelId), ] .filter(Boolean) @@ -822,7 +828,7 @@ export function useModelHarness({ setSection("harness", {...harness, kind: v})} withTooltip={withTooltip} disabled={disabled} diff --git a/web/packages/agenta-entity-ui/tests/unit/useModelHarness.test.ts b/web/packages/agenta-entity-ui/tests/unit/useModelHarness.test.ts new file mode 100644 index 0000000000..dccef8fca7 --- /dev/null +++ b/web/packages/agenta-entity-ui/tests/unit/useModelHarness.test.ts @@ -0,0 +1,23 @@ +/** + * Unit tests for the resolveHarnessKindValue function used by the model harness UI. + * + * These tests lock in the fallback behavior for omitted or undefined harness values and confirm + * that explicit harness selections such as `pi_agenta` and `claude` are preserved unchanged. + * Runs under @agenta/entity-ui's own vitest runner. + */ +import {describe, expect, it} from "vitest" + +import {resolveHarnessKindValue} from "../../src/DrillInView/SchemaControls/agentTemplate/useModelHarness" + +describe("resolveHarnessKindValue", () => { + it("defaults an omitted harness kind to pi_core", () => { + expect(resolveHarnessKindValue({})).toBe("pi_core") + expect(resolveHarnessKindValue({kind: undefined})).toBe("pi_core") + }) + + it("preserves explicit harness kinds", () => { + expect(resolveHarnessKindValue({kind: "pi_agenta"})).toBe("pi_agenta") + expect(resolveHarnessKindValue({kind: "claude"})).toBe("claude") + expect(resolveHarnessKindValue({kind: "codex"})).toBe("codex") + }) +})