fix(mac): guard onboarding workspace bootstrap

This commit is contained in:
Peter Steinberger
2025-12-21 01:31:31 +00:00
parent 4e1fe88195
commit 00cdcd4d28
4 changed files with 82 additions and 7 deletions

View File

@@ -48,4 +48,40 @@ struct AgentWorkspaceTests {
let second = try AgentWorkspace.bootstrap(workspaceURL: tmp)
#expect(second == agentsURL)
}
@Test
func bootstrapSafetyRejectsNonEmptyFolderWithoutAgents() throws {
let tmp = FileManager.default.temporaryDirectory
.appendingPathComponent("clawdis-ws-\(UUID().uuidString)", isDirectory: true)
defer { try? FileManager.default.removeItem(at: tmp) }
try FileManager.default.createDirectory(at: tmp, withIntermediateDirectories: true)
let marker = tmp.appendingPathComponent("notes.txt")
try "hello".write(to: marker, atomically: true, encoding: .utf8)
let result = AgentWorkspace.bootstrapSafety(for: tmp)
switch result {
case .unsafe:
break
case .safe:
#expect(false, "Expected unsafe bootstrap safety result.")
}
}
@Test
func bootstrapSafetyAllowsExistingAgentsFile() throws {
let tmp = FileManager.default.temporaryDirectory
.appendingPathComponent("clawdis-ws-\(UUID().uuidString)", isDirectory: true)
defer { try? FileManager.default.removeItem(at: tmp) }
try FileManager.default.createDirectory(at: tmp, withIntermediateDirectories: true)
let agents = tmp.appendingPathComponent(AgentWorkspace.agentsFilename)
try "# AGENTS.md".write(to: agents, atomically: true, encoding: .utf8)
let result = AgentWorkspace.bootstrapSafety(for: tmp)
switch result {
case .safe:
break
case .unsafe:
#expect(false, "Expected safe bootstrap safety result.")
}
}
}