Skip to content

🐛 Isolate Playwright E2E DB and add live-target guardrails#53

Merged
ebigunso merged 7 commits intomainfrom
feat/e2e-db-isolation-guardrails
Feb 21, 2026
Merged

🐛 Isolate Playwright E2E DB and add live-target guardrails#53
ebigunso merged 7 commits intomainfrom
feat/e2e-db-isolation-guardrails

Conversation

@ebigunso
Copy link
Copy Markdown
Owner

@ebigunso ebigunso commented Feb 20, 2026

Summary

  • add Playwright global setup and teardown to launch a harness-managed local API for E2E
  • enforce local-only API targets by default and fail fast on unsafe targets
  • provision disposable isolated SQLite DB artifacts under .playwright-cli/e2e-db
  • add backend API bind env support via API_BIND_ADDR for harness orchestration
  • document safe E2E workflow and validation mapping updates
  • fix auth bootstrap timeout by setting login form fallback to method=post action=/api/login

Validation

  • npm run check
  • npm run test:unit
  • cargo test -p sleep-api
  • negative guard check with unsafe E2E_API_BASE_URL fails fast as expected
  • npm run test:e2e:auth (passes)

Copilot AI review requested due to automatic review settings February 20, 2026 22:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive E2E test isolation infrastructure to prevent accidental data corruption during Playwright test runs. The implementation introduces a harness-managed local API with disposable SQLite databases, enforces localhost-only API targets by default, and adds explicit safety guardrails that fail fast if unsafe targets are detected.

Changes:

  • Added Playwright global setup/teardown to spawn an isolated API process with a unique disposable DB for each E2E run
  • Implemented safety guardrails that block non-localhost API targets unless explicitly overridden with ALLOW_NON_ISOLATED_E2E=1
  • Added backend API_BIND_ADDR configuration support to enable E2E harness orchestration
  • Refactored E2E tests to use stable selectors and wait for API responses to improve reliability
  • Updated documentation to describe safe E2E workflow and validation requirements

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
sleep-ui/tests/global.setup.ts New global setup that spawns isolated API with disposable DB, validates safety preconditions, and waits for API readiness
sleep-ui/tests/global.teardown.ts New global teardown that terminates spawned API process and cleans up DB artifacts
sleep-ui/tests/e2e.spec.ts Refactored tests to use helper functions for stable selectors, wait for API responses, and handle conditional fields
sleep-ui/tests/auth.setup.ts Added safety assertions to prevent running auth bootstrap against unsafe targets
sleep-ui/playwright.config.ts Integrated global setup/teardown, added URL validation, configured webServer to use isolated API
sleep-ui/package.json Added test:e2e:safe script alias (redundant with test:e2e)
sleep-ui/README.md Documented safe E2E workflow and explicit bypass mechanism
sleep-api/src/main.rs Updated to use configurable bind address from API_BIND_ADDR env var
sleep-api/src/config.rs Added api_bind_addr() function with default 0.0.0.0:8080
docs/coding-agent/references/validation.md Updated with E2E isolation validation requirements and canonical commands
docs/coding-agent/references/how-to-run.md Documented API/UI runtime requirements, bind address config, and E2E workflows
docs/coding-agent/plans/active/sleep-ui-e2e-db-isolation-guardrails-plan.md Added comprehensive plan document describing isolation approach and validation strategy

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ebigunso
Copy link
Copy Markdown
Owner Author

ebigunso commented Feb 21, 2026

Addressed review follow-ups from PR53:

  • Must fixes:

    • Hardened teardown for cross-platform process termination + DB cleanup retries.
    • Removed redundant test:e2e:safe script alias.
    • Documented strict-port behavior for Playwright E2E startup.
    • Reduced runtime-state collision risk by scoping state path to PLAYWRIGHT_E2E_RUN_ID.
  • Should fixes:

    • Made E2E date/offset generation deterministic (removed Date.now()-based randomness in key paths).
    • Replaced URL regex fallback checks with pathname-based checks.

Validation rerun:

  • npm run check
  • npm run test:e2e:auth

@ebigunso ebigunso changed the title Isolate Playwright E2E DB and add live-target guardrails 🐛 Isolate Playwright E2E DB and add live-target guardrails Feb 21, 2026
@ebigunso ebigunso self-assigned this Feb 21, 2026
@ebigunso ebigunso requested a review from Copilot February 21, 2026 05:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ebigunso
Copy link
Copy Markdown
Owner Author

Correction to previous note (plain text):

Addressed newest PR53 feedback and main conflict.

  1. Must-fix bypass runtime-state path in global setup:
  • Runtime directory is now created before writing runtime-state in bypass mode.
  1. Must-fix detached teardown reliability on Unix:
  • Teardown now signals Unix process groups using negative pid, with fallback to pid-level signals, plus DB cleanup retries.
  1. Should-fix readiness strictness:
  • Readiness check now accepts expected /api/session states 200 or 401, instead of broad less-than-500.
  1. Main conflict:
  • Merged origin/main and resolved login form conflict while keeping both method=post action=/api/login and data-testid=login-form-action.

