Skip to content

Time-Travel Testing (slice test), Deterministic Replay & Production Benchmarks

In traditional test runners (jest, vitest, bun test, deno test), if Test #1 writes a temporary file to disk or mutates a shared key-value store and fails mid-test, Test #2 inherits dirty state - leading to flaky tests that pass in isolation and fail in CI. Furthermore, no standard test runner lets you assert that a function stays within a strict CPU instruction fuel budget, memory ceiling, or Object-Capability security policy.

Slice solves both problems with slice test: the Time-Travel Test Runner.

This chapter shows you how to write unit, integration, and security tests with slice test, how to eliminate flaky time/randomness bugs with --deterministic, and how to run Slice’s 33-workload Docker benchmark suite against Node.js, Deno, and Bun.


1. Writing Tests with slice test ("slice:test" / "node:test" / "bun:test")

Section titled “1. Writing Tests with slice test ("slice:test" / "node:test" / "bun:test")”

You can import describe, test, it, beforeEach, afterEach, and expect from "slice:test", "node:test", or "bun:test" (or use them directly as globals).

1.1 How Automatic < 5 us Time-Travel Rollback Works

Section titled “1.1 How Automatic < 5 us Time-Travel Rollback Works”

Before executing every single test(...) / it(...) block, slice test automatically calls const snap = Slice.checkpoint(), runs your beforeEach hooks, test body, and afterEach hooks, and then calls Slice.restore(snap) inside a finally block!

That means:

  • Every file created, modified, or deleted via node:fs inside test("A", ...) is automatically rolled back in < 5 microseconds before test("B", ...) starts.
  • Every key or counter modified in Slice.kv inside test("A", ...) is automatically restored before test("B", ...) starts.
  • If you ever want a specific test to intentionally persist its state mutations, pass { isolateState: false } as the third argument: test("persists state", () => { ... }, { isolateState: false }).

Create tests/billing.test.ts:

import { describe, test, expect } from "slice:test";
import * as fs from "node:fs";
// Establish baseline state before the suite runs
Slice.kv.set("account:credits", "10000", 0);
fs.writeFileSync("/tmp/ledger.json", JSON.stringify({ balance: 10000 }));
describe("Billing Engine Time-Travel Suite", () => {
test("debits credits and mutates /tmp/ledger.json in Test 1", () => {
Slice.kv.set("account:credits", "2500", 0);
fs.writeFileSync("/tmp/ledger.json", JSON.stringify({ balance: 2500, mutatedBy: "test-1" }));
expect(Slice.kv.get("account:credits")).toBe("2500");
expect(JSON.parse(fs.readFileSync("/tmp/ledger.json", "utf8")).balance).toBe(2500);
});
test("automatically sees clean baseline VFS and Slice.kv in Test 2 (< 5 us rollback!)", () => {
// Both Slice.kv and /tmp/ledger.json were automatically restored after Test 1!
expect(Slice.kv.get("account:credits")).toBe("10000");
expect(JSON.parse(fs.readFileSync("/tmp/ledger.json", "utf8"))).toEqual({ balance: 10000 });
});
test("enforces OCap security, CPU fuel budgets, and memory ceilings", () => {
// 1. Assert that reading /etc/passwd violates FsReadDenied
const unauthorizedRead = Slice.evalSandbox(`
const fs = require("node:fs");
fs.readFileSync("/etc/passwd", "utf8");
`, { allowRead: ["/tmp"], fuel: 50_000 });
expect(unauthorizedRead).toViolate("FsReadDenied");
// 2. Assert that cloud metadata SSRF is blocked even with wildcard network
const ssrfAttempt = Slice.evalSandbox(`
Slice.fetchSync("http://169.254.169.254/latest/meta-data/");
`, { fuel: 50_000 });
expect(ssrfAttempt).toViolate("NetAccessDenied");
// 3. Assert that a hot pricing calculation stays within 1,000 CPU fuel instructions & 16 KB RAM
const fastCalc = Slice.evalSandbox(`
const subtotal: number = 450 * 12;
subtotal
`, { fuel: 50_000 });
expect(fastCalc).toStayWithinFuel(1000);
expect(fastCalc).toStayWithinMemory(16384);
});
});

Run the suite with slice test:

Terminal window
slice test

Output:

