跳到主要内容

bolt/test

bolt/test

导入自 @norbital-ai/bolt/test

Public test edge: one scoped workspace layer and Effect-native callers.

ActOptions type

type ActOptions = {
    key?: string;
    retry?: boolean;
    onConflict?: 'update' | 'keep';
    observed?: {
        readonly [id: string]: number;
    };
};

A test act's idempotency key and retry marker, conflict handling, and observed record revisions for concurrency checks.

成员

名称类型说明
key?string
retry?boolean
onConflict?'update' | 'keep'
observed?{ readonly [id: string]: number; }

源码: packages/bolt/src/test/effect.ts:175

Caller interface

interface Caller {
    read<C extends string>(collection: Is<C, ReadableName>, query: DeclaredQuery): Effect.Effect<Page<DeclaredRow<C>>, ReadFailed>;
    readonly authority: Authority;
    act<const N extends string>(callable: Is<N, KitCallable>, input: NoInfer<KitInput<N>>, options?: ActOptions): Effect.Effect<Committed<ActOutput<N>, N> | PendingApproval<N>, ActFailure>;
    query<const N extends string>(name: Is<N, QueryCallable>, input: NoInfer<QueryInput<N>>): Effect.Effect<QueryOutput<N>, ReadFailed>;
    start<const A extends string>(automation: Is<A, StartableName>, input: NoInfer<StartInput<A>>, options?: {
        id?: string;
    }): Effect.Effect<Committed<unknown> | PendingApproval, ActFailure>;
    upload(field: `${string}.${string}`, file: {
        name: string;
        mime: string;
        bytes: Uint8Array;
        id?: string;
    }): Effect.Effect<Committed<FileRef> | PendingApproval, ActFailure>;
    read<C extends string, const S extends Select<C> = {}>(collection: Is<C, ReadableName>, q: {
        where?: NoInfer<Where<C>>;
        select?: S;
        orderBy?: NoInfer<OrderBy<C>>;
        search?: string;
    } & Paged): Effect.Effect<Page<ListResult<C, S>>, ReadFailed>;
    read<const M extends ReadSet>(set: M & {
        readonly [K in keyof M]: ReadMember<M[K]['collection']>;
    }): Effect.Effect<ReadSetAnswer<M>, ReadFailed>;
    get<C extends string, const S extends Select<C> = {}>(collection: Is<C, ReadableName>, id: NoInfer<Id<C>>, q?: {
    …

Reads, queries, writes, uploads and automation starts through the real host routes under one authority, with native decoded values and typed failures.

成员

名称类型说明
read{ <C extends string>(collection: Is<C, ReadableName>, query: DeclaredQuery): Effect.Effect<Page<DeclaredRow<C>>, ReadFailed>; <C extends string, const S extends Select<C> = {}>(collection: Is<C, ReadableName>, q: { where?: NoInfer<Where<C>>; select?: S; orderBy?: NoInfer<OrderBy<C>>; search?: string; } & Paged): Effect.Effect<Page<ListResult<C, S>>, ReadFailed>; <const M extends ReadSet>(set: M &…
authorityAuthority
act<const N extends string>(callable: Is<N, KitCallable>, input: NoInfer<KitInput<N>>, options?: ActOptions) => Effect.Effect<Committed<ActOutput<N>, N> | PendingApproval<N>, ActFailure>
query<const N extends string>(name: Is<N, QueryCallable>, input: NoInfer<QueryInput<N>>) => Effect.Effect<QueryOutput<N>, ReadFailed>
start<const A extends string>(automation: Is<A, StartableName>, input: NoInfer<StartInput<A>>, options?: { id?: string; }) => Effect.Effect<Committed<unknown> | PendingApproval, ActFailure>
upload(field: `${string}.${string}`, file: { name: string; mime: string; bytes: Uint8Array; id?: string; }) => Effect.Effect<Committed<FileRef> | PendingApproval, ActFailure>
get<C extends string, const S extends Select<C> = {}>(collection: Is<C, ReadableName>, id: NoInfer<Id<C>>, q?: { select?: S; revision?: number; }) => Effect.Effect<ReadResult<C, S> | null, ReadFailed>

源码: packages/bolt/src/test/effect.ts:188

Cassette type

type Cassette = {
    readonly [modelClass: string]: readonly AiResponse[] | string;
};

Ordered AI responses per model class, supplied inline or by a JSON file containing a turns array.

源码: packages/bolt/src/test/effect.ts:237

CassetteAi function

function CassetteAi(options: CassetteOptions): Effect.Effect<{ requests: AiRequest[]; remaining: () => { [k: string]: number; }; layer: Layer.Layer<Ai, never, never>; }, KitInvalid, never>

Schema-decoded cassettes bind one native Ai layer; no provider Promise adapter.

参数

名称类型说明
optionsCassetteOptions
  • cassette: Cassette
  • sys_1?: Ai['Service']['ask']
  • firstPartMs?: number

源码: packages/bolt/src/test/effect.ts:1051

CassetteOptions type

type CassetteOptions = {
    cassette: Cassette;
    sys_1?: Ai['Service']['ask'];
    firstPartMs?: number;
};

AI playback configuration: response cassettes, an optional System 1 responder, and a delay before each inference stream's first part.

成员

名称类型说明
cassetteCassette
sys_1?Ai['Service']['ask']
firstPartMs?number

源码: packages/bolt/src/test/effect.ts:239

type FakeLinks = {
    readonly sent: {
        instance: string;
        message: Json;
        attachments?: readonly OutboundFile[];
    }[];
    readonly typed: {
        instance: string;
        to: string;
    }[];
    answer: (instance: string, op: Json) => Effect.Effect<Json, PortFailure>;
    page: (instance: string, feed: string, partition: string, cursor: Json | null) => Effect.Effect<DriverPage, PortFailure>;
};

The default integration driver fake: inspect sent messages and typing notices, or supply native Effect handlers for requests and feed pages.

成员

名称类型说明
sent{ instance: string; message: Json; attachments?: readonly OutboundFile[]; }[]
typed{ instance: string; to: string; }[]
answer(instance: string, op: Json) => Effect.Effect<Json, PortFailure>
page(instance: string, feed: string, partition: string, cursor: Json | null) => Effect.Effect<DriverPage, PortFailure>

源码: packages/bolt/src/test/effect.ts:245

Fakes type

type Fakes = {
    readonly files: {
        readonly blobs: Map<string, Uint8Array>;
    };
    readonly deadlines: {
        readonly announced: {
            scope: string;
            at: string;
        }[];
    };
    readonly sent: TransportMessage[];
    readonly links: FakeLinks;
    /** The runtime log the kit's host holds: every event written, oldest first, `id` its position. */
    readonly logs: LogRow[];
    readonly ai?: {
        readonly requests: readonly AiRequest[];
        remaining(): {
            readonly [modelClass: string]: number;
        };
    };
};

Observations of the kit's default file, deadline, transport and integration ports, plus AI requests and remaining responses when cassette playback is enabled.

成员

名称类型说明
files{ readonly blobs: Map<string, Uint8Array>; }
deadlines{ readonly announced: { scope: string; at: string; }[]; }
sentTransportMessage[]
linksFakeLinks
logsLogRow[]

The runtime log the kit's host holds: every event written, oldest first, id its position.

ai?{ readonly requests: readonly AiRequest[]; remaining(): { readonly [modelClass: string]: number; }; }

源码: packages/bolt/src/test/effect.ts:257

Kit type

type Kit = {
    readonly manifest: EngineManifest;
    /** The verified artifact hash, or the explicit in-memory test release. */
    readonly release: string;
    readonly db: TenantDbShape;
    /** The transform's native, unmasked stored reader, scoped to this workspace. */
    readonly storedRead: WorkspaceReads['read'];
    /** An action/automation's native batch writer, under this caller's authority. */
    bodyActs(who: Holder | Authority): Pick<Act, 'many'>;
    readonly fakes: Fakes;
    readonly count: {
        readonly reads: number;
        readonly writes: number;
        reset(): void;
    };
    readonly clock: {
        now(): string;
        set(instant: string): void;
        advance(value: string): void;
    };
    readonly admin: Holder;
    member(policies: readonly string[], over?: Partial<Extract<EngineActor, {
        kind: 'member';
    }>>): Holder & {
        readonly id: string;
    };
    as(who: Holder | Authority): Caller;
    visitor(app: string, options?: {
        readonly ip?: string;
    }): Caller;
    signIn(address: string): Effect.Effect<Authority, KitFailure>;
    runDue(): Effect.Effect<void, EngineError>;
    crash(runId: string): Effect.Effect<void, KitFailure>;
    settled(): Effect.Effect<void>;
    receive(instance: string, messages: Json | readonly Json[], options?: {
        readonly history?: true;
        readonly bins?: readonly Uint8Array[];
    }): Effect.Effect<void, EngineError>;
    /** Real native HTTP routes, includ…

A scoped workspace's test controls: create callers, inspect native rows and port observations, advance its clock, run due work, and exercise real HTTP and integration entry points.

成员

名称类型说明
manifestEngineManifest
releasestring

The verified artifact hash, or the explicit in-memory test release.

dbTenantDbShape
storedReadWorkspaceReads['read']

The transform's native, unmasked stored reader, scoped to this workspace.

bodyActs(who: Holder | Authority) => Pick<Act, "many">

An action/automation's native batch writer, under this caller's authority.

fakesFakes
count{ readonly reads: number; readonly writes: number; reset(): void; }
clock{ now(): string; set(instant: string): void; advance(value: string): void; }
adminHolder
member(policies: readonly string[], over?: Partial<Extract<EngineActor, { kind: "member"; }>>) => Holder & { readonly id: string; }
as(who: Holder | Authority) => Caller
visitor(app: string, options?: { readonly ip?: string; }) => Caller
signIn(address: string) => Effect.Effect<Authority, KitFailure>
runDue() => Effect.Effect<void, EngineError>
crash(runId: string) => Effect.Effect<void, KitFailure>
settled() => Effect.Effect<void>
receive(instance: string, messages: Json | readonly Json[], options?: { readonly history?: true; readonly bins?: readonly Uint8Array[]; }) => Effect.Effect<void, EngineError>
handle(request: Request, options?: { readonly address?: string; }) => Effect.Effect<Response>

Real native HTTP routes, including isolated public SSR when acquired from an artifact.

session(id: string) => Effect.Effect<string, KitFailure>

源码: packages/bolt/src/test/effect.ts:341

KitCallable type

type KitCallable = Callable | `${ReadableName}.erase`;

The workspace's generated and authored callables, including collection erase operations exercised by the test host.

源码: packages/bolt/src/test/effect.ts:182

KitFailure type

type KitFailure = KitInvalid | EngineError | PortFailure | PlatformError;

Failures while acquiring or operating a test workspace: invalid fixtures, engine faults, port failures and platform I/O errors.

源码: packages/bolt/src/test/effect.ts:235

KitInput type

type KitInput<N> = N extends `${infer C}.erase` ? {
    target: Id<C> | readonly Id<C>[];
    set?: Readonly<Record<string, Json>>;
} : ActInput<N>;

A callable's native typed input; erase operations accept one or more collection ids and an optional replacement set.

源码: packages/bolt/src/test/effect.ts:184

KitInvalid class

class KitInvalid extends KitInvalid_base {
}

Invalid test configuration, fixture input or compiler setup; these failures cannot be mistaken for a business refusal.

成员

名称类型说明
messagestring

源码: packages/bolt/src/test/effect.ts:231

TestOptions type

type TestOptions<P extends TestPorts = never> = {
    seed?: 'base' | 'sample' | 'none' | SeedPack;
    pack?: Pack;
    now?: string;
    secretsKey?: Redacted.Redacted<Uint8Array>;
    db?: Layer.Layer<TenantDb, KitFailure>;
    ports?: Layer.Layer<P, KitFailure>;
    fakes?: {
        ai?: CassetteOptions;
    };
    links?: null;
    host?: Partial<ShellHostConfig> & {
        envoys?: ShapeOf<typeof EnvoyConfig>;
        agent?: ShapeOf<typeof AgentHost>;
    };
    cpu?: GuestOptions['cpu'];
} & ({
    /** A release verified by readArtifact; public HTTP requests execute its isolated server programs. */
    artifact: Artifact;
    root?: never;
    manifest?: never;
    guest?: never;
    transforms?: never;
    projections?: never;
} | {
    artifact?: never;
    root?: string;
    manifest?: EngineManifest;
    guest?: GuestProgram;
    transforms?: Iterable<string>;
    projections?: Iterable<string>;
});

Workspace fixture and host configuration: use a verified release, check authored source, or supply a manifest/guest; choose seed data, control time, and native ports.

源码: packages/bolt/src/test/effect.ts:307

TestPorts type

type TestPorts = Files | Convert | Speech | WebRead | Browser | Geo | Metering | Transport | DeadlinePort | Drivers | Ai;

Host port service keys a test may replace with native Layers, including file storage, conversion, speech, web, geography, transport and AI.

源码: packages/bolt/src/test/effect.ts:294

TestWorkspace class

class TestWorkspace extends TestWorkspace_base {
    static readonly layer: <P extends TestPorts>(options: TestOptions<P>) => Layer.Layer<TestWorkspace | WorkspaceServices, KitFailure>;
}

A native test workspace service; its layer owns database and engine resources in scope and exposes the same host routes used by deployed workspaces.

源码: packages/bolt/src/test/effect.ts:1116

WorkspaceServices type

type WorkspaceServices = EngineServices | Crypto.Crypto | TenantDb | BoltHost | Files | Convert | Speech | WebRead | Browser | Geo | Metering | Transport | DeadlinePort | Drivers | Ai | Activation | ShellConfig | HostIdentity | Turnstile | SessionAuthority;

The engine, database, host, shell and port services made available alongside TestWorkspace by its layer.

源码: packages/bolt/src/test/effect.ts:374

check function

function check(root: string): Effect.Effect<import("../compiler/check/index.ts").CheckResult, KitInvalid, never>

Check a workspace root and return its diagnostics, manifest and guest program; compiler loading and tool failures become KitInvalid.

参数

名称类型说明
rootstring

源码: packages/bolt/src/test/effect.ts:890

describe function

function describe<OverrideExtraContext extends object = object>(name: string | Function, fn?: EffectVitest.SuiteFactory<OverrideExtraContext> | undefined, options?: number): EffectVitest.SuiteCollector<OverrideExtraContext>
function describe<OverrideExtraContext extends object = object>(name: string | Function, options: EffectVitest.SuiteOptions, fn?: EffectVitest.SuiteFactory<OverrideExtraContext> | undefined): EffectVitest.SuiteCollector<OverrideExtraContext>

Group related workspace test scenarios using Vitest's suite lifecycle.

参数

名称类型说明
namestring | Function
fn?SuiteFactory<OverrideExtraContext>
options?number

源码: packages/bolt/src/test/effect.ts:171

expect function

function expect<T>(actual: T, message?: string): EffectVitest.Assertion<T>
function expect(val: any, message?: string): Chai.Assertion

Assert workspace values and typed operation outcomes with Vitest's matchers.

参数

名称类型说明
actualT
message?string

源码: packages/bolt/src/test/effect.ts:173

it function

function it<ExtraContext extends {}>(name: string | Function, fn?: EffectVitest.TestFunction<ExtraContext> | undefined, options?: number): void
function it<ExtraContext extends {}>(name: string | Function, options?: TestCollectorOptions, fn?: EffectVitest.TestFunction<ExtraContext> | undefined): void

Effect-aware Vitest helpers: it.effect scopes each test, layer shares a scoped service layer across a suite, describe groups scenarios, and expect asserts their values and outcomes.

参数

名称类型说明
namestring | Function
fn?TestFunction<ExtraContext>
options?number

源码: packages/bolt/src/test/effect.ts:167

layer function

function layer<R, E>(layer_: Layer.Layer<R, E>, options?: { readonly memoMap?: Layer.MemoMap; readonly timeout?: Duration.Input; readonly excludeTestServices?: boolean; }): { (f: (it: EffectVitest.Vitest.MethodsNonLive<R>) => void): void; (name: string, f: (it: EffectVitest.Vitest.MethodsNonLive<R>) => void): void; }

Share one scoped Effect service layer across the tests in a suite.

参数

名称类型说明
layer_Layer.Layer<R, E>
options?{ readonly memoMap?: Layer.MemoMap; readonly timeout?: Duration.Input; readonly excludeTestServices?: boolean; }

源码: packages/bolt/src/test/effect.ts:169

readLogRows function

function readLogRows(rows: readonly LogRow[], x: LogQuery): readonly LogRow[]

The kit host's runtime log reader: a host store's page over rows, newest first (the tail reads forward).

参数

名称类型说明
rowsreadonly LogRow[]
xLogQuery
  • before?: string

    rows older than this id

  • after?: string

    rows newer than this id (the tail)

  • level?: LogLevel

    exactly this severity

  • min?: LogLevel

    this severity or worse

  • text?: string

    the event name or its attributes

  • conversation?: string
  • run?: string
  • automation?: string

    events naming this automation

  • since?: string

    instants bounding at: since inclusive, until exclusive

  • until?: string
  • limit?: number

    rows per page, 1 to 200 (default 200)

源码: packages/bolt/src/test/effect.ts:271

respondSystem1 function

function respondSystem1(request: System1Request): Effect.Effect<DecisionResult, PortFailure>

A deterministic, zero-cost System 1 responder for tests: prefer the respond choice, otherwise the first choice, and return zero scores.

参数

名称类型说明
requestSystem1Request
  • state: Schema.$Record<Schema.String, Schema.Codec<Schema.Json, Schema.Json, never, never>>
  • questions: Schema.$Record<Schema.String, Schema.Union<readonly [Schema.Struct<{ readonly type: Schema.Literal<"noul">; readonly instructions: Schema.String; readonly criteria: Schema.Struct<{ readonly true: Schema.String; readonly false: Schema.String; }>; }>, Schema.Struct<{ readonly type: Schema.Literal<"choice">; readonly instructions: Schema.String; readonly criteria: Schema.$Record<Schema.String, Schem…

源码: packages/bolt/src/test/effect.ts:1028