restores Helder in all its glory
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import Foundation
|
||||
import HelderCore
|
||||
import HelderServices
|
||||
import Testing
|
||||
|
||||
@Suite struct ConfigServiceTests {
|
||||
@Test func aFreshProjectGetsTheDefaultsFileAndTheDefaults() async throws {
|
||||
let dir = try TempDirectory()
|
||||
let config = await ConfigService(root: dir.root).resolve()
|
||||
#expect(config == .defaults)
|
||||
let written = try Data(contentsOf: dir.url(".helder/config.default.json"))
|
||||
#expect(try JSONDecoder().decode(HelderConfig.self, from: written) == .defaults)
|
||||
}
|
||||
|
||||
@Test func aSparseConfigMergesOverTheDefaults() async throws {
|
||||
let dir = try TempDirectory()
|
||||
try dir.write(".helder/config.json", #"{"ai":{"command":"claude --model opus"},"editor":{"tabSize":2}}"#)
|
||||
let config = await ConfigService(root: dir.root).resolve()
|
||||
#expect(config.ai.command == "claude --model opus")
|
||||
#expect(config.ai.autoLaunch)
|
||||
#expect(config.editor.tabSize == 2)
|
||||
#expect(!config.editor.autoSave)
|
||||
#expect(config.git.confirmDiscard)
|
||||
}
|
||||
|
||||
@Test func theDefaultsFileIsRewrittenWithTheBuiltInValues() async throws {
|
||||
let dir = try TempDirectory()
|
||||
try dir.write(".helder/config.json", #"{"ai":{"command":"x"}}"#)
|
||||
try dir.write(".helder/config.default.json", #"{"ai":{"command":"stale"}}"#)
|
||||
_ = await ConfigService(root: dir.root).resolve()
|
||||
let written = try JSONDecoder().decode(HelderConfig.self, from: Data(contentsOf: dir.url(".helder/config.default.json")))
|
||||
#expect(written.ai.command == "claude")
|
||||
}
|
||||
|
||||
@Test func currentReturnsTheLastResolvedConfig() async throws {
|
||||
let dir = try TempDirectory()
|
||||
let service = ConfigService(root: dir.root)
|
||||
#expect(await service.current() == .defaults)
|
||||
try dir.write(".helder/config.json", #"{"editor":{"tabSize":8}}"#)
|
||||
await service.resolve()
|
||||
#expect(await service.current().editor.tabSize == 8)
|
||||
}
|
||||
|
||||
@Test func anUnwritableProjectStillYieldsTheDefaults() async throws {
|
||||
let dir = try TempDirectory()
|
||||
try dir.write(".helder", "a file where the folder should be")
|
||||
#expect(await ConfigService(root: dir.root).resolve() == .defaults)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import Foundation
|
||||
import HelderCore
|
||||
import HelderServices
|
||||
import Testing
|
||||
|
||||
@Suite struct ProjectServicesTests {
|
||||
private func tempDir() throws -> URL {
|
||||
let url = FileManager.default.temporaryDirectory.appendingPathComponent("helder-test-\(UUID().uuidString)")
|
||||
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
|
||||
return url
|
||||
}
|
||||
|
||||
@Test func configServiceWritesDefaultsAndReadsOverrides() async throws {
|
||||
let root = try tempDir()
|
||||
defer { try? FileManager.default.removeItem(at: root) }
|
||||
let folder = root.appendingPathComponent(".helder")
|
||||
try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)
|
||||
try Data(#"{"editor":{"tabSize":2}}"#.utf8).write(to: folder.appendingPathComponent("config.json"))
|
||||
|
||||
let config = await ConfigService(root: root).resolve()
|
||||
#expect(config.editor.tabSize == 2)
|
||||
#expect(FileManager.default.fileExists(atPath: folder.appendingPathComponent("config.default.json").path))
|
||||
#expect(try String(contentsOf: folder.appendingPathComponent(".gitignore"), encoding: .utf8) == HelderConfig.gitignoreBody)
|
||||
}
|
||||
|
||||
@Test func notesRoundTrip() async throws {
|
||||
let root = try tempDir()
|
||||
defer { try? FileManager.default.removeItem(at: root) }
|
||||
let notes = NotesService(root: root)
|
||||
#expect(await notes.read() == "")
|
||||
try await notes.write("tell the agent\n")
|
||||
#expect(await notes.read() == "tell the agent\n")
|
||||
}
|
||||
|
||||
@Test func recentProjectsAreNewestFirstAndDeduplicated() async throws {
|
||||
let dir = try tempDir()
|
||||
defer { try? FileManager.default.removeItem(at: dir) }
|
||||
let a = try tempDir(), b = try tempDir()
|
||||
defer { try? FileManager.default.removeItem(at: a); try? FileManager.default.removeItem(at: b) }
|
||||
let store = RecentProjectsStore(fileURL: dir.appendingPathComponent("recent.json"))
|
||||
await store.add(a.path)
|
||||
await store.add(b.path)
|
||||
await store.add(a.path)
|
||||
#expect(await store.list().map(\.path) == [a.standardizedFileURL.path, b.standardizedFileURL.path])
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user