hibana 0.8.0

Const-projected Affine Multiparty Session Types for choreography-first Rust protocols
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
use std::fs;
use std::path::{Path, PathBuf};

fn read(path: &str) -> String {
    let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    let full = root.join(path);
    fs::read_to_string(&full)
        .unwrap_or_else(|err| panic!("read {} failed: {}", full.display(), err))
}

fn read_dir_rs(path: &str) -> String {
    let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(path);
    let mut parts = fs::read_dir(&root)
        .unwrap_or_else(|err| panic!("read {} failed: {}", root.display(), err))
        .map(|entry| {
            entry
                .unwrap_or_else(|err| {
                    panic!("read dir entry in {} failed: {}", root.display(), err)
                })
                .path()
        })
        .filter(|path| {
            let Some(name) = path.file_name().and_then(|name| name.to_str()) else {
                return false;
            };
            path.extension().and_then(|ext| ext.to_str()) == Some("rs")
                && name != "tests.rs"
                && !name.ends_with("_tests.rs")
        })
        .collect::<Vec<_>>();
    parts.sort();
    let mut source = String::new();
    for part in parts {
        source.push_str(
            &fs::read_to_string(&part)
                .unwrap_or_else(|err| panic!("read {} failed: {}", part.display(), err)),
        );
    }
    source
}

fn endpoint_facade_source() -> String {
    let mut source = read("src/endpoint.rs");
    source.push_str(&read_dir_rs("src/endpoint"));
    source
}

fn assert_absent(readme: &str, forbidden: &str, why: &str) {
    assert!(!readme.contains(forbidden), "{why}: {forbidden}");
}

fn collect_source_files(root: &Path, out: &mut Vec<PathBuf>) {
    for entry in fs::read_dir(root)
        .unwrap_or_else(|err| panic!("read_dir {} failed: {}", root.display(), err))
    {
        let entry =
            entry.unwrap_or_else(|err| panic!("read_dir entry {} failed: {}", root.display(), err));
        let path = entry.path();
        if path.is_dir() {
            collect_source_files(&path, out);
        } else if path.extension().and_then(|ext| ext.to_str()) != Some("stderr") {
            out.push(path);
        }
    }
}

