native macOS codings agent orchestrator prowl.onev.cat
Something went wrong. Try again.
4.8 kB · 159 lines
Swift
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160import Foundationimport Testing
@testable import supacode
struct CodexShellLaunchEnvironmentTests { @Test func probeUsesLoginShellAndReturnsOnlyValidatedLaunchFacts() async throws { let cwd = URL(filePath: "/tmp/Project Space/界", directoryHint: .isDirectory) let run: @Sendable (URL, String) async throws -> ShellOutput = { currentDirectory, script in #expect(currentDirectory == cwd) #expect(script.contains("command -v -- codex")) return ShellOutput( stdout: """ __PROWL_CODEX_EXECUTABLE__/opt/custom/bin/codex __PROWL_CODEX_HOME_BASE__/Users/tester __PROWL_CODEX_HOME__/tmp/codex-home __PROWL_CODEX_END__
""", stderr: "ignored", exitCode: 0 ) }
let environment = try #require( await CodexShellLaunchEnvironmentProbe.resolve( cwd: cwd, run: run, isExecutable: { $0 == "/opt/custom/bin/codex" } ) )
#expect(environment.executableURL.path(percentEncoded: false) == "/opt/custom/bin/codex") #expect( environment.processEnvironment == [ "HOME": "/Users/tester", "CODEX_HOME": "/tmp/codex-home", ]) }
@Test func loginShellBannerDoesNotHideTheFramedLaunchFacts() async throws { let output = ShellOutput( stdout: """ Welcome from zprofile __PROWL_CODEX_EXECUTABLE__/opt/codex __PROWL_CODEX_HOME_BASE__/Users/tester __PROWL_CODEX_HOME__ __PROWL_CODEX_END__ Login complete """, stderr: "", exitCode: 0 )
let environment = try #require( await CodexShellLaunchEnvironmentProbe.resolve( cwd: URL(filePath: "/tmp", directoryHint: .isDirectory), run: { _, _ in output }, isExecutable: { $0 == "/opt/codex" } ) )
#expect(environment.executableURL.path(percentEncoded: false) == "/opt/codex") #expect(environment.processEnvironment == ["HOME": "/Users/tester"]) }
@Test func multilineMarkerValueDegradesInsteadOfUsingItsFirstLine() async { let output = ShellOutput( stdout: """ Login banner __PROWL_CODEX_EXECUTABLE__/opt/codex __PROWL_CODEX_HOME_BASE__/Users/tester __PROWL_CODEX_HOME__/tmp/first second __PROWL_CODEX_END__ Login complete """, stderr: "", exitCode: 0 )
#expect( await CodexShellLaunchEnvironmentProbe.resolve( cwd: URL(filePath: "/tmp", directoryHint: .isDirectory), run: { _, _ in output }, isExecutable: { $0 == "/opt/codex" } ) == nil ) }
@Test func malformedNonAbsoluteAndFailedProbeDegrade() async { for output in [ ShellOutput(stdout: "not-json", stderr: "", exitCode: 0), ShellOutput( stdout: """ __PROWL_CODEX_EXECUTABLE__codex __PROWL_CODEX_HOME_BASE__/Users/tester __PROWL_CODEX_HOME__
""", stderr: "", exitCode: 0 ), ShellOutput( stdout: """ __PROWL_CODEX_EXECUTABLE__/opt/codex __PROWL_CODEX_HOME_BASE__/Users/tester __PROWL_CODEX_HOME__
""", stderr: "", exitCode: 1 ), ] { #expect( await CodexShellLaunchEnvironmentProbe.resolve( cwd: URL(filePath: "/tmp", directoryHint: .isDirectory), run: { _, _ in output }, isExecutable: { $0 == "/opt/codex" } ) == nil ) } }
@Test func profilePATHOverrideParticipatesInExecutableResolution() async throws { let output = """ __PROWL_CODEX_EXECUTABLE__/custom/bin/codex __PROWL_CODEX_HOME_BASE__/Users/tester __PROWL_CODEX_HOME__ __PROWL_CODEX_END__
""" let result = await CodexShellLaunchEnvironmentProbe.resolve( cwd: URL(filePath: "/tmp", directoryHint: .isDirectory), pathOverride: "/custom/bin:/usr/bin", run: { _, script in #expect(script.contains("PATH='/custom/bin:/usr/bin'; export PATH")) return ShellOutput(stdout: output, stderr: "", exitCode: 0) }, isExecutable: { $0 == "/custom/bin/codex" } )
#expect(result?.executableURL.path(percentEncoded: false) == "/custom/bin/codex") }
@Test func capturedShellHomeDefinesDefaultCodexHome() throws { let shell = CodexShellLaunchEnvironment( executableURL: URL(filePath: "/opt/codex"), processEnvironment: ["HOME": "/Users/shell-home"] ) let context = try CodexLaunchContext.capture( invocation: AgentInvocation(executable: "/opt/codex", arguments: []), inheritedCWD: URL(filePath: "/tmp/project", directoryHint: .isDirectory), environment: shell.processEnvironment )
#expect(context.codexHome.path(percentEncoded: false) == "/Users/shell-home/.codex/") }}