Skip to content

Commit 78b70eb

Browse files
test(smart-notes): spy on Agent.addRequest instead of createConnection
bun's stable node:https shim leaves globalAgent.createConnection undefined (it exists only on canary builds), so the keep-alive-agent test crashed on every stable runtime including CI. addRequest is the portable interception point: every Agent-routed request enters it on node and both bun lines. Co-authored-by: Alfonso <alfonso-magic-context@users.noreply.github.com>
1 parent 0087ee8 commit 78b70eb

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

packages/plugin/src/features/magic-context/smart-notes/ssrf-guard.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,13 @@ describe("createPinnedLookup", () => {
228228

229229
describe("guarded HTTPS request agent", () => {
230230
test("does not use a pre-seeded keep-alive global agent", async () => {
231-
const originalCreateConnection = https.globalAgent.createConnection;
232-
const globalCreateConnection = mock(originalCreateConnection.bind(https.globalAgent));
233-
https.globalAgent.createConnection = globalCreateConnection;
231+
// Intercept at addRequest: every request routed through an Agent must
232+
// enter addRequest, and it exists on every supported runtime — bun's
233+
// stable node:https shim leaves globalAgent.createConnection undefined,
234+
// so spying on createConnection only works on canary builds.
235+
const originalAddRequest = https.globalAgent.addRequest;
236+
const globalAddRequest = mock(originalAddRequest.bind(https.globalAgent));
237+
https.globalAgent.addRequest = globalAddRequest;
234238
try {
235239
const dedicated = createSmartNoteRequestAgent();
236240
expect(dedicated).not.toBe(https.globalAgent);
@@ -249,9 +253,9 @@ describe("guarded HTTPS request agent", () => {
249253
{ signal, timeoutMs: 100, bodyLimitBytes: 1024 },
250254
),
251255
).rejects.toBeInstanceOf(SmartNoteNetworkError);
252-
expect(globalCreateConnection).not.toHaveBeenCalled();
256+
expect(globalAddRequest).not.toHaveBeenCalled();
253257
} finally {
254-
https.globalAgent.createConnection = originalCreateConnection;
258+
https.globalAgent.addRequest = originalAddRequest;
255259
}
256260
});
257261
});

0 commit comments

Comments
 (0)