Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/commands/image/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default defineCommand({
};

if (params.image) {
if (params.image.startsWith('http')) {
if (params.image.startsWith('http://') || params.image.startsWith('https://')) {
ref.image_url = params.image;
} else {
ref.image_file = localFileToDataUri(resolve(params.image));
Expand Down
2 changes: 1 addition & 1 deletion src/utils/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function localFileToDataUri(filePath: string, maxBytes?: number): string
}

export function resolveImageInput(input: string, maxBytes?: number): string {
return input.startsWith('http') || input.startsWith('data:') || input.startsWith('mm_file://')
return input.startsWith('http://') || input.startsWith('https://') || input.startsWith('data:') || input.startsWith('mm_file://')
? input
: localFileToDataUri(input, maxBytes);
}
Expand Down
38 changes: 38 additions & 0 deletions test/commands/image/generate.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { describe, it, expect } from 'bun:test';
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { join } from 'node:path';
import { default as generateCommand } from '../../../src/commands/image/generate';

const baseConfig = {
Expand Down Expand Up @@ -91,4 +93,40 @@ describe('image generate command', () => {
expect(parsed.request.seed).toBe(42);
expect(parsed.request.model).toBe('image-01');
});

it.each(['http-image-', 'https-image-'])('encodes a local subject reference under %s', async (prefix) => {
const dir = mkdtempSync(prefix);
const file = join(dir, 'reference.png');
const png = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+a0qQAAAAASUVORK5CYII=', 'base64');
const originalLog = console.log;
let output = '';
console.log = (message: string) => { output += message; };
try {
writeFileSync(file, png);
await generateCommand.execute(
{ ...baseConfig, dryRun: true, output: 'json' },
{ ...baseFlags, dryRun: true, prompt: 'A cat', subjectRef: `type=character,image=${file}` },
);
const reference = JSON.parse(output).request.subject_reference[0];
expect(reference).toEqual({ type: 'character', image_file: `data:image/png;base64,${png.toString('base64')}` });
} finally {
console.log = originalLog;
rmSync(dir, { recursive: true, force: true });
}
});

it.each(['http://example.com/reference.png', 'https://example.com/reference.png'])('preserves remote subject reference %s', async (url) => {
const originalLog = console.log;
let output = '';
console.log = (message: string) => { output += message; };
try {
await generateCommand.execute(
{ ...baseConfig, dryRun: true, output: 'json' },
{ ...baseFlags, dryRun: true, prompt: 'A cat', subjectRef: `type=character,image=${url}` },
);
expect(JSON.parse(output).request.subject_reference).toEqual([{ type: 'character', image_url: url }]);
} finally {
console.log = originalLog;
}
});
});
19 changes: 18 additions & 1 deletion test/commands/video/generate.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'bun:test';
import { mkdtempSync, readFileSync, rmSync } from 'fs';
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
import { default as generateCommand } from '../../../src/commands/video/generate';
Expand Down Expand Up @@ -52,6 +52,23 @@ async function h3DryRun(flags: Partial<GlobalFlags>): Promise<Record<string, unk
}

describe('video generate command', () => {
it('encodes a local first frame whose relative path starts with http', async () => {
const dir = mkdtempSync('http-video-');
const file = join(dir, 'frame.png');
const png = Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+a0qQAAAAASUVORK5CYII=', 'base64');
try {
writeFileSync(file, png);
const body = await h3DryRun({ image: file });
expect(body.content).toContainEqual({
type: 'image_url',
image_url: { url: `data:image/png;base64,${png.toString('base64')}` },
role: 'first_frame',
});
} finally {
rmSync(dir, { recursive: true, force: true });
}
});

it('has correct name', () => {
expect(generateCommand.name).toBe('video generate');
});
Expand Down
Loading