native macOS codings agent orchestrator prowl.onev.cat
Something went wrong. Try again.
Swift
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108import ComposableArchitectureimport Foundationimport IdentifiedCollectionsimport Testing
@testable import Prowl
@MainActorstruct WindowTitleTests { @Test func formatIncludesTabWhenPresent() { #expect(WindowTitle.format(repository: "Prowl", tab: "codex") == "Prowl · codex") }
@Test func formatDropsEmptyTab() { #expect(WindowTitle.format(repository: "Prowl", tab: nil) == "Prowl") #expect(WindowTitle.format(repository: "Prowl", tab: "") == "Prowl") }
@Test func sanitizeRemovesControlCharacters() { #expect(WindowTitle.sanitize("codex\nsecret\u{1B}") == "codexsecret") #expect(WindowTitle.sanitize("\n\t\u{07}") == nil) }
@Test func computeUsesAppTitleWithoutSelection() { let manager = WorktreeTerminalManager(runtime: GhosttyRuntime()) let title = WindowTitle.compute(repositories: RepositoriesFeature.State(), terminalManager: manager) #expect(title == "Prowl") }
@Test func computeUsesViewTitlesForCanvasAndArchive() { let manager = WorktreeTerminalManager(runtime: GhosttyRuntime()) var state = RepositoriesFeature.State()
state.selection = .canvas #expect(WindowTitle.compute(repositories: state, terminalManager: manager) == "Canvas")
state.selection = .archivedWorktrees #expect( WindowTitle.compute(repositories: state, terminalManager: manager) == "Archived Worktrees" ) }
@Test func computeFallsBackToAppNameWhenWorktreeHasNoActiveTab() { let rootURL = URL(fileURLWithPath: "/tmp/repo") let worktree = makeWorktree(rootURL: rootURL) let repository = Repository( id: rootURL.path(percentEncoded: false), rootURL: rootURL, name: "repo", worktrees: IdentifiedArray(uniqueElements: [worktree]) ) var state = RepositoriesFeature.State(repositories: [repository]) state.selection = .worktree(worktree.id)
let terminalState = WorktreeTerminalState(runtime: GhosttyRuntime(), worktree: worktree) let tabId = terminalState.tabManager.createTab(title: "codex", icon: nil) terminalState.tabManager.closeTab(tabId)
#expect( WindowTitle.compute( repositories: state, terminalState: { id in id == worktree.id ? terminalState : nil } ) == "Prowl" )
#expect( WindowTitle.compute( repositories: state, terminalState: { _ in nil } ) == "Prowl" ) }
@Test func computeUsesCustomRepositoryTitleAndSelectedTabTitle() { let rootURL = URL(fileURLWithPath: "/tmp/repo") let worktree = makeWorktree(rootURL: rootURL) let repository = Repository( id: rootURL.path(percentEncoded: false), rootURL: rootURL, name: "repo", worktrees: IdentifiedArray(uniqueElements: [worktree]) ) var state = RepositoriesFeature.State(repositories: [repository]) state.selection = .worktree(worktree.id) state.repositoryCustomTitles[repository.id] = "Prowl"
let terminalState = WorktreeTerminalState(runtime: GhosttyRuntime(), worktree: worktree) _ = terminalState.tabManager.createTab(title: "codex\nhidden", icon: nil)
#expect( WindowTitle.compute( repositories: state, terminalState: { id in id == worktree.id ? terminalState : nil } ) == "Prowl · codexhidden" ) }
private func makeWorktree(rootURL: URL) -> Worktree { Worktree( id: rootURL.appendingPathComponent("main").path(percentEncoded: false), name: "main", detail: "detail", workingDirectory: rootURL.appendingPathComponent("main"), repositoryRootURL: rootURL ) }}