Files
steipete--codexbar/TestsLinux/ShellCommandSessionLinuxTests.swift
Mike Bannister b2969deeee fix: isolate interactive PATH probes from caller terminal (#2074)
* fix: restore terminal pgrp after PATH lookup

Snapshot the terminal foreground process group before the shell PATH
probe in ShellCommandLocator.runShellCommand and restore it on return,
so `watch` sessions keep TTY foreground ownership and Ctrl+C keeps
working after CLI commands.

Block SIGTTOU on the calling thread across the restoring tcsetpgrp: the
restore runs from a background process group (the probe shell moves the
terminal foreground and the post-completion kill(-pgid) cleanup strands
it), where the default SIGTTOU action would otherwise stop the CLI.

* fix: harden terminal foreground restoration

* fix: preserve newer terminal foreground jobs

* fix: restore redirected terminal ownership

* fix: harden terminal foreground recovery

* fix: recover dead terminal descendant groups

* fix: reject unrelated terminal foreground groups

* fix: isolate interactive PATH probes

* fix: define detached spawn flag on Linux

* fix: support detached probes on Linux

* test: gate detached session proof to Linux

* fix: restore terminal pgrp after PATH lookup

Snapshot the terminal foreground process group before the shell PATH
probe in ShellCommandLocator.runShellCommand and restore it on return,
so `watch` sessions keep TTY foreground ownership and Ctrl+C keeps
working after CLI commands.

Block SIGTTOU on the calling thread across the restoring tcsetpgrp: the
restore runs from a background process group (the probe shell moves the
terminal foreground and the post-completion kill(-pgid) cleanup strands
it), where the default SIGTTOU action would otherwise stop the CLI.

* fix: harden terminal foreground restoration

* fix: preserve newer terminal foreground jobs

* fix: restore redirected terminal ownership

* fix: harden terminal foreground recovery

* fix: recover dead terminal descendant groups

* fix: reject unrelated terminal foreground groups

* fix: isolate interactive PATH probes

* fix: support detached probes on Linux

* test: gate detached session proof to Linux

* fix: define detached spawn flag on Linux

---------

Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-07-11 18:28:26 -07:00

23 lines
751 B
Swift

import Foundation
import Testing
@testable import CodexBarCore
#if os(Linux)
@Suite(.serialized)
struct ShellCommandSessionLinuxTests {
@Test
func `shell probe launches as a detached session leader`() throws {
let output = ShellCommandLocator.test_runShellCommand(
shell: "/bin/sh",
arguments: ["-c", "printf '%s ' \"$$\"; ps -o sid= -p \"$$\""],
timeout: 5)
let text = try #require(output.flatMap { String(data: $0, encoding: .utf8) })
let identifiers = text.split(whereSeparator: \.isWhitespace).compactMap { Int32($0) }
#expect(identifiers.count == 2)
guard identifiers.count == 2 else { return }
#expect(identifiers[0] == identifiers[1])
}
}
#endif