fix: avoid unhandled rejection in TeamProvisioningService warmup test
probeClaudeRuntime spawns two probes in parallel; both called spawnCli. Mock threw on every call, leaving pingAttempt1Promise rejected and unhandled. Now throw only on first call, return fake child on second. Made-with: Cursor
This commit is contained in:
parent
0144046c07
commit
6e0fdad612
1 changed files with 19 additions and 1 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { EventEmitter } from 'events';
|
||||||
|
|
||||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
|
|
||||||
vi.mock('@main/services/team/ClaudeBinaryResolver', () => ({
|
vi.mock('@main/services/team/ClaudeBinaryResolver', () => ({
|
||||||
|
|
@ -17,6 +19,17 @@ function allowConsoleLogs() {
|
||||||
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function createFakeChild(exitCode: number): NodeJS.Process {
|
||||||
|
const child = new EventEmitter() as NodeJS.Process & {
|
||||||
|
stdout: EventEmitter;
|
||||||
|
stderr: EventEmitter;
|
||||||
|
};
|
||||||
|
child.stdout = new EventEmitter();
|
||||||
|
child.stderr = new EventEmitter();
|
||||||
|
setImmediate(() => child.emit('close', exitCode));
|
||||||
|
return child;
|
||||||
|
}
|
||||||
|
|
||||||
describe('TeamProvisioningService', () => {
|
describe('TeamProvisioningService', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
|
|
@ -26,8 +39,13 @@ describe('TeamProvisioningService', () => {
|
||||||
it('does not throw when spawnCli rejects', async () => {
|
it('does not throw when spawnCli rejects', async () => {
|
||||||
allowConsoleLogs();
|
allowConsoleLogs();
|
||||||
vi.mocked(ClaudeBinaryResolver.resolve).mockResolvedValue('C:\\path\\claude');
|
vi.mocked(ClaudeBinaryResolver.resolve).mockResolvedValue('C:\\path\\claude');
|
||||||
|
let callCount = 0;
|
||||||
vi.mocked(spawnCli).mockImplementation(() => {
|
vi.mocked(spawnCli).mockImplementation(() => {
|
||||||
throw new Error('spawn EINVAL');
|
callCount++;
|
||||||
|
if (callCount === 1) {
|
||||||
|
throw new Error('spawn EINVAL');
|
||||||
|
}
|
||||||
|
return createFakeChild(0) as ReturnType<typeof spawnCli>;
|
||||||
});
|
});
|
||||||
|
|
||||||
const svc = new TeamProvisioningService();
|
const svc = new TeamProvisioningService();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue