Skip to content

test(dev): add inflight-staging contention e2e; drop migration test - #1373

Merged
kalbasit merged 2 commits into
mainfrom
test-harness-coverage-audit
Jun 9, 2026
Merged

kalbasit merged 2 commits into
mainfrom
test-harness-coverage-audit

Conversation

@kalbasit

@kalbasit kalbasit commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add dev-scripts/test-inflight-staging-contention-e2e.py + test-inflight-staging-contention-auto.sh (and a task test:inflight-staging-contention target): a multi-replica + Redis-locker contention driver that activates in-flight NAR staging by racing concurrent readers against an in-flight download, asserting every reader gets a complete, byte-identical NAR (vs. nix-store --dump) across the download/chunking windows and local/s3 backends. Fails loudly if staging never activates.
  • Remove the obsolete dev-scripts/test-migration-e2e.py (the dbmate→Ent cutover it validated has shipped; unwired, no importers). The shared dbmate create/drop in run.py/migrate-all.py is retained.

This harness drove the discovery and validation of the in-flight-staging fixes stacked on top of it.

Test plan

  • task fmt / task lint / task test pass
  • Driver validated live against Garage/Postgres/Redis (download window green)

Add a multi-replica contention driver that actually activates in-flight
NAR staging — the fix for the #660 download-window and #1289
chunking-window incomplete-NAR bugs. Staging only engages under
contention (a reader racing an in-flight download with a distributed
locker), which Go unit tests cover only in-process and the k8s HA
permutations merely enable in config without ever driving. PR #1372
added run.py --inflight-staging, making a dev-level driver possible.

The driver (test-inflight-staging-contention-e2e.py) launches >=2 ncps
replicas via run.py with --locker redis --inflight-staging, verifies
effective config from state.json, then races N barrier-synchronized HTTP
clients on one uncached NAR. It asserts every reader gets a complete NAR
byte-identical to the canonical `nix-store --dump`, across the download
and chunking windows and the local/s3 backends, and fails loudly (with
producer-error vs. no-contention classification) if staging never
activated. A fixed-port wrapper and `task test:inflight-staging-
contention` mirror the CDC-lifecycle driver; it is opt-in, not part of
nix flake check.

Remove the obsolete test-migration-e2e.py: it validated the one-time
dbmate->Ent cutover, which has shipped, and is unwired (no Taskfile/CI/
nix/importer). The shared dbmate create/drop in run.py and migrate-all.py
are retained. Lineage comments in the CDC driver are cleaned up.

