Skip to content

Commit 4ae31bb

Browse files
committed
fix(linux): make release gate portable
1 parent 0f83d0b commit 4ae31bb

7 files changed

Lines changed: 36 additions & 17 deletions

File tree

desktop/gateway/src/codex_auth/platform.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(super) const fn supported() -> bool {
77
pub(super) fn browser_open_bin() -> PathBuf {
88
#[cfg(target_os = "linux")]
99
{
10-
return PathBuf::from("/usr/bin/xdg-open");
10+
PathBuf::from("/usr/bin/xdg-open")
1111
}
1212
#[cfg(not(target_os = "linux"))]
1313
{

desktop/src-tauri/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ pub fn run() {
463463
.expect("error while building tauri application");
464464

465465
app.run(|app, event| match event {
466+
#[cfg(target_os = "macos")]
466467
tauri::RunEvent::Reopen { .. } => show_main_window(app),
467468
tauri::RunEvent::ExitRequested { .. } | tauri::RunEvent::Exit => cleanup_for_exit(app),
468469
_ => {}

desktop/src-tauri/src/runtime/legacy_proxy.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,9 @@ where
255255

256256
#[cfg(test)]
257257
mod tests {
258-
use super::{
259-
is_legacy_csswitch_python, parse_lsof_records, parse_ps_record,
260-
stop_legacy_csswitch_python_on_port, LegacyProxyCleanup, ListenerProcess,
261-
};
258+
use super::{is_legacy_csswitch_python, parse_lsof_records, parse_ps_record, ListenerProcess};
259+
#[cfg(target_os = "macos")]
260+
use super::{stop_legacy_csswitch_python_on_port, LegacyProxyCleanup};
262261

263262
fn process(command_name: &str, uid: u32, command: &str) -> ListenerProcess {
264263
ListenerProcess {

desktop/src-tauri/src/runtime/platform.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub(crate) fn configure_runtime_script_command(
113113
pub(crate) fn installed_science_bin(home: &Path) -> PathBuf {
114114
#[cfg(target_os = "linux")]
115115
{
116-
return home.join(".local/bin/claude-science");
116+
home.join(".local/bin/claude-science")
117117
}
118118
#[cfg(not(target_os = "linux"))]
119119
{
@@ -125,7 +125,7 @@ pub(crate) fn installed_science_bin(home: &Path) -> PathBuf {
125125
pub(crate) fn browser_open_bin() -> PathBuf {
126126
#[cfg(target_os = "linux")]
127127
{
128-
return PathBuf::from("/usr/bin/xdg-open");
128+
PathBuf::from("/usr/bin/xdg-open")
129129
}
130130
#[cfg(not(target_os = "linux"))]
131131
{
@@ -136,7 +136,7 @@ pub(crate) fn browser_open_bin() -> PathBuf {
136136
pub(crate) fn lsof_bin() -> PathBuf {
137137
#[cfg(target_os = "linux")]
138138
{
139-
return PathBuf::from("/usr/bin/lsof");
139+
PathBuf::from("/usr/bin/lsof")
140140
}
141141
#[cfg(not(target_os = "linux"))]
142142
{
@@ -147,7 +147,7 @@ pub(crate) fn lsof_bin() -> PathBuf {
147147
pub(crate) fn ps_bin() -> PathBuf {
148148
#[cfg(target_os = "linux")]
149149
{
150-
return PathBuf::from("/usr/bin/ps");
150+
PathBuf::from("/usr/bin/ps")
151151
}
152152
#[cfg(not(target_os = "linux"))]
153153
{
@@ -162,7 +162,7 @@ pub(crate) fn id_bin() -> PathBuf {
162162
pub(crate) fn kill_bin() -> PathBuf {
163163
#[cfg(target_os = "linux")]
164164
{
165-
return PathBuf::from("/usr/bin/kill");
165+
PathBuf::from("/usr/bin/kill")
166166
}
167167
#[cfg(not(target_os = "linux"))]
168168
{

desktop/src-tauri/src/runtime/sandbox_session.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use std::process::{Command, Stdio};
33
use std::time::Duration;
44

55
use serde_json::{json, Value};
6-
use tauri::{Manager, Runtime};
6+
#[cfg(not(target_os = "linux"))]
7+
use tauri::Manager;
8+
use tauri::Runtime;
79

810
use crate::runtime::operation::{
911
self, OperationKind, OperationStage, OperationTrace, POLL_INTERVAL_MS,

test/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""CSSwitch offline and loopback test package."""

test/test_real_machine_guard.sh

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ trap cleanup EXIT
1515

1616
pass() { echo "PASS: $*"; }
1717
fail() { echo "FAIL: $*" >&2; FAILS=$((FAILS + 1)); }
18+
file_mode() {
19+
case "$(uname -s)" in
20+
Darwin) stat -f '%Lp' "$1" ;;
21+
Linux) stat -c '%a' "$1" ;;
22+
*) return 1 ;;
23+
esac
24+
}
1825

1926
mkdir -p "$REAL_HOME/.csswitch"
2027
printf '%s\n' 'real-config-sentinel' >"$REAL_HOME/.csswitch/config.json"
@@ -60,7 +67,7 @@ case "$PROXY_PORT:$SANDBOX_PORT" in
6067
;;
6168
esac
6269

63-
if [ "$(stat -f '%Lp' "$ACCEPTANCE_ROOT/state/runtime-ports.v1")" = 600 ]; then
70+
if [ "$(file_mode "$ACCEPTANCE_ROOT/state/runtime-ports.v1")" = 600 ]; then
6471
pass "persisted port state is mode 0600"
6572
else
6673
fail "persisted port state is not mode 0600"
@@ -90,8 +97,8 @@ else
9097
fail "Codex fixture contract mismatch"
9198
fi
9299

93-
if [ "$(stat -f '%Lp' "$CFG")" = 600 ] && \
94-
[ "$(stat -f '%Lp' "$ACCEPTANCE_ROOT/home/.csswitch-acceptance")" = 700 ]; then
100+
if [ "$(file_mode "$CFG")" = 600 ] && \
101+
[ "$(file_mode "$ACCEPTANCE_ROOT/home/.csswitch-acceptance")" = 700 ]; then
95102
pass "Codex fixture permissions are 0600/0700"
96103
else
97104
fail "Codex fixture permissions are too broad"
@@ -159,14 +166,23 @@ else
159166
pass "preflight rejects runtime use of OAuth callback ports"
160167
fi
161168

162-
if env PATH=/usr/bin:/bin \
169+
NO_LSOF_BIN="$TMP_ROOT/no-lsof-bin"
170+
mkdir -p "$NO_LSOF_BIN"
171+
for tool in awk cat chmod dirname mkdir python3 rm sort uname; do
172+
tool_path="$(command -v "$tool")"
173+
ln -s "$tool_path" "$NO_LSOF_BIN/$tool"
174+
done
175+
NO_LSOF_OUT="$TMP_ROOT/no-lsof.out"
176+
if env PATH="$NO_LSOF_BIN" \
163177
HOME="$REAL_HOME" \
164178
CSSWITCH_REAL_TEST_ROOT="$TMP_ROOT/no-lsof" \
165179
SCIENCE_BIN=/usr/bin/true \
166-
/bin/bash "$GUARD" preflight >/dev/null 2>&1; then
180+
/bin/bash "$GUARD" preflight >"$NO_LSOF_OUT" 2>&1; then
167181
fail "preflight treated missing lsof as an empty listener set"
168-
else
182+
elif grep -q '端口安全检查需要可执行 lsof' "$NO_LSOF_OUT"; then
169183
pass "preflight fails closed when lsof is unavailable"
184+
else
185+
fail "preflight failed before reaching the missing-lsof guard"
170186
fi
171187

172188
FAKE_BIN="$TMP_ROOT/fake-bin"

0 commit comments

Comments
 (0)