Files
workos__skills/scripts/tests/fetcher.spec.ts
T
Nick Nisi 718badf413 feat: scaffold @workos-inc/skills package with parser, fetcher, and 6 AuthKit skills
Phase 1 of the WorkOS skills generator. Sets up the repo as a publishable
npm package compatible with skills.sh, copies 6 hand-crafted AuthKit
framework skills from the CLI repo, and builds the foundation for skill
generation from llms-full.txt.

- npm package: @workos-inc/skills with skills/ in files array
- Fetcher: downloads llms.txt/llms-full.txt with retry + local cache
- Parser: extracts 24-section tree from ## Name {#anchor} boundaries
- Validator: format guards that fail loudly on doc structure changes
- 18 passing tests (bun test)
2026-02-06 11:36:11 -05:00

63 lines
1.7 KiB
TypeScript

import { describe, expect, it, beforeEach, afterEach } from "bun:test";
import { fetchDocs } from "../lib/fetcher.ts";
import { rm, mkdir } from "fs/promises";
import { join } from "path";
const TEST_CACHE_DIR = ".cache-test";
beforeEach(async () => {
await rm(TEST_CACHE_DIR, { recursive: true, force: true });
});
afterEach(async () => {
await rm(TEST_CACHE_DIR, { recursive: true, force: true });
});
describe("fetchDocs", () => {
it("fetches from network and caches", async () => {
const result = await fetchDocs("https://workos.com/docs/llms.txt", {
cacheDir: TEST_CACHE_DIR,
retries: 2,
});
expect(result.source).toBe("network");
expect(result.content.length).toBeGreaterThan(0);
expect(result.content).toContain("WorkOS");
// Second fetch should hit cache
const cached = await fetchDocs("https://workos.com/docs/llms.txt", {
cacheDir: TEST_CACHE_DIR,
retries: 2,
});
expect(cached.source).toBe("cache");
expect(cached.content).toBe(result.content);
});
it("bypasses expired cache", async () => {
// Pre-populate cache
await fetchDocs("https://workos.com/docs/llms.txt", {
cacheDir: TEST_CACHE_DIR,
retries: 2,
});
// Fetch with 0 TTL — should go to network
const result = await fetchDocs("https://workos.com/docs/llms.txt", {
cacheDir: TEST_CACHE_DIR,
maxAge: 0,
retries: 2,
});
expect(result.source).toBe("network");
});
it("throws on unreachable URL after retries", async () => {
await expect(
fetchDocs("https://localhost:19999/not-a-real-server", {
cacheDir: TEST_CACHE_DIR,
retries: 1,
}),
).rejects.toThrow("Failed to fetch");
});
});