Use source images as article references
This commit is contained in:
@@ -25,11 +25,12 @@ const prisma = {
|
||||
page: { findUnique: async () => ({ profile: null }) },
|
||||
};
|
||||
let automationCalls = 0;
|
||||
let automationBody = null;
|
||||
const provider = load("../src/lib/ai/image.ts", {
|
||||
"@/lib/db": { prisma },
|
||||
"@/lib/facebook/client": { UserFacingError },
|
||||
"./image-shared": shared,
|
||||
"./automation": { runAutomation: async (body) => { automationCalls++; assert.equal(body.kind, "image"); return { b64: Buffer.from("image").toString("base64") }; } },
|
||||
"./automation": { runAutomation: async (body) => { automationCalls++; automationBody = body; assert.equal(body.kind, "image"); return { b64: Buffer.from("image").toString("base64") }; } },
|
||||
});
|
||||
const { POST } = load("../src/app/api/ai/image/route.ts", {
|
||||
"next/server": { NextResponse: { json: (data, init) => Response.json(data, init) } },
|
||||
@@ -45,6 +46,8 @@ const { POST } = load("../src/app/api/ai/image/route.ts", {
|
||||
"@/lib/facebook/client": { UserFacingError },
|
||||
"@/lib/ai/claude": { generateStructured: async () => ({ prompt: "Soft natural light, a cake on a wooden table." }) },
|
||||
"@/lib/ai/shared": { profilePrompt: () => "" },
|
||||
"@/lib/ai/brand-palette": { logoPalettePrompt: async () => "" },
|
||||
"@/lib/ai/prompts": { IMAGE_ART_DIRECTION: "" },
|
||||
"@/lib/ai/image-shared": shared,
|
||||
"@/lib/ai/image": { assertImageQuota: provider.assertImageQuota, generateImage: async () => {
|
||||
generated++;
|
||||
@@ -74,6 +77,18 @@ const prompt = await (await request({ action: "prompt", description: "Cake" })).
|
||||
assert.equal(prompt.profileMissing, true);
|
||||
assert.ok(prompt.prompt);
|
||||
|
||||
assert.equal((await provider.generateImage("Cake", "landscape")).bytes.toString(), "image");
|
||||
assert.equal((await provider.generateImage("Cake", "landscape", false, "https://example.test/source.jpg")).bytes.toString(), "image");
|
||||
assert.equal(automationCalls, 1);
|
||||
assert.equal(automationBody.referenceImageUrl, "https://example.test/source.jpg");
|
||||
|
||||
const originalFetch = globalThis.fetch;
|
||||
globalThis.fetch = async () => new Response('<html><head><meta property="og:image" content="/news/source.jpg"><title>Source story</title></head><body><article>Useful source text</article></body></html>', { headers: { "content-type": "text/html" } });
|
||||
const website = load("../src/lib/ai/website.ts", {
|
||||
"node:dns/promises": { lookup: async () => [{ address: "203.0.113.10" }] },
|
||||
"node:net": { isIP: () => 0 },
|
||||
});
|
||||
const research = await website.websiteResearch("https://publisher.example/story");
|
||||
globalThis.fetch = originalFetch;
|
||||
assert.equal(research.imageUrl, "https://publisher.example/news/source.jpg");
|
||||
assert.match(research.prompt, /Useful source text/);
|
||||
console.log("AI image checks passed: page authorization, input validation, quota, storage, usage, browser-worker bridge.");
|
||||
|
||||
Reference in New Issue
Block a user