fix: stabilize cross-platform test cleanup
- commit
- 2b658227ff30f594db23f13951b5396ee18269bb
- author
- brice · · 2026-08-05 04:05 UTC
- parent
- d926884
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
3 files · +12 -4
M packages/agent/lsp/client.go +3 -2
| @@ -543,6 +543,7 @@ func (c *Client) Close() error { | |||
| 543 | 543 | _ = c.stdin.Close() | |
| 544 | 544 | c.writeMu.Unlock() | |
| 545 | 545 | killed := false | |
| 546 | + | process := c.cmd.Process | |
| 546 | 547 | exited := make(chan error, 1) | |
| 547 | 548 | go func() { exited <- c.cmd.Wait() }() | |
| 548 | 549 | timer := time.NewTimer(500 * time.Millisecond) | |
| @@ -550,8 +551,8 @@ func (c *Client) Close() error { | |||
| 550 | 551 | case waitErr = <-exited: | |
| 551 | 552 | timer.Stop() | |
| 552 | 553 | case <-timer.C: | |
| 553 | - | if c.cmd.Process != nil && c.cmd.ProcessState == nil { | |
| 554 | - | killed = c.cmd.Process.Kill() == nil | |
| 554 | + | if process != nil { | |
| 555 | + | killed = process.Kill() == nil | |
| 555 | 556 | } | |
| 556 | 557 | waitErr = <-exited | |
| 557 | 558 | } | |
| @@ -543,6 +543,7 @@ func (c *Client) Close() error { | |||||
| 543 | _ = c.stdin.Close() | 543 | _ = c.stdin.Close() | ||
| 544 | c.writeMu.Unlock() | 544 | c.writeMu.Unlock() | ||
| 545 | killed := false | 545 | killed := false | ||
| 546 | + | process := c.cmd.Process | |||
| 546 | exited := make(chan error, 1) | 547 | exited := make(chan error, 1) | ||
| 547 | go func() { exited <- c.cmd.Wait() }() | 548 | go func() { exited <- c.cmd.Wait() }() | ||
| 548 | timer := time.NewTimer(500 * time.Millisecond) | 549 | timer := time.NewTimer(500 * time.Millisecond) | ||
| @@ -550,8 +551,8 @@ func (c *Client) Close() error { | |||||
| 550 | case waitErr = <-exited: | 551 | case waitErr = <-exited: | ||
| 551 | timer.Stop() | 552 | timer.Stop() | ||
| 552 | case <-timer.C: | 553 | case <-timer.C: | ||
| 553 | - | if c.cmd.Process != nil && c.cmd.ProcessState == nil { | 554 | + | if process != nil { |
| 554 | - | killed = c.cmd.Process.Kill() == nil | 555 | + | killed = process.Kill() == nil |
| 555 | } | 556 | } | ||
| 556 | waitErr = <-exited | 557 | waitErr = <-exited | ||
| 557 | } | 558 | } | ||
M packages/agent/subagents/profiles.go +5 -1
| @@ -51,7 +51,11 @@ func Discover(cwd, userHome string) ([]*Profile, []error) { | |||
| 51 | 51 | for _, loc := range searchDirs(cwd, userHome) { | |
| 52 | 52 | entries, err := os.ReadDir(loc.dir) | |
| 53 | 53 | if err != nil { | |
| 54 | - | if !os.IsNotExist(err) { | |
| 54 | + | if os.IsNotExist(err) { | |
| 55 | + | if info, statErr := os.Stat(loc.dir); statErr == nil && !info.IsDir() { | |
| 56 | + | errs = append(errs, fmt.Errorf("read subagent directory %s: not a directory", loc.dir)) | |
| 57 | + | } | |
| 58 | + | } else { | |
| 55 | 59 | errs = append(errs, fmt.Errorf("read subagent directory %s: %w", loc.dir, err)) | |
| 56 | 60 | } | |
| 57 | 61 | continue | |
| @@ -51,7 +51,11 @@ func Discover(cwd, userHome string) ([]*Profile, []error) { | |||||
| 51 | for _, loc := range searchDirs(cwd, userHome) { | 51 | for _, loc := range searchDirs(cwd, userHome) { | ||
| 52 | entries, err := os.ReadDir(loc.dir) | 52 | entries, err := os.ReadDir(loc.dir) | ||
| 53 | if err != nil { | 53 | if err != nil { | ||
| 54 | - | if !os.IsNotExist(err) { | 54 | + | if os.IsNotExist(err) { |
| 55 | + | if info, statErr := os.Stat(loc.dir); statErr == nil && !info.IsDir() { | |||
| 56 | + | errs = append(errs, fmt.Errorf("read subagent directory %s: not a directory", loc.dir)) | |||
| 57 | + | } | |||
| 58 | + | } else { | |||
| 55 | errs = append(errs, fmt.Errorf("read subagent directory %s: %w", loc.dir, err)) | 59 | errs = append(errs, fmt.Errorf("read subagent directory %s: %w", loc.dir, err)) | ||
| 56 | } | 60 | } | ||
| 57 | continue | 61 | continue | ||
M packages/core/session_snapshot_test.go +4 -1
| @@ -508,10 +508,13 @@ func TestSnapshotRemovesOrphanedToolResultsAndMapsCheckpointCount(t *testing.T) | |||
| 508 | 508 | if err != nil { | |
| 509 | 509 | t.Fatal(err) | |
| 510 | 510 | } | |
| 511 | - | _, branchMessages, err := OpenSession(branchPath) | |
| 511 | + | branchSession, branchMessages, err := OpenSession(branchPath) | |
| 512 | 512 | if err != nil { | |
| 513 | 513 | t.Fatal(err) | |
| 514 | 514 | } | |
| 515 | + | if err := branchSession.Close(); err != nil { | |
| 516 | + | t.Fatal(err) | |
| 517 | + | } | |
| 515 | 518 | if len(branchMessages) != 3 { | |
| 516 | 519 | t.Fatalf("branch messages = %d, want 3", len(branchMessages)) | |
| 517 | 520 | } | |
| @@ -508,10 +508,13 @@ func TestSnapshotRemovesOrphanedToolResultsAndMapsCheckpointCount(t *testing.T) | |||||
| 508 | if err != nil { | 508 | if err != nil { | ||
| 509 | t.Fatal(err) | 509 | t.Fatal(err) | ||
| 510 | } | 510 | } | ||
| 511 | - | _, branchMessages, err := OpenSession(branchPath) | 511 | + | branchSession, branchMessages, err := OpenSession(branchPath) |
| 512 | if err != nil { | 512 | if err != nil { | ||
| 513 | t.Fatal(err) | 513 | t.Fatal(err) | ||
| 514 | } | 514 | } | ||
| 515 | + | if err := branchSession.Close(); err != nil { | |||
| 516 | + | t.Fatal(err) | |||
| 517 | + | } | |||
| 515 | if len(branchMessages) != 3 { | 518 | if len(branchMessages) != 3 { | ||
| 516 | t.Fatalf("branch messages = %d, want 3", len(branchMessages)) | 519 | t.Fatalf("branch messages = %d, want 3", len(branchMessages)) | ||
| 517 | } | 520 | } | ||