Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions desktop/src/features/agents/ui/effortPicker.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,19 @@ test("current effort preselects the matching option", () => {
assert.equal(state.selectValue, "high");
});

test("an unknown current effort falls back to the adapter-default sentinel", () => {
test("an unavailable saved effort stays visible without becoming the default", () => {
const state = effortPickerState({
backend: localBackend,
effortConfigId: "thought_level",
effortOptions: options,
currentEffort: "extreme",
});
assert.equal(state.selectValue, EFFORT_DEFAULT_DROPDOWN_VALUE);
assert.equal(state.selectValue, "extreme");
assert.deepEqual(state.options.at(-1), {
label: "extreme (unavailable)",
value: "extreme",
disabled: true,
});
});

test("a null current effort selects the adapter-default sentinel", () => {
Expand Down
20 changes: 13 additions & 7 deletions desktop/src/features/agents/ui/effortPicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@ export function effortPickerState({
})),
];

// Preselect the currently-configured effort when it maps to a known option;
// otherwise fall back to the adapter-default sentinel (also the null case).
// Preserve an explicit value when the adapter catalog changes. Presenting
// it as the default would hide the configured override without clearing it.
const trimmed = currentEffort?.trim() ?? "";
const selectValue =
trimmed.length > 0 &&
(effortOptions ?? []).some((option) => option.value === trimmed)
? trimmed
: EFFORT_DEFAULT_DROPDOWN_VALUE;
if (
trimmed &&
!(effortOptions ?? []).some((option) => option.value === trimmed)
) {
options.push({
label: `${trimmed} (unavailable)`,
value: trimmed,
disabled: true,
});
}
const selectValue = trimmed || EFFORT_DEFAULT_DROPDOWN_VALUE;

return { visible, options, selectValue };
}
Expand Down
38 changes: 38 additions & 0 deletions desktop/src/features/agents/ui/effortPickerField.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import assert from "node:assert/strict";
import test from "node:test";
import React from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { EffortPickerField } from "./EffortPickerField.tsx";

const options = [{ value: "low", displayName: "Low" }];
function render(value, effortOptions = options) {
return renderToStaticMarkup(
React.createElement(EffortPickerField, {
agent: { backend: { type: "local" } },
config: { effortConfigId: "depth", effortOptions },
value,
disabled: false,
onChange: () =>
assert.fail("Rendering must not rewrite the saved effort"),
}),
);
}

test("the real effort trigger discloses an unavailable explicit value", () => {
const html = render("high");
assert.match(html, /high \(unavailable\)/);
assert.doesNotMatch(html, />Adapter default</);
});

test("catalog recovery restores the adapter label without changing the value", () => {
const html = render("high", [
...options,
{ value: "high", displayName: "High" },
]);
assert.match(html, />High</);
assert.doesNotMatch(html, /unavailable/);
});

test("only an unset effort displays the adapter default", () => {
assert.match(render(null), />Adapter default</);
});