@xyo-network/event-kit-vitest-config

中文文档
2.3.4发布于 2026/11/03LGPL-3.0-onlyTypeScriptES Module

Vitest preset and owned local XL1 event stack with a real publisher and HTTPS receivers

原始使用文档
文档目录4 节
  1. What runs
  2. Lifecycle and lower-level access
  3. Boundaries
  4. Repository API-local qualification

@xyo-network/event-kit-vitest-config

An opt-in Vitest preset with a real, test-owned local event stack: an XL1 dev-chain child process, hash-addressed REST datalake, resident event publisher, and authenticated HTTPS receivers. Node.js 26 or newer is required; the repository pins Node 26.9.0.

pnpm add -D @xyo-network/event-kit-vitest-config vitest
// vitest.config.ts
import { defineEventKitVitestConfig } from '@xyo-network/event-kit-vitest-config'

export default defineEventKitVitestConfig({
  installers: { localEventStack: true },
})

Put integration specs in src/**/spec/local-event-stack/**/*.spec.ts (or packages/*/src/**/spec/local-event-stack/**/*.spec.ts in a workspace):

import { getLocalEventStack } from '@xyo-network/event-kit-vitest-config'
import { expect, it } from 'vitest'

it('receives finalized heads', async () => {
  const stack = getLocalEventStack()
  const subscription = await stack.subscribe({
    deploymentId: 'my-indexer',
    queueId: 'heads', // optional
    fromPosition: 0, // explicit historical floor; default is the source head at creation
    maxPositionsPerWake: 16,
  })
  const active = await subscription.waitForActive()
  const wake = await subscription.waitForWake()
  expect(wake.publisher).toBe(stack.publisher)
  expect(active.activeFromBlock).toBeGreaterThan(0)
  expect(wake.fromPosition).toBe(0)
  expect(wake.event.source).toEqual({ kind: 'xl1-finalized', chainId: stack.chainId })
  await subscription.revoke()
})
pnpm vitest run --project local-event-stack

Plain vitest run does not boot the stack. Its specs are excluded from ordinary Node/browser projects even when the installer is disabled. Set localEventStack: { optInOnly: false } to include it in ordinary runs. defineEventKitVitestProjects and defineEventKitInstallerProjects support composition with other presets. When composing only installer projects, also apply LOCAL_EVENT_STACK_EXCLUDE to your base projects.

What runs

Each spec file owns a fresh chain ID, ephemeral loopback ports and temporary directory. Tests within that file share the stack; do not stop it until the file's final test. Setup publishes the publisher's service and dedicated HPKE encryption key. subscribe() creates and funds an independent dev identity, starts a TLS receiver, and publishes an encrypted subscription plus grant via an elevated, subject-bearing Claim.

The background publisher discovers the finalized tuple through Statement Graph replay, decrypts the endpoint, performs its HTTPS ownership challenge, publishes acceptance and becomes eligible at authorization block acceptance block + 1. Each wake uses the canonical unversioned source-aware envelope and begins from the independently declared fromPosition, in batches of maxPositionsPerWake. Each subscriber has a durable cursor and outbox. Receivers independently replay the chain and perform real JWT, grant, lifecycle and atomic inbox checks before durable enqueue. No HTTP handler runs a reducer.

waitForWake() claims and acknowledges one queued wake. For explicit lease or reducer tests use subscription.queue.claim() and its ack() / release() methods. dropNextDeliveryResponses() simulates a lost response after durable admission; retries keep the same wake ID/hash under a fresh JWT. stats() exposes test-only delivery evidence. Treat its JWTs and fixture account/key state as sensitive test data; do not log or reuse them on real networks.

Lifecycle and lower-level access

  • Setup/teardown owns startup failures, publisher stop, gateways, receivers, datalake, child process and temporary directories. stop() is idempotent.
  • getLocalEventStack() is available inside tests/hooks, not at module scope. Alternatively import @xyo-network/event-kit-vitest-config/globals as a type to type the setup-owned eventStack global.
  • startLocalEventStack({ pollIntervalMs?, readyTimeoutMs? }) supports manual ownership. Always await stack.stop() in a finally block.
  • publisherClient, createSubscriber().client, viewer, rpcUrl, dataLakeUrl and advertisement expose the real public APIs for custom tests.
  • For your own receiver, call registerEndpoint(exactHttpsUrl, certificatePem) before publishing through a funded createSubscriber() client. The return value unregisters it. You own that custom server's cleanup and challenge, admission and queue implementation.

Boundaries

