meta.book.crate_ownership

Every .sage chapter lies beneath a directory identifying its Rust crate. The crate’s crate.sage manifest establishes the modeled crate boundary; the book loader checks that ownership against the Rust workspace. Book chapter namespaces and compiler-model item identities are distinct: moving a crate’s book directory preserves identities such as $sage_ir::symbols::Symbol when the modeled crate and declaration paths are unchanged.

Read in specification context · design/meta/book.md

Implementation

Implemented crates/sage-meta/src/correspondence.rs:362–367

sage_meta::correspondence · lib:sage_meta

#![allow(unused)]
fn main() {
    // {anchor}`meta.book.crate_ownership`
    pub fn validate(&self, documents: &[Document]) -> Vec<Diagnostic> {
        #[derive(Clone, Copy)]
        enum Unit {
            Namespace,
            Type,

}

See more source ↗

Implemented crates/sage-meta/src/spec.rs:733–738

sage_meta::spec · lib:sage_meta

#![allow(unused)]
fn main() {
                // {anchor}`meta.book.crate_ownership`
                if model_namespace.is_none() {
                    return Err(format!("Sage chapter `{file}` has no modeled crate owner").into());
                }
                for block in document.prose {
                    let (text, offsets) = dedent(&block.text);

}

See more source ↗

Implemented crates/sage-meta/src/workspace.rs:30–35

sage_meta::workspace · lib:sage_meta

#![allow(unused)]
fn main() {
// {anchor}`meta.book.crate_ownership`
pub fn crate_source_owner<'a>(documents: &'a [Document], source: &Path) -> Option<&'a str> {
    documents
        .iter()
        .filter_map(|document| match &document.header {
            crate::Header::Crate { name, .. } => Some((

}

See more source ↗

Implemented crates/sage-meta/src/validate.rs:124–129

sage_meta::validate · lib:sage_meta

#![allow(unused)]
fn main() {
// {anchor}`meta.book.crate_ownership`
fn build_model(documents: &[Document]) -> Model<'_> {
    let mut model = Model {
        classes: BTreeMap::new(),
        types: BTreeMap::new(),
        values: Vec::new(),

}

See more source ↗

Implemented crates/sage-meta/src/book.rs:107–112

sage_meta::book · bin:sage-meta

#![allow(unused)]
fn main() {
// {anchor}`meta.book.crate_ownership`
fn generate_crates(
    context: &Value,
    sections: &mut [Value],
    spec: &sage_meta::spec::SpecIndex,
) -> Result<(), Box<dyn std::error::Error>> {

}

See more source ↗

Tests and review

Indexed tests and the implementation-completeness and test-adequacy review; no test run is implied.

Implemented sage_meta::invalid_models_and_correspondence_fail_before_publishing_an_explorer

crates/sage-meta/tests/book.rs · test:book

#![allow(unused)]
fn main() {
#[test]
#[sage::test(meta.book.browser_delivery)]
#[sage::test(meta.book.crate_ownership)]
fn invalid_models_and_correspondence_fail_before_publishing_an_explorer() {
    for (path, replacement, expected) in [
        (
            "manual/design/crates/demo/symbols.sage",
            "module crate::symbols; struct Item { value: Missing }",
            "unknown type Missing",
        ),
        (
            "src/lib.rs",
            "#[sage::item(crate)] mod architecture {}",
            "has no Rust",
        ),
        (
            "src/lib.rs",
            "#[sage::item(support::Value)] pub struct WrongCrate;",
            "different crate",
        ),
    ] {
        let fixture = Fixture::new("manual");
        fixture.write(path, replacement);
        let output = fixture.run(&fixture.input("items"));
        assert!(!output.status.success());
        let error = String::from_utf8_lossy(&output.stderr);
        assert!(error.contains(expected), "{error}");
        assert!(output.stdout.is_empty());
        assert!(!fixture.asset().exists());
    }
}
}

See more source ↗

Implemented sage_meta::orphan_sage_module_and_nonexistent_rust_crate_are_rejected

crates/sage-meta/tests/book.rs · test:book

#![allow(unused)]
fn main() {
#[test]
#[sage::test(meta.book.crate_ownership)]
fn orphan_sage_module_and_nonexistent_rust_crate_are_rejected() {
    for (path, source, expected) in [
        (
            "orphan.sage",
            "module crate::orphan;",
            "no modeled crate owner",
        ),
        (
            "missing/crate.sage",
            "crate missing { \"\"\"No Rust workspace crate owns this model.\"\"\" }",
            "missing",
        ),
    ] {
        let fixture = Fixture::new("manual");
        fixture.model(path, source);
        let output = fixture.run(&fixture.input("items"));
        assert!(!output.status.success());
        let error = String::from_utf8_lossy(&output.stderr);
        assert!(error.contains(expected), "{error}");
        assert!(output.stdout.is_empty());
        assert!(!fixture.asset().exists());
    }
}
}

See more source ↗

Implemented sage_meta::relocating_crate_sources_preserves_model_identity_and_updates_book_routes

crates/sage-meta/tests/book.rs · test:book

#![allow(unused)]
fn main() {
#[test]
#[sage::test(meta.book.crate_ownership)]
fn relocating_crate_sources_preserves_model_identity_and_updates_book_routes() {
    let fixture = Fixture::new("manual");
    fixture.book("items");
    let before = std::fs::read_to_string(fixture.asset()).unwrap();
    let before_model = script_data(&before, "model-data");
    let crates = fixture.source.join("design/crates");
    std::fs::create_dir(crates.join("compiler")).unwrap();
    std::fs::rename(crates.join("demo"), crates.join("compiler/frontend")).unwrap();

    let book = fixture.book("items");
    let entries = chapters(book["items"].as_array().unwrap());
    assert!(entries.contains_key("design/crates/compiler/frontend/crate.sage"));
    assert!(entries.contains_key("design/crates/compiler/frontend/symbols.sage"));
    assert!(!entries.contains_key("design/crates/demo/crate.sage"));
    let after = std::fs::read_to_string(fixture.asset()).unwrap();
    let after_model = script_data(&after, "model-data");
    let namespaces = |model: &Value| {
        model
            .as_array()
            .unwrap()
            .iter()
            .map(|document| document["namespace"].as_str().unwrap().to_owned())
            .collect::<std::collections::BTreeSet<_>>()
    };
    assert_eq!(namespaces(&before_model), namespaces(&after_model));
    assert_eq!(
        namespaces(&after_model),
        ["demo", "demo::symbols", "support"]
            .map(String::from)
            .into_iter()
            .collect()
    );
    let entities = |model: &Value| {
        model
            .as_array()
            .unwrap()
            .iter()
            .flat_map(|document| {
                let namespace = document["namespace"].as_str().unwrap();
                document["document"]["declarations"]
                    .as_array()
                    .unwrap()
                    .iter()
                    .map(move |declaration| {
                        let name = declaration["Type"]["name"].as_str().unwrap();
                        format!("{namespace}::{name}")
                    })
            })
            .collect::<std::collections::BTreeSet<_>>()
    };
    assert_eq!(entities(&before_model), entities(&after_model));
    assert_eq!(
        entities(&after_model),
        ["demo::symbols::Item", "support::Value"]
            .map(String::from)
            .into_iter()
            .collect()
    );
    let before_source = script_data(&before, "source-data");
    let after_source = script_data(&after, "source-data");
    assert_eq!(
        before_source["targets"]["demo::symbols::Item"],
        after_source["targets"]["demo::symbols::Item"]
    );
    assert_eq!(
        after_source["targets"]["demo::symbols::Item"][0]["path"],
        "demo::symbols::ActualItem"
    );
    let navigation = script_data(&after, "book-data");
    assert_eq!(navigation["home"], "design/crates/index.html");
    assert_eq!(
        navigation["chapters"]["demo::symbols"],
        "design/crates/compiler/frontend/symbols.html"
    );
    let module_chapter = entries["design/crates/compiler/frontend/symbols.sage"];
    assert_eq!(
        Path::new(module_chapter["path"].as_str().unwrap()).with_extension("html"),
        Path::new("design/crates/compiler/frontend/symbols.html")
    );
    let module = module_chapter["content"].as_str().unwrap();
    assert!(module.contains("../../../../sage-explorer.html"));
}
}

See more source ↗

Review: Accepted · Codex /root/anchor_094.

Fresh final followup review of crate_ownership. Saved/read the previous complete report and captures, started fresh, recaptured all three helper dependencies, and compared every fragment. Claim, all three tests, four of five implementation files and all helpers are unchanged. The only spec.rs delta is an implementation_references association comment on an unrelated validator. Ownership, identity and publication behavior are unchanged.

The complete claim requires each Sage chapter to have a manifest-established modeled Rust crate boundary, ownership checked against the Rust workspace, and preserved compiler-model identities when only book directory placement changes. All five ordinary implementation entries remain relevant. workspace::crate_source_owner selects the deepest enclosing manifest directory; document_namespace uses the modeled crate name/module header instead of directory spelling. validate::build_model enforces crate.sage manifests, unique crates, nearest-owner/module-path consistency and modeled declaration identities. spec::load_workspace rejects Sage chapters without model ownership, while keeping path-derived chapter namespace separate from model identity. book::generate_crates validates model and Cargo correspondence before publishing the explorer. correspondence::validate requires Rust mappings and rejects wrong-crate ownership; Cargo metadata supplies actual crate/target owners. Browser serialization obtains the same modeled namespaces, while navigation routes use current source paths. The added comment changes none of these checks.

All three ordinary tests were reassessed. orphan_sage_module_and_nonexistent_rust_crate_are_rejected separately adds an orphan module and an unmapped missing crate manifest, requiring failure, relevant diagnostics, no output and no published asset. The missing-crate substring is broad but its fixture isolates that new unmapped manifest. invalid_models_and_correspondence_fail_before_publishing_an_explorer covers unknown modeled type, missing mappings and an explicitly wrong-crate mapping; it requires the expected error and no publication in each case. relocating_crate_sources_preserves_model_identity_and_updates_book_routes generates a baseline, moves demo to compiler/frontend without changing modeled paths, regenerates and asserts new chapter paths/absence of old paths, unchanged exact model namespace and declaration-ID sets, unchanged Rust mapping with concrete ActualItem identity, updated navigation/output route and increased relative explorer path. The cross-crate support reference remains validated after relocation. These are substantive before/after assertions distinguishing book placement from Rust identity.

Captured fixture helpers write real two-package Cargo/model/book sources, invoke the real preprocessor, parse JSON/snapshot data and recursively reject duplicate chapter paths. All claim requirements have current ordinary code and meaningful positive/negative/relocation evidence; there are no TODO/N/A entries or deferrals. The actual marker-only delta was checked against the full prior assessment and no other relied-on content changed. No source edits, build or behavioral tests occurred in this review; fresh start/read/record and source inspection only. No requested edits.

Browse meta anchors

116 anchors

Specification anchors and declared coverage
AnchorImplementationTests
meta (116)102 Implemented24 TODO103 Implemented36 TODO
meta.anchors (22)22 Implemented21 Implemented12 TODO
anchor_pagesImplementedImplementedTODO
book_explorerImplementedImplementedTODO
canonical_sourcesImplementedImplementedTODO
meta.anchors.content (7)7 Implemented7 Implemented
blocksImplementedImplemented
explicit_endImplementedImplemented
headingImplementedImplemented
literal_syntaxImplementedImplemented
next_anchorImplementedImplemented
source_endImplementedImplemented
unmatched_endImplementedImplemented
context_navigationImplementedImplementedTODO
evidence_statusImplementedImplementedTODO
explorer_navigationImplementedTODO
implementation_coverageImplementedImplementedTODO
implementation_referencesImplementedImplementedTODO
placeholder_statusImplementedImplementedTODO
point_excerptsImplementedImplementedTODO
region_balanceImplementedImplemented
region_excerptsImplementedImplementedTODO
test_coverageImplementedImplemented
test_referencesImplementedImplemented
unique_namesImplementedImplementedTODO
meta.book (21)10 Implemented18 TODO12 Implemented18 TODO
anchor_movesImplementedTODOImplementedTODO
authorityImplementedTODOImplementedTODO
browser_deliveryTODOImplementedTODO
browser_dependenciesTODOTODO
browser_rust_sourceTODOTODO
browser_searchTODOTODO
browser_serveTODOTODO
browser_structureTODOTODO
chapter_namesImplementedTODOImplementedTODO
crate_ownershipImplementedImplemented
crates_landingImplementedImplemented
entity_linksTODOTODO
index_groupsImplementedTODOImplementedTODO
index_namespace_pagesImplementedImplemented
index_rowsImplementedTODOImplementedTODO
index_statusImplementedTODOImplementedTODO
rfd_changesTODOTODO
sage_chaptersTODOImplementedTODO
self_descriptionTODOTODO
shared_modelImplementedTODOImplementedTODO
source_rolesTODOTODO
meta.contracts (4)4 Implemented3 TODO4 Implemented3 TODO
cache_invocationsImplementedTODOImplementedTODO
correspondenceImplementedImplemented
observation_coverageImplementedTODOImplementedTODO
validated_sessionImplementedTODOImplementedTODO
meta.language (39)39 Implemented39 Implemented
meta.language.calls (2)2 Implemented2 Implemented
declaredImplementedImplemented
forbiddenImplementedImplemented
meta.language.classes (3)3 Implemented3 Implemented
abstract_completeImplementedImplemented
override_signatureImplementedImplemented
single_inheritanceImplementedImplemented
meta.language.contexts (1)1 Implemented1 Implemented
inheritanceImplementedImplemented
meta.language.envelopes (7)7 Implemented7 Implemented
class_callsImplementedImplemented
createsImplementedImplemented
direct_callsImplementedImplemented
leafImplementedImplemented
permissionsImplementedImplemented
readsImplementedImplemented
receiver_callsImplementedImplemented
meta.language.fields (2)2 Implemented2 Implemented
context_stateImplementedImplemented
kindsImplementedImplemented
meta.language.methods (2)2 Implemented2 Implemented
kindsImplementedImplemented
proseImplementedImplemented
meta.language.model (3)3 Implemented3 Implemented
forbidden_pathsImplementedImplemented
inherited_prohibitionsImplementedImplemented
virtual_dispatchImplementedImplemented
meta.language.types (19)19 Implemented19 Implemented
argument_arityImplementedImplemented
declaration_proseImplementedImplemented
enum_variantsImplementedImplemented
field_proseImplementedImplemented
generic_parametersImplementedImplemented
member_commasImplementedImplemented
name_resolutionImplementedImplemented
opaque_representationImplementedImplemented
preludeImplementedImplemented
qualified_namesImplementedImplemented
recursive_valuesImplementedImplemented
struct_fieldsImplementedImplemented
tuplesImplementedImplemented
type_expressionsImplementedImplemented
unique_fieldsImplementedImplemented
unique_parametersImplementedImplemented
unique_variantsImplementedImplemented
unknown_namesImplementedImplemented
variant_proseImplementedImplemented
meta.reviews (27)27 Implemented27 Implemented
claim_textImplementedImplemented
complete_test_setImplementedImplemented
decisionsImplementedImplemented
fragment_associationsImplementedImplemented
fragment_formatImplementedImplemented
fragment_freshnessImplementedImplemented
gateImplementedImplemented
input_formatImplementedImplemented
input_fragmentsImplementedImplemented
output_formatImplementedImplemented
preparationImplementedImplemented
record_requiredImplementedImplemented
recorded_readsImplementedImplemented
recordingImplementedImplemented
review_delegationImplementedImplemented
review_diagnosticsImplementedImplemented
review_instructionsImplementedImplemented
review_scopeImplementedImplemented
selector_claimImplementedImplemented
selector_line_rangeImplementedImplemented
selector_testImplementedImplemented
selector_whole_fileImplementedImplemented
source_representationImplementedImplemented
stalenessImplementedImplemented
summary_formatImplementedImplemented
test_sourceImplementedImplemented
validation_layoutImplementedImplemented
meta.validation (3)3 TODO3 TODO
claim_specific_evidenceTODOTODO
independent_inspectionTODOTODO
review_packetsTODOTODO