(config, sessionId)
| 532 | } |
| 533 | |
| 534 | async function downloadAndExtractArtifact(config, sessionId) { |
| 535 | const sessionRoot = path.join(config.workRoot, "sessions", sessionId); |
| 536 | await fs.promises.rm(sessionRoot, { force: true, recursive: true }); |
| 537 | await fs.promises.mkdir(sessionRoot, { recursive: true }); |
| 538 | const zipPath = path.join(sessionRoot, "artifact.zip"); |
| 539 | const response = await fetch( |
| 540 | `${config.studioUrl}/api/actions/provider-hosts/sessions/${encodeURIComponent(sessionId)}/artifact`, |
| 541 | { |
| 542 | headers: { |
| 543 | "x-simdeck-host-id": config.hostId, |
| 544 | "x-simdeck-host-token": config.hostToken, |
| 545 | }, |
| 546 | }, |
| 547 | ); |
| 548 | if (!response.ok) { |
| 549 | throw new Error(`Artifact download failed: HTTP ${response.status}`); |
| 550 | } |
| 551 | await fs.promises.writeFile( |
| 552 | zipPath, |
| 553 | Buffer.from(await response.arrayBuffer()), |
| 554 | ); |
| 555 | await execFileAsync("ditto", ["-x", "-k", zipPath, sessionRoot], { |
| 556 | timeout: 120000, |
| 557 | }); |
| 558 | const appPath = await findAppBundle(sessionRoot); |
| 559 | if (!appPath) { |
| 560 | throw new Error("Artifact did not contain an .app bundle."); |
| 561 | } |
| 562 | return appPath; |
| 563 | } |
| 564 | |
| 565 | async function findAppBundle(root) { |
| 566 | const entries = await fs.promises.readdir(root, { withFileTypes: true }); |
no test coverage detected