Skip to content

Use Node.js test runner instead of mocha and chai#877

Closed
DZakh wants to merge 38 commits into
mainfrom
dz/nodejs-test-runner
Closed

Use Node.js test runner instead of mocha and chai#877
DZakh wants to merge 38 commits into
mainfrom
dz/nodejs-test-runner

Conversation

@DZakh

@DZakh DZakh commented Dec 29, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • Added multi-ecosystem indexer configuration supporting EVM, Fuel, and SVM chains with dynamic composition.
    • Introduced a terminal UI for real-time monitoring of indexer progress, sync status, and event metrics.
    • Added HTTP endpoints for health checks and state monitoring.
    • Upgraded to Node.js native test runner for improved testing.
  • Chores

    • Switched primary package manager to pnpm.
    • Updated dependencies including UI libraries (ink, ink-big-text, ink-spinner), server (express, yargs), and database tools.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 29, 2025

Copy link
Copy Markdown
Contributor

Caution

Review failed

Failed to post review comments

📝 Walkthrough

Walkthrough

This PR refactors the core indexer architecture from Handlers-based to Indexer-based execution, introduces context-based parameter passing, expands TypeScript configuration types, adds a terminal UI, migrates database access to PgStorage, and updates code generation templates and test frameworks across the codebase.

Changes

