diff --git a/apps/builder/app/builder/features/publish/publish-diagnostics-dialog.test.tsx b/apps/builder/app/builder/features/publish/publish-diagnostics-dialog.test.tsx index d229ec9e51..711b5cc297 100644 --- a/apps/builder/app/builder/features/publish/publish-diagnostics-dialog.test.tsx +++ b/apps/builder/app/builder/features/publish/publish-diagnostics-dialog.test.tsx @@ -328,6 +328,66 @@ test("lists each publish domain and copies the full loaded log", async () => { expect(copied).toContain("third.example"); }); +test("shows separate collapsible steps and copies only the selected step", async () => { + const writeText = vi.fn(async (_text: string) => {}); + Object.defineProperty(navigator, "clipboard", { + configurable: true, + value: { writeText }, + }); + render( + [], + true, + [ + { + buildId: "build-1", + target: "site", + domains: ["example.com"], + findings: [], + status: "failed", + logState: "available", + logText: "\nBuild (failure)\nfailed\n\nDeploy\ndone\n", + logSteps: [ + { name: "Build", status: "failure", text: "failed\n" }, + { name: "Deploy", status: "success", text: "done\n" }, + ], + }, + ], + undefined, + true + ); + const buttons = Array.from( + document.body.querySelectorAll("button[aria-labelledby]") + ); + const labelOf = (button: HTMLButtonElement) => + document.getElementById(button.getAttribute("aria-labelledby") ?? "") + ?.textContent; + const build = buttons.find((button) => labelOf(button) === "Build"); + const deploy = buttons.find((button) => labelOf(button) === "Deploy"); + expect(build).toBeDefined(); + expect(deploy).toBeDefined(); + expect(build?.getAttribute("aria-expanded")).toBe("true"); + expect(deploy?.getAttribute("aria-expanded")).toBe("false"); + await act(async () => userEvent.click(deploy!)); + expect(deploy?.getAttribute("aria-expanded")).toBe("true"); + const copyButtons = document.body.querySelectorAll( + 'button[aria-label="Copy log"]' + ); + expect(copyButtons).toHaveLength(2); + await act(async () => userEvent.click(copyButtons[1]!)); + expect(writeText).toHaveBeenCalledWith("done\n"); + expect(deploy?.getAttribute("aria-expanded")).toBe("true"); + await act(async () => + userEvent.click( + document.body.querySelector( + 'button[aria-label="Copy all reports"]' + )! + ) + ); + expect(writeText).toHaveBeenLastCalledWith( + "example.com\n\nBuild (failure)\nfailed\n\nDeploy\ndone\n" + ); +}); + test("publish failure is plain text and links to the Publish tab", async () => { render( [ diff --git a/apps/builder/app/builder/features/publish/publish-diagnostics-dialog.tsx b/apps/builder/app/builder/features/publish/publish-diagnostics-dialog.tsx index 6b740dcff0..aa145ffa9d 100644 --- a/apps/builder/app/builder/features/publish/publish-diagnostics-dialog.tsx +++ b/apps/builder/app/builder/features/publish/publish-diagnostics-dialog.tsx @@ -1,6 +1,7 @@ import { Fragment, useEffect, useState, type ReactNode } from "react"; import { Button, + Collapsible, Dialog, DialogClose, DialogContent, @@ -15,6 +16,8 @@ import { PanelTabsList, PanelTabsTrigger, ScrollArea, + SectionTitle, + SectionTitleLabel, Separator, Text, } from "@webstudio-is/design-system"; @@ -388,16 +391,65 @@ export const PublishDiagnosticsDialog = ({ {canViewPublishLogs && item.status !== "pending" && (item.logState === "available" ? ( - - {item.logText} - + item.logSteps === undefined ? ( + + {item.logText} + + ) : ( + item.logSteps.map((step, index) => ( + + + + } + suffix={ + + + event.stopPropagation() + } + > + + + + } + > + + {step.name} + + + + + + {step.text} + + + + )) + ) ) : ( {item.logHandle === undefined || diff --git a/apps/builder/app/builder/features/publish/use-publish-logs.test.tsx b/apps/builder/app/builder/features/publish/use-publish-logs.test.tsx index 9dd747e95d..d5b88f9aa9 100644 --- a/apps/builder/app/builder/features/publish/use-publish-logs.test.tsx +++ b/apps/builder/app/builder/features/publish/use-publish-logs.test.tsx @@ -175,6 +175,30 @@ test("Free does not fetch logs, then Pro reads the full UTF-8 log from byte zero expect(session.items[0]?.issues).toBeUndefined(); }); +test("decodes structured step boundaries without reading headings from log text", () => { + const first = new TextEncoder().encode("\nBuild\nfailed €\n"); + const second = new TextEncoder().encode("\nDeploy\ndone\n"); + const bytes = new Uint8Array([...first, ...second]); + const chunks = [ + encoded([...bytes.subarray(0, first.length - 3)]), + encoded([...bytes.subarray(first.length - 3)]), + ]; + expect( + sessionModule.decodePublishLogSteps(chunks, [ + { name: "Build", status: "failure", offset: 0, contentOffset: 7 }, + { + name: "Deploy", + status: "success", + offset: first.length, + contentOffset: first.length + 8, + }, + ]) + ).toEqual([ + { name: "Build", status: "failure", text: "failed €\n" }, + { name: "Deploy", status: "success", text: "done\n" }, + ]); +}); + test("missing execution handle does not retry an accepted publish", () => { render(false); act(() => diff --git a/apps/builder/app/builder/features/publish/use-publish-logs.tsx b/apps/builder/app/builder/features/publish/use-publish-logs.tsx index 9319f018c4..c5cc268dab 100644 --- a/apps/builder/app/builder/features/publish/use-publish-logs.tsx +++ b/apps/builder/app/builder/features/publish/use-publish-logs.tsx @@ -18,6 +18,7 @@ export type PublishLog = { issuesOmitted?: number; logState?: "loading" | "available" | "unavailable"; logText?: string; + logSteps?: { name: string; status: string; text: string }[]; }; const decodeChunk = (chunk: string) => { @@ -34,6 +35,37 @@ export const decodePublishLog = (chunks: string[]) => { .join(""); }; +export const decodePublishLogSteps = ( + chunks: string[], + steps: { + name: string; + status: string; + offset: number; + contentOffset: number; + }[] +) => { + const decoded = chunks.map(decodeChunk); + const bytes = new Uint8Array( + decoded.reduce((total, chunk) => total + chunk.byteLength, 0) + ); + let offset = 0; + for (const chunk of decoded) { + bytes.set(chunk, offset); + offset += chunk.byteLength; + } + const decoder = new TextDecoder(); + return steps.map((step, index) => ({ + name: step.name, + status: step.status, + text: decoder.decode( + bytes.subarray( + step.contentOffset, + steps[index + 1]?.offset ?? bytes.length + ) + ), + })); +}; + export const getPublishDuration = (item: PublishLog) => { if (item.startedAt === undefined || item.completedAt === undefined) { return; @@ -116,6 +148,7 @@ export const usePublishLogs = ( issuesOmitted: undefined, logState: undefined, logText: undefined, + logSteps: undefined, })) ); } @@ -201,6 +234,12 @@ export const usePublishLogs = ( try { let cursor: number | undefined; const chunks: string[] = []; + const steps: { + name: string; + status: string; + offset: number; + contentOffset: number; + }[] = []; const issues: NonNullable = []; let issuesOmitted = 0; while (isReadCurrent()) { @@ -229,6 +268,7 @@ export const usePublishLogs = ( return; } chunks.push(log.chunk); + steps.push(...(log.steps ?? [])); for (const issue of log.issues ?? []) { if (issues.length < 20) { issues.push(issue); @@ -249,6 +289,10 @@ export const usePublishLogs = ( update(item.buildId, { logState: "available", logText: decodePublishLog(chunks), + logSteps: + steps.length > 0 + ? decodePublishLogSteps(chunks, steps) + : undefined, issues: [ ...issues.filter(({ severity }) => severity === "error"), ...issues.filter(({ severity }) => severity === "warning"), diff --git a/packages/trpc-interface/src/shared/deployment-contract.test.ts b/packages/trpc-interface/src/shared/deployment-contract.test.ts index 7c9b54b080..ec59e9d659 100644 --- a/packages/trpc-interface/src/shared/deployment-contract.test.ts +++ b/packages/trpc-interface/src/shared/deployment-contract.test.ts @@ -30,6 +30,22 @@ test("the public deployment contract validates publish and status-only log reque code: "cancelled", }).availability ).toBe("available"); + const page = publishLogOutput.parse({ + availability: "available", + outcome: "failed", + logAvailability: "available", + log: { + encoding: "base64url", + chunk: "ZmFpbGVk", + complete: true, + steps: [ + { name: "Build", status: "failure", offset: 0, contentOffset: 7 }, + ], + }, + }); + expect(page.availability === "available" && page.log?.steps).toEqual([ + { name: "Build", status: "failure", offset: 0, contentOffset: 7 }, + ]); expect( publishLogInput.safeParse({ buildId: "build-1", diff --git a/packages/trpc-interface/src/shared/deployment-contract.ts b/packages/trpc-interface/src/shared/deployment-contract.ts index f158f823c3..4318d68136 100644 --- a/packages/trpc-interface/src/shared/deployment-contract.ts +++ b/packages/trpc-interface/src/shared/deployment-contract.ts @@ -69,6 +69,16 @@ export const publishLogOutput = z.discriminatedUnion("availability", [ chunk: z.string().max(400_000), complete: z.boolean(), nextCursor: z.number().int().nonnegative().safe().optional(), + steps: z + .array( + z.object({ + name: z.string(), + status: z.string(), + offset: z.number().int().nonnegative().safe(), + contentOffset: z.number().int().nonnegative().safe(), + }) + ) + .optional(), issues: z .array( z.object({