Skip to content

testing: Correlation ID harness — MU-plugin + TypeScript helper for E2E row isolation #194

@parhumm

Description

@parhumm

Summary

Implement the run-correlation system: a MU-plugin that injects [e2e:{RUN_ID}] into every tracked pageview's notes field, and a TypeScript helper to install/query/await correlated rows.

Motivation

Without row isolation, concurrent E2E tests interfere with each other and leftover rows from previous runs cause false positives. This is the foundation for every E2E test that makes DB assertions.

Dependencies

Implementation

Files to create

  • tests/e2e/mu-plugins/e2e-correlation-logger.php.tpl
  • tests/e2e/helpers/correlation.ts
  • tests/e2e/helpers/db.ts (skill spec §2.2 — DB pool)

MU-plugin template

```php

// SELECT WHERE notes LIKE '%[e2e:{runId}]%' function getCorrelatedRowCount(runId: string): Promise function waitForCorrelatedRow(runId: string, opts?: { timeout?: number; interval?: number }): Promise \`\`\` - `waitForCorrelatedRow()`: polls at 500ms intervals, default 10s timeout, throws on timeout with helpful message - All queries through `db.ts` pool — always parameterised ### `db.ts` exports (skill spec §2.2) \`\`\`typescript function getPrimaryPool(): DbPool function getTrackingRows(filter: string, params?: any[]): Promise function getRowCount(table: string, filter: string, params?: any[]): Promise function getVisitIdChain(correlationFilter: string): Promise \`\`\` ## Standards - Hook: `slimstat_track_pageview` filter (research 01 §C — "hook right before save") - MU-plugin MUST be idempotent — safe to install twice - `waitForCorrelatedRow()` MUST NOT use `setTimeout`/sleep — only DB-poll - Query filter always parameterised via `db.ts` (research 02 §1.1 SQL safety) - `uninstallCorrelationPlugin()` called in `afterAll` even if test fails ## Acceptance criteria - [ ] `installCorrelationPlugin('abc123')` writes plugin file to mu-plugins dir - [ ] After a page visit, `getCorrelatedRows('abc123')` returns ≥1 row - [ ] `waitForCorrelatedRow('abc123')` resolves within 10s of a tracked visit - [ ] Two concurrent tests with different `runId` values don't interfere - [ ] `uninstallCorrelationPlugin()` removes file and leaves no artifact ## References - Research 01 §C — Correlation IDs and oracles - Skill spec §2.2 (db.ts), §2.4 (correlation.ts), §3.1 (MU-plugin template)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions