Crux
API Reference@use-crux/core

Connected Knowledge Conformance

runConnectedKnowledgeConformance() for storage adapter authors.

import { runConnectedKnowledgeConformance } from "@use-crux/core/knowledge";
import type {
  ConnectedKnowledgeConformanceAssertion,
  ConnectedKnowledgeConformanceExpect,
  ConnectedKnowledgeConformanceTest,
  RunConnectedKnowledgeConformanceOptions,
} from "@use-crux/core/knowledge";

Overview

runConnectedKnowledgeConformance() registers shared storage behavior checks for connected-knowledge features through the caller's test runner.

It verifies observable behavior through the public Storage bundle: record key scans, generation publication, graph adjacency, view membership, view revisions, community generations, leases, and source removal.

runConnectedKnowledgeConformance(options)

Registers conformance cases. It does not return a value.

function runConnectedKnowledgeConformance(
  options: RunConnectedKnowledgeConformanceOptions,
): void;

Parameters

interface RunConnectedKnowledgeConformanceOptions {
  readonly createStorage: () => Storage | Promise<Storage>;
  readonly test: ConnectedKnowledgeConformanceTest;
  readonly expect: ConnectedKnowledgeConformanceExpect;
}

type ConnectedKnowledgeConformanceTest = (
  name: string,
  fn: () => void | Promise<void>,
) => void;

interface ConnectedKnowledgeConformanceExpect {
  (actual: unknown): ConnectedKnowledgeConformanceAssertion;
}
OptionTypeDefaultConstraints
createStorage() => Storage | Promise<Storage>RequiredMust create a fresh isolated storage bundle for each case. Returned storage must include records.
testConnectedKnowledgeConformanceTestRequiredCalled once for each named case.
expectConnectedKnowledgeConformanceExpectRequiredMust return the matcher subset below.
interface ConnectedKnowledgeConformanceAssertion {
  readonly not: Pick<ConnectedKnowledgeConformanceAssertion, "toBe">;
  toBe(expected: unknown): void;
  toEqual(expected: unknown): void;
  toMatchObject(expected: object): void;
}

Registered Cases

Case nameBehavior checked
round-trips knowledge refs and scans knowledge key prefixesReference codecs and namespace-scoped record prefix listing.
keeps generation publication atomic across publish, abandon, and crash-before-publishCurrent generation pointer, partial generation records, abandon cleanup, and previous-generation cleanup.
reads adjacency through outbound and inbound scansOutbound and inbound adjacency indexes and graph neighbor reads.
maintains view membership indexes and resolves members from indexes onlyMembership index maintenance and index-only view member resolution.
creates view revisions idempotently by content addressStable content-addressed revisions independent of member order.
serves community generations atomically and coordinates leasesCommunity generation visibility, lease claim, stale lease takeover, and heartbeat ownership.
removes source-scoped storage from indexed, claim, and view visibilityIndexed source deletion, claim deletion, hydration miss, and view membership removal.

Failures

The runner itself performs no option validation before registering tests. Failures surface from the caller's test function, expect matchers, storage operations, or the connected-knowledge stores exercised by each case.

Example

import { expect, test } from "vitest";
import { runConnectedKnowledgeConformance } from "@use-crux/core/knowledge";
import { createAdapterStorage } from "../src/storage";

runConnectedKnowledgeConformance({
  createStorage: createAdapterStorage,
  test,
  expect,
});

On this page