import { coverageForPackage } from "../../vitest.coverage";
import { defineConfig } from "vitest/config";

import { RFC64_UNIT_TESTS } from "./vitest.rfc64-unit-tests";

// generic-sql-source.test.ts uses `import('node:sqlite')`, which is
// `--experimental-sqlite`-gated on Node 22.5–23.x. The flag is a
// process-level toggle, so mirror `vitest.config.ts`: switch to the
// `forks` pool and pass execArgv there. See the long comment in
// `vitest.config.ts` for the full rationale.
const SQLITE_EXEC_ARGV = [
  "--experimental-sqlite",
  "--no-warnings=ExperimentalWarning",
];

export default defineConfig({
  test: {
    allowOnly: false,
    coverage: coverageForPackage("agent"),
    include: [
      "test/authority-index-snapshot-runtime.test.ts",
      "test/authority-index-snapshot-service.test.ts",
      "test/authority-index-snapshot-wiring.test.ts",
      "test/authority-index-config.test.ts",
      "test/warm-core-sharding-gate.test.ts",
      "test/context-graph-discovery-options.test.ts",
      "test/manifest-bound-snapshot-walk.test.ts",
      "test/private-swm-recovery-budget.test.ts",
      "test/private-swm-recovery-lifecycle-budget.test.ts",
      "test/sync-work-admission.test.ts",
      "test/sync-work-admission-lifecycle.test.ts",
      ...RFC64_UNIT_TESTS,
      "test/endorse.test.ts",
      "test/bounded-curator-discovery.test.ts",
      "test/discovery-peer-pagination.test.ts",
      "test/ack-candidate-pool.test.ts",
      "test/peer-capability.test.ts",
      "test/ack-candidate-discovery.test.ts",
      "test/e2e-dht-dial.test.ts",
      "test/generic-sql-source.test.ts",
      "test/sqlite-module-loader.test.ts",
      "test/imported-artifact.test.ts",
      "test/publish-finalized-agent-lane.test.ts",
      "test/publish-foreign-author-resolution.test.ts",
      "test/finalize-version-after-abandoned-update.test.ts",
      "test/durable-integrity-seal-assertion-version.test.ts",
      "test/iri-term.test.ts",
      "test/promote-async-default-agent.test.ts",
      "test/promote-swm-pointer-post-commit.test.ts",
      "test/clear-promote-async-facade.test.ts",
      "test/query-min-trust-alias.test.ts",
      "test/query-source-labels.test.ts",
      "test/query-private-authority-pending.test.ts",
      "test/unscoped-query-admission.test.ts",
      "test/prepare-unscoped-context-graph-read-checks.test.ts",
      "test/unscoped-query-consistency.test.ts",
      "test/query-source-coverage.test.ts",
      "test/context-graph-on-chain-id-source-labels.test.ts",
      "test/context-graph-public-meta-proof.test.ts",
      "test/context-graph-public-meta-repair.test.ts",
      "test/context-graph-public-meta-repair-http.test.ts",
      "test/list-context-graphs-cache-config.test.ts",
      "test/confirmed-meta-source-labels.test.ts",
      "test/sync-envelope-cursor.test.ts",
      "test/w2-ual-parity.test.ts",
      "test/rfc64-receiver-admission-deferral.test.ts",
      "test/rfc64-precommit-owner-attribution.test.ts",
      "test/exact-assets.test.ts",
      "test/exact-batch-stream-contract.test.ts",
      "test/exact-batch-stream-duplex.test.ts",
      "test/exact-batch-stream-loopback.test.ts",
      "test/exact-batch-stream-capability.test.ts",
      "test/vm-recovery-stream-profile.test.ts",
      "test/vm-recovery-experimental-stream-host.test.ts",
      "test/exact-batch-stream-binding.test.ts",
      "test/exact-batch-stream-host-verdict.test.ts",
      "test/exact-batch-stream-responder-switch.test.ts",
      "test/exact-graph-content-export.test.ts",
      "test/vm-recovery-local-admission.test.ts",
      "test/vm-reconcile-read-authority-wait.test.ts",
      "test/exact-asset-responder.test.ts",
      "test/responder-asset-metadata.test.ts",
      "test/exact-asset-wire-parse.test.ts",
      "test/swm/host-catchup-sign.test.ts",
      "test/swm/host-catchup-wire.test.ts",
      "test/swm/host-mode-store.test.ts",
      "test/swm/host-mode-key-canonicalization.test.ts",
      "test/swm/host-mode-strip-ciphertext.test.ts",
      "test/rs-heal-stranded-kc-decorated.test.ts",
      "test/random-sampling-context-graph-resolver.test.ts",
      "test/random-sampling-proof-repair.test.ts",
      "test/sync-protocol-peer-id.test.ts",
      "test/random-sampling-membership.test.ts",
      "test/random-sampling-handle-compatibility.test.ts",
      "test/vm-reconcile-source-labels.test.ts",
      "test/profile-fix-verify.test.ts",
      "test/pca-v10-facade.test.ts",
      "test/ensure-registered-for-publish.test.ts",
      "test/sync-verify-collapsed.test.ts",
      "test/sync-verify-rootless.test.ts",
      "test/sync-control-metadata-admission.test.ts",
      "test/sync-responder-per-cgid-meta.test.ts",
      "test/changelog-delta-page.test.ts",
      "test/sync-durable-worker-wire.test.ts",
      "test/changelog-requester.test.ts",
      "test/durable-sync-since-threading.test.ts",
      "test/durable-sync-budget.test.ts",
      "test/durable-sync-graph-scoped-materialization.test.ts",
      "test/finalized-swm-twin-reconciliation.test.ts",
      "test/durable-sync-lifecycle-binding.test.ts",
      "test/durable-manifest-digest.test.ts",
      "test/durable-manifest-continuation.test.ts",
      "test/durable-recovery-coordinator.test.ts",
      "test/manifest-resume-policy.test.ts",
      "test/durable-progress.test.ts",
      "test/gossip-publish-handler.test.ts",
      "test/discovery-subscription-boundary.test.ts",
      "test/core-fills-gap.test.ts",
      "test/regression-on-demand-cursor.test.ts",
      "test/regression-peer-store-repair.test.ts",
      "test/context-graph-name-candidate.test.ts",
      "test/context-graph-name-protocol.test.ts",
      "test/context-graph-name-resolver.test.ts",
      "test/context-graph-name-adoption.test.ts",
      "test/context-graph-name-hash-subscription.integration.test.ts",
      "test/context-graph-storage-discovery.test.ts",
      "test/context-graph-storage-discovery-agent.test.ts",
      "test/context-graph-on-chain-reference.test.ts",
      "test/context-graph-on-chain-id-resolution.test.ts",
      "test/context-graph-ontology-claim-binding.test.ts",
      "test/context-graph-claim-proof.test.ts",
      "test/vm-reconcile-peer-topology.test.ts",
      "test/swm-late-joiner-deferred-gossip.test.ts",
      "test/context-graph-metadata-placement.test.ts",
      "test/swm-plaintext-oracle-wiring.test.ts",
      "test/oversize-filter.test.ts",
      "test/cg-registration-oversize-guard.test.ts",
      "test/sync-responder-concurrent-interleaving.test.ts",
      "test/durable-meta-admission.test.ts",
      "test/sync-responder-log-volume.test.ts",
      "test/sync-responder-snapshot-cache.test.ts",
      "test/sync-responder-durable-meta-subject-atomic.test.ts",
      "test/sync-responder-snapshot-failure-policy.test.ts",
      "test/sync-responder-cursor.test.ts",
      "test/sync-responder-oversized-fallback.test.ts",
      "test/sync-responder-swm-meta-ceiling.test.ts",
      "test/sync-responder-large-graph-stack-overflow.test.ts",
      "test/sync-page-frame-budget.test.ts",
      "test/sync-byte-budget-pages.test.ts",
      "test/sync-exact-serving-recovery.test.ts",
      "test/sync-exact-plan-session.test.ts",
      "test/sync-append-in-place.test.ts",
      "test/sync-memory-metrics.test.ts",
      "test/sync-responder-metrics.test.ts",
      "test/sync-transport-metrics.test.ts",
      "test/sync-snapshot-helper-compatibility.test.ts",
      "test/sync-attempt-telemetry.test.ts",
      "test/sync-operation-telemetry.test.ts",
      "test/sync-fetch-coalescing.test.ts",
      "test/sync-fetch-coalescing-durable.test.ts",
      "test/sync-exact-accumulation.test.ts",
      "test/sync-exact-gzip-lifecycle.test.ts",
      "test/sync-wire-compression.test.ts",
      "test/sync-native-export-hostile.test.ts",
      "test/sync-exact-asset-export-cache.test.ts",
      "test/sync-exact-gzip-export.test.ts",
      "test/sync-backpressure.test.ts",
      "test/sync-policy.test.ts",
      "test/catchup-policy.test.ts",
      "test/catchup-concurrency.test.ts",
      // #2050 — the stop rule for the bounded repeat of the public SWM peer walk.
      "test/catchup-pass-policy.test.ts",
      "test/selected-swm-continuation.test.ts",
      "test/selected-swm-freshness.test.ts",
      "test/selected-swm-bootstrap-admission.test.ts",
      "test/selected-swm-lifecycle-core.test.ts",
      "test/selected-swm-lifecycle-session.test.ts",
      "test/selected-swm-lifecycle-queue.test.ts",
      "test/selected-swm-meta-transfer-coordinator.test.ts",
      "test/selected-swm-meta-budget.test.ts",
      "test/legacy-sync-graph-candidate.test.ts",
      "test/outbox-shutdown-lifecycle.test.ts",
      // Keyed persist scheduler shared by membership and subscription writes,
      // and the subscription drain / reopen that stop() and start() drive.
      "test/keyed-persist-scheduler.test.ts",
      "test/context-graph-membership-persist-scheduler.test.ts",
      "test/context-graph-subscription-persist-scheduler.test.ts",
      "test/context-graph-subscription-persist-lifecycle.test.ts",
      "test/outbox-drainer.test.ts",
      "test/sync-checkpoint-key.test.ts",
      "test/map-with-concurrency.test.ts",
      "test/peer-selection.test.ts",
      "test/sync-requester-priority.test.ts",
      "test/sync-requester-progress.test.ts",
      "test/swm-snapshot-coverage.test.ts",
      "test/swm-snapshot-coverage-selection.test.ts",
      "test/swm-snapshot-throw-progress.test.ts",
      "test/metadata-literal.test.ts",
      "test/rootless-durable-bounded-progress.test.ts",
      "test/rootless-durable-skips-legacy-partition.test.ts",
      "test/rootless-lifecycle-graph.test.ts",
      "test/swm-recovery-apply.test.ts",
      "test/swm-recovery.test.ts",
      "test/swm-recovery-identity-preservation.test.ts",
      // #2083: the discoverable suffix keeps runtime/type adoption in sync.
      "test/shared-memory-sync-ownership.typechecked.test.ts",
      "test/dkg-agent-snapshot-store-injection.test.ts",
      "test/swm-snapshot-sync.test.ts",
      "test/sync-responder-protection.test.ts",
      "test/sync-on-connect-retry.test.ts",
      "test/peer-event-lifecycle.test.ts",
      "test/rfc64-authority-accepted-catchup-timer.test.ts",
      "test/sync-on-connect-churn.test.ts",
      "test/sync-on-connect-compatibility.test.ts",
      "test/rfc64-sync-on-connect-recovery-plan-queue.test.ts",
      "test/rfc64-sync-on-connect-peer-job-accounting.test.ts",
      "test/rfc64-sync-on-connect-swm-lanes.test.ts",
      "test/rfc64-sync-on-connect-selected-retry.test.ts",
      "test/sync-on-connect-attempt-accounting.test.ts",
      "test/sync-on-connect-peer-job-runner.test.ts",
      "test/sync-on-connect-peer-scheduler.test.ts",
      "test/system-context-graph-policy.test.ts",
      "test/on-demand-agents-phonebook.test.ts",
      "test/on-demand-agents-phonebook-agent.test.ts",
      "test/sync-requester-bailout.test.ts",
      "test/swm-catchup-peer-selection.test.ts",
      "test/swm-curator-recovery-plan.test.ts",
      "test/swm-fanout-peer-selection.test.ts",
      "test/publish-literal-size.test.ts",
      "test/verify-batch.test.ts",
      "test/chain-cursor-wiring.test.ts",
      "test/chain-reconciler.test.ts",
      "test/vm-reconcile-self-prime.test.ts",
      "test/vm-reconcile-self-prime-budget.test.ts",
      "test/vm-reconcile-sweep.test.ts",
      "test/vm-reconcile-lifecycle-timer.test.ts",
      // #2858 — refresh of confirmed VM copies after an on-chain KA update.
      "test/vm-refresh-after-update.test.ts",
      "test/core-fills-gap.test.ts",
      "test/vm-promotion-gate.test.ts",
      "test/vm-recovery-microbatch-planner.test.ts",
      "test/vm-recovery-phase-timing.test.ts",
      "test/vm-recovery-transport-plan.test.ts",
      "test/vm-recovery-batch-timing-host.test.ts",
      "test/vm-recovery-pass-authority.test.ts",
      "test/vm-recovery-preparation.test.ts",
      "test/vm-recovery-preparation-host.test.ts",
      "test/vm-recovery-stream-evidence-retry-host.test.ts",
      "test/vm-recovery-footprint-prepared.test.ts",
      "test/vm-recovery-provider-policy.test.ts",
      "test/vm-recovery-core-transport-preference.test.ts",
      "test/vm-recovery-stream-setback-policy.test.ts",
      "test/vm-recovery-microbatch-host.test.ts",
      "test/vm-recovery-footprint-bridge.test.ts",
      "test/vm-recovery-footprint-bridge-adversarial.test.ts",
      "test/finalization-reconcile-local-state.test.ts",
      "test/startup-jitter.test.ts",
      "test/finalization-lifecycle-logger.test.ts",
      "test/finalization-handler.test.ts",
      "test/finalization-context-graph-id-resolution.test.ts",
      "test/finalization-recovery.test.ts",
      "test/finalization-recovery-worker.test.ts",
      "test/finalization-recovery-sqlite-deferred.test.ts",
      "test/finalization-recovery-sqlite-migration.test.ts",
      "test/finalization-recovery-sqlite-store.test.ts",
      "test/named-ka-publish-recovery.test.ts",
      "test/ka-graph-finalization-handler.test.ts",
      "test/ka-lifecycle-asset-ual-timeout.test.ts",
      "test/storage-ack-lifecycle-identity.test.ts",
      "test/storage-ack-endpoint.test.ts",
      "test/v10-ack-provider-wiring.test.ts",
      "test/storage-ack-lifecycle.test.ts",
      "test/agent-restart-gossip-resubscribe.test.ts",
      "test/storage-ack-registration-runtime.test.ts",
      "test/direct-rootless-publish.test.ts",
      "test/rootless-update-boundary.test.ts",
      "test/rootless-update-error.test.ts",
      "test/changelog-requester.test.ts",
      "test/encrypt-inline-policy.test.ts",
      "test/queued-publish-options.test.ts",
      "test/agents-meta-policy.test.ts",
      "test/agents-meta-sync-wiring.test.ts",
      "test/network-identity-proof.test.ts",
      "test/network-admission-probe-retry.test.ts",
      "test/network-admission.test.ts",
      "test/network-admission-coordinator.test.ts",
      "test/network-admission-connect-race.test.ts",
      "test/explicit-connect-admission.test.ts",
      "test/sync-responder-agents-meta-serve-skip.test.ts",
      "test/messenger-substrate.test.ts",
      "test/messenger-outbox-budget.test.ts",
      "test/context-graph-join-policy.test.ts",
      "test/bounded-operation.test.ts",
      "test/private-read-chain-authority.test.ts",
      "test/context-graph-authority-retry.test.ts",
      "test/context-graph-access-policy-state.test.ts",
      "test/context-graph-live-authority-fold.test.ts",
      "test/context-graph-historical-name-binding.test.ts",
      "test/context-graph-registration-resolution.test.ts",
      "test/context-graph-list-concurrency.test.ts",
      "test/context-graph-list-wire-only.test.ts",
      "test/cg-resolve-refresh.test.ts",
      "test/private-cg-membership-bootstrap.test.ts",
      "test/workspace-crypto-delegatee-filter.test.ts",
      "test/swm-public-snapshot-materialization.test.ts",
      "test/swm-public-cg-plaintext.test.ts",
      "test/swm-sender-key-stale-target.test.ts",
      "test/swm-sender-key-peer-routes.test.ts",
      // #2827 — SWM authority and plaintext decisions for a joined member of a
      // public, unregistered context graph.
      "test/public-unregistered-member-swm.test.ts",
      "test/approved-private-replica.test.ts",
      "test/swm-snapshot-materializer.test.ts",
      "test/swm-head-identity-preservation.test.ts",
      // #2079 — the already-materialized witness: the warm-path win, the count
      // gate that keeps it self-healing, and the digest binding that makes an
      // equal-count version change safe.
      "test/swm-materialization-witness.test.ts",
      "test/replace-subject-agent-wrapper.test.ts",
    ],
    testTimeout: 60_000,
    maxWorkers: 1,
    pool: "forks",
    execArgv: SQLITE_EXEC_ARGV,
  },
});
