-
Notifications
You must be signed in to change notification settings - Fork 2.2k
428 lines (377 loc) · 16.5 KB
/
Copy pathbackend-hermetic-e2e.yml
File metadata and controls
428 lines (377 loc) · 16.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
name: Backend Hermetic E2E
on:
pull_request:
branches: main
merge_group:
types: [checks_requested]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: backend-hermetic-e2e-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
scope:
name: Detect Hermetic Backend Scope
runs-on: ubuntu-latest
# The full-history fetch (fetch-depth: 0, required to resolve the PR base
# live for the scope diff) can exceed two minutes on hosted runners for
# large merge refs; the old 2-minute job cap killed the fetch mid-transfer
# and the merge gate correctly failed closed on "scope cancelled" with no
# code failure. Bound generously like the apt steps below: the cap is a
# hang backstop, not a budget the legitimate path must fit under.
timeout-minutes: 10
outputs:
applies: ${{ steps.scope.outputs.applies }}
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
fetch-depth: 0
- name: Decide whether hermetic backend coverage applies
id: scope
shell: bash
env:
EVENT_NAME: ${{ github.event_name }}
# Resolve the PR base live against the checkout (matching
# detect-changes) rather than the event-payload base.sha, which can be
# stale for a queued run (FC-stale-event-payload-diff-base, #10785).
PR_BASE_REF: origin/${{ github.base_ref }}
MERGE_GROUP_BASE_SHA: ${{ github.event.merge_group.base_sha }}
run: |
case "$EVENT_NAME" in
pull_request) base_sha="$PR_BASE_REF" ;;
merge_group) base_sha="$MERGE_GROUP_BASE_SHA" ;;
workflow_dispatch)
echo "applies=true" >> "$GITHUB_OUTPUT"
exit 0
;;
*)
echo "Unsupported event for hermetic backend scope: $EVENT_NAME" >&2
exit 1
;;
esac
if [[ -z "$base_sha" ]] || ! git cat-file -e "${base_sha}^{commit}"; then
echo "Cannot resolve hermetic backend scope base: ${base_sha:-<empty>}" >&2
exit 1
fi
changed_files="$(git diff --name-only "$base_sha"...HEAD)"
printf '%s\n' "$changed_files"
if grep -Eq '^(backend/|package\.json$|package-lock\.json$|\.github/workflows/backend-hermetic-e2e\.yml$)' <<<"$changed_files"; then
echo "applies=true" >> "$GITHUB_OUTPUT"
else
echo "applies=false" >> "$GITHUB_OUTPUT"
fi
hermetic-e2e:
name: Hermetic Backend E2E
runs-on: ubuntu-latest
timeout-minutes: 10
needs: scope
if: needs.scope.outputs.applies == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version-file: backend/.python-version
- name: Set up uv
# astral-sh/setup-uv v7, pinned to an immutable commit for CI supply-chain stability.
uses: astral-sh/setup-uv@ecd24dd710f2fb0dca1693a67af11fc4a5c5ec84
with:
# Exact version resolves locally; an unset version means "latest",
# which fetches the astral-sh/versions manifest and has hard-failed
# CI on that network call. Matches backend/Dockerfile UV_VERSION.
version: "0.11.13"
enable-cache: true
cache-dependency-glob: backend/pylock*.toml
- name: Install backend and e2e dependencies
working-directory: backend
run: uv pip sync pylock.toml --system
- name: Restore tokenizer cache
uses: actions/cache@v6
with:
path: ${{ runner.temp }}/tiktoken-cache
key: tiktoken-${{ runner.os }}-${{ hashFiles('backend/pylock.toml') }}
- name: Prewarm tokenizer cache
env:
TIKTOKEN_CACHE_DIR: ${{ runner.temp }}/tiktoken-cache
run: python backend/scripts/prewarm_tiktoken_cache.py
- name: Run hermetic backend e2e harness
env:
E2E_PYTEST_TIMEOUT: 120s
TIKTOKEN_CACHE_DIR: ${{ runner.temp }}/tiktoken-cache
run: bash backend/testing/e2e/run.sh -q --tb=short
listen-pusher-stack-gauntlet:
name: Listen Pusher Stack Gauntlet
runs-on: ubuntu-latest
timeout-minutes: 20
needs: scope
if: needs.scope.outputs.applies == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version-file: backend/.python-version
- name: Set up uv
uses: astral-sh/setup-uv@ecd24dd710f2fb0dca1693a67af11fc4a5c5ec84
with:
# Exact version resolves locally; an unset version means "latest",
# which fetches the astral-sh/versions manifest and has hard-failed
# CI on that network call. Matches backend/Dockerfile UV_VERSION.
version: "0.11.13"
enable-cache: true
cache-dependency-glob: backend/pylock*.toml
- name: Install backend dependencies in the gauntlet virtualenv
working-directory: backend
run: |
uv venv .venv
uv pip sync pylock.toml --python .venv/bin/python
- name: Set up Node.js for the Firestore emulator
uses: actions/setup-node@v7
with:
node-version: '22'
cache: npm
cache-dependency-path: package-lock.json
- name: Install pinned Firebase CLI dependencies
run: |
for attempt in 1 2 3; do
if npm ci --ignore-scripts --prefer-offline --no-audit --fund=false; then
exit 0
fi
if [[ "$attempt" == 3 ]]; then
echo "Pinned Firebase CLI dependency install failed after 3 attempts." >&2
npm cache verify || true
exit 1
fi
echo "npm ci failed on attempt $attempt/3; verifying cache before bounded retry." >&2
npm cache verify
sleep "$attempt"
done
- name: Set up Java for the Firestore emulator
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: '21'
- name: Install Redis server
# The harness spawns its own `redis-server` binary per test on an
# ephemeral port (see backend/testing/*/run.py), so this needs the
# actual package installed, not a `services:` container.
#
# apt against the default Azure-mirror apt source on hosted runners
# can silently stall (connects but never completes the transfer)
# instead of failing, which previously let this step hang until the
# job's 20-minute timeout killed it with an opaque "operation was
# canceled". Bound each apt network attempt and retry a few times so
# a stalled mirror fails over quickly, and cap the step itself as a
# backstop.
timeout-minutes: 5
run: |
sudo apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=10 -o Acquire::https::Timeout=10 update
sudo apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=10 -o Acquire::https::Timeout=10 install --yes redis-server
- name: Run listen to pusher stack gauntlet
run: npm run test:listen-pusher-stack:emulator -- --state-dir "$RUNNER_TEMP/listen-pusher-stack"
- name: Show listen gauntlet process diagnostics on failure
if: failure()
run: |
state_dir="$RUNNER_TEMP/listen-pusher-stack"
if [[ -d "$state_dir" ]]; then
find "$state_dir" -type f \( -name '*.log' -o -name '*.jsonl' \) -print -exec tail -n 160 {} \;
else
echo "Listen gauntlet state directory was not retained."
fi
sync-cloud-tasks-stack-gauntlet:
name: Sync Cloud Tasks Stack Gauntlet
runs-on: ubuntu-latest
timeout-minutes: 20
needs: scope
if: needs.scope.outputs.applies == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version-file: backend/.python-version
- name: Set up uv
uses: astral-sh/setup-uv@ecd24dd710f2fb0dca1693a67af11fc4a5c5ec84
with:
# Exact version resolves locally; an unset version means "latest",
# which fetches the astral-sh/versions manifest and has hard-failed
# CI on that network call. Matches backend/Dockerfile UV_VERSION.
version: "0.11.13"
enable-cache: true
cache-dependency-glob: backend/pylock*.toml
- name: Install backend dependencies in the gauntlet virtualenv
working-directory: backend
run: |
uv venv .venv
uv pip sync pylock.toml --python .venv/bin/python
- name: Set up Node.js for the Firestore emulator
uses: actions/setup-node@v7
with:
node-version: '22'
cache: npm
cache-dependency-path: package-lock.json
- name: Install pinned Firebase CLI dependencies
run: |
for attempt in 1 2 3; do
if npm ci --ignore-scripts --prefer-offline --no-audit --fund=false; then
exit 0
fi
if [[ "$attempt" == 3 ]]; then
echo "Pinned Firebase CLI dependency install failed after 3 attempts." >&2
npm cache verify || true
exit 1
fi
echo "npm ci failed on attempt $attempt/3; verifying cache before bounded retry." >&2
npm cache verify
sleep "$attempt"
done
- name: Set up Java for the Firestore emulator
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: '21'
- name: Install Redis server
# The harness spawns its own `redis-server` binary per test on an
# ephemeral port (see backend/testing/*/run.py), so this needs the
# actual package installed, not a `services:` container.
#
# apt against the default Azure-mirror apt source on hosted runners
# can silently stall (connects but never completes the transfer)
# instead of failing, which previously let this step hang until the
# job's 20-minute timeout killed it with an opaque "operation was
# canceled". Bound each apt network attempt and retry a few times so
# a stalled mirror fails over quickly, and cap the step itself as a
# backstop.
timeout-minutes: 5
run: |
sudo apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=10 -o Acquire::https::Timeout=10 update
sudo apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=10 -o Acquire::https::Timeout=10 install --yes redis-server
- name: Run Sync Cloud Tasks stack gauntlet
run: npm run test:sync-cloud-tasks-stack:emulator
replay-harness-phase0a-gauntlet:
name: Replay Harness Phase 0A Feasibility (advisory)
runs-on: ubuntu-latest
timeout-minutes: 20
needs: scope
if: needs.scope.outputs.applies == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version-file: backend/.python-version
- name: Set up uv
uses: astral-sh/setup-uv@ecd24dd710f2fb0dca1693a67af11fc4a5c5ec84
with:
# Exact version resolves locally; an unset version means "latest",
# which fetches the astral-sh/versions manifest and has hard-failed
# CI on that network call. Matches backend/Dockerfile UV_VERSION.
version: "0.11.13"
enable-cache: true
cache-dependency-glob: backend/pylock*.toml
- name: Install backend dependencies in the gauntlet virtualenv
working-directory: backend
run: |
uv venv .venv
uv pip sync pylock.toml --python .venv/bin/python
- name: Set up Node.js for the Firestore emulator
uses: actions/setup-node@v7
with:
node-version: '22'
cache: npm
cache-dependency-path: package-lock.json
- name: Install pinned Firebase CLI dependencies
run: npm ci --ignore-scripts
- name: Set up Java for the Firestore emulator
uses: actions/setup-java@v5
with:
distribution: temurin
java-version: '21'
- name: Install Redis server
# The harness spawns its own `redis-server` binary per test on an
# ephemeral port (see backend/testing/*/run.py), so this needs the
# actual package installed, not a `services:` container.
#
# apt against the default Azure-mirror apt source on hosted runners
# can silently stall (connects but never completes the transfer)
# instead of failing, which previously let this step hang until the
# job's 20-minute timeout killed it with an opaque "operation was
# canceled". Bound each apt network attempt and retry a few times so
# a stalled mirror fails over quickly, and cap the step itself as a
# backstop.
timeout-minutes: 5
run: |
sudo apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=10 -o Acquire::https::Timeout=10 update
sudo apt-get -o Acquire::Retries=3 -o Acquire::http::Timeout=10 -o Acquire::https::Timeout=10 install --yes redis-server
- name: Run Phase 0A replay harness feasibility experiment
env:
# Fixed state root so failed-job evidence (logs/attestations) is retained
# at a known path for the failure step below.
OMI_REPLAY_STATE_ROOT: ${{ runner.temp }}/omi-replay-harness
run: npm run test:replay-harness-phase0a:emulator
- name: Show replay harness logs on failure
if: failure()
run: |
state_root="$RUNNER_TEMP/omi-replay-harness"
if [[ -d "$state_root" ]]; then
find "$state_root" -type f \( -name '*.log' -o -name 'attestation.json' \) -print -exec sh -c 'echo "===== $1 ====="; tail -n 160 "$1"' _ {} \;
else
echo "Replay harness state directory was not retained."
fi
merge-gate:
name: Backend Hermetic Merge Gate
runs-on: ubuntu-latest
timeout-minutes: 2
# `!cancelled()` rather than `always()`: with cancel-in-progress above, a
# superseding push cancels this run mid-flight, and under `always()` the
# gate still executed against `cancelled` upstream results and reported a
# hard red with no code cause (3 of the last 4 re-run-to-green cycles on
# this workflow were exactly that). A cancelled run's verdict belongs to
# the superseding run, so the gate must go neutral, not red.
if: ${{ !cancelled() }}
needs: [scope, hermetic-e2e, listen-pusher-stack-gauntlet, sync-cloud-tasks-stack-gauntlet]
steps:
- name: Fail closed on selected hermetic checks
env:
SCOPE_RESULT: ${{ needs.scope.result }}
SCOPE_APPLIES: ${{ needs.scope.outputs.applies }}
HERMETIC_E2E_RESULT: ${{ needs.hermetic-e2e.result }}
LISTEN_PUSHER_RESULT: ${{ needs.listen-pusher-stack-gauntlet.result }}
SYNC_CLOUD_TASKS_RESULT: ${{ needs.sync-cloud-tasks-stack-gauntlet.result }}
run: |
# Belt to the `!cancelled()` suspenders: a partially-cancelled run
# (one upstream job cancelled without the gate itself being
# cancelled) is still superseded work, not a failure.
for result_name in SCOPE_RESULT HERMETIC_E2E_RESULT LISTEN_PUSHER_RESULT SYNC_CLOUD_TASKS_RESULT; do
if [[ "${!result_name}" == 'cancelled' ]]; then
echo "$result_name was cancelled by a superseding run; deferring to that run's gate."
exit 0
fi
done
if [[ "$SCOPE_RESULT" != 'success' ]]; then
echo "Hermetic backend scope failed with result: $SCOPE_RESULT" >&2
exit 1
fi
case "$SCOPE_APPLIES" in
true) required_result='success' ;;
false) required_result='skipped' ;;
*)
echo "Hermetic backend scope produced an invalid result: ${SCOPE_APPLIES:-<empty>}" >&2
exit 1
;;
esac
failed=0
for result_name in HERMETIC_E2E_RESULT LISTEN_PUSHER_RESULT SYNC_CLOUD_TASKS_RESULT; do
result="${!result_name}"
if [[ "$result" != "$required_result" ]]; then
echo "$result_name must be $required_result, got ${result:-<empty>}" >&2
failed=1
fi
done
exit "$failed"