Skip to content

Commit 63204bc

Browse files
authored
fix(coderabbit): resolve PR #62 re-review findings (#63)
Three findings from CodeRabbit's re-review of PR #62: 1. TemplateManagerWriteTest.php: a real test-isolation bug — test_update_template_reports_rollback_failure_when_delete_also_fails() added pre_insert_term/pre_delete_post filters and only removed them after update_template() returned. An unexpected exception from that call would skip both remove_filter() calls, leaking the filters into every later test in the same PHP process (any subsequent wp_insert_term()/wp_delete_post() call would be affected). Wrapped the call in try/finally so cleanup always runs. 2. Same file: added `@var \WP_Error $result` narrowing docblocks after four assertInstanceOf(\WP_Error::class, $result) calls, immediately before each result's get_error_code()/get_error_data() calls. composer analyze is already clean on develop (tests/* is excluded from this repo's own PHPStan paths) — applied because it's a trivial, readability-neutral-to-positive one-liner per site, not because our gate required it. 3. src/tools/templates.ts: list_templates' description said a non-null wp_id "is what makes a template editable via update_template" — false. update_template()'s own description (and behavior) already documents that a wp_id:null template is still editable: calling it creates a new override. Reworded to describe wp_id as existing database backing, matching get_template's accurate framing, without implying editability requires it. Manifest/bundle regenerated for the description change (tool count unchanged at 33). This is the last dispatch on the CodeRabbit-follow-up thread. Claude-Session: https://claude.ai/code/session_013YcSbKroBJjPanX3okQrT3
1 parent 53118bd commit 63204bc

4 files changed

Lines changed: 21 additions & 11 deletions

File tree

src/tools/templates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const TEMPLATE_TOOLS = [
2525
{
2626
name: 'list_templates',
2727
description:
28-
'List the active theme\'s templates (page layouts like "single", "archive") or template parts (reusable regions like "header", "footer") — works on a theme without a full block-theme structure too, as long as it has real templates/parts. Each row includes `wp_id` — present (non-null) whenever the template is backed by a database post, whether that\'s an override shadowing a theme file or a fully custom template with none; that\'s what makes it editable via update_template. Returns an empty list with a `note` only when there is truly nothing to list.',
28+
'List the active theme\'s templates (page layouts like "single", "archive") or template parts (reusable regions like "header", "footer") — works on a theme without a full block-theme structure too, as long as it has real templates/parts. Each row includes `wp_id` — present (non-null) when a database post already backs the template (an override shadowing a theme file, or a fully custom template with none); null means it currently resolves purely to the theme file. Every template is editable via update_template regardless — a null `wp_id` just means calling it creates the override rather than updating an existing one. Returns an empty list with a `note` only when there is truly nothing to list.',
2929
annotations: { ...READ_ANNOT, title: 'List templates' },
3030
inputSchema: {
3131
type: 'object' as const,

wordpress-plugin/gk-block-mcp/assets/mcp-server/index.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53604,7 +53604,7 @@ var TEMPLATE_SOURCE_ENUM = ["theme", "plugin", "custom"];
5360453604
var TEMPLATE_TOOLS = [
5360553605
{
5360653606
name: "list_templates",
53607-
description: 'List the active theme\'s templates (page layouts like "single", "archive") or template parts (reusable regions like "header", "footer") \u2014 works on a theme without a full block-theme structure too, as long as it has real templates/parts. Each row includes `wp_id` \u2014 present (non-null) whenever the template is backed by a database post, whether that\'s an override shadowing a theme file or a fully custom template with none; that\'s what makes it editable via update_template. Returns an empty list with a `note` only when there is truly nothing to list.',
53607+
description: 'List the active theme\'s templates (page layouts like "single", "archive") or template parts (reusable regions like "header", "footer") \u2014 works on a theme without a full block-theme structure too, as long as it has real templates/parts. Each row includes `wp_id` \u2014 present (non-null) when a database post already backs the template (an override shadowing a theme file, or a fully custom template with none); null means it currently resolves purely to the theme file. Every template is editable via update_template regardless \u2014 a null `wp_id` just means calling it creates the override rather than updating an existing one. Returns an empty list with a `note` only when there is truly nothing to list.',
5360853608
annotations: { ...READ_ANNOT2, title: "List templates" },
5360953609
inputSchema: {
5361053610
type: "object",

wordpress-plugin/gk-block-mcp/includes/abilities/tools.manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2116,7 +2116,7 @@
21162116
"name": "list_templates",
21172117
"ability": "gk-block-mcp/list-templates",
21182118
"label": "List templates",
2119-
"description": "List the active theme's templates (page layouts like \"single\", \"archive\") or template parts (reusable regions like \"header\", \"footer\") — works on a theme without a full block-theme structure too, as long as it has real templates/parts. Each row includes `wp_id` — present (non-null) whenever the template is backed by a database post, whether that's an override shadowing a theme file or a fully custom template with none; that's what makes it editable via update_template. Returns an empty list with a `note` only when there is truly nothing to list.",
2119+
"description": "List the active theme's templates (page layouts like \"single\", \"archive\") or template parts (reusable regions like \"header\", \"footer\") — works on a theme without a full block-theme structure too, as long as it has real templates/parts. Each row includes `wp_id` — present (non-null) when a database post already backs the template (an override shadowing a theme file, or a fully custom template with none); null means it currently resolves purely to the theme file. Every template is editable via update_template regardless — a null `wp_id` just means calling it creates the override rather than updating an existing one. Returns an empty list with a `note` only when there is truly nothing to list.",
21202120
"input_schema": {
21212121
"type": "object",
21222122
"properties": {

wordpress-plugin/gk-block-mcp/tests/Templates/TemplateManagerWriteTest.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -504,16 +504,22 @@ public function test_update_template_reports_rollback_failure_when_delete_also_f
504504
};
505505
add_filter( 'pre_delete_post', $delete_filter );
506506

507-
$result = $this->tm->update_template(
508-
$this->theme . '//index',
509-
'wp_template',
510-
array( 'content' => '<!-- wp:paragraph --><p>x</p><!-- /wp:paragraph -->' )
511-
);
512-
513-
remove_filter( 'pre_insert_term', $term_filter, 10 );
514-
remove_filter( 'pre_delete_post', $delete_filter );
507+
try {
508+
$result = $this->tm->update_template(
509+
$this->theme . '//index',
510+
'wp_template',
511+
array( 'content' => '<!-- wp:paragraph --><p>x</p><!-- /wp:paragraph -->' )
512+
);
513+
} finally {
514+
// Run on an unexpected exception too — a leftover filter here
515+
// would otherwise contaminate every later term/delete call in
516+
// the same PHP process, not just this test.
517+
remove_filter( 'pre_insert_term', $term_filter, 10 );
518+
remove_filter( 'pre_delete_post', $delete_filter );
519+
}
515520

516521
$this->assertInstanceOf( \WP_Error::class, $result );
522+
/** @var \WP_Error $result */
517523
$this->assertSame( 'rollback_failed', $result->get_error_code() );
518524
$this->assertStringContainsString( 'Simulated taxonomy failure', $result->get_error_message() );
519525
$data = $result->get_error_data();
@@ -600,6 +606,7 @@ public function test_update_template_hybrid_theme_bad_id_returns_not_found_not_c
600606
);
601607

