Repository navigation
Use @animalabs/mcpl-core 0.4.0, which needs Node 22.12.0 or later #16
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
Open
nissa-seru
wants to merge
5
commits into
anima-research:main
Choose a base branch
from
nissa-seru:fix/mcpl-core-0.4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+138
−22
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
05cd9db
Test that bad input from the host ends only what it should
50afa96
Use @animalabs/mcpl-core 0.4.0, and hear the errors it reports
6d72345
Test on Node 24 in CI too, and check the U+2028 answer is a result
94b403d
Merge main into the mcpl-core 0.4.0 raise
3dd5289
Merge main into the mcpl-core 0.4.0 raise
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| - **Operators:** github-mcpl needs Node 22.12.0 or later, the floor of | ||
| `@animalabs/mcpl-core` 0.4.0, which it now uses. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| - A host message whose JSON string holds U+2028 or U+2029 no longer ends the | ||
| process: on Node 24 the reader split the line there. | ||
| - A malformed line from the host is logged, and its connection stays open. A | ||
| stream error, such as a reset TCP connection, is logged and closes that | ||
| connection: over TCP the next host can then connect, and under `--stdio` the | ||
| process shuts down as it does when the host closes stdin. Before, each of | ||
| these ended the process with an unheard error. | ||
| - An error the TCP server reports while a host is connected, such as a failed | ||
| accept of another connection, is logged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { strict as assert } from 'node:assert'; | ||
| import { PassThrough } from 'node:stream'; | ||
| import { test } from 'node:test'; | ||
| import { McplConnection } from '@animalabs/mcpl-core'; | ||
| import { GitHubMcplServer } from '../src/server.js'; | ||
| import type { Logger } from '../src/types.js'; | ||
| import { FakeGitHubApi, TEST_BOT, TEST_REPO } from './harness.js'; | ||
|
|
||
| function capturingLogger(): Logger & { lines: string[] } { | ||
| const lines: string[] = []; | ||
| const push = (level: string) => (message: string, fields?: Record<string, unknown>) => { | ||
| lines.push(`${level} ${message} ${JSON.stringify(fields ?? {})}`); | ||
| }; | ||
| return { lines, debug: push('debug'), info: push('info'), warn: push('warn'), error: push('error') }; | ||
| } | ||
|
|
||
| /** A server serving one connection whose host side is written as raw lines, so a frame reaches the server's reader byte for byte. */ | ||
| function rawHost() { | ||
| const toServer = new PassThrough(); | ||
| const toHost = new PassThrough(); | ||
| const logger = capturingLogger(); | ||
| const server = new GitHubMcplServer(new FakeGitHubApi(), { botLogin: TEST_BOT.login, repos: [TEST_REPO], logger }); | ||
| const served = server.serve(McplConnection.fromStreams(toServer, toHost)); | ||
|
|
||
| const answers = new Map<number, unknown>(); | ||
| let buffered = ''; | ||
| toHost.on('data', (chunk: Buffer) => { | ||
| buffered += chunk.toString('utf8'); | ||
| let nl: number; | ||
| while ((nl = buffered.indexOf('\n')) >= 0) { | ||
| const line = buffered.slice(0, nl); | ||
| buffered = buffered.slice(nl + 1); | ||
| const msg = JSON.parse(line) as { id?: number }; | ||
| if (typeof msg.id === 'number') answers.set(msg.id, msg); | ||
| } | ||
| }); | ||
|
|
||
| async function answerTo(id: number, ms = 2000): Promise<unknown> { | ||
| const deadline = Date.now() + ms; | ||
| while (!answers.has(id)) { | ||
| if (Date.now() > deadline) throw new Error(`no answer to request ${id} within ${ms} ms`); | ||
| await new Promise((r) => setTimeout(r, 10)); | ||
| } | ||
| return answers.get(id); | ||
| } | ||
|
|
||
| async function initialize(): Promise<void> { | ||
| toServer.write( | ||
| JSON.stringify({ | ||
| jsonrpc: '2.0', | ||
| id: 1, | ||
| method: 'initialize', | ||
| params: { protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'raw-host', version: '0' } }, | ||
| }) + '\n', | ||
| ); | ||
| await answerTo(1); | ||
| toServer.write(JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' }) + '\n'); | ||
| } | ||
|
|
||
| return { toServer, logger, served, answerTo, initialize }; | ||
| } | ||
|
|
||
| test('a request whose string holds U+2028 or U+2029 is answered', { timeout: 5000 }, async (t) => { | ||
| const h = rawHost(); | ||
| t.after(() => h.toServer.end()); | ||
| await h.initialize(); | ||
|
|
||
| // Written by hand: JSON.stringify leaves U+2028 and U+2029 unescaped, as a host's encoder may. | ||
| h.toServer.write(`{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{"cursor":"a\u2028b"}}\n`); | ||
| h.toServer.write(`{"jsonrpc":"2.0","id":3,"method":"tools/list","params":{"cursor":"a\u2029b"}}\n`); | ||
|
|
||
| for (const id of [2, 3]) { | ||
| const answer = (await h.answerTo(id)) as { result?: unknown }; | ||
| assert.ok(answer.result, `request ${id} is answered with a result`); | ||
| } | ||
| }); | ||
|
|
||
| test('a malformed line is logged, and the next request is answered', { timeout: 5000 }, async (t) => { | ||
| const h = rawHost(); | ||
| t.after(() => h.toServer.end()); | ||
| await h.initialize(); | ||
|
|
||
| h.toServer.write('not json\n'); | ||
| h.toServer.write(JSON.stringify({ jsonrpc: '2.0', id: 2, method: 'tools/list' }) + '\n'); | ||
|
|
||
| const answer = (await h.answerTo(2)) as { result?: unknown }; | ||
| assert.ok(answer.result, 'request 2 is answered after the malformed line'); | ||
| assert.ok( | ||
| h.logger.lines.some((l) => l.startsWith('error ') && l.includes('Malformed JSON-RPC message')), | ||
| `the malformed line is logged: ${JSON.stringify(h.logger.lines)}`, | ||
| ); | ||
| }); | ||
|
|
||
| test('a stream error ends serve() and is logged', { timeout: 5000 }, async () => { | ||
| const h = rawHost(); | ||
| await h.initialize(); | ||
|
|
||
| h.toServer.destroy(new Error('read ECONNRESET (test)')); | ||
| await h.served; | ||
|
|
||
| assert.ok( | ||
| h.logger.lines.some((l) => l.startsWith('error ') && l.includes('read ECONNRESET (test)')), | ||
| `the stream error is logged: ${JSON.stringify(h.logger.lines)}`, | ||
| ); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Medium severity, test coverage. CI on Node 22 cannot catch a return of the U+2028/U+2029 bug, which only appears on Node 24.
The PR description says the U+2028 split only happens with mcpl-core 0.3.0's reader on Node 24.
.github/workflows/ci.ymlruns onlynode-version: 22, so on CI this test passes with either 0.3.0 or 0.4.0. It cannot fail there. The red-first run was done by hand on Node 24. Add a Node 24 job to the CI matrix, or the regression this test exists for will not be caught in CI.