import Foundation import Testing @testable import CodexBar @testable import CodexBarCore private final class DirectoryEntryVisitCounter: @unchecked Sendable { private let lock = NSLock() private var value = 0 func increment() { self.lock.withLock { self.value += 1 } } var count: Int { self.lock.withLock { self.value } } } private actor AdaptiveLocalScanSpy { private(set) var callCount = 0 func scan(includeFileOnlySessions _: Bool) -> [AgentSession] { self.callCount += 1 return [] } } @MainActor struct AdaptiveRefreshPerformanceTests { @Test func `agent aware detection stays within the bounded scan budget`() async throws { let fileManager = FileManager.default let root = fileManager.temporaryDirectory .appendingPathComponent("AdaptiveRefreshPerformanceTests-\(UUID().uuidString)", isDirectory: true) defer { try? fileManager.removeItem(at: root) } let config = SessionScanConfig() #expect(config.maxDirectoryEntryCount == 512) #expect(config.maxDirectoryDepth == 1) #expect(config.adaptiveDirectoryScanBudget == 0.15) let now = Date() let formatter = DateFormatter() formatter.locale = Locale(identifier: "en_US_POSIX") formatter.dateFormat = "yyyy/MM/dd" let codexHome = root.appendingPathComponent("codex-home", isDirectory: true) let sessionDirectory = codexHome .appendingPathComponent("sessions", isDirectory: true) .appendingPathComponent(formatter.string(from: now), isDirectory: true) try fileManager.createDirectory(at: sessionDirectory, withIntermediateDirectories: true) let fixtureURL = try AgentSessionParserTests.fixtureURL("agent-session-rollout", extension: "jsonl") let fixture = try Data(contentsOf: fixtureURL) for index in 0..