@@ -3792,6 +3792,7 @@ func TestDevcontainerDiscovery(t *testing.T) {
3792
3792
agentcontainers .WithContainerCLI (& fakeContainerCLI {}),
3793
3793
agentcontainers .WithDevcontainerCLI (mDCCLI ),
3794
3794
agentcontainers .WithProjectDiscovery (true ),
3795
+ agentcontainers .WithDiscoveryAutostart (true ),
3795
3796
)
3796
3797
api .Start ()
3797
3798
defer api .Close ()
@@ -3813,5 +3814,74 @@ func TestDevcontainerDiscovery(t *testing.T) {
3813
3814
// Then: We expect the mock infra to not fail.
3814
3815
})
3815
3816
}
3817
+
3818
+ t .Run ("Disabled" , func (t * testing.T ) {
3819
+ t .Parallel ()
3820
+ var (
3821
+ ctx = testutil .Context (t , testutil .WaitShort )
3822
+ logger = testutil .Logger (t )
3823
+ mClock = quartz .NewMock (t )
3824
+ mDCCLI = acmock .NewMockDevcontainerCLI (gomock .NewController (t ))
3825
+
3826
+ fs = map [string ]string {
3827
+ "/home/coder/.git/HEAD" : "" ,
3828
+ "/home/coder/.devcontainer/devcontainer.json" : "" ,
3829
+ }
3830
+
3831
+ r = chi .NewRouter ()
3832
+ )
3833
+
3834
+ // We expect that neither `ReadConfig`, nor `Up` are called as we
3835
+ // have explicitly disabled the agentcontainers API from attempting
3836
+ // to autostart devcontainers that it discovers.
3837
+ mDCCLI .EXPECT ().ReadConfig (gomock .Any (),
3838
+ "/home/coder" ,
3839
+ "/home/coder/.devcontainer/devcontainer.json" ,
3840
+ []string {},
3841
+ ).Return (agentcontainers.DevcontainerConfig {
3842
+ Configuration : agentcontainers.DevcontainerConfiguration {
3843
+ Customizations : agentcontainers.DevcontainerCustomizations {
3844
+ Coder : agentcontainers.CoderCustomization {
3845
+ AutoStart : true ,
3846
+ },
3847
+ },
3848
+ },
3849
+ }, nil ).Times (0 )
3850
+
3851
+ mDCCLI .EXPECT ().Up (gomock .Any (),
3852
+ "/home/coder" ,
3853
+ "/home/coder/.devcontainer/devcontainer.json" ,
3854
+ gomock .Any (),
3855
+ ).Return ("" , nil ).Times (0 )
3856
+
3857
+ api := agentcontainers .NewAPI (logger ,
3858
+ agentcontainers .WithClock (mClock ),
3859
+ agentcontainers .WithWatcher (watcher .NewNoop ()),
3860
+ agentcontainers .WithFileSystem (initFS (t , fs )),
3861
+ agentcontainers .WithManifestInfo ("owner" , "workspace" , "parent-agent" , "/home/coder" ),
3862
+ agentcontainers .WithContainerCLI (& fakeContainerCLI {}),
3863
+ agentcontainers .WithDevcontainerCLI (mDCCLI ),
3864
+ agentcontainers .WithProjectDiscovery (true ),
3865
+ agentcontainers .WithDiscoveryAutostart (false ),
3866
+ )
3867
+ api .Start ()
3868
+ defer api .Close ()
3869
+ r .Mount ("/" , api .Routes ())
3870
+
3871
+ // When: All expected dev containers have been found.
3872
+ require .Eventuallyf (t , func () bool {
3873
+ req := httptest .NewRequest (http .MethodGet , "/" , nil ).WithContext (ctx )
3874
+ rec := httptest .NewRecorder ()
3875
+ r .ServeHTTP (rec , req )
3876
+
3877
+ got := codersdk.WorkspaceAgentListContainersResponse {}
3878
+ err := json .NewDecoder (rec .Body ).Decode (& got )
3879
+ require .NoError (t , err )
3880
+
3881
+ return len (got .Devcontainers ) >= 1
3882
+ }, testutil .WaitShort , testutil .IntervalFast , "dev containers never found" )
3883
+
3884
+ // Then: We expect the mock infra to not fail.
3885
+ })
3816
3886
})
3817
3887
}
0 commit comments