(machineId: string)
| 48 | } |
| 49 | |
| 50 | refreshMachine(machineId: string): Machine | null { |
| 51 | const stored = this.store.machines.getMachine(machineId) |
| 52 | if (!stored) { |
| 53 | const existed = this.machines.delete(machineId) |
| 54 | if (existed) { |
| 55 | this.publisher.emit({ type: 'machine-updated', machineId, data: null }) |
| 56 | } |
| 57 | return null |
| 58 | } |
| 59 | |
| 60 | const existing = this.machines.get(machineId) |
| 61 | |
| 62 | const metadata = (() => { |
| 63 | const parsed = MachineMetadataSchema.safeParse(stored.metadata) |
| 64 | if (!parsed.success) return null |
| 65 | const data = parsed.data |
| 66 | const workspaceRoots = Array.from(new Set( |
| 67 | (data.workspaceRoots ?? []).filter((path) => path.trim().length > 0) |
| 68 | )) |
| 69 | return { |
| 70 | ...data, |
| 71 | workspaceRoots: workspaceRoots.length > 0 ? workspaceRoots : undefined |
| 72 | } |
| 73 | })() |
| 74 | |
| 75 | const runnerState = (() => { |
| 76 | if (stored.runnerState == null) return null |
| 77 | const parsed = RunnerStateSchema.safeParse(stored.runnerState) |
| 78 | return parsed.success ? parsed.data : null |
| 79 | })() |
| 80 | |
| 81 | const storedActiveAt = stored.activeAt ?? stored.createdAt |
| 82 | const existingActiveAt = existing?.activeAt ?? 0 |
| 83 | const useStoredActivity = storedActiveAt > existingActiveAt |
| 84 | |
| 85 | const machine: Machine = { |
| 86 | id: stored.id, |
| 87 | namespace: stored.namespace, |
| 88 | seq: stored.seq, |
| 89 | createdAt: stored.createdAt, |
| 90 | updatedAt: stored.updatedAt, |
| 91 | active: useStoredActivity ? stored.active : (existing?.active ?? stored.active), |
| 92 | activeAt: useStoredActivity ? storedActiveAt : (existingActiveAt || storedActiveAt), |
| 93 | metadata, |
| 94 | metadataVersion: stored.metadataVersion, |
| 95 | runnerState, |
| 96 | runnerStateVersion: stored.runnerStateVersion |
| 97 | } |
| 98 | |
| 99 | this.machines.set(machineId, machine) |
| 100 | this.publisher.emit({ type: 'machine-updated', machineId, data: machine }) |
| 101 | return machine |
| 102 | } |
| 103 | |
| 104 | reloadAll(): void { |
| 105 | const machines = this.store.machines.getMachines() |
no test coverage detected