Validation evidence:

  • cd sleep-ui && npm run check
  • cd sleep-ui && npm run test:unit
  • cd sleep-ui && npm run test:e2e:auth
  • git diff --name-only --diff-filter=U returned no output.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 10 comments.

Comments suppressed due to low confidence (1)

docs/coding-agent/plans/active/pr53-unresolved-comments-and-main-conflict-resolution-plan.md:120

  • This plan document describes future work to resolve PR #53 review comments and merge conflicts. It's unusual to include a plan for future PR revisions within the PR itself, as this creates a circular reference (the PR contains a plan to fix the PR).

Consider keeping such plans external to the PR (in a separate branch or working directory) until the work is complete, or mark them more clearly as "meta-documentation" that tracks the evolution of the PR. The current inclusion isn't harmful but may be confusing to reviewers who expect plan documents to describe completed or in-progress work, not future iterations.

# PR53 Unresolved Comments and Main Conflict Resolution Plan

- status: draft
- owner: orchestrator
- work_type: mixed
- created: 2026-02-22

## Goal
Resolve new unresolved PR #53 review comments (must + should as requested) and cleanly merge `origin/main` into `feat/e2e-db-isolation-guardrails` without regressions.

## Definition of Done
- New unresolved **must** comments are fixed:
  - bypass runtime-state write path creates parent runtime dir.
  - teardown termination is reliable for Unix detached/process-group behavior.
- New unresolved **should** comment is addressed:
  - readiness predicate in setup is tightened from broad `<500` behavior.
- Branch is rebased/merged with `origin/main` and has no unresolved conflicts.
- Required validations pass and PR #53 is updated with response notes.

## Scope
- `sleep-ui/tests/global.setup.ts`
- `sleep-ui/tests/global.teardown.ts`
- `sleep-ui/src/routes/login/+page.svelte` (merge conflict)
- PR #53 thread responses and validation evidence

## Non-goals
- No broad E2E harness redesign.
- No unrelated UI/test refactors.
- No backend behavior changes beyond what is needed for comment/conflict resolution.

## Task Waves
- Wave 1 (sequential triage): `Task_1`
- Wave 2 (parallel implementation): `Task_2`, `Task_3`, `Task_4`
- Wave 3 (sequential verification): `Task_5`

## Tasks

### Task_1
- type: research
- title: Confirm unresolved comments and merge conflict targets
- owns:
  - PR #53 review thread metadata
  - merge-base status with `origin/main`
- depends_on: []
- acceptance:
  - unresolved items are classified into must/should.
  - exact conflicted file list is confirmed.
- validation:
  - required: true
    owner: orchestrator
    kind: review
    detail: Classification accepted before edits.

### Task_2
- type: impl
- title: Fix runtime-state bypass path and readiness strictness
- owns:
  - `sleep-ui/tests/global.setup.ts`
- depends_on: [Task_1]
- acceptance:
  - `ALLOW_NON_ISOLATED_E2E=1` path cannot fail from missing runtime dir.
  - readiness probe checks expected successful/known states (not generic `<500`).
- validation:
  - required: true
    owner: worker
    kind: command
    detail: targeted auth smoke passes and unsafe/bypass paths behave as expected.

### Task_3
- type: impl
- title: Harden teardown for detached process cleanup on Unix
- owns:
  - `sleep-ui/tests/global.teardown.ts`
- depends_on: [Task_1]
- acceptance:
  - teardown targets detached process group on Unix where needed.
  - DB cleanup runs with retry only after termination attempts.
- validation:
  - required: true
    owner: worker
    kind: command
    detail: `npm run test:e2e:auth` finishes without leaked API process symptoms.

### Task_4
- type: impl
- title: Resolve merge conflict with origin/main in login page
- owns:
  - `sleep-ui/src/routes/login/+page.svelte`
- depends_on: [Task_1]
- acceptance:
  - preserve both `method="post" action="/api/login"` and incoming `data-testid` form hook.
  - no conflict markers remain.
- validation:
  - required: true
    owner: worker
    kind: command
    detail: `git diff --name-only --diff-filter=U` is empty after merge.

### Task_5
- type: validation
- title: Run required validations and post PR53 updates
- owns:
  - `sleep-ui/**`
- depends_on: [Task_2, Task_3, Task_4]
- acceptance:
  - `npm run check` and `npm run test:unit` pass.
  - `npm run test:e2e:auth` pass.
  - PR #53 comment with resolution mapping is posted.
- validation:
  - required: true
    owner: worker
    kind: command
    detail: `cd sleep-ui && npm run check && npm run test:unit && npm run test:e2e:auth`

## Progress Log
- 2026-02-22: Drafted from Researcher triage of newest unresolved threads and merge conflict.

## Decision Log
- 2026-02-22: Treat two teardown/setup threads as must-fix and readiness strictness as should-fix per user request to address both categories.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ebigunso ebigunso merged commit 37ac4a2 into main Feb 21, 2026
4 checks passed
@ebigunso ebigunso deleted the feat/e2e-db-isolation-guardrails branch February 21, 2026 21:11
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