|
47 | 47 | $contract = $read_json( rtrim( $wp_codebox_dir, '/' ) . '/contracts/run-agent-task-reusable-workflow-interface.v1.json' ); |
48 | 48 | $assert( 'wp-codebox/reusable-workflow-interface/v1' === ( $contract['schema'] ?? null ), 'WP Codebox producer schema version mismatch.' ); |
49 | 49 | $assert( '.github/workflows/run-agent-task.yml' === ( $contract['workflow'] ?? null ), 'WP Codebox producer contract targets an unexpected workflow.' ); |
| 50 | +$release = $read_json( $root . '/tests/wp-codebox-release.fixture.json' ); |
| 51 | +$release_tag = $release['tag'] ?? null; |
| 52 | +$assert( is_string( $release_tag ) && preg_match( '/^v\d+\.\d+\.\d+$/', $release_tag ) === 1, 'WP Codebox release fixture must declare an exact release tag.' ); |
| 53 | +$assert( substr( $release_tag, 1 ) === ( $release['package_version'] ?? null ), 'WP Codebox release fixture package version must match its tag.' ); |
| 54 | +$producer_package = $read_json( rtrim( $wp_codebox_dir, '/' ) . '/package.json' ); |
| 55 | +$assert( ( $release['package_version'] ?? null ) === ( $producer_package['version'] ?? null ), 'Checked-out WP Codebox package version must match the release fixture.' ); |
50 | 56 |
|
51 | 57 | $workflow = (string) file_get_contents( $root . '/.github/workflows/maintain-docs.yml' ); |
52 | | -$assert( preg_match( '/^\s*uses: Automattic\/wp-codebox\/\.github\/workflows\/run-agent-task\.yml@ca1cc53ea76d09dc53dd02df89e41ad7fe143a27$/m', $workflow ) === 1, 'Docs Agent must call the #1756 producer workflow revision.' ); |
| 58 | +$assert( preg_match( '/^\s*uses: Automattic\/wp-codebox\/\.github\/workflows\/run-agent-task\.yml@' . preg_quote( $release_tag, '/' ) . '$/m', $workflow ) === 1, 'Docs Agent must call the released WP Codebox workflow tag.' ); |
53 | 59 |
|
54 | 60 | preg_match( '/uses: Automattic\/wp-codebox\/\.github\/workflows\/run-agent-task\.yml@[^\n]+\n with:\n(?<inputs>.*?)\n secrets:\n(?<secrets>(?: [^\n]*\n?)*)/s', $workflow, $caller ); |
55 | 61 | $assert( isset( $caller['inputs'], $caller['secrets'] ), 'Docs Agent must declare producer inputs and secrets.' ); |
|
74 | 80 | } |
75 | 81 | } |
76 | 82 |
|
| 83 | +$assert( $release_tag === ( $caller_inputs['wp_codebox_release_ref'] ?? null ), 'Docs Agent must pass the WP Codebox release tag required by the producer contract.' ); |
| 84 | +$is_coherent_release_pair = static function ( string $consumer_workflow ): bool { |
| 85 | + preg_match( '/uses: Automattic\/wp-codebox\/\.github\/workflows\/run-agent-task\.yml@(?<workflow_tag>[^\s]+)/', $consumer_workflow, $workflow_match ); |
| 86 | + preg_match( '/^\s+wp_codebox_release_ref: (?<helper_tag>[^\s]+)$/m', $consumer_workflow, $helper_match ); |
| 87 | + |
| 88 | + return isset( $workflow_match['workflow_tag'], $helper_match['helper_tag'] ) |
| 89 | + && preg_match( '/^v\d+\.\d+\.\d+$/', $workflow_match['workflow_tag'] ) === 1 |
| 90 | + && $workflow_match['workflow_tag'] === $helper_match['helper_tag']; |
| 91 | +}; |
| 92 | +$assert( $is_coherent_release_pair( $workflow ), 'Docs Agent must use matching exact WP Codebox release tags.' ); |
| 93 | +$assert( ! $is_coherent_release_pair( str_replace( 'wp_codebox_release_ref: ' . $release_tag, 'wp_codebox_release_ref: v0.12.3', $workflow ) ), 'A mismatched WP Codebox workflow and helper release tag must fail.' ); |
| 94 | + |
77 | 95 | $caller_secrets = array(); |
78 | 96 | preg_match_all( '/^ (?<name>[A-Z0-9_]+): (?<value>[^\n]+)$/m', $caller['secrets'], $matches, PREG_SET_ORDER ); |
79 | 97 | foreach ( $matches as $match ) { |
|
87 | 105 | } |
88 | 106 | } |
89 | 107 |
|
90 | | -$assert( 'true' === ( $caller_inputs['require_access_token'] ?? null ), 'Docs Agent must require the caller-scoped publication token.' ); |
91 | 108 | $assert( '${{ github.token }}' === ( $caller_secrets['ACCESS_TOKEN'] ?? null ), 'Docs Agent must explicitly forward the caller-scoped GitHub token as ACCESS_TOKEN.' ); |
92 | 109 | $assert( '${{ secrets.OPENAI_API_KEY }}' === ( $caller_secrets['OPENAI_API_KEY'] ?? null ), 'Docs Agent must explicitly forward OPENAI_API_KEY.' ); |
93 | 110 | $assert( '${{ secrets.EXTERNAL_PACKAGE_SOURCE_POLICY }}' === ( $caller_secrets['EXTERNAL_PACKAGE_SOURCE_POLICY'] ?? null ), 'Docs Agent must explicitly forward the external package policy secret.' ); |
|
0 commit comments