* Post-create setup: provision container OR detect fork and setup credentials. * Runs after mux persists workspace metadata so build logs stream to UI in real-time. * * Handles ALL environment setup: * - Fresh workspace: provisions container (create, sync, checkout, credentials) * - F
(params: WorkspaceInitParams)
| 461 | * After this completes, the container is ready for initWorkspace() to run the hook. |
| 462 | */ |
| 463 | async postCreateSetup(params: WorkspaceInitParams): Promise<void> { |
| 464 | const { |
| 465 | projectPath, |
| 466 | branchName, |
| 467 | trunkBranch, |
| 468 | workspacePath, |
| 469 | initLogger, |
| 470 | abortSignal, |
| 471 | env, |
| 472 | skipInitHook, |
| 473 | } = params; |
| 474 | |
| 475 | if (!this.containerName) { |
| 476 | throw new Error("Container not initialized. Call createWorkspace first."); |
| 477 | } |
| 478 | const containerName = this.containerName; |
| 479 | |
| 480 | // Check if container already exists (e.g., from successful fork or aborted previous attempt) |
| 481 | const containerCheck = await this.checkExistingContainer( |
| 482 | containerName, |
| 483 | workspacePath, |
| 484 | branchName |
| 485 | ); |
| 486 | switch (containerCheck.action) { |
| 487 | case "skip": |
| 488 | // Fork path: container already valid, just log and setup credentials |
| 489 | initLogger.logStep( |
| 490 | skipInitHook |
| 491 | ? "Container already running (from fork), skipping init hook..." |
| 492 | : "Container already running (from fork), running init hook..." |
| 493 | ); |
| 494 | await this.setupCredentials(containerName, env); |
| 495 | return; |
| 496 | case "cleanup": |
| 497 | initLogger.logStep(containerCheck.reason); |
| 498 | await runDockerCommand(`docker rm -f ${containerName}`, 10000); |
| 499 | break; |
| 500 | case "create": |
| 501 | break; |
| 502 | } |
| 503 | |
| 504 | // Provision container (throws on error - caller handles) |
| 505 | await this.provisionContainer({ |
| 506 | containerName, |
| 507 | projectPath, |
| 508 | workspacePath, |
| 509 | branchName, |
| 510 | trunkBranch, |
| 511 | initLogger, |
| 512 | abortSignal, |
| 513 | env, |
| 514 | trusted: params.trusted, |
| 515 | }); |
| 516 | } |
| 517 | |
| 518 | /** |
| 519 | * Initialize workspace by running .mux/init hook. |
nothing calls this directly
no test coverage detected