Files
oh-my-pi/packages/coding-agent/test/tools/web-scrapers/documentation.test.ts
T
can1357 89e6479661 refactor: migrated environment variable access from process.env to Bun.env across 71 files
- Migrated all environment variable access from Node.js `process.env` to Bun runtime `Bun.env` API across the entire codebase.
- Updated 71 files including source code, tests, documentation, and configuration to use Bun's native environment variable API.
- Added comprehensive environment variables documentation in `packages/coding-agent/docs/environment-variables.md` covering 100+ environment variables organized by category.
- Updated CHANGELOG entries to reflect migration from `process.env` to `Bun.env` and environment variable prefix changes (PI_* vs OMP_*).
- Maintained identical behavior and logic across all changes - only the environment variable access method was updated.
2026-02-05 04:51:18 +01:00

86 lines
3.1 KiB
TypeScript

import { describe, expect, it } from "bun:test";
import { handleMDN } from "@oh-my-pi/pi-coding-agent/web/scrapers/mdn";
import { handleReadTheDocs } from "@oh-my-pi/pi-coding-agent/web/scrapers/readthedocs";
const SKIP = !Bun.env.WEB_FETCH_INTEGRATION;
describe.skipIf(SKIP)("handleMDN", () => {
it("returns null for non-MDN URLs", async () => {
const result = await handleMDN("https://example.com", 20);
expect(result).toBeNull();
});
it("returns null for non-docs MDN URLs", async () => {
const result = await handleMDN("https://developer.mozilla.org/en-US/", 20);
expect(result).toBeNull();
});
it("returns null for MDN blog URLs", async () => {
const result = await handleMDN("https://developer.mozilla.org/en-US/blog/", 20);
expect(result).toBeNull();
});
it("fetches Array.map documentation", async () => {
const result = await handleMDN(
"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map",
20,
);
expect(result).not.toBeNull();
expect(result?.method).toBe("mdn");
expect(result?.content).toContain("map");
expect(result?.contentType).toBe("text/markdown");
expect(result?.fetchedAt).toBeTruthy();
});
it("fetches Promise documentation", async () => {
const result = await handleMDN(
"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",
20,
);
expect(result).not.toBeNull();
expect(result?.method).toBe("mdn");
expect(result?.content).toContain("Promise");
expect(result?.truncated).toBeDefined();
});
it("fetches CSS documentation", async () => {
const result = await handleMDN("https://developer.mozilla.org/en-US/docs/Web/CSS/display", 20);
expect(result).not.toBeNull();
expect(result?.method).toBe("mdn");
expect(result?.content).toContain("display");
});
});
describe.skipIf(SKIP)("handleReadTheDocs", () => {
it("returns null for non-RTD URLs", async () => {
const result = await handleReadTheDocs("https://example.com", 20);
expect(result).toBeNull();
});
it("returns null for github.com URLs", async () => {
const result = await handleReadTheDocs("https://github.com/user/repo", 20);
expect(result).toBeNull();
});
it("fetches requests docs", async () => {
const result = await handleReadTheDocs("https://requests.readthedocs.io/en/latest/", 20);
expect(result).not.toBeNull();
expect(result?.method).toBe("readthedocs");
expect(result?.fetchedAt).toBeTruthy();
expect(result?.truncated).toBeDefined();
});
it("returns null for non-readthedocs sites", async () => {
// These sites use Sphinx/RTD theme but aren't hosted on readthedocs.io
expect(await handleReadTheDocs("https://www.sphinx-doc.org/en/master/", 20)).toBeNull();
expect(await handleReadTheDocs("https://docs.pytest.org/en/stable/", 20)).toBeNull();
expect(await handleReadTheDocs("https://pip.pypa.io/en/stable/", 20)).toBeNull();
});
it("handles readthedocs.io subdomain", async () => {
const result = await handleReadTheDocs("https://flask.palletsprojects.readthedocs.io/en/latest/", 20);
expect(result).not.toBeNull();
expect(result?.method).toBe("readthedocs");
});
});