Fix #53: funnel response-shape checks through one expectKey() helper - #107
Open
corgab wants to merge 2 commits into
Open
Fix #53: funnel response-shape checks through one expectKey() helper#107corgab wants to merge 2 commits into
corgab wants to merge 2 commits into
Conversation
…() helper
Five call sites in AbstractQuantumDriver repeated the same check on decoded
Python output: key present, value of the right type, else throw
QuantumExecutionException::malformedResponse() with a hand-written message.
expectKey() now performs the check and words the message once
("expected <subject> to have a \"<key>\" key holding <expected>"), so each
call site states only the script, the key, the predicate and the expected
shape. The count and length checks that are not shape checks stay inline.
Closes #53
…h item, and stop over-claiming counts types pollTask() now hands the status expectKey() validated to TaskSnapshot::fromResponse() instead of letting the snapshot re-parse the key. A batch item that is not an object gets its own message with its index, and the per-item counts check names the item too. The @var annotations on counts say array<mixed>, which is what is_array() proves; CircuitResult owns the value shape.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Five call sites in
AbstractQuantumDriverrepeated the same check on decoded Python output: key present, value of the right type, else throwQuantumExecutionException::malformedResponse()with a hand-written message. Only the script, the key and the type test differed. This PR extracts the helper the issue proposes.Plan
expectKey(array $response, string $script, string $key, Closure $isValid, string $expected, string $subject = 'the response'): mixedthat performs the presence-and-shape check, throws the shared exception with one wording, and returns the validated value.results, per-itemcounts, circuitcounts,task_arn,statusandbitschecks onto it, each passing its own predicate (is_array(...),is_string(...), non-empty string, validTaskStatus).Changes
src/Drivers/AbstractQuantumDriver.php:expectKey()added next topayload(); six checks rewritten as one call each. The message is uniform:expected <subject> to have a "<key>" key holding <expected>., with<subject>defaulting tothe responseand set toresult #<n>for batch items.pollTask()hands the validated status to the snapshot instead of letting it re-parse the key. The@varannotations on counts sayarray<mixed>, which is whatis_array()proves;CircuitResultowns the value shape as before.src/Tasks/TaskSnapshot.php:fromResponse()accepts an optional pre-validatedTaskStatusso the guard and the snapshot agree on the value.tests/Unit/Drivers/AbstractQuantumDriverTest.php: assertions updated to the unified wording; new tests pin the full message for a wrong-type key, prove an absent, null and wrong-type key are all reported the same way, and name the offending batch item.tests/Unit/Tasks/TaskSnapshotTest.php: the pre-validated status is carried as given.Tests
vendor/bin/pint --testpasses.vendor/bin/pest --compact: 797 tests, 1 skipped (791 before: +6).Closes #53