Skip to content

Commit 14dc669

Browse files
committed
fix(agent/agentcontainers): filter out "is a test" devcontainers
1 parent f6d9765 commit 14dc669

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

agent/agentcontainers/api.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,8 @@ func (api *API) processUpdatedContainersLocked(ctx context.Context, updated code
571571
slog.F("config_file", configFile),
572572
)
573573

574-
if len(api.containerLabelIncludeFilter) > 0 {
574+
// Filter out devcontainer tests, unless explicitly set in include filters.
575+
if len(api.containerLabelIncludeFilter) > 0 || container.Labels[DevcontainerIsTestRunLabel] == "true" {
575576
var ok bool
576577
for label, value := range api.containerLabelIncludeFilter {
577578
if v, found := container.Labels[label]; found && v == value {

agent/agentcontainers/api_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,16 @@ func TestAPI(t *testing.T) {
793793
agentcontainers.DevcontainerConfigFileLabel: "/workspace/runtime1/.devcontainer/devcontainer.json",
794794
},
795795
},
796+
{
797+
ID: "test-container-1",
798+
FriendlyName: "test-container-1",
799+
Running: true,
800+
Labels: map[string]string{
801+
agentcontainers.DevcontainerLocalFolderLabel: "/workspace/test1",
802+
agentcontainers.DevcontainerConfigFileLabel: "/workspace/test1/.devcontainer/devcontainer.json",
803+
agentcontainers.DevcontainerIsTestRunLabel: "true",
804+
},
805+
},
796806
{
797807
ID: "not-a-devcontainer",
798808
FriendlyName: "not-a-devcontainer",
@@ -834,6 +844,16 @@ func TestAPI(t *testing.T) {
834844
agentcontainers.DevcontainerLocalFolderLabel: "/workspace/runtime1",
835845
agentcontainers.DevcontainerConfigFileLabel: "/workspace/runtime1/.devcontainer/devcontainer.json",
836846
},
847+
},
848+
{
849+
ID: "test-container-1",
850+
FriendlyName: "test-container-1",
851+
Running: true,
852+
Labels: map[string]string{
853+
agentcontainers.DevcontainerLocalFolderLabel: "/workspace/test1",
854+
agentcontainers.DevcontainerConfigFileLabel: "/workspace/test1/.devcontainer/devcontainer.json",
855+
agentcontainers.DevcontainerIsTestRunLabel: "true",
856+
},
837857
},
838858
},
839859
},
@@ -880,6 +900,16 @@ func TestAPI(t *testing.T) {
880900
agentcontainers.DevcontainerLocalFolderLabel: "/workspace/non-running",
881901
agentcontainers.DevcontainerConfigFileLabel: "/workspace/non-running/.devcontainer/devcontainer.json",
882902
},
903+
},
904+
{
905+
ID: "test-container-1",
906+
FriendlyName: "test-container-1",
907+
Running: true,
908+
Labels: map[string]string{
909+
agentcontainers.DevcontainerLocalFolderLabel: "/workspace/test1",
910+
agentcontainers.DevcontainerConfigFileLabel: "/workspace/test1/.devcontainer/devcontainer.json",
911+
agentcontainers.DevcontainerIsTestRunLabel: "true",
912+
},
883913
},
884914
},
885915
},
@@ -913,6 +943,16 @@ func TestAPI(t *testing.T) {
913943
agentcontainers.DevcontainerLocalFolderLabel: "/workspace/known2",
914944
agentcontainers.DevcontainerConfigFileLabel: "/workspace/known2/.devcontainer/devcontainer.json",
915945
},
946+
},
947+
{
948+
ID: "test-container-1",
949+
FriendlyName: "test-container-1",
950+
Running: true,
951+
Labels: map[string]string{
952+
agentcontainers.DevcontainerLocalFolderLabel: "/workspace/test1",
953+
agentcontainers.DevcontainerConfigFileLabel: "/workspace/test1/.devcontainer/devcontainer.json",
954+
agentcontainers.DevcontainerIsTestRunLabel: "true",
955+
},
916956
},
917957
},
918958
},
@@ -966,6 +1006,16 @@ func TestAPI(t *testing.T) {
9661006
agentcontainers.DevcontainerLocalFolderLabel: "/var/lib/project3",
9671007
agentcontainers.DevcontainerConfigFileLabel: "/var/lib/project3/.devcontainer/devcontainer.json",
9681008
},
1009+
},
1010+
{
1011+
ID: "test-container-1",
1012+
FriendlyName: "test-container-1",
1013+
Running: true,
1014+
Labels: map[string]string{
1015+
agentcontainers.DevcontainerLocalFolderLabel: "/workspace/test1",
1016+
agentcontainers.DevcontainerConfigFileLabel: "/workspace/test1/.devcontainer/devcontainer.json",
1017+
agentcontainers.DevcontainerIsTestRunLabel: "true",
1018+
},
9691019
},
9701020
},
9711021
},

agent/agentcontainers/devcontainer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ const (
1818
// DevcontainerConfigFileLabel is the label that contains the path to
1919
// the devcontainer.json configuration file.
2020
DevcontainerConfigFileLabel = "devcontainer.config_file"
21+
// DevcontainerIsTestRunLabel is set if the devcontainer is part of a test
22+
// and should be excluded.
23+
DevcontainerIsTestRunLabel = "devcontainer.is_test_run"
2124
// The default workspace folder inside the devcontainer.
2225
DevcontainerDefaultContainerWorkspaceFolder = "/workspaces"
2326
)

0 commit comments

Comments
 (0)