Skip to content

test(trace): add anthropic-direct/query.test.ts covering opts.subagentId -> RunTurnInput threading #634

Description

@griffinwork40

Context

Follow-up from the review of #631 (subagentId trace attribution, issue #612). Non-blocking test-coverage finding — severity: low.

AnthropicDirectQuery threads its subagentId from constructor options into each per-turn RunTurnInput:

// src/agent/providers/anthropic-direct/query.ts
subagentId?: string;                                                    // :152 (option)
private readonly subagentId?: string;                                   // :243
if (opts.subagentId !== undefined) this.subagentId = opts.subagentId;   // :293
...(this.subagentId !== undefined ? { subagentId: this.subagentId } : {}),  // :427 (into RunTurnInput)

Gap

There is no dedicated src/agent/providers/anthropic-direct/query.test.ts asserting this class-level opts.subagentId → RunTurnInput.subagentId threading. Evidence (at PR merge commit 40167768): the directory holds only query-auth-retry.test.ts and a query/ subtree — no query.test.ts.

git ls-tree 40167768 src/agent/providers/anthropic-direct/ | grep query
# → query-auth-retry.test.ts, query.ts, query/ (tree) — no query.test.ts

Mitigation (why it's low, not medium)

The loop-level end of the same thread is covered — src/agent/providers/anthropic-direct/loop.trace.test.ts:281 ("tags tool_call started+completed with subagentId when the loop runs inside a fork") drives RunTurnInput.subagentId → emitted event. What's untested is specifically the AnthropicDirectQuery option → RunTurnInput hop. The openai-compatible side already has an equivalent class-level test (src/agent/providers/openai-compatible/query.test.ts — "tags tool_call events with config.subagentId when running inside a fork"), so this is a parity gap on the anthropic side.

Suggested approach / acceptance criteria

  • Add src/agent/providers/anthropic-direct/query.test.ts (or extend a query-level test) that constructs an AnthropicDirectQuery with subagentId set and asserts the emitted tool_call events carry it.
  • Assert the negative: omitting subagentId yields 'subagentId' in payload === false (matches the absent-key-on-root-session contract).
  • Keep it consistent with the existing openai-compatible pattern for symmetry.

Refs: #631 · #612 · sibling of #633

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions