test: simplify diffs viewer id extraction

This commit is contained in:
Peter Steinberger
2026-05-09 00:01:23 +01:00
parent 6e2b1d6366
commit f7e9c315e4

View File

@@ -397,7 +397,7 @@ describe("diffs tool", () => {
});
const viewerPath = String((result?.details as Record<string, unknown>).viewerPath);
const [id] = viewerPath.split("/").filter(Boolean).slice(-2);
const id = extractViewerArtifactId(viewerPath);
const html = await store.readHtml(id);
expect(html).toContain('body data-theme="light"');
expect(html).toContain("--diffs-font-size: 17px;");
@@ -446,7 +446,7 @@ describe("diffs tool", () => {
expect((result?.details as Record<string, unknown>).fileScale).toBe(2.75);
expect((result?.details as Record<string, unknown>).fileMaxWidth).toBe(1320);
const viewerPath = String((result?.details as Record<string, unknown>).viewerPath);
const [id] = viewerPath.split("/").filter(Boolean).slice(-2);
const id = extractViewerArtifactId(viewerPath);
const html = await store.readHtml(id);
expect(html).toContain('body data-theme="dark"');
});
@@ -580,6 +580,22 @@ function readDetails(result: unknown): Record<string, unknown> {
return details;
}
function extractViewerArtifactId(viewerPath: string): string {
let previousSegment: string | undefined;
let currentSegment: string | undefined;
for (const segment of viewerPath.split("/")) {
if (segment.length === 0) {
continue;
}
previousSegment = currentSegment;
currentSegment = segment;
}
if (!previousSegment) {
throw new Error(`Missing artifact id in viewer path: ${viewerPath}`);
}
return previousSegment;
}
function readParametersProperties(parameters: unknown): Record<string, unknown> {
if (isRecord(parameters) && isRecord(parameters.properties)) {
return parameters.properties;