fix(agent-packages): show local inventory before refresh

This commit is contained in:
mesalogo
2026-10-14 00:53:23 +08:00
parent 3ba1ef305d
commit a63060e097
10 changed files with 85 additions and 20 deletions
+11 -1
View File
@@ -1805,6 +1805,7 @@ describe('registerIpcHandlers SSH hosts', () => {
} as const
const agentPackageManager = {
getAllSnapshot: vi.fn(async () => agentPackageInventory),
getAllInventory: vi.fn(async () => agentPackageInventory),
forPlatform: vi.fn(() => agentPackageManager),
download: vi.fn(
async (
@@ -1944,7 +1945,16 @@ describe('registerIpcHandlers SSH hosts', () => {
).resolves.toEqual(agentPackageInventory)
expect(
agentPackageManager.getAllSnapshot
).toHaveBeenCalledWith({ refresh: true })
).toHaveBeenCalledWith({ refresh: true, localOnly: false })
await expect(
electronMocks.handlers.get(
ipcChannels.sshHostsAgentPackageInventory
)?.(event, { localOnly: true })
).resolves.toEqual(agentPackageInventory)
expect(agentPackageManager.getAllInventory).toHaveBeenCalledWith({
refresh: false,
localOnly: true
})
await expect(
electronMocks.handlers.get(
ipcChannels.sshHostsAgentPackageDownload
+3 -1
View File
@@ -4855,7 +4855,9 @@ export function registerIpcHandlers(
const request =
agentPackageInventoryRequestSchema.parse(input ?? {})
return agentPackageInventorySchema.parse(
await agentPackageManager.getAllSnapshot(request)
request.localOnly
? await agentPackageManager.getAllInventory(request)
: await agentPackageManager.getAllSnapshot(request)
)
}
)
@@ -300,6 +300,17 @@ export class AgentPackageManager {
})
}
async getAllInventory(options: { refresh?: boolean } = {}): Promise<AgentPackageInventory> {
const linux = await this.forPlatform('linux').getInventory(options)
const darwin = this.forPlatform('darwin')
darwin.#catalogState = this.forPlatform('linux').#catalogState
const mac = await darwin.getInventory(options)
return agentPackageInventorySchema.parse({
...linux,
entries: [...linux.entries, ...mac.entries]
})
}
#select(catalog: AgentPackageCatalog, architecture: AgentArchitecture, desktopVersion: string) {
return selectLatestCompatibleEntry(catalog, architecture, desktopVersion, this.#platform)
}