检查与测试
检查与测试
bolt check 编译工作区,并检查类型、结构历史和声明。bolt test 在临时数据库上运行你的测试。两者可在任何机器上运行,不需要主机。
测试
测试放在 tests/ 中,使用 Vitest 和 @effect/vitest。TestWorkspace.layer 在一个由 seed/test/ 填充的临时数据库上启动工作区。t.as(holder) 以管理员、成员或自动化的身份执行,所以测试验证的是真实权限,而不仅仅是代码。
// tests/claims-and-costings.test.ts (a sketch)
import { expect, it } from '@effect/vitest';
import { Effect } from 'effect';
import { TestWorkspace } from '@norbital-ai/bolt-cli/test';
// PROJECT is the id of a project whose zones include 'L01'
it.effect('refuses a BOQ cost item for an undeclared project zone', () =>
Effect.gen(function* () {
const t = yield* TestWorkspace;
const admin = yield* t.as(t.admin);
const item = (zone: string) => ({
item_code: 'BOQ-01',
description: 'Suspended Slabs',
project_id: PROJECT,
zone,
currency: 'SGD',
contract_qty: '1',
unit_rate: '100.00'
});
const refused = yield* Effect.flip(admin.act({ 'cost_items.create': [item('NO-SUCH-ZONE')] }));
expect(refused).toMatchObject({ _tag: 'ActRefused' });
const created = yield* admin.act({ 'cost_items.create': [item('L01')] });
expect(created.kind).toBe('committed');
}).pipe(Effect.provide(TestWorkspace.layer({ root: process.cwd(), now: '2026-06-01T00:00:00Z' })))
); 用少量虚构的数据行测试你自己的规则:一次成功的写入和一次被拒绝的写入,然后检查保存了什么。it.effect 运行在测试时钟上;要显式推进时钟,而不是等待。
运行时会发生什么
bolt test在一个由seed/test/填充的临时数据库上启动工作区。- 第一次写入为未声明的项目分区创建工程量清单成本项:它以
ActRefused失败。 - 第二次写入使用已声明的分区
L01,结果为committed。整个过程不会触及真实数据库。