Skip to main content

qualia_core_db/poet_host/invoke/
coverage.rs

1//! Live Vibe coverage map.
2//!
3//! rustdoc (`all.html` / JSON) is the *discovery* index of types. Binding every
4//! public item is the wrong job. The three catalogs that drive Vibe are:
5//!
6//! 1. [`crate::CAPABILITY_DESCRIPTORS`] — engine families / MCP
7//! 2. [`WASM_ENGINE`] — `wasm_bridge/engine` (compute-engine.html, wasm-scientific)
8//! 3. [`ids::ALL_BOUND`] — what `capability.invoke` actually reaches
9//!
10//! Scripts may run in a WASM UI; on desktop they call the **native** host
11//! (`poet_eval`). The WASM *subset* is whatever this crate compiles under
12//! `wasm-ontology` / `wasm-scientific`. Nightly rustdoc JSON is an optional
13//! extra pass (`scripts/vibe-coverage.ps1`) — it never replaces these tables.
14
15use super::ids;
16use crate::CAPABILITY_DESCRIPTORS;
17use std::collections::BTreeMap;
18use vibe::Value;
19
20/// Where a candidate lives.
21#[derive(Clone, Copy, Debug, PartialEq, Eq)]
22pub enum Source {
23    Descriptor,
24    WasmEngine,
25    Invoke,
26}
27
28/// Where it can execute.
29#[derive(Clone, Copy, Debug, PartialEq, Eq)]
30pub enum Profile {
31    Native,
32    WasmScientific,
33    WasmOntology,
34    Both,
35}
36
37#[derive(Clone, Copy, Debug, PartialEq, Eq)]
38pub enum Bind {
39    Bound,
40    Unbound,
41}
42
43#[derive(Clone, Copy, Debug)]
44pub struct Row {
45    pub source: Source,
46    pub id: &'static str,
47    pub seam: &'static str,
48    pub profile: Profile,
49    pub bind: Bind,
50}
51
52/// Browser compute-engine exports (`wasm_bridge/engine/*`). Same math as native
53/// solvers; GPU forge is native-only. Keep this list in lockstep with that folder.
54pub const WASM_ENGINE: &[(&str, &str)] = &[
55    ("cas_differentiate_wasm", "math"),
56    ("cas_simplify_wasm", "math"),
57    ("cas_expand_wasm", "math"),
58    ("cas_evaluate_wasm", "math"),
59    ("cas_factor_wasm", "math"),
60    ("cas_solve_quadratic_wasm", "math"),
61    ("la_matmul_wasm", "math"),
62    ("la_transpose_wasm", "math"),
63    ("la_determinant_wasm", "math"),
64    ("la_solve_wasm", "math"),
65    ("la_eigen_symmetric_wasm", "math"),
66    ("la_eigenvalues_wasm", "math"),
67    ("la_svd_wasm", "math"),
68    ("la_polynomial_roots_wasm", "math"),
69    ("stats_describe_wasm", "stats"),
70    ("stats_correlation_wasm", "stats"),
71    ("stats_linear_regression_wasm", "stats"),
72    ("num_bessel_j_wasm", "math"),
73    ("num_gcd_lcm_wasm", "math"),
74    ("num_is_prime_wasm", "math"),
75    ("crypto_sha256", "crypto"),
76    ("crypto_sha512", "crypto"),
77    ("crypto_blake3", "crypto"),
78    ("units_convert", "math"),
79    ("xform_dft", "math"),
80    ("graph_shortest_path", "graph"),
81    ("graph_spreading_activation", "graph"),
82];
83
84fn profile_name(p: Profile) -> &'static str {
85    match p {
86        Profile::Native => "native",
87        Profile::WasmScientific => "wasm-scientific",
88        Profile::WasmOntology => "wasm-ontology",
89        Profile::Both => "native+wasm",
90    }
91}
92
93fn source_name(s: Source) -> &'static str {
94    match s {
95        Source::Descriptor => "descriptor",
96        Source::WasmEngine => "wasm-engine",
97        Source::Invoke => "invoke",
98    }
99}
100
101fn bind_name(b: Bind) -> &'static str {
102    match b {
103        Bind::Bound => "bound",
104        Bind::Unbound => "unbound",
105    }
106}
107
108fn wasm_suggested_invoke(export: &str) -> Option<&'static str> {
109    match export {
110        "la_matmul_wasm" => Some(ids::LINALG_MATMUL),
111        "la_transpose_wasm" => Some(ids::LA_TRANSPOSE),
112        "la_determinant_wasm" => Some(ids::LA_DET),
113        "la_solve_wasm" => Some(ids::LA_SOLVE),
114        "la_eigen_symmetric_wasm" => Some(ids::LA_EIGEN_SYM),
115        "la_eigenvalues_wasm" => Some(ids::LA_EIGENVALUES),
116        "la_svd_wasm" => Some(ids::LA_SVD),
117        "la_polynomial_roots_wasm" => Some(ids::LA_POLY_ROOTS),
118        "cas_differentiate_wasm" => Some(ids::CAS_DIFFERENTIATE),
119        "cas_simplify_wasm" => Some(ids::CAS_SIMPLIFY),
120        "cas_expand_wasm" => Some(ids::CAS_EXPAND),
121        "cas_evaluate_wasm" => Some(ids::SYMBOLIC_EVAL),
122        "cas_factor_wasm" => Some(ids::CAS_FACTOR),
123        "cas_solve_quadratic_wasm" => Some(ids::CAS_SOLVE_QUADRATIC),
124        "num_gcd_lcm_wasm" => Some(ids::NT_GCD),
125        "num_is_prime_wasm" => Some(ids::NT_PRIME),
126        "num_bessel_j_wasm" => Some(ids::SPEC_BESSEL),
127        "stats_describe_wasm" => Some(ids::STAT_MEAN),
128        "stats_correlation_wasm" => Some(ids::STAT_PEARSON),
129        "stats_linear_regression_wasm" => Some(ids::STAT_LINEAR_REGRESSION),
130        "crypto_sha256" => Some(ids::CRYPTO_SHA256),
131        "crypto_sha512" => Some(ids::CRYPTO_SHA512),
132        "crypto_blake3" => Some(ids::CRYPTO_BLAKE3),
133        "units_convert" => Some(ids::UNITS_CONVERT),
134        "xform_dft" => Some(ids::XFORM_DFT),
135        "graph_shortest_path" => Some(ids::GRAPH_SHORTEST_PATH),
136        "graph_spreading_activation" => Some(ids::GRAPH_SPREADING_ACTIVATION),
137        _ => None,
138    }
139}
140
141/// Full coverage rows. Cold path — `Vec` is allowed.
142pub fn rows() -> Vec<Row> {
143    let mut out = Vec::new();
144    for d in CAPABILITY_DESCRIPTORS {
145        let bound = ids::family_bound(d.name);
146        out.push(Row {
147            source: Source::Descriptor,
148            id: d.name,
149            seam: d.domain,
150            profile: if d.surfaces.iter().any(|s| s.contains("wasm")) {
151                Profile::Both
152            } else {
153                Profile::Native
154            },
155            bind: if bound { Bind::Bound } else { Bind::Unbound },
156        });
157    }
158    for (export, seam) in WASM_ENGINE {
159        let bound = wasm_suggested_invoke(export).is_some();
160        out.push(Row {
161            source: Source::WasmEngine,
162            id: export,
163            seam,
164            profile: Profile::WasmScientific,
165            bind: if bound { Bind::Bound } else { Bind::Unbound },
166        });
167    }
168    for id in ids::ALL_BOUND {
169        out.push(Row {
170            source: Source::Invoke,
171            id,
172            seam: ids::seam_for(id),
173            profile: Profile::Both,
174            bind: Bind::Bound,
175        });
176    }
177    out
178}
179
180/// Coverage report as a Vibe `Value`.
181pub fn as_value() -> Value {
182    let rs = rows();
183    let bound = rs.iter().filter(|r| r.bind == Bind::Bound).count() as u64;
184    let unbound = rs.iter().filter(|r| r.bind == Bind::Unbound).count() as u64;
185    let list: Vec<Value> = rs
186        .iter()
187        .map(|r| {
188            let mut m = BTreeMap::new();
189            m.insert("source".into(), Value::String(source_name(r.source).into()));
190            m.insert("id".into(), Value::String(r.id.into()));
191            m.insert("seam".into(), Value::String(r.seam.into()));
192            m.insert(
193                "profile".into(),
194                Value::String(profile_name(r.profile).into()),
195            );
196            m.insert("bind".into(), Value::String(bind_name(r.bind).into()));
197            Value::Record(m)
198        })
199        .collect();
200    let mut out = BTreeMap::new();
201    out.insert("bound".into(), Value::U64(bound));
202    out.insert("unbound".into(), Value::U64(unbound));
203    out.insert("rows".into(), Value::List(list));
204    out.insert(
205        "note".into(),
206        Value::String(
207            "rustdoc lists types; bind operations. Desktop Vibe calls native. WASM subset = wasm-ontology/wasm-scientific cfgs."
208                .into(),
209        ),
210    );
211    Value::Record(out)
212}
213
214/// Coverage report as Markdown.
215pub fn markdown() -> String {
216    let rs = rows();
217    let mut s = String::from(
218        "# Vibe coverage matrix\n\nGenerated from `CAPABILITY_DESCRIPTORS` + `wasm_bridge/engine` + `ids::ALL_BOUND`.\n\n| source | id | seam | profile | bind |\n|---|---|---|---|---|\n",
219    );
220    for r in &rs {
221        s.push_str(&format!(
222            "| {} | `{}` | {} | {} | {} |\n",
223            source_name(r.source),
224            r.id,
225            r.seam,
226            profile_name(r.profile),
227            bind_name(r.bind)
228        ));
229    }
230    s
231}
232
233/// Machine-readable schema for a capability.invoke ID (T51).
234#[derive(Clone, Copy, Debug, PartialEq, Eq)]
235pub struct MachineSchema {
236    pub id: &'static str,
237    pub family: &'static str,
238    pub honesty: &'static str,
239    pub effect_class: &'static str,
240    pub arg_shape: &'static str,
241    pub return_shape: &'static str,
242}
243
244pub const SCHEMAS: &[MachineSchema] = &[
245    MachineSchema {
246        id: ids::DAG_EXECUTE,
247        family: "agent",
248        honesty: "certified",
249        effect_class: "Cold",
250        arg_shape: r#"{"type":"list","items":{"type":"record"}}"#,
251        return_shape: r#"{"type":"string"}"#,
252    },
253    MachineSchema {
254        id: ids::DAG_VALIDATE,
255        family: "agent",
256        honesty: "certified",
257        effect_class: "Pure",
258        arg_shape: r#"{"type":"list","items":{"type":"record"}}"#,
259        return_shape: r#"{"type":"bool"}"#,
260    },
261    MachineSchema {
262        id: ids::DAG_STATUS,
263        family: "agent",
264        honesty: "certified",
265        effect_class: "Pure",
266        arg_shape: r#"{"type":"record"}"#,
267        return_shape: r#"{"type":"record","properties":{"status":{"type":"string"}}}"#,
268    },
269    MachineSchema {
270        id: ids::DISCOVERY_LIST,
271        family: "runtime",
272        honesty: "certified",
273        effect_class: "Pure",
274        arg_shape: r#"{"type":"null"}"#,
275        return_shape: r#"{"type":"list","items":{"type":"string"}}"#,
276    },
277    MachineSchema {
278        id: ids::SHACL_VALIDATE,
279        family: "graph",
280        honesty: "certified",
281        effect_class: "Pure",
282        arg_shape: r#"{"type":"record"}"#,
283        return_shape: r#"{"type":"record"}"#,
284    },
285    MachineSchema {
286        id: ids::GRAPH_STATS,
287        family: "graph",
288        honesty: "certified",
289        effect_class: "Pure",
290        arg_shape: r#"{"type":"null"}"#,
291        return_shape: r#"{"type":"record"}"#,
292    },
293    MachineSchema {
294        id: ids::GRAPH_SPARQL,
295        family: "graph",
296        honesty: "certified",
297        effect_class: "Pure",
298        arg_shape: r#"{"type":"string"}"#,
299        return_shape: r#"{"type":"list"}"#,
300    },
301    MachineSchema {
302        id: ids::GRAPH_SHORTEST_PATH,
303        family: "graph",
304        honesty: "certified",
305        effect_class: "Pure",
306        arg_shape: r#"{"type":"record"}"#,
307        return_shape: r#"{"type":"list"}"#,
308    },
309    MachineSchema {
310        id: ids::LINALG_MATMUL,
311        family: "math",
312        honesty: "certified",
313        effect_class: "Pure",
314        arg_shape: r#"{"type":"record","properties":{"a":{"type":"list"},"b":{"type":"list"}}}"#,
315        return_shape: r#"{"type":"list"}"#,
316    },
317    MachineSchema {
318        id: ids::NT_GCD,
319        family: "math",
320        honesty: "certified",
321        effect_class: "Pure",
322        arg_shape: r#"{"type":"record","properties":{"a":{"type":"integer"},"b":{"type":"integer"}}}"#,
323        return_shape: r#"{"type":"integer"}"#,
324    },
325    MachineSchema {
326        id: ids::NT_PRIME,
327        family: "math",
328        honesty: "certified",
329        effect_class: "Pure",
330        arg_shape: r#"{"type":"integer"}"#,
331        return_shape: r#"{"type":"bool"}"#,
332    },
333    MachineSchema {
334        id: ids::CALC_SIMPSON,
335        family: "math",
336        honesty: "certified",
337        effect_class: "Pure",
338        arg_shape: r#"{"type":"record"}"#,
339        return_shape: r#"{"type":"number"}"#,
340    },
341    MachineSchema {
342        id: ids::DEONTIC_EVAL,
343        family: "logic",
344        honesty: "certified",
345        effect_class: "Pure",
346        arg_shape: r#"{"type":"null"}"#,
347        return_shape: r#"{"type":"record"}"#,
348    },
349    MachineSchema {
350        id: ids::EPISTEMIC_EVAL,
351        family: "logic",
352        honesty: "certified",
353        effect_class: "Pure",
354        arg_shape: r#"{"type":"null"}"#,
355        return_shape: r#"{"type":"record"}"#,
356    },
357    MachineSchema {
358        id: ids::PHYS_PROJECTILE,
359        family: "physics",
360        honesty: "certified",
361        effect_class: "Pure",
362        arg_shape: r#"{"type":"record"}"#,
363        return_shape: r#"{"type":"record"}"#,
364    },
365    MachineSchema {
366        id: ids::PHYS_WAVE_1D,
367        family: "physics",
368        honesty: "certified",
369        effect_class: "Pure",
370        arg_shape: r#"{"type":"record"}"#,
371        return_shape: r#"{"type":"list"}"#,
372    },
373    MachineSchema {
374        id: ids::PHYS_FIELD_SAMPLE,
375        family: "physics",
376        honesty: "certified",
377        effect_class: "Pure",
378        arg_shape: r#"{"type":"record"}"#,
379        return_shape: r#"{"type":"record"}"#,
380    },
381    MachineSchema {
382        id: ids::PHYS_MATERIAL_QUERY,
383        family: "physics",
384        honesty: "certified",
385        effect_class: "Pure",
386        arg_shape: r#"{"type":"record"}"#,
387        return_shape: r#"{"type":"record"}"#,
388    },
389    MachineSchema {
390        id: ids::PHYS_TICK_SPECTRUM_READING,
391        family: "physics",
392        honesty: "certified",
393        effect_class: "Pure",
394        arg_shape: r#"{"type":"record","properties":{"part":{"type":"string"},"signature":{"type":"string"},"reading":{"type":"string"}}}"#,
395        return_shape: r#"{"type":"record"}"#,
396    },
397    MachineSchema {
398        id: ids::PHYS_PART_SIGNATURE,
399        family: "physics",
400        honesty: "certified",
401        effect_class: "Pure",
402        arg_shape: r#"{"type":"record","properties":{"part":{"type":"string"},"signature":{"type":"string"},"facet":{"type":"string"}}}"#,
403        return_shape: r#"{"type":"record"}"#,
404    },
405    MachineSchema {
406        id: ids::PHYS_EVALUATE_INTERACTION,
407        family: "physics",
408        honesty: "certified",
409        effect_class: "Pure",
410        arg_shape: r#"{"type":"record"}"#,
411        return_shape: r#"{"type":"record"}"#,
412    },
413    MachineSchema {
414        id: ids::PHYS_HARMONIC_OSCILLATOR,
415        family: "physics",
416        honesty: "certified",
417        effect_class: "Pure",
418        arg_shape: r#"{"type":"record"}"#,
419        return_shape: r#"{"type":"record"}"#,
420    },
421    MachineSchema {
422        id: ids::SPECTRAL_EMF_TO_RGB,
423        family: "spectral",
424        honesty: "certified",
425        effect_class: "Pure",
426        arg_shape: r#"{"type":"record"}"#,
427        return_shape: r#"{"type":"record"}"#,
428    },
429    MachineSchema {
430        id: ids::RENDER_SCENE,
431        family: "render",
432        honesty: "certified",
433        effect_class: "Pure",
434        arg_shape: r#"{"type":"record"}"#,
435        return_shape: r#"{"type":"record"}"#,
436    },
437    MachineSchema {
438        id: ids::RENDER_SVG_PATH,
439        family: "render",
440        honesty: "certified",
441        effect_class: "Pure",
442        arg_shape: r#"{"type":"record"}"#,
443        return_shape: r#"{"type":"string"}"#,
444    },
445    MachineSchema {
446        id: ids::RENDER_CSS_COLOR,
447        family: "render",
448        honesty: "certified",
449        effect_class: "Pure",
450        arg_shape: r#"{"type":"record"}"#,
451        return_shape: r#"{"type":"string"}"#,
452    },
453    MachineSchema {
454        id: ids::MANIFOLD_PROJECT,
455        family: "manifold",
456        honesty: "certified",
457        effect_class: "Pure",
458        arg_shape: r#"{"type":"record"}"#,
459        return_shape: r#"{"type":"record"}"#,
460    },
461    MachineSchema {
462        id: ids::NLP_GAZETTEER_RUN,
463        family: "nlp",
464        honesty: "certified",
465        effect_class: "Pure",
466        arg_shape: r#"{"type":"string"}"#,
467        return_shape: r#"{"type":"list","items":{"type":"record"}}"#,
468    },
469    MachineSchema {
470        id: ids::CONDITIONING_VALIDATE,
471        family: "inference",
472        honesty: "certified",
473        effect_class: "Pure",
474        arg_shape: r#"{"type":"record"}"#,
475        return_shape: r#"{"type":"record"}"#,
476    },
477    MachineSchema {
478        id: ids::CONDITIONING_COMPILE,
479        family: "inference",
480        honesty: "certified",
481        effect_class: "Cold",
482        arg_shape: r#"{"type":"record"}"#,
483        return_shape: r#"{"type":"record"}"#,
484    },
485    MachineSchema {
486        id: ids::CONDITIONING_INSPECT,
487        family: "inference",
488        honesty: "certified",
489        effect_class: "Pure",
490        arg_shape: r#"{"type":"record"}"#,
491        return_shape: r#"{"type":"record"}"#,
492    },
493    MachineSchema {
494        id: ids::CONDITIONING_EVALUATE,
495        family: "inference",
496        honesty: "certified",
497        effect_class: "External",
498        arg_shape: r#"{"type":"record"}"#,
499        return_shape: r#"{"type":"record"}"#,
500    },
501    MachineSchema {
502        id: ids::CONDITIONING_ACTIVATE,
503        family: "inference",
504        honesty: "certified",
505        effect_class: "External",
506        arg_shape: r#"{"type":"record"}"#,
507        return_shape: r#"{"type":"record"}"#,
508    },
509    MachineSchema {
510        id: ids::CONDITIONING_ROLLBACK,
511        family: "inference",
512        honesty: "certified",
513        effect_class: "External",
514        arg_shape: r#"{"type":"record"}"#,
515        return_shape: r#"{"type":"record"}"#,
516    },
517    MachineSchema {
518        id: ids::INFERENCE_EMBED,
519        family: "inference",
520        honesty: "certified",
521        effect_class: "Pure",
522        arg_shape: r#"{"type":"string"}"#,
523        return_shape: r#"{"type":"list","items":{"type":"number"}}"#,
524    },
525    MachineSchema {
526        id: ids::INFERENCE_GROUNDING,
527        family: "inference",
528        honesty: "certified",
529        effect_class: "Pure",
530        arg_shape: r#"{"type":"record","properties":{"prompt":{"type":"string"},"text":{"type":"string"}}}"#,
531        return_shape: r#"{"type":"record"}"#,
532    },
533    MachineSchema {
534        id: ids::FINANCE_CONVERT_CURRENCY,
535        family: "econ",
536        honesty: "certified",
537        effect_class: "Pure",
538        arg_shape: r#"{"type":"record","properties":{"amount":{"type":"integer"},"rate_micros":{"type":"integer"}}}"#,
539        return_shape: r#"{"type":"record"}"#,
540    },
541    MachineSchema {
542        id: ids::CAPABILITY_GRANT,
543        family: "governance",
544        honesty: "certified",
545        effect_class: "Pure",
546        arg_shape: r#"{"type":"record"}"#,
547        return_shape: r#"{"type":"record"}"#,
548    },
549    MachineSchema {
550        id: ids::SENTINEL_INSPECT,
551        family: "governance",
552        honesty: "certified",
553        effect_class: "Pure",
554        arg_shape: r#"{"type":"record","properties":{"agent_did":{"type":"string"}}}"#,
555        return_shape: r#"{"type":"record"}"#,
556    },
557    MachineSchema {
558        id: ids::AUDIO_SPECTRUM,
559        family: "audio",
560        honesty: "certified",
561        effect_class: "Pure",
562        arg_shape: r#"{"type":"record"}"#,
563        return_shape: r#"{"type":"record"}"#,
564    },
565    MachineSchema {
566        id: ids::SCENE_CREATE,
567        family: "render",
568        honesty: "certified",
569        effect_class: "Pure",
570        arg_shape: r#"{"type":"record","properties":{"name":{"type":"string"}}}"#,
571        return_shape: r#"{"type":"record"}"#,
572    },
573    MachineSchema {
574        id: ids::LA_GEMM,
575        family: "math",
576        honesty: "certified",
577        effect_class: "Pure",
578        arg_shape: r#"{"type":"record","properties":{"a":{"type":"record"},"b":{"type":"record"}}}"#,
579        return_shape: r#"{"type":"record"}"#,
580    },
581    MachineSchema {
582        id: ids::LA_DOT,
583        family: "math",
584        honesty: "certified",
585        effect_class: "Pure",
586        arg_shape: r#"{"type":"record","properties":{"a":{"type":"list"},"b":{"type":"list"}}}"#,
587        return_shape: r#"{"type":"record","properties":{"value":{"type":"number"}}}"#,
588    },
589    MachineSchema {
590        id: ids::LA_NORM,
591        family: "math",
592        honesty: "certified",
593        effect_class: "Pure",
594        arg_shape: r#"{"type":"record","properties":{"a":{"type":"list"}}}"#,
595        return_shape: r#"{"type":"record","properties":{"value":{"type":"number"}}}"#,
596    },
597    MachineSchema {
598        id: ids::LA_TRACE,
599        family: "math",
600        honesty: "certified",
601        effect_class: "Pure",
602        arg_shape: r#"{"type":"record","properties":{"a":{"type":"record"}}}"#,
603        return_shape: r#"{"type":"record","properties":{"value":{"type":"number"}}}"#,
604    },
605    MachineSchema {
606        id: ids::LA_IDENTITY,
607        family: "math",
608        honesty: "certified",
609        effect_class: "Pure",
610        arg_shape: r#"{"type":"record","properties":{"n":{"type":"integer"}}}"#,
611        return_shape: r#"{"type":"record"}"#,
612    },
613    MachineSchema {
614        id: ids::LA_INVERSE,
615        family: "math",
616        honesty: "certified",
617        effect_class: "Pure",
618        arg_shape: r#"{"type":"record","properties":{"a":{"type":"record"}}}"#,
619        return_shape: r#"{"type":"record"}"#,
620    },
621    MachineSchema {
622        id: ids::ECON_AGGREGATE_WEALTH,
623        family: "econ",
624        honesty: "certified",
625        effect_class: "Pure",
626        arg_shape: r#"{"type":"record"}"#,
627        return_shape: r#"{"type":"record","properties":{"status":{"type":"string"}}}"#,
628    },
629    MachineSchema {
630        id: ids::ECON_NARRATIVE_DIVERGENCE,
631        family: "econ",
632        honesty: "certified",
633        effect_class: "Pure",
634        arg_shape: r#"{"type":"record"}"#,
635        return_shape: r#"{"type":"record","properties":{"status":{"type":"string"}}}"#,
636    },
637];
638
639/// Machine schema for invoke `id`.
640pub fn schema_for(id: &str) -> Option<&'static MachineSchema> {
641    SCHEMAS.iter().find(|s| s.id == id)
642}
643
644/// All registered machine schemas.
645pub fn all_schemas() -> &'static [MachineSchema] {
646    SCHEMAS
647}
648
649#[cfg(test)]
650mod tests {
651    use super::*;
652
653    #[test]
654    fn descriptors_are_all_bound() {
655        for r in rows() {
656            if r.source == Source::Descriptor {
657                assert_eq!(r.bind, Bind::Bound, "{}", r.id);
658            }
659        }
660    }
661
662    #[test]
663    fn wasm_engine_fully_bound() {
664        // Every wasm_bridge/engine export now has a capability.invoke wrapper.
665        // If you add a new export to WASM_ENGINE, also add it to wasm_suggested_invoke.
666        let unbound = rows()
667            .into_iter()
668            .filter(|r| r.source == Source::WasmEngine && r.bind == Bind::Unbound)
669            .count();
670        assert_eq!(unbound, 0, "every WASM_ENGINE export must have a capability.invoke id — add it to wasm_suggested_invoke");
671    }
672
673    #[test]
674    fn coverage_value_has_counts() {
675        match as_value() {
676            Value::Record(m) => match m.get("bound") {
677                Some(Value::U64(n)) => assert!(*n > 20),
678                other => panic!("{other:?}"),
679            },
680            other => panic!("{other:?}"),
681        }
682    }
683
684    #[test]
685    fn schema_for_known_id() {
686        let s = schema_for(ids::DAG_EXECUTE).expect("DAG_EXECUTE must have a schema");
687        assert_eq!(s.family, "agent");
688        assert_eq!(s.effect_class, "Cold");
689        let gemm = schema_for(ids::LA_GEMM).expect("LA_GEMM must have a schema");
690        assert_eq!(gemm.honesty, "certified");
691        let wealth = schema_for(ids::ECON_AGGREGATE_WEALTH).expect("wealth schema");
692        assert_eq!(wealth.honesty, "certified");
693    }
694
695    #[test]
696    fn schema_for_unknown_id() {
697        assert!(schema_for("nonexistent.foo").is_none());
698    }
699
700    #[test]
701    fn all_schemas_nonempty() {
702        assert!(!all_schemas().is_empty());
703    }
704
705    #[test]
706    fn every_schema_has_family() {
707        for s in all_schemas() {
708            assert!(!s.family.is_empty(), "schema {} has empty family", s.id);
709            assert!(
710                !s.arg_shape.is_empty(),
711                "schema {} has empty arg_shape",
712                s.id
713            );
714            assert!(
715                !s.return_shape.is_empty(),
716                "schema {} has empty return_shape",
717                s.id
718            );
719        }
720    }
721}