feat: separate publish step logs in diagnostics

This commit is contained in:
Oleg Isonen committed 2026-11-13 22:18:56 +00:00
1 parent 686e6ab092
commit 75e615b126
6 files changed
+216 -10

No files matched your search

@@ -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<HTMLButtonElement>("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<HTMLButtonElement>(
'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<HTMLButtonElement>(
'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(
[
@@ -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" ? (
<Text
as="pre"
userSelect="text"
css={{
whiteSpace: "pre-wrap",
overflowWrap: "anywhere",
}}
>
{item.logText}
</Text>
item.logSteps === undefined ? (
<Text
as="pre"
userSelect="text"
css={{
whiteSpace: "pre-wrap",
overflowWrap: "anywhere",
}}
>
{item.logText}
</Text>
) : (
item.logSteps.map((step, index) => (
<Collapsible.Root
key={index}
defaultOpen={step.status !== "success"}
>
<Collapsible.Trigger asChild>
<SectionTitle
suffixPlaceholder={
<CopyIcon aria-hidden />
}
suffix={
<CopyToClipboard
text={step.text}
copyText="Copy log"
>
<IconButton
type="button"
aria-label="Copy log"
onPointerDown={(event) =>
event.stopPropagation()
}
>
<CopyIcon aria-hidden />
</IconButton>
</CopyToClipboard>
}
>
<SectionTitleLabel>
{step.name}
</SectionTitleLabel>
</SectionTitle>
</Collapsible.Trigger>
<Collapsible.Content>
<Text
as="pre"
userSelect="text"
css={{
whiteSpace: "pre-wrap",
overflowWrap: "anywhere",
}}
>
{step.text}
</Text>
</Collapsible.Content>
</Collapsible.Root>
))
)
) : (
<Text color="subtle">
{item.logHandle === undefined ||
@@ -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(() =>
@@ -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<PublishLog["issues"]> = [];
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"),
@@ -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",
@@ -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({