@@ -15,6 +15,13 @@ trap cleanup EXIT
1515
1616pass () { echo " PASS: $* " ; }
1717fail () { 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
1926mkdir -p " $REAL_HOME /.csswitch"
2027printf ' %s\n' ' real-config-sentinel' > " $REAL_HOME /.csswitch/config.json"
@@ -60,7 +67,7 @@ case "$PROXY_PORT:$SANDBOX_PORT" in
6067 ;;
6168esac
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"
6572else
6673 fail " persisted port state is not mode 0600"
9097 fail " Codex fixture contract mismatch"
9198fi
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"
96103else
97104 fail " Codex fixture permissions are too broad"
@@ -159,14 +166,23 @@ else
159166 pass " preflight rejects runtime use of OAuth callback ports"
160167fi
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"
170186fi
171187
172188FAKE_BIN=" $TMP_ROOT /fake-bin"
0 commit comments