fix(opencode): switch session models without restart

This commit is contained in:
2026-08-20 22:38:18 +08:00
parent 1c6b004436
commit c0163bc507
18 changed files with 718 additions and 92 deletions

View File

@@ -231,6 +231,62 @@ describe('project Agent runtime readiness', () => {
}
});
it('keeps a deleted and recreated same-id Agent pending until generation rollover', async () => {
const projectPath = await mkdtemp(path.join(tmpdir(), 'makelore-agent-recreated-same-id-'));
try {
const initial = await createInitialProjectConfig(projectPath);
const agent = createAgent();
const original = await writeProjectConfig(projectPath, {
...initial,
initialized: true,
agents: [agent],
});
let runtimeGeneration = 1;
const manager = {
getRuntimeGeneration: () => runtimeGeneration,
getRuntimeGenerationProvenance: () => 'fresh' as const,
};
const listAgents = vi.fn(async () => [{ id: agent.id }]);
await expect(preflightProjectAgentRuntime(
manager,
projectPath,
{ listAgents },
agent.id,
)).resolves.toEqual({ ready: true, runtimeGeneration: 1 });
const removed = await writeProjectConfig(projectPath, {
...original,
agents: [],
});
await observeProjectAgentRuntime(manager, projectPath, removed);
const recreated = await writeProjectConfig(projectPath, {
...removed,
agents: [agent],
});
await observeProjectAgentRuntime(manager, projectPath, recreated);
listAgents.mockClear();
await expect(preflightProjectAgentRuntime(
manager,
projectPath,
{ listAgents },
agent.id,
)).resolves.toEqual({ ready: false, runtimeGeneration: 1 });
expect(listAgents).not.toHaveBeenCalled();
runtimeGeneration = 2;
await expect(preflightProjectAgentRuntime(
manager,
projectPath,
{ listAgents },
agent.id,
)).resolves.toEqual({ ready: true, runtimeGeneration: 2 });
} finally {
await rm(projectPath, { recursive: true, force: true });
}
});
it('never treats an attached runtime generation as an authoritative Agent baseline', async () => {
const projectPath = await mkdtemp(path.join(tmpdir(), 'makelore-agent-attached-runtime-'));
try {