fix: complete image_make asset delivery

This commit is contained in:
john
2026-07-19 19:09:26 +08:00
parent 9cf12e3786
commit 72ed4dde83
7 changed files with 66 additions and 6 deletions
+45
View File
@@ -80,6 +80,51 @@ test('image_make client fails closed on checksum mismatch', async () => {
);
});
test('image_make client resolves a completed idempotent reuse through status_url', async () => {
const image = Buffer.concat([Buffer.from('RIFF'), Buffer.alloc(4), Buffer.from('WEBPreused')]);
const sha256 = crypto.createHash('sha256').update(image).digest('hex');
const calls = [];
const client = createImageMakeClient({
baseUrl: 'http://127.0.0.1:8080', token: 'test-token', sleep: async () => {},
fetchImpl: async (url) => {
const path = new URL(url).pathname;
calls.push(path);
if (path === '/v1/generation-jobs') {
return Response.json({
job_id: 'job-reused',
status: 'succeeded',
status_url: '/v1/generation-jobs/job-reused',
});
}
if (path === '/v1/generation-jobs/job-reused') {
return Response.json({
job_id: 'job-reused',
status: 'succeeded',
result: {
download_url: '/v1/generation-jobs/job-reused/result',
sha256,
},
});
}
if (path.endsWith('/result')) {
return new Response(image, { headers: { 'content-type': 'image/webp' } });
}
throw new Error(`Unexpected request ${path}`);
},
});
const result = await client.generateImage({
prompt: 'reuse me',
presetId: 'memind_dark_hero',
idempotencyKey: 'imgreq-reused',
});
assert.equal(result.jobId, 'job-reused');
assert.deepEqual(calls, [
'/v1/generation-jobs',
'/v1/generation-jobs/job-reused',
'/v1/generation-jobs/job-reused/result',
]);
});
test('image_make env client stays disabled until URL and token are both configured', () => {
assert.equal(createImageMakeClientFromEnv({}), null);
assert.equal(createImageMakeClientFromEnv({ IMAGE_MAKE_BASE_URL: 'http://127.0.0.1:8080' }), null);