dist-mcp / mcp / toolResults.test.js
dist-mcp / mcp / toolResults.test.js
import assert from "node:assert/strict";
import path from "node:path";
import test from "node:test";
import { generateImageToolResult, generateSingleImageToolResult } from "./toolResults.js";
const scratchpadPath = "/tmp/example-scratchpad";
const reportPath = path.join(scratchpadPath, "generate-req-1.html");
function makeResult(overrides = {}) {
return {
index: 1,
notation: "i1",
filename: "image-a-i1.png",
absolutePath: path.join(scratchpadPath, "image-a-i1.png"),
isVideo: false,
...overrides,
};
}
test("mentions open_url_in_app_browser with the report's file:// URL (2+ results)", () => {
const text = generateImageToolResult("generate_image", reportPath, [makeResult(), makeResult({ index: 2, notation: "i2" })]);
assert.match(text, /open_url_in_app_browser/);
assert.match(text, /file:\/\/.*generate-req-1\.html/);
});
test("mentions view_images with the generated file's absolute path (2+ results)", () => {
const text = generateImageToolResult("generate_image", reportPath, [makeResult(), makeResult({ index: 2, notation: "i2" })]);
assert.match(text, /view_images/);
assert.match(text, /image-a-i1\.png/);
});
test("names the iN notation as the follow-up canvas/moodboard reference (2+ results)", () => {
const text = generateImageToolResult("generate_image", reportPath, [makeResult({ index: 2, notation: "i2" }), makeResult({ index: 3, notation: "i3" })]);
assert.match(text, /`i2`/);
});
test("adds a video-specific note pointing at the actual video file, separate from the still preview (2+ results)", () => {
const text = generateImageToolResult("generate_image", reportPath, [makeResult({ isVideo: true, videoFilename: "image-a-i1.mov" }), makeResult({ index: 2, notation: "i2" })]);
assert.match(text, /image-a-i1\.mov/);
assert.match(text, /still frame/);
});
test("upscale results are labeled with the upscale tool name (2+ results)", () => {
const text = generateImageToolResult("upscale", reportPath, [makeResult(), makeResult({ index: 2, notation: "i2" })]);
assert.match(text, /^upscale produced/);
});
test("single result: never mentions an HTML report", () => {
const text = generateSingleImageToolResult("generate_image", makeResult(), { model_used: "z_image_turbo.ckpt" });
assert.doesNotMatch(text, /\.html/);
});
test("single result: open_url_in_app_browser targets the generated file's own preview, not a report", () => {
const text = generateSingleImageToolResult("generate_image", makeResult(), undefined);
assert.match(text, /open_url_in_app_browser/);
assert.match(text, /file:\/\/.*image-a-i1\.png/);
});
test("single result: view_images uses the generated file's absolute path", () => {
const text = generateSingleImageToolResult("generate_image", makeResult(), undefined);
assert.match(text, /view_images/);
assert.match(text, /image-a-i1\.png/);
});
test("single result: metadata is inlined 1:1 from the tool call's summary, not a report reference", () => {
const summary = { model_used: "z_image_turbo.ckpt", width: 1024, height: 1024 };
const text = generateSingleImageToolResult("generate_image", makeResult(), summary);
assert.match(text, new RegExp(JSON.stringify(summary).replace(/[.*+?^${}()|[\]\\]/g, "\\$&")));
});
test("single result: names the iN notation as the follow-up canvas/moodboard reference", () => {
const text = generateSingleImageToolResult("generate_image", makeResult({ index: 2, notation: "i2" }), undefined);
assert.match(text, /`i2`/);
});
test("single result: adds a video-specific note pointing at the actual video file", () => {
const text = generateSingleImageToolResult("generate_image", makeResult({ isVideo: true, videoFilename: "image-a-i1.mov" }), undefined);
assert.match(text, /image-a-i1\.mov/);
assert.match(text, /still frame/);
});
test("single result: upscale is labeled with the upscale tool name", () => {
const text = generateSingleImageToolResult("upscale", makeResult(), undefined);
assert.match(text, /^upscale produced/);
});
import assert from "node:assert/strict";
import path from "node:path";
import test from "node:test";
import { generateImageToolResult, generateSingleImageToolResult } from "./toolResults.js";
const scratchpadPath = "/tmp/example-scratchpad";
const reportPath = path.join(scratchpadPath, "generate-req-1.html");
function makeResult(overrides = {}) {
return {
index: 1,
notation: "i1",
filename: "image-a-i1.png",
absolutePath: path.join(scratchpadPath, "image-a-i1.png"),
isVideo: false,
...overrides,
};
}
test("mentions open_url_in_app_browser with the report's file:// URL (2+ results)", () => {
const text = generateImageToolResult("generate_image", reportPath, [makeResult(), makeResult({ index: 2, notation: "i2" })]);
assert.match(text, /open_url_in_app_browser/);
assert.match(text, /file:\/\/.*generate-req-1\.html/);
});
test("mentions view_images with the generated file's absolute path (2+ results)", () => {
const text = generateImageToolResult("generate_image", reportPath, [makeResult(), makeResult({ index: 2, notation: "i2" })]);
assert.match(text, /view_images/);
assert.match(text, /image-a-i1\.png/);
});
test("names the iN notation as the follow-up canvas/moodboard reference (2+ results)", () => {
const text = generateImageToolResult("generate_image", reportPath, [makeResult({ index: 2, notation: "i2" }), makeResult({ index: 3, notation: "i3" })]);
assert.match(text, /`i2`/);
});
test("adds a video-specific note pointing at the actual video file, separate from the still preview (2+ results)", () => {
const text = generateImageToolResult("generate_image", reportPath, [makeResult({ isVideo: true, videoFilename: "image-a-i1.mov" }), makeResult({ index: 2, notation: "i2" })]);
assert.match(text, /image-a-i1\.mov/);
assert.match(text, /still frame/);
});
test("upscale results are labeled with the upscale tool name (2+ results)", () => {
const text = generateImageToolResult("upscale", reportPath, [makeResult(), makeResult({ index: 2, notation: "i2" })]);
assert.match(text, /^upscale produced/);
});
test("single result: never mentions an HTML report", () => {
const text = generateSingleImageToolResult("generate_image", makeResult(), { model_used: "z_image_turbo.ckpt" });
assert.doesNotMatch(text, /\.html/);
});
test("single result: open_url_in_app_browser targets the generated file's own preview, not a report", () => {
const text = generateSingleImageToolResult("generate_image", makeResult(), undefined);
assert.match(text, /open_url_in_app_browser/);
assert.match(text, /file:\/\/.*image-a-i1\.png/);
});
test("single result: view_images uses the generated file's absolute path", () => {
const text = generateSingleImageToolResult("generate_image", makeResult(), undefined);
assert.match(text, /view_images/);
assert.match(text, /image-a-i1\.png/);
});
test("single result: metadata is inlined 1:1 from the tool call's summary, not a report reference", () => {
const summary = { model_used: "z_image_turbo.ckpt", width: 1024, height: 1024 };
const text = generateSingleImageToolResult("generate_image", makeResult(), summary);
assert.match(text, new RegExp(JSON.stringify(summary).replace(/[.*+?^${}()|[\]\\]/g, "\\$&")));
});
test("single result: names the iN notation as the follow-up canvas/moodboard reference", () => {
const text = generateSingleImageToolResult("generate_image", makeResult({ index: 2, notation: "i2" }), undefined);
assert.match(text, /`i2`/);
});
test("single result: adds a video-specific note pointing at the actual video file", () => {
const text = generateSingleImageToolResult("generate_image", makeResult({ isVideo: true, videoFilename: "image-a-i1.mov" }), undefined);
assert.match(text, /image-a-i1\.mov/);
assert.match(text, /still frame/);
});
test("single result: upscale is labeled with the upscale tool name", () => {
const text = generateSingleImageToolResult("upscale", makeResult(), undefined);
assert.match(text, /^upscale produced/);
});