feat: add responsive CHRNX podcast atmosphere

This commit is contained in:
chrnx committed 2026-08-13 01:01:08 -05:00
1 parent 3840b7c168
commit 6443a46126
13 files changed
+190 -18

No files matched your search

+45
View File
@@ -1,3 +1,4 @@
import json
import shutil
import subprocess
import sys
@@ -9,6 +10,7 @@ from PIL import Image
PROJECT_ROOT = Path(__file__).resolve().parents[2]
ASSET_DIRECTORY = PROJECT_ROOT / "assets" / "images"
GENERATED_DIRECTORY = ASSET_DIRECTORY / "generated"
ALTER_EGO_ASSETS = (
"alter-ego-code.png",
"alter-ego-literature.png",
@@ -19,6 +21,12 @@ ALTER_EGO_ASSETS = (
)
ALTER_EGO_SOURCE_ASSETS = (*ALTER_EGO_ASSETS, "alter-ego-gaming-half-body.png")
BACKGROUND_ASSETS = ("podcast-frequency-grunge.png",)
PODCAST_DERIVATIVES = tuple(
f"podcast-frequency-grunge-{width}.{extension}"
for width in (384, 768, 1536)
for extension in ("avif", "webp")
)
PODCAST_MANIFEST = "podcast-frequency-grunge.json"
CONTACT_SHEET_SCRIPT = PROJECT_ROOT / "scripts" / "build-alter-ego-contact-sheet.py"
@@ -144,6 +152,43 @@ def test_background_asset_inventory_and_image_contract() -> None:
)
def test_podcast_responsive_derivative_inventory_manifest_and_budgets() -> None:
generated_names = sorted(path.name for path in GENERATED_DIRECTORY.iterdir())
assert len(generated_names) == 52, (
f"generated inventory expected 52 files, got {len(generated_names)}"
)
for name in (*PODCAST_DERIVATIVES, PODCAST_MANIFEST):
assert name in generated_names, f"missing {name}"
manifest = json.loads((GENERATED_DIRECTORY / PODCAST_MANIFEST).read_text())
assert manifest == {
"source": "podcast-frequency-grunge.png",
"formats": ["avif", "webp"],
"widths": [384, 768, 1536],
}
family_total = 0
for name in PODCAST_DERIVATIVES:
size = (GENERATED_DIRECTORY / name).stat().st_size
width = int(name.rsplit("-", 1)[1].split(".", 1)[0])
limit = 260 * 1024 if width == 1536 else 160 * 1024
assert size <= limit, f"{name} exceeds {limit} bytes: {size} bytes"
family_total += size
assert family_total <= 620 * 1024, (
"podcast-frequency-grunge family exceeds 620 KiB: "
f"{family_total} total bytes"
)
binary_total = sum(
path.stat().st_size
for path in GENERATED_DIRECTORY.iterdir()
if path.suffix in {".avif", ".webp"}
)
assert binary_total <= 2.75 * 1024 * 1024, (
f"generated binary payload exceeds 2.75 MiB: {binary_total} total bytes"
)
def test_background_contract_rejects_corrupt_idat_data(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
+36
View File
@@ -7,6 +7,42 @@
/** Responsive asset helper coverage. */
class ResponsiveMediaTest extends WP_UnitTestCase {
/** The podcast atmosphere resolves only to its fixed local master and dimensions. */
public function test_podcast_atmosphere_asset_is_allowlisted_with_exact_dimensions() {
$this->assertSame( 'assets/images/podcast-frequency-grunge.png', chrnx_get_topic_art_asset( 'podcast-frequency' ) );
$this->assertSame( array( 1536, 1024 ), chrnx_get_topic_art_dimensions( 'podcast-frequency' ) );
}
/** Podcast atmosphere markup exposes all modern widths and a decorative fallback. */
public function test_podcast_atmosphere_markup_is_responsive_and_decorative() {
$markup = chrnx_get_atmosphere_markup( 'podcast-frequency', 'chrnx-character-stage__frequency' );
$this->assertStringContainsString( '<picture', $markup );
$this->assertStringContainsString( 'class="chrnx-responsive-atmosphere"', $markup );
$this->assertStringContainsString( 'aria-hidden="true"', $markup );
$this->assertStringContainsString( 'type="image/avif"', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-384.avif 384w', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-768.avif 768w', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-1536.avif 1536w', $markup );
$this->assertStringContainsString( 'type="image/webp"', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-384.webp 384w', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-768.webp 768w', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge-1536.webp 1536w', $markup );
$this->assertStringContainsString( 'sizes="(max-width: 780px) 100vw, 1200px"', $markup );
$this->assertStringContainsString( 'podcast-frequency-grunge.png', $markup );
$this->assertStringContainsString( 'class="chrnx-character-stage__frequency"', $markup );
$this->assertStringContainsString( 'width="1536"', $markup );
$this->assertStringContainsString( 'height="1024"', $markup );
$this->assertStringContainsString( 'loading="lazy"', $markup );
$this->assertStringContainsString( 'decoding="async"', $markup );
$this->assertStringContainsString( 'alt=""', $markup );
}
/** Unknown atmosphere keys cannot synthesize asset paths or markup. */
public function test_unknown_atmosphere_returns_empty_markup() {
$this->assertSame( '', chrnx_get_atmosphere_markup( '../../private', 'unsafe class' ) );
}
/** Approved topic portraits render a compact picture element with a PNG fallback. */
public function test_topic_portrait_picture_markup_has_modern_sources_and_dimensions() {
$markup = chrnx_get_topic_portrait_markup( 'code', 'Code workshop portrait', 'chrnx-section-portrait' );
+35 -10
View File
@@ -166,7 +166,7 @@ test( 'lower home sections preserve editorial order and define layered panel tre
}
} );
test( 'all approved portraits rebuild byte-identically within payload bounds', () => {
test( 'all approved responsive media rebuild byte-identically within payload bounds', () => {
const readme = read( 'README.md' );
const documentedCommand = 'mktemp -d "${TMPDIR:-/tmp}/chrnx-responsive.XXXXXX"';
assert.ok( readme.includes( documentedCommand ) );
@@ -182,7 +182,7 @@ test( 'all approved portraits rebuild byte-identically within payload bounds', (
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, 45 );
assert.equal( names.length, 52 );
for ( const name of [
'alter-ego-gaming-half-body-384.avif',
'alter-ego-gaming-half-body-384.webp',
@@ -194,19 +194,37 @@ test( 'all approved portraits rebuild byte-identically within payload bounds', (
'the-no-names-collage-768.avif',
'the-no-names-collage-768.webp',
'the-no-names-collage.json',
'podcast-frequency-grunge-384.avif',
'podcast-frequency-grunge-384.webp',
'podcast-frequency-grunge-768.avif',
'podcast-frequency-grunge-768.webp',
'podcast-frequency-grunge-1536.avif',
'podcast-frequency-grunge-1536.webp',
'podcast-frequency-grunge.json',
] ) {
assert.ok( names.includes( name ), `missing ${ name }` );
}
assert.deepEqual(
JSON.parse( readFileSync( join( output, 'podcast-frequency-grunge.json' ), 'utf8' ) ),
{
source: 'podcast-frequency-grunge.png',
formats: [ 'avif', 'webp' ],
widths: [ 384, 768, 1536 ],
},
);
let total = 0;
let collageTotal = 0;
let gamingHalfBodyTotal = 0;
let podcastTotal = 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 binarySize = statSync( join( output, name ) ).size;
const expectedWidth = Number( name.match( /-(384|768|1536)\.(?:avif|webp)$/ )[ 1 ] );
const binaryLimit = expectedWidth === 1536 ? 260 * 1024 : 160 * 1024;
assert.ok( binarySize <= binaryLimit, `${ name } exceeds ${ binaryLimit } bytes: ${ binarySize } bytes` );
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]*/ );
@@ -223,14 +241,21 @@ test( 'all approved portraits rebuild byte-identically within payload bounds', (
if ( name.startsWith( 'alter-ego-gaming-half-body-' ) ) {
gamingHalfBodyTotal += generated.length;
}
if ( name.startsWith( 'podcast-frequency-grunge-' ) ) {
podcastTotal += generated.length;
}
}
}
assert.ok( collageTotal <= 400 * 1024, `collage derivatives exceed 400 KiB: ${ collageTotal }` );
assert.ok( collageTotal <= 400 * 1024, `collage family exceeds 400 KiB: ${ collageTotal } total bytes` );
assert.ok(
gamingHalfBodyTotal <= 340 * 1024,
`gaming half-body derivatives exceed 340 KiB: ${ gamingHalfBodyTotal }`,
`gaming half-body family exceeds 340 KiB: ${ gamingHalfBodyTotal } total bytes`,
);
assert.ok( total <= 2.4 * 1024 * 1024, `derivatives exceed 2.4 MiB: ${ total }` );
assert.ok(
podcastTotal <= 620 * 1024,
`podcast-frequency-grunge family exceeds 620 KiB: ${ podcastTotal } total bytes`,
);
assert.ok( total <= 2.75 * 1024 * 1024, `generated binary payload exceeds 2.75 MiB: ${ total } total bytes` );
} finally {
rmSync( output, { recursive: true, force: true } );
rmSync( external, { recursive: true, force: true } );
@@ -243,14 +268,14 @@ test( 'post-card CSS fallbacks never reuse approved section portraits', () => {
assert.doesNotMatch( components, /url\([^)]*(?:alter-ego-|the-no-names-musician-cutout)/ );
} );
test( 'podcast background source stays separate from portrait and card fallbacks', () => {
test( 'podcast background source uses fixed art and stays separate from card fallbacks', () => {
assert.ok(
existsSync( new URL( `../../${ PODCAST_BACKGROUND_SOURCE }`, import.meta.url ) ),
`missing ${ PODCAST_BACKGROUND_SOURCE }`,
);
const portraitAllowlist = read( 'inc/queries.php' );
assert.doesNotMatch( portraitAllowlist, /podcast-frequency-grunge\.png/ );
const artAllowlist = read( 'inc/queries.php' );
assert.match( artAllowlist, /'podcast-frequency'\s*=>\s*'podcast-frequency-grunge\.png'/ );
for ( const path of [
'assets/css/components.css',