fix: isolate CHRNX local integration state
This commit is contained in:
16 files changed
+536
-65
No files matched your search
@@ -43,7 +43,11 @@ Seed the local `wp-env` site with deterministic review content:
|
||||
|
||||
The script accepts only `localhost` or `127.0.0.1`. It updates records marked
|
||||
with `_chrnx_fixture_key` and leaves unrelated local content alone. Repeated
|
||||
runs reuse the same pages and posts.
|
||||
runs reuse the same pages and posts. Before its first normal seed, it snapshots
|
||||
the exact local values for `sticky_posts`, site title/tagline, front/posts Page
|
||||
settings, permalink structure, the Subscribe Page pointer, and an existing
|
||||
fixture-owned Subscribe Page status. Fixture stickies are merged with unrelated
|
||||
sticky IDs instead of replacing them.
|
||||
|
||||
Use an allowlisted local edge scenario, then restore the default dataset:
|
||||
|
||||
@@ -54,8 +58,14 @@ Use an allowlisted local edge scenario, then restore the default dataset:
|
||||
./scripts/seed-test-content.sh subscribe-unpublished
|
||||
./scripts/seed-test-content.sh subscribe-unavailable
|
||||
./scripts/seed-test-content.sh default
|
||||
./scripts/seed-test-content.sh restore
|
||||
```
|
||||
|
||||
`default` restores the fixture presentation after an edge scenario; it does not
|
||||
discard the pre-fixture snapshot. Run `restore` explicitly to reinstate the
|
||||
captured option values and owned Subscribe status byte-for-byte and remove the
|
||||
snapshot. Fixture pages/posts remain local and reusable.
|
||||
|
||||
Rebuild the responsive portrait derivatives on macOS with `sips`, `cwebp`, and
|
||||
`avifenc`:
|
||||
|
||||
@@ -63,10 +73,18 @@ Rebuild the responsive portrait derivatives on macOS with `sips`, `cwebp`, and
|
||||
./scripts/build-responsive-images.sh
|
||||
```
|
||||
|
||||
For a non-destructive reproducibility check, pass an explicit absolute temporary
|
||||
directory: `./scripts/build-responsive-images.sh "$(mktemp -d)"`. The automated
|
||||
smoke test byte-compares all 35 outputs, validates their formats and dimensions,
|
||||
and enforces 160 KiB per derivative and 1.7 MiB total payload bounds.
|
||||
For a non-destructive reproducibility check, create a named direct child of the
|
||||
system temporary directory and pass its explicit absolute path:
|
||||
|
||||
```sh
|
||||
responsive_output=$(mktemp -d "${TMPDIR:-/tmp}/chrnx-responsive.XXXXXX")
|
||||
./scripts/build-responsive-images.sh "$responsive_output"
|
||||
```
|
||||
|
||||
The rebuild rejects symlinks, nested paths, nonexistent paths, and destinations
|
||||
outside the canonical system temporary directory. The automated smoke test
|
||||
byte-compares all 35 outputs, validates their formats and dimensions, and
|
||||
enforces 160 KiB per derivative and 1.7 MiB total payload bounds.
|
||||
|
||||
The PNG masters remain unchanged. WordPress serves 384 px and 768 px AVIF or
|
||||
WebP sources, with the PNG as a fallback.
|
||||
|
||||
@@ -13,6 +13,7 @@ $chrnx_query = chrnx_run_eligible_query( $chrnx_args );
|
||||
$chrnx_heading = chrnx_get_heading_level( $attributes['headingLevel'] ?? 2, 2 );
|
||||
$chrnx_topic = chrnx_validate_editorial_term_slug( $chrnx_request['chrnx_topic'] ?? '', 'chrnx_topic' );
|
||||
$chrnx_language = chrnx_validate_editorial_term_slug( $chrnx_request['chrnx_language'] ?? '', 'chrnx_language' );
|
||||
$chrnx_show = chrnx_validate_editorial_term_slug( $chrnx_request['chrnx_show'] ?? '', 'chrnx_show' );
|
||||
$chrnx_search = $chrnx_args['s'] ?? '';
|
||||
$chrnx_form_url = chrnx_get_journal_base_url();
|
||||
$chrnx_title_id = wp_unique_id( 'chrnx-journal-title-' );
|
||||
@@ -86,6 +87,7 @@ $chrnx_fixed = chrnx_get_journal_archive_filter();
|
||||
array(
|
||||
'chrnx_topic' => $chrnx_topic,
|
||||
'chrnx_language' => $chrnx_language,
|
||||
'chrnx_show' => $chrnx_show,
|
||||
's' => $chrnx_search,
|
||||
),
|
||||
'strlen'
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
# Local Integration Isolation Implementation Plan
|
||||
|
||||
<!-- markdownlint-disable MD013 -->
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
|
||||
|
||||
**Goal:** Make local WordPress fixtures, Playwright scenarios, show archive links, and image rebuild checks deterministic, isolated, reversible, and safe.
|
||||
|
||||
**Architecture:** Browser readers run in three dependency roots while a serial Chromium scenario project mutates the local database only after all roots finish. The local seeder owns fixture records, snapshots environment options once, merges unrelated sticky posts, and restores exact original option values explicitly. Show archive routing derives only from validated archive context. Responsive image rebuilds accept the committed destination or one canonical direct child of the system temporary directory.
|
||||
|
||||
**Tech Stack:** WordPress PHP, WP-CLI/wp-env on Colima, Playwright, Node test runner, POSIX shell.
|
||||
|
||||
---
|
||||
|
||||
## Task 1: Isolate Playwright database scenarios
|
||||
|
||||
**Files:** `playwright.config.mjs`, `tests/e2e/visual-states.spec.mjs`, `tests/e2e/visual-scenarios.spec.mjs`, `tests/smoke/e2e-harness.test.mjs`
|
||||
|
||||
- [ ] Write smoke contracts for read-only specs and dependent serial scenario project.
|
||||
- [ ] Run smoke test and record the expected RED failure.
|
||||
- [ ] Move mutation coverage into the dedicated serial spec and configure dependencies.
|
||||
- [ ] Run smoke and focused scenario tests GREEN.
|
||||
|
||||
## Task 2: Restore local WordPress configuration exactly
|
||||
|
||||
**Files:** `scripts/seed-test-content.php`, `scripts/seed-test-content.sh`, `tests/php/SeedStateTest.php`, `README.md`
|
||||
|
||||
- [ ] Write adversarial WP/PHP integration tests for snapshot, sticky merge, scenarios, and exact restore.
|
||||
- [ ] Run the tests and record the expected RED failure.
|
||||
- [ ] Add versioned snapshot ownership and explicit restore scenario.
|
||||
- [ ] Run default/scenarios/restore/default and prove exact restoration plus idempotency.
|
||||
|
||||
## Task 3: Preserve show archive routing
|
||||
|
||||
**Files:** `inc/queries.php`, `blocks/journal-stream/render.php`, `tests/php/BlockRenderingTest.php`
|
||||
|
||||
- [ ] Write pretty/plain/subdirectory URL tests for `chrnx_show` archive context and rejected raw input.
|
||||
- [ ] Run focused PHP tests and record RED.
|
||||
- [ ] Add show to internal archive base and pagination values without public request parsing.
|
||||
- [ ] Run focused PHP tests GREEN.
|
||||
|
||||
## Task 4: Harden responsive rebuild destinations
|
||||
|
||||
**Files:** `scripts/build-responsive-images.sh`, `tests/smoke/visual-integration.test.mjs`, `README.md`
|
||||
|
||||
- [ ] Write tests for the documented exact command and symlink/nested/outside rejection.
|
||||
- [ ] Run smoke and record RED.
|
||||
- [ ] Canonicalize TMPDIR and require a non-symlink direct `chrnx-*` child.
|
||||
- [ ] Rebuild and byte-compare all 35 outputs GREEN.
|
||||
|
||||
## Task 5: Verify and commit
|
||||
|
||||
- [ ] Run adversarial seed lifecycle and leave default state.
|
||||
- [ ] Run the full E2E matrix twice and the complete `npm test` chain.
|
||||
- [ ] Run PHP/JS/CSS/PHPCS, asset, parse, HTTP, diff, and secret checks.
|
||||
- [ ] Stage only intentional files, inspect cached diff, and commit `fix: isolate CHRNX local integration state`.
|
||||
- [ ] Confirm a clean worktree and do not push or deploy.
|
||||
+2
-2
@@ -378,7 +378,7 @@ function chrnx_get_journal_base_url() {
|
||||
$url = get_permalink( $queried );
|
||||
return is_string( $url ) ? $url : '';
|
||||
}
|
||||
if ( $queried instanceof WP_Term && in_array( $queried->taxonomy, array( 'chrnx_topic', 'chrnx_language' ), true ) ) {
|
||||
if ( $queried instanceof WP_Term && in_array( $queried->taxonomy, array( 'chrnx_topic', 'chrnx_language', 'chrnx_show' ), true ) ) {
|
||||
$url = get_term_link( $queried );
|
||||
return is_wp_error( $url ) ? '' : $url;
|
||||
}
|
||||
@@ -433,7 +433,7 @@ function chrnx_get_full_journal_url() {
|
||||
function chrnx_get_journal_page_url( int $page, array $filters ) {
|
||||
$base_url = chrnx_get_journal_base_url();
|
||||
$args = array();
|
||||
foreach ( array( 'chrnx_topic', 'chrnx_language' ) as $taxonomy ) {
|
||||
foreach ( array( 'chrnx_topic', 'chrnx_language', 'chrnx_show' ) as $taxonomy ) {
|
||||
$slug = chrnx_validate_editorial_term_slug( $filters[ $taxonomy ] ?? '', $taxonomy );
|
||||
if ( '' !== $slug ) {
|
||||
$args[ $taxonomy ] = $slug;
|
||||
|
||||
+2
-1
@@ -17,11 +17,12 @@
|
||||
"test:smoke": "node --test tests/smoke/*.test.mjs",
|
||||
"test:js": "wp-scripts test-unit-js --runInBand",
|
||||
"test:php": "wp-env run cli --env-cwd=wp-content/themes/chrnx -- composer exec phpunit --",
|
||||
"test:integration": "./tests/integration/seed-state.sh",
|
||||
"test:e2e": "playwright test",
|
||||
"lint:js": "wp-scripts lint-js assets/js tests/js tests/e2e",
|
||||
"lint:css": "wp-scripts lint-style 'assets/css/**/*.css' 'blocks/**/*.css'",
|
||||
"lint:md": "wp-scripts lint-md-docs docs README.md",
|
||||
"test": "npm run test:smoke && npm run lint:js && npm run lint:css && npm run phpcs && npm run test:js && npm run test:php && npm run test:e2e"
|
||||
"test": "npm run test:smoke && npm run lint:js && npm run lint:css && npm run phpcs && npm run test:js && npm run test:php && npm run test:integration && npm run test:e2e"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "1.62.1",
|
||||
|
||||
@@ -14,15 +14,26 @@ export default defineConfig({
|
||||
projects: [
|
||||
{
|
||||
name: 'chromium',
|
||||
testIgnore: 'visual-scenarios.spec.mjs',
|
||||
use: { ...devices['Desktop Chrome'] },
|
||||
},
|
||||
{
|
||||
name: 'firefox',
|
||||
testIgnore: 'visual-scenarios.spec.mjs',
|
||||
use: { ...devices['Desktop Firefox'] },
|
||||
},
|
||||
{
|
||||
name: 'webkit',
|
||||
testIgnore: 'visual-scenarios.spec.mjs',
|
||||
use: { ...devices['Desktop Safari'] },
|
||||
},
|
||||
{
|
||||
name: 'scenarios',
|
||||
testMatch: 'visual-scenarios.spec.mjs',
|
||||
dependencies: [ 'chromium', 'firefox', 'webkit' ],
|
||||
fullyParallel: false,
|
||||
workers: 1,
|
||||
use: { ...devices['Desktop Chrome'] },
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -16,20 +16,31 @@ if [ "$chrnx_image_output" = "/" ] || [ "$chrnx_image_output" = "$chrnx_image_ro
|
||||
echo "Refusing broad image output path: $chrnx_image_output" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [ -L "$chrnx_image_output" ]; then
|
||||
echo "Refusing symbolic-link image output: $chrnx_image_output" >&2
|
||||
exit 2
|
||||
fi
|
||||
if [ "$chrnx_image_output" != "$chrnx_image_default_output" ]; then
|
||||
chrnx_image_safe_tmp=${TMPDIR:-/tmp}
|
||||
chrnx_image_safe_tmp=${chrnx_image_safe_tmp%/}
|
||||
case "$chrnx_image_output" in
|
||||
"$chrnx_image_safe_tmp"/chrnx-*) ;;
|
||||
*)
|
||||
echo "Temporary image output must be an existing chrnx-* directory under $chrnx_image_safe_tmp." >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
if [ ! -d "$chrnx_image_output" ]; then
|
||||
echo "Temporary image output does not exist: $chrnx_image_output" >&2
|
||||
exit 2
|
||||
fi
|
||||
chrnx_image_safe_tmp=$(CDPATH= cd -P -- "${TMPDIR:-/tmp}" && pwd)
|
||||
chrnx_image_output_parent=$(dirname -- "$chrnx_image_output")
|
||||
chrnx_image_output_name=$(basename -- "$chrnx_image_output")
|
||||
chrnx_image_output_parent=$(CDPATH= cd -P -- "$chrnx_image_output_parent" && pwd)
|
||||
case "$chrnx_image_output_name" in
|
||||
chrnx-*) ;;
|
||||
*)
|
||||
echo "Temporary image output basename must start with chrnx-." >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
if [ "$chrnx_image_output_parent" != "$chrnx_image_safe_tmp" ]; then
|
||||
echo "Temporary image output must be a direct child of $chrnx_image_safe_tmp." >&2
|
||||
exit 2
|
||||
fi
|
||||
chrnx_image_output=$(CDPATH= cd -P -- "$chrnx_image_output" && pwd)
|
||||
fi
|
||||
chrnx_image_tmp=$(mktemp -d "${TMPDIR:-/tmp}/chrnx-images.XXXXXX")
|
||||
trap 'rm -rf -- "$chrnx_image_tmp"' EXIT HUP INT TERM
|
||||
|
||||
@@ -12,7 +12,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' );
|
||||
$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.' );
|
||||
}
|
||||
@@ -62,6 +62,78 @@ function chrnx_seed_find_post( string $fixture_key, string $post_type ): int {
|
||||
return empty( $ids ) ? 0 : absint( $ids[0] );
|
||||
}
|
||||
|
||||
/** Return an option value together with whether the row exists. */
|
||||
function chrnx_seed_get_option_state( string $name ): array {
|
||||
$sentinel = new stdClass();
|
||||
$value = get_option( $name, $sentinel );
|
||||
return array(
|
||||
'exists' => $sentinel !== $value,
|
||||
'value' => $sentinel === $value ? null : $value,
|
||||
);
|
||||
}
|
||||
|
||||
/** Capture local configuration once before applying the visual fixture environment. */
|
||||
function chrnx_seed_snapshot_environment(): void {
|
||||
$snapshot_name = '_chrnx_fixture_environment_snapshot_v1';
|
||||
if ( is_array( get_option( $snapshot_name, false ) ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$options = array();
|
||||
foreach ( array( 'sticky_posts', 'blogname', 'blogdescription', 'show_on_front', 'page_on_front', 'page_for_posts', 'permalink_structure', 'chrnx_subscribe_page_id' ) as $name ) {
|
||||
$options[ $name ] = chrnx_seed_get_option_state( $name );
|
||||
}
|
||||
$subscribe_id = chrnx_seed_find_post( 'page-subscribe', 'page' );
|
||||
$snapshot = array(
|
||||
'version' => 1,
|
||||
'options' => $options,
|
||||
'subscribe' => array(
|
||||
'exists' => $subscribe_id > 0,
|
||||
'id' => $subscribe_id,
|
||||
'status' => $subscribe_id > 0 ? get_post_status( $subscribe_id ) : null,
|
||||
),
|
||||
);
|
||||
update_option( $snapshot_name, $snapshot, false );
|
||||
}
|
||||
|
||||
/** Restore the exact local configuration captured before fixture ownership began. */
|
||||
function chrnx_seed_restore_environment(): void {
|
||||
$snapshot_name = '_chrnx_fixture_environment_snapshot_v1';
|
||||
$snapshot = get_option( $snapshot_name, null );
|
||||
if ( ! is_array( $snapshot ) || 1 !== ( $snapshot['version'] ?? null ) || ! is_array( $snapshot['options'] ?? null ) ) {
|
||||
WP_CLI::log( 'CHRNX_FIXTURES_RESTORE snapshot=none' );
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $snapshot['options'] as $name => $state ) {
|
||||
if ( ! is_string( $name ) || ! is_array( $state ) || ! array_key_exists( 'exists', $state ) ) {
|
||||
WP_CLI::error( 'Fixture environment snapshot is malformed.' );
|
||||
}
|
||||
if ( $state['exists'] ) {
|
||||
update_option( $name, $state['value'] ?? null );
|
||||
} else {
|
||||
delete_option( $name );
|
||||
}
|
||||
}
|
||||
|
||||
$subscribe = $snapshot['subscribe'] ?? array();
|
||||
if ( ! empty( $subscribe['exists'] ) ) {
|
||||
$subscribe_id = absint( $subscribe['id'] ?? 0 );
|
||||
if ( $subscribe_id > 0 && 'page-subscribe' === get_post_meta( $subscribe_id, '_chrnx_fixture_key', true ) ) {
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $subscribe_id,
|
||||
'post_status' => sanitize_key( $subscribe['status'] ?? 'publish' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
delete_option( '_chrnx_fixture_featured_limit' );
|
||||
delete_option( $snapshot_name );
|
||||
flush_rewrite_rules( false );
|
||||
WP_CLI::log( 'CHRNX_FIXTURES_RESTORE snapshot=restored' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert or update one fixture-owned post without touching unrelated content.
|
||||
*
|
||||
@@ -97,6 +169,12 @@ function chrnx_seed_upsert_post( array $fixture, string $post_type, int $offset
|
||||
return absint( $result );
|
||||
}
|
||||
|
||||
if ( 'restore' === $chrnx_seed_scenario ) {
|
||||
chrnx_seed_restore_environment();
|
||||
return;
|
||||
}
|
||||
|
||||
chrnx_seed_snapshot_environment();
|
||||
chrnx_seed_editorial_terms();
|
||||
$chrnx_seed_pages = chrnx_seed_read_fixture( 'pages.json' );
|
||||
$chrnx_seed_posts = chrnx_seed_read_fixture( 'posts.json' );
|
||||
@@ -172,7 +250,10 @@ if ( preg_match( '/^featured-([123])$/', $chrnx_seed_scenario, $chrnx_seed_match
|
||||
} else {
|
||||
delete_option( '_chrnx_fixture_featured_limit' );
|
||||
}
|
||||
update_option( 'sticky_posts', array_slice( $chrnx_seed_sticky_ids, 0, $chrnx_seed_featured_count ) );
|
||||
$chrnx_seed_current_stickies = array_map( 'absint', (array) get_option( 'sticky_posts', array() ) );
|
||||
$chrnx_seed_unrelated_stickies = array_values( array_diff( $chrnx_seed_current_stickies, array_values( $chrnx_seed_post_ids ) ) );
|
||||
$chrnx_seed_selected_stickies = array_slice( $chrnx_seed_sticky_ids, 0, $chrnx_seed_featured_count );
|
||||
update_option( 'sticky_posts', array_values( array_unique( array_merge( $chrnx_seed_unrelated_stickies, $chrnx_seed_selected_stickies ) ) ) );
|
||||
update_option( 'blogname', 'CHRNX' );
|
||||
update_option( 'blogdescription', 'Ideas made tangible.' );
|
||||
update_option( 'show_on_front', 'page' );
|
||||
|
||||
@@ -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) ;;
|
||||
default|featured-1|featured-2|featured-3|subscribe-unpublished|subscribe-unavailable|restore) ;;
|
||||
*)
|
||||
echo "Unknown local fixture scenario: $chrnx_seed_scenario" >&2
|
||||
exit 2
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const projectRoot = fileURLToPath( new URL( '../..', import.meta.url ) );
|
||||
const seedScenario = ( scenario ) =>
|
||||
execFileSync( './scripts/seed-test-content.sh', [ scenario ], {
|
||||
cwd: projectRoot,
|
||||
env: {
|
||||
...process.env,
|
||||
PATH: `/opt/homebrew/opt/docker/bin:${ process.env.PATH ?? '' }`,
|
||||
},
|
||||
stdio: 'pipe',
|
||||
} );
|
||||
|
||||
test.describe.configure( { mode: 'serial' } );
|
||||
|
||||
test.afterAll( () => {
|
||||
seedScenario( 'default' );
|
||||
} );
|
||||
|
||||
test( 'local featured and subscribe scenarios restore the default dataset', async ( { page } ) => {
|
||||
try {
|
||||
for ( const count of [ 1, 2 ] ) {
|
||||
seedScenario( `featured-${ count }` );
|
||||
await page.goto( `/?fixtureScenario=featured-${ count }` );
|
||||
await expect( page.locator( '.chrnx-featured-stories article' ) ).toHaveCount( count );
|
||||
const hrefs = await page
|
||||
.locator( '.chrnx-featured-stories article a' )
|
||||
.evaluateAll( ( links ) => links.map( ( link ) => link.href ) );
|
||||
expect( new Set( hrefs ).size ).toBe( hrefs.length );
|
||||
}
|
||||
for ( const scenario of [ 'subscribe-unpublished', 'subscribe-unavailable' ] ) {
|
||||
seedScenario( scenario );
|
||||
await page.goto( `/?fixtureScenario=${ scenario }` );
|
||||
await expect( page.locator( '.chrnx-subscribe-cta' ) ).toHaveCount( 0 );
|
||||
}
|
||||
} finally {
|
||||
seedScenario( 'default' );
|
||||
}
|
||||
await page.goto( '/' );
|
||||
await expect( page.locator( '.chrnx-featured-stories article' ) ).toHaveCount( 3 );
|
||||
await expect(
|
||||
page.getByRole( 'link', { name: 'Subscribe', exact: true } ).first(),
|
||||
).toBeVisible();
|
||||
} );
|
||||
@@ -1,18 +1,5 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
import { injectAxe } from 'axe-playwright';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const projectRoot = fileURLToPath( new URL( '../..', import.meta.url ) );
|
||||
const seedScenario = ( scenario ) =>
|
||||
execFileSync( './scripts/seed-test-content.sh', [ scenario ], {
|
||||
cwd: projectRoot,
|
||||
env: {
|
||||
...process.env,
|
||||
PATH: `/opt/homebrew/opt/docker/bin:${ process.env.PATH ?? '' }`,
|
||||
},
|
||||
stdio: 'pipe',
|
||||
} );
|
||||
|
||||
const viewports = [
|
||||
{ width: 375, height: 812 },
|
||||
@@ -151,35 +138,6 @@ test( 'cards without featured media use CSS-only topic treatments', async ( { pa
|
||||
}
|
||||
} );
|
||||
|
||||
test( 'local featured and subscribe scenarios restore the default dataset', async ( {
|
||||
page,
|
||||
}, testInfo ) => {
|
||||
test.skip( testInfo.project.name !== 'chromium', 'Database scenarios run once in Chromium.' );
|
||||
try {
|
||||
for ( const count of [ 1, 2 ] ) {
|
||||
seedScenario( `featured-${ count }` );
|
||||
await page.goto( `/?fixtureScenario=featured-${ count }` );
|
||||
await expect( page.locator( '.chrnx-featured-stories article' ) ).toHaveCount( count );
|
||||
const hrefs = await page
|
||||
.locator( '.chrnx-featured-stories article a' )
|
||||
.evaluateAll( ( links ) => links.map( ( link ) => link.href ) );
|
||||
expect( new Set( hrefs ).size ).toBe( hrefs.length );
|
||||
}
|
||||
for ( const scenario of [ 'subscribe-unpublished', 'subscribe-unavailable' ] ) {
|
||||
seedScenario( scenario );
|
||||
await page.goto( `/?fixtureScenario=${ scenario }` );
|
||||
await expect( page.locator( '.chrnx-subscribe-cta' ) ).toHaveCount( 0 );
|
||||
}
|
||||
} finally {
|
||||
seedScenario( 'default' );
|
||||
}
|
||||
await page.goto( '/' );
|
||||
await expect( page.locator( '.chrnx-featured-stories article' ) ).toHaveCount( 3 );
|
||||
await expect(
|
||||
page.getByRole( 'link', { name: 'Subscribe', exact: true } ).first(),
|
||||
).toBeVisible();
|
||||
} );
|
||||
|
||||
test( 'podcast canonical metadata is safe and missing metadata never invents a player or link', async ( {
|
||||
page,
|
||||
} ) => {
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
/**
|
||||
* Adversarial assertions for the local fixture environment lifecycle.
|
||||
*
|
||||
* @package CHRNX
|
||||
*/
|
||||
|
||||
$chrnx_test_host = wp_parse_url( home_url( '/' ), PHP_URL_HOST );
|
||||
if ( ! in_array( $chrnx_test_host, array( 'localhost', '127.0.0.1' ), true ) ) {
|
||||
WP_CLI::error( 'Refusing fixture-state tests outside local wp-env.' );
|
||||
}
|
||||
|
||||
$chrnx_test_mode = isset( $args[0] ) && is_string( $args[0] ) ? $args[0] : '';
|
||||
$chrnx_test_option_names = array(
|
||||
'sticky_posts',
|
||||
'blogname',
|
||||
'blogdescription',
|
||||
'show_on_front',
|
||||
'page_on_front',
|
||||
'page_for_posts',
|
||||
'permalink_structure',
|
||||
'chrnx_subscribe_page_id',
|
||||
);
|
||||
|
||||
/** Return exact option existence and serialized value. */
|
||||
function chrnx_test_option_state( string $name ): array {
|
||||
global $wpdb;
|
||||
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Test asserts exact persisted option bytes.
|
||||
$raw = $wpdb->get_var( $wpdb->prepare( "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s", $name ) );
|
||||
return array(
|
||||
'exists' => null !== $raw,
|
||||
'raw' => $raw,
|
||||
);
|
||||
}
|
||||
|
||||
/** Return IDs for fixture-owned sticky posts. */
|
||||
function chrnx_test_fixture_stickies(): array {
|
||||
$sticky = array_map( 'absint', (array) get_option( 'sticky_posts', array() ) );
|
||||
return array_values(
|
||||
array_filter(
|
||||
$sticky,
|
||||
static function ( int $post_id ): bool {
|
||||
return '' !== (string) get_post_meta( $post_id, '_chrnx_fixture_key', true );
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/** Find one local fixture-owned post. */
|
||||
function chrnx_test_find_fixture( string $key, string $post_type ): int {
|
||||
$ids = get_posts(
|
||||
array(
|
||||
'post_type' => $post_type,
|
||||
'post_status' => 'any',
|
||||
'posts_per_page' => 1,
|
||||
'fields' => 'ids',
|
||||
'meta_key' => '_chrnx_fixture_key',
|
||||
'meta_value' => $key,
|
||||
)
|
||||
);
|
||||
return empty( $ids ) ? 0 : absint( $ids[0] );
|
||||
}
|
||||
|
||||
/** Fail with a precise integration assertion. */
|
||||
function chrnx_test_assert( bool $condition, string $message ): void {
|
||||
if ( ! $condition ) {
|
||||
WP_CLI::error( $message );
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'setup' === $chrnx_test_mode ) {
|
||||
$chrnx_test_created_id = wp_insert_post(
|
||||
array(
|
||||
'post_status' => 'publish',
|
||||
'post_title' => 'Unrelated sticky sentinel',
|
||||
'post_type' => 'post',
|
||||
),
|
||||
true
|
||||
);
|
||||
if ( is_wp_error( $chrnx_test_created_id ) ) {
|
||||
WP_CLI::error( 'Could not create unrelated sticky sentinel.' );
|
||||
}
|
||||
update_option( 'sticky_posts', array( absint( $chrnx_test_created_id ) ) );
|
||||
update_option( 'blogname', 'Pre-existing local title' );
|
||||
update_option( 'blogdescription', 'Pre-existing local description' );
|
||||
update_option( 'show_on_front', 'posts' );
|
||||
update_option( 'page_on_front', 0 );
|
||||
update_option( 'page_for_posts', 0 );
|
||||
update_option( 'permalink_structure', '' );
|
||||
update_option( 'chrnx_subscribe_page_id', 424242 );
|
||||
$chrnx_test_subscribe_id = chrnx_test_find_fixture( 'page-subscribe', 'page' );
|
||||
if ( $chrnx_test_subscribe_id > 0 ) {
|
||||
wp_update_post(
|
||||
array(
|
||||
'ID' => $chrnx_test_subscribe_id,
|
||||
'post_status' => 'private',
|
||||
)
|
||||
);
|
||||
}
|
||||
$chrnx_test_expected = array();
|
||||
foreach ( $chrnx_test_option_names as $chrnx_test_option_name ) {
|
||||
$chrnx_test_expected[ $chrnx_test_option_name ] = chrnx_test_option_state( $chrnx_test_option_name );
|
||||
}
|
||||
$chrnx_test_expected['subscribe'] = array(
|
||||
'exists' => $chrnx_test_subscribe_id > 0,
|
||||
'id' => $chrnx_test_subscribe_id,
|
||||
'status' => $chrnx_test_subscribe_id > 0 ? get_post_status( $chrnx_test_subscribe_id ) : null,
|
||||
);
|
||||
update_option( '_chrnx_seed_test_expected', $chrnx_test_expected, false );
|
||||
update_option( '_chrnx_seed_test_unrelated_id', absint( $chrnx_test_created_id ), false );
|
||||
WP_CLI::success( 'Adversarial fixture environment prepared.' );
|
||||
return;
|
||||
}
|
||||
|
||||
$chrnx_test_unrelated_id = absint( get_option( '_chrnx_seed_test_unrelated_id', 0 ) );
|
||||
if ( 'check-default' === $chrnx_test_mode || 'check-featured-1' === $chrnx_test_mode ) {
|
||||
$chrnx_test_sticky = array_map( 'absint', (array) get_option( 'sticky_posts', array() ) );
|
||||
chrnx_test_assert( in_array( $chrnx_test_unrelated_id, $chrnx_test_sticky, true ), 'Seeder removed an unrelated sticky post.' );
|
||||
$chrnx_test_expected_count = 'check-featured-1' === $chrnx_test_mode ? 1 : 3;
|
||||
chrnx_test_assert( count( chrnx_test_fixture_stickies() ) === $chrnx_test_expected_count, 'Fixture sticky scenario count is wrong.' );
|
||||
if ( 'check-default' === $chrnx_test_mode ) {
|
||||
chrnx_test_assert( 'CHRNX' === get_option( 'blogname' ), 'Default visual title was not applied.' );
|
||||
chrnx_test_assert( '/%postname%/' === get_option( 'permalink_structure' ), 'Default visual permalinks were not applied.' );
|
||||
}
|
||||
WP_CLI::success( 'Fixture sticky ownership is isolated.' );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'check-subscribe-unpublished' === $chrnx_test_mode ) {
|
||||
$chrnx_test_subscribe_id = chrnx_test_find_fixture( 'page-subscribe', 'page' );
|
||||
chrnx_test_assert( 'draft' === get_post_status( $chrnx_test_subscribe_id ), 'Subscribe unpublished scenario did not draft the fixture page.' );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'check-subscribe-unavailable' === $chrnx_test_mode ) {
|
||||
chrnx_test_assert( 0 === absint( get_option( 'chrnx_subscribe_page_id' ) ), 'Subscribe unavailable scenario did not clear its fixture pointer.' );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'check-restore' === $chrnx_test_mode ) {
|
||||
$chrnx_test_expected = get_option( '_chrnx_seed_test_expected', array() );
|
||||
foreach ( $chrnx_test_option_names as $chrnx_test_option_name ) {
|
||||
chrnx_test_assert( chrnx_test_option_state( $chrnx_test_option_name ) === $chrnx_test_expected[ $chrnx_test_option_name ], 'Restore mismatch for ' . $chrnx_test_option_name . '.' );
|
||||
}
|
||||
if ( ! empty( $chrnx_test_expected['subscribe']['exists'] ) ) {
|
||||
chrnx_test_assert( get_post_status( $chrnx_test_expected['subscribe']['id'] ) === $chrnx_test_expected['subscribe']['status'], 'Subscribe fixture status was not restored.' );
|
||||
}
|
||||
chrnx_test_assert( false === get_option( '_chrnx_fixture_environment_snapshot_v1', false ), 'Snapshot was not removed after restore.' );
|
||||
WP_CLI::success( 'Original local configuration restored exactly.' );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'cleanup' === $chrnx_test_mode ) {
|
||||
if ( $chrnx_test_unrelated_id > 0 ) {
|
||||
wp_delete_post( $chrnx_test_unrelated_id, true );
|
||||
}
|
||||
delete_option( '_chrnx_seed_test_expected' );
|
||||
delete_option( '_chrnx_seed_test_unrelated_id' );
|
||||
return;
|
||||
}
|
||||
|
||||
WP_CLI::error( 'Unknown fixture-state test mode.' );
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
chrnx_test_root=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd)
|
||||
chrnx_test_docker=${CHRNX_DOCKER_CLI_DIR:-/opt/homebrew/opt/docker/bin}
|
||||
chrnx_test_wp() {
|
||||
PATH="$chrnx_test_docker:$PATH" npm exec -- wp-env run cli wp eval-file wp-content/themes/chrnx/tests/integration/seed-state.php "$1"
|
||||
}
|
||||
chrnx_test_seed() {
|
||||
PATH="$chrnx_test_docker:$PATH" "$chrnx_test_root/scripts/seed-test-content.sh" "$1"
|
||||
}
|
||||
chrnx_test_cleanup() {
|
||||
chrnx_test_seed restore >/dev/null 2>&1 || true
|
||||
chrnx_test_wp cleanup >/dev/null 2>&1 || true
|
||||
chrnx_test_seed default >/dev/null 2>&1 || true
|
||||
}
|
||||
trap chrnx_test_cleanup EXIT HUP INT TERM
|
||||
|
||||
cd -- "$chrnx_test_root"
|
||||
chrnx_test_seed restore
|
||||
chrnx_test_wp setup
|
||||
chrnx_test_seed default
|
||||
chrnx_test_wp check-default
|
||||
chrnx_test_seed featured-1
|
||||
chrnx_test_wp check-featured-1
|
||||
chrnx_test_seed subscribe-unpublished
|
||||
chrnx_test_wp check-subscribe-unpublished
|
||||
chrnx_test_seed subscribe-unavailable
|
||||
chrnx_test_wp check-subscribe-unavailable
|
||||
chrnx_test_seed restore
|
||||
chrnx_test_wp check-restore
|
||||
chrnx_test_wp cleanup
|
||||
chrnx_test_seed default
|
||||
trap - EXIT HUP INT TERM
|
||||
@@ -712,6 +712,57 @@ class BlockRenderingTest extends WP_UnitTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/** Show archive pagination keeps canonical archive routing and rejects raw show filters. */
|
||||
public function test_show_archive_pagination_preserves_internal_routing_only() {
|
||||
global $wp_rewrite;
|
||||
$previous_structure = get_option( 'permalink_structure' );
|
||||
$term = get_term_by( 'slug', 'silicon-ranch', 'chrnx_show' );
|
||||
for ( $index = 1; $index <= 12; ++$index ) {
|
||||
$post_id = self::factory()->post->create( array( 'post_title' => 'Show archive result ' . $index ) );
|
||||
wp_set_object_terms( $post_id, 'podcasts', 'chrnx_topic' );
|
||||
wp_set_object_terms( $post_id, 'silicon-ranch', 'chrnx_show' );
|
||||
}
|
||||
$previous_get = $_GET; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Synthetic read-only request.
|
||||
$pretty_link = static function ( $url, $term_object, $taxonomy ) {
|
||||
if ( 'chrnx_show' === $taxonomy && 'silicon-ranch' === $term_object->slug ) {
|
||||
return 'https://example.test/subdirectory/show/silicon-ranch/';
|
||||
}
|
||||
return $url;
|
||||
};
|
||||
try {
|
||||
$wp_rewrite->set_permalink_structure( '/%postname%/' );
|
||||
$this->go_to( get_term_link( $term ) );
|
||||
add_filter( 'term_link', $pretty_link, 10, 3 );
|
||||
$_GET = array( // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Synthetic read-only request.
|
||||
'chrnx_show' => 'invented-show',
|
||||
'evil' => 'drop-me',
|
||||
);
|
||||
$output = $this->render_journal_stream();
|
||||
preg_match( '/chrnx-journal-stream__pagination.*?href="([^"]+)".*?<\/nav>/s', $output, $pretty_match );
|
||||
$pretty_href = html_entity_decode( $pretty_match[1] ?? '', ENT_QUOTES | ENT_HTML5, 'UTF-8' );
|
||||
$this->assertSame( '/subdirectory/show/silicon-ranch/', wp_parse_url( $pretty_href, PHP_URL_PATH ) );
|
||||
parse_str( (string) wp_parse_url( $pretty_href, PHP_URL_QUERY ), $pretty_query );
|
||||
$this->assertSame( 'silicon-ranch', $pretty_query['chrnx_show'] ?? '' );
|
||||
$this->assertArrayNotHasKey( 'evil', $pretty_query );
|
||||
|
||||
remove_filter( 'term_link', $pretty_link, 10 );
|
||||
$wp_rewrite->set_permalink_structure( '' );
|
||||
$this->go_to( get_term_link( $term ) );
|
||||
$output = $this->render_journal_stream();
|
||||
preg_match( '/chrnx-journal-stream__pagination.*?href="([^"]+)".*?<\/nav>/s', $output, $plain_match );
|
||||
$plain_href = html_entity_decode( $plain_match[1] ?? '', ENT_QUOTES | ENT_HTML5, 'UTF-8' );
|
||||
parse_str( (string) wp_parse_url( $plain_href, PHP_URL_QUERY ), $plain_query );
|
||||
$this->assertSame( 'silicon-ranch', $plain_query['chrnx_show'] ?? '' );
|
||||
$this->assertSame( '2', (string) ( $plain_query['paged'] ?? '' ) );
|
||||
$this->assertArrayNotHasKey( 'evil', $plain_query );
|
||||
} finally {
|
||||
remove_filter( 'term_link', $pretty_link, 10 );
|
||||
$_GET = $previous_get;
|
||||
$wp_rewrite->set_permalink_structure( $previous_structure );
|
||||
$this->go_to( '/' );
|
||||
}
|
||||
}
|
||||
|
||||
/** Plain-permalink Journal links preserve Page routing and only validated public filters. */
|
||||
public function test_journal_pagination_preserves_plain_page_routing() {
|
||||
global $wp_rewrite;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { readFile, readdir } from 'node:fs/promises';
|
||||
import test from 'node:test';
|
||||
|
||||
test( 'Playwright seeds deterministic local fixtures once outside browser workers', async () => {
|
||||
@@ -14,3 +14,31 @@ test( 'Playwright seeds deterministic local fixtures once outside browser worker
|
||||
assert.equal( seed.match( /chrnx_seed_editorial_terms\(\);/g )?.length, 1 );
|
||||
assert.doesNotMatch( spec, /wp-env|execFileSync|beforeAll/ );
|
||||
} );
|
||||
|
||||
test( 'database scenarios run only in a serial Chromium project after all read-only browsers', async () => {
|
||||
const config = await readFile( 'playwright.config.mjs', 'utf8' );
|
||||
const files = await readdir( 'tests/e2e' );
|
||||
const scenario = await readFile( 'tests/e2e/visual-scenarios.spec.mjs', 'utf8' );
|
||||
|
||||
for ( const file of files.filter( ( name ) => name.endsWith( '.spec.mjs' ) && name !== 'visual-scenarios.spec.mjs' ) ) {
|
||||
const source = await readFile( `tests/e2e/${ file }`, 'utf8' );
|
||||
assert.doesNotMatch( source, /seed-test-content|wp-env|execFileSync/, `${ file } must be DB read-only` );
|
||||
}
|
||||
|
||||
assert.match( config, /name:\s*['"]scenarios['"]/ );
|
||||
assert.match( config, /testMatch:\s*['"]visual-scenarios\.spec\.mjs['"]/ );
|
||||
assert.match( config, /dependencies:\s*\[\s*['"]chromium['"],\s*['"]firefox['"],\s*['"]webkit['"]\s*\]/s );
|
||||
assert.match( config, /fullyParallel:\s*false/ );
|
||||
assert.match( config, /workers:\s*1/ );
|
||||
assert.match( scenario, /test\.describe\.configure\(\s*\{\s*mode:\s*['"]serial['"]/s );
|
||||
assert.match( scenario, /test\.afterAll[\s\S]*seedScenario\(\s*['"]default['"]\s*\)/ );
|
||||
} );
|
||||
|
||||
test( 'the npm integration chain finishes PHP and seed-state checks before browser workers', async () => {
|
||||
const manifest = JSON.parse( await readFile( 'package.json', 'utf8' ) );
|
||||
assert.match( manifest.scripts[ 'test:integration' ], /tests\/integration\/seed-state\.sh/ );
|
||||
assert.match(
|
||||
manifest.scripts.test,
|
||||
/npm run test:php && npm run test:integration && npm run test:e2e/,
|
||||
);
|
||||
} );
|
||||
@@ -1,5 +1,5 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdtempSync, readFileSync, readdirSync, rmSync, statSync } from 'node:fs';
|
||||
import { mkdtempSync, readFileSync, readdirSync, rmSync, statSync, symlinkSync, writeFileSync } from 'node:fs';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
@@ -77,10 +77,19 @@ test( 'the visual layer is separately enqueued and covers responsive accessible
|
||||
} );
|
||||
|
||||
test( 'all approved portraits rebuild byte-identically within payload bounds', () => {
|
||||
const output = mkdtempSync( join( tmpdir(), 'chrnx-image-test-' ) );
|
||||
const readme = read( 'README.md' );
|
||||
const documentedCommand = 'mktemp -d "${TMPDIR:-/tmp}/chrnx-responsive.XXXXXX"';
|
||||
assert.ok( readme.includes( documentedCommand ) );
|
||||
const output = execFileSync( 'sh', [ '-c', documentedCommand ], { encoding: 'utf8' } ).trim();
|
||||
const unsafeOutput = join( output, 'unsafe-output' );
|
||||
const external = mkdtempSync( join( tmpdir(), 'chrnx-external-' ) );
|
||||
const symlink = join( tmpdir(), `chrnx-symlink-${ process.pid }` );
|
||||
try {
|
||||
assert.throws( () => execFileSync( './scripts/build-responsive-images.sh', [ unsafeOutput ], { cwd: new URL( '../..', import.meta.url ) } ) );
|
||||
writeFileSync( join( external, 'sentinel' ), 'unchanged' );
|
||||
symlinkSync( external, symlink );
|
||||
assert.throws( () => execFileSync( './scripts/build-responsive-images.sh', [ symlink ], { cwd: new URL( '../..', import.meta.url ) } ) );
|
||||
assert.deepEqual( readdirSync( external ), [ 'sentinel' ] );
|
||||
execFileSync( './scripts/build-responsive-images.sh', [ output ], { cwd: new URL( '../..', import.meta.url ) } );
|
||||
const names = readdirSync( output ).sort();
|
||||
assert.equal( names.length, 35 );
|
||||
@@ -107,6 +116,8 @@ test( 'all approved portraits rebuild byte-identically within payload bounds', (
|
||||
assert.ok( total <= 1.7 * 1024 * 1024, `derivatives exceed 1.7 MiB: ${ total }` );
|
||||
} finally {
|
||||
rmSync( output, { recursive: true, force: true } );
|
||||
rmSync( external, { recursive: true, force: true } );
|
||||
rmSync( symlink, { force: true } );
|
||||
}
|
||||
} );
|
||||
|
||||
|
||||
Reference in new issue
Block a user