da636e3f51
- Added image-reference rendering to make `[Image #N]` placeholders clickable in chat. - Added MIME-aware image blob materialization with extensioned sidecar paths. - Added clickable path, line, and URL hyperlinks for read, search, and fetch outputs. - Hardened OSC8 hyperlink emission with URI validation and control-byte/idempotency checks.
77 lines
2.3 KiB
TypeScript
77 lines
2.3 KiB
TypeScript
import { afterAll, afterEach, beforeAll, describe, expect, it } from "bun:test";
|
|
import { resetSettingsForTest, Settings, settings } from "@oh-my-pi/pi-coding-agent/config/settings";
|
|
import { getThemeByName } from "../../src/modes/theme/theme";
|
|
import { readToolRenderer } from "../../src/tools/read";
|
|
|
|
function extractLinkUris(text: string): string[] {
|
|
return [...text.matchAll(/\x1b\]8;[^;]*;([^\x1b]+)\x1b\\/g)].map(match => match[1]!);
|
|
}
|
|
|
|
beforeAll(async () => {
|
|
resetSettingsForTest();
|
|
await Settings.init({ inMemory: true });
|
|
});
|
|
|
|
afterEach(() => {
|
|
settings.clearOverride("tui.hyperlinks");
|
|
});
|
|
|
|
afterAll(() => {
|
|
resetSettingsForTest();
|
|
});
|
|
|
|
describe("readToolRenderer hyperlinks", () => {
|
|
it("links local-style read titles to the resolved filesystem path and selected line", async () => {
|
|
settings.override("tui.hyperlinks", "always");
|
|
const theme = await getThemeByName("dark");
|
|
expect(theme).toBeDefined();
|
|
|
|
const component = readToolRenderer.renderResult(
|
|
{
|
|
content: [{ type: "text", text: "second line" }],
|
|
details: {
|
|
resolvedPath: "/tmp/omp-local/handoff.md",
|
|
displayContent: { text: "second line", startLine: 2 },
|
|
contentType: "text/plain",
|
|
},
|
|
},
|
|
{ expanded: false, isPartial: false },
|
|
theme!,
|
|
{ path: "local://handoff.md:2" },
|
|
);
|
|
|
|
const rendered = component.render(200).join("\n");
|
|
expect(rendered).toContain("local://handoff.md");
|
|
expect(rendered).toContain(":2");
|
|
expect(extractLinkUris(rendered)).toContain("file:///tmp/omp-local/handoff.md?line=2");
|
|
});
|
|
|
|
it("links HTTP read result headers to the final URL", async () => {
|
|
settings.override("tui.hyperlinks", "always");
|
|
const theme = await getThemeByName("dark");
|
|
expect(theme).toBeDefined();
|
|
|
|
const component = readToolRenderer.renderResult(
|
|
{
|
|
content: [{ type: "text", text: "---\n\nhello" }],
|
|
details: {
|
|
kind: "url",
|
|
url: "http://example.com/start",
|
|
finalUrl: "http://example.com/final",
|
|
contentType: "text/plain",
|
|
method: "fetch",
|
|
truncated: false,
|
|
notes: [],
|
|
},
|
|
} as never,
|
|
{ expanded: false, isPartial: false },
|
|
theme!,
|
|
{ path: "http://example.com/start" },
|
|
);
|
|
|
|
const rendered = component.render(200).join("\n");
|
|
expect(rendered).toContain("example.com /final");
|
|
expect(extractLinkUris(rendered)).toContain("http://example.com/final");
|
|
});
|
|
});
|