doctrine 0.10.0

Project tooling CLI
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
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
// SPDX-License-Identifier: GPL-3.0-only
//! The status-class partition (SL-047 design §5.3, OQ-8; SL-158 D1 trinary) —
//! the pure policy data that classifies a node's authored status into
//! [`StatusClass::Workable`] (eligible for default-active work) /
//! [`StatusClass::Gating`] (non-workable, non-terminal — blocks dependents but
//! never surfaces as work) / [`StatusClass::Terminal`] (default-excluded,
//! never blocks dependents) / [`StatusClass::Unrecognised`] (the D12
//! conservative default: non-eligible **and** a diagnostic).
//!
//! Pure: no clock, RNG, or disk — a `(kind, status) -> StatusClass` lookup over the
//! static [`PARTITION`] table. Kind identity is the `&'static str` prefix (the same
//! identity `EntityKey` carries); `entity::Kind` is data, not `Eq`, so the table
//! keys on `kind.prefix`.
//!
//! **Drift canary (VT-1).** Each partitioned closed-enum kind asserts
//! `workable ∪ gating ∪ terminal == <kind>'s status vocabulary`, reading the REAL
//! authoritative const (`*_STATUSES` in each kind module) — so the canary FAILS at
//! test time if a kind adds a status the table forgot. REC is status-less (no
//! const-compare); slice binds against the ADR-009/`SLICE_STATUSES` lifecycle
//! vocabulary (its stringly status has no closed enum), and a slice status outside
//! the table rides `Unrecognised`.
//!
//! Consumed by the priority CLI surface (SL-047 PHASE-03 — `channels`/`surface` call
//! [`status_class`]), so the PHASE-02 self-clearing `not(test)` `dead_code`
//! suppression has retired itself, as designed (`mem.pattern.lint.
//! dead-code-expect-vs-cfg-test`).

use crate::{entity, kinds};

/// How a node's authored status classifies for default-active work selection.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum StatusClass {
    /// Eligible — the status is in the kind's workable set.
    Workable,
    /// Non-workable, non-terminal — the status is in the kind's gating set.
    /// A Gating node blocks its dependents (≠ Terminal) but never surfaces
    /// as work (≠ Workable). Knowledge records use this for unsettled states.
    Gating,
    /// Default-excluded — the status is in the kind's terminal set (or the
    /// status-less REC kind, whose every node is context-only).
    Terminal,
    /// Not in the kind's vocabulary — the D12 conservative default: non-eligible
    /// AND a diagnostic (the table forgot a status, or the status drifted).
    Unrecognised,
}

/// One kind's status partition: the workable (eligible), gating (blocks but not
/// eligible), and terminal (default-excluded) status sets, keyed by the kind's
/// canonical-id `prefix`. A status absent from ALL THREE sets is
/// [`StatusClass::Unrecognised`].
struct KindPartition {
    /// The kind's canonical-id prefix (`SL`, `ADR`, `ISS`, …) — kind identity.
    prefix: &'static str,
    workable: &'static [&'static str],
    /// Non-workable, non-terminal — blocks dependents but never eligible.
    gating: &'static [&'static str],
    terminal: &'static [&'static str],
}

