Skip to content

Harden E2E seed loading for test_cases schema drift and add preflight seed integrity check - #312

Merged
bg-playground merged 4 commits into
mainfrom
copilot/bgstm-311-fix-e2e-test-failures
May 7, 2026
Merged

Harden E2E seed loading for test_cases schema drift and add preflight seed integrity check#312
bg-playground merged 4 commits into
mainfrom
copilot/bgstm-311-fix-e2e-test-failures

Conversation

Copilot AI commented May 7, 2026

Copy link
Copy Markdown
Contributor

E2E startup was seeding requirements but dropping seeded test cases/links when test_cases.auto_registered is present and non-nullable, causing deterministic Traceability Matrix failures (TC-004 missing, zeroed coverage). This PR aligns seed behavior with live schema and fails fast when seed integrity is incomplete.

  • Diagnostic findings

  • Seed compatibility + startup fail-fast

    • Updated seed.sql to:
      • enable ON_ERROR_STOP
      • seed external_id for TC-001..TC-005
      • conditionally include auto_registered=false when the column exists.
    • Updated backend seed execution (backend/entrypoint.sh) to run psql -v ON_ERROR_STOP=1 so partial seed failures stop container startup.
  • E2E smoke check (pre-test guardrail)

    • Added Playwright globalSetup (frontend/tests/e2e/global-setup.ts) and wired it in frontend/playwright.config.ts.
    • Preflight assertions:
      • requirements >= 5
      • test_cases >= 5
      • links >= 3
      • TC-001..TC-005 present by external_id
    • Throws explicit errors naming missing seed entities to prevent latent data issues from surfacing as downstream UI failures.
-- seed.sql (schema-aware test_case insert path)
IF EXISTS (
  SELECT 1
  FROM information_schema.columns
  WHERE table_schema = current_schema()
    AND table_name = 'test_cases'
    AND column_name = 'auto_registered'
) THEN
  INSERT INTO test_cases (..., external_id, ..., auto_registered, ...)
  VALUES (..., 'TC-004', ..., false, ...);
