fix(webui): restore full-project typechecking
This commit is contained in:
1 parent
f869212e7d
commit
a1bca7dc50
56 files changed
+622
-583
No files matched your search
@@ -82,8 +82,10 @@ describe("FilePreviewPanel", () => {
|
||||
vi.mocked(fetchFilePreview).mockImplementation(async (_token, _session, path) => {
|
||||
const details = path.endsWith("details.md");
|
||||
const name = details ? "details.md" : "REPORT.md";
|
||||
const content = details ? "# Details\n\n[Return](./REPORT.md)\n" : report;
|
||||
return { path: `/workspace/reports/${name}`, display_path: `reports/${name}`,
|
||||
language: "markdown", content: details ? "# Details\n\n[Return](./REPORT.md)\n" : report, truncated: false };
|
||||
project_path: "/workspace", size: new TextEncoder().encode(content).byteLength,
|
||||
language: "markdown", content, truncated: false };
|
||||
});
|
||||
const store = new FilePreviewStore();
|
||||
const resource = createFilePreviewResource(path => fetchFilePreview("test", "a", path));
|
||||
@@ -118,7 +120,7 @@ describe("FilePreviewPanel", () => {
|
||||
it("opens the sidebar image in the shared zoomable viewer and returns to the preview", async () => {
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue({
|
||||
kind: "image", path: "/workspace/chart.png", display_path: "chart.png",
|
||||
size: 42, mime_type: "image/png", data_url: "data:image/png;base64,example",
|
||||
project_path: "/workspace", size: 42, mime_type: "image/png", data_url: "data:image/png;base64,example",
|
||||
});
|
||||
render(<FilePreviewPanel sessionKey="websocket:a" path="chart.png" token="test" />);
|
||||
const trigger = await screen.findByRole("button", { name: "View image: chart.png" });
|
||||
@@ -139,6 +141,8 @@ describe("FilePreviewPanel", () => {
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue({
|
||||
path: "/Users/hr/workspace/quicksort.py",
|
||||
display_path: "quicksort.py",
|
||||
project_path: "/Users/hr/workspace",
|
||||
size: 11,
|
||||
language: "python",
|
||||
content: "print('ok')",
|
||||
truncated: false,
|
||||
@@ -162,7 +166,7 @@ describe("FilePreviewPanel", () => {
|
||||
});
|
||||
|
||||
it("paints cached content immediately, revalidates it, and does not restart when the cache ages", async () => {
|
||||
const cached = { path: "notes.txt", display_path: "notes.txt", language: "text", content: "Cached", truncated: false };
|
||||
const cached = { path: "notes.txt", display_path: "notes.txt", project_path: "/workspace", size: 6, language: "text", content: "Cached", truncated: false };
|
||||
let resolve!: (payload: typeof cached) => void;
|
||||
const loadPreview = vi.fn(() => new Promise<typeof cached>(r => { resolve = r; }));
|
||||
const view = (initialPreview?: typeof cached) => <FilePreviewPanel sessionKey="a" path="notes.txt"
|
||||
@@ -178,7 +182,7 @@ describe("FilePreviewPanel", () => {
|
||||
});
|
||||
|
||||
it("reports a failed revalidation rather than leaving stale cached content looking current", async () => {
|
||||
const cached = { path: "notes.txt", display_path: "notes.txt", language: "text", content: "Cached", truncated: false };
|
||||
const cached = { path: "notes.txt", display_path: "notes.txt", project_path: "/workspace", size: 6, language: "text", content: "Cached", truncated: false };
|
||||
render(<FilePreviewPanel sessionKey="a" path="notes.txt" token="test" initialPreview={cached}
|
||||
loadPreview={vi.fn().mockRejectedValue(new Error("Forbidden"))} />);
|
||||
await screen.findByText("Could not preview this file.");
|
||||
@@ -186,7 +190,7 @@ describe("FilePreviewPanel", () => {
|
||||
});
|
||||
|
||||
it("does not repaint a cache hit twice after its initial synchronous paint", async () => {
|
||||
const cached = { path: "notes.txt", display_path: "notes.txt", language: "text", content: "Cached", truncated: false };
|
||||
const cached = { path: "notes.txt", display_path: "notes.txt", project_path: "/workspace", size: 6, language: "text", content: "Cached", truncated: false };
|
||||
const loadPreview = vi.fn().mockResolvedValue(cached);
|
||||
render(<FilePreviewPanel sessionKey="a" path="notes.txt" token="test"
|
||||
initialPreview={cached} loadPreview={loadPreview} />);
|
||||
@@ -199,6 +203,8 @@ describe("FilePreviewPanel", () => {
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue({
|
||||
path: "/workspace/notes.md",
|
||||
display_path: "notes.md",
|
||||
project_path: "/workspace",
|
||||
size: 7,
|
||||
language: "markdown",
|
||||
content: "# Notes",
|
||||
truncated: false,
|
||||
@@ -227,6 +233,7 @@ describe("FilePreviewPanel", () => {
|
||||
it("defaults old Markdown payloads to preview and switches to exact source without another read", async () => {
|
||||
const content = "# Report\n\n**Done**\n\n| Item | Status |\n| --- | --- |\n| Copy | OK |\n";
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue({ path: "/workspace/REPORT.md", display_path: "REPORT.md",
|
||||
project_path: "/workspace", size: new TextEncoder().encode(content).byteLength,
|
||||
language: "markdown", content, truncated: true });
|
||||
render(<FilePreviewPanel sessionKey="a" path="REPORT.md" token="test" />);
|
||||
await screen.findByRole("heading", { name: "Report" });
|
||||
@@ -250,7 +257,7 @@ describe("FilePreviewPanel", () => {
|
||||
|
||||
it("resets the display for another file or session but keeps source on credential renewal", async () => {
|
||||
const payload = { path: "/workspace/notes.md", display_path: "notes.md", language: "markdown",
|
||||
content: "# Notes", truncated: false };
|
||||
project_path: "/workspace", size: 7, content: "# Notes", truncated: false };
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue(payload);
|
||||
const view = (path: string, sessionKey = "a", token = "old") =>
|
||||
<FilePreviewPanel sessionKey={sessionKey} path={path} token={token} />;
|
||||
@@ -270,14 +277,16 @@ describe("FilePreviewPanel", () => {
|
||||
|
||||
it("keeps document resources inert and opens relative links through the session preview callback", async () => {
|
||||
const open = vi.fn();
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue({ path: "/workspace/reports/REPORT.mdx", display_path: "reports/REPORT.mdx",
|
||||
language: "markdown", truncated: false, content: [
|
||||
const content = [
|
||||
"# Report", "[Local](../notes%20one.md)", "",
|
||||
"- Reference — [Website](https://example.com)", "[Section](#details)", "[Chat](#/chat/websocket:other)",
|
||||
"[Unsafe](javascript:alert(1))", '<img src="https://example.com/raw.png" onerror="alert(1)">',
|
||||
'<iframe src="https://example.com/frame"></iframe>', '<script>alert(1)</script>',
|
||||
"`skills/cron/SKILL.md`", "<CustomComponent />",
|
||||
].join("\n\n") });
|
||||
].join("\n\n");
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue({ path: "/workspace/reports/REPORT.mdx", display_path: "reports/REPORT.mdx",
|
||||
project_path: "/workspace", size: new TextEncoder().encode(content).byteLength,
|
||||
language: "markdown", truncated: false, content });
|
||||
const { container } = render(<FilePreviewPanel sessionKey="a" path="reports/REPORT.mdx" token="test" onOpenFilePreview={open} />);
|
||||
await screen.findByRole("heading", { name: "Report" });
|
||||
expect(container.querySelector("img, iframe, script, video, audio")).toBeNull();
|
||||
@@ -294,7 +303,7 @@ describe("FilePreviewPanel", () => {
|
||||
it("preserves the open image and zoom on token renewal, using the current token for the next file", async () => {
|
||||
vi.mocked(fetchFilePreview).mockResolvedValue({
|
||||
kind: "image", path: "/workspace/chart.png", display_path: "chart.png",
|
||||
size: 42, mime_type: "image/png", data_url: "data:image/png;base64,example",
|
||||
project_path: "/workspace", size: 42, mime_type: "image/png", data_url: "data:image/png;base64,example",
|
||||
});
|
||||
const view = (token: string, path = "chart.png") =>
|
||||
<FilePreviewPanel sessionKey="websocket:a" path={path} token={token} />;
|
||||
|
||||
Reference in new issue
Block a user