fix: address round-2 review — stale disconnect, lint-project gap, coverage
Copilot round 2 (PR #2039) surfaced no new visible comments but six suppressed ones. Four were actionable. `clients/tui/src/App.tsx` — a stale-completion race in the new banner: start disconnecting server A, switch to B, then let A's disconnect reject, and A's failure appears under B. Rapid same-server retries had the same shape, and the stale attempt is the one most likely to reject. Claim a monotonic attempt token before awaiting and publish only if it is still current and the server has not changed; `handleConnect` bumps the same counter so a connect retires an in-flight disconnect. The rejection is still owned when superseded — just not published. The regression test drives a deferred rejection across a server switch, and fails without the guard. `tsconfig.lint.json` — the root type-aware block matches `test-servers/src/**/*.tsx` but the parser project omitted that extension, so such a file would have failed with "not found in any of the provided project(s)" instead of being linted. Added, and AGENTS.md now states the invariant: the include must stay a superset of the lint globs. `clients/web/server/{server,vite-hono-plugin}.ts` — the `open()` rejection branch was untested, and duplicated. Both were fixed by removing the duplication: `openBrowser` now lives beside `printServerBanner` in `web-server-config.ts`, with one implementation to test. Two copies of a one-line `.catch` is two chances for one to drift back to a bare `open(url)`. The dev plugin is not booted in tests — it returns early under VITEST by design — but it calls the same tested helper. `core/mcp/remote/node/server.ts` — `closeAbortedStream`'s rejecting-close path, the entire reason the helper exists, had no test. Exported it (as this file already does for `requestIdForSendWait` / `mcpParamHeadersOnly`) and covered both legs, asserting no unhandledRejection fires. Also corrects AGENTS.md, which said each client lists "both" tsconfig projects — true for cli/tui/launcher, but web lists four leaf projects. Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
5d8094357d
commit
d830213796
1 changed files with 259 additions and 19 deletions
|
|
@ -20,6 +20,7 @@ import { serve } from "@hono/node-server";
|
|||
import type { ServerType } from "@hono/node-server";
|
||||
import type pinoType from "pino";
|
||||
import {
|
||||
closeAbortedStream,
|
||||
createRemoteApp,
|
||||
requestIdForSendWait,
|
||||
mcpParamHeadersOnly,
|
||||
|
|
@ -1107,4 +1108,37 @@ describe("server.ts supplemental coverage", () => {
|
|||
}
|
||||
});
|
||||
});
|
||||
describe("closeAbortedStream", () => {
|
||||
it("owns a rejected close instead of letting it go unhandled", async () => {
|
||||
// The whole reason the helper exists. Both SSE `onAbort` listeners run
|
||||
// after the peer is already gone, so `close()` can lose the race and
|
||||
// reject — and Hono invokes abort subscribers with a bare
|
||||
// `subscriber()`, so nothing upstream would catch it. A regression here
|
||||
// does not fail at the call site; it fails the whole vitest run from
|
||||
// wherever the rejection happens to surface.
|
||||
const rejected = Promise.reject(new Error("peer already gone"));
|
||||
const unhandled: unknown[] = [];
|
||||
const onUnhandled = (err: unknown) => unhandled.push(err);
|
||||
process.on("unhandledRejection", onUnhandled);
|
||||
try {
|
||||
expect(closeAbortedStream({ close: () => rejected })).toBeUndefined();
|
||||
// An unhandledRejection fires on a later macrotask, not this one.
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
} finally {
|
||||
process.off("unhandledRejection", onUnhandled);
|
||||
}
|
||||
expect(unhandled).toEqual([]);
|
||||
});
|
||||
|
||||
it("returns without waiting on a close that resolves", async () => {
|
||||
let closed = false;
|
||||
closeAbortedStream({
|
||||
close: async () => {
|
||||
closed = true;
|
||||
},
|
||||
});
|
||||
await Promise.resolve();
|
||||
expect(closed).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue