feat(image): complete reviewed generation delivery
Memind CI / Test, build, and release guards (pull_request) Successful in 2m47s

This commit is contained in:
john
2026-07-20 20:04:44 +08:00
parent fc3d27aae0
commit 4b15610aa8
42 changed files with 1764 additions and 97 deletions
+50
View File
@@ -125,6 +125,56 @@ test('image_make client resolves a completed idempotent reuse through status_url
]);
});
test('image_make client keeps polling while job is validating', async () => {
const image = Buffer.concat([
Buffer.from('RIFF'),
Buffer.alloc(4),
Buffer.from('WEBP'),
Buffer.from('validating'),
]);
const sha256 = crypto.createHash('sha256').update(image).digest('hex');
let polls = 0;
const client = createImageMakeClient({
baseUrl: 'http://127.0.0.1:8080',
token: 'test-token',
sleep: async () => {},
fetchImpl: async (url) => {
const path = new URL(url).pathname;
if (path === '/v1/generation-jobs') {
return Response.json({ job_id: 'job-1', status: 'running' }, { status: 201 });
}
if (path === '/v1/generation-jobs/job-1') {
polls += 1;
if (polls === 1) {
return Response.json({ job_id: 'job-1', status: 'validating' });
}
return Response.json({
job_id: 'job-1',
status: 'succeeded',
result: {
download_url: '/v1/generation-jobs/job-1/result',
sha256,
width: 1664,
height: 928,
},
});
}
if (path.endsWith('/result')) {
return new Response(image, {
headers: { 'content-type': 'image/webp', 'x-artifact-sha256': sha256 },
});
}
throw new Error(`Unexpected request ${path}`);
},
});
const result = await client.generateImage({
prompt: 'hangzhou snow',
presetId: 'memind_dark_hero',
});
assert.equal(result.jobId, 'job-1');
assert.equal(polls, 2);
});
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);