mirror of
https://github.com/workos/skills.git
synced 2026-09-14 20:07:08 +08:00
718badf413
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)
63 lines
1.7 KiB
TypeScript
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");
|
|
});
|
|
});
|