Skip to content

Return false from isSupported() when the output modality has no matching capability - #271

Open
jigneshbhavani wants to merge 1 commit into
WordPress:trunkfrom
jigneshbhavani:fix/is-supported-unsupported-output-modality
Open

Return false from isSupported() when the output modality has no matching capability#271
jigneshbhavani wants to merge 1 commit into
WordPress:trunkfrom
jigneshbhavani:fix/is-supported-unsupported-output-modality

Conversation

@jigneshbhavani

Copy link
Copy Markdown

Fixes #270

isSupported() is declared : bool, but the RuntimeException from inferCapabilityFromOutputModalities() propagates straight out of it when the configured output modality has no matching capability. ModalityEnum::document() is the reachable case, since DOCUMENT is a first class modality but CapabilityEnum has nothing to map it to.

This catches that one call and returns false. Asking whether an unsupported modality is supported has a correct answer, and it is no.

Two things kept deliberately narrow:

  • generateResult() is untouched and still throws for the same modality. That is the right behaviour there, and testGenerateResultThrowsExceptionForUnsupportedOutputModality() asserts it.
  • Only the inference call sits inside the try, so a RuntimeException raised anywhere else in isSupported() still propagates.

I also considered changing inferCapabilityFromOutputModalities() to return ?CapabilityEnum and letting each caller decide, which reads a little cleaner, but it changes a shared private method used by the generation path as well. Happy to redo it that way if you would rather.

Testing

testIsSupportedReturnsFalseForUnsupportedOutputModality() fails on trunk with:

WordPress\AiClient\Common\Exception\RuntimeException: Output modality "document" is not yet supported.

src/Builders/PromptBuilder.php:556
src/Builders/PromptBuilder.php:616
tests/unit/Builders/PromptBuilderTest.php:3877

and passes with the patch. Full unit suite green at 1165 tests, 4261 assertions. phpcs and phpstan both clean.

I did not add an @since line to the docblock since I do not know which version this would land in. Say the word and I will add it.

I checked the open PRs that touch nearby code and there is no overlap. #222 adds isSupportedForSoundGeneration(), which passes an explicit capability and never reaches the inference branch, and #254 changes ModelResolver::isSupported(), which is a different method.

isSupported() is declared to return bool, but the RuntimeException from
inferCapabilityFromOutputModalities() propagated out of it when the
configured output modality had no matching capability.

generateResult() still throws for the same modality, which is the
behaviour testGenerateResultThrowsExceptionForUnsupportedOutputModality
asserts.

Fixes WordPress#270
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jigneshbhavani <bejignesh@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@codecov

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.50%. Comparing base (a31b0ec) to head (f9f2bec).

Additional details and impacted files
@@            Coverage Diff            @@
##              trunk     #271   +/-   ##
=========================================
  Coverage     86.49%   86.50%           
- Complexity     1327     1328    +1     
=========================================
  Files            68       68           
  Lines          4295     4297    +2     
=========================================
+ Hits           3715     3717    +2     
  Misses          580      580           
Flag Coverage Δ
unit 86.50% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PromptBuilder::isSupported() throws instead of returning false when the output modality has no matching capability

1 participant