Files
Netcatty/domain/hostGroupTreeFlat.test.ts
T
陈大猫andCursor 36e5779d94 perf(terminal): reduce terminal tab-switch and layout jank (#1321)
* perf(terminal): smooth layout drags and faster tab switching

Defer xterm refit during split, sidebar, and host-tree drags while keeping pane containers in sync with live layout measurements. Refactor TerminalLayer into focused sections with TabBridge/memo optimizations and add the terminal host tree sidebar.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(terminal): keep side panels alive and guard session attach races

Prevent terminal boot unmount from leaking backend sessions, keep SFTP/scripts/theme/AI state when switching side tabs, and defer heavy SFTP UI mount so first entry stays responsive.

Co-authored-by: Cursor <cursoragent@cursor.com>

* perf(terminal): reduce tab switch jank

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-09 03:35:03 +08:00

74 lines
1.9 KiB
TypeScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { buildHostGroupTree } from './hostGroupTree.ts';
import { flattenHostGroupTree, hostTreeFlatRowKey } from './hostGroupTreeFlat.ts';
import type { Host } from '../types';
const host = (id: string, label: string, group?: string): Host => ({
id,
label,
hostname: `${id}.example.com`,
username: 'root',
port: 22,
group,
tags: [],
os: 'linux',
});
test('flattenHostGroupTree emits group rows before visible children', () => {
const { groupTree, ungroupedHosts } = buildHostGroupTree(
[
host('1', 'web-1', 'prod/web'),
host('2', 'db-1', 'prod/db'),
host('3', 'local'),
],
['prod/web'],
);
const expanded = new Set(['prod', 'prod/web', 'prod/db']);
const rows = flattenHostGroupTree({
groupNodes: groupTree,
ungroupedHosts,
expandedPaths: expanded,
searchActive: false,
});
assert.deepEqual(
rows.map((row) => (row.kind === 'group' ? `g:${row.node.path}` : `h:${row.host.id}`)),
['g:prod', 'g:prod/db', 'h:2', 'g:prod/web', 'h:1', 'h:3'],
);
});
test('flattenHostGroupTree hides collapsed subtrees', () => {
const { groupTree, ungroupedHosts } = buildHostGroupTree(
[host('1', 'web-1', 'prod/web')],
[],
);
const rows = flattenHostGroupTree({
groupNodes: groupTree,
ungroupedHosts,
expandedPaths: new Set(['prod']),
searchActive: false,
});
assert.deepEqual(rows.map(hostTreeFlatRowKey), ['g:prod', 'g:prod/web']);
});
test('flattenHostGroupTree expands all rows while searching', () => {
const { groupTree, ungroupedHosts } = buildHostGroupTree(
[host('1', 'web-1', 'prod/web')],
[],
);
const rows = flattenHostGroupTree({
groupNodes: groupTree,
ungroupedHosts,
expandedPaths: new Set(),
searchActive: true,
});
assert.deepEqual(rows.map(hostTreeFlatRowKey), ['g:prod', 'g:prod/web', 'h:1']);
});