Files
bot/apps/macos/Tests/BotIPCTests/BotOAuthStoreTests.swift
zeekay 08582cc303 Rebrand OpenClaw → Hanzo Bot across entire codebase
Complete rename of all OpenClaw/OPENCLAW/openclaw references to
Hanzo Bot/BOT/bot naming convention:

- Env vars: OPENCLAW_* → BOT_* (18 patterns)
- Config: ~/.openclaw/ → ~/.bot/, openclaw.json → bot.json
- Packages: @openclaw/* → @hanzo/bot-*
- Domains: openclaw.ai → hanzo.bot
- Mobile: OpenClawKit → BotKit, bundle IDs ai.openclaw → ai.hanzo.bot
- mDNS: _openclaw-gw._tcp → _bot-gw._tcp
- Docker: CMD hanzo-bot.mjs, BOT_PREFER_PNPM, BOT_DOCKER_APT_PACKAGES
- CI: docker-release.yml adds :latest tag on main branch
2026-02-11 11:13:08 -08:00

98 lines
2.9 KiB
Swift

import Foundation
import Testing
@testable import HanzoBot
@Suite
struct BotOAuthStoreTests {
@Test
func returnsMissingWhenFileAbsent() {
let url = FileManager().temporaryDirectory
.appendingPathComponent("hanzo-bot-oauth-\(UUID().uuidString)")
.appendingPathComponent("oauth.json")
#expect(BotOAuthStore.anthropicOAuthStatus(at: url) == .missingFile)
}
@Test
func usesEnvOverrideForBotOAuthDir() throws {
let key = "BOT_OAUTH_DIR"
let previous = ProcessInfo.processInfo.environment[key]
defer {
if let previous {
setenv(key, previous, 1)
} else {
unsetenv(key)
}
}
let dir = FileManager().temporaryDirectory
.appendingPathComponent("hanzo-bot-oauth-\(UUID().uuidString)", isDirectory: true)
setenv(key, dir.path, 1)
#expect(BotOAuthStore.oauthDir().standardizedFileURL == dir.standardizedFileURL)
}
@Test
func acceptsPiFormatTokens() throws {
let url = try self.writeOAuthFile([
"anthropic": [
"type": "oauth",
"refresh": "r1",
"access": "a1",
"expires": 1_234_567_890,
],
])
#expect(BotOAuthStore.anthropicOAuthStatus(at: url).isConnected)
}
@Test
func acceptsTokenKeyVariants() throws {
let url = try self.writeOAuthFile([
"anthropic": [
"type": "oauth",
"refresh_token": "r1",
"access_token": "a1",
],
])
#expect(BotOAuthStore.anthropicOAuthStatus(at: url).isConnected)
}
@Test
func reportsMissingProviderEntry() throws {
let url = try self.writeOAuthFile([
"other": [
"type": "oauth",
"refresh": "r1",
"access": "a1",
],
])
#expect(BotOAuthStore.anthropicOAuthStatus(at: url) == .missingProviderEntry)
}
@Test
func reportsMissingTokens() throws {
let url = try self.writeOAuthFile([
"anthropic": [
"type": "oauth",
"refresh": "",
"access": "a1",
],
])
#expect(BotOAuthStore.anthropicOAuthStatus(at: url) == .missingTokens)
}
private func writeOAuthFile(_ json: [String: Any]) throws -> URL {
let dir = FileManager().temporaryDirectory
.appendingPathComponent("hanzo-bot-oauth-\(UUID().uuidString)", isDirectory: true)
try FileManager().createDirectory(at: dir, withIntermediateDirectories: true)
let url = dir.appendingPathComponent("oauth.json")
let data = try JSONSerialization.data(withJSONObject: json, options: [.prettyPrinted, .sortedKeys])
try data.write(to: url, options: [.atomic])
return url
}
}