@sema-agent/core
Version:
Stateless, task-oriented AI agent core
31 lines (30 loc) • 2.26 kB
TypeScript
import { type WorkflowRunStore } from "./workflow-run-store.js";
import type { WorkflowRun, WorkflowRunStatus } from "../orchestration/workflow.js";
/**
* design/97 S1b/§D.8 — the **runner-agnostic** cross-backend contract for {@link WorkflowRunStore}, so the
* SAME assertions run over every backend AND **service can import it to verify its own PG implementation**
* (§D.8: "contract 函数须 service 可复用,放可被 import 的位置,非纯 test/ 私有").
*
* It lives in `src/` (compiled into `dist/`, re-exported from the package barrel) and uses Node's built-in
* `assert` — NO vitest dependency — so it runs under any harness (vitest, node:test, a bare script). Core's
* `test/cross-backend-shared.ts` wraps {@link workflowRunStoreContract} in a single vitest `it()` to bind it
* to the InMemory + File backends; service binds it to its PG store.
*
* The fixtures pin `createdAt`/`endedAt` so the `listByScope` ordering + `reap` retention are deterministic
* (no wall clock). `make()` must return a FRESH, empty store each call.
*/
/** Build a {@link WorkflowRun} fixture (terminal `completed` by default). All fields explicit + deterministic. */
export declare function createWorkflowRun(over?: Partial<WorkflowRun>): WorkflowRun;
/**
* The full cross-backend contract for {@link WorkflowRunStore}. `make` returns a fresh store; `runAssertion`
* lets a harness label/await each case (a vitest binding passes `it`; a bare runner can pass a sequential
* runner). The DEFAULT runs the cases inline and sequentially (so `service` can call
* `await workflowRunStoreContract(make)` with no harness at all).
*
* ⚠️ Binding note: the cases are REGISTERED eagerly and awaited via `Promise.all` — an async
* `runAssertion` that schedules work concurrently will interleave cases. Bindings whose stores share state
* (e.g. SQL twins on one table) must CHAIN the assertions themselves (serialize inside `runAssertion`).
*/
export declare function workflowRunStoreContract(make: () => WorkflowRunStore, runAssertion?: (name: string, fn: () => Promise<void>) => void): Promise<void>;
/** Re-export so a contract caller can label runs by status without re-importing the run module. */
export type { WorkflowRunStatus };