Skip to content

Commit 72b9c4a

Browse files
authored
test(e2e): pin direct podman calls to harness socket on macOS (#2909)
The podman_gateway_start e2e test shells out to `podman` directly (unlike every other Podman e2e test, which routes through the gateway). The harness `e2e/with-podman-gateway.sh` clobbers `XDG_CONFIG_HOME` with an empty dir to isolate CLI/SDK gateway metadata. On macOS the podman client resolves its VM connection config from `XDG_CONFIG_HOME`, so a bare `podman ps` falls back to a nonexistent native rootless socket and fails with "unable to connect to Podman socket". On Linux the socket resolves via `XDG_RUNTIME_DIR`, so the test passes there and this is a macOS-only false failure. Target the same API socket the gateway uses by passing `--url unix://$SOCKET` when the harness-exported `OPENSHELL_PODMAN_SOCKET` is set, mirroring the shell's `podman_cmd` helper. When the var is unset (running the test outside the harness), fall back to plain `podman`, so Linux behavior is unchanged. Signed-off-by: Russell Bryant <rbryant@redhat.com>
1 parent 0a1f246 commit 72b9c4a

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

e2e/rust/tests/podman_gateway_start.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,32 @@ const START_FILE: &str = "/sandbox/podman-gateway-start-state";
2323
const MANAGED_BY_LABEL_FILTER: &str = "label=openshell.managed=true";
2424
const SANDBOX_NAME_LABEL: &str = "openshell.ai/sandbox-name";
2525

26+
/// Build a `podman` command that targets the same API socket the gateway uses.
27+
///
28+
/// The e2e harness (`e2e/with-podman-gateway.sh`) exports
29+
/// `OPENSHELL_PODMAN_SOCKET` (discovered via `podman machine inspect` on macOS,
30+
/// or the rootless socket on Linux) and also clobbers `XDG_CONFIG_HOME` with an
31+
/// empty directory to isolate CLI/SDK gateway metadata. On macOS the podman
32+
/// client resolves its VM connection through `XDG_CONFIG_HOME`, so a bare
33+
/// `podman ps` here falls back to a nonexistent native rootless socket and
34+
/// fails. Pinning `--url` to the exported socket bypasses connection-config
35+
/// resolution entirely and mirrors the shell's `podman_cmd` helper.
36+
///
37+
/// When `OPENSHELL_PODMAN_SOCKET` is unset (e.g. running this test outside the
38+
/// harness), fall back to plain `podman`, leaving Linux behavior unchanged.
39+
fn podman_command() -> Command {
40+
let mut command = Command::new("podman");
41+
if let Ok(socket) = std::env::var("OPENSHELL_PODMAN_SOCKET") {
42+
if !socket.is_empty() {
43+
command.arg("--url").arg(format!("unix://{socket}"));
44+
}
45+
}
46+
command
47+
}
48+
2649
fn sandbox_container_running(sandbox_name: &str) -> Result<bool, String> {
2750
let sandbox_name_filter = format!("label={SANDBOX_NAME_LABEL}={sandbox_name}");
28-
let output = Command::new("podman")
51+
let output = podman_command()
2952
.args(["ps", "-aq", "--filter", MANAGED_BY_LABEL_FILTER, "--filter"])
3053
.arg(sandbox_name_filter)
3154
.stdout(Stdio::piped())
@@ -50,7 +73,7 @@ fn sandbox_container_running(sandbox_name: &str) -> Result<bool, String> {
5073
"expected one Podman container for sandbox '{sandbox_name}', found {ids:?}"
5174
));
5275
};
53-
let output = Command::new("podman")
76+
let output = podman_command()
5477
.args(["inspect", "-f", "{{.State.Running}}", container_id])
5578
.output()
5679
.map_err(|err| format!("failed to run podman inspect: {err}"))?;

0 commit comments

Comments
 (0)