2 Commits
Author SHA1 Message Date
hi-neasonandClaude 73ea597230 test(core): cover DirHistory move-to-front, trim, persistence, bounds (#1663)
DirHistory's exported methods (Add, List, Get, Previous, Contains,
SetMaxSize) had no direct tests; engine tests only used NewDirHistory
as setup. The methods carry non-trivial logic — move-to-front dedup,
maxSize trimming, 1-based Get with bounds check, Previous at index 2,
defensive-copy List, JSON persistence across instances — so a
regression in any of them would have gone unnoticed.

Add table-driven tests covering each behavior plus the corrupt-file
load path.

Co-authored-by: Claude <noreply@anthropic.com>
2026-09-27 18:00:27 +08:00
hi-neasonandClaude 44d2808264 fix(core): lock CommandRegistry.agentDirs in SetAgentDirs and Resolve (#1662)
SetAgentDirs wrote r.agentDirs with no lock held, while Resolve read the
same field after releasing r.mu.RUnlock(), even though ListAll accessed
it under RLock. Today the write happens at engine construction and does
not overlap with Resolve, but the inconsistent locking meant any future
runtime re-bind raced on the slice header under -race.

- Take r.mu.Lock in SetAgentDirs and copy the incoming slice so later
  caller mutations don't leak into the registry.
- Snapshot agentDirs under RLock in Resolve before doing file IO, so
  the lock is not held across disk reads but the slice header is read
  safely.
- Add a -race regression test that concurrently swaps agent dirs while
  other goroutines resolve config and agent commands.

Co-authored-by: Claude <noreply@anthropic.com>
2026-09-27 14:22:21 +08:00