END IF;

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 127.0.0.11
    • Triggering command: REDACTED, pid is -1 (packet block)
  • dl.google.com
    • Triggering command: /usr/lib/apt/methods/https /usr/lib/apt/methods/https --process /tmp/runc-process3457108610 --detach --pid-file /run/containerd/io.containerd.runtime.v2.task/moby/08efd86bb6084c004dc18f20bcd8c26643dfdf24644c36ddda252b3e7c321a7e/8a4903d29032e6e0f7d9a7cbb56dbe15c4baa5d00ebc328013e361301a532f6e.pid 08efd86bb6084c004dc18f20bcd8c26643dfdf24644c36ddda252b3e7c321a7e sql/17/bin/psql /run/containerd/python 19e9ee20d3bb68af927c02fa91d4da420be/aabe5d2470e792854e99a86113d2f5b02d2a2cd9489b8677�� 732/log.json sql/17/bin/psql 732/�� y filter docker-buildx d73/config.json -i gko9qeip1ax docker-buildx (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Diagnostic + fix task for BGSTM#311

The E2E test environment is starting up with only requirements seeded — the 5 seeded test_cases (TC-001..TC-005) and their 3 requirement_test_case_links are missing from the database by the time the Traceability Matrix tests run. This causes frontend/tests/e2e/traceability.spec.ts:37 (seeded test case "TC-004" is visible in the matrix) to fail deterministically.

Full context, evidence, and three hypotheses are in BGSTM#311. Read that issue first — it has the failing-run screenshot evidence, the comparison table of observed vs. expected matrix metrics, and the diagnostic steps for each hypothesis.

Your job — diagnose, then fix

Step 1: Diagnose (don't skip)

Work through the three hypotheses in order and document what you find:

  1. Hypothesis 1 — Schema mismatch in frontend/tests/e2e/fixtures/seed.sql.

    • Run seed.sql against a freshly migrated test DB locally (use the same Postgres image/version the CI compose file uses).
    • Capture stdout AND stderr. Look for any INSERT INTO test_cases ... ERROR — column count mismatch, NOT NULL violation, missing column, type mismatch, FK violation, etc.
    • Compare the column list in the INSERT INTO test_cases (...) statement against the actual test_cases table schema (check the latest Alembic migration that defines/alters it).
    • Same comparison for requirement_test_case_links.
  2. Hypothesis 2 — backend/app/db/sample_data.py runs after seed.sql and overwrites/diverges.

    • Trace the test-environment startup sequence in docker-compose.test.yml (or whatever the E2E compose file is) and the backend container's entrypoint/start command.
    • Determine whether sample_data.py is invoked during E2E startup, and in what order relative to seed.sql loading.
    • If it runs, compare its TC-001..TC-00X UUIDs to those in seed.sqlON CONFLICT (id) DO NOTHING only protects against re-inserting matching IDs.
  3. Hypothesis 3 — A spec or fixture truncates test_cases.

    • git grep -n -E "TRUNCATE|DELETE FROM test_cases|truncate.*test_cases" frontend/ backend/
    • Check playwright.config.ts global setup, any beforeAll/globalSetup hooks, and backend test fixtures.

Document findings in the PR description as a "Diagnostic findings" section. State which hypothesis was confirmed (or describe the actual root cause if it turns out to be something else).

Step 2: Fix

Apply the minimal fix that addresses the confirmed root cause. Most likely candidates based on the evidence:

  • If Hyp 1: correct the seed.sql column list / values to match the live schema. Add external_id and any other required columns. Keep the existing TC-001..TC-005 IDs and titles intact so existing tests still find them.
  • If Hyp 2: disable sample_data.py for the E2E profile, or align its data with seed.sql's expected IDs.
  • If Hyp 3: remove the offending truncation, or move it to only run before the spec that needs an empty state (and have that spec re-seed afterwards).

Step 3: Add a fail-fast smoke check

Per #311's acceptance criteria, add a smoke check to the E2E setup that fails fast with a clear error if seed loading is incomplete. Suggested approach: a tiny pre-test script (or a globalSetup step in playwright.config.ts) that queries the API or DB after seed and asserts row counts:

- requirements >= 5
- test_cases >= 5 (and TC-001..TC-005 specifically present)
- requirement_test_case_links >= 3

If any assertion fails, throw with a clear message naming which seed entity is missing. This prevents future regressions from masquerading as flaky UI tests for hours of debugging.

Step 4: Verify

  • Re-run the full Playwright E2E suite locally — traceability.spec.ts:37 (TC-004) must pass on first attempt without retries.
  • Traceability Matrix page shows non-zero coverage and all 5 seeded TC-00X rows appear in either the Linked Test Cases column (for the linked ones) or the Orphan Test Cases section (for TC-003 and TC-005, which are unlinked per seed.sql).
  • CI passes on this PR's first attempt.

Constraints

Files likely involved

  • frontend/tests/e2e/fixtures/seed.sql — primary suspect
  • frontend/tests/e2e/playwright.config.ts (or equivalent) — for the new s...

This pull request was created from Copilot chat.

Copilot AI and others added 3 commits May 7, 2026 13:42
Copilot AI changed the title [WIP] Diagnose and fix E2E test environment issues Harden E2E seed loading for test_cases schema drift and add preflight seed integrity check May 7, 2026
Copilot AI requested a review from bg-playground May 7, 2026 13:49
@bg-playground
bg-playground marked this pull request as ready for review May 7, 2026 14:06
@bg-playground
bg-playground merged commit c9ba7d6 into main May 7, 2026
11 checks passed
@bg-playground
bg-playground deleted the copilot/bgstm-311-fix-e2e-test-failures branch May 7, 2026 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants