Skip to content

Commit 89e6586

Browse files
authored
Merge pull request #846 from Automattic/fix/845-bounded-form-topology
Keep truncated form topology fallback-only
2 parents 59f8064 + a6f957a commit 89e6586

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

php-transformer/src/ArtifactCompiler/ArtifactCompiler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ private function runtimeDeclarationsFromFallbacks(array $declarations, array $fa
595595
$products[$productSlug] = $row;
596596
}
597597
} elseif ( 'html_form_fallback' === $code && is_array($fallback['controls'] ?? null) ) {
598+
if ( true === ($fallback['control_topology']['truncated'] ?? false) ) continue;
598599
$selector = is_string($fallback['selector'] ?? null) ? $fallback['selector'] : '';
599600
$form = array('selector' => $selector, 'source_path' => $sourcePath, 'form' => is_array($fallback['form'] ?? null) ? $fallback['form'] : array(), 'controls' => array_values(array_filter($fallback['controls'], 'is_array')));
600601
if ( is_array($fallback['control_topology'] ?? null) ) $form['control_topology'] = $fallback['control_topology'];

php-transformer/tests/contract/run.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,13 @@ public function match(DOMElement $element, PatternContext $context): ?array
597597
$assert(128 === count($exactTopology['nodes'] ?? array()) && false === ($exactTopology['truncated'] ?? null), 'form control topology retains exactly the configured node limit without reporting truncation');
598598
$assert(128 === count($overflowTopology['nodes'] ?? array()) && true === ($overflowTopology['truncated'] ?? null), 'form control topology truncates deterministically when one source-ordered control exceeds the node limit');
599599
$assert(64 === ($overflowTopology['nodes'][127]['control'] ?? null), 'node-limit truncation preserves the last in-bounds flat control reference');
600+
$exactTopologyResult = (new ArtifactCompiler())->compile(array('entrypoint' => 'index.html', 'files' => array('index.html' => $boundedTopologyHtml(0))))->toArray();
601+
$overflowTopologyResult = (new ArtifactCompiler())->compile(array('entrypoint' => 'index.html', 'files' => array('index.html' => $boundedTopologyHtml(1))))->toArray();
602+
$runtimeDeclarationKeys = static fn(array $result): array => array_map(static fn(array $declaration): string => ($declaration['kind'] ?? '') . ':' . ($declaration['type'] ?? $declaration['capability'] ?? ''), $result['source_reports']['wordpress_site_plan']['runtime_declarations'] ?? array());
603+
$assert(in_array('entity_collection:forms', $runtimeDeclarationKeys($exactTopologyResult), true), 'complete bounded form topology remains provider-materializable');
604+
$assert(!in_array('entity_collection:forms', $runtimeDeclarationKeys($overflowTopologyResult), true) && !in_array('dependency:form', $runtimeDeclarationKeys($overflowTopologyResult), true), 'truncated form topology remains fallback-only without claiming provider materialization');
605+
$assert('html_form_fallback' === ($overflowTopologyResult['fallbacks'][0]['diagnostic_code'] ?? '') && true === ($overflowTopologyResult['fallbacks'][0]['control_topology']['truncated'] ?? null), 'fallback-only overflow forms retain explicit source-loss evidence');
606+
$assert(isset($overflowTopologyResult['source_reports']['wordpress_site_plan']), 'fallback-only overflow forms still produce a WordPress site plan');
600607
$presentationTopology = ( new HtmlTransformer() )->transform('<main><form><custom-element id="bad id" class="safe bad/token one two three four five six seven eight nine ' . str_repeat('x', 81) . '"><input name="safe"></custom-element><button type="submit">Send</button></form></main>')->toArray()['fallbacks'][0]['control_topology']['nodes'][0] ?? array();
601608
$assert(! isset($presentationTopology['tag']) && ! isset($presentationTopology['source_id']), 'form topology omits unsupported wrapper tags and malformed source IDs');
602609
$assert('safe one two three four five six seven' === ($presentationTopology['class'] ?? ''), 'form topology retains only the first eight bounded safe class tokens');

0 commit comments

Comments
 (0)