Files
hmbown--codewhale/web/lib/static-installer.test.ts
wehub-resource-sync d68f003000
CI / Change detection (push) Has been cancelled
CI / Version drift (push) Has been cancelled
CI / Lint (push) Has been cancelled
CI / Workflow RLM cache (push) Has been cancelled
CI / Test (macos-latest) (push) Has been cancelled
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / npm wrapper smoke (push) Has been cancelled
CI / Mobile runtime smoke (push) Has been cancelled
CI / Workflow lint (push) Has been cancelled
CI / Documentation (push) Has been cancelled
Web Frontend / Lint & Type Check (push) Failing after 1s
Auto-close harvested PRs / close (push) Failing after 1s
cargo-deny / cargo-deny (bans licenses sources) (push) Failing after 1s
Security audit / cargo-audit (push) Failing after 1s
Sync to CNB / sync (push) Failing after 1s
cargo-deny / cargo-deny (advisories) (push) Failing after 3s
Web Frontend / Deploy to Cloudflare (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:08:23 +08:00

54 lines
1.6 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
import { fetchWithStaticInstaller } from "./static-installer";
function ctx(): unknown {
return {
waitUntil: vi.fn(),
passThroughOnException: vi.fn(),
};
}
describe("static installer route", () => {
const fallbackFetch = vi.fn(async () => new Response("fallback", { status: 200 }));
beforeEach(() => {
vi.clearAllMocks();
});
it("serves /install.sh from the static asset binding before OpenNext fallback", async () => {
const assetFetch = vi.fn(async () =>
new Response("#!/bin/sh\necho codewhale\n", {
headers: { "content-type": "application/octet-stream" },
}),
);
const response = await fetchWithStaticInstaller(
new Request("https://codewhale.net/install.sh"),
{ ASSETS: { fetch: assetFetch } },
ctx(),
fallbackFetch,
);
expect(assetFetch).toHaveBeenCalledOnce();
expect(fallbackFetch).not.toHaveBeenCalled();
expect(response.headers.get("content-type")).toBe("text/x-shellscript; charset=utf-8");
expect(response.headers.get("cache-control")).toBe("public, max-age=300");
expect(await response.text()).toContain("echo codewhale");
});
it("delegates non-installer paths to the OpenNext handler", async () => {
const assetFetch = vi.fn();
const response = await fetchWithStaticInstaller(
new Request("https://codewhale.net/install"),
{ ASSETS: { fetch: assetFetch } },
ctx(),
fallbackFetch,
);
expect(assetFetch).not.toHaveBeenCalled();
expect(fallbackFetch).toHaveBeenCalledOnce();
expect(await response.text()).toBe("fallback");
});
});