|
1 | 1 | import { describe, it, expect, beforeEach, afterEach } from 'bun:test' |
2 | | -import { initManager, manager, registerRawOutputCallback } from '../src/plugin/pty/manager.ts' |
| 2 | +import { initManager, manager, rawOutputCallbacks, registerRawOutputCallback } from '../src/plugin/pty/manager.ts' |
3 | 3 |
|
4 | 4 | describe('PTY Echo Behavior', () => { |
5 | 5 | const fakeClient = { |
@@ -42,39 +42,38 @@ describe('PTY Echo Behavior', () => { |
42 | 42 | }) |
43 | 43 |
|
44 | 44 | it.skipIf(!process.env.SYNC_TESTS)('should receive initial data once', async () => { |
45 | | - const receivedOutputs: string[] = [] |
46 | | - |
47 | | - const promise = new Promise<void>((resolve) => { |
48 | | - // Subscribe to raw output events |
49 | | - registerRawOutputCallback((_sessionId, rawData) => { |
50 | | - receivedOutputs.push(rawData) |
51 | | - if (receivedOutputs.join('').includes('Hello World')) { |
52 | | - resolve() |
| 45 | + |
| 46 | + const title = crypto.randomUUID() |
| 47 | + // Subscribe to raw output events |
| 48 | + const promise = new Promise<string>((resolve) => { |
| 49 | + let rawDataTotal = '' |
| 50 | + registerRawOutputCallback((session, rawData) => { |
| 51 | + if (session.title !== title) return |
| 52 | + rawDataTotal += rawData |
| 53 | + if (rawData.includes('Hello World')) { |
| 54 | + resolve(rawDataTotal) |
53 | 55 | } |
54 | 56 | }) |
55 | | - setTimeout(resolve, 1000) |
56 | 57 | }).catch((e) => { |
57 | 58 | console.error(e) |
58 | 59 | }) |
59 | 60 |
|
60 | 61 | // Spawn interactive bash session |
61 | 62 | const session = manager.spawn({ |
| 63 | + title: title, |
62 | 64 | command: 'echo', |
63 | 65 | args: ['Hello World'], |
64 | 66 | description: 'Echo test session', |
65 | 67 | parentSessionId: 'test', |
66 | 68 | }) |
67 | 69 |
|
68 | | - await promise |
| 70 | + const rawData = await promise |
69 | 71 |
|
70 | 72 | // Clean up |
71 | 73 | manager.kill(session.id, true) |
| 74 | + rawOutputCallbacks.length = 0 |
72 | 75 |
|
73 | 76 | // Verify echo occurred |
74 | | - const allOutput = receivedOutputs.join('') |
75 | | - expect(allOutput).toContain('Hello World') |
76 | | - |
77 | | - // Should have received some output (prompt + echo) |
78 | | - expect(receivedOutputs.length).toBeGreaterThan(0) |
79 | | - }) |
| 77 | + expect(rawData).toContain('Hello World') |
| 78 | + }, 1000) |
80 | 79 | }) |
0 commit comments