native macOS codings agent orchestrator prowl.onev.cat
Something went wrong. Try again.
6.1 kB · 155 lines
Swift
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156import Foundationimport Testing
@testable import supacode
struct RepositoryNameTests { @Test func usesParentDirectoryNameForBareRepositoryRoots() { let root = URL(fileURLWithPath: "/tmp/work/repo-alpha/.bare")
#expect(Repository.name(for: root) == "repo-alpha") }
@Test func preservesNormalRepositoryName() { let root = URL(fileURLWithPath: "/tmp/work/repo-alpha")
#expect(Repository.name(for: root) == "repo-alpha") }}
struct SupacodePathsTests { @Test func repositoryDirectoryUsesRepoNameForNormalRoots() { let root = URL(fileURLWithPath: "/tmp/work/repo-alpha") let directory = SupacodePaths.repositoryDirectory(for: root)
#expect(directory.lastPathComponent == "repo-alpha") }
@Test func repositoryDirectoryUsesSanitizedPathForBareRoots() { let root = URL(fileURLWithPath: "/tmp/work/repo-alpha/.bare") let directory = SupacodePaths.repositoryDirectory(for: root)
#expect(directory.lastPathComponent == "tmp_work_repo-alpha_.bare") }
@Test func repositoryDirectoryDoesNotCollideForDifferentBareRoots() { let firstRoot = URL(fileURLWithPath: "/tmp/work/repo-alpha/.bare") let secondRoot = URL(fileURLWithPath: "/tmp/work/repo-beta/.bare")
let firstDirectory = SupacodePaths.repositoryDirectory(for: firstRoot) let secondDirectory = SupacodePaths.repositoryDirectory(for: secondRoot)
#expect(firstDirectory != secondDirectory) }
@Test func repositorySettingsURLUsesSupacodeRepoDirectory() { let root = URL(fileURLWithPath: "/tmp/work/repo-alpha") let settingsURL = SupacodePaths.repositorySettingsURL(for: root)
#expect(settingsURL.lastPathComponent == "prowl.json") #expect(settingsURL.deletingLastPathComponent().lastPathComponent == "repo-alpha") #expect(settingsURL.deletingLastPathComponent().deletingLastPathComponent().lastPathComponent == "repo") }
@Test func userRepositorySettingsURLUsesSupacodeRepoDirectory() { let root = URL(fileURLWithPath: "/tmp/work/repo-alpha/.bare") let settingsURL = SupacodePaths.userRepositorySettingsURL(for: root)
#expect(settingsURL.lastPathComponent == "prowl.onevcat.json") #expect(settingsURL.deletingLastPathComponent().lastPathComponent == ".bare") #expect(settingsURL.deletingLastPathComponent().deletingLastPathComponent().lastPathComponent == "repo") }
@Test func worktreeBaseDirectoryDefaultsToLegacyRepositoryDirectory() { let root = URL(fileURLWithPath: "/tmp/work/repo-alpha") let directory = SupacodePaths.worktreeBaseDirectory( for: root, globalDefaultPath: nil, repositoryOverridePath: nil )
#expect(directory == SupacodePaths.repositoryDirectory(for: root)) }
@Test func worktreeBaseDirectoryUsesGlobalParentDirectory() { let root = URL(fileURLWithPath: "/tmp/work/repo-alpha") let directory = SupacodePaths.worktreeBaseDirectory( for: root, globalDefaultPath: "/tmp/worktrees", repositoryOverridePath: nil ) let expectedDirectory = URL(filePath: "/tmp/worktrees/repo-alpha", directoryHint: .isDirectory) .standardizedFileURL
#expect(directory == expectedDirectory) }
@Test func worktreeBaseDirectoryRepositoryOverrideTakesPrecedence() { let root = URL(fileURLWithPath: "/tmp/work/repo-alpha") let directory = SupacodePaths.worktreeBaseDirectory( for: root, globalDefaultPath: "/tmp/worktrees", repositoryOverridePath: "/tmp/repo-alpha-worktrees" ) let expectedDirectory = URL(filePath: "/tmp/repo-alpha-worktrees", directoryHint: .isDirectory) .standardizedFileURL
#expect(directory == expectedDirectory) }
@Test func exampleWorktreePathUsesResolvedBaseDirectory() { let root = URL(fileURLWithPath: "/tmp/work/repo-alpha") let path = SupacodePaths.exampleWorktreePath( for: root, globalDefaultPath: "/tmp/worktrees", repositoryOverridePath: nil ) let expectedPath = URL(filePath: "/tmp/worktrees/repo-alpha/swift-otter", directoryHint: .isDirectory) .standardizedFileURL .path(percentEncoded: false)
#expect(path == expectedPath) }
@Test func repositorySnapshotURLUsesAppSupportCacheDirectory() { let path = SupacodePaths.repositorySnapshotURL.path(percentEncoded: false)
#expect(path.contains("/Library/Application Support/com.onevcat.prowl/cache/")) }
@Test func migrateLegacyCacheMovesSnapshotFilesToCacheDirectory() throws { let tempRoot = URL(fileURLWithPath: NSTemporaryDirectory()) .appending(path: UUID().uuidString, directoryHint: .isDirectory) let legacyDirectory = tempRoot.appending(path: "legacy", directoryHint: .isDirectory) let cacheDirectory = tempRoot.appending(path: "cache", directoryHint: .isDirectory) let repositorySnapshot = legacyDirectory.appending(path: "repository-snapshot.json", directoryHint: .notDirectory) let terminalSnapshot = legacyDirectory.appending( path: "terminal-layout-snapshot.json", directoryHint: .notDirectory )
try FileManager.default.createDirectory(at: legacyDirectory, withIntermediateDirectories: true) try Data("repo".utf8).write(to: repositorySnapshot) try Data("terminal".utf8).write(to: terminalSnapshot)
try SupacodePaths.migrateLegacyCacheFilesIfNeeded( legacyDirectory: legacyDirectory, cacheDirectory: cacheDirectory )
let migratedRepositorySnapshotPath = cacheDirectory .appending(path: "repository-snapshot.json") .path(percentEncoded: false) let migratedTerminalSnapshotPath = cacheDirectory .appending(path: "terminal-layout-snapshot.json") .path(percentEncoded: false) #expect(FileManager.default.fileExists(atPath: migratedRepositorySnapshotPath)) #expect(FileManager.default.fileExists(atPath: migratedTerminalSnapshotPath)) #expect(!FileManager.default.fileExists(atPath: repositorySnapshot.path(percentEncoded: false))) #expect(!FileManager.default.fileExists(atPath: terminalSnapshot.path(percentEncoded: false)))
try? FileManager.default.removeItem(at: tempRoot) }}