|
1 | 1 | import { expect, it } from "vitest"; |
| 2 | +import { createLocalAgents } from "./local"; |
2 | 3 | import { localAgentsFixture } from "./local-testing"; |
3 | 4 | import { createAgentLibrary } from "./library"; |
4 | 5 | import { createAgentChoices, templateAgentChoices } from "./choices"; |
@@ -207,6 +208,76 @@ it("revokes failed local evidence without dropping ready legacy candidates, then |
207 | 208 | library.dispose(); |
208 | 209 | }); |
209 | 210 |
|
| 211 | +it("reads the local list again from Retry and clears its error once a read succeeds", async () => { |
| 212 | + // The error shape Agents reports when `app_agent_list` fails at startup. |
| 213 | + const native = localAgentsFixture([], "error"); |
| 214 | + native.set({ |
| 215 | + status: "error", |
| 216 | + error: "Could not read saved agent identities", |
| 217 | + }); |
| 218 | + const bound = createLocalAgents(); |
| 219 | + bound.bind(native); |
| 220 | + const library = createAgentLibrary(async () => ({ |
| 221 | + definitions: [], |
| 222 | + identities: [], |
| 223 | + })); |
| 224 | + const lifetime = new AbortController(); |
| 225 | + const choices = createAgentChoices({ |
| 226 | + scope, |
| 227 | + library: library.queries, |
| 228 | + native: bound.agents, |
| 229 | + archives: archiveFixture(), |
| 230 | + signal: lifetime.signal, |
| 231 | + }); |
| 232 | + try { |
| 233 | + await library.queries.refresh(); |
| 234 | + expect(choices.snapshot()).toMatchObject({ |
| 235 | + status: "ready", |
| 236 | + error: "Could not read saved agent identities", |
| 237 | + identities: [], |
| 238 | + }); |
| 239 | + expect(choices.snapshot().templates.complete).toBe(false); |
| 240 | + // The read problem is resolved before Retry; only Retry reads again. |
| 241 | + native.onRefresh(() => native.set({ status: "ready", agents: [agent] })); |
| 242 | + await choices.refresh(); |
| 243 | + expect(native.reads()).toBe(1); |
| 244 | + const state = choices.snapshot(); |
| 245 | + expect(state.error).toBeUndefined(); |
| 246 | + expect(state.identities).toEqual([ |
| 247 | + { |
| 248 | + pubkey: agent.pubkey, |
| 249 | + name: agent.name, |
| 250 | + managed: true, |
| 251 | + managedName: agent.name, |
| 252 | + }, |
| 253 | + ]); |
| 254 | + expect(state.templates).toMatchObject({ |
| 255 | + status: "ready", |
| 256 | + complete: true, |
| 257 | + pending: false, |
| 258 | + }); |
| 259 | + expect(state.templates.error).toBeUndefined(); |
| 260 | + // Template refreshes read whichever source they use, and only that one. |
| 261 | + await choices.refresh("templates"); |
| 262 | + expect(native.reads()).toBe(2); |
| 263 | + const unavailable = localAgentsFixture([], "unavailable"); |
| 264 | + const legacyOnly = createAgentChoices({ |
| 265 | + scope, |
| 266 | + library: library.queries, |
| 267 | + native: unavailable, |
| 268 | + archives: archiveFixture(), |
| 269 | + signal: lifetime.signal, |
| 270 | + }); |
| 271 | + await legacyOnly.refresh("templates"); |
| 272 | + expect(unavailable.reads()).toBe(0); |
| 273 | + await legacyOnly.refresh(false); |
| 274 | + expect(unavailable.reads()).toBe(1); |
| 275 | + } finally { |
| 276 | + lifetime.abort(); |
| 277 | + library.dispose(); |
| 278 | + } |
| 279 | +}); |
| 280 | + |
210 | 281 | it("uses legacy roster choices only on hosts without local agents", async () => { |
211 | 282 | const legacy = { pubkey: "bc".repeat(32), name: "Carl" }; |
212 | 283 | const library = createAgentLibrary(async () => ({ |
|
0 commit comments