Cohort / File(s) Summary
Configuration & Type System
codegenerator/cli/npm/envio/index.d.ts, codegenerator/cli/src/hbs_templating/codegen_templates.rs, codegenerator/cli/templates/dynamic/codegen/src/Types.ts.hbs, codegenerator/cli/src/config_parsing/system_config.rs, codegenerator/cli/src/config_parsing/chain_helpers.rs
Introduces comprehensive IndexerConfig type with ecosystem support (EVM, Fuel, SVM), adds chain/contract configuration types, makes max_reorg_depth optional (Option), and expands public TypeScript type surface for no-code configuration.
Context Refactoring
codegenerator/cli/npm/envio/src/EventProcessing.res, codegenerator/cli/npm/envio/src/GlobalState.res, codegenerator/cli/npm/envio/src/Ctx.res, codegenerator/cli/templates/dynamic/codegen/src/TestHelpers_MockDb.res.hbs
Replaces ~indexer: Indexer.t parameter passing with ~ctx: Ctx.t across core handlers and state management, updates all field access from indexer.persistence/indexer.config to ctx.persistence/ctx.config.
Config Management & Internal Types
codegenerator/cli/npm/envio/src/Config.res, codegenerator/cli/npm/envio/src/Internal.res, codegenerator/cli/npm/envio/src/UserContext.res
Extends Config with name, description, handlers fields; adds codegenContract/codegenChain types; removes chains field from handlerContext; updates fromPublic signature to accept codegenChains parameter.
Handlers → Indexer Migration
scenarios/test_codegen/src/handlers/EventHandlers.res, scenarios/erc20_multichain_factory/src/EventHandlers.res, scenarios/test_codegen/src/handlers/EventHandlers.ts, codegenerator/cli/src/hbs_templating/contract_import_templates.rs
Moves all handler registrations from Handlers.* namespace to Indexer.* namespace; updates TypeScript handlers to use EvmChainId and single context.chain instead of context.chains map.
Handler Context Changes
codegenerator/cli/templates/dynamic/codegen/src/Types.res.hbs, codegenerator/cli/templates/dynamic/codegen/src/Types.ts.hbs, scenarios/test_codegen/test/EventOrigin_test.res
Removes chains map from handlerContext; replaces with single chain property containing id and isLive; updates test setup and assertions accordingly.
Terminal UI & Server
codegenerator/cli/npm/envio/src/tui/Tui.res, codegenerator/cli/npm/envio/src/tui/bindings/Ink.res, codegenerator/cli/npm/envio/src/tui/components/TuiData.res, codegenerator/cli/npm/envio/src/tui/components/SyncETA.res, codegenerator/cli/npm/envio/src/Main.res
Introduces new TUI module with ChainLine, TotalEventsProcessed, App components; adds Ink bindings for terminal rendering; implements HTTP server with /healthz, /console, /metrics endpoints; adds dynamic indexer state management.
Database & Storage
codegenerator/cli/npm/envio/src/PgStorage.res, codegenerator/cli/npm/envio/src/PgStorage.gen.ts, codegenerator/cli/npm/envio/src/PgStorage.res.d.mts, codegenerator/cli/templates/static/codegen/src/db/Db.res, scenarios/test_codegen/test/helpers/DbHelpers.res
Adds PgStorage.makeClient binding for database initialization; replaces Db.makeClient with PgStorage.makeClient across codebase; removes old Db client logic.
Code Generation Templates
codegenerator/cli/templates/dynamic/codegen/src/Generated.res.hbs, codegenerator/cli/templates/dynamic/codegen/src/Indexer.res.hbs, codegenerator/cli/templates/dynamic/codegen/src/Handlers.res.hbs, codegenerator/cli/templates/dynamic/codegen/index.js.hbs, codegenerator/cli/templates/dynamic/codegen/index.d.ts.hbs, codegenerator/cli/templates/dynamic/codegen/internal.config.ts.hbs
Removes Handlers.res template; adds Indexer.res.hbs with {{indexer_code}} placeholder; updates index.js/index.d.ts to export from Indexer.gen; adds internal.config.ts.hbs template; refactors Generated.res to use Config.fromPublic with internalConfigJson.
Entity & Enum Templates
codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs, codegenerator/cli/templates/dynamic/codegen/src/db/Enums.res.hbs
Changes entity name bindings from coerced strings to string literals; removes EntityType enum module; updates allEnums declaration to typed array form; adjusts gql_enum name references.
Chain Helpers & Field Updates
codegenerator/cli/templates/dynamic/codegen/src/db/Entities.res.hbs, scenarios/test_codegen/test/__mocks__/MockConfig.res, scenarios/test_codegen/test/Viem_test.res, codegenerator/cli/templates/static/erc20_template/typescript/config.yaml
Adds name field to Config.chain; updates MockConfig and test references; changes Viem.parseAbi return type from Ethers.abi to EvmTypes.Abi.t; reorganizes erc20_template config structure with contracts/chains sections.
Package & Build Configuration
codegenerator/cli/npm/envio/package.json, codegenerator/cli/npm/envio/package.json.tmpl, codegenerator/cli/npm/envio/rescript.json, .github/workflows/build_and_test.yml, scenarios/test_codegen/package.json, codegenerator/cli/templates/dynamic/codegen/package.json.hbs
Adds express, yargs, ink, postgres dependencies; adds rescript jsx configuration; reorders codegen steps in workflows; replaces mocha with node:test; adds tsx for db scripts; removes @rescript/react from many places.
Test Framework Migration
codegenerator/cli/templates/dynamic/contract_import_templates/rescript/test/Test.res.hbs, codegenerator/cli/templates/dynamic/contract_import_templates/typescript/test/Test.ts.hbs, codegenerator/cli/templates/static/blank_template/rescript/test/Test.res, scenarios/test_codegen/test/test.ts, scenarios/fuel_test/test/test.ts, codegenerator/cli/templates/static/greeter_template/typescript/test/test.ts
Replaces mocha/chai with node:test and node:assert across all test templates; updates test imports in template and scenario files.
Test & Mock Utilities
scenarios/test_codegen/test/EventFilters_test.res, scenarios/test_codegen/test/EventHandler_test.ts, scenarios/test_codegen/test/Indexer_test.res, scenarios/test_codegen/test/Integration_ts_helpers.res, scenarios/test_codegen/test/helpers/Mock.res, scenarios/test_codegen/test/helpers/utils.ts
Adds new indexer type tests; removes makeChainManager export; updates chainId handling and Mock setup; adds chain name field to configs; adds registerAllHandlers await; introduces chainId type alias.
Type Bindings & External APIs
codegenerator/cli/npm/envio/src/bindings/Postgres.res, codegenerator/cli/npm/envio/src/bindings/Postgres.gen.ts, codegenerator/cli/npm/envio/src/bindings/Postgres.res.d.mts, codegenerator/cli/npm/envio/src/bindings/NodeJs.res, codegenerator/cli/npm/envio/src/bindings/Ethers.res, codegenerator/cli/npm/envio/src/Utils.res
Adds Postgres.sql type bindings via genType; introduces Node.js test helpers (Test, Assert modules); removes Ethers.abi and makeAbi; adds enumerablePropertyDescriptor and defineProperty utilities.
Ecosystem & Chain Detection
codegenerator/cli/npm/envio/src/ChainFetcher.res, codegenerator/cli/npm/envio/src/sources/FuelSDK.res, codegenerator/cli/npm/envio/src/LogSelection.res, codegenerator/cli/npm/envio/src/GlobalStateManager.res*
Adds ChainFetcher.isLive function; updates FuelSDK transpileAbi/getLogDecoder to use EvmTypes.Abi.t; adds sentinel value handling for eventFilters; removes stateUpdatedHook from GlobalStateManager.
Build & Documentation
.cursor/rules/navigation.mdc, CONTRIBUTING.md, .gitignore, codegenerator/cli/Cargo.toml, codegenerator/cli/template_dirs.rs, codegenerator/cli/templates/static/codegen/rescript.json
Adds pnpm/assert rules; updates codegen CLI invocation to pnpm; adds .pnpm-store to .gitignore; adds insta dev dependency; comments out subgraph migration test; adjusts rescript.json structure.
Removed Event Handler Templates
codegenerator/cli/templates/dynamic/subgraph_migration_templates/rescript/src/handlers/EventHandlers.res.hbs, codegenerator/cli/templates/dynamic/subgraph_migration_templates/typescript/src/handlers/EventHandlers.ts.hbs
Completely removes subgraph migration event handler scaffolding templates.
Deprecated/Cleanup
codegenerator/cli/templates/static/codegen/src/Index.res, codegenerator/cli/templates/static/codegen/src/ink/EnvioInkApp.res, codegenerator/cli/templates/static/codegen/src/ink/components/ChainData.res
Removes embedded server/TUI logic from Index.res; removes old EnvioInkApp component; removes ChainData component (moved to new tui/ structure).
Schema & Storage Tests
scenarios/test_codegen/test/lib_tests/PgStorage_test.res, scenarios/test_codegen/test/schema_types/BigDecimal_test.res, scenarios/test_codegen/test/schema_types/Timestamp_test.res, scenarios/test_codegen/test/config-with-all-options.yaml
Updates PgStorage initialization to use Enums.allEnums; migrates from Db.makeClient to PgStorage.makeClient; adds new test configuration file with all options.
Configuration & Infrastructure
scenarios/test_codegen/tsconfig.json, scenarios/erc20_multichain_factory/package.json, .github/workflows/build_and_test.yml
Adds tsconfig include field; updates package.json to use node --import tsx for tests; reorders codegen steps relative to pnpm install.

