@githolon/testing-Nomos域的法律TDD
测试你的律法 任何同行判断它的方式. testHolon() 靴子峡谷
同行办公室 正在与节点本地开发平台进行中
(原始内容存档于2012-10-12) (英语). wasm32-wasp1 内核文物——每个平台使用的相同生命周期——安装了您
将律法编成起源, 并给你一个喇叭
通过编译器生成的接收器从vitest驱动(build/<name>.reception.mjs) (中文(简体) ). 无物被模拟:每个生成的呼叫运行真实
作者出道口(载荷 zod ) 计划再运行 出道口 出道口 出道口 出道口 出道口 出道口 出道口 出道口 出道口 出道口 出道口 出道口 出道口 出道口 出道口 出道口口 出道口 出道口口 出道口 出道口口 出道口 出道口 出道口出道口 出道口出道 出道口出道口出道口出道 出道口出道 出道口出道口出道口出道口口出道口出道口出道口出道口出道口出道口出道口出道口出道口出道口出道口出道口出道口出道口出道口出道口出道口出道口出道口出道口出道口出道口出道
被封在铁链上 verify() 是同一个原 verify_chain 页:1
云运行于上传生.
npm i -D @githolon/testing vitest
npx nomos-compile # your canonical law → build/<name>.law.usdz
import { describe, expect, it } from "vitest";
import { testHolon } from "@githolon/testing";
import { seatsClient } from "./build/seats.reception.mjs";
it("the law refuses an over-capacity booking", async () => {
const h = await testHolon({ law: "./build/seats.law.usdz", deterministic: true });
const app = h.app(seatsClient, { actor: "person:alice" });
const b = await app.openBooking({ label: "launch", capacity: 2 });
await app.takeSeat({ bookingId: b.booking, attendee: "ada", takenAt: T });
await app.takeSeat({ bookingId: b.booking, attendee: "bob", takenAt: T });
// THE HEADLINE — invariants are real law; the refusal carries the law's own reject code:
await expect(
app.takeSeat({ bookingId: b.booking, attendee: "eve", takenAt: T }),
).rejects.toThrow(/seats-exceed-capacity/);
});
水面 水面
const h = await testHolon({
law: "./build/<name>.law.usdz", // opaque canonical archive; the kernel composes and identifies it
deterministic: true, // pinned clock + seeded rng + fixed replica (below)
});
const app = h.app(generatedClient, { actor: "person:alice" });
await app.someBusinessAction(typedPayload); // compiler-generated payload, result and USDA codec
await app.someDeclaredQuestion(typedParams); // compiler-generated nominal query + typed decoder
h.intents(); // the chain, parsed — genesis installs first, then every dispatch
h.verify(); // the wasm verify_chain verdict (the cloud's upload-birth gate)
await h.fork(); // a cheap what-if branch — a fresh engine cold-mounting the
// exact tree bytes; fork dispatches never touch the parent
await h.device(); // another offline device starting from this exact state
await h.sync(peer); // idempotent exchange; conflicts remain typed domain data
await h.restart(); // cold rebuild from ledger history, never a trusted snapshot
h.lawHash; // sha256(package bytes) — the content-addressed law id
h.kernelSha256; // exact provider-selected kernel fetched, verified and cached by digest
Refusal 已输入 : { name: "Refusal", domain, directiveId, refusal } 与
逐字记录 message - 有效载荷 -- -- schema拒绝、缺失事例和
被宣布的无变种人全部通过同一条道到达,与边缘完全相同.
决定时钟( R)
计划是纯粹的功能 (payload, ports)被俘虏的人质
钟和Rng 在每个意图的信封。 绳子都钉在那主机上
边框( 以同步作者调用为范围 —— 引擎未受影响 ) :
// the shorthand: clock 2026-01-01 advancing +1s/intent, seed 42, replica 7
const h = await testHolon({ law, deterministic: true });
// or granular:
const h = await testHolon({
law,
clock: { start: "2026-01-01T00:00:00.000Z", stepMs: 1000 }, // or an ISO/ms start, or () => now
seed: 7, // minted ids reproduce run-to-run
replica: 99, // the 63-bit replica id on every captured clock
});
await app.someBusinessAction(payload);
同样的种子 + 时钟 + 复制 + QQ 字节相同历史相同的薄荷身份证, 同样的链子头,运行后运行。 (记住: 域名时间戳仍然搭入 IN 您的有效载荷作为 ISO 字符串—— 捕获的时钟是信封的,而不是您的 诸法相. )
食谱
测试一个不变量 (自无常门落地以来) 在作者处所、收监和核实的变量:
await expect(app.takeSeat(overCapacityPayload))
.rejects.toThrow(/seats-exceed-capacity/);
expect(h.intents().length).toBe(before); // a refusal commits NOTHING
expect(h.verify().valid).toBe(true); // the chain stays green
测试合并驱动程序 - 合并是法律:
await app.tagEntry({ entry: entry.ref, tags: ["kind"] });
await app.tagEntry({ entry: entry.ref, tags: ["warm", "kind"] });
expect((await app.entries.find(entry.ref)).tags).toEqual(["kind", "warm"]); // AddWins unions
await app.reactToEntry({ entry: entry.ref, reactor: "bob", reaction: "👏", reactedAt });
await app.reactToEntry({ entry: entry.ref, reactor: "bob", reaction: "💚", reactedAt: later });
expect((await app.entries.find(entry.ref)).reactions).toEqual({ bob: "💚" }); // MapOf(Lww)
测试一个衍生字段 ——发动机预测,从未入帐:
const { entry } = await app.signGuestbook({ mood: "grumpy", ... });
expect((await app.entries.find(entry)).moodEmoji).toBe("😠"); // projected
expect(JSON.stringify(h.intents().at(-1))).not.toContain("moodEmoji"); // never sealed
如果在叉子上的话 - 无后果分支:
const f = await h.fork();
const forkApp = f.app(generatedClient);
await expect(forkApp.breachingWrite(payload)).rejects.toThrow(/your-code/);
await forkApp.somethingElse(payload); // lands on the fork; parent app remains unchanged
跨越两个离线设备生成的外观 无内核、意图或 租户测试中的工作空间管道:
import { co2Client } from "../build/co2.reception";
const alice = await testHolon({ law: "./build/co2.law.usdz", deterministic: true });
const aliceApp = alice.app(co2Client, { actor: "person:alice" });
await aliceApp.addSite({ estateId, name: "Trafford Depot" });
const bob = await alice.device();
const bobApp = bob.app(co2Client, { actor: "person:bob" });
await aliceApp.mergeAssetStatus({ assetId, operationalStatus: "operational" });
await bobApp.mergeAssetStatus({ assetId, operationalStatus: "inspection-due" });
await alice.sync(bob);
const [conflict] = await aliceApp.conflicts.asset.pending();
await conflict.merge(() => "operational-after-inspection");
const restarted = await alice.restart();
expect(restarted.verify().valid).toBe(true);
工作实例: 这个软件包自己的套件( Nametest/harness.test.mjs,座位
petture)和客本实例的法律测试
(单位:千美元)examples/guestbook/test/law.test.mts) (中文(简体) ).
跑步时间是怎样来的(这本原话,老实说)
节点平台壳牌和犬类同行办公室 构建时捆入此包 从源模块。 释放携带 只有生产内核的SHA-256描述符——而不是专有可执行文件. 第一次击出胜利:
runtimeDir选项/NOMOS_OFFLINE_RUNTIME(或仅测试)GITHOLON_RUNTIME_DIR)——您控制的一个目录 持有{holon.wasm, bootstrap.law.usdz, nomos.law.usdz}。该主题必须匹配此包 固定释放文摘。 在 CI 中按下此目录, 以进行完全的隐形运行 .- 单曲 诺姆斯2雷波,
cloud/cloudflare-shell销售商 d. 直接使用dam +域名文物。 从来没有任何网络. - 释放缓存 —— 说
~/.holon/runtime/kernels/<release-sha>(单位:千美元)HOLON_CONFIG_DIR(原始内容存档于2017-03-25). overse. - 论云 ——取出不可磨灭之物
/v1/runtime/kernels/<release-sha>/holon.wasm加上公共框架 软件包从https://nomos.cafe(单位:千美元)cloud选项/NOMOS_CLOUD覆盖). 诺摩斯先核实字节后再去抓取.
除了单曲之外的每一道在Web Assembly(CAP-813)开始前都会验证内核的SIGNATURE:提供方
向安保部提供内核证明(/v1/runtime/kernels/<sha>/attestation.dsse.json)和释放键
证书集( e)/v1/runtime/kernel-release-key.certificate.dsse.json; 对照信任根进行验证
此包针并缓存到内核旁边 kernel.attestation.dsse.json 财务报告和审定财务报表
kernel-release-key.certificate.dsse.jsonA级 runtimeDir 必须携带两个文件。 未签署、外国或
已过期内核被键入拒绝 KernelAttestationRefused 命名失败的链接。 你造的内核
仅在明确的本地开发选择下运行 NOMOS_LOCAL_DEV_KERNEL_TRUST_ROOT=<your local-dev root>
(由签一个字的工具所印出) 绳子每次都会在板上公布.
因此:FIRST运行在单人机外的一款新鲜机器上需要网络
一次 一次吗. offline: true (或 GITHOLON_TESTING_OFFLINE=1禁止4号车道——你
获得一个明确错误来命名您的选项而不是一个惊喜获取 。 一个被遗忘或
不同的内核在Web Assembly开始前被拒绝.