fix: close PI core chat review gaps
This commit is contained in:
@@ -5,6 +5,7 @@ import { tmpdir } from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { createCodingConversationStore } from '../../electron/coding-projects/conversation-store';
|
||||
import { CodingProjectService } from '../../electron/coding-projects/project-service';
|
||||
import { createCodingProjectAgent } from '../../electron/coding-projects/project-config';
|
||||
import {
|
||||
createCodingProjectStore,
|
||||
@@ -170,6 +171,74 @@ describe('Pi session registry', () => {
|
||||
]));
|
||||
});
|
||||
|
||||
it('shares one project mutation queue with ProjectService metadata writes', async () => {
|
||||
const projectPath = await mkdtemp(path.join(tmpdir(), 'makelore-pi-shared-conversations-'));
|
||||
roots.push(projectPath);
|
||||
const projectStore = createCodingProjectStore(createMemoryCodingProjectStorage(), {
|
||||
createId: () => 'project-shared',
|
||||
now: () => NOW,
|
||||
});
|
||||
await createLocalCodingProject({ projectPath, now: NOW }, projectStore);
|
||||
await createCodingProjectAgent(projectPath, {
|
||||
id: 'agent-a',
|
||||
avatarId: 'avatar-01',
|
||||
roleName: 'Implementer',
|
||||
name: 'Agent A',
|
||||
model: { accountId: 'account-a', modelId: 'model-a', thinkingLevel: 'medium' },
|
||||
modelResolution: 'resolved',
|
||||
responsibility: { mission: 'Implement', owns: [], boundaries: [], collaborators: [], principles: [] },
|
||||
}, { now: NOW });
|
||||
const conversationIds = [
|
||||
'f47ac10b-58cc-4372-a567-0e02b2c3d484',
|
||||
'f47ac10b-58cc-4372-a567-0e02b2c3d485',
|
||||
];
|
||||
const sharedStore = createCodingConversationStore(projectPath, {
|
||||
createId: () => conversationIds.shift() as string,
|
||||
now: () => NOW,
|
||||
});
|
||||
const left = await sharedStore.create({
|
||||
agentId: 'agent-a',
|
||||
title: 'Left',
|
||||
model: { accountId: 'account-a', modelId: 'model-a', thinkingLevel: 'medium' },
|
||||
modelResolution: 'resolved',
|
||||
});
|
||||
const sharedProvider = vi.fn(() => sharedStore);
|
||||
const projects = new CodingProjectService(projectStore, {
|
||||
createConversationStore: sharedProvider,
|
||||
});
|
||||
const registry = new PiSessionRegistry({
|
||||
projectStore,
|
||||
createConversationStore: sharedProvider,
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
registry.ensureBinding({
|
||||
conversationId: left.id,
|
||||
projectId: 'project-shared',
|
||||
agentId: 'agent-a',
|
||||
title: left.title,
|
||||
model: { model: left.model, modelResolution: left.modelResolution },
|
||||
}, async () => ({ piSessionId: 'pi-left', sessionKey: 'key-left' })),
|
||||
projects.conversationStore(projectPath).create({
|
||||
agentId: 'agent-a',
|
||||
title: 'Right',
|
||||
model: { accountId: 'account-a', modelId: 'model-a', thinkingLevel: 'medium' },
|
||||
modelResolution: 'resolved',
|
||||
}),
|
||||
]);
|
||||
|
||||
const persisted = await sharedStore.read();
|
||||
expect(projects.conversationStore(projectPath)).toBe(sharedStore);
|
||||
expect(persisted.conversations).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: left.id,
|
||||
piSessionId: 'pi-left',
|
||||
sessionKey: 'key-left',
|
||||
}),
|
||||
expect.objectContaining({ title: 'Right', agentId: 'agent-a' }),
|
||||
]));
|
||||
});
|
||||
|
||||
it('maps first session binding persistence failure to the stable storage error', async () => {
|
||||
const projectPath = await mkdtemp(path.join(tmpdir(), 'makelore-pi-registry-binding-failure-'));
|
||||
roots.push(projectPath);
|
||||
|
||||
Reference in New Issue
Block a user