Sequence Diagram(s)

sequenceDiagram
    participant Main as Main.start()
    participant Config as Config.fromPublic()
    participant ChainMgr as ChainManager
    participant GlobalState as GlobalState
    participant EventProc as EventProcessing
    participant Persistence as Persistence/PgStorage
    participant TUI as TUI/Server

    Main->>Config: Parse internalConfigJson + codegenChains
    Config->>Persistence: Initialize DB client (PgStorage.makeClient)
    Config-->>Main: Return Config with merged contracts/ABIs
    
    Main->>ChainMgr: Create with Config
    Main->>Persistence: Load initial state from DB
    
    Main->>GlobalState: Create with ctx (Config + Persistence)
    Main->>TUI: Start TUI + HTTP server
    
    Main->>Main: Dispatch NextQuery(CheckAllChains)
    
    loop Event Processing
        EventProc->>GlobalState: Get state via ctx
        EventProc->>Persistence: Read batches via ctx.persistence
        EventProc->>EventProc: Process events with single chain context
        EventProc->>Persistence: Write entities via ctx.persistence
        EventProc->>GlobalState: Update progress
        GlobalState->>TUI: Emit state changes
    end
    
    TUI->>GlobalState: Poll getState()
    TUI-->>User: Render chain progress/metrics
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

  • Add context.chain #835: Implements the same context.chain refactor replacing handlerContext.chains with a single chain field containing id and isLive properties.
  • Platform & Storage abstractions #819: Introduces similar storage/persistence API refactors and broad platform abstraction changes affecting Config, EventRegister, and template generation across the same files.
  • V3 config.yaml and other breaking changes #848: Implements overlapping V3 breaking changes including removing preload_handlers, switching multichain semantics, and renaming networks→chains.

Suggested reviewers

  • JonoPrest

🐰 Whisker-twitching with glee at this grand refactoring spree!
From Handlers to Indexer, the code now flows so free,
Contexts replace parameters in a choreography divine,
TUI dances on the terminal—what a design!
Chains now singular, ecosystems unite,
This architectural leap makes the future bright!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.62% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly describes the primary change: migrating from mocha and chai test runners to Node.js built-in test runner across the codebase.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dz/nodejs-test-runner

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@DZakh
DZakh changed the base branch from main to dz/indexer-config December 29, 2025 13:43
Base automatically changed from dz/indexer-config to main January 5, 2026 11:19
@DZakh

DZakh commented Jan 6, 2026

Copy link
Copy Markdown
Member Author

Closed in favor of Vitest #884

@DZakh DZakh closed this Jan 6, 2026
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.

1 participant