MCPcopy Index your code
hub / github.com/coder/coder / TestDevcontainerPrebuildSupport

Function TestDevcontainerPrebuildSupport

agent/agentcontainers/api_test.go:5004–5183  ·  view source on GitHub ↗

TestDevcontainerPrebuildSupport validates that devcontainers survive the transition from prebuild to claimed workspace, ensuring the existing container is reused with updated configuration rather than being recreated.

(t *testing.T)

Source from the content-addressed store, hash-verified

5002// from prebuild to claimed workspace, ensuring the existing container is reused
5003// with updated configuration rather than being recreated.
5004func TestDevcontainerPrebuildSupport(t *testing.T) {
5005 t.Parallel()
5006
5007 if runtime.GOOS == "windows" {
5008 t.Skip("Dev Container tests are not supported on Windows")
5009 }
5010
5011 var (
5012 ctx = testutil.Context(t, testutil.WaitShort)
5013 logger = testutil.Logger(t)
5014
5015 fDCCLI = &fakeDevcontainerCLI{readConfigErrC: make(chan func(envs []string) error, 1)}
5016 fCCLI = &fakeContainerCLI{arch: runtime.GOARCH}
5017 fSAC = &fakeSubAgentClient{}
5018
5019 testDC = codersdk.WorkspaceAgentDevcontainer{
5020 ID: uuid.New(),
5021 WorkspaceFolder: "/home/coder/coder",
5022 ConfigPath: "/home/coder/coder/.devcontainer/devcontainer.json",
5023 }
5024
5025 testContainer = newFakeContainer("test-container-id", testDC.ConfigPath, testDC.WorkspaceFolder)
5026
5027 prebuildOwner = "prebuilds"
5028 prebuildWorkspace = "prebuilds-xyz-123"
5029 prebuildAppURL = "prebuilds.zed"
5030
5031 userOwner = "user"
5032 userWorkspace = "user-workspace"
5033 userAppURL = "user.zed"
5034 )
5035
5036 // ==================================================
5037 // PHASE 1: Prebuild workspace creates devcontainer
5038 // ==================================================
5039
5040 // Given: There are no containers initially.
5041 fCCLI.containers = codersdk.WorkspaceAgentListContainersResponse{}
5042
5043 api := agentcontainers.NewAPI(logger,
5044 // We want this first `agentcontainers.API` to have a manifest info
5045 // that is consistent with what a prebuild workspace would have.
5046 agentcontainers.WithManifestInfo(prebuildOwner, prebuildWorkspace, "dev", "/home/coder"),
5047 // Given: We start with a single dev container resource.
5048 agentcontainers.WithDevcontainers(
5049 []codersdk.WorkspaceAgentDevcontainer{testDC},
5050 []codersdk.WorkspaceAgentScript{{ID: testDC.ID, LogSourceID: uuid.New()}},
5051 ),
5052 agentcontainers.WithSubAgentClient(fSAC),
5053 agentcontainers.WithContainerCLI(fCCLI),
5054 agentcontainers.WithDevcontainerCLI(fDCCLI),
5055 agentcontainers.WithWatcher(watcher.NewNoop()),
5056 )
5057 api.Start()
5058
5059 fCCLI.mu.Lock()
5060 fCCLI.containers = codersdk.WorkspaceAgentListContainersResponse{
5061 Containers: []codersdk.WorkspaceAgentContainer{testContainer},

Callers

nothing calls this directly

Calls 15

StartMethod · 0.95
CreateDevcontainerMethod · 0.95
CloseMethod · 0.95
ContextFunction · 0.92
LoggerFunction · 0.92
NewAPIFunction · 0.92
WithManifestInfoFunction · 0.92
WithDevcontainersFunction · 0.92
WithSubAgentClientFunction · 0.92
WithContainerCLIFunction · 0.92
WithDevcontainerCLIFunction · 0.92
WithWatcherFunction · 0.92

Tested by

no test coverage detected