Skip to content

Commit 6667f0c

Browse files
committed
fix(test): improve callback handling and CI test inclusion
Modify spawn-repeat test to use session titles for callback filtering, preventing interference between tests. Update CI workflow to include the test in the test suite. This ensures reliable test execution and complete test coverage in CI.
1 parent 6a7c378 commit 6667f0c

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444

4545
- name: Run test
4646
if: matrix.quality == 'test'
47-
run: bun test websocket.test.ts web-server.test.ts types.test.ts
47+
run: bun test websocket.test.ts web-server.test.ts types.test.ts spawn-repeat.test.ts
4848

4949
- name: Type check
5050
if: matrix.quality == 'typecheck'

test/spawn-repeat.test.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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'
33

44
describe('PTY Echo Behavior', () => {
55
const fakeClient = {
@@ -42,39 +42,38 @@ describe('PTY Echo Behavior', () => {
4242
})
4343

4444
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)
5355
}
5456
})
55-
setTimeout(resolve, 1000)
5657
}).catch((e) => {
5758
console.error(e)
5859
})
5960

6061
// Spawn interactive bash session
6162
const session = manager.spawn({
63+
title: title,
6264
command: 'echo',
6365
args: ['Hello World'],
6466
description: 'Echo test session',
6567
parentSessionId: 'test',
6668
})
6769

68-
await promise
70+
const rawData = await promise
6971

7072
// Clean up
7173
manager.kill(session.id, true)
74+
rawOutputCallbacks.length = 0
7275

7376
// 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)
8079
})

0 commit comments

Comments
 (0)