@@ -1472,6 +1472,110 @@ final class SocketListenerAcceptPolicyTests: XCTestCase {
14721472 )
14731473 }
14741474
1475+ func testRestorableAgentStartupInputUsesInlineCommandWhenShort( ) {
1476+ let snapshot = SessionRestorableAgentSnapshot (
1477+ kind: . claude,
1478+ sessionId: " claude-session-123 " ,
1479+ workingDirectory: " /tmp/cmux project " ,
1480+ launchCommand: AgentLaunchCommandSnapshot (
1481+ launcher: " claude " ,
1482+ executablePath: " /opt/Claude Code/bin/claude " ,
1483+ arguments: [
1484+ " /opt/Claude Code/bin/claude " ,
1485+ " --model " ,
1486+ " sonnet "
1487+ ] ,
1488+ workingDirectory: " /tmp/cmux project " ,
1489+ environment: nil ,
1490+ capturedAt: 123 ,
1491+ source: " environment "
1492+ )
1493+ )
1494+
1495+ XCTAssertEqual ( snapshot. resumeStartupInput ( ) , snapshot. resumeCommand. map { $0 + " \n " } )
1496+ }
1497+
1498+ func testRestorableAgentStartupInputUsesLauncherScriptWhenCommandExceedsTerminalInputBudget( ) throws {
1499+ let tempDir = FileManager . default. temporaryDirectory
1500+ . appendingPathComponent ( " cmux-agent-resume-test- \( UUID ( ) . uuidString) " , isDirectory: true )
1501+ try FileManager . default. createDirectory ( at: tempDir, withIntermediateDirectories: true )
1502+ defer { try ? FileManager . default. removeItem ( at: tempDir) }
1503+
1504+ let longPath = " /tmp/ " + String( repeating: " nested-path- " , count: 120 )
1505+ let snapshot = SessionRestorableAgentSnapshot (
1506+ kind: . codex,
1507+ sessionId: " 019dad34-d218-7943-b81a-eddac5c87951 " ,
1508+ workingDirectory: " /tmp/repo " ,
1509+ launchCommand: AgentLaunchCommandSnapshot (
1510+ launcher: " codex " ,
1511+ executablePath: " /Users/example/.bun/bin/codex " ,
1512+ arguments: [
1513+ " /Users/example/.bun/bin/codex " ,
1514+ " --model " ,
1515+ " gpt-5.4 " ,
1516+ " --add-dir " ,
1517+ longPath,
1518+ " initial prompt should not replay "
1519+ ] ,
1520+ workingDirectory: " /tmp/repo " ,
1521+ environment: [ " CODEX_HOME " : " /tmp/codex " ] ,
1522+ capturedAt: 123 ,
1523+ source: " environment "
1524+ )
1525+ )
1526+
1527+ let input = try XCTUnwrap ( snapshot. resumeStartupInput ( temporaryDirectory: tempDir) )
1528+ XCTAssertLessThanOrEqual ( input. utf8. count, SessionRestorableAgentSnapshot . maxInlineStartupInputBytes)
1529+ XCTAssertTrue ( input. hasPrefix ( " /bin/zsh ' " ) )
1530+ XCTAssertFalse ( input. contains ( longPath) )
1531+
1532+ let trimmedInput = input. trimmingCharacters ( in: . whitespacesAndNewlines)
1533+ let prefix = " /bin/zsh ' "
1534+ let scriptPath = String ( trimmedInput. dropFirst ( prefix. count) . dropLast ( ) )
1535+ let scriptContents = try String ( contentsOfFile: scriptPath, encoding: . utf8)
1536+ XCTAssertTrue ( scriptContents. contains ( longPath) )
1537+ XCTAssertTrue ( scriptContents. contains ( " 'resume' " ) )
1538+ XCTAssertTrue ( scriptContents. contains ( " '019dad34-d218-7943-b81a-eddac5c87951' " ) )
1539+
1540+ let attributes = try FileManager . default. attributesOfItem ( atPath: scriptPath)
1541+ let permissions = try XCTUnwrap ( attributes [ . posixPermissions] as? NSNumber ) . intValue & 0o777
1542+ XCTAssertEqual ( permissions, 0o600 )
1543+ }
1544+
1545+ func testRestorableAgentStartupInputSkipsOversizedCommandWhenScriptCannotBeWritten( ) throws {
1546+ let tempDir = FileManager . default. temporaryDirectory
1547+ . appendingPathComponent ( " cmux-agent-resume-test- \( UUID ( ) . uuidString) " , isDirectory: true )
1548+ try FileManager . default. createDirectory ( at: tempDir, withIntermediateDirectories: true )
1549+ defer { try ? FileManager . default. removeItem ( at: tempDir) }
1550+
1551+ let blockedDirectory = tempDir. appendingPathComponent ( " not-a-directory " , isDirectory: false )
1552+ try " occupied " . write ( to: blockedDirectory, atomically: true , encoding: . utf8)
1553+ let longPath = " /tmp/ " + String( repeating: " nested-path- " , count: 120 )
1554+ let snapshot = SessionRestorableAgentSnapshot (
1555+ kind: . codex,
1556+ sessionId: " 019dad34-d218-7943-b81a-eddac5c87951 " ,
1557+ workingDirectory: " /tmp/repo " ,
1558+ launchCommand: AgentLaunchCommandSnapshot (
1559+ launcher: " codex " ,
1560+ executablePath: " /Users/example/.bun/bin/codex " ,
1561+ arguments: [
1562+ " /Users/example/.bun/bin/codex " ,
1563+ " --model " ,
1564+ " gpt-5.4 " ,
1565+ " --add-dir " ,
1566+ longPath,
1567+ " initial prompt should not replay "
1568+ ] ,
1569+ workingDirectory: " /tmp/repo " ,
1570+ environment: [ " CODEX_HOME " : " /tmp/codex " ] ,
1571+ capturedAt: 123 ,
1572+ source: " environment "
1573+ )
1574+ )
1575+
1576+ XCTAssertNil ( snapshot. resumeStartupInput ( temporaryDirectory: blockedDirectory) )
1577+ }
1578+
14751579 func testClaudeResumeCommandPreservesDangerouslySkipPermissionsAndObservedEnvironment( ) {
14761580 let snapshot = SessionRestorableAgentSnapshot (
14771581 kind: . claude,
0 commit comments