mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-06 07:29:42 +02:00
feat(settings): show the Codex CLI tab only where codex is installed
Both settings on the App Settings "Codex CLI" tab (bypass approvals, animated status effects) are handed to `codex` at launch, so on an instance where the binary does not resolve the tab offers choices nothing can act on. Gate it on availability instead. renderIndexHtml injects window.__codemanCodexAvailable, mirroring the existing gesture-availability flag, and settings-ui.js hides the tab button when it is absent. Injected rather than fetched on modal open so the tab cannot flicker in and back out; isCodexAvailable() memoizes its PATH probe, so the per-render cost is nil. Installing codex later needs a restart, exactly like the /api/codex/status route that already backs the Run menu. Solo popups skip the probe since they have no settings modal. Only the tab BUTTON is toggled. The panel already carries .modal-tab-content.hidden unless it is the selected tab and openAppSettings() always reopens on Display, so an unreachable button keeps the panel unreachable. The inputs stay in the DOM and are still populated and read back on save, so a user without codex cannot silently wipe the codex preferences of an instance that has it. Animations stay off by default for new local Codex sessions. Verified in a browser on this host, which has no codex: the flag is absent, the Codex tab is hidden while the other tabs are unaffected, and saving App Settings with the tab hidden leaves codexAnimationsEnabled/codexDangerouslyBypassApprovals untouched. With the flag forced on, the tab appears, its panel opens, and toggling the visible slider persists. The openAppSettings coupling test was checked to fail when the call is removed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,16 @@
|
||||
*/
|
||||
import { describe, it, expect, afterEach, vi } from 'vitest';
|
||||
import { WebServer } from '../src/web/server.js';
|
||||
import { isCodexAvailable } from '../src/utils/codex-cli-resolver.js';
|
||||
|
||||
// renderIndexHtml probes the real PATH for `codex`, which would make the codex
|
||||
// assertions below depend on whatever happens to be installed on the machine
|
||||
// running the suite. Default to "not installed" so every OTHER test in this file
|
||||
// renders exactly as before, and opt in per test.
|
||||
vi.mock('../src/utils/codex-cli-resolver.js', () => ({
|
||||
isCodexAvailable: vi.fn(() => false),
|
||||
resolveCodexDir: vi.fn(() => null),
|
||||
}));
|
||||
|
||||
const TEMPLATE = [
|
||||
'<head>',
|
||||
@@ -86,6 +96,27 @@ describe('WebServer.renderIndexHtml', () => {
|
||||
expect(html).toContain('gesture-codeman.js');
|
||||
});
|
||||
|
||||
it('exposes codex availability so the App Settings Codex tab can be gated', async () => {
|
||||
vi.mocked(isCodexAvailable).mockReturnValue(true);
|
||||
const { server } = makeServer({});
|
||||
const html = await render(server);
|
||||
expect(html).toContain('window.__codemanCodexAvailable=true');
|
||||
});
|
||||
|
||||
it('omits the codex flag entirely when the codex binary does not resolve', async () => {
|
||||
vi.mocked(isCodexAvailable).mockReturnValue(false);
|
||||
const { server } = makeServer({});
|
||||
const html = await render(server);
|
||||
expect(html).not.toContain('__codemanCodexAvailable');
|
||||
});
|
||||
|
||||
it('skips the codex probe for a solo window, which has no settings modal', async () => {
|
||||
vi.mocked(isCodexAvailable).mockReturnValue(true);
|
||||
const { server } = makeServer({});
|
||||
const html = await render(server, 'sess-123');
|
||||
expect(html).not.toContain('__codemanCodexAvailable');
|
||||
});
|
||||
|
||||
it('does not expose gesture at all when CODEMAN_GESTURE is unset', async () => {
|
||||
delete process.env.CODEMAN_GESTURE;
|
||||
const { server } = makeServer({ gestureControlEnabled: true });
|
||||
|
||||
Reference in New Issue
Block a user