/// The §5.3 status-class table, verbatim. Backlog's five prefixes
/// (`ISS`/`IMP`/`CHR`/`RSK`/`IDE`) share ONE partition (one generic backlog
/// vocabulary, PRD-009) — listed per-prefix so the lookup is a flat prefix match.
/// `promoted` is NOT modelled here (a node-attr concern surfaced in channels, F1).
/// REC is status-less and absent from this table — [`status_class`] maps its `None`
/// status to [`StatusClass::Terminal`] directly (DD-4 context-only, no diagnostic).
const PARTITION: &[KindPartition] = &[
    // slice — ADR-009 lifecycle vocabulary (stringly status, no closed enum).
    KindPartition {
        prefix: kinds::SL,
        workable: &[
            "proposed",
            "design",
            "plan",
            "ready",
            "started",
            "audit",
            "reconcile",
        ],
        gating: &[],
        terminal: &["done", "abandoned"],
    },
    // ADR
    KindPartition {
        prefix: kinds::ADR,
        workable: &["proposed"],
        gating: &[],
        terminal: &["accepted", "rejected", "superseded", "deprecated"],
    },
    // policy
    KindPartition {
        prefix: kinds::POL,
        workable: &["draft"],
        gating: &[],
        terminal: &["required", "superseded", "deprecated", "retired"],
    },
    // standard
    KindPartition {
        prefix: kinds::STD,
        workable: &["draft"],
        gating: &[],
        terminal: &["default", "required", "superseded", "deprecated", "retired"],
    },
    // PRD (product spec)
    KindPartition {
        prefix: kinds::PRD,
        workable: &["draft"],
        gating: &[],
        terminal: &["active", "deprecated", "superseded"],
    },
    // tech spec
    KindPartition {
        prefix: kinds::SPEC,
        workable: &["draft"],
        gating: &[],
        terminal: &["active", "deprecated", "superseded"],
    },
    // requirement
    KindPartition {
        prefix: kinds::REQ,
        workable: &["pending", "in-progress"],
        gating: &[],
        terminal: &["active", "deprecated", "retired", "superseded"],
    },
    // backlog ×5 — one generic vocabulary; `promoted` resolution handled in channels.
    KindPartition {
        prefix: kinds::ISS,
        workable: BACKLOG_WORKABLE,
        gating: &[],
        terminal: BACKLOG_TERMINAL,
    },
    KindPartition {
        prefix: kinds::IMP,
        workable: BACKLOG_WORKABLE,
        gating: &[],
        terminal: BACKLOG_TERMINAL,
    },
    KindPartition {
        prefix: kinds::CHR,
        workable: BACKLOG_WORKABLE,
        gating: &[],
        terminal: BACKLOG_TERMINAL,
    },
    KindPartition {
        prefix: kinds::RSK,
        workable: BACKLOG_WORKABLE,
        gating: &[],
        terminal: BACKLOG_TERMINAL,
    },
    KindPartition {
        prefix: kinds::IDE,
        workable: BACKLOG_WORKABLE,
        gating: &[],
        terminal: BACKLOG_TERMINAL,
    },
    // RV (review) — DERIVED active/done (NodeAttr already carries the derived string).
    KindPartition {
        prefix: kinds::RV,
        workable: &["active"],
        gating: &[],
        terminal: &["done"],
    },
    // REV (revision, SL-066/ADR-013) — its OWN row: REV vocab ≠ backlog's, so it
    // cannot ride the backlog arm. Without this row a `done`/`abandoned` REV
    // classifies `Unrecognised != Terminal` and `blocked_by` (channels.rs:67, which
    // excuses only `class == Terminal`) blocks its dependent FOREVER — the inverse of
    // the IDE-010 payoff. The terminal set reads REV's real vocab via the
    // `crate::revision::REV_STATUSES`-bound canary (`revision_partition_covers_the_real_vocabulary`).
    KindPartition {
        prefix: kinds::REV,
        workable: &["proposed", "started"],
        gating: &[],
        terminal: &["done", "abandoned"],
    },
    // Knowledge records (SL-059, NF-003 / D7; SL-158 D1 trinary) — NEVER
    // `Workable`: each kind's entry is `workable: &[]`, unsettled statuses in
    // `gating` (blocks dependents, never eligible), settled statuses in `terminal`.
    // The union `gating ∪ terminal` reads the REAL `knowledge::*_STATUSES` const,
    // so the VT-1 canary fails if a kind adds a status the table forgot.
    KindPartition {
        prefix: kinds::ASM,
        workable: &[],
        gating: &["held", "testing"],
        terminal: &["validated", "invalidated", "obsolete"],
    },
    KindPartition {
        prefix: kinds::DEC,
        workable: &[],
        gating: &["proposed"],
        terminal: &["accepted", "rejected", "superseded"],
    },
    KindPartition {
        prefix: kinds::QUE,
        workable: &[],
        gating: &["open"],
        terminal: &["answered", "obsolete"],
    },
    KindPartition {
        prefix: kinds::CON,
        workable: &[],
        gating: &["active"],
        terminal: &["waived", "superseded", "retired"],
    },
    KindPartition {
        prefix: kinds::EVD,
        workable: &[],
        gating: &["captured", "disputed"],
        terminal: &["confirmed", "retracted", "superseded"],
    },
    KindPartition {
        prefix: kinds::HYP,
        workable: &[],
        gating: &["proposed"],
        terminal: &["confirmed", "refuted"],
    },
];

