Skip to content

Feat/anticapture client#257

Merged
LeonardoVieira1630 merged 60 commits into
devfrom
feat/anticapture_client
May 18, 2026
Merged

Feat/anticapture client#257
LeonardoVieira1630 merged 60 commits into
devfrom
feat/anticapture_client

Conversation

@LeonardoVieira1630
Copy link
Copy Markdown
Member

@LeonardoVieira1630 LeonardoVieira1630 commented May 13, 2026

Summary

Migrates the entire monorepo from Jest to Vitest, replaces hand-rolled HTTP/GraphQL mocks in integrated tests with MSW, and refactors packages/anticapture-client to delegate to the upstream @anticapture/client SDK instead of maintaining its own GraphQL codegen pipeline. The result is a smaller, type-safer client (local query files, codegen output, and generated gql/* artifacts are removed) and a uniform testing setup across all apps and packages, with Simple<Name> in-memory doubles replacing scattered vi.fn()/jest.mock usage.

Changes

Test runner migration (Jest → Vitest)

  • Removed all jest.config.{js,ts} files and added vitest.config.ts in every workspace: apps/consumers, apps/dispatcher, apps/integrated-tests, apps/logic-system, apps/subscription-server, packages/anticapture-client, packages/messages.
  • Updated each package.json to use Vitest scripts and dependencies; refreshed pnpm-lock.yaml accordingly.
  • Rewrote test files across consumers, dispatcher, logic-system, and anticapture-client to use Vitest APIs.

Integrated tests: MSW + simpler doubles

  • Added apps/integrated-tests/src/setup/msw-server.ts and Vitest setup files (setup/vitest/global-setup.ts, setup/vitest/setup.ts); removed the old setup/jest/* and mocks/* (graphql-mock-setup, http-client-mock, slack/telegram mock setups, ens-resolver-mock, jest-mock-factory).
  • Introduced Simple<Name> test clients: test-clients/simple-slack.client.ts, test-clients/simple-telegram.client.ts; removed the older slack-test.client.ts / telegram-test.client.ts.
  • Refactored every integration test under tests/core, tests/slack, and tests/telegram to use MSW handlers and the new doubles; standardized factory and helper usage in src/fixtures/factories/* and src/helpers/*.

anticapture-client rewrite over @anticapture/client SDK

  • Replaced the local GraphQL pipeline with the SDK: deleted codegen.yaml, the queries/*.graphql files, src/gql/* (fragment-masking, gql, graphql, index), local schemas.ts, and the corresponding generated dist/gql/* artifacts.
  • Rewrote src/anticapture-client.ts to consume SDK types and methods; migrated each method incrementally (constructor + getDAOs, simple per-DAO methods, listProposals per-DAO and fan-out, listVotingPowerHistory, listRecentVotesFromAllDaos plus offchain variant); fixed fan-out guard in getOffchainProposalNonVoters and added edge-case tests.
  • Added src/with-retry-and-timeout.ts helper plus tests; added src/test-doubles.ts and src/types.ts (re-exported from index.ts).
  • Added @anticapture/client as a dependency and documented the SDK surface in packages/anticapture-client/AGENTS.md.

New interfaces and testability

  • Added IVotingPowerRepository, INotificationClientFactory, IEnsResolver, and an IAnticaptureClient plus noopAnticaptureClient for use in tests.
  • Promoted selected private properties to protected in trigger/dispatcher services so tests can exercise them without mocking.
  • Strengthened dispatcher typing and updated notification-factory, subscription-client, trigger-processor, and all trigger services to consume the new interfaces and SDK-sourced types.

Logic system tests

  • Renamed tests/mocks.tstests/fixtures.ts and added tests/simple-doubles.ts; updated every trigger test (new-proposal, new-offchain-proposal, proposal-finished, offchain-proposal-finished, offchain-vote-cast, voting-power, voting-reminder, threshold-repository, base-trigger) to use the new pattern.

Docs and configuration

  • Added a Vitest + MSW migration design spec under docs/ and updated AGENTS.md files in consumers, dispatcher, integrated-tests, logic-system, subscription-server, and anticapture-client.
  • Minor tweaks to .env.example, docker-compose.yml, and per-app env configs.

LeonardoVieira1630 and others added 30 commits April 30, 2026 11:28
- Pin retry to manual exponential backoff (no new dependency)
- Flag setClientConfig shape as an early-validation assumption
- Clarify smoke-test criterion as qualitative

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…surface

Installs @anticapture/client ^1.0.0. Appends verified SDK surface section
to the migration spec: function mapping, client config shape (no
setClientConfig — per-call config.client closure pattern), enum value
differences (OrderDirection lowercase, QueryInput_* aliases needed), type
shape differences (OffchainProposal richer, Voter has extra fields), and
integrated-tests decision (skip with TODO in this PR).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…icapture/client

- Replace AxiosInstance constructor with AnticaptureClientConfig (baseURL, defaultHeaders, maxRetries, timeoutMs)
- Build sdkConfig passed to every SDK call instead of global mutation
- Implement getDAOs using getDaos() from @anticapture/client; stub all other methods
- Rewrite test-helpers.ts with MSW server factory and daosResponse helper
- Rewrite anticapture-client.test.ts with MSW-based getDAOs tests; skip unmigrated blocks
- Skip offchain-proposal.test.ts (listOffchainProposals not migrated yet)
- Add @anticapture+client to jest transformIgnorePatterns to handle ESM package

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…capture/client

Implements getProposalById, getEventThreshold, listVotes, getProposalNonVoters,
getOffchainProposalNonVoters, and listOffchainVotes using real SDK calls with
fan-out for proposal lookups. Adds MSW tests for all 6 methods (happy + error paths).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…oters; add missing edge-case tests

- Fix `res?.items?.length >= 0` → `res?.items != null` so an empty array from one DAO doesn't terminate the fan-out early
- Add explanatory comments on all `as any` casts for SDK dao params
- Add test: returns empty array on 500 from all offchain DAOs
- Add test: skips DAO on non-404 server error and continues to next DAO

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace stub with real SDK implementation using historicalVotingPower.
Supports per-DAO mode and parallel fan-out across all DAOs with ASC timestamp sort.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…fchain variant

Replaces 'not migrated yet' stubs with real fan-out implementations that delegate to already-migrated listVotes/listOffchainVotes methods, filter offchain-only DAOs, and sort results ASC by timestamp.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@LeonardoVieira1630 LeonardoVieira1630 added the enhancement New feature or request label May 14, 2026
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

all of these should be removed and rely on the turbo repo

Comment thread apps/logic-system/src/repositories/threshold.repository.ts Outdated
Comment thread apps/logic-system/src/repositories/voting-power.repository.ts Outdated
Comment thread apps/logic-system/src/triggers/proposal-finished-trigger.ts Outdated
LeonardoVieira1630 and others added 6 commits May 18, 2026 13:41
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…-tests

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…e-client tests

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants