native macOS codings agent orchestrator prowl.onev.cat
Something went wrong. Try again.
Swift
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125import Foundationimport IdentifiedCollectionsimport Testing
@testable import Prowl
@MainActorstruct WorktreeCommandsTests { @Test func codeHostWorktreeIDUsesCanvasFocusedWorktreeInCanvasMode() { let rootPath = "/tmp/repo-canvas-command-code-host" let worktree = Self.makeWorktree(id: "\(rootPath)/wt-1", name: "feature/canvas", repoRoot: rootPath) let repository = Self.makeRepository(rootPath: rootPath, name: "Repo", worktrees: [worktree]) var state = RepositoriesFeature.State(repositories: [repository]) state.selection = SidebarSelection.canvas
let result = codeHostWorktreeID( repositories: state, canvasFocusedWorktreeID: worktree.id )
#expect(result == worktree.id) }
@Test func codeHostWorktreeIDRequiresCodeHostSupport() { let repository = Repository( id: "/tmp/plain-folder-code-host", rootURL: URL(fileURLWithPath: "/tmp/plain-folder-code-host"), name: "Folder", kind: .plain, worktrees: [] ) var state = RepositoriesFeature.State(repositories: [repository]) state.selection = SidebarSelection.canvas
let result = codeHostWorktreeID( repositories: state, canvasFocusedWorktreeID: repository.id )
#expect(result == nil) }
@Test func renameBranchCommandTargetUsesCanvasFocusedWorktree() { let rootPath = "/tmp/repo-canvas-command-rename" let worktree = Self.makeWorktree(id: "\(rootPath)/wt-1", name: "feature/canvas", repoRoot: rootPath) let repository = Self.makeRepository(rootPath: rootPath, name: "Repo", worktrees: [worktree]) var repositories = RepositoriesFeature.State(repositories: [repository]) repositories.selection = .canvas let state = AppFeature.State(repositories: repositories)
let result = renameBranchCommandTargetID( appState: state, canvasFocusedWorktreeID: worktree.id )
#expect(result == worktree.id) }
@Test func renameBranchCommandTargetRejectsMultiSelection() { let rootPath = "/tmp/repo-multi-command-rename" let worktreeA = Self.makeWorktree(id: "\(rootPath)/wt-a", name: "a", repoRoot: rootPath) let worktreeB = Self.makeWorktree(id: "\(rootPath)/wt-b", name: "b", repoRoot: rootPath) let repository = Self.makeRepository(rootPath: rootPath, name: "Repo", worktrees: [worktreeA, worktreeB]) var repositories = RepositoriesFeature.State(repositories: [repository]) repositories.selection = .worktree(worktreeA.id) repositories.sidebarSelectedWorktreeIDs = [worktreeA.id, worktreeB.id] let state = AppFeature.State(repositories: repositories)
let result = renameBranchCommandTargetID(appState: state, canvasFocusedWorktreeID: nil)
#expect(result == nil) }
@Test func renameBranchCommandTargetRejectsUnresolvedSelection() { var repositories = RepositoriesFeature.State() repositories.selection = .worktree("/tmp/repo-pending-command-rename/pending") repositories.sidebarSelectedWorktreeIDs = ["/tmp/repo-pending-command-rename/pending"] let state = AppFeature.State(repositories: repositories)
let result = renameBranchCommandTargetID(appState: state, canvasFocusedWorktreeID: nil)
#expect(result == nil) }
@Test func renameBranchCommandTargetRejectsBlockingSheet() { let rootPath = "/tmp/repo-modal-command-rename" let worktree = Self.makeWorktree(id: "\(rootPath)/wt-1", name: "feature/modal", repoRoot: rootPath) let repository = Self.makeRepository(rootPath: rootPath, name: "Repo", worktrees: [worktree]) var repositories = RepositoriesFeature.State(repositories: [repository]) repositories.selection = .worktree(worktree.id) repositories.sidebarSelectedWorktreeIDs = [worktree.id] repositories.deleteWorktreeConfirmation = DeleteWorktreeConfirmation( id: 0, title: "Delete worktree?", message: "Delete the worktree?", targets: [], deleteBranch: false ) let state = AppFeature.State(repositories: repositories)
let result = renameBranchCommandTargetID(appState: state, canvasFocusedWorktreeID: nil)
#expect(result == nil) }
private static func makeWorktree(id: String, name: String, repoRoot: String) -> Worktree { Worktree( id: id, name: name, detail: id, workingDirectory: URL(fileURLWithPath: id), repositoryRootURL: URL(fileURLWithPath: repoRoot) ) }
private static func makeRepository(rootPath: String, name: String, worktrees: [Worktree]) -> Repository { Repository( id: rootPath, rootURL: URL(fileURLWithPath: rootPath), name: name, worktrees: IdentifiedArray(uniqueElements: worktrees) ) }}