-
Notifications
You must be signed in to change notification settings - Fork 11
fix: include stderr in process exceptions #212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import * as fs from 'node:fs'; | ||
| import * as os from 'node:os'; | ||
| import * as path from 'node:path'; | ||
| import { once } from 'node:events'; | ||
| import * as acp from '@agentclientprotocol/sdk'; | ||
| import { startCodexConnection } from '../../CodexJsonRpcConnection'; | ||
| import { CodexAppServerClient } from '../../CodexAppServerClient'; | ||
| import { CodexAcpClient } from '../../CodexAcpClient'; | ||
| import { CodexAcpServer } from '../../CodexAcpServer'; | ||
| import { createMockConnections } from './test-utils'; | ||
|
|
||
| describe('CodexACPAgent - process exit error', () => { | ||
| it.skipIf(process.platform === 'win32')('includes the crashed process stderr', async () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe add win case also? :)
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have CI on win, also the change is not OS specific. I suggest to keep it as is, otherwise I need to blindly add win case support without actual checking or spend unreasonable time to check it. |
||
| const fakeCodex = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'codex-bad-')), 'codex'); | ||
| fs.writeFileSync(fakeCodex, "#!/bin/sh\necho 'codex: failed to launch' >&2\nexit 1\n"); | ||
| fs.chmodSync(fakeCodex, 0o755); | ||
|
|
||
| const connection = startCodexConnection(fakeCodex); | ||
| let stderr = ''; | ||
| connection.process.stderr.on('data', (chunk: Buffer) => { stderr += chunk.toString(); }); | ||
|
|
||
| const codexClient = new CodexAcpClient(new CodexAppServerClient(connection.connection)); | ||
| const agent = new CodexAcpServer( | ||
| createMockConnections().mockAcpConnection, | ||
| codexClient, | ||
| undefined, | ||
| () => connection.process.exitCode, | ||
| () => stderr, | ||
| ); | ||
|
|
||
| await once(connection.process, 'close'); // process exited and stderr flushed | ||
|
|
||
| await expect(agent.initialize({ protocolVersion: acp.PROTOCOL_VERSION })) | ||
| .rejects.toThrow("Codex process has exited with code 1:\ncodex: failed to launch"); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lastError instead of recent maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not actually last, it's all stderr limited to some size.
I'm not sure we can actually get single error - it still can be spitted into a few data events.