Validated live against real Garage/Postgres/Redis: cluster, config
checks, the cross-replica race, and byte-identity all pass. The harness
immediately surfaced a real ncps bug (staging producer races into the
holder's deleted temp file on fast downloads, so staging never serves);
the fix is deferred to a separate change.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@kalbasit

kalbasit commented Jun 8, 2026 •

Copy link
Copy Markdown
Owner Author

@dosubot dosubot Bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Jun 8, 2026
@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 68a0ec74-9a64-47fa-8812-1f50839e9b33

📥 Commits

Reviewing files that changed from the base of the PR and between 77512c7 and 6ab9955.

📒 Files selected for processing (1)
  • dev-scripts/test-inflight-staging-contention-e2e.py

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added an end-to-end harness to validate in-flight NAR staging under multi-replica contention, verifying byte-identical delivery across concurrent readers and reporting per-phase results.
  • Tests

    • New fixed-port task and wrapper to start required dev services, run the contention driver with passthrough args, and teardown on exit.
    • Exercises download (CDC off) and chunking (CDC on) phases across local and S3 backends.
  • Chores

    • Removed an obsolete migration e2e test script.
  • Documentation

    • Added spec, design, proposal and task docs describing the new coverage and execution steps.

Walkthrough

This pull request adds a new e2e harness to validate in‑flight NAR staging under multi‑replica contention: spec/design docs, a fixed‑port bash wrapper and Taskfile task, a Python driver that runs contention races and validates byte‑identical NAR delivery across CDC windows and storage backends, and minor doc cleanups.

Changes

In-flight staging contention e2e harness

Layer / File(s) Summary
Specification and design documentation
openspec/changes/archive/2026-06-08-test-harness-coverage-audit/design.md, openspec/changes/archive/2026-06-08-test-harness-coverage-audit/proposal.md, openspec/changes/archive/2026-06-08-test-harness-coverage-audit/specs/inflight-staging-contention-e2e/spec.md, openspec/changes/archive/2026-06-08-test-harness-coverage-audit/.openspec.yaml, openspec/changes/archive/2026-06-08-test-harness-coverage-audit/tasks.md, openspec/specs/inflight-staging-contention-e2e/spec.md
Complete specifications and design describing multi-replica Redis-locked cluster setup, deterministic contention strategy, byte-identical decompressed NAR validation, separate download/chunking windows (CDC off/on), storage-backend matrix (local and s3), and wrapper lifecycle requirements.
Wrapper script and task integration
dev-scripts/test-inflight-staging-contention-auto.sh, Taskfile.yml
Bash wrapper starts fixed-port dev dependency stack, waits up to 120s for required service ports (S3/Postgres/MariaDB/Redis), runs the Python e2e driver with passthrough args, tears down services on exit, and a Taskfile task invokes the wrapper forwarding {{.CLI_ARGS}}.
E2E driver core implementation
dev-scripts/test-inflight-staging-contention-e2e.py
Python driver orchestrates cluster lifecycle via run.py --locker redis --inflight-staging, realizes a canonical NAR via Nix, fetches narinfo to learn NAR URL/compression, runs barrier‑synchronized concurrent GETs across many clients, decompresses and SHA‑256 digests payloads, asserts HTTP 200 and digest equality to the canonical reference, enforces staging activation via log scans, runs phases across CDC windows and storages, and writes per-phase result.json plus summary.json under timestamped .e2e-results/.
Documentation updates
dev-scripts/test-cdc-lifecycle-e2e.py
Docstring and comment edits to clarify the CDC lifecycle wording and .e2e-results/ gitignore behavior; removed references to the obsolete migration e2e script in section headings.

Sequence Diagram(s)

sequenceDiagram
  participant Wrapper as test-inflight-staging-contention-auto.sh
  participant DepsStack as nix run .#deps
  participant Driver as test-inflight-staging-contention-e2e.py
  participant Cluster as dev-scripts/run.py (multi-replica)
  participant Replica1 as ncps replica 1
  participant Replica2 as ncps replica 2
  
  Wrapper->>DepsStack: start services (Redis, S3, Postgres, MariaDB)
  DepsStack-->>Wrapper: services ready on fixed ports
  Wrapper->>Driver: invoke with CLI args
  Driver->>Cluster: start with --locker redis --inflight-staging
  Cluster->>Replica1: launch replica 1
  Cluster->>Replica2: launch replica 2
  Replica1-->>Driver: state.json (inflight_staging enabled)
  Replica2-->>Driver: state.json (inflight_staging enabled)
  Driver->>Driver: realise flake, compute canonical NAR digest
  Driver->>Replica1: fetch .narinfo for target store-path
  Replica1-->>Driver: narinfo with URL/compression
  par Concurrent NAR fetches
    Driver->>Replica1: GET NAR (client 1)
    Driver->>Replica2: GET NAR (client 2)
    Driver->>Replica1: GET NAR (client N)
  end
  Replica1-->>Driver: HTTP 200 + compressed NAR (client 1)
  Replica2-->>Driver: HTTP 200 + compressed NAR (client 2)
  Driver->>Driver: decompress all NARs, compute digests
  Driver->>Driver: assert all digests match canonical
  Driver->>Replica1: scan logs for staging activation evidence
  Replica1-->>Driver: debug log: staging activated
  Driver->>Driver: write phase result (PASS/FAIL)
  Driver->>Cluster: stop cluster
  Wrapper->>DepsStack: teardown services
  DepsStack-->>Wrapper: services stopped
  Wrapper-->>Driver: exit with aggregated summary
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

enhancement, documentation, size:L, merge-stack

Poem

🐰 I hopped through docs and scripts today,
racing NARs where replicas play,
Redis held the lock so neat,
digests matched — a rabbit's treat,
teardown done, the harness says hooray!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 39.13% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main changes: adding a new inflight-staging contention e2e test and removing the obsolete migration test.
Description check ✅ Passed The description is directly related to the changeset, detailing the additions and removals with context about their purpose and validation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new end-to-end test harness (test-inflight-staging-contention-e2e.py) and an automated wrapper script to validate in-flight NAR staging under multi-replica contention using a Redis locker. It also removes the obsolete test-migration-e2e.py script and updates related documentation and task configurations. The review feedback focuses on improving the robustness of the new Python test script, specifically by enhancing HTTP error handling in the http_get helper to prevent dead code, opening subprocess logs in binary mode to avoid encoding issues, and explicitly specifying UTF-8 encoding when reading logs and state files.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
dev-scripts/test-cdc-lifecycle-e2e.py (1)

165-176: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

File handle leak if subprocess.Popen raises.

Same issue as in test-inflight-staging-contention-e2e.py: the file is opened before subprocess.Popen, and if Popen raises, the file handle leaks.

🛡️ Proposed fix using try/except pattern
-    f = open(log_path, "w")
-    # start_new_session=True puts the child in its own session/process group
-    # (like os.setsid) so stop_ncps can kill the whole group via os.killpg —
-    # the modern, fork-safe replacement for preexec_fn=os.setsid.
-    p = subprocess.Popen(
-        args,
-        cwd=REPO_ROOT,
-        stdout=f,
-        stderr=subprocess.STDOUT,
-        start_new_session=True,
-    )
-    return p, f
+    try:
+        f = open(log_path, "w")
+        # start_new_session=True puts the child in its own session/process group
+        # (like os.setsid) so stop_ncps can kill the whole group via os.killpg —
+        # the modern, fork-safe replacement for preexec_fn=os.setsid.
+        p = subprocess.Popen(
+            args,
+            cwd=REPO_ROOT,
+            stdout=f,
+            stderr=subprocess.STDOUT,
+            start_new_session=True,
+        )
+        return p, f
+    except Exception:
+        if 'f' in locals():
+            f.close()
+        raise
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@dev-scripts/test-cdc-lifecycle-e2e.py` around lines 165 - 176, The file
handle f opened with open(log_path, "w") may leak if subprocess.Popen(...)
raises; wrap the Popen call so f is always closed on error (either open the file
with a context manager around Popen or use try/except/finally to close f on
exception). Specifically, change the behavior around subprocess.Popen (the call
that creates p) so that if Popen fails you close f rather than returning; ensure
the function that returns p, f still returns a valid pair only when Popen
succeeds, referencing the variables f, log_path, args, REPO_ROOT, and the
subprocess.Popen invocation (with start_new_session=True).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@dev-scripts/test-inflight-staging-contention-auto.sh`:
- Around line 23-24: The direnv bootstrap is split across two separate commands
so the unset/eval runs even if `direnv allow .` fails; change the two-line
sequence (`direnv status | grep -q "Found RC allowed 0" || direnv allow .` and
`unset DIRENV_DIR DIRENV_FILE DIRENV_WATCHES DIRENV_DIFF && eval "$(direnv
export bash)"`) into a single chained expression using `||` and `&&` as: run the
status check OR attempt `direnv allow .` and only if one of those succeeds then
run the `unset DIRENV_*` and `eval "$(direnv export bash)"`, ensuring the
unset/eval only executes on success.

In `@dev-scripts/test-inflight-staging-contention-e2e.py`:
- Around line 155-165: Open handle 'f' may leak if subprocess.Popen(args, ...)
raises; change the logic around the open(log_path, "w") and subprocess.Popen
call so the file is always closed on error: open the file, call
subprocess.Popen, and if Popen raises close 'f' and re-raise (or use a context
manager/try/finally) so you only return (p, f) when Popen succeeds. Update the
code that uses log_path, f, subprocess.Popen, args, REPO_ROOT, and
start_new_session to implement this cleanup.

---

Outside diff comments:
In `@dev-scripts/test-cdc-lifecycle-e2e.py`:
- Around line 165-176: The file handle f opened with open(log_path, "w") may
leak if subprocess.Popen(...) raises; wrap the Popen call so f is always closed
on error (either open the file with a context manager around Popen or use
try/except/finally to close f on exception). Specifically, change the behavior
around subprocess.Popen (the call that creates p) so that if Popen fails you
close f rather than returning; ensure the function that returns p, f still
returns a valid pair only when Popen succeeds, referencing the variables f,
log_path, args, REPO_ROOT, and the subprocess.Popen invocation (with
start_new_session=True).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9cef3caf-84d9-4920-a82e-ee9bfdd79948

📥 Commits

Reviewing files that changed from the base of the PR and between 15b0c63 and 77512c7.

📒 Files selected for processing (11)
  • Taskfile.yml
  • dev-scripts/test-cdc-lifecycle-e2e.py
  • dev-scripts/test-inflight-staging-contention-auto.sh
  • dev-scripts/test-inflight-staging-contention-e2e.py
  • dev-scripts/test-migration-e2e.py
  • openspec/changes/archive/2026-06-08-test-harness-coverage-audit/.openspec.yaml
  • openspec/changes/archive/2026-06-08-test-harness-coverage-audit/design.md
  • openspec/changes/archive/2026-06-08-test-harness-coverage-audit/proposal.md
  • openspec/changes/archive/2026-06-08-test-harness-coverage-audit/specs/inflight-staging-contention-e2e/spec.md
  • openspec/changes/archive/2026-06-08-test-harness-coverage-audit/tasks.md
  • openspec/specs/inflight-staging-contention-e2e/spec.md
💤 Files with no reviewable changes (1)
  • dev-scripts/test-migration-e2e.py

Address review feedback on the contention e2e driver:
- scan_logs / read_state / the cluster log file now open with
  encoding="utf-8" (errors="replace" for the ncps logs, which can carry
  non-UTF-8 bytes from Nix build output) so reads never crash on locale
  or non-ASCII content. (threads PRRT_kwDONV6tZs6H_Vpz, _Vp1, _Vpu)
- start_cluster closes the log file if subprocess.Popen raises, so the
  handle never leaks. (thread PRRT_kwDONV6tZs6H_XpY)
@kalbasit
kalbasit enabled auto-merge (squash) June 9, 2026 00:10
@kalbasit
kalbasit merged commit 2605560 into main Jun 9, 2026
46 of 58 checks passed
@kalbasit
kalbasit deleted the test-harness-coverage-audit branch June 9, 2026 00:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-stack size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants