Skip to content

Commit db6157e

Browse files
committed
update comments
1 parent 6b08fd1 commit db6157e

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

agent/agentcontainers/devcontainercli_test.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,14 @@ type testDevcontainerExecer struct {
130130

131131
// CommandContext returns a test binary command that simulates devcontainer responses.
132132
func (e *testDevcontainerExecer) CommandContext(ctx context.Context, name string, args ...string) *exec.Cmd {
133-
// Only handle "devcontainer" commands
133+
// Only handle "devcontainer" commands.
134134
if name != "devcontainer" {
135-
// For non-devcontainer commands, we use a standard execer
135+
// For non-devcontainer commands, use a standard execer.
136136
return agentexec.DefaultExecer.CommandContext(ctx, name, args...)
137137
}
138138

139139
// Create a command that runs the test binary with special flags
140-
// that tell it to simulate a devcontainer command
140+
// that tell it to simulate a devcontainer command.
141141
testArgs := []string{
142142
"-test.run=TestDevcontainerHelperProcess",
143143
"--",
@@ -147,15 +147,15 @@ func (e *testDevcontainerExecer) CommandContext(ctx context.Context, name string
147147

148148
//nolint:gosec // This is a test binary, so we don't need to worry about command injection.
149149
cmd := exec.CommandContext(ctx, e.testExePath, testArgs...)
150-
// Set this environment variable so the child process knows it's the helper
150+
// Set this environment variable so the child process knows it's the helper.
151151
cmd.Env = append(os.Environ(), "TEST_DEVCONTAINER_WANT_HELPER_PROCESS=1")
152152

153153
return cmd
154154
}
155155

156156
// PTYCommandContext returns a PTY command.
157157
func (*testDevcontainerExecer) PTYCommandContext(_ context.Context, name string, args ...string) *pty.Cmd {
158-
// This method shouldn't be called for our devcontainer tests
158+
// This method shouldn't be called for our devcontainer tests.
159159
panic("PTYCommandContext not expected in devcontainer tests")
160160
}
161161

@@ -164,7 +164,7 @@ func (*testDevcontainerExecer) PTYCommandContext(_ context.Context, name string,
164164
//
165165
//nolint:revive,paralleltest // This is a test helper function.
166166
func TestDevcontainerHelperProcess(t *testing.T) {
167-
// If not called by the test as a helper process, run normally
167+
// If not called by the test as a helper process, do nothing.
168168
if os.Getenv("TEST_DEVCONTAINER_WANT_HELPER_PROCESS") != "1" {
169169
return
170170
}
@@ -175,17 +175,15 @@ func TestDevcontainerHelperProcess(t *testing.T) {
175175
os.Exit(2)
176176
}
177177

178-
// Check if it's a devcontainer command
179178
if helperArgs[0] != "devcontainer" {
180179
fmt.Fprintf(os.Stderr, "Unknown command: %s\n", helperArgs[0])
181180
os.Exit(2)
182181
}
183182

184-
// Verify arguments against expected arguments
183+
// Verify arguments against expected arguments and skip
184+
// "devcontainer", it's not included in the input args.
185185
wantArgs := os.Getenv("TEST_DEVCONTAINER_WANT_ARGS")
186-
// Get the actual arguments (skip "devcontainer").
187186
gotArgs := strings.Join(helperArgs[1:], " ")
188-
189187
if gotArgs != wantArgs {
190188
fmt.Fprintf(os.Stderr, "Arguments don't match.\nWant: %q\nGot: %q\n",
191189
wantArgs, gotArgs)
@@ -270,17 +268,17 @@ func TestDockerDevcontainerCLI(t *testing.T) {
270268
})
271269
}
272270

273-
// setupDevcontainerWorkspace creates a minimal devcontainer.json file
274-
// in the workspace directory and returns its path.
271+
// setupDevcontainerWorkspace prepares a test environment with a minimal
272+
// devcontainer.json configuration and returns the path to the config file.
275273
func setupDevcontainerWorkspace(t *testing.T, workspaceFolder string) string {
276274
t.Helper()
277275

278-
// Create .devcontainer directory.
276+
// Create the devcontainer directory structure.
279277
devcontainerDir := filepath.Join(workspaceFolder, ".devcontainer")
280278
err := os.MkdirAll(devcontainerDir, 0o755)
281279
require.NoError(t, err, "create .devcontainer directory")
282280

283-
// Create a minimal devcontainer.json file with a test-specific label.
281+
// Write a minimal configuration with test labels for identification.
284282
configPath := filepath.Join(devcontainerDir, "devcontainer.json")
285283
content := `{
286284
"image": "alpine:latest",
@@ -295,8 +293,8 @@ func setupDevcontainerWorkspace(t *testing.T, workspaceFolder string) string {
295293
return configPath
296294
}
297295

298-
// findDevcontainerByID finds a container by ID and returns it along with a boolean
299-
// indicating whether it was found.
296+
// findDevcontainerByID locates a container by its ID and verifies it has our
297+
// test label. Returns the container and whether it was found.
300298
func findDevcontainerByID(t *testing.T, pool *dockertest.Pool, id string) (*docker.Container, bool) {
301299
t.Helper()
302300

@@ -310,7 +308,8 @@ func findDevcontainerByID(t *testing.T, pool *dockertest.Pool, id string) (*dock
310308
return container, true
311309
}
312310

313-
// removeDevcontainerByID removes the test devcontainer if it exists.
311+
// removeDevcontainerByID safely cleans up a test container by ID, verifying
312+
// it has our test label before removal to prevent accidental deletion.
314313
func removeDevcontainerByID(t *testing.T, pool *dockertest.Pool, id string) {
315314
t.Helper()
316315

0 commit comments

Comments
 (0)