| 1 | #!/bin/sh |
| 2 | # tests/run.sh - offline checks for plugin_antigravity_login across all 3 modes. |
| 3 | # |
| 4 | # Every check runs against ./plugin_antigravity_login with the credential paths |
| 5 | # and both CLIs redirected at throwaway fixtures, so the suite proves the public |
| 6 | # contract without touching a real Google session and without a network. |
| 7 | # |
| 8 | # What it proves: |
| 9 | # - --meta is exactly {"name":"google","desc":"Google login"} and is reachable |
| 10 | # with no password (discovery must never be gated) |
| 11 | # - every action 401s without the node password, and 401 is a real CGI Status |
| 12 | # - status parses the accounts array + sibling files + the CLI JSON and never |
| 13 | # emits a token |
| 14 | # - start returns the CLI's auth_url, finish rejects garbage codes locally and |
| 15 | # re-reads state after a successful exchange |
| 16 | # - refresh performs the grant, drops the access token, and surfaces failure |
| 17 | # - the HTML page carries the bot theme handoff, no CDN and no <script src=> |
| 18 | # - the source has no hard-coded secret, no internal address and no emoji |
| 19 | # |
| 20 | # Exit code 0 = everything passed. |
| 21 | |
| 22 | set -u |
| 23 | |
| 24 | ROOT=$(cd "$(dirname "$0")/.." && pwd) |
| 25 | cd "$ROOT" || exit 1 |
| 26 | |
| 27 | BIN=./plugin_antigravity_login |
| 28 | ID=plugin_antigravity_login |
| 29 | PASS=0 |
| 30 | FAIL=0 |
| 31 | |
| 32 | if [ -t 1 ]; then |
| 33 | C_OK=$(printf '\033[32m'); C_BAD=$(printf '\033[31m'); C_B=$(printf '\033[1m'); C_0=$(printf '\033[0m') |
| 34 | else |
| 35 | C_OK=; C_BAD=; C_B=; C_0= |
| 36 | fi |
| 37 | pass() { PASS=$((PASS + 1)); printf ' %sok%s %s\n' "$C_OK" "$C_0" "$1"; } |
| 38 | fail() { FAIL=$((FAIL + 1)); printf ' %sFAIL%s %s\n' "$C_BAD" "$C_0" "$1"; } |
| 39 | |
| 40 | check() { # check <desc> <expected-substring> <actual> |
| 41 | if printf '%s' "$3" | grep -F -q -- "$2"; then pass "$1"; else |
| 42 | fail "$1 (want: $2)"; printf ' got: %s\n' "$(printf '%s' "$3" | head -c 400)" |
| 43 | fi |
| 44 | } |
| 45 | |
| 46 | check_not() { # check_not <desc> <forbidden-substring> <actual> |
| 47 | if printf '%s' "$3" | grep -F -q -- "$2"; then |
| 48 | fail "$1 (must NOT contain: $2)"; else pass "$1" |
| 49 | fi |
| 50 | } |
| 51 | |
| 52 | section() { printf '\n%s== %s ==%s\n' "$C_B" "$1" "$C_0"; } |
| 53 | |
| 54 | # strip CGI headers if present, drop CRs, keep the payload |
| 55 | body() { |
| 56 | printf '%s\n' "$1" | tr -d '\r' | awk ' |
| 57 | BEGIN { inhdr = 0 } |
| 58 | NR == 1 && ($0 ~ /^(Content-Type|Status|Cache-Control|X-Content-Type-Options|X-Frame-Options|Referrer-Policy|Content-Security-Policy):/) { inhdr = 1; next } |
| 59 | inhdr && $0 == "" { inhdr = 0; next } |
| 60 | inhdr { next } |
| 61 | { print } |
| 62 | ' |
| 63 | } |
| 64 | |
| 65 | json_ok() { # json_ok <desc> <json> [python-expression] |
| 66 | expr=${3:-True} |
| 67 | if printf '%s' "$2" | python3 -c "import json,sys; d=json.load(sys.stdin); sys.exit(0 if ($expr) else 1)" 2>/dev/null; then |
| 68 | pass "$1" |
| 69 | else |
| 70 | fail "$1 (invalid JSON or assertion failed)"; printf ' got: %s\n' "$(printf '%s' "$2" | head -c 400)" |
| 71 | fi |
| 72 | } |
| 73 | |
| 74 | api() { body "$(QUERY_STRING="$1" $BIN)"; } |
| 75 | apiraw() { QUERY_STRING="$1" $BIN; } |
| 76 | |
| 77 | # ---------------------------------------------------------------- build |
| 78 | section "build" |
| 79 | if [ ! -x "$BIN" ]; then |
| 80 | echo " building native binary..." |
| 81 | gcc -O2 -std=c99 -Wall -Wextra -I src -o "$BIN" src/plugin_antigravity_login.c || { |
| 82 | fail "native build"; exit 1; } |
| 83 | fi |
| 84 | pass "native binary present" |
| 85 | |
| 86 | # generated page header must match src/ui.html |
| 87 | if python3 tools/gen_ui.py --check >/dev/null 2>&1; then |
| 88 | pass "src/ui_html.h is in sync with src/ui.html" |
| 89 | else |
| 90 | fail "src/ui_html.h is stale - run tools/gen_ui.py" |
| 91 | fi |
| 92 | |
| 93 | # the page header must not be hand-edited: it is generated from ui.html |
| 94 | check "ui header is marked generated" \ |
| 95 | "Generated by tools/gen_ui.py" "$(head -1 src/ui_html.h)" |
| 96 | |
| 97 | # ---------------------------------------------------------------- fixtures |
| 98 | FIX=$(mktemp -d 2>/dev/null || mktemp -d -t agyfix) |
| 99 | trap 'rm -rf "$FIX"' EXIT |
| 100 | |
| 101 | mkdir -p "$FIX/none" "$FIX/empty" "$FIX/full" "$FIX/full/scorpiox-env" "$FIX/pending" |
| 102 | export ANTIGRAVITY_LOGIN_BIN="$ROOT/tests/mock_login.sh" |
| 103 | export ANTIGRAVITY_TOKEN_BIN="$ROOT/tests/mock_token.sh" |
| 104 | export ANTIGRAVITY_PENDING_PATH="$FIX/pending/antigravity-default.json" |
| 105 | |
| 106 | # empty credentials file (exists but has no accounts) |
| 107 | : > "$FIX/empty/antigravity_accounts.json" |
| 108 | |
| 109 | # a realistic signed-in fixture: the accounts array + selected account + profile |
| 110 | cat > "$FIX/full/antigravity_accounts.json" <<'JSON' |
| 111 | [ |
| 112 | {"email":"other@example.com","refresh_token":"1//other-refresh"}, |
| 113 | {"email":"pico@example.com","refresh_token":"1//pico-refresh-value"} |
| 114 | ] |
| 115 | JSON |
| 116 | printf 'pico@example.com\n' > "$FIX/full/selected_account.txt" |
| 117 | printf 'PROVIDER=google_gemini\nGOOGLE_TOKEN_SOURCE=local\nGOOGLE_ACCOUNT=pico@example.com\nGOOGLE_PROJECT_ID=proj-mock-42\nMODEL=gemini-3.7-flash-tiered\n' \ |
| 118 | > "$FIX/full/scorpiox-env/antigravity.txt" |
| 119 | |
| 120 | # ---------------------------------------------------------------- metadata |
| 121 | section "mode 1: discovery metadata" |
| 122 | META=$("$BIN" --meta) |
| 123 | if [ "$META" = '{"name":"google","desc":"Google login"}' ]; then |
| 124 | pass "--meta is exactly the contract line" |
| 125 | else |
| 126 | fail "--meta mismatch"; printf ' got: %s\n' "$META" |
| 127 | fi |
| 128 | json_ok "--meta is valid JSON with name+desc" "$META" \ |
| 129 | "d['name']=='google' and d['desc']=='Google login'" |
| 130 | check "--meta desc is within 15 chars" "Google login" "$META" |
| 131 | |
| 132 | ENVMETA=$(SX_PLUGIN_META=1 "$BIN") |
| 133 | check "SX_PLUGIN_META=1 works like --meta" '"name":"google"' "$ENVMETA" |
| 134 | |
| 135 | # --meta must not be gated by the node password |
| 136 | META_PW=$(BOT_PASSWORD=testpw "$BIN" --meta) |
| 137 | check "--meta ignores BOT_PASSWORD" '"name":"google"' "$META_PW" |
| 138 | |
| 139 | check "--version prints the plugin id and version" "$ID" "$("$BIN" --version)" |
| 140 | |
| 141 | # ---------------------------------------------------------------- auth |
| 142 | section "node auth" |
| 143 | export BOT_PASSWORD=testpw |
| 144 | RAW=$(apiraw "action=status") |
| 145 | check "unauthenticated action returns a 401 Status line" "Status: 401 Unauthorized" "$RAW" |
| 146 | check "unauthenticated action body is JSON" '"error":"invalid node password"' "$RAW" |
| 147 | |
| 148 | RAW=$(apiraw "") |
| 149 | check "unauthenticated HTML also 401s" "Status: 401 Unauthorized" "$RAW" |
| 150 | |
| 151 | HDR=$(api "action=status&pwd=testpw") |
| 152 | check "?pwd= authenticates" '"ok":true' "$HDR" |
| 153 | |
| 154 | HDR=$(QUERY_STRING="action=status" HTTP_X_BOT_PASSWORD=testpw $BIN) |
| 155 | check "X-Bot-Password authenticates" '"ok":true' "$(body "$HDR")" |
| 156 | |
| 157 | HDR=$(QUERY_STRING="action=status" HTTP_AUTHORIZATION="Bearer testpw" $BIN) |
| 158 | check "Authorization: Bearer authenticates" '"ok":true' "$(body "$HDR")" |
| 159 | |
| 160 | WRONG=$(apiraw "action=status&pwd=nope") |
| 161 | check "a wrong password still 401s" "Status: 401 Unauthorized" "$WRONG" |
| 162 | unset BOT_PASSWORD |
| 163 | |
| 164 | # ---------------------------------------------------------------- status |
| 165 | section "action=status" |
| 166 | NOFIX=$(ANTIGRAVITY_CREDS_PATH="$FIX/none/antigravity_accounts.json" \ |
| 167 | MOCK_STATUS_JSON='{"ok":true,"provider":"antigravity","logged_in":false,"expires_at":0,"expired":false,"has_refresh":false,"pending":false}' \ |
| 168 | api "action=status") |
| 169 | json_ok "status with no credentials is valid JSON" "$NOFIX" \ |
| 170 | "d['ok'] is True and d['logged_in'] is False and d['has_refresh'] is False" |
| 171 | check_not "status with no credentials emits no token field" "refresh_token" "$NOFIX" |
| 172 | |
| 173 | EMPTYJ=$(ANTIGRAVITY_CREDS_PATH="$FIX/empty/antigravity_accounts.json" api "action=status") |
| 174 | json_ok "empty accounts file yields logged_in false" "$EMPTYJ" \ |
| 175 | "d['ok'] is True and d['logged_in'] is False" |
| 176 | |
| 177 | FULL=$(ANTIGRAVITY_CREDS_PATH="$FIX/full/antigravity_accounts.json" \ |
| 178 | MOCK_STATUS_JSON='{"ok":true,"provider":"antigravity","logged_in":true,"expires_at":4102444800000,"expired":false,"has_refresh":true,"pending":false,"identity":"pico@example.com"}' \ |
| 179 | api "action=status") |
| 180 | json_ok "signed-in status reports logged_in + has_refresh" "$FULL" \ |
| 181 | "d['ok'] is True and d['logged_in'] is True and d['has_refresh'] is True" |
| 182 | check_not "signed-in status never returns the refresh token" "1//pico-refresh-value" "$FULL" |
| 183 | check_not "signed-in status never returns any token literal" "refresh_token\":" "$FULL" |
| 184 | |
| 185 | check "status reports the selected account email" "pico@example.com" "$FULL" |
| 186 | check "status reads the companion project from the profile" "proj-mock-42" "$FULL" |
| 187 | check "status reports the credentials path" "$FIX/full/antigravity_accounts.json" "$FULL" |
| 188 | json_ok "status has the full contract field set" "$FULL" \ |
| 189 | "all(k in d for k in ('logged_in','email','project_id','expires_at','expires_in_sec','expired','has_refresh','account','pending','profile'))" |
| 190 | |
| 191 | # expired session: the CLI says the expiry is in the past |
| 192 | EXPIRED=$(ANTIGRAVITY_CREDS_PATH="$FIX/full/antigravity_accounts.json" \ |
| 193 | MOCK_STATUS_JSON='{"ok":true,"provider":"antigravity","logged_in":true,"expires_at":1000000000000,"expired":true,"has_refresh":true,"pending":false}' \ |
| 194 | api "action=status") |
| 195 | json_ok "an expired session reports expired true and a negative remaining time" "$EXPIRED" \ |
| 196 | "d['expired'] is True and d['expires_in_sec'] < 0" |
| 197 | |
| 198 | # a far-future expiry must not overflow: expires_in_sec used to be an int, so |
| 199 | # any expiry past 2038 came out as -1987015054 while expired stayed false. |
| 200 | FAR=$(ANTIGRAVITY_CREDS_PATH="$FIX/full/antigravity_accounts.json" \ |
| 201 | MOCK_STATUS_JSON='{"ok":true,"provider":"antigravity","logged_in":true,"expires_at":4102444800000,"expired":false,"has_refresh":true}' \ |
| 202 | api "action=status") |
| 203 | json_ok "a post-2038 expiry reports a positive remaining time" "$FAR" \ |
| 204 | "d['expires_in_sec'] > 0 and d['expired'] is False" |
| 205 | json_ok "a post-2038 expiry normalises ms to seconds" "$FAR" \ |
| 206 | "d['expires_at'] == 4102444800" |
| 207 | |
| 208 | # pending marker file present -> pending true even without CLI help |
| 209 | : > "$FIX/pending/antigravity-default.json" |
| 210 | PEND=$(ANTIGRAVITY_CREDS_PATH="$FIX/none/antigravity_accounts.json" \ |
| 211 | MOCK_STATUS_JSON='{"ok":true,"provider":"antigravity","logged_in":false,"pending":false}' \ |
| 212 | api "action=status") |
| 213 | json_ok "the pending marker file makes status pending" "$PEND" "d['pending'] is True" |
| 214 | rm -f "$FIX/pending/antigravity-default.json" |
| 215 | |
| 216 | # no CLI on PATH: status must still answer from the files alone |
| 217 | NOCLI=$(ANTIGRAVITY_LOGIN_BIN="/nonexistent/login-cli" \ |
| 218 | ANTIGRAVITY_CREDS_PATH="$FIX/full/antigravity_accounts.json" api "action=status") |
| 219 | json_ok "status answers without the login CLI" "$NOCLI" \ |
| 220 | "d['ok'] is True and d['logged_in'] is True" |
| 221 | json_ok "cli_present is false when the CLI is missing" "$NOCLI" "d['cli_present'] is False" |
| 222 | |
| 223 | # format=json with no action means status |
| 224 | FMT=$(ANTIGRAVITY_CREDS_PATH="$FIX/full/antigravity_accounts.json" \ |
| 225 | MOCK_STATUS_JSON='{"ok":true,"logged_in":true,"has_refresh":true}' api "format=json") |
| 226 | json_ok "format=json alone answers status" "$FMT" "d['ok'] is True and 'logged_in' in d" |
| 227 | |
| 228 | # ---------------------------------------------------------------- start |
| 229 | section "action=start" |
| 230 | START=$(api "action=start") |
| 231 | json_ok "start returns ok + an auth_url" "$START" \ |
| 232 | "d['ok'] is True and d['auth_url'].startswith('https://accounts.google.com/')" |
| 233 | check "start reports the paste_code flow" '"flow":"paste_code"' "$START" |
| 234 | check "start carries the PKCE challenge in the URL" "code_challenge=" "$START" |
| 235 | check "start carries the S256 method" "code_challenge_method=S256" "$START" |
| 236 | check "start reports an expiry window" "expires_in" "$START" |
| 237 | |
| 238 | # the plugin must not invent a client secret of its own |
| 239 | check_not "start never echoes a client secret" "GOCSPX" "$START" |
| 240 | |
| 241 | NOCLISTART=$(ANTIGRAVITY_LOGIN_BIN="/nonexistent/login-cli" api "action=start") |
| 242 | json_ok "start without the CLI returns a structured error" "$NOCLISTART" \ |
| 243 | "d['ok'] is False and d['error']=='cli_unavailable'" |
| 244 | |
| 245 | # ---------------------------------------------------------------- finish |
| 246 | section "action=finish" |
| 247 | MISSING=$(api "action=finish") |
| 248 | json_ok "finish without a code is a 400-style error object" "$MISSING" \ |
| 249 | "d['ok'] is False and d['error']=='missing_code'" |
| 250 | |
| 251 | SHELLY=$(api "action=finish&code=\$(touch_/tmp/pwned)") |
| 252 | json_ok "finish rejects shell metacharacters before running anything" "$SHELLY" \ |
| 253 | "d['ok'] is False and d['error']=='invalid_code'" |
| 254 | if [ -e /tmp/pwned ]; then fail "shell injection created /tmp/pwned"; rm -f /tmp/pwned; else pass "shell injection did not execute"; fi |
| 255 | |
| 256 | QUOTED=$(api "action=finish&code=abc%27def") |
| 257 | json_ok "finish rejects a quote in the code" "$QUOTED" \ |
| 258 | "d['ok'] is False and d['error']=='invalid_code'" |
| 259 | |
| 260 | FAILED=$(MOCK_FAIL=1 api "action=finish&code=4/0AX4XfWh-test-code") |
| 261 | json_ok "a rejected exchange surfaces the CLI error" "$FAILED" \ |
| 262 | "d['ok'] is False and d['error'] in ('exchange','finish_failed')" |
| 263 | |
| 264 | # successful exchange: the mock writes the credential files into $MOCK_WRITE_DIR |
| 265 | mkdir -p "$FIX/finishdir" |
| 266 | OKF=$(MOCK_WRITE_DIR="$FIX/finishdir" ANTIGRAVITY_CREDS_PATH="$FIX/finishdir/antigravity_accounts.json" \ |
| 267 | api "action=finish&code=4/0AX4XfWh-test-code") |
| 268 | json_ok "a successful exchange reports done + logged_in" "$OKF" \ |
| 269 | "d['ok'] is True and d['state']=='done' and d['logged_in'] is True" |
| 270 | check "the exchange result re-reads the new account" "pico@example.com" "$OKF" |
| 271 | check_not "the exchange result never carries the token" "1//mock-refresh-token-value" "$OKF" |
| 272 | |
| 273 | # a full redirect URL is accepted (the CLI extracts code= itself) |
| 274 | FULLURL=$(MOCK_WRITE_DIR="$FIX/finishdir" ANTIGRAVITY_CREDS_PATH="$FIX/finishdir/antigravity_accounts.json" \ |
| 275 | api "action=finish&code=https%3A%2F%2Fantigravity.google%2Foauth-callback%3Fcode%3D4%2F0AX-test%26state%3Dxyz") |
| 276 | json_ok "a whole redirect URL is accepted" "$FULLURL" "d['ok'] is True and d['state']=='done'" |
| 277 | |
| 278 | # POST body carrying the code |
| 279 | POSTB=$(printf '{"code":"4/0AX4XfWh-post-code"}' | \ |
| 280 | REQUEST_METHOD=POST CONTENT_LENGTH=32 \ |
| 281 | MOCK_WRITE_DIR="$FIX/finishdir" ANTIGRAVITY_CREDS_PATH="$FIX/finishdir/antigravity_accounts.json" \ |
| 282 | QUERY_STRING="action=finish" $BIN) |
| 283 | json_ok "the code can arrive in a POST body" "$(body "$POSTB")" "d['ok'] is True" |
| 284 | |
| 285 | # ---------------------------------------------------------------- cancel |
| 286 | section "action=cancel" |
| 287 | CANCEL=$(api "action=cancel") |
| 288 | json_ok "cancel reports a cancelled state" "$CANCEL" \ |
| 289 | "d['ok'] is True and d['state']=='cancelled' and d['pending'] is False" |
| 290 | |
| 291 | # ---------------------------------------------------------------- refresh |
| 292 | section "action=refresh" |
| 293 | REFR=$(ANTIGRAVITY_CREDS_PATH="$FIX/full/antigravity_accounts.json" api "action=refresh") |
| 294 | json_ok "refresh succeeds and reports refreshed" "$REFR" \ |
| 295 | "d['ok'] is True and d['refreshed'] is True" |
| 296 | check_not "refresh NEVER returns the access token" "ya29.MOCK-ACCESS-TOKEN-MUST-NOT-LEAK" "$REFR" |
| 297 | check_not "refresh has no access_token key at all" "access_token" "$REFR" |
| 298 | check "refresh reports the project from the token CLI" "proj-mock-42" "$REFR" |
| 299 | |
| 300 | REFRFAIL=$(MOCK_TOKEN_FAIL=1 api "action=refresh") |
| 301 | json_ok "a failed refresh returns a structured error" "$REFRFAIL" \ |
| 302 | "d['ok'] is False and d['error']=='refresh_failed'" |
| 303 | |
| 304 | REFRNOCLI=$(ANTIGRAVITY_TOKEN_BIN="/nonexistent/token-cli" api "action=refresh") |
| 305 | json_ok "refresh without the token CLI says cli_unavailable" "$REFRNOCLI" \ |
| 306 | "d['ok'] is False and d['error']=='cli_unavailable'" |
| 307 | |
| 308 | # ---------------------------------------------------------------- errors |
| 309 | section "unknown routes and actions" |
| 310 | UNK=$(api "action=teleport") |
| 311 | json_ok "an unknown action is a structured error" "$UNK" \ |
| 312 | "d['ok'] is False and d['error']=='unknown_action'" |
| 313 | RAWUNK=$(apiraw "action=teleport") |
| 314 | check "an unknown action returns a 404 Status" "Status: 404 Not Found" "$RAWUNK" |
| 315 | check "the error carries the plugin contract headers" "Content-Type: application/json" "$RAWUNK" |
| 316 | check_not "no response emits Content-Length" "Content-Length" "$RAWUNK" |
| 317 | |
| 318 | BADS=$(api "action=status") |
| 319 | check_not "JSON responses carry Cache-Control: no-store" "Cache-Control: no-store" "$BADS" |
| 320 | |
| 321 | # ---------------------------------------------------------------- HTML |
| 322 | section "mode 3: HTML UI" |
| 323 | HTMLRAW=$(apiraw "") |
| 324 | HTML=$(body "$HTMLRAW") |
| 325 | check "HTML is served as text/html" "Content-Type: text/html; charset=utf-8" "$HTMLRAW" |
| 326 | check "HTML declares a viewport" "name=\"viewport\"" "$HTML" |
| 327 | check "HTML carries the CSP header" "Content-Security-Policy" "$HTMLRAW" |
| 328 | check "HTML declares color-scheme via the theme tokens" "color-scheme" "$HTML" |
| 329 | check "HTML includes the bot prepaint script" "bot_theme" "$HTML" |
| 330 | check "HTML includes the theme handoff listener" "sx-theme" "$HTML" |
| 331 | check "HTML has the status pill" 'id="pill"' "$HTML" |
| 332 | check "HTML has the start button" 'id="btnStart"' "$HTML" |
| 333 | check "HTML has the paste input" 'id="codeInput"' "$HTML" |
| 334 | check "HTML has the finish button" 'id="btnFinish"' "$HTML" |
| 335 | check "HTML has the cancel button" 'id="btnCancel"' "$HTML" |
| 336 | check "HTML has the refresh button" 'id="btnRefresh"' "$HTML" |
| 337 | check "HTML has the companion project card" "Companion project" "$HTML" |
| 338 | check "HTML uses the two-route API helper" "plugin_antigravity_login" "$HTML" |
| 339 | check "HTML hides the back link in embed mode" "embed-hide" "$HTML" |
| 340 | check_not "HTML loads no CDN script" "<script src=" "$HTML" |
| 341 | check_not "HTML references no external host script" "cdnjs" "$HTML" |
| 342 | check_not "HTML makes no outbound fetch to a third party" "googleapis.com" "$HTML" |
| 343 | check_not "HTML carries no emoji" "๐" "$HTML" |
| 344 | |
| 345 | if command -v python3 >/dev/null 2>&1; then |
| 346 | printf '%s' "$HTML" > "$FIX/page.html" |
| 347 | if python3 - "$FIX/page.html" <<'PY' |
| 348 | import re, sys |
| 349 | html = open(sys.argv[1], encoding='utf-8').read() |
| 350 | # every id referenced by getElementById must exist in the markup |
| 351 | ids = set(re.findall(r'id="([^"]+)"', html)) |
| 352 | missing = [i for i in re.findall(r"\$\('([^']+)'\)", html) if i not in ids] |
| 353 | sys.exit(1 if missing else 0) |
| 354 | PY |
| 355 | then pass "every JS element id exists in the markup" |
| 356 | else fail "the page JS references an element id that is not in the HTML"; fi |
| 357 | fi |
| 358 | |
| 359 | # ---------------------------------------------------------------- source hygiene |
| 360 | section "source hygiene" |
| 361 | check_not "source has no OAuth client secret" "GOCSPX" "$(cat src/plugin_antigravity_login.c)" |
| 362 | check_not "source has no Google API key" "AIza" "$(cat src/plugin_antigravity_login.c)" |
| 363 | check_not "source has no GitHub token" "ghp_" "$(cat src/plugin_antigravity_login.c)" |
| 364 | check_not "source has no internal address" "192.168." "$(cat src/plugin_antigravity_login.c src/ui.html)" |
| 365 | check_not "source has no 10.x internal address" "10.0." "$(cat src/plugin_antigravity_login.c src/ui.html)" |
| 366 | check_not "the page has no internal address either" "172.16" "$(cat src/ui.html)" |
| 367 | |
| 368 | # no emoji anywhere in the shipped sources (byte-level check, not a regex guess) |
| 369 | if python3 - src/plugin_antigravity_login.c src/ui.html src/bot_theme_plugin.h <<'PY' |
| 370 | import sys, unicodedata |
| 371 | bad = [] |
| 372 | for path in sys.argv[1:]: |
| 373 | for n, line in enumerate(open(path, encoding='utf-8'), 1): |
| 374 | for ch in line: |
| 375 | o = ord(ch) |
| 376 | if o < 0x2000: |
| 377 | continue |
| 378 | if 0x2190 <= o <= 0x21FF: # arrows are typography, not emoji |
| 379 | continue |
| 380 | if unicodedata.category(ch) in ('So', 'Sk') or 0x1F000 <= o <= 0x1FAFF: |
| 381 | bad.append('%s:%d %r' % (path, n, ch)) |
| 382 | if bad: |
| 383 | print('\n'.join(bad[:10])) |
| 384 | sys.exit(1) |
| 385 | PY |
| 386 | then pass "no emoji in source, page or theme header" |
| 387 | else fail "emoji found in the shipped sources"; fi |
| 388 | |
| 389 | # ---------------------------------------------------------------- extra builds |
| 390 | section "cross-target builds" |
| 391 | if command -v musl-gcc >/dev/null 2>&1; then |
| 392 | if musl-gcc -O2 -std=c99 -static -I src -o "$FIX/musl-bin" src/plugin_antigravity_login.c 2>/dev/null; then |
| 393 | pass "static musl build" |
| 394 | MUSLMETA=$("$FIX/musl-bin" --meta) |
| 395 | check "the musl binary reports the same metadata" '"name":"google"' "$MUSLMETA" |
| 396 | else fail "static musl build"; fi |
| 397 | else |
| 398 | echo " skip musl-gcc not installed" |
| 399 | fi |
| 400 | |
| 401 | if command -v x86_64-w64-mingw32-gcc >/dev/null 2>&1; then |
| 402 | if x86_64-w64-mingw32-gcc -O2 -std=c99 -static -I src -o "$FIX/win-bin.exe" src/plugin_antigravity_login.c 2>/dev/null; then |
| 403 | pass "MinGW-w64 build" |
| 404 | if [ "$(head -c 2 "$FIX/win-bin.exe")" = "MZ" ]; then |
| 405 | pass "the Windows build has a real PE header" |
| 406 | else fail "the Windows build is not a PE (missing MZ)"; fi |
| 407 | else fail "MinGW-w64 build"; fi |
| 408 | else |
| 409 | echo " skip x86_64-w64-mingw32-gcc not installed" |
| 410 | fi |
| 411 | |
| 412 | if command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then |
| 413 | if aarch64-linux-gnu-gcc -O2 -std=c99 -static -I src -o "$FIX/arm-bin" src/plugin_antigravity_login.c 2>/dev/null; then |
| 414 | pass "static arm64 build" |
| 415 | else fail "static arm64 build"; fi |
| 416 | else |
| 417 | echo " skip aarch64-linux-gnu-gcc not installed" |
| 418 | fi |
| 419 | |
| 420 | # _FORTIFY_SOURCE=2: the sqlite plugin lost a whole build to this, so it is |
| 421 | # part of every suite now. |
| 422 | if gcc -O2 -std=c99 -D_FORTIFY_SOURCE=2 -I src -o "$FIX/fortify-bin" src/plugin_antigravity_login.c 2>/dev/null; then |
| 423 | FORTMETA=$("$FIX/fortify-bin" --meta) |
| 424 | check "a _FORTIFY_SOURCE=2 build runs --meta clean" '"name":"google"' "$FORTMETA" |
| 425 | FORTSTAT=$(ANTIGRAVITY_CREDS_PATH="$FIX/full/antigravity_accounts.json" \ |
| 426 | QUERY_STRING="action=status" "$FIX/fortify-bin") |
| 427 | json_ok "a fortify build answers status without aborting" "$(body "$FORTSTAT")" "d['ok'] is True" |
| 428 | else |
| 429 | fail "_FORTIFY_SOURCE=2 build" |
| 430 | fi |
| 431 | |
| 432 | # ---------------------------------------------------------------- summary |
| 433 | printf '\n%s== summary ==%s\n' "$C_B" "$C_0" |
| 434 | printf ' %d passed, %d failed\n' "$PASS" "$FAIL" |
| 435 | [ "$FAIL" -eq 0 ] || exit 1 |
| 436 | exit 0 |