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)
| 5002 | // from prebuild to claimed workspace, ensuring the existing container is reused |
| 5003 | // with updated configuration rather than being recreated. |
| 5004 | func 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}, |
nothing calls this directly
no test coverage detected