#[test]
fn readme_stays_self_contained_and_hibana_scoped() {
    let readme = read("README.md");

    for required in [
        "hibana-header.svg",
        "## What Hibana Is",
        "## Install",
        "## Quick Start",
        "## Application Guide",
        "## Protocol Integration",
        "## Guarantees",
        "## Validation",
        "cargo add hibana",
        "The default feature set is empty.",
        "flow().send() / recv() / offer() / RouteBranch::decode()",
        "`flow().send()`, `recv()`, or `RouteBranch::decode()` succeeds",
        "If you are writing an application, stay on `hibana::g` and `Endpoint`.",
        "are implementing a protocol crate, use `hibana::integration`",
        "Keep choreography terms local.",
        "protocol-neutral `WireControlKind` trait",
        "The message label is choreography identity. Control meaning comes from the",
        "control kind's descriptor metadata, not from reserved numeric labels.",
        "The public wire effect catalogue is:",
        "Protocol crates use the same `hibana::g` language as applications.",
        "no second composition language.",
        "let program = g::seq(prefix, app);",
        "let client: RoleProgram<0> = project(&program);",
        "let server: RoleProgram<1> = project(&program);",
        "let endpoint = rv.session(SessionId::new(1)).role(&client).enter()?;",
        "integration::runtime::Config::from_resources(...)",
        "integration::SessionKitStorage::uninit().init()",
        "kit.rendezvous(...)",
        "registered rendezvous .session(...).role(...)",
        "`integration::wire::{Payload, WireEncode, WirePayload}`",
        "fn decode_validated_payload(input: Payload<'_>) -> Self::Decoded<'_>",
        "`integration::ids::{EffIndex, Lane, SessionId}`",
        "`integration::cap::{GenericCapToken, WireControlKind, WireControlEffect}`",
        "`integration::runtime::TapEvent`",
        "cargo +1.95.0 check --no-default-features --lib -p hibana",
        "cargo +1.95.0 check --features std --lib -p hibana",
        "cargo +1.95.0 doc -p hibana --no-deps --no-default-features",
        "The full test suite is repository-only",
        "source-tree fixtures that",
        "intentionally excluded from the production crate package",
        "bash ./.github/scripts/run_final_form_gates.sh",
        "repo-only unit tests are enabled",
        "`hibana_repo_tests`",
        "It is intentionally kept outside the crate package.",
    ] {
        assert!(
            readme.contains(required),
            "README must stay self-contained and hibana-scoped: {required}"
        );
    }

    for forbidden in [
        "## Constitution",
        "Phase 7",
        "Phase 0a",
        ".github/scripts/check_",
        "final-form",
        "quarantine",
        "route frontier",
        "`WireDecode`",
        "owned default path",
        "hibana-quic",
        "hibana_mgmt",
        "hibana-mgmt",
        "hibana_epf",
        "hibana-epf",
        "hibana-cross-repo",
        "`hibana::integration::mgmt`",
        "`hibana::integration::policy::epf`",
        "`hibana::integration::mgmt::request_reply::PREFIX`",
        "`hibana::integration::mgmt::observe_stream::PREFIX`",
        "`hibana::integration::mgmt::ROLE_CONTROLLER`",
        "`hibana::integration::mgmt::ROLE_CLUSTER`",
        "`hibana::integration::mgmt::Request::Load(LoadRequest)`",
        "`hibana::integration::mgmt::Request::LoadAndActivate(LoadRequest)`",
        "`hibana::integration::mgmt::Request::Activate(SlotRequest)`",
        "`hibana::integration::mgmt::Request::Restore(SlotRequest)`",
        "`hibana::integration::mgmt::Request::Stats(SlotRequest)`",
        "`integration/cross-repo/`",
        "staging location for cross-repo smoke",
        "App code writes `APP: g::Program<_>`",
        "transport_prefix",
        "appkit",
        "appkits",
        "appkit_prefix",
        "build_management_prefix",
        "drive_management_pair",
        "MyDemux",
        "EPF",
        "project(&PROGRAM)",
        "const APP: g::Program<_>",
        "static APP: g::Program<_>",
        "const PROGRAM: g::Program<_>",
        "static PROGRAM: g::Program<_>",
        "`hibana::integration::program::steps`",
        "AUTO_MINT_WIRE",
        "enter(None)",
        "Passing `None`",
        "`CapDelegate`: `input[0] = (dst_rv << 16) | dst_lane`",
        "integration::SessionKit::enter(...)",
        "integration::policy::replay::PolicyAttrs",
        "integration::advanced::policy::replay::PolicyAttrs",
        "kit.enter::<",
        "fn decode_payload(input: Payload<'_>) -> Result<Self::Decoded<'_>, CodecError>",
        "cargo +1.95.0 test -p hibana --features std",
    ] {
        assert_absent(
            &readme,
            forbidden,
            "README must not leak other-crate or internal-only wording",
        );
    }

    assert_absent(
        &readme,
        &["project::", "<"].concat(),
        "README must not leak other-crate or internal-only wording",
    );

    for forbidden in ["cargo +nightly", "cargo +stable", "workspace_smoke"] {
        assert_absent(
            &readme,
            forbidden,
            "README must not pin removed toolchain or smoke-helper lanes",
        );
    }
}

#[test]
fn docs_do_not_regrow_stale_attach_api() {
    for path in [
        "README.md",
        "src/lib.rs",
        "src/integration.rs",
        "src/rendezvous/core.rs",
    ] {
        let source = read(path);
        for forbidden in [
            concat!("SessionKit::", "new"),
            "SessionKit::enter",
            "kit.enter::<",
            "enter(rv, sid",
            "from_resources(\n//!     &mut tap_buf,\n//!     &mut slab",
        ] {
            assert!(
                !source.contains(forbidden),
                "{path} must document the witness-chain attach API, not stale `{forbidden}`"
            );
        }
    }
}

