Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Generate images via OpenAI, Google, OpenRouter, DashScope, Jimeng, Seedream, and Replicate APIs with batch support.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/build-batch.test.ts
1import assert from "node:assert/strict";2import fs from "node:fs/promises";3import os from "node:os";4import path from "node:path";5import { execFile } from "node:child_process";6import { promisify } from "node:util";7import test from "node:test";89const execFileAsync = promisify(execFile);10const repoRoot = path.resolve(import.meta.dirname, "..", "..", "..");11const scriptPath = path.join(repoRoot, "skills", "baoyu-image-gen", "scripts", "build-batch.ts");1213async function makeFixture(): Promise<{14root: string;15outlinePath: string;16promptsDir: string;17outputPath: string;18}> {19const root = await fs.mkdtemp(path.join(os.tmpdir(), "baoyu-image-gen-build-batch-"));20const outlinePath = path.join(root, "outline.md");21const promptsDir = path.join(root, "prompts");22const outputPath = path.join(root, "batch.json");2324await fs.mkdir(promptsDir, { recursive: true });25await fs.writeFile(26outlinePath,27`## Illustration 128**Position**: demo29**Purpose**: demo30**Visual Content**: demo31**Filename**: 01-demo.png32`,33);34await fs.writeFile(path.join(promptsDir, "01-demo.md"), "A demo prompt\n");3536return { root, outlinePath, promptsDir, outputPath };37}3839async function runBuildBatch(args: string[]): Promise<void> {40await execFileAsync(process.execPath, ["--import", "tsx", scriptPath, ...args], {41cwd: repoRoot,42});43}4445test("build-batch omits default model so baoyu-image-gen can resolve env or EXTEND defaults", async () => {46const fixture = await makeFixture();4748await runBuildBatch([49"--outline",50fixture.outlinePath,51"--prompts",52fixture.promptsDir,53"--output",54fixture.outputPath,55]);5657const batch = JSON.parse(await fs.readFile(fixture.outputPath, "utf8")) as {58tasks: Array<Record<string, unknown>>;59};6061assert.equal(batch.tasks.length, 1);62assert.equal(batch.tasks[0]?.provider, "replicate");63assert.equal(Object.hasOwn(batch.tasks[0]!, "model"), false);64});6566test("build-batch preserves explicit model overrides", async () => {67const fixture = await makeFixture();6869await runBuildBatch([70"--outline",71fixture.outlinePath,72"--prompts",73fixture.promptsDir,74"--output",75fixture.outputPath,76"--model",77"acme/custom-model",78]);7980const batch = JSON.parse(await fs.readFile(fixture.outputPath, "utf8")) as {81tasks: Array<Record<string, unknown>>;82};8384assert.equal(batch.tasks[0]?.model, "acme/custom-model");85});8687test("build-batch propagates direct-usage references from prompt frontmatter", async () => {88const fixture = await makeFixture();8990await fs.writeFile(91path.join(fixture.promptsDir, "01-demo.md"),92`---93illustration_id: 0194type: infographic95references:96- ref_id: 0197filename: 01-ref-brand.png98usage: direct99- ref_id: 02100filename: 02-ref-style.png101usage: style102---103104A demo prompt105`,106);107108await runBuildBatch([109"--outline",110fixture.outlinePath,111"--prompts",112fixture.promptsDir,113"--output",114fixture.outputPath,115]);116117const batch = JSON.parse(await fs.readFile(fixture.outputPath, "utf8")) as {118tasks: Array<Record<string, unknown>>;119};120121assert.deepEqual(batch.tasks[0]?.ref, ["references/01-ref-brand.png"]);122});123124test("build-batch omits ref field when no direct references exist", async () => {125const fixture = await makeFixture();126127await fs.writeFile(128path.join(fixture.promptsDir, "01-demo.md"),129`---130illustration_id: 01131references:132- ref_id: 01133filename: 01-ref-palette.png134usage: palette135---136137A demo prompt138`,139);140141await runBuildBatch([142"--outline",143fixture.outlinePath,144"--prompts",145fixture.promptsDir,146"--output",147fixture.outputPath,148]);149150const batch = JSON.parse(await fs.readFile(fixture.outputPath, "utf8")) as {151tasks: Array<Record<string, unknown>>;152};153154assert.equal(Object.hasOwn(batch.tasks[0]!, "ref"), false);155});156157test("build-batch honors --refs-dir override", async () => {158const fixture = await makeFixture();159160await fs.writeFile(161path.join(fixture.promptsDir, "01-demo.md"),162`---163illustration_id: 01164references:165- ref_id: 01166filename: brand.png167usage: direct168---169170A demo prompt171`,172);173174await runBuildBatch([175"--outline",176fixture.outlinePath,177"--prompts",178fixture.promptsDir,179"--output",180fixture.outputPath,181"--refs-dir",182"refs",183]);184185const batch = JSON.parse(await fs.readFile(fixture.outputPath, "utf8")) as {186tasks: Array<Record<string, unknown>>;187};188189assert.deepEqual(batch.tasks[0]?.ref, ["refs/brand.png"]);190});191