9bb1683445
- Added support for embedded URL selectors with `:raw` and `:L#-L#` line range syntax in read command. - Implemented `parseReadUrlTarget()` function to parse and validate URL read targets with line range support. - Updated read CLI to delegate URL inputs through read tool pipeline instead of treating as local file paths. - Added comprehensive test coverage for URL selector parsing and CLI URL delegation. - Refactored URL handling in read tool to use structured `ParsedReadUrlTarget` object.
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "bun:test";
|
|
import * as os from "node:os";
|
|
import * as path from "node:path";
|
|
import { runReadCommand } from "@oh-my-pi/pi-coding-agent/cli/read-cli";
|
|
import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
|
|
import * as scrapers from "@oh-my-pi/pi-coding-agent/web/scrapers/types";
|
|
|
|
describe("runReadCommand URL handling", () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("delegates URL inputs through the read tool pipeline", async () => {
|
|
const cwd = path.join(os.tmpdir(), "read-cli-url-test");
|
|
const settings = Settings.isolated({ "fetch.enabled": true });
|
|
const pageUrl = "https://example.com/cli-read";
|
|
const consoleLogSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
|
vi.spyOn(Settings, "init").mockResolvedValue(settings);
|
|
vi.spyOn(scrapers, "loadPage").mockResolvedValue({
|
|
ok: true,
|
|
status: 200,
|
|
contentType: "text/plain",
|
|
finalUrl: pageUrl,
|
|
content: "CLI URL content",
|
|
});
|
|
const cwdSpy = vi.spyOn(process, "cwd").mockReturnValue(cwd);
|
|
|
|
await runReadCommand({ path: pageUrl });
|
|
|
|
expect(cwdSpy).toHaveBeenCalled();
|
|
expect(consoleLogSpy).toHaveBeenCalledWith(expect.stringContaining("CLI URL content"));
|
|
});
|
|
});
|