mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-28 13:10:40 +00:00
refactor(extensions): reuse shared helper primitives
This commit is contained in:
@@ -95,23 +95,11 @@ describe("diffs tool", () => {
|
||||
});
|
||||
|
||||
it("renders PDF output when fileFormat is pdf", async () => {
|
||||
const screenshotter = {
|
||||
screenshotHtml: vi.fn(
|
||||
async ({
|
||||
outputPath,
|
||||
image,
|
||||
}: {
|
||||
outputPath: string;
|
||||
image: { format: string; qualityPreset: string; scale: number; maxWidth: number };
|
||||
}) => {
|
||||
expect(image.format).toBe("pdf");
|
||||
expect(outputPath).toMatch(/preview\.pdf$/);
|
||||
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
||||
await fs.writeFile(outputPath, Buffer.from("%PDF-1.7"));
|
||||
return outputPath;
|
||||
},
|
||||
),
|
||||
};
|
||||
const screenshotter = createPdfScreenshotter({
|
||||
assertOutputPath: (outputPath) => {
|
||||
expect(outputPath).toMatch(/preview\.pdf$/);
|
||||
},
|
||||
});
|
||||
|
||||
const tool = createDiffsTool({
|
||||
api: createApi(),
|
||||
@@ -208,22 +196,7 @@ describe("diffs tool", () => {
|
||||
});
|
||||
|
||||
it("accepts deprecated format alias for fileFormat", async () => {
|
||||
const screenshotter = {
|
||||
screenshotHtml: vi.fn(
|
||||
async ({
|
||||
outputPath,
|
||||
image,
|
||||
}: {
|
||||
outputPath: string;
|
||||
image: { format: string; qualityPreset: string; scale: number; maxWidth: number };
|
||||
}) => {
|
||||
expect(image.format).toBe("pdf");
|
||||
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
||||
await fs.writeFile(outputPath, Buffer.from("%PDF-1.7"));
|
||||
return outputPath;
|
||||
},
|
||||
),
|
||||
};
|
||||
const screenshotter = createPdfScreenshotter();
|
||||
|
||||
const tool = createDiffsTool({
|
||||
api: createApi(),
|
||||
@@ -492,6 +465,23 @@ function createPngScreenshotter(
|
||||
};
|
||||
}
|
||||
|
||||
function createPdfScreenshotter(
|
||||
params: {
|
||||
assertOutputPath?: (outputPath: string) => void;
|
||||
} = {},
|
||||
): DiffScreenshotter {
|
||||
const screenshotHtml: DiffScreenshotter["screenshotHtml"] = vi.fn(
|
||||
async ({ outputPath, image }: { outputPath: string; image: DiffRenderOptions["image"] }) => {
|
||||
expect(image.format).toBe("pdf");
|
||||
params.assertOutputPath?.(outputPath);
|
||||
await fs.mkdir(path.dirname(outputPath), { recursive: true });
|
||||
await fs.writeFile(outputPath, Buffer.from("%PDF-1.7"));
|
||||
return outputPath;
|
||||
},
|
||||
);
|
||||
return { screenshotHtml };
|
||||
}
|
||||
|
||||
function readTextContent(result: unknown, index: number): string {
|
||||
const content = (result as { content?: Array<{ type?: string; text?: string }> } | undefined)
|
||||
?.content;
|
||||
|
||||
Reference in New Issue
Block a user