From e9d6dec2f4e5bfa125dea67c86163fc93d8ec21d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 15 Jan 2026 06:13:20 +0000 Subject: [PATCH] fix: make log dir overrideable in tests (#909) (thanks @roshanasingh4) --- CHANGELOG.md | 1 + apps/macos/Sources/Clawdbot/LogLocator.swift | 18 +++++++++++++++--- .../ClawdbotIPCTests/LogLocatorTests.swift | 13 ++++++++----- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aafe35a6e..f32a32418 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ ### Fixes - Browser: add tests for snapshot labels/efficient query params and labeled image responses. +- macOS: ensure launchd log directory exists with a test-only override. (#909) — thanks @roshanasingh4. - Telegram: register dock native commands with underscores to avoid `BOT_COMMAND_INVALID` (#929, fixes #901) — thanks @grp06. - Google: downgrade unsigned thinking blocks before send to avoid missing signature errors. - Agents: make user time zone and 24-hour time explicit in the system prompt. (#859) — thanks @CashWilliams. diff --git a/apps/macos/Sources/Clawdbot/LogLocator.swift b/apps/macos/Sources/Clawdbot/LogLocator.swift index 1444223ea..8714f7d0c 100644 --- a/apps/macos/Sources/Clawdbot/LogLocator.swift +++ b/apps/macos/Sources/Clawdbot/LogLocator.swift @@ -1,9 +1,21 @@ import Foundation enum LogLocator { - private static let logDir = URL(fileURLWithPath: "/tmp/clawdbot") - private static let stdoutLog = logDir.appendingPathComponent("clawdbot-stdout.log") - private static let gatewayLog = logDir.appendingPathComponent("clawdbot-gateway.log") + private static var logDir: URL { + if let override = ProcessInfo.processInfo.environment["CLAWDBOT_LOG_DIR"], !override.isEmpty { + return URL(fileURLWithPath: override) + } + + return URL(fileURLWithPath: "/tmp/clawdbot") + } + + private static var stdoutLog: URL { + logDir.appendingPathComponent("clawdbot-stdout.log") + } + + private static var gatewayLog: URL { + logDir.appendingPathComponent("clawdbot-gateway.log") + } private static func ensureLogDirExists() { try? FileManager.default.createDirectory(at: self.logDir, withIntermediateDirectories: true) diff --git a/apps/macos/Tests/ClawdbotIPCTests/LogLocatorTests.swift b/apps/macos/Tests/ClawdbotIPCTests/LogLocatorTests.swift index 61db98c93..bc29f9e2b 100644 --- a/apps/macos/Tests/ClawdbotIPCTests/LogLocatorTests.swift +++ b/apps/macos/Tests/ClawdbotIPCTests/LogLocatorTests.swift @@ -1,21 +1,24 @@ +import Darwin import Foundation import Testing @testable import Clawdbot @Suite struct LogLocatorTests { @Test func launchdGatewayLogPathEnsuresTmpDirExists() throws { - let dirPath = "/tmp/clawdbot" let fm = FileManager.default + let baseDir = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true) + let logDir = baseDir.appendingPathComponent("clawdbot-tests-\(UUID().uuidString)") - // Simulate a clean machine state where /tmp/clawdbot does not exist. - if fm.fileExists(atPath: dirPath) { - try? fm.removeItem(atPath: dirPath) + setenv("CLAWDBOT_LOG_DIR", logDir.path, 1) + defer { + unsetenv("CLAWDBOT_LOG_DIR") + try? fm.removeItem(at: logDir) } _ = LogLocator.launchdGatewayLogPath var isDir: ObjCBool = false - #expect(fm.fileExists(atPath: dirPath, isDirectory: &isDir)) + #expect(fm.fileExists(atPath: logDir.path, isDirectory: &isDir)) #expect(isDir.boolValue == true) } }