Download src/api/agent-canvas-updates.test.ts from SaylorTwift/openhands: direct link, hf CLI and curl.
- Browser
- Download file 1.38 kB
-
https://huggingface.co/SaylorTwift/openhands/resolve/main/src/api/agent-canvas-updates.test.ts
- Command line
-
hf download hf://SaylorTwift/openhands/src/api/agent-canvas-updates.test.ts
-
curl -L -o agent-canvas-updates.test.ts https://huggingface.co/SaylorTwift/openhands/resolve/main/src/api/agent-canvas-updates.test.ts
1.38 kB
| import { afterEach, describe, expect, it, vi } from "vitest"; | |
| import { fetchLatestAgentCanvasVersion } from "./agent-canvas-updates"; | |
| function stubFetchResponse(response: Partial<Response>) { | |
| const fetchMock = vi.fn().mockResolvedValue(response as Response); | |
| vi.stubGlobal("fetch", fetchMock); | |
| return fetchMock; | |
| } | |
| afterEach(() => { | |
| vi.unstubAllGlobals(); | |
| }); | |
| describe("fetchLatestAgentCanvasVersion", () => { | |
| it("fetches the npm registry latest dist-tag and returns the trimmed version", async () => { | |
| const fetchMock = stubFetchResponse({ | |
| ok: true, | |
| json: async () => ({ version: " 1.6.0 " }), | |
| }); | |
| await expect(fetchLatestAgentCanvasVersion()).resolves.toBe("1.6.0"); | |
| expect(fetchMock).toHaveBeenCalledWith( | |
| "https://registry.npmjs.org/@openhands/agent-canvas/latest", | |
| expect.objectContaining({ headers: { Accept: "application/json" } }), | |
| ); | |
| }); | |
| it("rejects when the registry responds with an error status", async () => { | |
| stubFetchResponse({ ok: false, status: 503 }); | |
| await expect(fetchLatestAgentCanvasVersion()).rejects.toThrow("503"); | |
| }); | |
| it("rejects when the response has no usable version field", async () => { | |
| stubFetchResponse({ ok: true, json: async () => ({ version: 42 }) }); | |
| await expect(fetchLatestAgentCanvasVersion()).rejects.toThrow( | |
| "missing version", | |
| ); | |
| }); | |
| }); | |