Skip to content

test(cdc): non-CDC->CDC->drain->non-CDC lifecycle e2e + k8s permutation - #1348

Merged
kalbasit merged 4 commits into
mainfrom
user/wnasreddine/integration-tests
Jun 7, 2026
Merged

kalbasit merged 4 commits into
mainfrom
user/wnasreddine/integration-tests

Conversation

@kalbasit

@kalbasit kalbasit commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary

Adds end-to-end test infrastructure for the full CDC lifecycle (successor to test-migration-e2e.py):

  • Local driver dev-scripts/test-cdc-lifecycle-e2e.py + task test:cdc-lifecycle (auto-wrapper brings up the fixed-port nix run .#deps stack). Drives non-CDC -> CDC (eager+lazy) -> drain -> non-CDC by restarting ncps, asserting DB + serving invariants per phase plus cross-cutting checks (upload presence; fsck no-data-loss).
  • k8s-tests permutation ha-s3-postgres-cdc-lifecycle (nix/k8s-tests) gated on a cdc-lifecycle marker, with a _test_cdc_lifecycle phase script (ConfigMap CDC flip + rollout restart; in-pod migrate-chunks-to-nar).

This driver caught the CDC serving bug fixed below it in the stack (#1346); after that fix the full lifecycle passes end-to-end. Depends on the image fix (#stacked) for in-cluster pod start.

Test plan

  • Local lifecycle e2e PASSES end-to-end (Phases 0-4 + cross-cutting), deterministic
  • task fmt/lint/test green; k8s permutation generates/lists/installs
  • Full in-cluster k8s lifecycle run (now unblocked by the image fix) — in progress
  • OpenSpec change cdc-lifecycle-e2e-tests archived before merge (6.2/6.3 + in-cluster run pending)

@kalbasit

kalbasit commented Jun 7, 2026 •

Copy link
Copy Markdown
Owner Author

This change is part of the following stack:

Change managed by git-spice.

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

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a Taskfile task and Bash wrapper to run a new Python e2e driver that exercises the CDC lifecycle (non-CDC → CDC eager/lazy → drain → restart) with DB/HTTP/CLI assertions, plus a Kubernetes permutation and tester helpers to run the same lifecycle on Kind; includes docs/specs and test wiring.

Changes

CDC Lifecycle End-to-End Testing

Layer / File(s) Summary
Task and Bash wrapper
Taskfile.yml, dev-scripts/test-cdc-lifecycle-auto.sh
Task test:cdc-lifecycle and Bash wrapper start fixed-port dev deps, wait readiness (ports 9000/5432/3306/6379), run the Python driver, and teardown via EXIT trap.
Python driver core & orchestration
dev-scripts/test-cdc-lifecycle-e2e.py (core ranges)
Adds logging/assert helpers, ncps start/stop/restart with readiness/port checks, HTTP fetch/head helpers, narinfo parse, NAR fetch + decompression+digest, cache seeding, and CLI wrappers for migrate-chunks-to-nar and fsck.
Five-phase lifecycle assertions
dev-scripts/test-cdc-lifecycle-e2e.py (phase functions)
Phase 0 baseline (CDC off), Phase 1 eager CDC, Phase 2 lazy CDC, Phase 3 drain (dry-run then force reclaim), Phase 4 restart auto-complete; plus cross-cutting HEAD/GET and fsck --repair validations and per-phase artifacts.
Runner & CLI entrypoint
dev-scripts/test-cdc-lifecycle-e2e.py (runner/main)
Lifecycle runner producing per-target result.json and root summary.json, supports --db, --storage, --keep-going, and ensures ncps cleanup on success/failure.
Kubernetes permutation & feature marker
nix/k8s-tests/config.nix
Adds ha-s3-postgres-cdc-lifecycle permutation and a top-level cdc-lifecycle feature marker mirrored into generateValues for test routing.
k8s README and docs
nix/k8s-tests/README.md
Updates permutation count to 13 and documents the new CDC lifecycle permutation and local driver pointer.
Test-config flag generation
nix/k8s-tests/src/k8s_tests.py
Adds cdc_lifecycle boolean to generated deployment entries when features includes cdc-lifecycle.
k8s tester helpers & in-pod ops
nix/k8s-tests/src/k8s_tests_tester.py (helper ranges)
Adds Postgres port-forward query, ConfigMap mutation to disable CDC, rollout restart/readiness, in-pod migrate-chunks-to-nar exec, narinfo/NAR serve-check, and S3 chunk prefix correction.
k8s lifecycle & topology tests
nix/k8s-tests/src/k8s_tests_tester.py (lifecycle+topology)
Implements _test_cdc_lifecycle (Postgres-only) multi-phase flow and _test_cdc_topology enforcing per-pod and cross-replica HEAD/GET agreement and phantom detection.
OpenSpec design/proposal/specs & tasks
openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/*, openspec/specs/cdc-lifecycle-*/*
Adds design/proposal/specs/tasks and updates .openspec.yaml metadata describing local and k8s CDC lifecycle e2e requirements and wiring.

Sequence Diagram(s)

sequenceDiagram
  participant Taskfile
  participant BashWrapper
  participant Deps
  participant PythonDriver
  participant NCPS
  participant HTTP
  participant DB
  Taskfile->>BashWrapper: task test:cdc-lifecycle
  BashWrapper->>Deps: nix run .#deps up --detached (PC port)
  BashWrapper->>BashWrapper: wait ports ready (9000,5432,3306,6379)
  BashWrapper->>PythonDriver: start driver (pass CLI args)
  PythonDriver->>NCPS: start_ncps(clean?/cdc?/lazy?)
  NCPS->>DB: record cdc_* keys / chunk tables
  PythonDriver->>HTTP: fetch .narinfo, GET NAR bytes
  PythonDriver->>NCPS: restart(cdc=True/False,lazy=...)
  PythonDriver->>NCPS: run migrate-chunks-to-nar / fsck via run_cli
  NCPS->>DB: migrate chunks → nar, clear cdc_* keys
  PythonDriver->>Deps: EXIT trap -> process-compose down
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

  • kalbasit/ncps#1334: Related de-chunking/normalization logic exercised by the drain/migrate phases.
  • kalbasit/ncps#1301: Implementation of migrate-chunks-to-nar CLI that the e2e driver invokes and validates.
  • kalbasit/ncps#1233: Prior dev-scripts e2e orchestrator with overlapping lifecycle helper patterns.

Suggested labels

enhancement, documentation

Poem

🐰 I hopped and watched the server spin,
Seeds pushed, chunks formed, then drained within,
Digests matched beneath my paw,
Restarts cleared the CDC law,
Logs safe, the rabbit dances—win!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% 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 'test(cdc): non-CDC->CDC->drain->non-CDC lifecycle e2e + k8s permutation' directly and clearly summarizes the main change: adding end-to-end tests for the CDC lifecycle with both local and Kubernetes test infrastructure.
Description check ✅ Passed The description is directly related to the changeset, detailing the local driver, k8s-tests permutation, test status, and dependencies. It provides meaningful context about the CDC lifecycle testing being added.
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.


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 comprehensive end-to-end testing for the content-defined chunking (CDC) lifecycle (non-CDC -> CDC -> drain -> non-CDC). It adds a local Python-based e2e test driver (dev-scripts/test-cdc-lifecycle-e2e.py) with a corresponding Taskfile target, and extends the Kubernetes integration test suite (nix/k8s-tests) with a new multi-replica ha-s3-postgres-cdc-lifecycle permutation. Feedback on the changes focuses on improving robustness and error handling in the test scripts, specifically by replacing the deprecated preexec_fn with start_new_session=True in subprocess management, adding defensive guards when accessing Kubernetes ConfigMap data, and ensuring subprocess failures during chunk migration are explicitly caught with check=True.

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.

Comment thread dev-scripts/test-cdc-lifecycle-e2e.py Resolved
Comment thread nix/k8s-tests/src/k8s_tests_tester.py Resolved
Comment thread nix/k8s-tests/src/k8s_tests_tester.py Resolved

@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.

Caution

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

⚠️ Outside diff range comments (2)
nix/k8s-tests/README.md (1)

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

Update the expected output count from 12 to 13.

The troubleshooting command example shows the expected output as 12, but this PR adds a 13th permutation (ha-s3-postgres-cdc-lifecycle). Update the comment to reflect the new count.

📝 Proposed fix
-# Should output: 12
+# Should output: 13
🤖 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 `@nix/k8s-tests/README.md` at line 306, Update the expected count in the
troubleshooting example comment from "# Should output: 12" to "# Should output:
13" in the README entry that documents the command output; this reflects the new
permutation "ha-s3-postgres-cdc-lifecycle" added by the PR so the example and
comment are consistent with the updated permutations.
dev-scripts/test-cdc-lifecycle-auto.sh (1)

1-56: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Bootstrap direnv before executing non-git commands.

This shell script runs several non-git commands (cd, nix, python3) without first bootstrapping direnv. As per coding guidelines, non-interactive shell scripts matching **/*.sh must bootstrap direnv before any non-git command.

🔧 Proposed fix

Add the direnv bootstrap block after the shebang and set flags:

 #!/usr/bin/env bash
 set -euo pipefail
+
+# Bootstrap direnv in non-interactive shells
+direnv status | grep -q "Found RC allowed 0" || direnv allow . && unset DIRENV_DIR DIRENV_FILE DIRENV_WATCHES DIRENV_DIFF && eval "$(direnv export bash)"

 # test-cdc-lifecycle-auto.sh — start the FIXED-port dev backends

As per coding guidelines: Bootstrap direnv before any non-git command in non-interactive shells. Use: direnv status | grep -q "Found RC allowed 0" || direnv allow . && unset DIRENV_DIR DIRENV_FILE DIRENV_WATCHES DIRENV_DIFF && eval "$(direnv export bash)". See env-execution.md.

🤖 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-auto.sh` around lines 1 - 56, Add a direnv
bootstrap block immediately after the shebang and before any non-git commands
(before REPO_ROOT assignment and any calls to nix/run/python3) to satisfy the
non-interactive shell guideline; implement the suggested check-and-allow flow
(run direnv status check, direnv allow ., unset DIRENV_* vars, and eval direnv
export bash) so the script boots direnv before it executes REPO_ROOT=..., nix
run .#deps, and the final python3 dev-scripts/test-cdc-lifecycle-e2e.py "$@"
invocation.

Source: Coding guidelines

🧹 Nitpick comments (1)
dev-scripts/test-cdc-lifecycle-e2e.py (1)

606-608: 💤 Low value

Consider using _ for the unused return code.

The fsck return code is fetched but never checked. Use _ to signal this is intentional.

♻️ Proposed change
-    rc, out = fsck(db, storage, repair=True)
+    _, out = fsck(db, storage, repair=True)
     with open(os.path.join(sdir, "fsck-repair.txt"), "w") as fp:
🤖 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 606 - 608, The fsck call
currently assigns the unused return code to rc which is never checked; change
the assignment to use the canonical underscore for unused values (e.g., replace
"rc, out = fsck(db, storage, repair=True)" with "_, out = fsck(db, storage,
repair=True)") so it signals intent to ignore the return code while keeping the
rest of the logic that writes out to the file using sdir and out intact.
🤖 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.

Outside diff comments:
In `@dev-scripts/test-cdc-lifecycle-auto.sh`:
- Around line 1-56: Add a direnv bootstrap block immediately after the shebang
and before any non-git commands (before REPO_ROOT assignment and any calls to
nix/run/python3) to satisfy the non-interactive shell guideline; implement the
suggested check-and-allow flow (run direnv status check, direnv allow ., unset
DIRENV_* vars, and eval direnv export bash) so the script boots direnv before it
executes REPO_ROOT=..., nix run .#deps, and the final python3
dev-scripts/test-cdc-lifecycle-e2e.py "$@" invocation.

In `@nix/k8s-tests/README.md`:
- Line 306: Update the expected count in the troubleshooting example comment
from "# Should output: 12" to "# Should output: 13" in the README entry that
documents the command output; this reflects the new permutation
"ha-s3-postgres-cdc-lifecycle" added by the PR so the example and comment are
consistent with the updated permutations.

---

Nitpick comments:
In `@dev-scripts/test-cdc-lifecycle-e2e.py`:
- Around line 606-608: The fsck call currently assigns the unused return code to
rc which is never checked; change the assignment to use the canonical underscore
for unused values (e.g., replace "rc, out = fsck(db, storage, repair=True)" with
"_, out = fsck(db, storage, repair=True)") so it signals intent to ignore the
return code while keeping the rest of the logic that writes out to the file
using sdir and out intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1653bb2c-baa0-4236-a3dd-11f250339672

📥 Commits

Reviewing files that changed from the base of the PR and between d510e49 and 25505a6.

📒 Files selected for processing (13)
  • Taskfile.yml
  • dev-scripts/test-cdc-lifecycle-auto.sh
  • dev-scripts/test-cdc-lifecycle-e2e.py
  • nix/k8s-tests/README.md
  • nix/k8s-tests/config.nix
  • nix/k8s-tests/src/k8s_tests.py
  • nix/k8s-tests/src/k8s_tests_tester.py
  • openspec/changes/cdc-lifecycle-e2e-tests/.openspec.yaml
  • openspec/changes/cdc-lifecycle-e2e-tests/design.md
  • openspec/changes/cdc-lifecycle-e2e-tests/proposal.md
  • openspec/changes/cdc-lifecycle-e2e-tests/specs/cdc-lifecycle-e2e/spec.md
  • openspec/changes/cdc-lifecycle-e2e-tests/specs/cdc-lifecycle-k8s-test/spec.md
  • openspec/changes/cdc-lifecycle-e2e-tests/tasks.md

@kalbasit
kalbasit force-pushed the user/wnasreddine/integration-tests branch from 25505a6 to 217caae Compare June 7, 2026 06:33

@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: 5

🤖 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-cdc-lifecycle-auto.sh`:
- Around line 17-35: Add the direnv bootstrap check near the top of the script
(after the REPO_ROOT cd and before any non-git commands like nix or python are
run); specifically insert the provided direnv guard: run `direnv status | grep
-q "Found RC allowed 0" || direnv allow . && unset DIRENV_DIR DIRENV_FILE
DIRENV_WATCHES DIRENV_DIFF && eval "$(direnv export bash)"` so the environment
is allowed and exported before the script uses `nix run` or `process-compose`
(affects the global scope of this script where PC_PORT, cleanup(), trap, and
subsequent nix/process-compose calls execute).

In `@dev-scripts/test-cdc-lifecycle-e2e.py`:
- Around line 606-610: The fsck exit code (rc) returned by fsck(db, storage,
repair=True) is currently ignored so failures don't fail the phase; update the
post-fsck handling to check rc and fail the test when rc != 0 by raising an
exception or exiting non-zero (e.g., assert or sys.exit) before
writing/continuing to after/total_nar_count and the log; reference the rc
variable and the fsck(db, storage, repair=True) call so the check happens
immediately after that call and before subsequent steps that assume success.

In `@nix/k8s-tests/src/k8s_tests_tester.py`:
- Around line 1348-1385: The _serve_check function currently only tests
test_hashes[0], which may not be a chunked NAR; update _serve_check (and its
callers in Phase B) to accept or select a proven chunked hash instead of always
using test_hashes[0]: either add a parameter like chunked_hash to _serve_check
and pass the chunked hash captured in Phase A (or stored on the tester object),
or have _serve_check query the test_data (e.g., a new "chunked_narinfo_hash" or
"chunked_hash" key) and use that value when present; ensure the code paths that
call _serve_check in Phase B pass the chunked hash so the port-forward GETs
validate an actually chunked NAR.
- Around line 1328-1346: The subprocess.run call invoking kubectl in the code
block (the call that assigns to result) doesn't enforce failure on non-zero
exit; change it to ensure the test fails when the command fails by either adding
check=True to the subprocess.run invocation or immediately checking
result.returncode and raising an exception (include result.stdout and
result.stderr in the exception message) so the function (the block that runs
"/bin/ncps migrate-chunks-to-nar") fails fast on non-zero return codes.

In `@openspec/changes/cdc-lifecycle-e2e-tests/tasks.md`:
- Line 51: The status line for "7.4 Archive before merge" incorrectly states
tasks 6.2/6.3 are unimplemented while the checklist shows them implemented;
reconcile these by updating the status text to match the checklist: if 6.2 and
6.3 are implemented, change "unimplemented (6.2/6.3)" to "implemented
(6.2/6.3)"; if they are actually unimplemented, revert the checklist marks for
6.2/6.3 to not-implemented so the archive note is accurate. Ensure you edit the
"7.4 Archive before merge" note and the corresponding checklist entries (tasks
6.2 and 6.3) so both reflect the same implementation state.
🪄 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: 8e502480-4eef-410e-9db1-3beef3230966

📥 Commits

Reviewing files that changed from the base of the PR and between 25505a6 and 217caae.

📒 Files selected for processing (13)
  • Taskfile.yml
  • dev-scripts/test-cdc-lifecycle-auto.sh
  • dev-scripts/test-cdc-lifecycle-e2e.py
  • nix/k8s-tests/README.md
  • nix/k8s-tests/config.nix
  • nix/k8s-tests/src/k8s_tests.py
  • nix/k8s-tests/src/k8s_tests_tester.py
  • openspec/changes/cdc-lifecycle-e2e-tests/.openspec.yaml
  • openspec/changes/cdc-lifecycle-e2e-tests/design.md
  • openspec/changes/cdc-lifecycle-e2e-tests/proposal.md
  • openspec/changes/cdc-lifecycle-e2e-tests/specs/cdc-lifecycle-e2e/spec.md
  • openspec/changes/cdc-lifecycle-e2e-tests/specs/cdc-lifecycle-k8s-test/spec.md
  • openspec/changes/cdc-lifecycle-e2e-tests/tasks.md
✅ Files skipped from review due to trivial changes (4)
  • openspec/changes/cdc-lifecycle-e2e-tests/.openspec.yaml
  • openspec/changes/cdc-lifecycle-e2e-tests/design.md
  • openspec/changes/cdc-lifecycle-e2e-tests/proposal.md
  • nix/k8s-tests/README.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • Taskfile.yml
  • nix/k8s-tests/src/k8s_tests.py
  • nix/k8s-tests/config.nix

Comment thread dev-scripts/test-cdc-lifecycle-auto.sh Resolved
Comment thread dev-scripts/test-cdc-lifecycle-e2e.py Resolved
Comment thread nix/k8s-tests/src/k8s_tests_tester.py Resolved
Comment thread nix/k8s-tests/src/k8s_tests_tester.py Resolved
@kalbasit
kalbasit force-pushed the user/wnasreddine/integration-tests branch from 217caae to 021b8f6 Compare June 7, 2026 06:56

@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: 7

🧹 Nitpick comments (1)
nix/k8s-tests/src/k8s_tests_tester.py (1)

1283-1313: ⚡ Quick win

Preserve kubectl rollout output on restart failures.

If Line 1287 or Line 1299 fails, _test_cdc_lifecycle() only surfaces a generic Lifecycle error: ..., so the rollout reason is lost. Catch CalledProcessError here and include the captured stdout/stderr in the returned TestResult.

Suggested change
     def _rollout_restart_and_wait(self, deployment_config: dict) -> TestResult:
         """Restart the ncps Deployment and wait for pods to be ready again."""
         name = deployment_config["name"]
         namespace = deployment_config["namespace"]
-        subprocess.run(
-            [
-                "kubectl",
-                "rollout",
-                "restart",
-                f"deployment/ncps-{name}",
-                "-n",
-                namespace,
-            ],
-            check=True,
-            capture_output=True,
-        )
-        subprocess.run(
-            [
-                "kubectl",
-                "rollout",
-                "status",
-                f"deployment/ncps-{name}",
-                "-n",
-                namespace,
-                "--timeout=180s",
-            ],
-            check=True,
-            capture_output=True,
-        )
+        try:
+            subprocess.run(
+                [
+                    "kubectl",
+                    "rollout",
+                    "restart",
+                    f"deployment/ncps-{name}",
+                    "-n",
+                    namespace,
+                ],
+                check=True,
+                capture_output=True,
+                text=True,
+            )
+            subprocess.run(
+                [
+                    "kubectl",
+                    "rollout",
+                    "status",
+                    f"deployment/ncps-{name}",
+                    "-n",
+                    namespace,
+                    "--timeout=180s",
+                ],
+                check=True,
+                capture_output=True,
+                text=True,
+            )
+        except subprocess.CalledProcessError as e:
+            output = (e.stdout or "") + (e.stderr or "")
+            return TestResult(
+                "Pods",
+                False,
+                f"kubectl rollout failed for ncps-{name}",
+                details=output.strip(),
+            )
         # Reuse the pod-readiness gate so subsequent checks see ready pods.
         return self._test_pods(deployment_config)
🤖 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 `@nix/k8s-tests/src/k8s_tests_tester.py` around lines 1283 - 1313, In
_rollout_restart_and_wait, wrap the two subprocess.run calls that perform
"kubectl rollout restart" and "kubectl rollout status" in a try/except that
catches subprocess.CalledProcessError and returns a TestResult containing a
clear lifecycle error message plus the captured stdout and stderr from the
exception (use e.stdout/e.stderr) so the kubectl failure reason is preserved; on
success continue to call and return self._test_pods(deployment_config) as
before.
🤖 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-cdc-lifecycle-e2e.py`:
- Around line 483-486: The test currently only asserts NAR presence and length
(using fetch_nar_bytes, check(len(nar) > 0, and state["baseline_nar_len"]) which
misses content corruption; compute a strong digest (e.g. SHA-256) of the
returned bytes from fetch_nar_bytes, store it in state (e.g.
state["baseline_nar_digest"]) and thereafter replace/augment length-based checks
with exact digest equality checks after each phase
(eager/lazy/drain/restart/fsck) where fetch_nar_bytes is called; update the
other occurrences that currently store or compare len(nar) to instead compute
and compare the digest (use the same digest key names for each phase like
baseline_nar_digest, eager_nar_digest, lazy_nar_digest, etc.) and keep the
existing chunked_nar_count checks unchanged.
- Around line 376-385: The migrate_chunks_to_nar function currently swallows
non-zero exits for dry-run mode; change its error handling so any non-zero
return code from run_cli("migrate-chunks-to-nar", ...) raises a RuntimeError
(include rc and out) even when dry_run is True so phase_drain() will fail on a
broken --dry-run path; update the conditional around rc != 0 (and the error
text) in migrate_chunks_to_nar to always raise on failure and keep returning out
otherwise.
- Around line 668-672: The cleanup block currently swallows all exceptions from
stop_ncps(state.get("srv"), state.get("f")); change it to catch Exception as e,
log the exception (include context like which srv/f failed) and fold the error
into result["error"] (create result["error"] if missing, e.g. append or
concatenate a short message and the exception string) so failures during cleanup
are visible to logs and the overall test result; update the finally block around
stop_ncps to perform these steps and preserve the original exception flow if
needed.

In `@nix/k8s-tests/src/k8s_tests_tester.py`:
- Around line 178-190: The CDC topology checks are incorrectly nested inside the
cdc_lifecycle guard; move the block that calls
_test_cdc_topology(deployment_config), appends topology_result to results, and
calls _print_test_result(topology_result) so it executes unconditionally (after
the lifecycle block), leaving the existing
_test_cdc_lifecycle(deployment_config) call and its result handling intact;
_test_cdc_topology already self-skips for single-replica/no-data cases, so this
change ensures eligible deployments exercise the phantom/cross-replica
assertions.
- Around line 1588-1628: The current _test_cdc_topology() uses test_hashes[0]
and treats states == {None} as success, which lets the topology test pass when
every replica reports the hash missing; change the logic in _test_cdc_topology()
so that a uniform "None" set is treated as failure (return a failing TestResult)
OR revalidate the object via the Service before declaring success: call the
existing HTTP recheck path (reuse _test_http_endpoints() or a dedicated service
GET) for the same test_hashes[0]; if the service confirms absence, still fail
the CDC topology test, otherwise proceed with the existing presence-agreement
checks. Ensure you update the branch that currently returns success for states
== {None} to instead either perform the revalidation or return a failure and
reference symbols _test_cdc_topology, _test_http_endpoints, _pod_presence_ok,
test_hashes, and TestResult.

In
`@openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/specs/cdc-lifecycle-e2e/spec.md`:
- Around line 9-10: The WHEN line references the wrong entrypoint (task
test:deps:start); update the harness invocation to the actual lifecycle driver
by replacing any mention of task test:deps:start with the fixed-port wrapper
entrypoint task test:cdc-lifecycle (and/or nix run .#deps) so the scenario
describes invoking the e2e driver via task test:cdc-lifecycle (or nix run
.#deps), and verify any other occurrences in this spec (e.g., the lifecycle
entrypoint wording) are updated to match that actual wiring to avoid a
non-reproducible run path.

In `@openspec/specs/cdc-lifecycle-e2e/spec.md`:
- Around line 15-16: The spec's canonical scenario references the wrong task
entrypoint; update the WHEN/THEN lines to use the implemented fixed-port driver
entrypoint (replace references to "task test:deps:start" with "task
test:cdc-lifecycle") and ensure the requirement phrase about "ensure that each
instruction is followed for each code segment you review" remains verbatim and
consistent with the implemented task wiring (check the task name used by the
lifecycle flow and any surrounding text mentioning the wrapper/fixed-port deps
to match "task test:cdc-lifecycle").

---

Nitpick comments:
In `@nix/k8s-tests/src/k8s_tests_tester.py`:
- Around line 1283-1313: In _rollout_restart_and_wait, wrap the two
subprocess.run calls that perform "kubectl rollout restart" and "kubectl rollout
status" in a try/except that catches subprocess.CalledProcessError and returns a
TestResult containing a clear lifecycle error message plus the captured stdout
and stderr from the exception (use e.stdout/e.stderr) so the kubectl failure
reason is preserved; on success continue to call and return
self._test_pods(deployment_config) as before.
🪄 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: a0c17d0c-d0d8-4759-a733-7147bee4ea6e

📥 Commits

Reviewing files that changed from the base of the PR and between 217caae and 021b8f6.

📒 Files selected for processing (15)
  • Taskfile.yml
  • dev-scripts/test-cdc-lifecycle-auto.sh
  • dev-scripts/test-cdc-lifecycle-e2e.py
  • nix/k8s-tests/README.md
  • nix/k8s-tests/config.nix
  • nix/k8s-tests/src/k8s_tests.py
  • nix/k8s-tests/src/k8s_tests_tester.py
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/.openspec.yaml
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/design.md
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/proposal.md
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/specs/cdc-lifecycle-e2e/spec.md
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/specs/cdc-lifecycle-k8s-test/spec.md
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/tasks.md
  • openspec/specs/cdc-lifecycle-e2e/spec.md
  • openspec/specs/cdc-lifecycle-k8s-test/spec.md
✅ Files skipped from review due to trivial changes (2)
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/.openspec.yaml
  • nix/k8s-tests/README.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • dev-scripts/test-cdc-lifecycle-auto.sh
  • Taskfile.yml
  • nix/k8s-tests/src/k8s_tests.py
  • nix/k8s-tests/config.nix

Comment thread dev-scripts/test-cdc-lifecycle-e2e.py Resolved
Comment thread dev-scripts/test-cdc-lifecycle-e2e.py Resolved
Comment thread dev-scripts/test-cdc-lifecycle-e2e.py Resolved
Comment thread nix/k8s-tests/src/k8s_tests_tester.py Resolved
Comment thread nix/k8s-tests/src/k8s_tests_tester.py Resolved
@kalbasit
kalbasit force-pushed the user/wnasreddine/fix-docker-etc-passwd branch from d510e49 to 3d06e81 Compare June 7, 2026 14:32
kalbasit added a commit that referenced this pull request Jun 7, 2026
Address PR #1348 review (gemini-code-assist, coderabbitai):
- e2e driver: use start_new_session=True instead of preexec_fn=os.setsid;
  fail the cross-cutting phase when 'fsck --repair' exits non-zero.
- auto.sh: bootstrap direnv before nix/python (env-execution rule) so it
  works standalone, not only under 'task'.
- k8s tester: guard ConfigMap data before reading config.yaml; raise when the
  in-pod migrate-chunks-to-nar exec returns non-zero; drive Phase B's
  drain-mode serve check with a DB-proven chunked narinfo hash instead of an
  arbitrary test hash.

Threads: PRRT_kwDONV6tZs6Hofcm, PRRT_kwDONV6tZs6Hofco, PRRT_kwDONV6tZs6Hofcp,
PRRT_kwDONV6tZs6HohVZ, PRRT_kwDONV6tZs6HohVa, PRRT_kwDONV6tZs6HohVb,
PRRT_kwDONV6tZs6HohVc

Co-Authored-By: Claude Opus 4.8 <[email protected]>
kalbasit added a commit that referenced this pull request Jun 7, 2026
Address PR #1348 re-review (coderabbitai):
- e2e driver: fail on non-zero migrate-chunks-to-nar --dry-run exit; assert
  NAR content identity via sha256 of decompressed bytes (catches same-size
  corruption) across lazy/drain/restart/fsck rereads; surface cleanup
  stop_ncps() failures into result instead of swallowing them.
- k8s tester: run multi-replica topology checks for every deployment (not
  only cdc-lifecycle) since _test_cdc_topology self-skips ineligible ones;
  treat 'NAR absent on all replicas' as a failure (it was served earlier).
- specs: point the harness-invocation scenario at the fixed-port
  'task test:cdc-lifecycle' entrypoint instead of the random-port
  'task test:deps:start'.

Threads: PRRT_kwDONV6tZs6HooDa, PRRT_kwDONV6tZs6HooDb, PRRT_kwDONV6tZs6HooDc,
PRRT_kwDONV6tZs6HooDe, PRRT_kwDONV6tZs6HooDf, PRRT_kwDONV6tZs6HooDg,
PRRT_kwDONV6tZs6HooDi

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@kalbasit
kalbasit force-pushed the user/wnasreddine/integration-tests branch from 021b8f6 to 7e1f709 Compare June 7, 2026 14:33
@kalbasit
kalbasit force-pushed the user/wnasreddine/fix-docker-etc-passwd branch from 3d06e81 to f61201e Compare June 7, 2026 14:39
kalbasit added a commit that referenced this pull request Jun 7, 2026
Address PR #1348 review (gemini-code-assist, coderabbitai):
- e2e driver: use start_new_session=True instead of preexec_fn=os.setsid;
  fail the cross-cutting phase when 'fsck --repair' exits non-zero.
- auto.sh: bootstrap direnv before nix/python (env-execution rule) so it
  works standalone, not only under 'task'.
- k8s tester: guard ConfigMap data before reading config.yaml; raise when the
  in-pod migrate-chunks-to-nar exec returns non-zero; drive Phase B's
  drain-mode serve check with a DB-proven chunked narinfo hash instead of an
  arbitrary test hash.

Threads: PRRT_kwDONV6tZs6Hofcm, PRRT_kwDONV6tZs6Hofco, PRRT_kwDONV6tZs6Hofcp,
PRRT_kwDONV6tZs6HohVZ, PRRT_kwDONV6tZs6HohVa, PRRT_kwDONV6tZs6HohVb,
PRRT_kwDONV6tZs6HohVc

Co-Authored-By: Claude Opus 4.8 <[email protected]>
kalbasit added a commit that referenced this pull request Jun 7, 2026
Address PR #1348 re-review (coderabbitai):
- e2e driver: fail on non-zero migrate-chunks-to-nar --dry-run exit; assert
  NAR content identity via sha256 of decompressed bytes (catches same-size
  corruption) across lazy/drain/restart/fsck rereads; surface cleanup
  stop_ncps() failures into result instead of swallowing them.
- k8s tester: run multi-replica topology checks for every deployment (not
  only cdc-lifecycle) since _test_cdc_topology self-skips ineligible ones;
  treat 'NAR absent on all replicas' as a failure (it was served earlier).
- specs: point the harness-invocation scenario at the fixed-port
  'task test:cdc-lifecycle' entrypoint instead of the random-port
  'task test:deps:start'.

Threads: PRRT_kwDONV6tZs6HooDa, PRRT_kwDONV6tZs6HooDb, PRRT_kwDONV6tZs6HooDc,
PRRT_kwDONV6tZs6HooDe, PRRT_kwDONV6tZs6HooDf, PRRT_kwDONV6tZs6HooDg,
PRRT_kwDONV6tZs6HooDi

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@kalbasit
kalbasit force-pushed the user/wnasreddine/integration-tests branch from 7e1f709 to 69fc398 Compare June 7, 2026 14:39

@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: 3

♻️ Duplicate comments (1)
nix/k8s-tests/src/k8s_tests_tester.py (1)

1377-1391: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fail Phase B when no chunk-backed narinfo can be identified.

If _chunked_narinfo_hash() returns None, _serve_check() falls back to test_hashes[0], so the drain-mode check can still pass without ever exercising a chunk-backed NAR. That reintroduces a false-green on the core lifecycle assertion.

Suggested fix
             chunked_hash = self._chunked_narinfo_hash(deployment_config)
+            if not chunked_hash:
+                return TestResult(
+                    "CDC Lifecycle",
+                    False,
+                    "Phase A: could not identify a chunk-backed narinfo for drain-mode validation",
+                )
             details.append(
                 f"Phase A: {chunks[0]} chunks, cdc_enabled present"
                 + (f", chunked narinfo {chunked_hash}" if chunked_hash else "")
             )

Also applies to: 1467-1486

🤖 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 `@nix/k8s-tests/src/k8s_tests_tester.py` around lines 1377 - 1391, The
drain-mode serve check currently falls back to test_hashes[0] when no
chunk-backed narinfo is found, allowing a false-positive; update _serve_check to
call self._chunked_narinfo_hash(deployment_config) when narinfo_hash is None
and, if that helper returns None, return False (fail Phase B) instead of using
test_hashes[0]; apply the same change to the other occurrence around the
1467-1486 block so both code paths require a chunk-backed narinfo and only use
test_hashes as a secondary non-drain fallback.
🧹 Nitpick comments (1)
dev-scripts/test-cdc-lifecycle-e2e.py (1)

500-519: ⚡ Quick win

Deduplicate Phase 0 before the state contract drifts further.

phase_baseline() and the inline baseline block in run_lifecycle() already disagree on what Phase 0 records: this helper still writes baseline_nar_len, while later phases consume baseline_digest. If someone reuses phase_baseline() later, Phase 2 will fail on state["baseline_digest"]. Please route Phase 0 through one implementation or delete the stale helper.

Also applies to: 693-704

🤖 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 500 - 519,
phase_baseline() is out of sync with run_lifecycle(): it writes
state["baseline_nar_len"] while later phases expect state["baseline_digest"],
causing Phase 2 to fail; update phase_baseline (the phase_baseline function) to
populate state["baseline_digest"] (e.g., set state["baseline_digest"] = h or
compute the digest from the fetched nar) and remove or stop relying on
state["baseline_nar_len"], or alternatively delete the stale helper and funnel
Phase 0 through the single implementation used in run_lifecycle so both places
use the same state key.
🤖 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-cdc-lifecycle-e2e.py`:
- Around line 632-642: The presence sweep currently iterates only over
("baseline","baseline_hash") and ("eager","eager_hash") and omits the lazy
upload recorded by phase_cdc_lazy() in state["lazy_hash"]; update the loop in
dev-scripts/test-cdc-lifecycle-e2e.py to include the lazy pair (e.g.
("lazy","lazy_hash")) so the same fetch_narinfo -> parse_narinfo ->
http_head/http_get checks run for the lazy NAR as well, ensuring
head_status/get_status and body length assertions are applied to
state["lazy_hash"] just like baseline_hash and eager_hash.
- Around line 605-614: The test currently reads the boot log once after
restart() and may race with startup writes; change the assertion to poll the
log_path for the drain-completion text within a short timeout (e.g., loop for a
few seconds with small sleep intervals), reopening/reading the file each
iteration and breaking when "drain" (case-insensitive) is found, then call
check(...) only after the loop to fail if the message never appears; update the
section around restart(...), log_path and the final check to use this polling
logic so the test reliably waits for drain completion.

In `@nix/k8s-tests/src/k8s_tests_tester.py`:
- Around line 1421-1422: The broad "except Exception: return False" blocks at
the shown try/except sites must not swallow transport/port-forward/request setup
errors; change them to either catch only expected semantic-validation exceptions
or remove the except entirely so the exception bubbles up (or log and re-raise).
Specifically, update the try/except around the port-forward/request setup (the
two blocks at the locations shown) to avoid returning False on generic
Exception—use specific exception types (e.g., subprocess.CalledProcessError,
requests.exceptions.RequestException) if you need to handle transport errors,
otherwise re-raise the exception so the failing TestResult reflects the real
infrastructure error.

---

Duplicate comments:
In `@nix/k8s-tests/src/k8s_tests_tester.py`:
- Around line 1377-1391: The drain-mode serve check currently falls back to
test_hashes[0] when no chunk-backed narinfo is found, allowing a false-positive;
update _serve_check to call self._chunked_narinfo_hash(deployment_config) when
narinfo_hash is None and, if that helper returns None, return False (fail Phase
B) instead of using test_hashes[0]; apply the same change to the other
occurrence around the 1467-1486 block so both code paths require a chunk-backed
narinfo and only use test_hashes as a secondary non-drain fallback.

---

Nitpick comments:
In `@dev-scripts/test-cdc-lifecycle-e2e.py`:
- Around line 500-519: phase_baseline() is out of sync with run_lifecycle(): it
writes state["baseline_nar_len"] while later phases expect
state["baseline_digest"], causing Phase 2 to fail; update phase_baseline (the
phase_baseline function) to populate state["baseline_digest"] (e.g., set
state["baseline_digest"] = h or compute the digest from the fetched nar) and
remove or stop relying on state["baseline_nar_len"], or alternatively delete the
stale helper and funnel Phase 0 through the single implementation used in
run_lifecycle so both places use the same state key.
🪄 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: ab3552e2-b1ff-4bc0-bcbf-e9a7642af845

📥 Commits

Reviewing files that changed from the base of the PR and between 021b8f6 and 7e1f709.

📒 Files selected for processing (15)
  • Taskfile.yml
  • dev-scripts/test-cdc-lifecycle-auto.sh
  • dev-scripts/test-cdc-lifecycle-e2e.py
  • nix/k8s-tests/README.md
  • nix/k8s-tests/config.nix
  • nix/k8s-tests/src/k8s_tests.py
  • nix/k8s-tests/src/k8s_tests_tester.py
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/.openspec.yaml
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/design.md
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/proposal.md
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/specs/cdc-lifecycle-e2e/spec.md
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/specs/cdc-lifecycle-k8s-test/spec.md
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/tasks.md
  • openspec/specs/cdc-lifecycle-e2e/spec.md
  • openspec/specs/cdc-lifecycle-k8s-test/spec.md
✅ Files skipped from review due to trivial changes (4)
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/design.md
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/proposal.md
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/.openspec.yaml
  • nix/k8s-tests/README.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • Taskfile.yml
  • nix/k8s-tests/config.nix
  • nix/k8s-tests/src/k8s_tests.py
  • dev-scripts/test-cdc-lifecycle-auto.sh

Comment thread dev-scripts/test-cdc-lifecycle-e2e.py Resolved
Comment thread dev-scripts/test-cdc-lifecycle-e2e.py Resolved
Comment thread nix/k8s-tests/src/k8s_tests_tester.py Resolved

@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

♻️ Duplicate comments (3)
nix/k8s-tests/src/k8s_tests_tester.py (3)

1470-1486: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fail Phase A if no narinfo-backed chunked hash can be found.

chunks > 0 is not enough here. When _chunked_narinfo_hash() returns None, _serve_check() silently falls back to test_hashes[0], so Phase B can pass without ever exercising drain-mode serving from a known-chunked NAR.

Suggested change
             chunked_hash = self._chunked_narinfo_hash(deployment_config)
+            if not chunked_hash:
+                return TestResult(
+                    "CDC Lifecycle",
+                    False,
+                    "Phase A: no narinfo-backed chunked NAR found; drain-mode serve check would not exercise chunked serving",
+                )
             details.append(
-                f"Phase A: {chunks[0]} chunks, cdc_enabled present"
-                + (f", chunked narinfo {chunked_hash}" if chunked_hash else "")
+                f"Phase A: {chunks[0]} chunks, cdc_enabled present, chunked narinfo {chunked_hash}"
             )
🤖 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 `@nix/k8s-tests/src/k8s_tests_tester.py` around lines 1470 - 1486, Phase A
currently records "chunks > 0" as success even when
_chunked_narinfo_hash(deployment_config) returns None, which allows Phase B to
pass using a fallback hash; change the Phase A logic in the block using
_chunked_narinfo_hash, chunks and deployment_config so that if chunks > 0 but
chunked_hash is falsy you immediately return a failing TestResult for "CDC
Lifecycle" with a clear message ("Phase A: no narinfo-backed chunked hash
found") instead of proceeding; this ensures _serve_check(deployment_config,
chunked_hash) always gets a real chunked hash when chunks were detected.

190-193: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Keep topology behind a proven service baseline.

_test_cdc_topology() now treats {None} as a real regression because test_hashes[0] was “served earlier via the Service”, but this call still happens even when _test_http_endpoints() already failed. That turns an existing service/storage outage into a second, misleading topology failure. Either skip topology when that service precondition was not met, or revalidate the hash through the Service inside _test_cdc_topology() before using the all-absent branch.

🤖 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 `@nix/k8s-tests/src/k8s_tests_tester.py` around lines 190 - 193, The topology
test is being run even when the Service baseline may have failed, causing a
misleading second failure; update the call site or the _test_cdc_topology
implementation to guard against that: either (A) at the call site, only invoke
_test_cdc_topology(deployment_config) if the HTTP/service baseline from
_test_http_endpoints() succeeded, or (B) inside _test_cdc_topology(), revalidate
the served hash via the Service (e.g., attempt to read test_hashes[0] through
the Service endpoint) before treating {None} as a real regression and fallback
to the "all-absent" branch; pick one approach and implement the corresponding
conditional check so topology is only evaluated when the service baseline is
confirmed.

1421-1422: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Don’t collapse setup errors into semantic CDC failures.

These except Exception: return False blocks turn port-forward startup failures, kubectl errors, and request setup problems into plain “did not serve” / “phantom presence” results. Let unexpected transport errors bubble so the outer TestResult reports the real infrastructure failure.

Also applies to: 1598-1599

🤖 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 `@nix/k8s-tests/src/k8s_tests_tester.py` around lines 1421 - 1422, The broad
"except Exception: return False" swallows infrastructure/transport errors;
replace those catches (both occurrences) with either no catch (let exceptions
propagate) or narrow catches for only the expected semantic failure types (e.g.,
specific validation or timeout exceptions), and re-raise or log and re-raise
unexpected errors so kubectl/port-forward/subprocess/k8s client failures
surface. Locate the two occurrences of "except Exception: return False" in
k8s_tests_tester.py and change them to either remove the handler or to catch
targeted exceptions (for example requests.exceptions.RequestException,
subprocess.CalledProcessError, kubernetes.client.exceptions.ApiException) and
only return False for the truly expected CDC/semantic failure cases while
allowing other exceptions to bubble up.

Source: Linters/SAST tools

🧹 Nitpick comments (1)
dev-scripts/test-cdc-lifecycle-e2e.py (1)

500-519: ⚡ Quick win

Collapse the duplicated Phase 0 setup into one code path.

phase_baseline() and the inline baseline block in run_lifecycle() have already drifted: the helper stores baseline_nar_len, while later phases consume baseline_digest. Keeping both copies makes the baseline assertions easy to update in only one place.

Also applies to: 685-705

🤖 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 500 - 519, Duplicate
baseline setup exists between phase_baseline() and an inline block in
run_lifecycle(); consolidate them by making phase_baseline() the single source
of truth: have phase_baseline() compute and store both the baseline hash/digest
(state["baseline_digest"] or update existing state["baseline_hash"]) and the
baseline NAR length (state["baseline_nar_len"]), and ensure it performs the same
checks currently duplicated (cdc keys, narinfo fetch, nar length,
chunked_nar_count). Then remove the inline baseline code in run_lifecycle() and
replace it with a call to phase_baseline(state, db, storage, sdir), updating any
later phases to read state["baseline_digest"] (or the chosen consistent key)
instead of the old duplicated value so there is one canonical baseline value and
assertions only live in phase_baseline().
🤖 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-cdc-lifecycle-e2e.py`:
- Around line 627-669: The test never actually deletes a narinfo to exercise the
"non-destructive purge" invariant; add a step that removes one of the two
references to a shared NAR (e.g. call the existing deletion helper for the
"eager" narinfo using state["eager_hash"] or a suitable
delete_narinfo()/remove_narinfo() function), then assert the deleted narinfo is
gone (fetch_narinfo(state["eager_hash"]) is None or appropriate 404) while the
surviving reference (fetch_narinfo(state["baseline_hash"]), http_head/http_get
on the NAR path, and served_nar_digest(parse_narinfo(...))) still serves the
bytes and matches state["baseline_digest"]; run fsck/repair again if necessary
and re-check the surviving NAR content unchanged.

---

Duplicate comments:
In `@nix/k8s-tests/src/k8s_tests_tester.py`:
- Around line 1470-1486: Phase A currently records "chunks > 0" as success even
when _chunked_narinfo_hash(deployment_config) returns None, which allows Phase B
to pass using a fallback hash; change the Phase A logic in the block using
_chunked_narinfo_hash, chunks and deployment_config so that if chunks > 0 but
chunked_hash is falsy you immediately return a failing TestResult for "CDC
Lifecycle" with a clear message ("Phase A: no narinfo-backed chunked hash
found") instead of proceeding; this ensures _serve_check(deployment_config,
chunked_hash) always gets a real chunked hash when chunks were detected.
- Around line 190-193: The topology test is being run even when the Service
baseline may have failed, causing a misleading second failure; update the call
site or the _test_cdc_topology implementation to guard against that: either (A)
at the call site, only invoke _test_cdc_topology(deployment_config) if the
HTTP/service baseline from _test_http_endpoints() succeeded, or (B) inside
_test_cdc_topology(), revalidate the served hash via the Service (e.g., attempt
to read test_hashes[0] through the Service endpoint) before treating {None} as a
real regression and fallback to the "all-absent" branch; pick one approach and
implement the corresponding conditional check so topology is only evaluated when
the service baseline is confirmed.
- Around line 1421-1422: The broad "except Exception: return False" swallows
infrastructure/transport errors; replace those catches (both occurrences) with
either no catch (let exceptions propagate) or narrow catches for only the
expected semantic failure types (e.g., specific validation or timeout
exceptions), and re-raise or log and re-raise unexpected errors so
kubectl/port-forward/subprocess/k8s client failures surface. Locate the two
occurrences of "except Exception: return False" in k8s_tests_tester.py and
change them to either remove the handler or to catch targeted exceptions (for
example requests.exceptions.RequestException, subprocess.CalledProcessError,
kubernetes.client.exceptions.ApiException) and only return False for the truly
expected CDC/semantic failure cases while allowing other exceptions to bubble
up.

---

Nitpick comments:
In `@dev-scripts/test-cdc-lifecycle-e2e.py`:
- Around line 500-519: Duplicate baseline setup exists between phase_baseline()
and an inline block in run_lifecycle(); consolidate them by making
phase_baseline() the single source of truth: have phase_baseline() compute and
store both the baseline hash/digest (state["baseline_digest"] or update existing
state["baseline_hash"]) and the baseline NAR length (state["baseline_nar_len"]),
and ensure it performs the same checks currently duplicated (cdc keys, narinfo
fetch, nar length, chunked_nar_count). Then remove the inline baseline code in
run_lifecycle() and replace it with a call to phase_baseline(state, db, storage,
sdir), updating any later phases to read state["baseline_digest"] (or the chosen
consistent key) instead of the old duplicated value so there is one canonical
baseline value and assertions only live in phase_baseline().
🪄 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: 5eb9118a-6c2d-4fcd-9a46-922bd8377f23

📥 Commits

Reviewing files that changed from the base of the PR and between 7e1f709 and 69fc398.

📒 Files selected for processing (15)
  • Taskfile.yml
  • dev-scripts/test-cdc-lifecycle-auto.sh
  • dev-scripts/test-cdc-lifecycle-e2e.py
  • nix/k8s-tests/README.md
  • nix/k8s-tests/config.nix
  • nix/k8s-tests/src/k8s_tests.py
  • nix/k8s-tests/src/k8s_tests_tester.py
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/.openspec.yaml
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/design.md
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/proposal.md
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/specs/cdc-lifecycle-e2e/spec.md
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/specs/cdc-lifecycle-k8s-test/spec.md
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/tasks.md
  • openspec/specs/cdc-lifecycle-e2e/spec.md
  • openspec/specs/cdc-lifecycle-k8s-test/spec.md
✅ Files skipped from review due to trivial changes (4)
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/.openspec.yaml
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/proposal.md
  • openspec/changes/archive/2026-06-06-cdc-lifecycle-e2e-tests/design.md
  • nix/k8s-tests/README.md
🚧 Files skipped from review as they are similar to previous changes (4)
  • Taskfile.yml
  • nix/k8s-tests/src/k8s_tests.py
  • nix/k8s-tests/config.nix
  • dev-scripts/test-cdc-lifecycle-auto.sh

Comment thread dev-scripts/test-cdc-lifecycle-e2e.py Resolved
Comment thread dev-scripts/test-cdc-lifecycle-e2e.py Resolved
Base automatically changed from user/wnasreddine/fix-docker-etc-passwd to main June 7, 2026 15:01
kalbasit and others added 3 commits June 7, 2026 15:01
Add a successor to test-migration-e2e.py that exercises the full CDC
lifecycle, driven by restarting ncps with/without the CDC serve flags
(drain mode is decided at boot by initCDCDrainMode).

Local driver (dev-scripts/test-cdc-lifecycle-e2e.py + the auto wrapper
and 'task test:cdc-lifecycle'): brings up the fixed-port nix run .#deps
stack and asserts DB + serving invariants at each phase plus the
upload-presence and fsck-repair cross-cutting checks. Results land under
the already-gitignored .e2e-results/cdc/.

K8s topology (nix/k8s-tests): new ha-s3-postgres-cdc-lifecycle permutation
gated on a cdc-lifecycle marker feature, with _test_cdc_lifecycle driving
the same phases on a Kind cluster (ConfigMap CDC flip + rollout restart,
in-pod migrate-chunks-to-nar reusing the pod's --config).

Includes the OpenSpec change artifacts (proposal/specs/design/tasks).
Address PR #1348 review (gemini-code-assist, coderabbitai):
- e2e driver: use start_new_session=True instead of preexec_fn=os.setsid;
  fail the cross-cutting phase when 'fsck --repair' exits non-zero.
- auto.sh: bootstrap direnv before nix/python (env-execution rule) so it
  works standalone, not only under 'task'.
- k8s tester: guard ConfigMap data before reading config.yaml; raise when the
  in-pod migrate-chunks-to-nar exec returns non-zero; drive Phase B's
  drain-mode serve check with a DB-proven chunked narinfo hash instead of an
  arbitrary test hash.

Threads: PRRT_kwDONV6tZs6Hofcm, PRRT_kwDONV6tZs6Hofco, PRRT_kwDONV6tZs6Hofcp,
PRRT_kwDONV6tZs6HohVZ, PRRT_kwDONV6tZs6HohVa, PRRT_kwDONV6tZs6HohVb,
PRRT_kwDONV6tZs6HohVc

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Address PR #1348 re-review (coderabbitai):
- e2e driver: fail on non-zero migrate-chunks-to-nar --dry-run exit; assert
  NAR content identity via sha256 of decompressed bytes (catches same-size
  corruption) across lazy/drain/restart/fsck rereads; surface cleanup
  stop_ncps() failures into result instead of swallowing them.
- k8s tester: run multi-replica topology checks for every deployment (not
  only cdc-lifecycle) since _test_cdc_topology self-skips ineligible ones;
  treat 'NAR absent on all replicas' as a failure (it was served earlier).
- specs: point the harness-invocation scenario at the fixed-port
  'task test:cdc-lifecycle' entrypoint instead of the random-port
  'task test:deps:start'.

Threads: PRRT_kwDONV6tZs6HooDa, PRRT_kwDONV6tZs6HooDb, PRRT_kwDONV6tZs6HooDc,
PRRT_kwDONV6tZs6HooDe, PRRT_kwDONV6tZs6HooDf, PRRT_kwDONV6tZs6HooDg,
PRRT_kwDONV6tZs6HooDi

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@kalbasit
kalbasit force-pushed the user/wnasreddine/integration-tests branch from 69fc398 to d0419e3 Compare June 7, 2026 15:01
@kalbasit
kalbasit enabled auto-merge (squash) June 7, 2026 15:01
Comment thread dev-scripts/test-cdc-lifecycle-e2e.py Dismissed
Comment thread dev-scripts/test-cdc-lifecycle-auto.sh Dismissed
Comment thread dev-scripts/test-cdc-lifecycle-auto.sh Dismissed
Comment thread dev-scripts/test-cdc-lifecycle-auto.sh Dismissed
Comment thread dev-scripts/test-cdc-lifecycle-auto.sh Dismissed
Comment thread dev-scripts/test-cdc-lifecycle-e2e.py Dismissed
Comment thread dev-scripts/test-cdc-lifecycle-e2e.py Dismissed
Comment thread nix/k8s-tests/src/k8s_tests_tester.py Dismissed
Comment thread nix/k8s-tests/src/k8s_tests_tester.py Dismissed
Comment thread nix/k8s-tests/src/k8s_tests_tester.py Dismissed
Comment thread dev-scripts/test-cdc-lifecycle-e2e.py Dismissed
Address PR #1348 re-review (coderabbitai) + code scanning:
- poll for the drain-completion log line instead of a single race-prone read
- include the lazy upload in the HEAD/GET presence sweep
- assert migrate-chunks-to-nar --dry-run actually reports drain candidates
- k8s tester: let port-forward/request transport errors propagate so the
  TestResult shows the real infra error, not a false 'did not serve'/'phantom'
- redact the S3 secret-access-key before logging the CLI command (CodeQL
  clear-text logging)
- docstring: state the non-destructive-purge invariant is unit-tested, not
  exercised here (real packages never share a NAR)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@kalbasit
kalbasit merged commit a163730 into main Jun 7, 2026
41 of 56 checks passed
@kalbasit
kalbasit deleted the user/wnasreddine/integration-tests branch June 7, 2026 15:17
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