fix: preserve image attachments in live and restored conversations
This commit is contained in:
@@ -171,6 +171,49 @@ afterEach(async () => {
|
||||
});
|
||||
|
||||
describe('Pi Conversation runtime', () => {
|
||||
|
||||
it.each(['What is in this picture?', ''])('keeps submitted image references visible before Pi emits its user message (%s)', async (text) => {
|
||||
const projectPath = await mkdtemp(path.join(tmpdir(), 'makelore-image-runtime-'));
|
||||
roots.push(projectPath);
|
||||
const projectStore = createCodingProjectStore(createMemoryCodingProjectStorage(), {
|
||||
createId: () => 'project-image', now: () => NOW,
|
||||
});
|
||||
await createLocalCodingProject({ projectPath, now: NOW }, projectStore);
|
||||
const model = { accountId: 'account-image', modelId: 'deepseek-flash', thinkingLevel: 'off' as const };
|
||||
await createCodingProjectAgent(projectPath, {
|
||||
id: 'agent-image', avatarId: 'avatar-01', roleName: 'Reader', name: 'Reader',
|
||||
model, modelResolution: 'resolved',
|
||||
responsibility: { mission: 'Read images', owns: [], boundaries: [], collaborators: [], principles: [] },
|
||||
}, { now: NOW });
|
||||
const conversation = await createCodingConversationStore(projectPath).create({
|
||||
agentId: 'agent-image', title: 'Image', model, modelResolution: 'resolved',
|
||||
});
|
||||
let worker: RuntimeFakeWorker;
|
||||
const runtime = new PiConversationRuntime({
|
||||
pool: new PiWorkerPool({ openWorker: async ({ generation }) => {
|
||||
worker = new RuntimeFakeWorker('image-worker', generation);
|
||||
return { worker, session: { piSessionId: 'image-session', sessionKey: 'image-key' } };
|
||||
} }),
|
||||
registry: new PiSessionRegistry({ projectStore }),
|
||||
resolveModel: async (candidate) => ({ ...candidate, runtimeProviderId: 'image-provider', input: ['text', 'image'] }),
|
||||
resolveImages: async () => [{ type: 'image', data: 'aW1hZ2U=', mimeType: 'image/png' }],
|
||||
});
|
||||
try {
|
||||
await runtime.prepare({ conversationId: conversation.id, projectId: 'project-image',
|
||||
agentId: 'agent-image', title: 'Image', model: { model, modelResolution: 'resolved' } });
|
||||
await runtime.prompt({ conversationId: conversation.id, clientRequestId: 'image-request',
|
||||
mode: 'prompt', text, attachments: [{ attachmentId: 'image-attachment' }] });
|
||||
expect(worker!.requests.find(command => command.type === 'prompt')).toMatchObject({
|
||||
images: [{ type: 'image', data: 'aW1hZ2U=', mimeType: 'image/png' }],
|
||||
});
|
||||
const snapshot = await runtime.getSnapshot(conversation.id);
|
||||
expect(snapshot.nodes).toContainEqual(expect.objectContaining({
|
||||
role: 'user', blocks: expect.arrayContaining([expect.objectContaining({
|
||||
kind: 'image', attachmentId: 'image-attachment', mime: 'image/png',
|
||||
})]),
|
||||
}));
|
||||
} finally { await runtime.shutdown(); }
|
||||
});
|
||||
it('persists native managed choices and rejects removed effort or unsupported images before prompt', async () => {
|
||||
const projectPath = await mkdtemp(path.join(tmpdir(), 'makelore-managed-runtime-'));
|
||||
roots.push(projectPath);
|
||||
|
||||
Reference in New Issue
Block a user