fix(test/delegation): add CanCommunicate mock expectations
Some checks failed
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 5s
Harness Replays / detect-changes (pull_request) Successful in 17s
Lint curl status-code capture / Scan workflows for curl status-capture pollution (pull_request) Successful in 18s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 20s
CI / Detect changes (pull_request) Successful in 1m8s
E2E API Smoke Test / detect-changes (pull_request) Successful in 1m16s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 1m14s
E2E Staging Canvas (Playwright) / detect-changes (pull_request) Successful in 1m15s
qa-review / approved (pull_request) Failing after 23s
security-review / approved (pull_request) Failing after 22s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 57s
gate-check-v3 / gate-check (pull_request) Successful in 34s
sop-tier-check / tier-check (pull_request) Successful in 26s
Harness Replays / Harness Replays (pull_request) Successful in 6s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 24s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 10s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Failing after 5m12s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 6m14s
CI / Python Lint & Test (pull_request) Successful in 7m44s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (pull_request) Successful in 9m17s
CI / Canvas (Next.js) (pull_request) Successful in 14m39s
CI / Platform (Go) (pull_request) Failing after 15m58s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
CI / all-required (pull_request) Failing after 5s

executeDelegation(sourceID, targetID) fires proxyA2ARequest which calls
registry.CanCommunicate(sourceID, targetID) when source != target. Both
IDs are different test fixtures (ws-source-159, ws-target-159), so the
lookup fires two separate getWorkspaceRef queries:

  SELECT id, parent_id FROM workspaces WHERE id = $1  -- sourceID
  SELECT id, parent_id FROM workspaces WHERE id = $1  -- targetID

expectExecuteDelegationBase only mocked the URL/status fallback query.
sqlmock would fail with "unexpected query" when the CanCommunicate
lookups fired — this was a silent failure because the tests never
verified ExpectationWereMet on the CanCommunicate path.

Fix: add two ExpectQuery rows for both parent_id lookups (both NULL,
root-level siblings, allowed).

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Molecule AI · core-be 2026-05-11 23:25:01 +00:00
parent 8c484776dc
commit 5fa9688be3

View File

@ -983,7 +983,16 @@ func expectExecuteDelegationBase(mock sqlmock.Sqlmock) {
WithArgs("dispatched", "", testSourceID, testDelegationID).
WillReturnResult(sqlmock.NewResult(0, 1))
// CanCommunicate (source=target self-call is always allowed — no DB lookup needed)
// CanCommunicate: source != target → fires two getWorkspaceRef lookups.
// Both test fixtures have parent_id = NULL (root-level siblings) → allowed.
// Order matches call order: source first, then target.
mock.ExpectQuery("SELECT id, parent_id FROM workspaces WHERE id").
WithArgs(testSourceID).
WillReturnRows(sqlmock.NewRows([]string{"id", "parent_id"}).AddRow(testSourceID, nil))
mock.ExpectQuery("SELECT id, parent_id FROM workspaces WHERE id").
WithArgs(testTargetID).
WillReturnRows(sqlmock.NewRows([]string{"id", "parent_id"}).AddRow(testTargetID, nil))
// resolveAgentURL: reads ws:{id}:url from Redis, falls back to DB for target
mock.ExpectQuery("SELECT url, status FROM workspaces WHERE id = ").
WithArgs(testTargetID).