[PASS] Billing Engine Time-Travel Suite > debits credits and mutates /tmp/ledger.json in Test 1 (1000 us, VFS+KV Rollback #1)
[PASS] Billing Engine Time-Travel Suite > automatically sees clean baseline VFS and Slice.kv in Test 2 (< 5 us rollback!) (1000 us, VFS+KV Rollback #2)
[PASS] Billing Engine Time-Travel Suite > enforces OCap security, CPU fuel budgets, and memory ceilings (1000 us, VFS+KV Rollback #3)
Slice Time-Travel Test Suite: 3 passed, 0 failed, 0 skipped (3 VFS+KV rollbacks in 14.58 ms, seed=Some(20261024))

2. Complete expect(actual) Matcher Reference

Section titled “2. Complete expect(actual) Matcher Reference”

All matchers support negation via .not (e.g., expect(x).not.toBe(0), expect(res).not.toViolate()).

Matcher Description
.toBe(expected) Strict equality (===).
.toEqual(expected) Deep structural equality for objects and arrays.
.toContain(itemOrSubstring) Asserts that a string contains itemOrSubstring or an array includes itemOrSubstring.
.toBeTruthy() / .toBeFalsy() Asserts Boolean(actual) === true or false.
.toBeNull() Asserts actual === null.
.toBeDefined() / .toBeUndefined() Asserts actual !== undefined or actual === undefined.
.toBeGreaterThan(n) / .toBeGreaterThanOrEqual(n) Numeric > and >= comparisons.
.toBeLessThan(n) / .toBeLessThanOrEqual(n) Numeric < and <= comparisons.
.toHaveLength(n) Asserts actual.length === n.
.toHaveProperty(key, val?) Asserts key in actual (and optionally deep-equals val).
.toThrow(substring?) Calls actual() and asserts that it throws an exception (optionally matching substring).

2.2 Slice-Exclusive Security & Resource Matchers

Section titled “2.2 Slice-Exclusive Security & Resource Matchers”

Pass either a SandboxEvalOutcome returned by Slice.evalSandbox(...) or a zero-argument function () => Slice.evalSandbox(...):

Matcher Description
.toViolate(kindOrSubstring?) Asserts that the sandboxed code trapped (ok === false) with a violation matching kindOrSubstring (e.g. "FsReadDenied", "FsWriteDenied", "NetAccessDenied", "EnvAccessDenied", "CpuFuelExhausted", "MemoryCeilingExceeded", "EGRESS_SECRET_LEAK_BLOCKED", or any message substring).
.toStayWithinFuel(maxFuel) Asserts that ok === true and fuelUsed <= maxFuel.
.toStayWithinMemory(maxBytes) Asserts that ok === true and memoryUsedBytes <= maxBytes.

3. Reproducible Debugging with --deterministic=<seed>

Section titled “3. Reproducible Debugging with --deterministic=<seed>”

By default, slice test runs with a deterministic seed (--deterministic=20261024), and you can pass --deterministic=<seed> to slice run, slice serve, or slice test:

Terminal window
slice test --deterministic=998877
slice run ./src/simulation.ts --deterministic=998877

When deterministic mode is active:

  1. Math.random(), crypto.randomUUID(), crypto.getRandomValues(), and crypto.subtle.generateKey() use a seeded SplitMix64 PRNG that produces the exact same sequence of values on every run.
  2. Date.now() and performance.now() use a monotonic virtual clock (1700000000000 + tick_ms) that advances deterministically.
  3. setTimeout(fn, delayMs) and setInterval(fn, delayMs) execute via Deterministic Virtual Time-Warp (0 ns wall-clock sleep): a setTimeout(fn, 5000) advances the virtual clock by +5000 ms and runs fn immediately without sleeping the OS thread!
  4. Outbound fetch() automatically records upstream HTTP responses into Slice.kv (fetch_cassette:<METHOD>:<URL>) and replays them deterministically.

4. Running the 33-Workload Docker Benchmark Suite (tests/)

Section titled “4. Running the 33-Workload Docker Benchmark Suite (tests/)”

Slice includes a comprehensive Linux x86_64 Docker benchmark suite (tests/) that tests 33 realistic multi-file TypeScript + node_modules applications, full-stack edge frameworks (Hono, itty-router + UnJS, Express/Polka, SvelteKit 3 + Svelte 5), and architectural case studies against the latest official releases of Bun, Deno, and Node.js, verifying 100% byte-for-byte identical JSON output across all 4 runtimes and automatically writing timestamped reports to tests/reports/latest.md plus a self-contained cross-release HTML comparison dashboard at tests/reports/comparison.html (node tests/scripts/generate_comparison_html.mjs).

Terminal window
# Run the automated benchmark suite & doc sync (PowerShell or Bash)
./scripts/run_benchmarks.sh
# Or run specific tagged suites:
./scripts/run_benchmarks.sh "apps,frameworks,case_studies,serve,swarm"

Latest Verified Benchmark Report: tests/reports/latest.md (Archive: bench_v0.15.0_20261127_233301Z_7ee5d25.md)
Provenance: Slice v0.15.0 (7ee5d25) | Generated 2026-11-27T23:33:01Z | Environment: Linux x86_64 Docker (io_uring SQPOLL + WRPKRU)
Scorecard Across All 33 Production Workloads: Beats Deno (v2.9.8) on 33/33, Node.js (v27.0.0-alpha.0.1.1) on 33/33, Bun (v1.4.5) on 33/33 cold one-shot, and all 3 runtimes on 33/33 workloads in --warm pooled execution.

1. Core Architecture, HTTP Throughput & 1,000-Tenant MicroVM Density

Section titled “1. Core Architecture, HTTP Throughput & 1,000-Tenant MicroVM Density”
Metric Slice (v0.15.0 SLICEBC\x01) Bun (v1.4.5) Deno (v2.9.8) Node.js (v27.0.0-alpha.0.1.1) Slice Advantage
In-Process Isolate Cold Start (P50 / P99) 0.85 us / 1.49 us N/A (Process/VM) N/A (Process/VM) N/A (Process/VM) ~120,000x faster than 125ms Firecracker VM
1,000-Tenant MicroVM Swarm (Boot + Exec) 1.03 ms (8.62 MB RSS) > 5,000 ms > 15,000 ms > 30,000 ms > 3,900x faster / ~32,000x denser
500-Module Monorepo Cold Boot (stat() Calls) 3.15 ms (0 stat()) 12.72 ms (500+ stat) 41.80 ms (500+ stat) 70.38 ms (1,500+ stat) 4.0x faster than Bun / 22.3x Node.js
HTTP/1.1 Keep-Alive Throughput (16k Reqs) 159,746 req/s (Tier-0)
140,405 req/s (Tier-1)
97,553 req/s 98,900 req/s 49,367 req/s 1.64x (Tier-0) / 1.44x (Tier-1) vs Bun.serve
Peak Process Memory (Max RSS Across Suite) 13.88 - 22.37 MB 36.75 - 48.25 MB 45.39 - 62.00 MB 68.45 - 90.59 MB 1.5x-2.4x less than Bun / 3.9x-6.8x less than Node
Multi-Tenant Security Containment 5 / 5 PASS (OCap+SES+Fuel+DLP) 0 / 5 (Ambient) 2 / 5 (Coarse CLI) 0 / 5 (Ambient) Hardware & Language Zero-Trust Isolation

2. Real-Life Workload Summary by Domain (All 33 Workloads Aggregated)

Section titled “2. Real-Life Workload Summary by Domain (All 33 Workloads Aggregated)”
Workload Domain & Stack Coverage Suites Slice Cold .cas Avg (Range) Slice Warm (--warm) Avg Bun v1.4.5 Avg Deno v2.9.8 Avg Node.js v27.0.0-alpha.0.1.1 Avg Category Speedup vs Bun / Node.js
Core Edge, Auth & Crypto (Apps 01, 04, 05, 16)
Multi-file TS, SHA-256/HMAC, JWT/OAuth2, .env Auto-DLP
4 7.03 ms (5.59-8.96 ms) 2.00 ms 16.39 ms 44.31 ms 59.33 ms 2.33x Bun (8.21x Warm) / 8.45x Node
NPM Ecosystem, AST & Disk I/O (Apps 02, 03, 06, 07, 08, 20)
semver, flatted, dlv/dset, mitt, 10-Shard JSONL I/O, Buffer
6 8.95 ms (6.17-12.05 ms) 2.38 ms 19.07 ms 48.74 ms 61.46 ms 2.13x Bun (8.00x Warm) / 6.86x Node
WinterTC Web Standards, Fetch Mesh & DLP (Apps 09-14, 17-19)
Request/Response, Static CDN 304, SSE, Live fetch, WebCrypto
9 13.41 ms (8.51-28.51 ms) 6.25 ms 20.36 ms 53.58 ms 90.24 ms 1.52x Bun (3.26x Warm) / 6.73x Node
Realtime WebSockets, Workers & Wasm/TSX (Apps 15, 21-24)
RFC 6455 WS, worker_threads + TCP/UDP, Pure-Rust wasmi Wasm, TSX SSR
5 14.28 ms (7.14-29.82 ms) 2.32 ms 30.17 ms 64.63 ms 82.53 ms 2.11x Bun (12.99x Warm) / 5.78x Node
Full-Stack Edge & Node Frameworks (FW 01-04)
Hono v4.6.20, itty-router + UnJS Nitro, Express/Polka node:http, SvelteKit 3.1.1 + Svelte 5.57.3
4 20.06 ms (14.31-30.29 ms) 7.00 ms 33.99 ms 57.76 ms 91.37 ms 1.69x Bun (4.86x Warm) / 4.56x Node
AI Agent, Multi-Tenant SaaS & Chaos Case Studies (CS 01-05)
Depth-4 ToT Agent, MCP Code Mode, 12-Tenant Mesh, Wasm CDR, 48 Payment Sagas
5 16.39 ms (8.85-29.01 ms) 4.57 ms 21.33 ms 54.81 ms 72.68 ms 1.30x Bun (4.67x Warm) / 4.43x Node

3. Flagship Real-World Representative Workloads (9 of 33 Highlights)

Section titled “3. Flagship Real-World Representative Workloads (9 of 33 Highlights)”
# Flagship Workload Slice Cold .cas Slice Warm (--warm) Bun v1.4.5 Deno v2.9.8 Node.js v27.0.0-alpha.0.1.1 Speedup vs Bun / Node.js
01 01-fintech-checkout (Multi-File TS + SHA-256) 5.59 ms 0.86 ms 14.73 ms 37.38 ms 57.37 ms 2.64x Bun (17.11x Warm) / 10.27x Node
03 03-disk-io-log-pipeline (10 JSONL Shards Disk I/O) 6.17 ms 1.10 ms 15.21 ms 44.60 ms 57.77 ms 2.47x Bun (13.78x Warm) / 9.37x Node
14 14-federated-api-mesh-dlp (bytes + dlv + dset + Live fetch) 12.99 ms 7.16 ms 24.71 ms 53.84 ms 105.46 ms 1.90x Bun (3.45x Warm) / 8.12x Node
20 20-node-compat-and-edge-router (Uint8Array Buffer/Node Core/AST Bundler) 9.40 ms 0.48 ms 24.26 ms 55.54 ms 68.57 ms 2.58x Bun (50.33x Warm) / 7.30x Node
22 22-worker-threads-and-raw-sockets (3 Worker Threads + TCP/UDP + 5-Ring Sec) 29.82 ms 2.59 ms 58.27 ms 116.34 ms 96.51 ms 1.95x Bun (22.47x Warm) / 3.24x Node
FW-01 FW-01: frameworks/01-hono-edge-microservice ([email protected] + hono/cookie + ms) 17.98 ms 5.29 ms 22.87 ms 57.19 ms 91.68 ms 1.27x Bun (4.32x Warm) / 5.10x Node
FW-04 FW-04: frameworks/04-sveltekit-edge-ssr (@sveltejs/[email protected] + [email protected] + [email protected]) 31.57 ms 13.19 ms 46.89 ms 71.81 ms 107.25 ms 1.55x Bun (3.56x Warm) / 3.54x Node
CS-01 CS-01: case_studies/01-tot-autonomous-sre-agent (20 ToT Sandboxes) 29.01 ms 11.99 ms 29.76 ms 73.08 ms 82.97 ms 1.03x Bun (2.48x Warm) / 2.86x Node
CS-05 CS-05: case_studies/05-time-travel-chaos-fuzzer-payments (48 Payment Sagas) 8.85 ms 2.35 ms 21.11 ms 63.96 ms 78.56 ms 2.39x Bun (8.99x Warm) / 8.88x Node

Full 33-workload latency breakdown, standalone binary metrics, peak RSS per app, and historical reports: tests/reports/latest.md.


5. Running Slice’s Rust Workspace Test Suite (For Contributors)

Section titled “5. Running Slice’s Rust Workspace Test Suite (For Contributors)”

If you are building Slice from source and want to verify the internal Rust unit test suites:

Terminal window
# Run all workspace unit and integration tests across all crates
cargo test --workspace