This is a local integration harness, not a mock-based unit-test fixture and not the production event-kit publisher run command. Like dApp Kit's fixture, it launches the published XL1 CLI; it additionally disables shared health/metrics listeners so concurrent stacks do not collide. No apiLocal installer is required. No chain credentials, public datalake, Sequence or Mainnet access is needed. All XL1_* environment overrides and NODE_TLS_REJECT_UNAUTHORIZED=0 must be unset to prevent ambient wallet/network configuration leaking into the child process.

Only exact, explicitly registered HTTPS URLs on literal 127.0.0.1 are callable. TLS verification remains enabled with per-endpoint certificate trust. DNS names, redirects and implicit LAN access are rejected. This test-only allowance does not change production endpoint rules. Each challenge nonce permits one outbound attempt. A failed or ambiguous HTTP attempt retries on a later publisher pass with a fresh challenge; a received proof is retained for acceptance retries.

The chain uses simplified dev consensus and in-memory chain state; publisher, datalake and inbox files exist only until teardown. This does not qualify production supervision, restart recovery, SQLite, multiple VMs, Sequence or Mainnet. Hosted production qualification remains separate.

Repository API-local qualification

This repository keeps the opt-in api-local project name and existing protocol specs, with a repository-owned setupFiles override in the root Vitest config. Each file launches the same public XL1 CLI dev chain used by the event stack, then supplies its actually observed rpcUrl and chainId globals. The config resolves the setup source relative to its own URL, so package-scoped test runs use the same setup. Test wallets use the public dev mnemonic; no internal locator global or provider-ID modification is supplied.

pnpm test:api-local
pnpm test:api-local-statements
pnpm test:live

The published xl1-vitest-config/chain-test 5.5.0 in-process producer imports a SimpleBlockRunner without the stable provider ID required by XL1 SDK 5.8.0. The supported setup override changes the chain runtime to the public CLI; it does not patch dependencies, downgrade the application SDK or restore constructor name provider identity. Results from this gate are CLI-backed local-chain evidence, distinct from historical in-process apiLocal evidence and hosted qualification.

The repository's pnpm test:packed-event-stack gate installs from the local pnpm cache with strict peer checks, typechecks a separate consumer, then runs two spec files through the packed setup entry. Populate the dependency cache before running it; this gate is not a registry publication check.

License: LGPL-3.0-only.

版本与发布记录

@xyo-network/event-kit-vitest-config 共发布 20 个版本,首次发布于 2026/08/28;过去 12 个月发布了 20 个版本。

版本发布日期距今
2.3.4latest2026/11/03今天
2.3.32026/11/03今天
2.3.22026/10/313 天前
2.3.12026/10/303 天前
2.3.02026/10/295 天前
2.2.32026/10/286 天前

关于 @xyo-network/event-kit-vitest-config 的常见问题

@xyo-network/event-kit-vitest-config 是什么?

使用真正的发布者和HTTPS接收器测试预设和拥有的本地XL1事件堆栈

如何安装 @xyo-network/event-kit-vitest-config?

在项目目录运行 npm install @xyo-network/event-kit-vitest-config,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:ajv(^8.20)、zod(^4.6)、vite(^8.3)、ethers(^6.17)、vitest(^5.0)、async-mutex(^0.5)、@ariestools/sdk(^9.0)、@xyo-network/sdk(^8.1)、@ariestools/actor(^2.0)、@opentelemetry/api(^1.10)、@xyo-network/xl1-sdk(^5.8)、@ariestools/vitest-config(^10.2)、@xyo-network/sdk-protocol(^8.0)、@xyo-network/xl1-protocol(^5.8)、@xyo-network/xl1-statement-graph-sdk(^0.7)、@xyo-network/xl1-statement-graph-engine(^0.7)、@xyo-network/xl1-statement-graph-schemas(^0.7)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@xyo-network/event-kit-vitest-config 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@xyo-network/event-kit-vitest-config 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@xyo-network/event-kit-vitest-config 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=26。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@xyo-network/event-kit-vitest-config 可以商用吗?

@xyo-network/event-kit-vitest-config 使用 LGPL-3.0-only 许可。弱 Copyleft:作为库被调用时通常不要求开源你自己的代码,但修改库本身需以 LGPL 开源;前端打包合并后的适用边界存在不同理解。以上为概括,不构成法律意见,请以许可原文为准。

@xyo-network/event-kit-vitest-config 还在维护吗?

最新版本 2.3.4 发布于 2026/11/03(今天);至今共发布 20 个版本,其中过去 12 个月发布了 20 个;首次发布于 2026/08/28。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。