From 12259f48379878762f8246595b327196068108e9 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Wed, 12 Aug 2026 22:51:08 -0500 Subject: [PATCH] test: isolate Related Stories partial counts --- .../2026-08-12-related-stories-layouts.md | 19 +-- ...26-08-12-related-stories-layouts-design.md | 2 +- playwright.config.mjs | 16 +- scripts/seed-test-content.php | 137 +----------------- scripts/seed-test-content.sh | 2 +- tests/e2e/related-stories-scenarios.spec.mjs | 104 ------------- tests/smoke/e2e-harness.test.mjs | 36 +++-- 7 files changed, 33 insertions(+), 283 deletions(-) delete mode 100644 tests/e2e/related-stories-scenarios.spec.mjs diff --git a/docs/superpowers/plans/2026-08-12-related-stories-layouts.md b/docs/superpowers/plans/2026-08-12-related-stories-layouts.md index 54092df..82e5d53 100644 --- a/docs/superpowers/plans/2026-08-12-related-stories-layouts.md +++ b/docs/superpowers/plans/2026-08-12-related-stories-layouts.md @@ -32,7 +32,7 @@ - `tests/e2e/global-setup.mjs` only if the existing idempotent fixture seed needs no-op-safe related-story guarantees. - `tests/fixtures/posts.json` only if deterministic five-related-story coverage cannot be formed from the existing twelve posts; keep the approved fixture count invariant unless a failing test proves expansion necessary. - `playwright.config.mjs` — environment-selectable base URL while preserving the default 8888 contract. -- `scripts/seed-test-content.sh` and `scripts/seed-test-content.php` — local-only serial `related-1/2/4` scenarios, if the runtime partial-count RED requires them. +- `scripts/seed-test-content.sh` and `scripts/seed-test-content.php` — local-only visual scenarios that mutate fixture-owned content only. ### Create @@ -42,7 +42,6 @@ - `tests/js/editor-related-posts.test.js` — registration, numeric coercion, allowlisting, and edit behavior. - `tests/js/related-posts.test.js` — initialization, navigation, focus, resize, failure, and cleanup behavior. - `tests/e2e/related-stories.spec.mjs` — real editor, frontend, responsive, accessibility, no-JS, and permalink coverage. -- `tests/e2e/related-stories-scenarios.spec.mjs` — serial mutation scenarios that always restore default fixture state. - `tests/smoke/related-stories-contract.test.mjs` — metadata, CSS, localization, and forbidden-behavior checks. ## Task 0: Start and prove the isolated environment @@ -374,12 +373,8 @@ git commit -m "style: add Related Stories layouts" **Files:** - Modify: `tests/e2e/related-stories.spec.mjs` -- Create: `tests/e2e/related-stories-scenarios.spec.mjs` - Modify: `playwright.config.mjs` - Modify: `tests/smoke/e2e-harness.test.mjs` -- Modify: `scripts/seed-test-content.sh` -- Modify: `scripts/seed-test-content.php` -- Modify: `tests/fixtures/posts.json` and `tests/e2e/global-setup.mjs` only if a RED test proves existing fixtures cannot provide five deterministic related stories - Modify as required by a valid RED: `assets/js/related-posts.js`, `blocks/related-posts/render.php`, `blocks/related-posts/style.css` - [ ] **Step 1: Write failing browser acceptance tests** @@ -396,23 +391,22 @@ On a seeded single-post route containing the default block, add tests for: - clicking each rendered related card reaches a same-origin published single-post response with HTTP 200 and no PHP warning; - axe finds no automatically detectable WCAG 2.2 AA violations in grid and active carousel states. -Create the mutation spec before changing the seed. It requests local scenarios `related-1`, `related-2`, and `related-4`, asserts exact rendered counts, and restores `default` in both `finally` and `afterAll`. Add a dedicated Playwright `related-scenarios` project with `workers:1`, `fullyParallel:false`, `dependencies:['scenarios']`, and `testMatch:'related-stories-scenarios.spec.mjs'`. The existing `scenarios` project already depends on every read-only browser project, so this explicit chain guarantees the two database-mutating projects never overlap. Every reader project and the existing `scenarios` project ignore the new mutation spec; `related-scenarios` ignores the older mutation spec. +Partial availability counts of one, two, and four are server integration cases. Keep them in `BlockRenderingTest.php`, using isolated PHPUnit factories and parsed article counts. Browser coverage uses the stable seeded `3/5 × adaptive/grid/carousel` matrix and must not mutate unrelated or unowned posts to manufacture smaller result sets. -Before implementation, extend `tests/smoke/e2e-harness.test.mjs` with a RED contract that recognizes exactly `visual-scenarios.spec.mjs` and `related-stories-scenarios.spec.mjs` as mutation specs, continues rejecting `seed-test-content`, `wp-env`, and `execFileSync` from every reader spec, and requires the dependency chain `chromium/firefox/webkit → scenarios → related-scenarios` with both mutation projects single-worker and non-parallel. +Before implementation, extend `tests/smoke/e2e-harness.test.mjs` with a RED contract that recognizes only `visual-scenarios.spec.mjs` as a mutation spec, continues rejecting `seed-test-content`, `wp-env`, and `execFileSync` from every reader spec, and requires the dependency chain `chromium/firefox/webkit → scenarios` with the mutation project single-worker and non-parallel. The contract also rejects Related Stories scenarios or snapshots that could change unowned content. - [ ] **Step 2: Run acceptance RED** ```bash CHRNX_E2E_BASE_URL=http://localhost:8908 npx playwright test tests/e2e/related-stories.spec.mjs --project=chromium --grep 'interaction|no JavaScript|permalink|accessibility' -CHRNX_E2E_BASE_URL=http://localhost:8908 npx playwright test tests/e2e/related-stories-scenarios.spec.mjs --project=related-scenarios node --test tests/smoke/e2e-harness.test.mjs ``` -Expected: tests that require the new block behavior fail before final integration; harness smoke fails because the second mutation spec/project is not yet allowlisted and chained; fixture changes are authorized only if the permalink/count precondition itself fails. +Expected: tests that require the new block behavior fail before final integration; harness smoke fails until browser specs stay read-only and no unsafe Related Stories mutation scenario exists. - [ ] **Step 3: Make the minimum integration/fixture correction** -Prefer existing published fixtures. Add allowlisted local-only `related-1/2/4` scenarios to both seed entrypoints. Each scenario snapshots the owned fixtures, leaves the current fixture published, leaves exactly the requested number of eligible related fixtures published, and temporarily drafts only the remaining `_chrnx_fixture_key`-owned posts. The serial test restores `default` in `finally`; default republishes the declared fixture statuses. This keeps all scenario behavior inside local seed tooling and leaves the production selector untouched. If five deterministic related posts are impossible, update existing fixture taxonomy/tag assignments without increasing the approved 7-page/12-post count. Keep keys/slugs stable, seed twice, and prove the same 19 owned IDs and default fingerprint before/after serial scenarios. Do not add URL rewriting or test-only production hooks. +Keep browser acceptance on the existing published fixtures. The local seed may update only `_chrnx_fixture_key`-owned records and must never snapshot, draft, delete, or otherwise mutate unowned posts. Preserve the approved 7-page/12-post count, stable keys/slugs, and production selector. Exact partial-count behavior remains covered by isolated PHPUnit factories; do not add URL rewriting or test-only production hooks. - [ ] **Step 4: Run Chromium GREEN, then all engines** @@ -420,7 +414,6 @@ Prefer existing published fixtures. Add allowlisted local-only `related-1/2/4` s CHRNX_E2E_BASE_URL=http://localhost:8908 npx playwright test tests/e2e/related-stories.spec.mjs --project=chromium CHRNX_E2E_BASE_URL=http://localhost:8908 npx playwright test tests/e2e/related-stories.spec.mjs --project=firefox CHRNX_E2E_BASE_URL=http://localhost:8908 npx playwright test tests/e2e/related-stories.spec.mjs --project=webkit -CHRNX_E2E_BASE_URL=http://localhost:8908 npx playwright test tests/e2e/related-stories-scenarios.spec.mjs --project=related-scenarios node --test tests/smoke/e2e-harness.test.mjs ``` @@ -429,7 +422,7 @@ Expected: all behavior passes in Chromium, Firefox, and WebKit. Axe may remain i - [ ] **Step 5: Commit Task 5** ```bash -git add tests/e2e/related-stories.spec.mjs tests/e2e/related-stories-scenarios.spec.mjs playwright.config.mjs tests/smoke/e2e-harness.test.mjs scripts/seed-test-content.sh scripts/seed-test-content.php tests/fixtures/posts.json tests/e2e/global-setup.mjs assets/js/related-posts.js blocks/related-posts/render.php blocks/related-posts/style.css +git add tests/e2e/related-stories.spec.mjs playwright.config.mjs tests/smoke/e2e-harness.test.mjs assets/js/related-posts.js blocks/related-posts/render.php blocks/related-posts/style.css git commit -m "test: verify Related Stories workflows" ``` diff --git a/docs/superpowers/specs/2026-08-12-related-stories-layouts-design.md b/docs/superpowers/specs/2026-08-12-related-stories-layouts-design.md index 9b49c97..70bf704 100644 --- a/docs/superpowers/specs/2026-08-12-related-stories-layouts-design.md +++ b/docs/superpowers/specs/2026-08-12-related-stories-layouts-design.md @@ -129,7 +129,7 @@ Test-driven implementation begins with failing tests for: - Independent JavaScript controllers, measured one-card movement, edge disabling, resize updates, reduced motion, missing-markup safety, and cleanup. - CSS contracts for adaptive, grid, carousel, scroll snap, 45px controls, no-JS, reduced motion, and absence of page overflow. - Playwright coverage at 375, 768, 900, 901, 1440, and 2560 pixels in light and dark themes. -- The complete `3/5 × adaptive/grid/carousel` matrix, plus adaptive availability counts of one, two, and four. +- The complete browser `3/5 × adaptive/grid/carousel` matrix, plus isolated PHPUnit factory coverage for availability counts of one, two, and four; browser fixtures never mutate unowned posts to manufacture partial results. - Runtime geometry: exact grid column counts; carousel card width formula within two CSS pixels; 24px-to-25% continuation preview bounds; correct control visibility at 900/901; track-only overflow; and `document.documentElement.scrollWidth <= document.documentElement.clientWidth`. - Resize focus regression in both directions, including 900→901 while Previous owns focus and while Next owns focus; the visible section heading becomes the destination before controls hide. - Real pointer/button and keyboard interaction without a focus trap. diff --git a/playwright.config.mjs b/playwright.config.mjs index ed68f4d..be14962 100644 --- a/playwright.config.mjs +++ b/playwright.config.mjs @@ -15,36 +15,26 @@ export default defineConfig({ projects: [ { name: 'chromium', - testIgnore: [ 'visual-scenarios.spec.mjs', 'related-stories-scenarios.spec.mjs' ], + testIgnore: 'visual-scenarios.spec.mjs', use: { ...devices['Desktop Chrome'] }, }, { name: 'firefox', - testIgnore: [ 'visual-scenarios.spec.mjs', 'related-stories-scenarios.spec.mjs' ], + testIgnore: 'visual-scenarios.spec.mjs', use: { ...devices['Desktop Firefox'] }, }, { name: 'webkit', - testIgnore: [ 'visual-scenarios.spec.mjs', 'related-stories-scenarios.spec.mjs' ], + testIgnore: 'visual-scenarios.spec.mjs', use: { ...devices['Desktop Safari'] }, }, { name: 'scenarios', testMatch: 'visual-scenarios.spec.mjs', - testIgnore: 'related-stories-scenarios.spec.mjs', dependencies: [ 'chromium', 'firefox', 'webkit' ], fullyParallel: false, workers: 1, use: { ...devices['Desktop Chrome'] }, }, - { - name: 'related-scenarios', - testMatch: 'related-stories-scenarios.spec.mjs', - testIgnore: 'visual-scenarios.spec.mjs', - dependencies: [ 'scenarios' ], - fullyParallel: false, - workers: 1, - use: { ...devices['Desktop Chrome'] }, - }, ], }); diff --git a/scripts/seed-test-content.php b/scripts/seed-test-content.php index 4c4a5af..59be910 100644 --- a/scripts/seed-test-content.php +++ b/scripts/seed-test-content.php @@ -14,7 +14,7 @@ if ( ! in_array( $chrnx_seed_host, array( 'localhost', '127.0.0.1' ), true ) ) { WP_CLI::error( 'Refusing to seed a non-local WordPress site.' ); } $chrnx_seed_scenario = isset( $args[0] ) && is_string( $args[0] ) ? $args[0] : 'default'; -$chrnx_seed_scenarios = array( 'default', 'featured-1', 'featured-2', 'featured-3', 'subscribe-unpublished', 'subscribe-unavailable', 'related-1', 'related-2', 'related-4', 'restore' ); +$chrnx_seed_scenarios = array( 'default', 'featured-1', 'featured-2', 'featured-3', 'subscribe-unpublished', 'subscribe-unavailable', 'restore' ); if ( ! in_array( $chrnx_seed_scenario, $chrnx_seed_scenarios, true ) ) { WP_CLI::error( 'Unknown local fixture scenario.' ); } @@ -81,123 +81,11 @@ function chrnx_seed_upsert_post( array $fixture, string $post_type, int $offset return absint( $result ); } -/** Return the option that stores temporary unrelated-post statuses. */ -function chrnx_seed_related_status_snapshot_name(): string { - return '_chrnx_fixture_related_unowned_status_snapshot_v1'; -} - -/** - * Capture every eligible unrelated post before a Related Stories scenario. - * - * @return array Exact records from the first scenario. - */ -function chrnx_seed_snapshot_related_unowned_statuses(): array { - $snapshot_name = chrnx_seed_related_status_snapshot_name(); - $snapshot = get_option( $snapshot_name, false ); - if ( is_array( $snapshot ) && 1 === ( $snapshot['version'] ?? null ) && is_array( $snapshot['posts'] ?? null ) ) { - return $snapshot['posts']; - } - - $candidate_ids = get_posts( - array( - 'post_type' => 'post', - 'post_status' => 'publish', - 'posts_per_page' => -1, - 'fields' => 'ids', - 'no_found_rows' => true, - 'meta_query' => array( - array( - 'key' => '_chrnx_fixture_key', - 'compare' => 'NOT EXISTS', - ), - ), - ) - ); - $records = array(); - foreach ( $candidate_ids as $candidate_id ) { - $candidate_id = absint( $candidate_id ); - if ( chrnx_is_eligible_editorial_post( $candidate_id ) ) { - $records[] = array( - 'id' => $candidate_id, - 'status' => (string) get_post_status( $candidate_id ), - ); - } - } - update_option( - $snapshot_name, - array( - 'version' => 1, - 'posts' => $records, - ), - false - ); - return $records; -} - -/** Temporarily draft the exact unrelated posts captured for a Related Stories scenario. */ -function chrnx_seed_draft_related_unowned_posts(): void { - foreach ( chrnx_seed_snapshot_related_unowned_statuses() as $record ) { - $post_id = absint( $record['id'] ?? 0 ); - if ( $post_id <= 0 || ! get_post( $post_id ) ) { - continue; - } - $result = wp_update_post( - array( - 'ID' => $post_id, - 'post_status' => 'draft', - ), - true - ); - if ( is_wp_error( $result ) ) { - WP_CLI::error( 'Could not isolate an unrelated Related Stories fixture candidate.' ); - } - } -} - -/** Restore exact unrelated-post statuses after a Related Stories scenario. */ -function chrnx_seed_restore_related_unowned_statuses(): bool { - $snapshot_name = chrnx_seed_related_status_snapshot_name(); - $snapshot = get_option( $snapshot_name, false ); - if ( ! is_array( $snapshot ) ) { - return false; - } - if ( 1 !== ( $snapshot['version'] ?? null ) || ! is_array( $snapshot['posts'] ?? null ) ) { - WP_CLI::error( 'Related Stories fixture snapshot is invalid.' ); - } - foreach ( $snapshot['posts'] as $record ) { - $post_id = absint( $record['id'] ?? 0 ); - $status = sanitize_key( $record['status'] ?? '' ); - if ( $post_id <= 0 || ! get_post( $post_id ) ) { - continue; - } - if ( ! array_key_exists( $status, get_post_stati() ) ) { - WP_CLI::error( 'Related Stories fixture snapshot contains an invalid post status.' ); - } - $result = wp_update_post( - array( - 'ID' => $post_id, - 'post_status' => $status, - ), - true - ); - if ( is_wp_error( $result ) ) { - WP_CLI::error( 'Could not restore an unrelated Related Stories fixture candidate.' ); - } - } - delete_option( $snapshot_name ); - return true; -} - if ( 'restore' === $chrnx_seed_scenario ) { - chrnx_seed_restore_related_unowned_statuses(); WP_CLI::log( chrnx_fixture_environment_restore() ? 'CHRNX_FIXTURES_RESTORE snapshot=restored' : 'CHRNX_FIXTURES_RESTORE snapshot=none' ); return; } -if ( 'default' === $chrnx_seed_scenario ) { - chrnx_seed_restore_related_unowned_statuses(); -} - chrnx_fixture_environment_snapshot(); chrnx_seed_editorial_terms(); $chrnx_seed_pages = chrnx_seed_read_fixture( 'pages.json' ); @@ -261,29 +149,6 @@ foreach ( $chrnx_seed_posts as $chrnx_seed_index => $chrnx_seed_post ) { $chrnx_seed_post_ids[ $chrnx_seed_post['fixtureKey'] ] = $chrnx_seed_post_id; } -if ( preg_match( '/^related-([124])$/', $chrnx_seed_scenario, $chrnx_seed_related_match ) ) { - chrnx_seed_draft_related_unowned_posts(); - $chrnx_seed_related_count = absint( $chrnx_seed_related_match[1] ); - $chrnx_seed_current_key = 'post-literature-long'; - $chrnx_seed_related_candidates = array_values( array_diff( array_keys( $chrnx_seed_post_ids ), array( $chrnx_seed_current_key ) ) ); - $chrnx_seed_published_keys = array_merge( - array( $chrnx_seed_current_key ), - array_slice( $chrnx_seed_related_candidates, 0, $chrnx_seed_related_count ) - ); - foreach ( $chrnx_seed_post_ids as $chrnx_seed_post_key => $chrnx_seed_owned_post_id ) { - $chrnx_seed_status_result = wp_update_post( - array( - 'ID' => $chrnx_seed_owned_post_id, - 'post_status' => in_array( $chrnx_seed_post_key, $chrnx_seed_published_keys, true ) ? 'publish' : 'draft', - ), - true - ); - if ( is_wp_error( $chrnx_seed_status_result ) ) { - WP_CLI::error( 'Could not apply Related Stories fixture status.' ); - } - } -} - $chrnx_seed_sticky_ids = array(); foreach ( $chrnx_seed_posts as $chrnx_seed_post ) { if ( ! empty( $chrnx_seed_post['featured'] ) && isset( $chrnx_seed_post_ids[ $chrnx_seed_post['fixtureKey'] ] ) ) { diff --git a/scripts/seed-test-content.sh b/scripts/seed-test-content.sh index d038d42..28630ad 100755 --- a/scripts/seed-test-content.sh +++ b/scripts/seed-test-content.sh @@ -7,7 +7,7 @@ chrnx_docker_cli_dir=${CHRNX_DOCKER_CLI_DIR:-/opt/homebrew/opt/docker/bin} chrnx_seed_scenario=${1:-default} case "$chrnx_seed_scenario" in - default|featured-1|featured-2|featured-3|subscribe-unpublished|subscribe-unavailable|related-1|related-2|related-4|restore) ;; + default|featured-1|featured-2|featured-3|subscribe-unpublished|subscribe-unavailable|restore) ;; *) echo "Unknown local fixture scenario: $chrnx_seed_scenario" >&2 exit 2 diff --git a/tests/e2e/related-stories-scenarios.spec.mjs b/tests/e2e/related-stories-scenarios.spec.mjs deleted file mode 100644 index 3a7e913..0000000 --- a/tests/e2e/related-stories-scenarios.spec.mjs +++ /dev/null @@ -1,104 +0,0 @@ -import { createHash } from 'node:crypto'; -import { execFileSync } from 'node:child_process'; -import { fileURLToPath } from 'node:url'; -import { expect, test } from '@playwright/test'; - -const projectRoot = fileURLToPath( new URL( '../..', import.meta.url ) ); -const commandEnvironment = { - ...process.env, - PATH: `/opt/homebrew/opt/docker/bin:${ process.env.PATH ?? '' }`, -}; -const seedScenario = ( scenario ) => - execFileSync( './scripts/seed-test-content.sh', [ scenario ], { - cwd: projectRoot, - env: commandEnvironment, - stdio: 'pipe', - } ); - -function readFixtureState() { - const php = String.raw` - $owned = get_posts(array('post_type'=>array('page','post'),'post_status'=>'any','posts_per_page'=>-1,'orderby'=>'ID','order'=>'ASC','meta_key'=>'_chrnx_fixture_key')); - $records = array(); - foreach ($owned as $post) { - $records[] = array('id'=>$post->ID,'key'=>get_post_meta($post->ID,'_chrnx_fixture_key',true),'type'=>$post->post_type,'status'=>$post->post_status,'slug'=>$post->post_name,'content'=>hash('sha256',$post->post_content)); - } - $unrelated = get_posts(array('post_type'=>array('page','post'),'post_status'=>'any','posts_per_page'=>-1,'orderby'=>'ID','order'=>'ASC','meta_query'=>array(array('key'=>'_chrnx_fixture_key','compare'=>'NOT EXISTS')))); - $outside = array(); - foreach ($unrelated as $post) { - $outside[] = array('id'=>$post->ID,'type'=>$post->post_type,'status'=>$post->post_status,'slug'=>$post->post_name,'content'=>hash('sha256',$post->post_content)); - } - echo 'CHRNX_STATE=' . wp_json_encode(array('owned'=>$records,'unrelated'=>$outside,'relatedSnapshot'=>get_option('_chrnx_fixture_related_unowned_status_snapshot_v1',false))); - `; - const output = execFileSync( 'npm', [ 'exec', '--', 'wp-env', 'run', 'cli', 'wp', 'eval', php ], { - cwd: projectRoot, - env: commandEnvironment, - encoding: 'utf8', - } ); - const encoded = output.match( /CHRNX_STATE=(\{.*\})/ )?.[ 1 ]; - if ( ! encoded ) { - throw new Error( 'Could not read the local fixture state.' ); - } - const state = JSON.parse( encoded ); - return { - ...state, - fingerprint: createHash( 'sha256' ).update( JSON.stringify( state ) ).digest( 'hex' ), - }; -} - -test.describe.configure( { mode: 'serial' } ); - -test.afterAll( () => { - seedScenario( 'default' ); -} ); - -test( 'related scenarios render exact partial counts and restore the identical default dataset', async ( { - page, -} ) => { - seedScenario( 'default' ); - const baseline = readFixtureState(); - const unrelatedBaseline = baseline.unrelated.find( ( post ) => post.slug === 'hello-world' ); - expect( unrelatedBaseline ).toMatchObject( { status: 'publish', slug: 'hello-world' } ); - expect( baseline.owned.filter( ( post ) => post.type === 'page' ) ).toHaveLength( 7 ); - expect( baseline.owned.filter( ( post ) => post.type === 'post' ) ).toHaveLength( 12 ); - expect( baseline.owned ).toHaveLength( 19 ); - seedScenario( 'default' ); - expect( readFixtureState() ).toEqual( baseline ); - - try { - for ( const count of [ 1, 2, 4 ] ) { - seedScenario( `related-${ count }` ); - const duringScenario = readFixtureState(); - const unrelatedDuringScenario = duringScenario.unrelated.find( - ( post ) => post.id === unrelatedBaseline.id, - ); - expect( unrelatedDuringScenario ).toEqual( { - ...unrelatedBaseline, - status: 'draft', - } ); - expect( duringScenario.relatedSnapshot.posts ).toContainEqual( { - id: unrelatedBaseline.id, - status: 'publish', - } ); - await page.setViewportSize( { width: 900, height: 900 } ); - await page.goto( `/long-title-night-writing-fixture/?fixtureScenario=related-${ count }` ); - const section = page.locator( '#related-stories-5-adaptive .chrnx-related-posts' ); - const cards = section.locator( '.chrnx-related-card' ); - const buttons = section.getByRole( 'button' ); - await expect( cards ).toHaveCount( count ); - await expect( buttons ).toHaveCount( 2 ); - if ( count === 1 ) { - await expect( buttons.nth( 0 ) ).toBeDisabled(); - await expect( buttons.nth( 1 ) ).toBeDisabled(); - } - } - } finally { - seedScenario( 'default' ); - } - - const restored = readFixtureState(); - expect( restored ).toEqual( baseline ); - await page.goto( '/long-title-night-writing-fixture/?fixtureScenario=default' ); - await expect( page.locator( '#related-stories-5-adaptive .chrnx-related-card' ) ).toHaveCount( - 5, - ); -} ); diff --git a/tests/smoke/e2e-harness.test.mjs b/tests/smoke/e2e-harness.test.mjs index 9308bb1..42a2611 100644 --- a/tests/smoke/e2e-harness.test.mjs +++ b/tests/smoke/e2e-harness.test.mjs @@ -30,10 +30,10 @@ test( 'Playwright caps read-only browser concurrency for the local WordPress sta assert.equal( config.workers, 2 ); } ); -test( 'exactly two serial mutation projects run after every read-only browser', async () => { +test( 'exactly one serial mutation project runs after every read-only browser', async () => { const config = await readFile( 'playwright.config.mjs', 'utf8' ); const files = await readdir( 'tests/e2e' ); - const mutationSpecs = [ 'related-stories-scenarios.spec.mjs', 'visual-scenarios.spec.mjs' ]; + const mutationSpecs = [ 'visual-scenarios.spec.mjs' ]; const mutationSources = await Promise.all( mutationSpecs.map( ( file ) => readFile( `tests/e2e/${ file }`, 'utf8' ) ), ); @@ -53,31 +53,37 @@ test( 'exactly two serial mutation projects run after every read-only browser', } assert.deepEqual( detectedMutations.sort(), mutationSpecs ); - assert.equal( - config.match( - /testIgnore:\s*\[\s*['"]visual-scenarios\.spec\.mjs['"],\s*['"]related-stories-scenarios\.spec\.mjs['"]\s*\]/gs, - )?.length, - 3, - ); + assert.equal( config.match( /testIgnore:\s*['"]visual-scenarios\.spec\.mjs['"]/g )?.length, 3 ); assert.match( config, /name:\s*['"]scenarios['"]/ ); assert.match( config, /testMatch:\s*['"]visual-scenarios\.spec\.mjs['"]/ ); - assert.match( config, /testIgnore:\s*['"]related-stories-scenarios\.spec\.mjs['"]/ ); assert.match( config, /dependencies:\s*\[\s*['"]chromium['"],\s*['"]firefox['"],\s*['"]webkit['"]\s*\]/s, ); - assert.match( config, /name:\s*['"]related-scenarios['"]/ ); - assert.match( config, /testMatch:\s*['"]related-stories-scenarios\.spec\.mjs['"]/ ); - assert.match( config, /testIgnore:\s*['"]visual-scenarios\.spec\.mjs['"]/ ); - assert.match( config, /dependencies:\s*\[\s*['"]scenarios['"]\s*\]/s ); - assert.equal( config.match( /fullyParallel:\s*false/g )?.length, 2 ); - assert.equal( config.match( /workers:\s*1/g )?.length, 2 ); + assert.doesNotMatch( config, /related-scenarios|related-stories-scenarios/ ); + assert.equal( config.match( /fullyParallel:\s*false/g )?.length, 1 ); + assert.equal( config.match( /workers:\s*1/g )?.length, 1 ); for ( const source of mutationSources ) { assert.match( source, /test\.describe\.configure\(\s*\{\s*mode:\s*['"]serial['"]/s ); assert.match( source, /test\.afterAll[\s\S]*seedScenario\(\s*['"]default['"]\s*\)/ ); } } ); +test( 'Related Stories partial-count verification never mutates unowned browser content', async () => { + const seed = await readFile( 'scripts/seed-test-content.php', 'utf8' ); + const shell = await readFile( 'scripts/seed-test-content.sh', 'utf8' ); + const phpTest = await readFile( 'tests/php/BlockRenderingTest.php', 'utf8' ); + const files = await readdir( 'tests/e2e' ); + + assert.doesNotMatch( seed, /related-[124]|related_unowned|unowned_status_snapshot/ ); + assert.doesNotMatch( shell, /related-[124]/ ); + assert.equal( files.includes( 'related-stories-scenarios.spec.mjs' ), false ); + assert.match( + phpTest, + /related_partial_count_provider[\s\S]*array\(\s*1\s*\)[\s\S]*array\(\s*2\s*\)[\s\S]*array\(\s*4\s*\)/, + ); +} ); + test( 'the npm integration chain finishes isolated PHP before browser workers', async () => { const manifest = JSON.parse( await readFile( 'package.json', 'utf8' ) ); assert.equal( manifest.scripts[ 'test:integration' ], undefined );