Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ public function __call( string $name, array $arguments ) {
if ( self::is_generating_method( $name ) ) {
return $this->error;
}
if ( self::is_support_check_method( $name ) ) {
return false;
}
return $this;
}
}
Expand Down
22 changes: 22 additions & 0 deletions tests/phpunit/tests/ai-client/wpAiClientPromptBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2648,6 +2648,28 @@ public function test_support_check_methods_return_false_in_error_state() {
$this->assertFalse( $prompt_builder->is_supported_for_text_generation(), 'is_supported_for_text_generation should return false when in error state' );
}

/**
* Tests that support check methods return false when the wrapped builder throws.
*
* @ticket 65781
*/
public function test_support_check_methods_return_false_when_builder_throws() {
$registry = AiClient::defaultRegistry();
$prompt_builder = new WP_AI_Client_Prompt_Builder( $registry, 'Test text' );

/*
* The document modality has no capability to infer, so the wrapped builder
* throws while determining whether the prompt is supported.
*/
$result = $prompt_builder->as_output_modalities( ModalityEnum::document() )->is_supported();

$this->assertIsBool( $result, 'is_supported should return a boolean' );
$this->assertFalse( $result, 'is_supported should return false when the wrapped builder throws' );

// The error is still recorded, so a generating method returns it.
$this->assertWPError( $prompt_builder->generate_text(), 'The caught error should still be returned by generating methods' );
}

/**
* Tests that generating methods return WP_Error when in error state.
*
Expand Down
Loading