#[test]
fn public_docs_do_not_expose_internal_storage_vocabulary() {
    for path in [
        "README.md",
        "src/lib.rs",
        "src/integration.rs",
        ".github/allowlists/lib-public-api.txt",
        ".github/allowlists/g-public-api.txt",
        ".github/allowlists/endpoint-public-api.txt",
        ".github/allowlists/integration-public-api.txt",
    ] {
        let source = read(path);
        for forbidden in ["resident", "Resident"] {
            assert!(
                !source.contains(forbidden),
                "{path} must keep resident descriptor/storage vocabulary internal: {forbidden}"
            );
        }
    }
}

#[test]
fn canonical_docs_are_readme_and_crate_docs_only() {
    let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    assert!(
        !root.join("docs").exists(),
        "docs/ must not regrow as a second canonical documentation tree"
    );
    assert!(
        !root.join("GUIDE.md").exists() && !root.join("INTERNALS.md").exists(),
        "standalone guide/internal docs must not regrow as second documentation authorities"
    );

    let readme = read("README.md");
    let endpoint = endpoint_facade_source();
    let lib = read("src/lib.rs");

    for (path, source) in [("README.md", readme.as_str()), ("src/lib.rs", lib.as_str())] {
        assert!(
            !source.contains("hibana::substrate"),
            "{path} must document the current integration surface, not stale substrate paths"
        );
        assert!(
            source.contains("hibana::integration"),
            "{path} must name the current integration surface"
        );
    }

    assert!(
        !readme.contains("preview restash on decode failure"),
        "README must not describe decode failure as a restashable preview"
    );
    assert!(
        endpoint.contains("A decode failure is terminal for the current generation"),
        "crate docs must document terminal decode failure semantics"
    );
    assert!(
        endpoint.contains("when a send, receive, or route decode succeeds")
            && endpoint.contains("Successful sends, receives, and route decodes consume")
            && endpoint.contains("/// progress. Dropped send/route previews")
            && !endpoint.contains("when a send or route decode succeeds")
            && !endpoint.contains("Successful sends and route decodes consume progress"),
        "endpoint docs must include direct recv() as a committed progress operation"
    );
    assert!(
        readme.contains("`flow().send()`, `recv()`, or `RouteBranch::decode()` succeeds")
            && !readme.contains("Endpoint progress happens when a send or\ndecode succeeds"),
        "README progress contract must include recv(), not only send/decode"
    );
    assert!(
        lib.contains("successful sends, receives, and route decodes")
            && !lib.contains("successful `send()` and `decode()` consume"),
        "crate root docs must include direct recv() as a committed progress operation"
    );
    assert!(
        !readme.contains("type BorrowedBytes = &'static [u8];"),
        "README borrowed payload example must not imply a static frame borrow"
    );
}

#[test]
fn projection_constructor_stays_on_canonical_call_shape() {
    let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    let forbidden = ["project::", "<"].concat();
    let mut files = vec![
        root.join("README.md"),
        root.join("src/lib.rs"),
        root.join("src/g.rs"),
        root.join("src/integration.rs"),
    ];

    collect_source_files(&root.join("tests"), &mut files);

    let mut offenders = Vec::new();
    for file in files {
        let src = fs::read_to_string(&file)
            .unwrap_or_else(|err| panic!("read {} failed: {}", file.display(), err));
        for (line_idx, line) in src.lines().enumerate() {
            if line.contains(&forbidden) {
                let rel = file.strip_prefix(&root).unwrap_or(file.as_path()).display();
                offenders.push(format!("{}:{}:{}", rel, line_idx + 1, line.trim()));
            }
        }
    }

    assert!(
        offenders.is_empty(),
        "projection must use the canonical `project(&program)` call shape:\n{}",
        offenders.join("\n")
    );
}

