mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-24 00:50:44 +00:00
Codex P2: resolveWorkspaceTabLabel treated any workspace whose title equals "Workspace" as an untouched default and replaced it with a host label — so a workspace a user renamed to "Workspace" (or a snippet named "Workspace") lost its chosen name. Add an explicit Workspace.autoTitle flag. It is authoritative when present: - set false on user rename, snippet-created, named "New Workspace", and any createWorkspaceFromTargets call given an explicit name; - absent/true means the tab may derive a host label. Legacy workspaces without the flag fall back to the old default-title string check, so already-open default splits still get host labels and previously renamed workspaces keep their names. - domain/models/workspace.ts: add autoTitle field. - domain/workspace.ts: thread autoTitle through createWorkspaceFromSessionIds. - application/state/useSessionState.ts: mark rename / snippet / named creation paths as explicit; createWorkspaceFromTargets takes an optional name and only marks custom when one is given. - domain/sessionTabTitle.ts: derive only when autoTitle (with legacy string fallback); tests for explicit "Workspace" name and explicit auto-title.
202 lines
6.1 KiB
TypeScript
202 lines
6.1 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import {
|
|
DEFAULT_WORKSPACE_TITLE,
|
|
getSessionConnectionLabel,
|
|
resolveCodingCliProviderIconUpdate,
|
|
resolveSessionTabTitle,
|
|
resolveWorkspaceTabLabel,
|
|
shouldUpdateCodingCliTabIcon,
|
|
} from './sessionTabTitle';
|
|
|
|
test('getSessionConnectionLabel prefers customName over hostLabel', () => {
|
|
assert.equal(
|
|
getSessionConnectionLabel({ customName: 'Prod', hostLabel: 'web-01' }),
|
|
'Prod',
|
|
);
|
|
assert.equal(
|
|
getSessionConnectionLabel({ hostLabel: 'web-01' }),
|
|
'web-01',
|
|
);
|
|
});
|
|
|
|
test('resolveSessionTabTitle ignores dynamic title for non-agent sessions', () => {
|
|
assert.equal(
|
|
resolveSessionTabTitle(
|
|
{ hostLabel: 'web-01', dynamicTitle: 'root@v2022:/var/log' },
|
|
),
|
|
'web-01',
|
|
);
|
|
});
|
|
|
|
test('resolveSessionTabTitle uses dynamic title for agent sessions', () => {
|
|
assert.equal(
|
|
resolveSessionTabTitle(
|
|
{ hostLabel: 'web-01', dynamicTitle: 'claude: refactor auth', codingCliProviderId: 'claude' },
|
|
),
|
|
'claude: refactor auth',
|
|
);
|
|
});
|
|
|
|
test('resolveSessionTabTitle uses dynamic title for all sessions in all mode', () => {
|
|
assert.equal(
|
|
resolveSessionTabTitle(
|
|
{ hostLabel: 'web-01', dynamicTitle: 'root@v2022:/var/log' },
|
|
'all',
|
|
),
|
|
'root@v2022:/var/log',
|
|
);
|
|
});
|
|
|
|
test('resolveSessionTabTitle disables dynamic titles in off mode', () => {
|
|
assert.equal(
|
|
resolveSessionTabTitle(
|
|
{ hostLabel: 'web-01', dynamicTitle: 'claude: refactor auth', codingCliProviderId: 'claude' },
|
|
'off',
|
|
),
|
|
'web-01',
|
|
);
|
|
});
|
|
|
|
test('resolveSessionTabTitle falls back to connection label when dynamic title is empty', () => {
|
|
assert.equal(
|
|
resolveSessionTabTitle({ hostLabel: 'web-01', dynamicTitle: ' ' }),
|
|
'web-01',
|
|
);
|
|
});
|
|
|
|
test('resolveSessionTabTitle prefers user customName over dynamic title', () => {
|
|
assert.equal(
|
|
resolveSessionTabTitle(
|
|
{ customName: 'Prod deploy', hostLabel: 'web-01', dynamicTitle: 'claude: refactor auth' },
|
|
),
|
|
'Prod deploy',
|
|
);
|
|
});
|
|
|
|
test('resolveSessionTabTitle strips agent spinner prefixes from dynamic titles', () => {
|
|
assert.equal(
|
|
resolveSessionTabTitle(
|
|
{ hostLabel: 'web-01', dynamicTitle: '⠋ Droid', codingCliProviderId: 'droid' },
|
|
),
|
|
'Droid',
|
|
);
|
|
});
|
|
|
|
test('coding CLI icon updates stop without clearing the current icon when dynamic titles are off', () => {
|
|
assert.equal(shouldUpdateCodingCliTabIcon('off'), false);
|
|
assert.equal(shouldUpdateCodingCliTabIcon('agent'), true);
|
|
assert.equal(shouldUpdateCodingCliTabIcon('all'), true);
|
|
|
|
assert.equal(resolveCodingCliProviderIconUpdate({
|
|
dynamicTabTitleMode: 'off',
|
|
currentProviderId: 'claude',
|
|
nextProviderId: null,
|
|
}), undefined);
|
|
assert.equal(resolveCodingCliProviderIconUpdate({
|
|
dynamicTabTitleMode: 'off',
|
|
currentProviderId: 'claude',
|
|
nextProviderId: 'opencode',
|
|
}), undefined);
|
|
assert.equal(resolveCodingCliProviderIconUpdate({
|
|
dynamicTabTitleMode: 'agent',
|
|
currentProviderId: 'claude',
|
|
nextProviderId: null,
|
|
}), null);
|
|
});
|
|
|
|
test('resolveWorkspaceTabLabel keeps a user-renamed workspace title', () => {
|
|
assert.equal(
|
|
resolveWorkspaceTabLabel(
|
|
{ title: 'My Cluster', focusedSessionId: 's1' },
|
|
[{ id: 's1', hostLabel: 'web-01', hostId: 'host-web' }],
|
|
),
|
|
'My Cluster',
|
|
);
|
|
});
|
|
|
|
test('resolveWorkspaceTabLabel derives the focused host name from a default-title workspace', () => {
|
|
assert.equal(
|
|
resolveWorkspaceTabLabel(
|
|
{ title: DEFAULT_WORKSPACE_TITLE, focusedSessionId: 's2' },
|
|
[
|
|
{ id: 's1', hostLabel: 'Localhost', hostId: 'local-terminal' },
|
|
{ id: 's2', hostLabel: 'prod-db', hostId: 'host-db' },
|
|
],
|
|
),
|
|
// Two distinct hosts: focused host + "+1" for the other.
|
|
'prod-db +1',
|
|
);
|
|
});
|
|
|
|
test('resolveWorkspaceTabLabel shows a single host name without a suffix', () => {
|
|
assert.equal(
|
|
resolveWorkspaceTabLabel(
|
|
{ title: DEFAULT_WORKSPACE_TITLE, focusedSessionId: 's1' },
|
|
[
|
|
// Two local terminals share the stable local hostId.
|
|
{ id: 's1', hostLabel: 'Localhost', hostId: 'local-terminal' },
|
|
{ id: 's2', hostLabel: 'Localhost', hostId: 'local-terminal' },
|
|
],
|
|
),
|
|
'Localhost',
|
|
);
|
|
});
|
|
|
|
test('resolveWorkspaceTabLabel does not add a suffix when a same-host pane is renamed', () => {
|
|
assert.equal(
|
|
resolveWorkspaceTabLabel(
|
|
{ title: DEFAULT_WORKSPACE_TITLE, focusedSessionId: 's1' },
|
|
[
|
|
{ id: 's1', hostLabel: 'web-01', hostId: 'host-web' },
|
|
// Same host (hostId), but a rename rewrote this pane's customName AND
|
|
// hostLabel — hostId still ties it to the same host, so no "+1".
|
|
{ id: 's2', customName: 'logs', hostLabel: 'logs', hostId: 'host-web' },
|
|
],
|
|
),
|
|
'web-01',
|
|
);
|
|
});
|
|
|
|
test('resolveWorkspaceTabLabel shows the focused rename while counting hosts', () => {
|
|
assert.equal(
|
|
resolveWorkspaceTabLabel(
|
|
{ title: DEFAULT_WORKSPACE_TITLE, focusedSessionId: 's1' },
|
|
[
|
|
{ id: 's1', customName: 'my-web', hostLabel: 'my-web', hostId: 'host-web' },
|
|
{ id: 's2', hostLabel: 'db-02', hostId: 'host-db' },
|
|
],
|
|
),
|
|
'my-web +1',
|
|
);
|
|
});
|
|
|
|
test('resolveWorkspaceTabLabel keeps a workspace explicitly named "Workspace"', () => {
|
|
// autoTitle:false marks the title as user-chosen even when it equals the
|
|
// default sentinel — it must not be replaced by a host label.
|
|
assert.equal(
|
|
resolveWorkspaceTabLabel(
|
|
{ title: DEFAULT_WORKSPACE_TITLE, autoTitle: false, focusedSessionId: 's1' },
|
|
[{ id: 's1', hostLabel: 'web-01', hostId: 'host-web' }],
|
|
),
|
|
'Workspace',
|
|
);
|
|
});
|
|
|
|
test('resolveWorkspaceTabLabel derives a label for an explicitly auto-titled workspace', () => {
|
|
assert.equal(
|
|
resolveWorkspaceTabLabel(
|
|
{ title: DEFAULT_WORKSPACE_TITLE, autoTitle: true, focusedSessionId: 's1' },
|
|
[{ id: 's1', hostLabel: 'Localhost', hostId: 'local-terminal' }],
|
|
),
|
|
'Localhost',
|
|
);
|
|
});
|
|
|
|
test('resolveWorkspaceTabLabel falls back to the default title with no sessions', () => {
|
|
assert.equal(
|
|
resolveWorkspaceTabLabel({ title: DEFAULT_WORKSPACE_TITLE, focusedSessionId: null }, []),
|
|
DEFAULT_WORKSPACE_TITLE,
|
|
);
|
|
});
|