Repository navigation
fix(settings): expose the Advisor default setting and wire it to new chats (fixes #323) #557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import "../tests/setup-dom.mjs"; | ||
| import assert from "node:assert/strict"; | ||
| import test from "node:test"; | ||
| import { act, createElement } from "react"; | ||
| import { createRoot } from "react-dom/client"; | ||
| import { SettingsConfig } from "./SettingsConfig"; | ||
|
|
||
| const noop = () => {}; | ||
|
|
||
| /** Render the real Agent & Intelligence panel with a stubbed settings API. */ | ||
| async function renderIntelligenceTab(t, { advisorEnabled = true } = {}) { | ||
| const puts = []; | ||
| const originalFetch = globalThis.fetch; | ||
| globalThis.fetch = async (url, options = {}) => { | ||
| if (String(url) === "/api/omp-settings" && (options.method ?? "GET") === "PUT") { | ||
| const settings = JSON.parse(options.body).settings; | ||
| puts.push(settings); | ||
| return Response.json({ success: true, settings }); | ||
| } | ||
| if (String(url) === "/api/omp-settings") return Response.json({ settings: { advisor: { enabled: advisorEnabled } } }); | ||
| return Response.json({}); | ||
| }; | ||
| const container = document.createElement("div"); | ||
| document.body.append(container); | ||
| const root = createRoot(container); | ||
| t.after(() => { | ||
| act(() => root.unmount()); | ||
| container.remove(); | ||
| globalThis.fetch = originalFetch; | ||
| }); | ||
| await act(async () => { | ||
| root.render(createElement(SettingsConfig, { | ||
| activeTab: "intelligence", | ||
| toolCallsDefaultCollapsed: false, onToolCallsDefaultCollapsedChange: noop, | ||
| hideToolActivity: false, onHideToolActivityChange: noop, | ||
| expandThinkingByDefault: false, onExpandThinkingByDefaultChange: noop, onHideThinkingBlockChange: noop, | ||
| providerUsageVisible: false, onProviderUsageVisibleChange: noop, | ||
| scopeNativeSelectAll: false, onScopeNativeSelectAllChange: noop, | ||
| openUrlAutomatically: false, onOpenUrlAutomaticallyChange: noop, | ||
| cwd: null, remoteHost: false, sessionId: null, | ||
| onModelsSaved: noop, onPluginsReloaded: noop, | ||
| appUpdate: null, onRefreshAppUpdate: async () => null, | ||
| onRequestAppUpdate: noop, onSelectTab: noop, onClose: noop, | ||
| })); | ||
| }); | ||
| await act(() => new Promise((resolve) => setTimeout(resolve, 20))); | ||
| return { container, puts }; | ||
| } | ||
|
|
||
| const advisorSwitch = (container) => container.querySelector('[data-search-id="advisor-enabled"] button[role="switch"]'); | ||
|
|
||
| test("Agent & Intelligence exposes the Advisor default and persists it", async (t) => { | ||
| const { container, puts } = await renderIntelligenceTab(t, { advisorEnabled: true }); | ||
| assert.ok(container.textContent.includes("Advisor"), "no Advisor section in the intelligence tab"); | ||
| const toggle = advisorSwitch(container); | ||
| assert.ok(toggle, "no Advisor toggle"); | ||
| assert.equal(toggle.getAttribute("aria-checked"), "true"); | ||
| act(() => toggle.click()); | ||
| await act(() => new Promise((resolve) => setTimeout(resolve, 50))); | ||
| assert.ok(puts.length >= 1, "toggling Advisor sent no PUT"); | ||
| assert.equal(puts.at(-1).advisor.enabled, false); | ||
| }); | ||
|
|
||
| test("the Advisor toggle reflects a disabled global default", async (t) => { | ||
| const { container } = await renderIntelligenceTab(t, { advisorEnabled: false }); | ||
| const toggle = advisorSwitch(container); | ||
| assert.ok(toggle, "no Advisor toggle"); | ||
| assert.equal(toggle.getAttribute("aria-checked"), "false"); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update
advisorDefaultafter an in-page settings save.If the user enables Advisor in Settings and then closes Settings,
advisorDefaultremains false. This loader runs only on mount or window focus.SettingsConfighas no callback that updates the parent after saving. Subsequent new chats therefore receive the old default until another focus event or reload.Update the parent from the successful settings save, or refresh the default when Settings closes. Apply this for both enabling and disabling.