@@ -82,10 +82,11 @@ function extractPromptFromArgs(args) {
8282 * RuntimeConnection: typeof import("@github/copilot-sdk").RuntimeConnection,
8383 * approveAll: typeof import("@github/copilot-sdk").approveAll
8484 * },
85+ * sessionStateBaseDir?: string,
8586 * }} options
8687 * @returns {Promise<{exitCode: number, output: string, hasOutput: boolean, durationMs: number}> }
8788 */
88- async function runWithCopilotSDK ( { sdkUri, prompt, logger, attempt = 0 , model, connectionToken, provider, maxToolDenials, permissionConfig, coreLogger, sdkModule } ) {
89+ async function runWithCopilotSDK ( { sdkUri, prompt, logger, attempt = 0 , model, connectionToken, provider, maxToolDenials, permissionConfig, coreLogger, sdkModule, sessionStateBaseDir } ) {
8990 // Lazy-require to avoid loading the SDK when it is not needed.
9091 // The SDK is large and has side-effects on import (worker threads, etc.).
9192 const { CopilotClient, RuntimeConnection, approveAll } = sdkModule ?? require ( "@github/copilot-sdk" ) ;
@@ -106,7 +107,9 @@ async function runWithCopilotSDK({ sdkUri, prompt, logger, attempt = 0, model, c
106107
107108 // Session state directory — mirrors the target path used by unified_timeline.cjs.
108109 // /tmp/gh-aw/sandbox/agent/logs/copilot-session-state/{sessionId}/events.jsonl
109- const sessionStateBase = path . join ( os . tmpdir ( ) , "gh-aw" , "sandbox" , "agent" , "logs" , "copilot-session-state" ) ;
110+ // GH_AW_SESSION_STATE_BASE_DIR may be set in tests to redirect writes to an isolated directory.
111+ const defaultSessionStateBase = path . join ( os . tmpdir ( ) , "gh-aw" , "sandbox" , "agent" , "logs" , "copilot-session-state" ) ;
112+ const sessionStateBase = sessionStateBaseDir ?? process . env . GH_AW_SESSION_STATE_BASE_DIR ?? defaultSessionStateBase ;
110113
111114 /** @type {ReadonlyArray<NonNullable<import("@github/copilot-sdk").CopilotClientOptions["logLevel"]>> } */
112115 const VALID_LOG_LEVELS = [ "none" , "error" , "warning" , "info" , "debug" , "all" ] ;
0 commit comments