fix: improve integration test reliability (#13)
- Add custom types config after bd init in daemon tests - Replace fixed sleeps with poll-based waiting in tmux tests - Skip beads integration test for JSONL-only repos Fixes flaky test failures in parallel execution.
This commit is contained in:
committed by
Steve Yegge
parent
775af2973d
commit
c8c765a239
@@ -259,25 +259,36 @@ func writeTownJSON(t *testing.T, path string, data interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
// testTmuxSessionWithStubAgent tests that a tmux session runs the stub agent.
|
||||
func pollForOutput(t *testing.T, sessionName, expected string, timeout time.Duration) (string, bool) {
|
||||
t.Helper()
|
||||
deadline := time.Now().Add(timeout)
|
||||
for time.Now().Before(deadline) {
|
||||
output := captureTmuxPane(t, sessionName, 50)
|
||||
if strings.Contains(output, expected) {
|
||||
return output, true
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
return captureTmuxPane(t, sessionName, 50), false
|
||||
}
|
||||
|
||||
func testTmuxSessionWithStubAgent(t *testing.T, tmpDir, stubAgentPath, rigName string) {
|
||||
t.Helper()
|
||||
|
||||
sessionName := fmt.Sprintf("gt-test-%d", time.Now().UnixNano())
|
||||
sessionName := fmt.Sprintf("gt-test-pid%d-%d", os.Getpid(), time.Now().UnixNano())
|
||||
workDir := tmpDir
|
||||
|
||||
// Cleanup session on exit
|
||||
exec.Command("tmux", "kill-session", "-t", sessionName).Run()
|
||||
|
||||
defer func() {
|
||||
exec.Command("tmux", "kill-session", "-t", sessionName).Run()
|
||||
}()
|
||||
|
||||
// Create tmux session
|
||||
cmd := exec.Command("tmux", "new-session", "-d", "-s", sessionName, "-c", workDir)
|
||||
if err := cmd.Run(); err != nil {
|
||||
t.Fatalf("Failed to create tmux session: %v", err)
|
||||
}
|
||||
|
||||
// Set environment variables
|
||||
envVars := map[string]string{
|
||||
"GT_ROLE": "polecat",
|
||||
"GT_POLECAT": "test-polecat",
|
||||
@@ -291,42 +302,39 @@ func testTmuxSessionWithStubAgent(t *testing.T, tmpDir, stubAgentPath, rigName s
|
||||
}
|
||||
}
|
||||
|
||||
// Send the stub agent command
|
||||
agentCmd := fmt.Sprintf("%s --test-mode --stub", stubAgentPath)
|
||||
cmd = exec.Command("tmux", "send-keys", "-t", sessionName, agentCmd, "Enter")
|
||||
if err := cmd.Run(); err != nil {
|
||||
t.Fatalf("Failed to send keys: %v", err)
|
||||
}
|
||||
|
||||
output, started := waitForTmuxOutputContains(t, sessionName, "STUB_AGENT_STARTED", 12*time.Second)
|
||||
if !started {
|
||||
t.Skipf("stub agent output not detected; tmux capture unreliable. Output:\n%s", output)
|
||||
output, found := pollForOutput(t, sessionName, "STUB_AGENT_STARTED", 12*time.Second)
|
||||
if !found {
|
||||
t.Skipf("stub agent output not detected; tmux capture unreliable. Output:
|
||||
%s", output)
|
||||
}
|
||||
|
||||
// Verify environment variables were visible to agent
|
||||
if !strings.Contains(output, "GT_ROLE: polecat") {
|
||||
t.Logf("Warning: GT_ROLE not visible in agent output (tmux env may not propagate to subshell)")
|
||||
}
|
||||
|
||||
// Send a question and verify response
|
||||
cmd = exec.Command("tmux", "send-keys", "-t", sessionName, "ping", "Enter")
|
||||
if err := cmd.Run(); err != nil {
|
||||
t.Fatalf("Failed to send ping: %v", err)
|
||||
}
|
||||
|
||||
output, pong := waitForTmuxOutputContains(t, sessionName, "STUB_AGENT_ANSWER: pong", 6*time.Second)
|
||||
if !pong {
|
||||
output, found = pollForOutput(t, sessionName, "STUB_AGENT_ANSWER: pong", 6*time.Second)
|
||||
if !found {
|
||||
t.Errorf("Expected 'pong' response, got:\n%s", output)
|
||||
}
|
||||
|
||||
// Send exit command
|
||||
cmd = exec.Command("tmux", "send-keys", "-t", sessionName, "exit", "Enter")
|
||||
if err := cmd.Run(); err != nil {
|
||||
t.Logf("Warning: failed to send exit: %v", err)
|
||||
}
|
||||
|
||||
output, exited := waitForTmuxOutputContains(t, sessionName, "STUB_AGENT_EXITING", 3*time.Second)
|
||||
if !exited {
|
||||
output, found = pollForOutput(t, sessionName, "STUB_AGENT_EXITING", 3*time.Second)
|
||||
if !found {
|
||||
t.Logf("Note: Agent may have exited before capture. Output:\n%s", output)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user