Skip to content

Fix #52: name each Python script once per method - #108

Open
corgab wants to merge 4 commits into
mainfrom
fix/52-script-name-once
Open

Fix #52: name each Python script once per method#108
corgab wants to merge 4 commits into
mainfrom
fix/52-script-name-once

Conversation

@corgab

@corgab corgab commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Summary

Every Python script name appeared two to four times in AbstractQuantumDriver: at the bridge call and again in each malformed-response message that could follow it. Each method now names its script once.

Stacked on #107. This branch builds on fix/53-response-shape-helper because both touch the same lines of AbstractQuantumDriver. It targets main so CI runs (the workflow only runs for PRs against main), which means the diff shows #107's two commits as well until #107 merges; after that GitHub drops them and only the last two commits remain. Merge #107 first.

Plan

  1. Add a protected callScript(string $script, array $data): array that wraps execute() plus the payload() envelope, so the script name meets the bridge in one place and a custom driver with a script of its own gets the same treatment.
  2. In each of the five methods, hold the name in a local $script, pass it to callScript(), and reuse the same variable for the expectKey() and malformedResponse() calls that follow.

Changes

  • src/Drivers/AbstractQuantumDriver.php: callScript() added next to expectKey(); executeBatch(), runDefinition(), submitTask(), pollTask() and generateEntropy() each hold their script name in one local. The five .py literals in the class are now exactly five, one per method. While there, executeBatch() sends the circuits as a list whatever keys the caller used (the method already normalised keys for validation and events, but not for the payload, so an associative array became a JSON object batch.py could not iterate), and the expectKey() docblock example matches its real call site.
  • tests/Unit/Drivers/AbstractQuantumDriverTest.php: a test proves an associative batch reaches Python as a list.

Tests

Closes #52

…() 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.
Every script name appeared two to four times in AbstractQuantumDriver: at
the bridge call and again in each malformed-response message that could
follow it. Each method now holds the name in one local, hands it to the
new callScript() helper (execute() plus the payload envelope) and reuses
the same variable for expectKey() and malformedResponse(), so a message
can never name a script other than the one that ran.

Closes #52
…ubclasses, fix a docblock example

executeBatch() now array_values() the circuit payload, matching the two
other places in the method that already normalise keys, so a driver called
with an associative array no longer hands batch.py a JSON object.
callScript() is protected so a custom driver's own script gets the same
envelope, and expectKey()'s subject example matches the real call site.
@corgab
corgab changed the base branch from fix/53-response-shape-helper to main September 8, 2026 19:19
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.

[maintainability] Python script names are repeated as string literals throughout AbstractQuantumDriver

1 participant