| index 0b9118a..a85531d 100755 |
| index 2e5f5aa..ed90d6b 100644 | ||
| --- a/src/plugin_codex_login.c | ||
| +++ b/src/plugin_codex_login.c | ||
| @@ -837,8 +837,11 @@ static void shell_quote_into(const char *in, char *out, size_t outsz) | ||
| 837 | 837 | * -1 when the binary is not on this node ("command not found"). |
| 838 | 838 | * |
| 839 | 839 | * pclose() hands back a WAIT STATUS, not an exit code: a missing command |
| 840 | - * arrives as 32512 (127 << 8). Treating that as the tool's own failure would | |
| 841 | - * report "refresh failed" for a node that simply has no SCORPIOX CODE. */ | |
| 840 | + * arrives as 32512 (127 << 8) and a non-executable one as 32256 (126 << 8). | |
| 841 | + * Both mean "this node cannot run the tool", which is a different message from | |
| 842 | + * "the tool ran and said no", so both are reported as -1 here. Treating them as | |
| 843 | + * the tool's own failure would say "refresh failed" about a node that simply | |
| 844 | + * has no SCORPIOX CODE installed. */ | |
| 842 | 845 | static int run_capture(const char *bin, const char *args, buf_t *out) |
| 843 | 846 | { |
| 844 | 847 | char cmd[CMD_SZ]; |
| @@ -872,7 +875,10 @@ static int run_capture(const char *bin, const char *args, buf_t *out) | ||
| 872 | 875 | while (n > 0 && isspace((unsigned char)out->p[n - 1])) out->p[--n] = '\0'; |
| 873 | 876 | out->n = n; |
| 874 | 877 | } |
| 875 | - if (rc != -1 && ((rc >> 8) & 0xff) == 127) return -1; | |
| 878 | + if (rc != -1) { | |
| 879 | + int status = (rc >> 8) & 0xff; | |
| 880 | + if (status == 127 || status == 126) return -1; | |
| 881 | + } | |
| 876 | 882 | return 1; |
| 877 | 883 | } |
| 878 | 884 |
| index a7c6b25..003003d 100755 | ||
| --- a/tests/mock_login.sh | ||
| +++ b/tests/mock_login.sh | ||
| @@ -11,11 +11,11 @@ | ||
| 11 | 11 | # MOCK_NOUSER=1 makes --start return no user_code (a malformed CLI answer). |
| 12 | 12 | # MOCK_EXISTS=1 makes --start report "credentials already exist". |
| 13 | 13 | |
| 14 | -CREDS="${CODEX_CREDS_PATH:-/nonexistent}" | |
| 14 | +CREDS="${CODEX_CREDS_PATH:-/tmp/sx-mock-scratch}" | |
| 15 | 15 | # A decodable JWT whose payload says exp=1794509681; tests replace it with a |
| 16 | 16 | # freshly generated one so the countdown is real. |
| 17 | 17 | MOCK_DEFAULT_TOKEN="eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3OTQ1MDk2ODEsImNoYXRncHRfYWNjb3VudF9pZCI6ImFjY3QtZGVmYXVsdCJ9.DEVFAKE" |
| 18 | -PEND="${CODEX_PENDING_DIR:-/nonexistent}/codex-default.json" | |
| 18 | +PEND="${CODEX_PENDING_DIR:-/tmp/sx-mock-scratch}/codex-default.json" | |
| 19 | 19 | ACC="${CODEX_ACCOUNT:-default}" |
| 20 | 20 | |
| 21 | 21 | li=false; hr=false; exp=0 |
| index 90eab0b..d92314f 100755 | ||
| --- a/tests/run.sh | ||
| +++ b/tests/run.sh | ||
| @@ -337,7 +337,7 @@ OUT=$(body "$(MOCK_NOUSER=1 QUERY_STRING="action=start&$PWDQ" $BIN)") | ||
| 337 | 337 | json_ok "a start with no user code is start_incomplete" "$OUT" 'd["ok"] is False and d["error"]=="start_incomplete"' |
| 338 | 338 | |
| 339 | 339 | # no CLI on the node |
| 340 | -OUT=$(body "$(CODEX_LOGIN_BIN=/nonexistent QUERY_STRING="action=start&$PWDQ" $BIN)") | |
| 340 | +OUT=$(body "$(CODEX_LOGIN_BIN=sx-absent-cli-for-tests QUERY_STRING="action=start&$PWDQ" $BIN)") | |
| 341 | 341 | json_ok "a missing login CLI is cli_unavailable, not a crash" "$OUT" \ |
| 342 | 342 | 'd["ok"] is False and d["error"]=="cli_unavailable"' |
| 343 | 343 | |
| @@ -366,7 +366,7 @@ json_ok "a denied device code is a terminal failed state" "$OUT" \ | ||
| 366 | 366 | json_ok "the failed state carries the CLI error" "$OUT" 'd["error"]=="denied"' |
| 367 | 367 | json_ok "the failed state clears pending" "$OUT" 'd["pending"] is False' |
| 368 | 368 | |
| 369 | -OUT=$(body "$(CODEX_LOGIN_BIN=/nonexistent QUERY_STRING="action=poll&$PWDQ" $BIN)") | |
| 369 | +OUT=$(body "$(CODEX_LOGIN_BIN=sx-absent-cli-for-tests QUERY_STRING="action=poll&$PWDQ" $BIN)") | |
| 370 | 370 | json_ok "poll with no CLI is cli_unavailable" "$OUT" 'd["error"]=="cli_unavailable"' |
| 371 | 371 | |
| 372 | 372 | # ---------------------------------------------------------------- cancel |
| @@ -380,7 +380,7 @@ if [ -f "$FIX/pend/codex-default.json" ]; then fail "cancel removed the marker"; | ||
| 380 | 380 | |
| 381 | 381 | printf '{"device_auth_id":"dev-1","user_code":"ABCD-1234","created":%s}\n' "$NOW" \ |
| 382 | 382 | > "$FIX/pend/codex-default.json" |
| 383 | -OUT=$(body "$(CODEX_LOGIN_BIN=/nonexistent QUERY_STRING="action=cancel&$PWDQ" $BIN)") | |
| 383 | +OUT=$(body "$(CODEX_LOGIN_BIN=sx-absent-cli-for-tests QUERY_STRING="action=cancel&$PWDQ" $BIN)") | |
| 384 | 384 | json_ok "cancel with no CLI still clears the marker" "$OUT" \ |
| 385 | 385 | 'd["ok"] is True and d["pending"] is False and d["cli_present"] is False' |
| 386 | 386 | if [ -f "$FIX/pend/codex-default.json" ]; then fail "cancel without CLI removed the marker"; else pass "cancel without CLI removed the marker"; fi |
| @@ -404,7 +404,7 @@ OUT=$(body "$(MOCK_FAIL=1 QUERY_STRING="action=refresh&$PWDQ" $BIN)") | ||
| 404 | 404 | json_ok "a failing refresh CLI is reported as failure" "$OUT" \ |
| 405 | 405 | 'd["ok"] is False and d["error"]=="refresh_failed"' |
| 406 | 406 | |
| 407 | -OUT=$(body "$(CODEX_REFRESH_BIN=/nonexistent QUERY_STRING="action=refresh&$PWDQ" $BIN)") | |
| 407 | +OUT=$(body "$(CODEX_REFRESH_BIN=sx-absent-cli-for-tests QUERY_STRING="action=refresh&$PWDQ" $BIN)") | |
| 408 | 408 | json_ok "a missing refresh CLI is cli_unavailable" "$OUT" 'd["error"]=="cli_unavailable"' |
| 409 | 409 | |
| 410 | 410 | # ---------------------------------------------------------------- unknown action |
| 411 | 411 |
| index 0b9118a..a85531d 100755 | index 0b9118a..a85531d 100755 |
| index 2e5f5aa..ed90d6b 100644 | index 2e5f5aa..ed90d6b 100644 | ||
| --- a/src/plugin_codex_login.c | --- a/src/plugin_codex_login.c | ||
| +++ b/src/plugin_codex_login.c | +++ b/src/plugin_codex_login.c | ||
| @@ -837,8 +837,11 @@ static void shell_quote_into(const char *in, char *out, size_t outsz) | @@ -837,8 +837,11 @@ static void shell_quote_into(const char *in, char *out, size_t outsz) | ||
| 837 | * -1 when the binary is not on this node ("command not found"). | 837 | * -1 when the binary is not on this node ("command not found"). |
| 838 | * | 838 | * |
| 839 | * pclose() hands back a WAIT STATUS, not an exit code: a missing command | 839 | * pclose() hands back a WAIT STATUS, not an exit code: a missing command |
| 840 | - * arrives as 32512 (127 << 8). Treating that as the tool's own failure would | 840 | + * arrives as 32512 (127 << 8) and a non-executable one as 32256 (126 << 8). |
| 841 | - * report "refresh failed" for a node that simply has no SCORPIOX CODE. */ | 841 | + * Both mean "this node cannot run the tool", which is a different message from |
| 842 | + * "the tool ran and said no", so both are reported as -1 here. Treating them as | ||
| 843 | + * the tool's own failure would say "refresh failed" about a node that simply | ||
| 844 | + * has no SCORPIOX CODE installed. */ | ||
| 842 | static int run_capture(const char *bin, const char *args, buf_t *out) | 845 | static int run_capture(const char *bin, const char *args, buf_t *out) |
| 843 | { | 846 | { |
| 844 | char cmd[CMD_SZ]; | 847 | char cmd[CMD_SZ]; |
| @@ -872,7 +875,10 @@ static int run_capture(const char *bin, const char *args, buf_t *out) | @@ -872,7 +875,10 @@ static int run_capture(const char *bin, const char *args, buf_t *out) | ||
| 872 | while (n > 0 && isspace((unsigned char)out->p[n - 1])) out->p[--n] = '\0'; | 875 | while (n > 0 && isspace((unsigned char)out->p[n - 1])) out->p[--n] = '\0'; |
| 873 | out->n = n; | 876 | out->n = n; |
| 874 | } | 877 | } |
| 875 | - if (rc != -1 && ((rc >> 8) & 0xff) == 127) return -1; | 878 | + if (rc != -1) { |
| 879 | + int status = (rc >> 8) & 0xff; | ||
| 880 | + if (status == 127 || status == 126) return -1; | ||
| 881 | + } | ||
| 876 | return 1; | 882 | return 1; |
| 877 | } | 883 | } |
| 878 | 884 |
| index a7c6b25..003003d 100755 | index a7c6b25..003003d 100755 | ||
| --- a/tests/mock_login.sh | --- a/tests/mock_login.sh | ||
| +++ b/tests/mock_login.sh | +++ b/tests/mock_login.sh | ||
| @@ -11,11 +11,11 @@ | @@ -11,11 +11,11 @@ | ||
| 11 | # MOCK_NOUSER=1 makes --start return no user_code (a malformed CLI answer). | 11 | # MOCK_NOUSER=1 makes --start return no user_code (a malformed CLI answer). |
| 12 | # MOCK_EXISTS=1 makes --start report "credentials already exist". | 12 | # MOCK_EXISTS=1 makes --start report "credentials already exist". |
| 13 | 13 | ||
| 14 | -CREDS="${CODEX_CREDS_PATH:-/nonexistent}" | 14 | +CREDS="${CODEX_CREDS_PATH:-/tmp/sx-mock-scratch}" |
| 15 | # A decodable JWT whose payload says exp=1794509681; tests replace it with a | 15 | # A decodable JWT whose payload says exp=1794509681; tests replace it with a |
| 16 | # freshly generated one so the countdown is real. | 16 | # freshly generated one so the countdown is real. |
| 17 | MOCK_DEFAULT_TOKEN="eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3OTQ1MDk2ODEsImNoYXRncHRfYWNjb3VudF9pZCI6ImFjY3QtZGVmYXVsdCJ9.DEVFAKE" | 17 | MOCK_DEFAULT_TOKEN="eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3OTQ1MDk2ODEsImNoYXRncHRfYWNjb3VudF9pZCI6ImFjY3QtZGVmYXVsdCJ9.DEVFAKE" |
| 18 | -PEND="${CODEX_PENDING_DIR:-/nonexistent}/codex-default.json" | 18 | +PEND="${CODEX_PENDING_DIR:-/tmp/sx-mock-scratch}/codex-default.json" |
| 19 | ACC="${CODEX_ACCOUNT:-default}" | 19 | ACC="${CODEX_ACCOUNT:-default}" |
| 20 | 20 | ||
| 21 | li=false; hr=false; exp=0 | 21 | li=false; hr=false; exp=0 |
| index 90eab0b..d92314f 100755 | index 90eab0b..d92314f 100755 | ||
| --- a/tests/run.sh | --- a/tests/run.sh | ||
| +++ b/tests/run.sh | +++ b/tests/run.sh | ||
| @@ -337,7 +337,7 @@ OUT=$(body "$(MOCK_NOUSER=1 QUERY_STRING="action=start&$PWDQ" $BIN)") | @@ -337,7 +337,7 @@ OUT=$(body "$(MOCK_NOUSER=1 QUERY_STRING="action=start&$PWDQ" $BIN)") | ||
| 337 | json_ok "a start with no user code is start_incomplete" "$OUT" 'd["ok"] is False and d["error"]=="start_incomplete"' | 337 | json_ok "a start with no user code is start_incomplete" "$OUT" 'd["ok"] is False and d["error"]=="start_incomplete"' |
| 338 | 338 | ||
| 339 | # no CLI on the node | 339 | # no CLI on the node |
| 340 | -OUT=$(body "$(CODEX_LOGIN_BIN=/nonexistent QUERY_STRING="action=start&$PWDQ" $BIN)") | 340 | +OUT=$(body "$(CODEX_LOGIN_BIN=sx-absent-cli-for-tests QUERY_STRING="action=start&$PWDQ" $BIN)") |
| 341 | json_ok "a missing login CLI is cli_unavailable, not a crash" "$OUT" \ | 341 | json_ok "a missing login CLI is cli_unavailable, not a crash" "$OUT" \ |
| 342 | 'd["ok"] is False and d["error"]=="cli_unavailable"' | 342 | 'd["ok"] is False and d["error"]=="cli_unavailable"' |
| 343 | 343 | ||
| @@ -366,7 +366,7 @@ json_ok "a denied device code is a terminal failed state" "$OUT" \ | @@ -366,7 +366,7 @@ json_ok "a denied device code is a terminal failed state" "$OUT" \ | ||
| 366 | json_ok "the failed state carries the CLI error" "$OUT" 'd["error"]=="denied"' | 366 | json_ok "the failed state carries the CLI error" "$OUT" 'd["error"]=="denied"' |
| 367 | json_ok "the failed state clears pending" "$OUT" 'd["pending"] is False' | 367 | json_ok "the failed state clears pending" "$OUT" 'd["pending"] is False' |
| 368 | 368 | ||
| 369 | -OUT=$(body "$(CODEX_LOGIN_BIN=/nonexistent QUERY_STRING="action=poll&$PWDQ" $BIN)") | 369 | +OUT=$(body "$(CODEX_LOGIN_BIN=sx-absent-cli-for-tests QUERY_STRING="action=poll&$PWDQ" $BIN)") |
| 370 | json_ok "poll with no CLI is cli_unavailable" "$OUT" 'd["error"]=="cli_unavailable"' | 370 | json_ok "poll with no CLI is cli_unavailable" "$OUT" 'd["error"]=="cli_unavailable"' |
| 371 | 371 | ||
| 372 | # ---------------------------------------------------------------- cancel | 372 | # ---------------------------------------------------------------- cancel |
| @@ -380,7 +380,7 @@ if [ -f "$FIX/pend/codex-default.json" ]; then fail "cancel removed the marker"; | @@ -380,7 +380,7 @@ if [ -f "$FIX/pend/codex-default.json" ]; then fail "cancel removed the marker"; | ||
| 380 | 380 | ||
| 381 | printf '{"device_auth_id":"dev-1","user_code":"ABCD-1234","created":%s}\n' "$NOW" \ | 381 | printf '{"device_auth_id":"dev-1","user_code":"ABCD-1234","created":%s}\n' "$NOW" \ |
| 382 | > "$FIX/pend/codex-default.json" | 382 | > "$FIX/pend/codex-default.json" |
| 383 | -OUT=$(body "$(CODEX_LOGIN_BIN=/nonexistent QUERY_STRING="action=cancel&$PWDQ" $BIN)") | 383 | +OUT=$(body "$(CODEX_LOGIN_BIN=sx-absent-cli-for-tests QUERY_STRING="action=cancel&$PWDQ" $BIN)") |
| 384 | json_ok "cancel with no CLI still clears the marker" "$OUT" \ | 384 | json_ok "cancel with no CLI still clears the marker" "$OUT" \ |
| 385 | 'd["ok"] is True and d["pending"] is False and d["cli_present"] is False' | 385 | 'd["ok"] is True and d["pending"] is False and d["cli_present"] is False' |
| 386 | if [ -f "$FIX/pend/codex-default.json" ]; then fail "cancel without CLI removed the marker"; else pass "cancel without CLI removed the marker"; fi | 386 | if [ -f "$FIX/pend/codex-default.json" ]; then fail "cancel without CLI removed the marker"; else pass "cancel without CLI removed the marker"; fi |
| @@ -404,7 +404,7 @@ OUT=$(body "$(MOCK_FAIL=1 QUERY_STRING="action=refresh&$PWDQ" $BIN)") | @@ -404,7 +404,7 @@ OUT=$(body "$(MOCK_FAIL=1 QUERY_STRING="action=refresh&$PWDQ" $BIN)") | ||
| 404 | json_ok "a failing refresh CLI is reported as failure" "$OUT" \ | 404 | json_ok "a failing refresh CLI is reported as failure" "$OUT" \ |
| 405 | 'd["ok"] is False and d["error"]=="refresh_failed"' | 405 | 'd["ok"] is False and d["error"]=="refresh_failed"' |
| 406 | 406 | ||
| 407 | -OUT=$(body "$(CODEX_REFRESH_BIN=/nonexistent QUERY_STRING="action=refresh&$PWDQ" $BIN)") | 407 | +OUT=$(body "$(CODEX_REFRESH_BIN=sx-absent-cli-for-tests QUERY_STRING="action=refresh&$PWDQ" $BIN)") |
| 408 | json_ok "a missing refresh CLI is cli_unavailable" "$OUT" 'd["error"]=="cli_unavailable"' | 408 | json_ok "a missing refresh CLI is cli_unavailable" "$OUT" 'd["error"]=="cli_unavailable"' |
| 409 | 409 | ||
| 410 | # ---------------------------------------------------------------- unknown action | 410 | # ---------------------------------------------------------------- unknown action |
| 411 | 411 |