Skip to content

test(server): add route-level integration tests for migrated tool_use services - #3637

Merged
bokelley merged 1 commit into
mainfrom
claude/issue-3621-route-level-tool-use-integration-tests
Apr 30, 2026
Merged

bokelley merged 1 commit into
mainfrom
claude/issue-3621-route-level-tool-use-integration-tests

Conversation

@bokelley

Copy link
Copy Markdown
Contributor

Summary

Closes #3621.

Adds four integration tests that pin the tool_use output → DB write contract for the four services migrated to typed input_schema tool invocations in PR #3611. Without these tests, a drift in the tool_use response shape (e.g. action returning undefined) would let unit tests pass while silently persisting malformed data to the DB.

  • brand-classifier-route.test.ts — POST /api/admin/brand-enrichment/domain/:domain → brands row has keller_type, house_domain, confidence, related_domains from classify_brand tool output
  • brand-enrichment-route.test.ts — POST /api/admin/brand-enrichment/expand-house/:domain → brands rows seeded with correct house_domain + keller_type from discover_sub_brands output; also covers the tool_use-missing → 500 path
  • property-enhancement-function.test.ts — enhanceProperty() (no HTTP route; called from MCP tool) → hosted_properties.adagents_json.ext.enhancement.ai_analysis written from analyze_property output
  • prospect-triage-function.test.ts — triageEmailDomain() (no HTTP route; called from webhooks/batch) → TriageResult + prospect_triage_log row match assess_prospect output; covers priority default and early-skip path

Pattern

All four files follow the brand-properties-parse.test.ts SDK-layer mock pattern:

  • vi.hoisted() + vi.mock('@anthropic-ai/sdk', FakeAnthropic) with a shared mocks.anthropicCreate spy
  • Fail-fast default (mockRejectedValue) overridden per test with mockResolvedValueOnce
  • PID+timestamp domain suffixes for parallel-safe isolation
  • Real DB (migrations + pool) with beforeEach/afterAll cleanup
  • Primary assertions are DB reads after the route/function call, not just response body checks

Notes

  • closeDatabase() in afterAll is the pre-existing shared-pool pattern used throughout server/tests/integration/. The integration test runner (vitest run server/tests/integration) has no fileParallelism: false — this is a systemic risk carried forward from existing files, not introduced here.
  • property-enhancement-function.test.ts mocks whoiser with only the named whoisDomain export (the source uses const { whoisDomain } = await import('whoiser')); the default.whoisDomain key was removed after pre-PR review.
  • prospect-triage-function.test.ts pre-emptively mocks account-management-db.js (createActionItem) even though none of the three test cases reach handleSkipSideEffects, guarding against future test additions that exercise that path.

Test plan

  • npm run test:server-integration -- --reporter=verbose brand-classifier-route passes with DB running
  • npm run test:server-integration -- --reporter=verbose brand-enrichment-route passes
  • npm run test:server-integration -- --reporter=verbose property-enhancement-function passes
  • npm run test:server-integration -- --reporter=verbose prospect-triage-function passes
  • No existing integration tests regress

https://claude.ai/code/session_01RFAvM1RBMzagDAcy5hxZEW


Generated by Claude Code

… services (issue #3621)

Closes #3621. Adds four integration tests that pin the tool_use output →
DB write contract for brand-classifier, brand-enrichment/expandHouse,
property-enhancement, and prospect-triage — the services migrated to
typed input_schema tool invocations in PR #3611.

https://claude.ai/code/session_01RFAvM1RBMzagDAcy5hxZEW
@bokelley
bokelley marked this pull request as ready for review April 30, 2026 10:07
@bokelley
bokelley merged commit 3d78b04 into main Apr 30, 2026
12 of 13 checks passed
@bokelley
bokelley deleted the claude/issue-3621-route-level-tool-use-integration-tests branch April 30, 2026 10:08
bokelley added a commit that referenced this pull request Apr 30, 2026
Build Check was cancelled when #3637 merged so these tests landed
unverified. Subsequent main runs have all been red.

Five issues, fixed forward (production behavior unchanged except for
the next_event days rounding):

- brand-classifier-route + brand-enrichment-route tests used
  '${pid}_${Date.now()}' as the SUFFIX, producing underscored test
  domains. enrichBrand rejects those via /^[a-z0-9.-]+\.[a-z]{2,}$/
  → route returned 500. Switch separator to hyphen.

- property-enhancement-function test mocked AdAgentsManager with
  vi.fn().mockImplementation(...). vi.fn returns a function, not a
  constructor; production calls `new AdAgentsManager()`. Replace
  with a real class.

- prospect-triage-function test raced logTriageDecision, which is
  fire-and-forget by design. Add a small awaitTriageLog poll helper
  instead of changing the production call to await (that would
  alter caller-visible latency for a per-domain triage decision).

- member-context.ts: next_event "in N days" rendered with Math.floor
  on (starts_at - now) / 86_400_000, which flipped "in 5 days" to
  "in 4 days" when a sub-millisecond gap accrued between the test
  setting starts_at and the formatter computing the diff. Switch to
  Math.round — also semantically correct (an event 4.7 days away
  should render as "in 5 days", not "in 4 days").

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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.

Route-level integration tests for migrated tool_use services

2 participants