fix: group diagnostics by complete publish

This commit is contained in:
Oleg Isonen committed 2026-11-13 22:22:11 +00:00
1 parent 75e615b126
commit c67e693d94
6 files changed
+161 -277

No files matched your search

@@ -328,7 +328,7 @@ 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 () => {
test("collapses each complete publish and copies its full log from the header", async () => {
const writeText = vi.fn(async (_text: string) => {});
Object.defineProperty(navigator, "clipboard", {
configurable: true,
@@ -341,51 +341,44 @@ test("shows separate collapsible steps and copies only the selected step", async
{
buildId: "build-1",
target: "site",
domains: ["example.com"],
domains: ["first.example"],
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" },
],
logText: "Complete first publish log",
},
{
buildId: "build-2",
target: "site",
domains: ["second.example"],
findings: [],
status: "success",
logState: "available",
logText: "Complete second publish log",
},
],
undefined,
true
);
const buttons = Array.from(
const triggers = 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");
expect(triggers).toHaveLength(2);
expect(triggers[0]?.getAttribute("aria-expanded")).toBe("true");
expect(triggers[1]?.getAttribute("aria-expanded")).toBe("false");
expect(document.body.textContent).toContain("Complete first publish log");
expect(document.body.textContent).not.toContain(
"Complete second publish log"
);
await act(async () => userEvent.click(triggers[1]!));
expect(document.body.textContent).toContain("Complete second publish log");
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"
);
expect(writeText).toHaveBeenCalledWith("Complete second publish log");
expect(triggers[1]?.getAttribute("aria-expanded")).toBe("true");
});
test("publish failure is plain text and links to the Publish tab", async () => {
@@ -343,164 +343,149 @@ export const PublishDiagnosticsDialog = ({
{items.length === 0 && (
<Text color="subtle">No publishes in this session.</Text>
)}
{items.map((item) => {
{items.map((item, index) => {
const duration = getPublishDuration(item);
return (
<Flex key={item.buildId} direction="column" gap={2}>
{item.domains.length > 0 ? (
<Flex direction="column" gap={1}>
{item.domains.map((domain) => (
<Text key={domain} variant="labels">
{domain}
</Text>
))}
</Flex>
) : (
<Text variant="labels">Static export</Text>
)}
<Text color="subtle">
{item.status === "pending"
? "Publishing started"
: item.status === "success"
? "Published"
: "Publish failed"}
</Text>
{canViewPublishLogs &&
item.startedAt !== undefined && (
<Text>
Started:{" "}
{new Date(item.startedAt).toLocaleString()}
</Text>
)}
{canViewPublishLogs && duration !== undefined && (
<Text>Duration: {duration}s</Text>
)}
{canViewPublishLogs &&
item.status === "failed" &&
(item.failedStage !== undefined ||
item.code !== undefined) && (
<Text color="destructive">
{[
item.failedStage,
item.code?.replaceAll("_", " "),
]
.filter(Boolean)
.join(" · ")}
</Text>
)}
{canViewPublishLogs &&
item.status !== "pending" &&
(item.logState === "available" ? (
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>
<Collapsible.Root
key={item.buildId}
asChild
defaultOpen={index === 0}
>
<Flex direction="column" gap={2}>
<Collapsible.Trigger asChild>
<SectionTitle
suffixPlaceholder={<CopyIcon aria-hidden />}
suffix={
canViewPublishLogs &&
item.logState === "available" &&
item.logText !== undefined && (
<CopyToClipboard
text={item.logText}
copyText="Copy log"
>
<IconButton
type="button"
aria-label="Copy log"
onPointerDown={(event) =>
event.stopPropagation()
}
>
<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 ||
item.logState === "unavailable"
? "Publish logs are unavailable."
: "Loading logs…"}
</Text>
))}
{item.findings.length > 0 && (
<Flex direction="column" gap={1}>
<Text variant="labels">Audit</Text>
{item.findings.map((finding, index) => (
<Text key={index}>
{canViewPublishLogs
? (finding.summary ?? finding.title)
: shortFinding(finding)}
</Text>
))}
</Flex>
)}
{canViewPublishLogs &&
item.issues !== undefined &&
item.issues.length > 0 && (
<Text variant="labels">Build</Text>
)}
{canViewPublishLogs &&
item.issues?.map((issue, index) => (
<Text
key={index}
color={
issue.severity === "error"
? "destructive"
: "subtle"
<CopyIcon aria-hidden />
</IconButton>
</CopyToClipboard>
)
}
>
{issue.message}
</Text>
))}
{canViewPublishLogs &&
(item.issuesOmitted ?? 0) > 0 && (
<Text color="subtle">
{item.issuesOmitted} more issues not shown.
</Text>
)}
{!canViewPublishLogs && (
<Text color="subtle">
Upgrade to Pro to view publish logs.
</Text>
)}
<Separator />
</Flex>
<SectionTitleLabel>
{item.domains.length > 0
? item.domains.join(" · ")
: "Static export"}
</SectionTitleLabel>
</SectionTitle>
</Collapsible.Trigger>
<Collapsible.Content asChild>
<Flex direction="column" gap={2}>
<Text color="subtle">
{item.status === "pending"
? "Publishing started"
: item.status === "success"
? "Published"
: "Publish failed"}
</Text>
{canViewPublishLogs &&
item.startedAt !== undefined && (
<Text>
Started:{" "}
{new Date(
item.startedAt
).toLocaleString()}
</Text>
)}
{canViewPublishLogs &&
duration !== undefined && (
<Text>Duration: {duration}s</Text>
)}
{canViewPublishLogs &&
item.status === "failed" &&
(item.failedStage !== undefined ||
item.code !== undefined) && (
<Text color="destructive">
{[
item.failedStage,
item.code?.replaceAll("_", " "),
]
.filter(Boolean)
.join(" · ")}
</Text>
)}
{canViewPublishLogs &&
item.status !== "pending" &&
(item.logState === "available" ? (
<Text
as="pre"
userSelect="text"
css={{
whiteSpace: "pre-wrap",
overflowWrap: "anywhere",
}}
>
{item.logText}
</Text>
) : (
<Text color="subtle">
{item.logHandle === undefined ||
item.logState === "unavailable"
? "Publish logs are unavailable."
: "Loading logs…"}
</Text>
))}
{item.findings.length > 0 && (
<Flex direction="column" gap={1}>
<Text variant="labels">Audit</Text>
{item.findings.map((finding, index) => (
<Text key={index}>
{canViewPublishLogs
? (finding.summary ?? finding.title)
: shortFinding(finding)}
</Text>
))}
</Flex>
)}
{canViewPublishLogs &&
item.issues !== undefined &&
item.issues.length > 0 && (
<Text variant="labels">Build</Text>
)}
{canViewPublishLogs &&
item.issues?.map((issue, index) => (
<Text
key={index}
color={
issue.severity === "error"
? "destructive"
: "subtle"
}
>
{issue.message}
</Text>
))}
{canViewPublishLogs &&
(item.issuesOmitted ?? 0) > 0 && (
<Text color="subtle">
{item.issuesOmitted} more issues not
shown.
</Text>
)}
{!canViewPublishLogs && (
<Text color="subtle">
Upgrade to Pro to view publish logs.
</Text>
)}
</Flex>
</Collapsible.Content>
<Separator />
</Flex>
</Collapsible.Root>
);
})}
</PanelContent>
@@ -175,30 +175,6 @@ 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,7 +18,6 @@ export type PublishLog = {
issuesOmitted?: number;
logState?: "loading" | "available" | "unavailable";
logText?: string;
logSteps?: { name: string; status: string; text: string }[];
};
const decodeChunk = (chunk: string) => {
@@ -35,37 +34,6 @@ 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;
@@ -148,7 +116,6 @@ export const usePublishLogs = (
issuesOmitted: undefined,
logState: undefined,
logText: undefined,
logSteps: undefined,
}))
);
}
@@ -234,12 +201,6 @@ 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()) {
@@ -268,7 +229,6 @@ 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);
@@ -289,10 +249,6 @@ 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,22 +30,6 @@ 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,16 +69,6 @@ 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({