/// The shared backlog workable set (the five backlog prefixes partition identically).
const BACKLOG_WORKABLE: &[&str] = &["open", "triaged", "started"];
/// The shared backlog terminal set (a promoted resolution is a SEPARATE channel
/// reason, F1 — not a status class).
const BACKLOG_TERMINAL: &[&str] = &["resolved", "closed"];

/// Classify a node's `(kind, status)` into a [`StatusClass`] (design §5.3; SL-158 D1 trinary).
///
/// - `Some(s)` → table lookup on `kind.prefix`: `s ∈ workable → Workable`,
///   `s ∈ gating → Gating`, `s ∈ terminal → Terminal`,
///   **else `Unrecognised`** (the D12 conservative default — non-eligible plus a
///   diagnostic).
/// - `None` (the status-less REC kind) → `Terminal`, NO diagnostic (DD-4
///   context-only, expected — never surfaced as drift).
/// - RV resolves through the table via its DERIVED `active`/`done` (already held in
///   `NodeAttr.status` from PHASE-01), exactly like any other kind.
///
/// `promoted` is intentionally NOT consulted here — a promoted backlog node is
/// excluded by a SEPARATE channel reason (F1 / REQ-075 AC2), surfaced where the
/// node-attr lives, not folded into the status class.
pub(crate) fn status_class(kind: &entity::Kind, status: Option<&str>) -> StatusClass {
    let Some(status) = status else {
        // The only status-less kind is REC: context-only, default-excluded, expected.
        return StatusClass::Terminal;
    };
    let Some(part) = PARTITION.iter().find(|p| p.prefix == kind.prefix) else {
        // A kind with no partition entry (e.g. a future kind) — conservative default.
        return StatusClass::Unrecognised;
    };
    if part.workable.contains(&status) {
        StatusClass::Workable
    } else if part.gating.contains(&status) {
        StatusClass::Gating
    } else if part.terminal.contains(&status) {
        StatusClass::Terminal
    } else {
        StatusClass::Unrecognised
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::test_support::SCHEMA_KNOWLEDGE;
    use crate::{
        adr, backlog, knowledge, policy, requirement, review, revision, slice, spec, standard,
    };
    use std::collections::BTreeSet;

    /// Look up a partition entry by prefix (test helper).
    fn part(prefix: &str) -> &'static KindPartition {
        PARTITION
            .iter()
            .find(|p| p.prefix == prefix)
            .expect("prefix in PARTITION")
    }

    /// `workable ∪ gating ∪ terminal` for a prefix, as a set.
    fn vocab(prefix: &str) -> BTreeSet<&'static str> {
        let p = part(prefix);
        p.workable
            .iter()
            .chain(p.gating.iter())
            .chain(p.terminal.iter())
            .copied()
            .collect()
    }

    fn set(items: &[&'static str]) -> BTreeSet<&'static str> {
        items.iter().copied().collect()
    }

    // -- VT-1: partition drift canary — table vocabulary == real const vocabulary --

    #[test]
    fn slice_partition_binds_adr009_lifecycle_vocabulary() {
        // slice has a STRINGLY status (no closed enum) — its canary binds to the
        // ADR-009 / SLICE_STATUSES lifecycle set, the transition authority.
        assert_eq!(vocab("SL"), set(slice::SLICE_STATUSES));
    }

    #[test]
    fn adr_partition_covers_the_real_vocabulary() {
        assert_eq!(vocab("ADR"), set(adr::ADR_STATUSES));
    }

    #[test]
    fn policy_partition_covers_the_real_vocabulary() {
        assert_eq!(vocab("POL"), set(policy::POLICY_STATUSES));
    }

    #[test]
    fn standard_partition_covers_the_real_vocabulary() {
        assert_eq!(vocab("STD"), set(standard::STANDARD_STATUSES));
    }

    #[test]
    fn prd_and_tech_spec_partitions_cover_the_real_vocabulary() {
        // SPEC_STATUSES covers BOTH the PRD and tech-spec rows.
        assert_eq!(vocab("PRD"), set(spec::SPEC_STATUSES));
        assert_eq!(vocab("SPEC"), set(spec::SPEC_STATUSES));
    }

    #[test]
    fn requirement_partition_covers_the_real_vocabulary() {
        assert_eq!(vocab("REQ"), set(requirement::REQ_STATUSES));
    }

    #[test]
    fn backlog_partition_covers_the_real_vocabulary() {
        // All five backlog prefixes share the one backlog vocabulary.
        for prefix in ["ISS", "IMP", "CHR", "RSK", "IDE"] {
            assert_eq!(
                vocab(prefix),
                set(backlog::BACKLOG_STATUSES),
                "{prefix} partition matches BACKLOG_STATUSES"
            );
        }
    }

    #[test]
    fn review_partition_covers_the_real_vocabulary() {
        assert_eq!(vocab("RV"), set(review::REVIEW_STATUSES));
    }

    // -- SL-066 VT-2: the REV partition's G1 canary (its own vocab, not backlog's) --

    #[test]
    fn revision_partition_covers_the_real_vocabulary() {
        // REV gets its OWN row + own const — the table vocab must equal the real
        // `revision::REV_STATUSES` (NOT backlog's), or a status drifts unnoticed.
        assert_eq!(vocab("REV"), set(revision::REV_STATUSES));
    }

    #[test]
    fn revision_done_and_abandoned_classify_terminal() {
        // The precondition for `needs REV-N` to unblock its dependent: a terminal
        // REV must classify `Terminal` (not `Unrecognised`), so `blocked_by` excuses
        // it (channels.rs:67). proposed/started stay `Workable`.
        assert_eq!(
            status_class(&revision::REV_KIND, Some("done")),
            StatusClass::Terminal
        );
        assert_eq!(
            status_class(&revision::REV_KIND, Some("abandoned")),
            StatusClass::Terminal
        );
        assert_eq!(
            status_class(&revision::REV_KIND, Some("proposed")),
            StatusClass::Workable
        );
        assert_eq!(
            status_class(&revision::REV_KIND, Some("started")),
            StatusClass::Workable
        );
    }

    // -- SL-059, SL-158 VT-1: the four knowledge partitions cover their real vocab (three-way) --

    #[test]
    fn knowledge_partitions_cover_the_real_vocabularies() {
        // VT-1 (three-way): workable ∪ gating ∪ terminal == statuses(kind) per kind;
        // the canary reads the REAL `knowledge::*_STATUSES` const.
        for kind in knowledge::RecordKind::ALL {
            let prefix = kind.prefix();
            assert_eq!(
                vocab(prefix),
                set(knowledge::statuses(kind)),
                "{prefix} partition matches statuses({kind:?})"
            );
        }
    }

    // -- SL-158 VT-2: class boundary per knowledge kind --------------------------

    #[test]
    fn knowledge_unsettled_gating_settled_terminal() {
        // VT-2: each unsettled status → Gating, each settled → Terminal, never Workable.
        // ASM
        assert_eq!(
            status_class(&knowledge::ASSUMPTION_KIND, Some("held")),
            StatusClass::Gating
        );
        assert_eq!(
            status_class(&knowledge::ASSUMPTION_KIND, Some("testing")),
            StatusClass::Gating
        );
        assert_eq!(
            status_class(&knowledge::ASSUMPTION_KIND, Some("validated")),
            StatusClass::Terminal
        );
        assert_eq!(
            status_class(&knowledge::ASSUMPTION_KIND, Some("invalidated")),
            StatusClass::Terminal
        );
        assert_eq!(
            status_class(&knowledge::ASSUMPTION_KIND, Some("obsolete")),
            StatusClass::Terminal
        );
        // DEC
        assert_eq!(
            status_class(&knowledge::DECISION_KIND, Some("proposed")),
            StatusClass::Gating
        );
        assert_eq!(
            status_class(&knowledge::DECISION_KIND, Some("accepted")),
            StatusClass::Terminal
        );
        assert_eq!(
            status_class(&knowledge::DECISION_KIND, Some("rejected")),
            StatusClass::Terminal
        );
        assert_eq!(
            status_class(&knowledge::DECISION_KIND, Some("superseded")),
            StatusClass::Terminal
        );
        // QUE
        assert_eq!(
            status_class(&knowledge::QUESTION_KIND, Some("open")),
            StatusClass::Gating
        );
        assert_eq!(
            status_class(&knowledge::QUESTION_KIND, Some("answered")),
            StatusClass::Terminal
        );
        assert_eq!(
            status_class(&knowledge::QUESTION_KIND, Some("obsolete")),
            StatusClass::Terminal
        );
        // CON
        assert_eq!(
            status_class(&knowledge::CONSTRAINT_KIND, Some("active")),
            StatusClass::Gating
        );
        assert_eq!(
            status_class(&knowledge::CONSTRAINT_KIND, Some("waived")),
            StatusClass::Terminal
        );
        assert_eq!(
            status_class(&knowledge::CONSTRAINT_KIND, Some("superseded")),
            StatusClass::Terminal
        );
        assert_eq!(
            status_class(&knowledge::CONSTRAINT_KIND, Some("retired")),
            StatusClass::Terminal
        );
        // EVD
        assert_eq!(
            status_class(&knowledge::EVIDENCE_KIND, Some("captured")),
            StatusClass::Gating
        );
        assert_eq!(
            status_class(&knowledge::EVIDENCE_KIND, Some("disputed")),
            StatusClass::Gating
        );
        assert_eq!(
            status_class(&knowledge::EVIDENCE_KIND, Some("confirmed")),
            StatusClass::Terminal
        );
        assert_eq!(
            status_class(&knowledge::EVIDENCE_KIND, Some("retracted")),
            StatusClass::Terminal
        );
        assert_eq!(
            status_class(&knowledge::EVIDENCE_KIND, Some("superseded")),
            StatusClass::Terminal
        );
        // HYP
        assert_eq!(
            status_class(&knowledge::HYPOTHESIS_KIND, Some("proposed")),
            StatusClass::Gating
        );
        assert_eq!(
            status_class(&knowledge::HYPOTHESIS_KIND, Some("confirmed")),
            StatusClass::Terminal
        );
        assert_eq!(
            status_class(&knowledge::HYPOTHESIS_KIND, Some("refuted")),
            StatusClass::Terminal
        );
    }

    // -- SL-158 VT-5: Gating record not eligible --------------------------------

    #[test]
    fn knowledge_gating_statuses_are_not_workable() {
        // VT-5: a Gating record is NOT eligible / not on the worklist.
        // `eligible` reads `status_class == Workable`; every unsettled/gating
        // knowledge status classifies Gating (≠ Workable).
        for kind in knowledge::RecordKind::ALL {
            for status in knowledge::statuses(kind) {
                let class = status_class(kind.kind(), Some(status));
                if class == StatusClass::Gating {
                    // Explicit: the gating status is NOT Workable → not eligible.
                    assert!(
                        class != StatusClass::Workable,
                        "{:?}/{status} is Gating — must not be Workable",
                        kind
                    );
                }
            }
        }
    }

    #[test]
    fn every_knowledge_status_classifies_gating_or_terminal_never_workable() {
        // SL-158: unsettled → Gating, settled → Terminal, NEVER Workable.
        for kind in knowledge::RecordKind::ALL {
            for status in knowledge::statuses(kind) {
                let class = status_class(kind.kind(), Some(status));
                assert!(
                    class == StatusClass::Gating || class == StatusClass::Terminal,
                    "{:?}/{status} must be Gating or Terminal, got {class:?}",
                    kind
                );
                assert_ne!(
                    class,
                    StatusClass::Workable,
                    "{:?}/{status} must never be Workable",
                    kind
                );
            }
        }
    }

    #[test]
    fn decision_accepted_diverges_hidden_from_status_class() {
        // F-A5 (VT-4): the two notions deliberately disagree on `accepted` — it is
        // LIST-VISIBLE (`is_hidden == false`, a live decision is not settled-away)
        // yet never workable (`status_class == Terminal`, SL-158 settled → Terminal).
        assert!(!knowledge::is_hidden(
            knowledge::RecordKind::Decision,
            "accepted"
        ));
        assert_eq!(
            status_class(&knowledge::DECISION_KIND, Some("accepted")),
            StatusClass::Terminal
        );
    }

    // -- SL-158 VT-8: knowledge-in-priority golden ---------------------------------

    #[test]
    fn knowledge_gating_and_terminal_e2e_golden() {
        // VT-8: create a corpus with one unsettled + one settled knowledge record,
        // build the priority graph, and assert the status class is Gating/Terminal.
        use crate::priority::graph;
        use crate::relation_graph::EntityKey;

        let dir = tempfile::tempdir().unwrap();
        let root = dir.path();
        std::fs::create_dir_all(root.join(".doctrine/doctrine")).unwrap();
        std::fs::write(
            root.join(".doctrine/doctrine.toml"),
            "[doctrine]\nversion = \"0.1.0\"\n",
        )
        .unwrap();

        // Create a minimal slice so the graph has at least one "work" entity.
        let slice_dir = root.join(".doctrine/slice/001");
        std::fs::create_dir_all(&slice_dir).unwrap();
        std::fs::write(
            slice_dir.join("slice-001.toml"),
            "id = 1\nslug = \"s\"\ntitle = \"S\"\nstatus = \"proposed\"\n\
             created = \"2026-01-01\"\nupdated = \"2026-01-01\"\n",
        )
        .unwrap();
        std::fs::write(slice_dir.join("slice-001.md"), "scope\n").unwrap();

        // Seed one unsettled (gating) question: QUE-001, status = "open".
        let que_dir = root.join(".doctrine/knowledge/question/001");
        std::fs::create_dir_all(&que_dir).unwrap();
        std::fs::write(
            que_dir.join("record-001.toml"),
            format!(
                "schema = \"{SCHEMA_KNOWLEDGE}\"\nversion = 1\n\
             id = 1\nslug = \"q1\"\ntitle = \"Q1\"\n\
             record_kind = \"question\"\nstatus = \"open\"\n\
             created = \"2026-01-01\"\nupdated = \"2026-01-01\"\ntags = []\n"
            ),
        )
        .unwrap();
        std::fs::write(que_dir.join("record-001.md"), "open question\n").unwrap();

        // Seed one settled (terminal) question: QUE-002, status = "answered".
        let que2_dir = root.join(".doctrine/knowledge/question/002");
        std::fs::create_dir_all(&que2_dir).unwrap();
        std::fs::write(
            que2_dir.join("record-002.toml"),
            format!(
                "schema = \"{SCHEMA_KNOWLEDGE}\"\nversion = 1\n\
             id = 2\nslug = \"q2\"\ntitle = \"Q2\"\n\
             record_kind = \"question\"\nstatus = \"answered\"\n\
             created = \"2026-01-01\"\nupdated = \"2026-01-01\"\ntags = []\n"
            ),
        )
        .unwrap();
        std::fs::write(que2_dir.join("record-002.md"), "answered question\n").unwrap();

        let g = graph::build(root).unwrap();

        // Look up the knowledge nodes via the projection.
        let que1 = EntityKey {
            prefix: "QUE",
            id: 1,
        };
        let que2 = EntityKey {
            prefix: "QUE",
            id: 2,
        };

        // The graph carries attrs — read status_class through class_of.
        use crate::priority::channels;
        // eligible is status_class == Workable; Gating ≠ Workable, Terminal ≠ Workable.
        assert!(
            !channels::eligible(&g, que1.clone()),
            "QUE-001 (open) is Gating — not eligible"
        );
        assert!(
            !channels::eligible(&g, que2.clone()),
            "QUE-002 (answered) is Terminal — not eligible"
        );

        // Direct status_class check via the partition table (pure, no graph needed).
        assert_eq!(
            status_class(&knowledge::QUESTION_KIND, Some("open")),
            StatusClass::Gating,
            "open question → Gating"
        );
        assert_eq!(
            status_class(&knowledge::QUESTION_KIND, Some("answered")),
            StatusClass::Terminal,
            "answered question → Terminal"
        );
    }

    // -- VT-3: conservative / status-less classification ----------------------

    #[test]
    fn non_knowledge_rows_have_empty_gating() {
        // Every non-knowledge row must have `gating: &[]` — behaviour byte-identical
        // to the pre-SL-158 world where Gating did not exist.
        for p in super::PARTITION.iter() {
            if crate::kinds::is_record(p.prefix) {
                // Knowledge rows have non-empty gating by design.
                continue;
            }
            assert!(
                p.gating.is_empty(),
                "non-knowledge row {} must have gating: &[]",
                p.prefix
            );
        }
    }

    #[test]
    fn rec_status_less_is_terminal_no_diagnostic() {
        // REC is the known status-less kind: None → Terminal, NOT Unrecognised
        // (so it raises no drift diagnostic — DD-4 context-only).
        assert_eq!(
            status_class(&crate::rec::REC_KIND, None),
            StatusClass::Terminal
        );
    }

    #[test]
    fn unrecognised_status_is_its_own_class() {
        // A status outside the kind's vocabulary → Unrecognised (the diagnostic
        // default), distinct from Terminal.
        assert_eq!(
            status_class(&slice::SLICE_KIND, Some("not-a-real-status")),
            StatusClass::Unrecognised
        );
    }

    #[test]
    fn workable_and_terminal_lookups() {
        // A workable slice status.
        assert_eq!(
            status_class(&slice::SLICE_KIND, Some("design")),
            StatusClass::Workable
        );
        // audit / reconcile are WORKABLE (VT-2 boundary — not yet terminal).
        assert_eq!(
            status_class(&slice::SLICE_KIND, Some("audit")),
            StatusClass::Workable
        );
        assert_eq!(
            status_class(&slice::SLICE_KIND, Some("reconcile")),
            StatusClass::Workable
        );
        // A terminal slice status.
        assert_eq!(
            status_class(&slice::SLICE_KIND, Some("done")),
            StatusClass::Terminal
        );
    }

    #[test]
    fn rv_derived_status_resolves_through_the_table() {
        // RV carries a DERIVED active/done — classified like any kind (Charge I).
        assert_eq!(
            status_class(&review::REVIEW_KIND, Some("active")),
            StatusClass::Workable
        );
        assert_eq!(
            status_class(&review::REVIEW_KIND, Some("done")),
            StatusClass::Terminal
        );
    }
}