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

Method validateBeforePersist

src/node/runtime/CoderSSHRuntime.ts:524–554  ·  view source on GitHub ↗

* Validate before persisting workspace metadata. * Checks if a Coder workspace with this name already exists.

(
    _finalBranchName: string,
    config: RuntimeConfig
  )

Source from the content-addressed store, hash-verified

522 * Checks if a Coder workspace with this name already exists.
523 */
524 async validateBeforePersist(
525 _finalBranchName: string,
526 config: RuntimeConfig
527 ): Promise<Result<void, string>> {
528 if (!isSSHRuntime(config) || !config.coder) {
529 return Ok(undefined);
530 }
531
532 // Skip for "existing" mode - user explicitly selected an existing workspace
533 if (config.coder.existingWorkspace) {
534 return Ok(undefined);
535 }
536
537 const workspaceName = config.coder.workspaceName;
538 if (!workspaceName) {
539 return Ok(undefined);
540 }
541
542 const exists = await this.coderService.workspaceExists(workspaceName);
543
544 if (exists) {
545 await this.coderService.disposeProvisioningSession(workspaceName);
546 return Err(
547 `A Coder workspace named "${workspaceName}" already exists. ` +
548 `Either switch to "Existing" mode to use it, delete/rename it in Coder, ` +
549 `or choose a different mux workspace name.`
550 );
551 }
552
553 return Ok(undefined);
554 }
555
556 /**
557 * Create workspace (fast path only - no SSH needed).

Callers

nothing calls this directly

Calls 5

isSSHRuntimeFunction · 0.90
OkFunction · 0.90
ErrFunction · 0.90
workspaceExistsMethod · 0.80

Tested by

no test coverage detected