| 1 | #!/bin/sh |
| 2 | # Deterministic mock for scorpiox-google-quota used by tests/run.sh. |
| 3 | acct="" |
| 4 | while [ $# -gt 0 ]; do |
| 5 | case "$1" in |
| 6 | --account) acct="$2"; shift 2 ;; |
| 7 | --json) shift ;; |
| 8 | *) shift ;; |
| 9 | esac |
| 10 | done |
| 11 | |
| 12 | # Verify the plugin sanitized inherited token/profile overrides. |
| 13 | if [ -n "${GOOGLE_ACCESS_TOKEN:-}" ]; then |
| 14 | echo "error: GOOGLE_ACCESS_TOKEN leaked into child env" >&2 |
| 15 | exit 1 |
| 16 | fi |
| 17 | if [ "${GOOGLE_TOKEN_SOURCE:-}" != "local" ]; then |
| 18 | echo "error: expected GOOGLE_TOKEN_SOURCE=local" >&2 |
| 19 | exit 1 |
| 20 | fi |
| 21 | |
| 22 | echo "INFO : ya29.MOCK-TOKEN-MUST-NOT-LEAK" >&2 |
| 23 | |
| 24 | RST_CLAUDE="${MOCK_RESET_CLAUDE:-2026-11-25T06:00:00Z}" |
| 25 | RST_GEMINI="${MOCK_RESET_GEMINI:-2026-11-25T03:00:00Z}" |
| 26 | |
| 27 | case "$acct" in |
| 28 | alpha@example.com) |
| 29 | cat <<EOF |
| 30 | { |
| 31 | "ok": true, |
| 32 | "email": "alpha@example.com", |
| 33 | "project": "proj-alpha", |
| 34 | "endpoint": "https://daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota", |
| 35 | "buckets": [ |
| 36 | {"tokenType": "WTUS", "modelId": "chat_20706", "remainingFraction": 1}, |
| 37 | {"resetTime": "$RST_CLAUDE", "tokenType": "WTUS", "modelId": "claude-opus-4-6-thinking", "remainingFraction": 1}, |
| 38 | {"resetTime": "$RST_CLAUDE", "tokenType": "WTUS", "modelId": "claude-opus-5-5-high", "remainingFraction": 1}, |
| 39 | {"resetTime": "$RST_CLAUDE", "tokenType": "WTUS", "modelId": "claude-sonnet-4-6", "remainingFraction": 1}, |
| 40 | {"resetTime": "$RST_CLAUDE", "tokenType": "WTUS", "modelId": "claude-sonnet-5-5-high", "remainingFraction": 1}, |
| 41 | {"resetTime": "$RST_GEMINI", "tokenType": "WTUS", "modelId": "gemini-3.8-flash-tiered", "remainingFraction": 0.855}, |
| 42 | {"resetTime": "$RST_GEMINI", "tokenType": "WTUS", "modelId": "gemini-4-argon-high", "remainingFraction": 1}, |
| 43 | {"resetTime": "$RST_GEMINI", "tokenType": "WTUS", "modelId": "gemini-4-hydrogen-high", "remainingFraction": 0.855}, |
| 44 | {"resetTime": "$RST_GEMINI", "tokenType": "WTUS", "modelId": "gemini-4-hydrogen-sonar", "remainingFraction": 0.855}, |
| 45 | {"resetTime": "$RST_GEMINI", "tokenType": "WTUS", "modelId": "gemini-4-neon-high", "remainingFraction": 0.855}, |
| 46 | {"tokenType": "WTUS", "modelId": "tab_flash_lite_preview", "remainingFraction": 1} |
| 47 | ], |
| 48 | "summary": { |
| 49 | "groups": [ |
| 50 | { |
| 51 | "displayName": "Gemini Models", |
| 52 | "buckets": [ |
| 53 | {"bucketId": "gemini-weekly", "window": "weekly", "remainingFraction": 0.855, "resetTime": "$RST_GEMINI"}, |
| 54 | {"bucketId": "gemini-5h", "window": "5h", "remainingFraction": 0.375, "resetTime": "$RST_CLAUDE"} |
| 55 | ] |
| 56 | }, |
| 57 | { |
| 58 | "displayName": "Claude and GPT models", |
| 59 | "buckets": [ |
| 60 | {"bucketId": "3p-weekly", "window": "weekly", "remainingFraction": 0.99, "resetTime": "$RST_GEMINI"}, |
| 61 | {"bucketId": "3p-5h", "window": "5h", "remainingFraction": 1} |
| 62 | ] |
| 63 | } |
| 64 | ] |
| 65 | } |
| 66 | } |
| 67 | EOF |
| 68 | exit 0 |
| 69 | ;; |
| 70 | beta@example.com) |
| 71 | cat <<EOF |
| 72 | { |
| 73 | "ok": true, |
| 74 | "email": "beta@example.com", |
| 75 | "project": "aicode-consumers", |
| 76 | "endpoint": "https://daily-cloudcode-pa.googleapis.com/v1internal:retrieveUserQuota", |
| 77 | "buckets": [ |
| 78 | {"resetTime": "$RST_CLAUDE", "tokenType": "WTUS", "modelId": "claude-sonnet-4-6", "remainingFraction": 0.42}, |
| 79 | {"resetTime": "$RST_GEMINI", "tokenType": "WTUS", "modelId": "gemini-3.8-flash-tiered", "remainingFraction": null}, |
| 80 | {"resetTime": "$RST_GEMINI", "tokenType": "WTUS", "modelId": "gemini-4-hydrogen-sonar"} |
| 81 | ], |
| 82 | "summary": { |
| 83 | "groups": [ |
| 84 | { |
| 85 | "displayName": "Gemini Models", |
| 86 | "buckets": [ |
| 87 | {"bucketId": "gemini-weekly", "window": "weekly", "resetTime": "$RST_GEMINI"} |
| 88 | ] |
| 89 | }, |
| 90 | { |
| 91 | "displayName": "Claude and GPT models", |
| 92 | "buckets": [ |
| 93 | {"bucketId": "3p-weekly", "window": "weekly", "remainingFraction": 0.42, "resetTime": "$RST_GEMINI"}, |
| 94 | {"bucketId": "3p-5h", "window": "5h", "remainingFraction": 0.50, "resetTime": "$RST_CLAUDE"} |
| 95 | ] |
| 96 | } |
| 97 | ] |
| 98 | } |
| 99 | } |
| 100 | EOF |
| 101 | exit 0 |
| 102 | ;; |
| 103 | broken@example.com) |
| 104 | echo "error: invalid_grant" >&2 |
| 105 | exit 1 |
| 106 | ;; |
| 107 | *) |
| 108 | echo "error: unknown mock account $acct" >&2 |
| 109 | exit 1 |
| 110 | ;; |
| 111 | esac |