fix: complete CHRNX responsive edge states

This commit is contained in:
chrnx committed 2026-08-12 09:02:34 -05:00
1 parent 5073178492
commit 1e9386ac13
15 files changed
+384 -35

No files matched your search

+16
View File
@@ -45,6 +45,17 @@ 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.
Use an allowlisted local edge scenario, then restore the default dataset:
```sh
./scripts/seed-test-content.sh featured-1
./scripts/seed-test-content.sh featured-2
./scripts/seed-test-content.sh featured-3
./scripts/seed-test-content.sh subscribe-unpublished
./scripts/seed-test-content.sh subscribe-unavailable
./scripts/seed-test-content.sh default
```
Rebuild the responsive portrait derivatives on macOS with `sips`, `cwebp`, and
`avifenc`:
@@ -52,6 +63,11 @@ 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.
The PNG masters remain unchanged. WordPress serves 384 px and 768 px AVIF or
WebP sources, with the PNG as a fallback.
+11 -12
View File
@@ -245,54 +245,53 @@ footer a {
.chrnx-journal-card__fallback,
.chrnx-podcast-card__fallback,
.chrnx-related-card__fallback {
background-position: right bottom;
background-repeat: no-repeat;
background-size: auto 125%;
background-color: var(--chrnx-surface-raised);
background-image:
linear-gradient(135deg, transparent 0 46%, color-mix(in srgb, var(--chrnx-card-accent, var(--chrnx-green)) 35%, transparent) 47% 52%, transparent 53%),
radial-gradient(circle at 72% 28%, color-mix(in srgb, var(--chrnx-card-accent, var(--chrnx-green)) 28%, transparent) 0 15%, transparent 16%);
}
.chrnx-featured-story__fallback.is-topic-code,
.chrnx-journal-card__fallback.is-topic-code,
.chrnx-related-card__fallback.is-topic-code {
background-image: url(../images/generated/alter-ego-code-384.webp);
--chrnx-card-accent: #59c3c3;
}
.chrnx-featured-story__fallback.is-topic-research,
.chrnx-journal-card__fallback.is-topic-research,
.chrnx-related-card__fallback.is-topic-research {
background-image: url(../images/generated/alter-ego-research-384.webp);
--chrnx-card-accent: #a5d66a;
}
.chrnx-featured-story__fallback.is-topic-gaming,
.chrnx-journal-card__fallback.is-topic-gaming,
.chrnx-related-card__fallback.is-topic-gaming {
background-image: url(../images/generated/alter-ego-gaming-384.webp);
--chrnx-card-accent: #da7b45;
}
.chrnx-featured-story__fallback.is-topic-literature,
.chrnx-journal-card__fallback.is-topic-literature,
.chrnx-related-card__fallback.is-topic-literature {
background-image: url(../images/generated/alter-ego-literature-384.webp);
--chrnx-card-accent: #b88ad9;
}
.chrnx-featured-story__fallback.is-topic-life,
.chrnx-journal-card__fallback.is-topic-life,
.chrnx-related-card__fallback.is-topic-life {
background-image: url(../images/generated/alter-ego-life-384.webp);
--chrnx-card-accent: #e0b75b;
}
.chrnx-featured-story__fallback.is-topic-podcasts,
.chrnx-journal-card__fallback.is-topic-podcasts,
.chrnx-podcast-card__fallback.is-topic-podcasts,
.chrnx-related-card__fallback.is-topic-podcasts {
background-color: #10151d;
background-image: url(../images/generated/alter-ego-podcasts-384.webp);
--chrnx-card-accent: #58a7d8;
}
.chrnx-featured-story__fallback.is-topic-music,
.chrnx-journal-card__fallback.is-topic-music,
.chrnx-related-card__fallback.is-topic-music {
background-color: #160f0b;
background-image: url(../images/generated/the-no-names-musician-cutout-384.webp);
--chrnx-card-accent: #d36b3f;
}
.chrnx-journal-stream__filters {
+1 -1
View File
@@ -25,7 +25,7 @@ $chrnx_label = $chrnx_term instanceof WP_Term ? $chrnx_term->name : ucfirst( $
</div>
<div class="chrnx-topic-hero__art">
<?php if ( is_readable( get_theme_file_path( $chrnx_asset ) ) ) : ?>
<?php echo chrnx_get_topic_portrait_markup( $chrnx_topic, '', 'chrnx-section-portrait' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?>
<?php echo chrnx_get_topic_portrait_markup( $chrnx_topic, '', 'chrnx-section-portrait', 'eager' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Helper returns escaped, allowlisted markup. ?>
<?php else : ?>
<span class="chrnx-topic-hero__fallback" aria-hidden="true"></span>
<?php endif; ?>
+5 -2
View File
@@ -11,9 +11,10 @@
* @param string $topic_slug Topic slug.
* @param string $alt Alternative text. Empty is valid for decorative art.
* @param string $class_name Optional image class.
* @param string $loading Either lazy (default) or eager for above-fold art.
* @return string Safe picture markup or an empty string.
*/
function chrnx_get_topic_portrait_markup( string $topic_slug, string $alt = '', string $class_name = '' ): string {
function chrnx_get_topic_portrait_markup( string $topic_slug, string $alt = '', string $class_name = '', string $loading = 'lazy' ): string {
$source = chrnx_get_topic_art_asset( $topic_slug );
$dimensions = chrnx_get_topic_art_dimensions( $topic_slug );
if ( '' === $source || 2 !== count( $dimensions ) ) {
@@ -27,11 +28,13 @@ function chrnx_get_topic_portrait_markup( string $topic_slug, string $alt = '',
$classes = is_array( $split_classes ) ? array_filter( $split_classes ) : array();
$class = implode( ' ', array_map( 'sanitize_html_class', $classes ) );
$decorative = '' === $alt ? ' aria-hidden="true"' : '';
$loading = 'eager' === $loading ? 'eager' : 'lazy';
$priority = 'eager' === $loading ? ' fetchpriority="high"' : '';
$markup = '<picture class="chrnx-responsive-portrait"' . $decorative . '>';
$markup .= '<source type="image/avif" srcset="' . esc_url( $base_uri . '-384.avif' ) . ' 384w, ' . esc_url( $base_uri . '-768.avif' ) . ' 768w" sizes="' . esc_attr( $sizes ) . '">';
$markup .= '<source type="image/webp" srcset="' . esc_url( $base_uri . '-384.webp' ) . ' 384w, ' . esc_url( $base_uri . '-768.webp' ) . ' 768w" sizes="' . esc_attr( $sizes ) . '">';
$markup .= '<img' . ( '' !== $class ? ' class="' . esc_attr( $class ) . '"' : '' ) . ' src="' . esc_url( get_theme_file_uri( $source ) ) . '" width="' . esc_attr( $dimensions[0] ) . '" height="' . esc_attr( $dimensions[1] ) . '" loading="lazy" decoding="async" sizes="' . esc_attr( $sizes ) . '" alt="' . esc_attr( $alt ) . '">';
$markup .= '<img' . ( '' !== $class ? ' class="' . esc_attr( $class ) . '"' : '' ) . ' src="' . esc_url( get_theme_file_uri( $source ) ) . '" width="' . esc_attr( $dimensions[0] ) . '" height="' . esc_attr( $dimensions[1] ) . '" loading="' . esc_attr( $loading ) . '"' . $priority . ' decoding="async" sizes="' . esc_attr( $sizes ) . '" alt="' . esc_attr( $alt ) . '">';
$markup .= '</picture>';
return $markup;
+7
View File
@@ -169,6 +169,13 @@ function chrnx_get_post_topic_slug( $post_id ) {
*/
function chrnx_get_featured_story_ids( int $limit = 3 ): array {
$limit = min( 12, max( 0, $limit ) );
$host = wp_parse_url( home_url( '/' ), PHP_URL_HOST );
if ( in_array( $host, array( 'localhost', '127.0.0.1' ), true ) ) {
$fixture_limit = absint( get_option( '_chrnx_fixture_featured_limit', 0 ) );
if ( in_array( $fixture_limit, array( 1, 2, 3 ), true ) ) {
$limit = min( $limit, $fixture_limit );
}
}
if ( 0 === $limit ) {
return array();
}
+4 -1
View File
@@ -60,7 +60,10 @@ add_action( 'admin_init', 'chrnx_register_subscribe_setting' );
*/
function chrnx_get_subscribe_url(): string {
$page_id = absint( get_option( 'chrnx_subscribe_page_id', 0 ) );
$page = get_post( $page_id );
if ( 0 === $page_id ) {
return '';
}
$page = get_post( $page_id );
if ( ! $page instanceof WP_Post || 'page' !== $page->post_type || 'publish' !== $page->post_status ) {
return '';
}
+28 -1
View File
@@ -3,7 +3,34 @@ set -eu
chrnx_image_script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
chrnx_image_root=$(dirname -- "$chrnx_image_script_dir")
chrnx_image_output="$chrnx_image_root/assets/images/generated"
chrnx_image_default_output="$chrnx_image_root/assets/images/generated"
chrnx_image_output=${1:-"$chrnx_image_default_output"}
case "$chrnx_image_output" in
/*) ;;
*)
echo "Image output must be an explicit absolute path." >&2
exit 2
;;
esac
if [ "$chrnx_image_output" = "/" ] || [ "$chrnx_image_output" = "$chrnx_image_root" ]; then
echo "Refusing broad image output path: $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
fi
chrnx_image_tmp=$(mktemp -d "${TMPDIR:-/tmp}/chrnx-images.XXXXXX")
trap 'rm -rf -- "$chrnx_image_tmp"' EXIT HUP INT TERM
+27 -5
View File
@@ -11,6 +11,11 @@ $chrnx_seed_host = wp_parse_url( home_url( '/' ), PHP_URL_HOST );
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' );
if ( ! in_array( $chrnx_seed_scenario, $chrnx_seed_scenarios, true ) ) {
WP_CLI::error( 'Unknown local fixture scenario.' );
}
/**
* Read one fixture JSON document from the mapped theme.
@@ -114,7 +119,7 @@ foreach ( $chrnx_seed_posts as $chrnx_seed_index => $chrnx_seed_post ) {
wp_set_object_terms( $chrnx_seed_post_id, array(), 'chrnx_show', false );
}
foreach ( array( 'chrnx_episode_number', 'chrnx_episode_duration' ) as $chrnx_seed_meta_key ) {
foreach ( array( 'chrnx_episode_number', 'chrnx_episode_duration', 'canonical_episode_url' ) as $chrnx_seed_meta_key ) {
delete_post_meta( $chrnx_seed_post_id, $chrnx_seed_meta_key );
}
if ( isset( $chrnx_seed_post['episodeNumber'] ) ) {
@@ -123,6 +128,9 @@ foreach ( $chrnx_seed_posts as $chrnx_seed_index => $chrnx_seed_post ) {
if ( isset( $chrnx_seed_post['episodeDuration'] ) ) {
update_post_meta( $chrnx_seed_post_id, 'chrnx_episode_duration', chrnx_sanitize_episode_duration( $chrnx_seed_post['episodeDuration'] ) );
}
if ( isset( $chrnx_seed_post['canonicalEpisodeUrl'] ) ) {
update_post_meta( $chrnx_seed_post_id, 'canonical_episode_url', chrnx_sanitize_canonical_episode_url( $chrnx_seed_post['canonicalEpisodeUrl'] ) );
}
$chrnx_seed_post_ids[ $chrnx_seed_post['fixtureKey'] ] = $chrnx_seed_post_id;
}
@@ -132,21 +140,35 @@ foreach ( $chrnx_seed_posts as $chrnx_seed_post ) {
$chrnx_seed_sticky_ids[] = $chrnx_seed_post_ids[ $chrnx_seed_post['fixtureKey'] ];
}
}
update_option( 'sticky_posts', $chrnx_seed_sticky_ids );
$chrnx_seed_featured_count = 3;
if ( preg_match( '/^featured-([123])$/', $chrnx_seed_scenario, $chrnx_seed_match ) ) {
$chrnx_seed_featured_count = absint( $chrnx_seed_match[1] );
update_option( '_chrnx_fixture_featured_limit', $chrnx_seed_featured_count );
} else {
delete_option( '_chrnx_fixture_featured_limit' );
}
update_option( 'sticky_posts', array_slice( $chrnx_seed_sticky_ids, 0, $chrnx_seed_featured_count ) );
update_option( 'blogname', 'CHRNX' );
update_option( 'blogdescription', 'Ideas made tangible.' );
update_option( 'show_on_front', 'page' );
update_option( 'page_on_front', $chrnx_seed_page_ids['home'] );
update_option( 'page_for_posts', 0 );
update_option( 'chrnx_subscribe_page_id', $chrnx_seed_page_ids['subscribe'] );
wp_update_post(
array(
'ID' => $chrnx_seed_page_ids['subscribe'],
'post_status' => 'subscribe-unpublished' === $chrnx_seed_scenario ? 'draft' : 'publish',
)
);
update_option( 'chrnx_subscribe_page_id', 'subscribe-unavailable' === $chrnx_seed_scenario ? 0 : $chrnx_seed_page_ids['subscribe'] );
update_option( 'permalink_structure', '/%postname%/' );
flush_rewrite_rules( false );
WP_CLI::log(
sprintf(
'CHRNX_FIXTURES pages=%d posts=%d front=%d',
'CHRNX_FIXTURES pages=%d posts=%d front=%d scenario=%s',
count( $chrnx_seed_page_ids ),
count( $chrnx_seed_post_ids ),
$chrnx_seed_page_ids['home']
$chrnx_seed_page_ids['home'],
$chrnx_seed_scenario
)
);
+10 -1
View File
@@ -4,6 +4,15 @@ set -eu
chrnx_script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
chrnx_project_dir=$(dirname -- "$chrnx_script_dir")
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) ;;
*)
echo "Unknown local fixture scenario: $chrnx_seed_scenario" >&2
exit 2
;;
esac
if [ ! -x "$chrnx_docker_cli_dir/docker" ]; then
echo "Docker CLI not found at the approved Colima path: $chrnx_docker_cli_dir/docker" >&2
@@ -19,4 +28,4 @@ case "$chrnx_seed_probe" in
exit 1
;;
esac
PATH="$chrnx_docker_cli_dir:$PATH" npm exec -- wp-env run cli wp eval-file wp-content/themes/chrnx/scripts/seed-test-content.php
PATH="$chrnx_docker_cli_dir:$PATH" npm exec -- wp-env run cli wp eval-file wp-content/themes/chrnx/scripts/seed-test-content.php "$chrnx_seed_scenario"
+148 -3
View File
@@ -1,5 +1,18 @@
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 },
@@ -77,7 +90,10 @@ test( 'long, incomplete, empty, and missing states stay usable', async ( { page
await page.goto( '/conversacion-pendiente-de-datos-editoriales/' );
await expect(
page.getByRole( 'heading', { level: 1, name: 'Conversación pendiente de datos editoriales' } ),
page.getByRole( 'heading', {
level: 1,
name: 'Conversación pendiente de datos editoriales',
} ),
).toBeVisible();
await expect( page.locator( '.chrnx-podcast-meta' ) ).toHaveCount( 0 );
@@ -85,15 +101,144 @@ test( 'long, incomplete, empty, and missing states stay usable', async ( { page
await expect( page.locator( 'pre code' ) ).toContainText( 'const state' );
await expectNoHorizontalOverflow( page );
for ( const [ path, title ] of [
[
'/long-title-night-writing-fixture/',
'Escribir cuando la casa por fin se queda en silencio',
],
[
'/una-cuerda-rota-tambien-puede-decidir-el-arreglo/',
'Una cuerda rota también puede decidir el arreglo',
],
[ '/nota-local-sin-extracto/', 'Nota local sin extracto' ],
[ '/note-without-topic/', 'Note without a topic' ],
[ '/nota-sin-idioma-asignado/', 'Nota sin idioma asignado' ],
] ) {
await page.goto( path );
await expect( page.getByRole( 'heading', { level: 1 } ) ).toContainText( title );
await expectNoHorizontalOverflow( page );
}
await expect( page.locator( '.chrnx-entry__meta a', { hasText: 'English' } ) ).toHaveCount( 0 );
await page.goto( '/unbroken-token-overflow-test/' );
await expect( page.locator( 'pre code' ) ).toContainText(
'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
);
await expectNoHorizontalOverflow( page );
await page.goto( '/journal/?chrnx_topic=..%2F..%2Fcode&chrnx_language%5B%5D=en&s%5B%5D=x' );
await expect( page.locator( 'select[name="chrnx_topic"]' ) ).toHaveValue( '' );
await expect( page.locator( 'select[name="chrnx_language"]' ) ).toHaveValue( '' );
await expect( page.locator( '.chrnx-journal-stream__filters input[name="s"]' ) ).toHaveValue(
'',
);
await expectNoHorizontalOverflow( page );
await page.goto( '/this-route-does-not-exist/' );
await expect( page ).toHaveTitle( /Page not found/i );
await expect( page.getByRole( 'heading', { level: 1, name: 'Page not found' } ) ).toBeVisible();
} );
test( 'cards without featured media use CSS-only topic treatments', async ( { page } ) => {
await page.goto( '/' );
const fallbacks = page.locator(
'.chrnx-featured-story__fallback, .chrnx-journal-card__fallback, .chrnx-podcast-card__fallback',
);
await expect( fallbacks.first() ).toBeVisible();
expect( await fallbacks.locator( 'img' ).count() ).toBe( 0 );
for ( const fallback of await fallbacks.all() ) {
const background = await fallback.evaluate(
( element ) => window.getComputedStyle( element ).backgroundImage,
);
expect( background ).not.toMatch( /alter-ego-|the-no-names-musician-cutout/ );
}
} );
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,
} ) => {
await page.goto( '/silicon-ranch-conversaciones-sin-diapositivas/' );
await expect( page.getByRole( 'link', { name: 'Open canonical episode page' } ) ).toHaveAttribute(
'href',
'https://example.test/local-podcast-episode',
);
await expect( page.locator( 'iframe, audio' ) ).toHaveCount( 0 );
await page.goto( '/conversacion-pendiente-de-datos-editoriales/' );
await expect( page.locator( '.chrnx-podcast-meta, iframe, audio' ) ).toHaveCount( 0 );
await expect( page.getByRole( 'link', { name: 'Open canonical episode page' } ) ).toHaveCount(
0,
);
} );
test( 'site routes preserve heading order, named landmarks, and skip-link keyboard flow', async ( {
page,
}, testInfo ) => {
for ( const path of [ '/', '/music/', '/podcasts/', '/about/', '/topic/code/', '/journal/' ] ) {
await page.goto( path );
const headings = await page
.locator( 'h1, h2, h3, h4, h5, h6' )
.evaluateAll( ( nodes ) => nodes.map( ( node ) => Number( node.tagName.slice( 1 ) ) ) );
expect( headings.filter( ( level ) => level === 1 ) ).toHaveLength( 1 );
for ( let index = 1; index < headings.length; index += 1 ) {
expect(
headings[ index ] - headings[ index - 1 ],
`${ path } heading sequence`,
).toBeLessThanOrEqual( 1 );
}
await expect( page.getByRole( 'banner' ) ).toHaveCount( 1 );
await expect( page.getByRole( 'main' ) ).toHaveCount( 1 );
await expect( page.getByRole( 'contentinfo' ) ).toHaveCount( 1 );
const landmarkNames = await page
.locator( 'nav' )
.evaluateAll( ( nodes ) => nodes.map( ( node ) => node.getAttribute( 'aria-label' ) ) );
expect( landmarkNames.every( Boolean ) ).toBeTruthy();
expect( new Set( landmarkNames ).size ).toBe( landmarkNames.length );
if ( testInfo.project.name === 'chromium' ) {
await page.keyboard.press( 'Tab' );
const skip = page.getByRole( 'link', { name: 'Skip to content' } );
await expect( skip ).toBeFocused();
await skip.press( 'Enter' );
await expect( page.locator( 'main#chrnx-main' ) ).toBeFocused();
}
}
} );
test( 'reduced motion removes card transitions while theme preference remains user-controlled', async ( {
page,
} ) => {
await page.emulateMedia( { reducedMotion: 'reduce', colorScheme: 'light' } );
await page.emulateMedia( {
reducedMotion: 'reduce',
colorScheme: 'light',
} );
await page.goto( '/' );
const card = page.locator( '.chrnx-featured-story' ).first();
const duration = await card.evaluate( ( element ) =>
@@ -111,7 +256,7 @@ test( 'key public surfaces pass automated WCAG 2.2 AA checks', async ( { page },
'One engine is sufficient for deterministic axe rules.',
);
const tags = [ 'wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa', 'wcag22aa' ];
for ( const viewport of [ viewports[ 0 ], viewports[ 2 ] ] ) {
for ( const viewport of viewports ) {
await page.setViewportSize( viewport );
for ( const path of [
'/',
+41 -1
View File
@@ -28,6 +28,7 @@
},
{
"fixtureKey": "post-literature-long",
"slug": "long-title-night-writing-fixture",
"title": "Escribir cuando la casa por fin se queda en silencio y cada pequeño ruido parece tener una opinión larguísima sobre el borrador abierto",
"excerpt": "Notas sobre escribir de noche, editar sin piedad y conservar la parte que todavía respira.",
"content": "<!-- wp:paragraph --><p>La noche no vuelve más inteligente al texto, pero sí deja escuchar dónde está fingiendo.</p><!-- /wp:paragraph -->",
@@ -37,6 +38,7 @@
},
{
"fixtureKey": "post-music-studio",
"slug": "una-cuerda-rota-tambien-puede-decidir-el-arreglo",
"title": "Una cuerda rota también puede decidir el arreglo",
"excerpt": "Diario de producción de The No Names: estudio crudo, cero live.",
"content": "<!-- wp:paragraph --><p>La toma no quedó limpia. Quedó viva, que para este disco importa bastante más.</p><!-- /wp:paragraph -->",
@@ -53,7 +55,8 @@
"language": "es",
"show": "silicon-ranch",
"episodeNumber": 2,
"episodeDuration": "58:24"
"episodeDuration": "58:24",
"canonicalEpisodeUrl": "https://example.test/local-podcast-episode"
},
{
"fixtureKey": "post-podcast-missing-meta",
@@ -103,5 +106,42 @@
"content": "<!-- wp:quote --><blockquote class=\"wp-block-quote\"><p>La tinta sabía algo que el narrador todavía no.</p></blockquote><!-- /wp:quote -->",
"topic": "literature",
"language": "es"
},
{
"fixtureKey": "post-missing-excerpt",
"slug": "nota-local-sin-extracto",
"title": "Nota local sin extracto",
"content": "<!-- wp:paragraph --><p>Fixture local para comprobar el resumen ausente.</p><!-- /wp:paragraph -->",
"topic": "life",
"language": "es",
"fixtureState": "missing-excerpt"
},
{
"fixtureKey": "post-missing-topic",
"slug": "note-without-topic",
"title": "Note without a topic",
"excerpt": "A local fixture with no editorial topic.",
"content": "<!-- wp:paragraph --><p>The theme must not infer a private identity or category.</p><!-- /wp:paragraph -->",
"language": "en",
"fixtureState": "missing-topic"
},
{
"fixtureKey": "post-missing-language",
"slug": "nota-sin-idioma-asignado",
"title": "Nota sin idioma asignado",
"excerpt": "Fixture local sin taxonomía de idioma.",
"content": "<!-- wp:paragraph --><p>El contenido permanece legible sin inventar metadatos.</p><!-- /wp:paragraph -->",
"topic": "research",
"fixtureState": "missing-language"
},
{
"fixtureKey": "post-unbroken-code",
"slug": "unbroken-token-overflow-test",
"title": "Unbroken token overflow test",
"excerpt": "A deliberately hostile local layout fixture.",
"content": "<!-- wp:code --><pre class=\"wp-block-code\"><code>ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789</code></pre><!-- /wp:code -->",
"topic": "code",
"language": "en",
"fixtureState": "unbroken-code"
}
]
+14 -1
View File
@@ -460,7 +460,8 @@ class BlockRenderingTest extends WP_UnitTestCase {
$this->assertStringContainsString( 'alt=""', $output );
$this->assertStringContainsString( 'width="1122"', $output );
$this->assertStringContainsString( 'height="1402"', $output );
$this->assertStringContainsString( 'loading="lazy"', $output );
$this->assertStringContainsString( 'loading="eager"', $output );
$this->assertStringContainsString( 'fetchpriority="high"', $output );
$this->assertStringContainsString( 'decoding="async"', $output );
$unsafe = render_block(
@@ -635,6 +636,18 @@ class BlockRenderingTest extends WP_UnitTestCase {
$this->assertStringNotContainsString( '<img', $output );
}
/** Topic heroes are the section surface and prioritize their approved portrait. */
public function test_topic_hero_portrait_is_eager_and_high_priority() {
$output = render_block(
array(
'blockName' => 'chrnx/topic-hero',
'attrs' => array( 'topic' => 'code' ),
)
);
$this->assertStringContainsString( 'loading="eager"', $output );
$this->assertStringContainsString( 'fetchpriority="high"', $output );
}
/** Journal pagination preserves only validated filters in actual rendered links. */
public function test_journal_pagination_links_preserve_only_valid_bounded_filters() {
$raw_search = 'needle' . str_repeat( 'x', 150 ) . '<b>unsafe</b>';
+9
View File
@@ -27,4 +27,13 @@ class ResponsiveMediaTest extends WP_UnitTestCase {
public function test_unknown_topic_portrait_returns_empty_markup() {
$this->assertSame( '', chrnx_get_topic_portrait_markup( '../../private', '', '' ) );
}
/** Above-fold art opts into eager high-priority loading while defaults remain lazy. */
public function test_topic_portrait_loading_is_explicitly_allowlisted() {
$eager = chrnx_get_topic_portrait_markup( 'code', '', '', 'eager' );
$this->assertStringContainsString( 'loading="eager"', $eager );
$this->assertStringContainsString( 'fetchpriority="high"', $eager );
$this->assertStringContainsString( 'loading="lazy"', chrnx_get_topic_portrait_markup( 'code' ) );
$this->assertStringNotContainsString( 'fetchpriority="high"', chrnx_get_topic_portrait_markup( 'code', '', '', 'invalid' ) );
}
}
+13
View File
@@ -87,6 +87,19 @@ class SettingsTest extends WP_UnitTestCase {
$this->assertSame( '', chrnx_get_subscribe_url() );
}
/** An unavailable setting cannot fall through to the current global page. */
public function test_subscribe_url_rejects_zero_even_with_a_global_page() {
$page = self::factory()->post->create_and_get(
array(
'post_type' => 'page',
'post_status' => 'publish',
)
);
$GLOBALS['post'] = $page;
update_option( 'chrnx_subscribe_page_id', 0 );
$this->assertSame( '', chrnx_get_subscribe_url() );
}
/** Field callback uses the core page dropdown and escaped description. */
public function test_subscribe_field_renders_a_core_page_dropdown() {
self::factory()->post->create(
+50 -7
View File
@@ -1,5 +1,8 @@
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { mkdtempSync, readFileSync, readdirSync, rmSync, statSync } from 'node:fs';
import { execFileSync } from 'node:child_process';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { test } from 'node:test';
const read = ( path ) => readFileSync( new URL( `../../${ path }`, import.meta.url ), 'utf8' );
@@ -18,6 +21,13 @@ test( 'local visual fixtures define stable pages and representative editorial st
assert.ok( posts.some( ( post ) => post.content.includes( 'wp:code' ) ) );
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-media' ) );
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-podcast-meta' ) );
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-excerpt' && !( 'excerpt' in post ) ) );
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-topic' && !( 'topic' in post ) ) );
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-language' && !( 'language' in post ) ) );
assert.ok( posts.some( ( post ) => post.fixtureState === 'unbroken-code' && /[A-Z0-9]{256}/.test( post.content ) ) );
assert.ok( posts.some( ( post ) => /^https:\/\//.test( post.canonicalEpisodeUrl ?? '' ) ) );
assert.ok( posts.some( ( post ) => post.fixtureState === 'missing-podcast-meta' && !( 'canonicalEpisodeUrl' in post ) ) );
assert.equal( new Set( posts.map( ( post ) => post.fixtureKey ) ).size, posts.length );
for ( const topic of [ 'code', 'research', 'gaming', 'literature', 'music', 'podcasts', 'life' ] ) {
assert.ok( posts.some( ( post ) => post.topic === topic ), `missing ${ topic } fixture` );
}
@@ -29,7 +39,10 @@ test( 'the seed entrypoint is explicitly local-only and uses a stable fixture ke
assert.match( shell, /localhost|127\.0\.0\.1/ );
assert.match( shell, /wp eval-file/ );
assert.match( shell, /featured-1/ );
assert.match( shell, /subscribe-unavailable/ );
assert.match( php, /_chrnx_fixture_key/ );
assert.match( php, /canonical_episode_url/ );
assert.match( php, /show_on_front/ );
assert.match( php, /page_on_front/ );
assert.match( php, /page_for_posts/ );
@@ -46,15 +59,45 @@ test( 'the visual layer is separately enqueued and covers responsive accessible
assert.match( components, /html\[data-theme="light"\]/ );
} );
test( 'all approved portraits expose reproducible WebP and AVIF derivatives', () => {
for ( const topic of [ 'code', 'gaming', 'life', 'literature', 'podcasts', 'research' ] ) {
const manifest = JSON.parse( read( `assets/images/generated/alter-ego-${ topic }.json` ) );
assert.equal( manifest.source, `alter-ego-${ topic }.png` );
assert.deepEqual( manifest.formats, [ 'avif', 'webp' ] );
assert.deepEqual( manifest.widths, [ 384, 768 ] );
test( 'all approved portraits rebuild byte-identically within payload bounds', () => {
const output = mkdtempSync( join( tmpdir(), 'chrnx-image-test-' ) );
const unsafeOutput = join( output, 'unsafe-output' );
try {
assert.throws( () => execFileSync( './scripts/build-responsive-images.sh', [ unsafeOutput ], { cwd: new URL( '../..', import.meta.url ) } ) );
execFileSync( './scripts/build-responsive-images.sh', [ output ], { cwd: new URL( '../..', import.meta.url ) } );
const names = readdirSync( output ).sort();
assert.equal( names.length, 35 );
let total = 0;
for ( const name of names ) {
const generated = readFileSync( join( output, name ) );
const committed = readFileSync( new URL( `../../assets/images/generated/${ name }`, import.meta.url ) );
assert.deepEqual( generated, committed, `${ name } must rebuild byte-identically` );
if ( /\.(?:avif|webp)$/.test( name ) ) {
assert.ok( statSync( join( output, name ) ).size <= 160 * 1024, `${ name } exceeds 160 KiB` );
const expectedWidth = Number( name.match( /-(384|768)\.(?:avif|webp)$/ )[ 1 ] );
const dimensions = execFileSync( 'sips', [ '-g', 'pixelWidth', '-g', 'pixelHeight', join( output, name ) ], { encoding: 'utf8' } );
assert.match( dimensions, new RegExp( `pixelWidth: ${ expectedWidth }` ) );
assert.match( dimensions, /pixelHeight: [1-9][0-9]*/ );
if ( name.endsWith( '.webp' ) ) {
assert.equal( generated.subarray( 0, 4 ).toString(), 'RIFF' );
assert.equal( generated.subarray( 8, 12 ).toString(), 'WEBP' );
} else {
assert.equal( generated.subarray( 4, 12 ).toString(), 'ftypavif' );
}
total += generated.length;
}
}
assert.ok( total <= 1.7 * 1024 * 1024, `derivatives exceed 1.7 MiB: ${ total }` );
} finally {
rmSync( output, { recursive: true, force: true } );
}
} );
test( 'post-card CSS fallbacks never reuse approved section portraits', () => {
const components = read( 'assets/css/components.css' );
assert.doesNotMatch( components, /url\([^)]*(?:alter-ego-|the-no-names-musician-cutout)/ );
} );
test( 'front page and section pages connect the real editorial patterns', () => {
const front = read( 'templates/front-page.html' );
assert.match( front, /chrnx\/home-intro/ );