mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-07-21 08:15:23 -04:00
[PR #181] [CLOSED] test: add unit tests for terminal ExecCommand detach behavior #218
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/vxcontrol/pentagi/pull/181
Author: @mason5052
Created: 3/5/2026
Status: ❌ Closed
Base:
master← Head:test/terminal-detached-context📝 Commits (2)
9524cbbtest: add unit tests for terminal ExecCommand detach behavior977d0e0fix: tighten detach timing assertion from 2s to 1s📊 Changes
1 file changed (+174 additions, -0 deletions)
View changed files
📝
backend/pkg/tools/terminal_test.go(+174 -0)📄 Description
Description of the Change
Problem
The terminal
ExecCommandfunction (408 lines) had zero test coverage. The detached execution path -- recently fixed for context isolation (#176, #179) -- particularly needed validation.Solution
Add mock infrastructure and 4 test cases for terminal command execution:
Mock infrastructure:
mockDockerClient: Implements fulldocker.DockerClientinterface with configurable responses, timing delays, and error injection. Usesnet.Pipe()for realistic streaming output simulation.mockTermLogProvider: ImplementsTermLogProviderinterface (no-op for tests).var _ Interface = (*mock)(nil)).Test cases:
TestExecCommandDetachReturnsQuickly: Verifiesdetach=truereturns "Command started in background" within ~500ms even when the command takes 2s+TestExecCommandDetachQuickCompletion: Verifiesdetach=truereturns actual output when command finishes before the quick check timeoutTestExecCommandNonDetachWaitsForCompletion: Verifiesdetach=falseblocks until command completes and returns full outputTestExecCommandContainerNotRunning: Verifies proper error handling when container is not runningThe mock infrastructure is reusable for future terminal.go test expansion (ReadFile, WriteFile, etc.).
Related to #176
Adds test coverage for #179
Type of Change
Areas Affected
Testing and Verification
Test Configuration
Test Steps
go test ./pkg/tools/ -run "TestExecCommand" -v-- all 4 tests passgo vet ./pkg/tools/-- no warningsTestSploitusParseExploitsResponse/nginxfailure is unrelated (Windows Defender file access issue on test data)Security Considerations
No security impact. Test-only change. Mock infrastructure does not interact with real Docker.
Checklist
go fmtandgo vet🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.