Merge branch 'v2/main' into v2/fix/1919-rfc6570-uri-template-expansion
This commit is contained in:
commit
63250a6c52
2 changed files with 2391 additions and 126 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -496,6 +496,75 @@ describe("/api/servers routes", () => {
|
|||
expect(res.status).toBe(400);
|
||||
});
|
||||
|
||||
// #1906 — the endpoint overrides travel as plain strings and land under
|
||||
// `oauth` on disk beside the credentials.
|
||||
it("persists the oauth endpoint overrides on POST", async () => {
|
||||
const res = await fetch(`${h.baseUrl}/api/servers`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
id: "endpointoverrides",
|
||||
config: { type: "streamable-http", url: "https://x.test/mcp" },
|
||||
settings: {
|
||||
headers: [],
|
||||
metadata: [],
|
||||
connectionTimeout: 0,
|
||||
requestTimeout: 0,
|
||||
oauthAuthorizationUrl: "https://staging.test/authorize",
|
||||
oauthTokenUrl: "https://staging.test/token",
|
||||
},
|
||||
}),
|
||||
});
|
||||
expect(res.status).toBe(200);
|
||||
const stored = readConfig(h.configPath).mcpServers.endpointoverrides;
|
||||
expect(stored?.oauth).toEqual({
|
||||
authorizationUrl: "https://staging.test/authorize",
|
||||
tokenUrl: "https://staging.test/token",
|
||||
});
|
||||
});
|
||||
|
||||
it("drops an empty oauth endpoint override rather than writing it", async () => {
|
||||
const res = await fetch(`${h.baseUrl}/api/servers`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
id: "blankoverrides",
|
||||
config: { type: "streamable-http", url: "https://x.test/mcp" },
|
||||
settings: {
|
||||
headers: [],
|
||||
metadata: [],
|
||||
connectionTimeout: 0,
|
||||
requestTimeout: 0,
|
||||
oauthAuthorizationUrl: "",
|
||||
oauthTokenUrl: "",
|
||||
},
|
||||
}),
|
||||
});
|
||||
expect(res.status).toBe(200);
|
||||
expect(
|
||||
readConfig(h.configPath).mcpServers.blankoverrides,
|
||||
).not.toHaveProperty("oauth");
|
||||
});
|
||||
|
||||
it("rejects a non-string oauthTokenUrl payload", async () => {
|
||||
const res = await fetch(`${h.baseUrl}/api/servers`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
id: "badtokenurl",
|
||||
config: { type: "streamable-http", url: "https://x.test/mcp" },
|
||||
settings: {
|
||||
headers: [],
|
||||
metadata: [],
|
||||
connectionTimeout: 0,
|
||||
requestTimeout: 0,
|
||||
oauthTokenUrl: 42,
|
||||
},
|
||||
}),
|
||||
});
|
||||
expect(res.status).toBe(400);
|
||||
});
|
||||
|
||||
it("updates Inspector-extension fields at the top level on PUT", async () => {
|
||||
writeFileSync(
|
||||
h.configPath,
|
||||
|
|
|
|||
Loading…
Reference in a new issue