#[test]
fn quality_gates_do_not_directly_execute_non_executable_scripts() {
    let workflow = read(".github/workflows/quality-gates.yml");

    let required = "bash ./.github/scripts/run_final_form_gates.sh";
    assert!(
        workflow.contains(required),
        "quality gates must use the final-form gate as the only script authority: {required}"
    );

    for forbidden in [
        "dtolnay/rust-toolchain",
        "toolchain: stable",
        "cargo test",
        "cargo check",
        "run: ./.github/scripts/check_plane_boundaries.sh",
        "check_topology_hygiene.sh",
        "check_text_integrity.sh",
    ] {
        assert!(
            !workflow.contains(forbidden),
            "quality gates must remain a thin final-form wrapper: {forbidden}"
        );
    }
}

#[test]
fn protocol_wire_control_example_keeps_message_label_separate_from_control_metadata() {
    let readme = read("README.md");

    for required in [
        "const CUSTOM_WIRE_MSG_LABEL: u8 = 200;",
        "const TAG: u8 = 0x90;",
        "const EFFECT: WireControlEffect = WireControlEffect::Fence;",
        "{ CUSTOM_WIRE_MSG_LABEL }",
        "controls use reusable descriptor semantics",
    ] {
        assert!(
            readme.contains(required),
            "README explicit wire-control example must keep labels separate from control metadata: {required}"
        );
    }

    for forbidden in [
        "WireControlKind>::LABEL",
        "const LABEL: u8 =",
        "const TAP_ID",
        "CUSTOM_WIRE_TAP_ID",
        "0x0300 + 124",
        "0x0300 + 90",
    ] {
        assert!(
            !readme.contains(forbidden),
            "README explicit wire-control example must not reintroduce label-derived control metadata: {forbidden}"
        );
    }
}

#[test]
fn core_repo_keeps_cross_repo_harness_outside_tree() {
    let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("integration/cross-repo");
    assert!(
        !path.exists(),
        "cross-repo smoke must stay outside the hibana repo: {}",
        path.display()
    );
}

#[test]
fn readme_keeps_binding_surface_canonical_without_advanced_bucket() {
    let readme = read("README.md");
    let everyday = readme
        .split("Useful integration owners:")
        .nth(1)
        .and_then(|tail| tail.split("### Transport").next())
        .expect("README must keep everyday integration owners before transport details");

    assert!(
        !readme.contains("integration::binding::advanced") && !everyday.contains("::advanced"),
        "README must not teach a secondary advanced binding API"
    );
}

#[test]
fn docs_route_protocol_invisible_liveness_to_transport_errors() {
    let readme = read("README.md");
    let lib_rs = read("src/lib.rs");

    for doc in [readme.as_str(), lib_rs.as_str()] {
        assert!(
            doc.contains("TransportError")
                && doc.contains("poll_send")
                && doc.contains("poll_recv")
                && doc.contains("transport"),
            "docs must place protocol-invisible carrier liveness in the transport error path"
        );
    }
}

#[test]
fn crate_root_docs_do_not_regrow_internal_buckets() {
    let lib_rs = read("src/lib.rs");

    for forbidden in [
        "mod epf;",
        "pub mod runtime;",
        "pub mod transport;",
        "pub mod observe;",
    ] {
        assert!(
            !lib_rs.contains(forbidden),
            "crate root must stay on the minimal app/integration surface: {forbidden}"
        );
    }
}

#[test]
fn crate_root_docs_keep_descriptor_first_control_story() {
    let lib_rs = read("src/lib.rs");

    for required in [
        "descriptor-first control facts",
        "Public wire controls expose a `WireControlEffect`",
        "internal atomic operation are derived descriptor facts",
    ] {
        assert!(
            lib_rs.contains(required),
            "crate root docs must describe the descriptor-first control model: {required}"
        );
    }

    for forbidden in [
        "cancel pair, checkpoint/rollback, splice",
        "shot and permissions are embedded in the const metadata",
        "manages local state (lane/gen/cap/splice)",
    ] {
        assert!(
            !lib_rs.contains(forbidden),
            "crate root docs must not describe the removed control execution model: {forbidden}"
        );
    }
}