Compare commits
1 Commits
main
...
fix/telegr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a3238cf89 |
@ -72,6 +72,7 @@ Status: stable.
|
||||
- **BREAKING:** Gateway auth mode "none" is removed; gateway now requires token/password (Tailscale Serve identity still allowed).
|
||||
|
||||
### Fixes
|
||||
- Telegram: use undici fetch for per-account proxy dispatcher. (#4456) Thanks @spiceoogway.
|
||||
- Telegram: avoid silent empty replies by tracking normalization skips before fallback. (#3796)
|
||||
- Telegram: scope native skill commands to bound agent per bot. (#4360) Thanks @robhparker.
|
||||
- Mentions: honor mentionPatterns even when explicit mentions are present. (#3303) Thanks @HirokiKobayashi-R.
|
||||
|
||||
45
src/telegram/proxy.test.ts
Normal file
45
src/telegram/proxy.test.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
const { ProxyAgent, undiciFetch, proxyAgentSpy, getLastAgent } = vi.hoisted(() => {
|
||||
const undiciFetch = vi.fn();
|
||||
const proxyAgentSpy = vi.fn();
|
||||
class ProxyAgent {
|
||||
static lastCreated: ProxyAgent | undefined;
|
||||
proxyUrl: string;
|
||||
constructor(proxyUrl: string) {
|
||||
this.proxyUrl = proxyUrl;
|
||||
ProxyAgent.lastCreated = this;
|
||||
proxyAgentSpy(proxyUrl);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
ProxyAgent,
|
||||
undiciFetch,
|
||||
proxyAgentSpy,
|
||||
getLastAgent: () => ProxyAgent.lastCreated,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("undici", () => ({
|
||||
ProxyAgent,
|
||||
fetch: undiciFetch,
|
||||
}));
|
||||
|
||||
import { makeProxyFetch } from "./proxy.js";
|
||||
|
||||
describe("makeProxyFetch", () => {
|
||||
it("uses undici fetch with ProxyAgent dispatcher", async () => {
|
||||
const proxyUrl = "http://proxy.test:8080";
|
||||
undiciFetch.mockResolvedValue({ ok: true });
|
||||
|
||||
const proxyFetch = makeProxyFetch(proxyUrl);
|
||||
await proxyFetch("https://api.telegram.org/bot123/getMe");
|
||||
|
||||
expect(proxyAgentSpy).toHaveBeenCalledWith(proxyUrl);
|
||||
expect(undiciFetch).toHaveBeenCalledWith(
|
||||
"https://api.telegram.org/bot123/getMe",
|
||||
expect.objectContaining({ dispatcher: getLastAgent() }),
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -1,11 +1,11 @@
|
||||
// @ts-nocheck
|
||||
import { ProxyAgent } from "undici";
|
||||
import { ProxyAgent, fetch as undiciFetch } from "undici";
|
||||
import { wrapFetchWithAbortSignal } from "../infra/fetch.js";
|
||||
|
||||
export function makeProxyFetch(proxyUrl: string): typeof fetch {
|
||||
const agent = new ProxyAgent(proxyUrl);
|
||||
return wrapFetchWithAbortSignal((input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const base = init ? { ...init } : {};
|
||||
return fetch(input, { ...base, dispatcher: agent });
|
||||
return undiciFetch(input, { ...base, dispatcher: agent });
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user