Files
homeclaw/tests/pty-store-list.test.ts
T

36 lines
1.6 KiB
TypeScript

/**
* 웹 터미널 세션 목록(pty_list) — 소유자별 필터와 이름표 검증
*/
import { test, describe, beforeEach } from 'node:test';
import assert from 'node:assert/strict';
import { ptyStore, listPtySessions, cleanPtyKey, cleanPtyMode } from '../src/gateway/pty-store';
describe('listPtySessions', () => {
beforeEach(() => ptyStore.clear());
const mk = (username: string, extra: any = {}) => ({ proc: {}, username, ws: null, buf: 'SECRET', idle: null, ...extra });
test('내 세션만, 최근 시작 순으로, 출력 버퍼는 싣지 않는다', () => {
ptyStore.set('a', mk('kim', { key: 'ws:proj_1', mode: 'claude', startedAt: 100 }));
ptyStore.set('b', mk('kim', { key: 'pcb:smps', mode: 'shell', startedAt: 200, ws: {} }));
ptyStore.set('c', mk('papa', { key: 'ws:proj_1', startedAt: 300 }));
const l = listPtySessions('kim');
assert.deepEqual(l.map(x => x.shellId), ['b', 'a']);
assert.equal(l[0].attached, true);
assert.equal(l[1].attached, false);
assert.ok(!JSON.stringify(l).includes('SECRET'));
});
});
describe('이름표 검증', () => {
test('올바른 key만 통과', () => {
assert.equal(cleanPtyKey('ws:proj_m5j2c2bp'), 'ws:proj_m5j2c2bp');
assert.equal(cleanPtyKey('pcb:smps 전원'), 'pcb:smps 전원');
for (const bad of ['', 'x:y', 'ws:', 'ws:../..', 'ws:a/b', 'ws:a\nb', undefined, 5, {}]) assert.equal(cleanPtyKey(bad), undefined, JSON.stringify(bad));
});
test('mode는 허용 목록만', () => {
assert.equal(cleanPtyMode('claude-ollama'), 'claude-ollama');
assert.equal(cleanPtyMode('rm -rf /'), undefined);
assert.equal(cleanPtyMode(undefined), undefined);
});
});