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/providers/jimeng.test.ts
1import assert from "node:assert/strict";2import test, { type TestContext } from "node:test";34import type { CliArgs } from "../types.ts";5import { generateImage } from "./jimeng.ts";67function makeArgs(overrides: Partial<CliArgs> = {}): CliArgs {8return {9prompt: null,10promptFiles: [],11imagePath: null,12provider: null,13model: null,14aspectRatio: null,15size: null,16quality: null,17imageSize: null,18imageApiDialect: null,19referenceImages: [],20n: 1,21batchFile: null,22jobs: null,23json: false,24help: false,25...overrides,26};27}2829function useEnv(30t: TestContext,31values: Record<string, string | null>,32): void {33const previous = new Map<string, string | undefined>();34for (const [key, value] of Object.entries(values)) {35previous.set(key, process.env[key]);36if (value == null) {37delete process.env[key];38} else {39process.env[key] = value;40}41}4243t.after(() => {44for (const [key, value] of previous.entries()) {45if (value == null) {46delete process.env[key];47} else {48process.env[key] = value;49}50}51});52}5354test("Jimeng submit request uses prompt field expected by current API", async (t) => {55useEnv(t, {56JIMENG_ACCESS_KEY_ID: "test-access-key",57JIMENG_SECRET_ACCESS_KEY: "test-secret-key",58JIMENG_BASE_URL: null,59JIMENG_REGION: null,60});6162const originalFetch = globalThis.fetch;63t.after(() => {64globalThis.fetch = originalFetch;65});6667const calls: Array<{68input: string;69init?: RequestInit;70}> = [];7172globalThis.fetch = async (input, init) => {73calls.push({74input: String(input),75init,76});7778if (calls.length === 1) {79return Response.json({80code: 10000,81data: {82task_id: "task-123",83},84});85}8687return Response.json({88code: 10000,89data: {90status: "done",91binary_data_base64: [Buffer.from("jimeng-image").toString("base64")],92},93});94};9596const image = await generateImage(97"A quiet bamboo forest",98"jimeng_t2i_v40",99makeArgs({ quality: "normal" }),100);101102assert.equal(Buffer.from(image).toString("utf8"), "jimeng-image");103assert.equal(calls.length, 2);104assert.equal(105calls[0]?.input,106"https://visual.volcengineapi.com/?Action=CVSync2AsyncSubmitTask&Version=2022-08-31",107);108109const submitBody = JSON.parse(String(calls[0]?.init?.body)) as Record<string, unknown>;110assert.equal(submitBody.req_key, "jimeng_t2i_v40");111assert.equal(submitBody.prompt, "A quiet bamboo forest");112assert.ok(!("prompt_text" in submitBody));113assert.equal(submitBody.width, 1024);114assert.equal(submitBody.height, 1024);115});116