fix(coding): preserve runtime model and failure contracts

This commit is contained in:
brother7 committed 2026-08-23 21:21:02 +08:00
1 parent 52b2467d5d
commit 195979d30f
11 files changed
+427 -112

No files matched your search

+97
View File
@@ -92,4 +92,101 @@ describe('Pi session registry', () => {
session: { piSessionId: 'pi-session-a', sessionKey: 'session-key-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);
const projectStore = createCodingProjectStore(createMemoryCodingProjectStorage(), {
createId: () => 'project-binding-failure',
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 conversations = createCodingConversationStore(projectPath, {
createId: () => 'f47ac10b-58cc-4372-a567-0e02b2c3d480',
now: () => NOW,
});
const created = await conversations.create({
agentId: 'agent-a',
title: 'Conversation A',
model: { accountId: 'account-a', modelId: 'model-a', thinkingLevel: 'medium' },
modelResolution: 'resolved',
});
const registry = new PiSessionRegistry({
projectStore,
createConversationStore: () => conversations,
});
const input = {
conversationId: created.id,
projectId: 'project-binding-failure',
agentId: 'agent-a',
title: created.title,
model: { model: created.model, modelResolution: created.modelResolution },
} as const;
await registry.prepare(input);
vi.spyOn(conversations, 'ensureSessionBinding').mockRejectedValueOnce(new Error('disk full'));
await expect(registry.ensureBinding(input, async () => ({
piSessionId: 'pi-session-a',
sessionKey: 'session-key-a',
}))).rejects.toMatchObject({
publicError: { code: 'CODING_STORAGE_WRITE_FAILED', recoverable: true },
});
});
it('maps model metadata persistence failure to the stable storage error', async () => {
const projectPath = await mkdtemp(path.join(tmpdir(), 'makelore-pi-registry-model-failure-'));
roots.push(projectPath);
const projectStore = createCodingProjectStore(createMemoryCodingProjectStorage(), {
createId: () => 'project-model-failure',
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 conversations = createCodingConversationStore(projectPath, {
createId: () => 'f47ac10b-58cc-4372-a567-0e02b2c3d481',
now: () => NOW,
});
const created = await conversations.create({
agentId: 'agent-a',
title: 'Conversation A',
model: { accountId: 'account-a', modelId: 'model-a', thinkingLevel: 'medium' },
modelResolution: 'resolved',
});
const registry = new PiSessionRegistry({
projectStore,
createConversationStore: () => conversations,
});
await registry.prepare({
conversationId: created.id,
projectId: 'project-model-failure',
agentId: 'agent-a',
title: created.title,
model: { model: created.model, modelResolution: created.modelResolution },
});
vi.spyOn(conversations, 'setModelState').mockRejectedValueOnce(new Error('disk full'));
await expect(registry.setModel(created.id, {
model: { accountId: 'account-b', modelId: 'model-b', thinkingLevel: 'high' },
modelResolution: 'resolved',
})).rejects.toMatchObject({
publicError: { code: 'CODING_STORAGE_WRITE_FAILED', recoverable: true },
});
});
});