mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-15 18:59:33 +01:00
fix(palette): offer a Docker case's container agents in Cmd+K, as the Run menu does
The new-session row's agents now go through _runModeAvailableForCase (session-ui.js), the rule extracted from _refreshRunModeAvailability, for the case the row launches in: a Docker case offers what its container has (live probe, else availableModes, else ungated), so a container-only Run mode is offered and is the row's default again. The default is resolved per render (pick, else the Run button's mode, else the first offered), so a query that moves the row to another case starts on the Run mode when that case offers it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
fac47f067d
commit
f6e21a7c50
4 files changed
+244
-61
No files matched your search
@@ -3,7 +3,7 @@ import { resolve } from 'node:path';
|
||||
import vm from 'node:vm';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
function loadPaletteHarness(overrides: Record<string, any> = {}) {
|
||||
function loadPaletteHarness(overrides: Record<string, any> = {}, { sessionUi = false } = {}) {
|
||||
const elements: Record<string, any> = {};
|
||||
const listeners: Record<string, (event: any) => void> = {};
|
||||
const CodemanApp = function CodemanApp(this: any) {};
|
||||
@@ -70,6 +70,12 @@ function loadPaletteHarness(overrides: Record<string, any> = {}) {
|
||||
|
||||
const panelsUi = readFileSync(resolve(import.meta.dirname, '../src/web/public/panels-ui.js'), 'utf8');
|
||||
vm.runInContext(panelsUi, context, { filename: 'panels-ui.js' });
|
||||
// session-ui.js loads after panels-ui.js in index.html. Opt-in: it also brings
|
||||
// the real selectQuickStartCase, which the case-pick tests above stub around.
|
||||
if (sessionUi) {
|
||||
const sessionUiSrc = readFileSync(resolve(import.meta.dirname, '../src/web/public/session-ui.js'), 'utf8');
|
||||
vm.runInContext(sessionUiSrc, context, { filename: 'session-ui.js' });
|
||||
}
|
||||
|
||||
const app = new (CodemanApp as any)();
|
||||
app.sessions = new Map([
|
||||
@@ -350,9 +356,12 @@ const PALETTE_CATALOG = [
|
||||
];
|
||||
|
||||
/** A palette whose agent list comes from the injected CLI catalog, codex not installed. */
|
||||
function loadAgentPalette(catalog: any[] = PALETTE_CATALOG) {
|
||||
function loadAgentPalette(catalog: any[] = PALETTE_CATALOG, options: { sessionUi?: boolean } = {}) {
|
||||
const available: Record<string, boolean> = { claude: true, shell: true, codex: false, opencode: true, gemini: true };
|
||||
const harness = loadPaletteHarness({ window: { __codemanCliCatalog: catalog, __codemanCliAvailable: available } });
|
||||
const harness = loadPaletteHarness(
|
||||
{ window: { __codemanCliCatalog: catalog, __codemanCliAvailable: available } },
|
||||
options
|
||||
);
|
||||
// Mirrors settings-ui.js isCliAvailable(): unknown reads as available.
|
||||
harness.app.isCliAvailable = (id: string) => available[id] !== false;
|
||||
harness.app._runMode = 'claude';
|
||||
@@ -514,9 +523,11 @@ describe('Command-K new-session agent picker', () => {
|
||||
expect(elements.commandPaletteList.innerHTML).not.toContain('data-palette-agent-cycle');
|
||||
});
|
||||
|
||||
it('keeps the Run button mode when the host offers a single other agent (a Docker case)', async () => {
|
||||
// The host has only Shell, while a Docker case's Run menu put the Run
|
||||
// button on the container's claude: Enter must still start claude.
|
||||
it('keeps the Run button mode when a single other agent is offered', async () => {
|
||||
// Only Shell is offered while the Run button names claude: with nothing to
|
||||
// pick between, the row keeps the Run button's mode, as before the picker
|
||||
// existed, so run() answers a missing claude with its install hint instead
|
||||
// of the palette silently starting Shell.
|
||||
const { app, elements } = loadAgentPalette(PALETTE_CATALOG.slice(0, 2));
|
||||
app.isCliAvailable = (id: string) => id !== 'claude';
|
||||
let modeDuringRun: string | undefined;
|
||||
@@ -537,6 +548,128 @@ describe('Command-K new-session agent picker', () => {
|
||||
});
|
||||
});
|
||||
|
||||
/** The toolbar Run menu's entries, as renderRegistryRunOptions() and index.html draw them. */
|
||||
function fakeRunMenu(modes: string[]) {
|
||||
const options = modes.map((mode) => ({ dataset: { mode }, style: { display: 'PRISTINE' } }));
|
||||
return {
|
||||
options,
|
||||
querySelectorAll: (selector: string) => (selector === '.run-mode-option[data-mode]' ? options : []),
|
||||
querySelector: () => null,
|
||||
prepend: vi.fn(),
|
||||
};
|
||||
}
|
||||
const shownByRunMenu = (menu: ReturnType<typeof fakeRunMenu>) =>
|
||||
menu.options.filter((option) => option.style.display === 'flex').map((option) => option.dataset.mode);
|
||||
|
||||
/**
|
||||
* A palette with session-ui.js loaded, so the agent list goes through the Run
|
||||
* menu's real availability rule. Host flags as in loadAgentPalette (no codex
|
||||
* here); the active case is a Docker case with the given `docker` record.
|
||||
*/
|
||||
function loadDockerPalette(docker: Record<string, any>) {
|
||||
const harness = loadAgentPalette(PALETTE_CATALOG, { sessionUi: true });
|
||||
harness.app.cases = [
|
||||
{ name: 'plex-previews' },
|
||||
{ name: 'far', location: 'remote' },
|
||||
{ name: 'dock', location: 'docker', docker },
|
||||
];
|
||||
harness.elements.quickStartCase.value = 'dock';
|
||||
harness.app.selectQuickStartCase = vi.fn();
|
||||
// The Run menu's live container probe is a docker exec round trip; here it
|
||||
// never lands, which is also what a probe still in flight looks like.
|
||||
harness.app._probeDockerCaseModes = vi.fn();
|
||||
return harness;
|
||||
}
|
||||
|
||||
const ADOPTED = { owned: false, hostId: 'local', container: 'dev-box', availableModes: ['shell', 'claude', 'codex'] };
|
||||
|
||||
describe('Command-K new-session agents follow the Run menu for the row case', () => {
|
||||
it('offers a Docker case its container agents and starts on a container-only Run mode', async () => {
|
||||
// codex is missing on the host but ships in the container, and the Run
|
||||
// button is on it (picked from the Run menu, which gates on the container).
|
||||
const { app, elements } = loadDockerPalette(ADOPTED);
|
||||
app._runMode = 'codex';
|
||||
let modeDuringRun: string | undefined;
|
||||
app.run = vi.fn(async () => {
|
||||
modeDuringRun = app._runMode;
|
||||
});
|
||||
|
||||
app.openCommandPalette();
|
||||
elements.commandPaletteSearch.value = 'nomatch';
|
||||
app.renderCommandPalette();
|
||||
const index = app.commandPaletteItems.findIndex((i: any) => i.type === 'new-session');
|
||||
|
||||
expect(app._commandPaletteAgentChoices('dock').map((c: any) => c.id)).toEqual(['claude', 'shell', 'codex']);
|
||||
expect(app.commandPaletteItems[index]).toMatchObject({
|
||||
caseName: 'dock',
|
||||
mode: 'codex',
|
||||
subtitle: 'Run Codex in dock',
|
||||
});
|
||||
expect(elements.commandPaletteList.innerHTML).toContain('run-mode-dot codex');
|
||||
|
||||
// The same agents the Run menu shows for this case.
|
||||
const menu = fakeRunMenu(['claude', 'codex', 'opencode', 'shell']);
|
||||
app._refreshRunModeAvailability(menu);
|
||||
expect(shownByRunMenu(menu)).toEqual(['claude', 'codex']);
|
||||
|
||||
await app.activateCommandPaletteItem(index);
|
||||
expect(modeDuringRun).toBe('codex');
|
||||
expect(app._runMode).toBe('codex');
|
||||
});
|
||||
|
||||
it('offers every enabled agent for an owned container nothing has probed yet, and then follows the probe', () => {
|
||||
// An owned container runs the base image, which ships every CLI, and before
|
||||
// its first session there is nothing to probe: like the Run menu, an unknown
|
||||
// list does not gate, so a probe still in flight cannot empty the row.
|
||||
const { app } = loadDockerPalette({ owned: true, hostId: 'local', container: 'codeman-dock' });
|
||||
app._runMode = 'codex';
|
||||
|
||||
app.openCommandPalette();
|
||||
|
||||
expect(app._commandPaletteAgentChoices('dock').map((c: any) => c.id)).toEqual([
|
||||
'claude',
|
||||
'shell',
|
||||
'codex',
|
||||
'opencode',
|
||||
]);
|
||||
expect(app.commandPaletteItems.find((i: any) => i.type === 'new-session').mode).toBe('codex');
|
||||
// The palette reads what the Run menu learned; it never starts a docker exec itself.
|
||||
expect(app._probeDockerCaseModes).not.toHaveBeenCalled();
|
||||
const menu = fakeRunMenu(['claude', 'codex', 'opencode', 'shell']);
|
||||
app._refreshRunModeAvailability(menu);
|
||||
expect(shownByRunMenu(menu)).toEqual(['claude', 'codex', 'opencode']);
|
||||
|
||||
// Once the live probe has landed, both follow it.
|
||||
app._dockerCaseModes = { dock: ['shell', 'opencode'] };
|
||||
expect(app._commandPaletteAgentChoices('dock').map((c: any) => c.id)).toEqual(['shell', 'opencode']);
|
||||
app._refreshRunModeAvailability(menu);
|
||||
expect(shownByRunMenu(menu)).toEqual(['opencode']);
|
||||
});
|
||||
|
||||
it('keeps the host rule for local and remote cases, and follows the case the query names', () => {
|
||||
const { app, elements } = loadDockerPalette(ADOPTED);
|
||||
elements.quickStartCase.value = 'plex-previews';
|
||||
app._runMode = 'codex'; // missing on the host
|
||||
const row = () => app.commandPaletteItems.find((i: any) => i.type === 'new-session');
|
||||
|
||||
app.openCommandPalette();
|
||||
|
||||
expect(app._commandPaletteAgentChoices('plex-previews').map((c: any) => c.id)).toEqual([
|
||||
'claude',
|
||||
'shell',
|
||||
'opencode',
|
||||
]);
|
||||
expect(app._commandPaletteAgentChoices('far').map((c: any) => c.id)).toEqual(['claude', 'shell', 'opencode']);
|
||||
expect(row()).toMatchObject({ caseName: 'plex-previews', mode: 'claude' });
|
||||
|
||||
// Typing the Docker case's name moves the row there, where the container
|
||||
// has the Run button's codex, so the row starts on it.
|
||||
elements.commandPaletteSearch.value = 'dock';
|
||||
app.renderCommandPalette();
|
||||
expect(row()).toMatchObject({ caseName: 'dock', mode: 'codex' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('Session Manager unified list', () => {
|
||||
it('maps UnifiedSessionItem fields to the history-record shape and routes clicks by liveness', async () => {
|
||||
const { app, elements } = loadPaletteHarness({
|
||||
|
||||
@@ -299,8 +299,8 @@ describe('adopted container: run modes come from the CONTAINER, not the host', (
|
||||
* exactly what happened twice: a comment added above the assertion pushed the
|
||||
* asserted line past the cutoff and CI failed on a test that was still true.
|
||||
*/
|
||||
const refreshFn = (src) => {
|
||||
const start = src.indexOf('_refreshRunModeAvailability(menu) {');
|
||||
const methodFn = (src, signature) => {
|
||||
const start = src.indexOf(signature);
|
||||
expect(start).toBeGreaterThan(-1);
|
||||
const open = src.indexOf('{', start);
|
||||
let depth = 0;
|
||||
@@ -308,23 +308,30 @@ describe('adopted container: run modes come from the CONTAINER, not the host', (
|
||||
if (src[i] === '{') depth++;
|
||||
else if (src[i] === '}' && --depth === 0) return src.slice(start, i + 1);
|
||||
}
|
||||
throw new Error('unbalanced braces in _refreshRunModeAvailability');
|
||||
throw new Error(`unbalanced braces in ${signature}`);
|
||||
};
|
||||
// The per-mode decision lives in ONE helper, shared by the Run menu and the
|
||||
// Cmd+K new-session row (panels-ui.js), so the two cannot drift apart.
|
||||
const ruleFn = (src) => methodFn(src, '_runModeAvailableForCase(mode, caseName) {');
|
||||
|
||||
it('gates a docker case on availableModes instead of host CLI probes', () => {
|
||||
// The sandbox host had codex but no claude while the adopted container had
|
||||
// claude and no codex; gating on the host hid the only mode that worked.
|
||||
const fn = refreshFn(ui);
|
||||
const fn = ruleFn(ui);
|
||||
expect(fn).toContain("location === 'docker'");
|
||||
expect(fn).toContain('availableModes');
|
||||
// Non-docker cases must keep the original host probe (#201).
|
||||
expect(fn).toContain('this.isCliAvailable(mode)');
|
||||
// And the Run menu asks that helper rather than keeping its own copy.
|
||||
expect(methodFn(ui, '_refreshRunModeAvailability(menu) {')).toContain(
|
||||
'this._runModeAvailableForCase(mode, caseName)'
|
||||
);
|
||||
});
|
||||
|
||||
it('leaves an owned container ungated when nothing was probed', () => {
|
||||
// Our base image ships every CLI, so an absent list means "unknown", and
|
||||
// treating unknown as "nothing available" would empty the menu.
|
||||
expect(refreshFn(ui)).toMatch(/containerModes \?[^:]*:\s*true/);
|
||||
expect(ruleFn(ui)).toMatch(/containerModes \?[^:]*:\s*true/);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user