MCPcopy
hub / github.com/coder/mux / finalizeConfig

Method finalizeConfig

src/node/runtime/CoderSSHRuntime.ts:446–518  ·  view source on GitHub ↗

* Finalize runtime config after collision handling. * Derives Coder workspace name from branch name and computes SSH host.

(
    finalBranchName: string,
    config: RuntimeConfig
  )

Source from the content-addressed store, hash-verified

444 * Derives Coder workspace name from branch name and computes SSH host.
445 */
446 async finalizeConfig(
447 finalBranchName: string,
448 config: RuntimeConfig
449 ): Promise<Result<RuntimeConfig, string>> {
450 if (!isSSHRuntime(config) || !config.coder) {
451 return Ok(config);
452 }
453
454 const coder = config.coder;
455 let workspaceName = coder.workspaceName?.trim() ?? "";
456
457 if (!coder.existingWorkspace) {
458 // New workspace: derive name from mux workspace name if not provided
459 if (!workspaceName) {
460 workspaceName = `mux-${finalBranchName}`;
461 }
462 // Transform to Coder-compatible name (handles underscores, etc.)
463 workspaceName = toCoderCompatibleName(workspaceName);
464
465 // Validate against Coder's regex
466 if (!CODER_NAME_REGEX.test(workspaceName)) {
467 return Err(
468 `Workspace name "${finalBranchName}" cannot be converted to a valid Coder name. ` +
469 `Use only letters, numbers, and hyphens.`
470 );
471 }
472 } else {
473 // Existing workspace: name must be provided (selected from dropdown)
474 if (!workspaceName) {
475 return Err("Coder workspace name is required for existing workspaces");
476 }
477 }
478
479 // Final validation
480 if (!workspaceName) {
481 return Err("Coder workspace name is required");
482 }
483
484 // Verify Coder auth before persisting workspace metadata.
485 // Without this, existing-workspace flows skip all auth checks and can create
486 // unusable entries when the user is logged out or their session has expired.
487 try {
488 await this.coderService.verifyAuthenticatedSession();
489 } catch (error) {
490 const message = getErrorMessage(error);
491 return Err(
492 `Failed to verify Coder authentication. ` +
493 `Make sure you're logged in with the Coder CLI. ` +
494 `(${message})`
495 );
496 }
497
498 // Keep a provisioning session around for new workspaces so we can reuse the same token
499 // when fetching template parameters during postCreateSetup.
500 if (!coder.existingWorkspace) {
501 try {
502 await this.coderService.ensureProvisioningSession(workspaceName);
503 } catch (error) {

Callers

nothing calls this directly

Calls 9

isSSHRuntimeFunction · 0.90
OkFunction · 0.90
ErrFunction · 0.90
getErrorMessageFunction · 0.90
resolveCoderSSHHostFunction · 0.90
toCoderCompatibleNameFunction · 0.85
testMethod · 0.80

Tested by

no test coverage detected