602608
$this->assertInstanceOf( \WP_Error::class, $result );
609+
/** @var \WP_Error $result */
603610
$this->assertSame( 'not_found', $result->get_error_code() );
604611
$data = $result->get_error_data();
605612
$this->assertSame( 404, $data['status'] );
@@ -617,6 +624,7 @@ public function test_reset_template_hybrid_theme_bad_id_returns_not_found_not_cl
617624
$result = $this->tm->reset_template( 'hybrid-theme//does-not-exist', 'wp_template_part' );
618625

619626
$this->assertInstanceOf( \WP_Error::class, $result );
627+
/** @var \WP_Error $result */
620628
$this->assertSame( 'not_found', $result->get_error_code() );
621629
$data = $result->get_error_data();
622630
$this->assertSame( 404, $data['status'] );
@@ -635,6 +643,7 @@ public function test_update_template_classic_theme_still_returns_400_when_nothin
635643
$result = $this->tm->update_template( 'default//does-not-exist', 'wp_template', array( 'content' => '<!-- wp:paragraph --><p>x</p><!-- /wp:paragraph -->' ) );
636644

637645
$this->assertInstanceOf( \WP_Error::class, $result );
646+
/** @var \WP_Error $result */
638647
$this->assertSame( 'classic_theme', $result->get_error_code() );
639648
$data = $result->get_error_data();
640649
$this->assertSame( 400, $data['status'] );
@@ -651,6 +660,7 @@ public function test_reset_template_classic_theme_still_returns_400_when_nothing
651660
$result = $this->tm->reset_template( 'default//does-not-exist', 'wp_template' );
652661

653662
$this->assertInstanceOf( \WP_Error::class, $result );
663+
/** @var \WP_Error $result */
654664
$this->assertSame( 'classic_theme', $result->get_error_code() );
655665
$data = $result->get_error_data();
656666
$this->assertSame( 400, $data['status'] );

0 commit comments

Comments
 (0)