( provision: () => Promise<ProvisionedGuest>, )
| 57 | * desktop-packaged without a display. |
| 58 | */ |
| 59 | export const attachOrProvision = async ( |
| 60 | provision: () => Promise<ProvisionedGuest>, |
| 61 | ): Promise<(() => Promise<void>) | void> => { |
| 62 | let ip = process.env.E2E_DESKTOP_VM_IP; |
| 63 | let teardownVm: (() => Promise<void>) | undefined; |
| 64 | |
| 65 | if (!ip) { |
| 66 | // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: VM/host setup may fail; degrade to a skip |
| 67 | try { |
| 68 | const result = await provision(); |
| 69 | ip = result.ip; |
| 70 | teardownVm = result.teardown; |
| 71 | } catch (error) { |
| 72 | console.warn(`[desktop] provision failed, scenario will skip: ${String(error)}`); |
| 73 | return; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // oxlint-disable-next-line executor/no-try-catch-or-throw -- boundary: forwarding may fail; degrade to a skip |
| 78 | try { |
| 79 | const forward = await guestTunnel(ip, CDP_GUEST_PORT); |
| 80 | process.env.E2E_DESKTOP_CDP_PORT = String(forward.localPort); |
| 81 | process.env.E2E_DESKTOP_VM_IP = ip; |
| 82 | return async () => { |
| 83 | forward.close(); |
| 84 | await teardownVm?.(); |
| 85 | }; |
| 86 | } catch (error) { |
| 87 | console.warn(`[desktop] could not forward CDP from ${ip}: ${String(error)}`); |
| 88 | await teardownVm?.(); |
| 89 | return; |
| 90 | } |
| 91 | }; |
no test coverage detected