Skip to content

test(identitybroker): add the per-call harness, fault transport, gateway stand-in, and AS-2 trust test seam - #2784

Merged
ChrisJBurns merged 1 commit into
mainfrom
split/2535-1-test-support
Nov 15, 2026
Merged

ChrisJBurns merged 1 commit into
mainfrom
split/2535-1-test-support

Conversation

@ChrisJBurns

@ChrisJBurns ChrisJBurns commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Part 1 of 4 for #2535 (per-call grant and gateway token). Stack: this PR → #2785 → #2786 → #2783.

Test infrastructure only; no production behaviour changes.

  • internal/testutil/identityharness: the harness AS-1 issues ID-JAGs from a session's grant (step (7)), checking the agent through a harness-owned ActorValidator; a fault transport for the ID-JAG exchange and AS-2 redemption; a gateway (vMCP) stand-in for MCP broker authorizes gateway calls and sends them to the configured gateway #2536/Connect provider accounts at the embedded gateway #2537; JWKSURL() and HasJSONRPCResult. The harness imports no internal/ package (new depguard rule).
  • AS-2 trust test seam: internal/adapter/mcpbroker/internal/as2trust, the opaque mcpbroker.AS2Trust, and mcpbrokertest (StartAS2, TrustAS1), fenced from production code by depguard and Go's internal-package rule. Replaces the unexported as2TrustForTest; as2_test.go migrated.
  • as1servertest.HarnessActorValidator maps the broker's credential check to the harness validator.

Shortcut (marked in code): AS-2 trusts AS-1 only in tests, removed by #2533. The harness AS-1's ID-JAG issuance is retired by #2654 once stacklok/toolhive#6898 (PR stacklok/toolhive#7130) and #6899 ship.

API compatibility

No wire or production change; test support and an unset test-only config field.

…way stand-in, and AS-2 trust test seam

The identity harness's AS-1 issues per-call ID-JAGs, checking actor tokens
through a test-supplied ActorValidator; FaultTransport fails, drops, or
intercepts requests to any authorization server; and a minimal gateway
stand-in needs a bearer token. ToolHiveConfig.AS2Trust, built only through
mcpbrokertest, lets tests make the real AS-2 trust the harness's AS-1.

Co-authored-by: Mecatl <noreply@mecatl.dev>

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Two non-blocking comments inline.

BrokerClient *ToolHiveBrokerClient
// AS2Trust, with AS-2 set up, makes AS-2 trust an ID-JAG issuer; see
// AS2Trust.
AS2Trust AS2Trust

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToolHiveConfig.AS2Trust is exported, so the test-only trust is now part of the production config API. The zero value is safe, but nothing stops production code from calling NewAS2Trust today. The only guard is convention and this comment. Could we add a fence production code can't reach, or at least record that this field is removed with #2533?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #2794: a depguard rule now lets only toolhive_construction.go and mcpbrokertest import as2trust outside tests (a planted production import in the adapter is refused), and the field records that it goes with #2533.

// newTrustingAS2 is AS-2 configured to trust the harness's AS-1, for Alice
// and Bob, through the test-only seam.
// and Bob, through the test-only seam, ToolHiveConfig.AS2Trust.
func newTrustingAS2(t *testing.T) (*identityharness.Harness, as2BrokerClient, *Process) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newTrustingAS2 repeats most of mcpbrokertest.StartAS2: the client secret env var, the ToolHiveConfig, NewToolHiveProcess, the nil check, and the cleanup. The two copies can drift. Could this call StartAS2 with the harness trust, or could StartAS2 take the broker config as a parameter?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #2794, partly: these tests are package mcpbroker, and mcpbrokertest imports mcpbroker, so they cannot call StartAS2 without an import cycle (moving them out would need shims for ~10 unexported helpers). Both setups now build the trust through as2trust.Trust.WithDefaults, and newTrustingAS2 documents why it exists alongside StartAS2.

@ChrisJBurns
ChrisJBurns merged commit 67bd651 into main Nov 15, 2026
50 checks passed
@ChrisJBurns
ChrisJBurns deleted the split/2535-1-test-support branch November 15, 2026 22:29
@toolhive-release-app toolhive-release-app Bot mentioned this pull request Nov 18, 2026
2 tasks
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.

2 participants