meta.anchors.test_references

Every #[sage::test(...)] reference must resolve to an existing specification anchor and be attached to a Rust test. Dangling and misplaced references are errors.

One test can cover several rules and a rule can have several tests. Unlike sage::item, a test may reference a rule across crate boundaries. An eligible test entry is a module-level function with the built-in #[test] attribute in a Cargo target with tests and the standard test harness enabled. Targets with test = false or harness = false and unconditionally or conditionally ignored tests cannot satisfy the requirement.

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

Implementation

Implemented crates/sage-meta/src/correspondence.rs:808–813

sage_meta::correspondence · lib:sage_meta

#![allow(unused)]
fn main() {
    // {anchor}`meta.anchors.test_references`
    fn record_tests(&mut self, attrs: &[syn::Attribute], site: &RustSite, context: &Context) {
        for attribute in attrs.iter().filter(|attribute| {
            attribute.path().segments.len() == 2
                && attribute.path().segments[0].ident == "sage"
                && attribute.path().segments[1].ident == "test"

}

See more source ↗

Implemented crates/sage-meta/src/spec.rs:189–194

sage_meta::spec · lib:sage_meta

#![allow(unused)]
fn main() {
    // {anchor}`meta.anchors.test_references`
    pub(crate) fn validate_test_references(
        &self,
        tests: &BTreeMap<String, Vec<RustSite>>,
    ) -> Vec<Diagnostic> {
        let mut diagnostics = Vec::new();

}

See more source ↗

Tests and review

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

Implemented sage_meta::cargo_discovers_unit_and_integration_tests_and_excludes_disabled_harnesses

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

#[test]
#[sage::test(meta.anchors.test_references)]
fn cargo_discovers_unit_and_integration_tests_and_excludes_disabled_harnesses() {
    let fixture =
        std::env::temp_dir().join(format!("sage-correspondence-tests-{}", std::process::id()));
    std::fs::create_dir_all(fixture.join("src")).unwrap();
    std::fs::create_dir_all(fixture.join("tests/support")).unwrap();
    std::fs::write(
        fixture.join("Cargo.toml"),
        r#"[package]
name = "test-fixture"
version = "0.0.0"
edition = "2024"
[workspace]
[[bin]]
name = "disabled"
path = "src/disabled.rs"
test = false
[[test]]
name = "custom"
path = "tests/custom.rs"
harness = false
"#,
    )
    .unwrap();
    std::fs::write(
        fixture.join("src/lib.rs"),
        r#"
        #[cfg(test)] mod unit {
            #[test] #[sage::test(meta.unit)] fn check() {}
        }
    "#,
    )
    .unwrap();
    std::fs::write(
        fixture.join("tests/integration.rs"),
        r#"
        mod support;
        #[test] #[sage::test(meta.integration)] fn check() {}
    "#,
    )
    .unwrap();
    std::fs::write(
        fixture.join("tests/support/mod.rs"),
        r#"
        #[test] #[sage::test(meta.support)] fn check() {}
    "#,
    )
    .unwrap();
    for (file, anchor) in [
        ("src/disabled.rs", "meta.disabled"),
        ("tests/custom.rs", "meta.custom"),
    ] {
        std::fs::write(
            fixture.join(file),
            format!("fn main() {{}} #[test] #[sage::test({anchor})] fn check() {{}}"),
        )
        .unwrap();
    }
    let index = CorrespondenceIndex::load(&fixture).unwrap();
    assert_eq!(index.tests.len(), 3);
    assert_eq!(index.tests["meta.unit"][0].target, "lib:test_fixture");
    assert_eq!(
        index.tests["meta.integration"][0].target,
        "test:integration"
    );
    assert_eq!(index.tests["meta.support"][0].file, "tests/support/mod.rs");
    assert_eq!(index.diagnostics.len(), 2, "{:?}", index.diagnostics);
    assert!(index.diagnostics.iter().all(|diagnostic| {
        diagnostic
            .message
            .contains("test = false or harness = false")
    }));
    std::fs::remove_dir_all(fixture).unwrap();
}

See more source ↗

Implemented sage_meta::ignored_tests_cannot_supply_specification_coverage

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

#![allow(unused)]
fn main() {
#[test]
#[sage::test(meta.anchors.test_references)]
fn ignored_tests_cannot_supply_specification_coverage() {
    for ignore in [
        "#[ignore]",
        "#[ignore = \"too slow\"]",
        "#[cfg_attr(feature = \"slow\", ignore)]",
        "#[cfg_attr(test, cfg_attr(feature = \"slow\", ignore))]",
    ] {
        let index = index(&format!(
            "#[test] {ignore} #[sage::test(meta.rule)] fn check() {{}}"
        ));
        assert!(index.tests.is_empty());
        assert_eq!(
            index.diagnostics.len(),
            1,
            "{ignore}: {:?}",
            index.diagnostics
        );
        assert!(index.diagnostics[0].message.contains("ignored"));
    }
}
}

See more source ↗

Implemented sage_meta::test_annotations_reject_malformed_names_and_unsupported_placements

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

#![allow(unused)]
fn main() {
#[test]
#[sage::test(meta.anchors.test_references)]
fn test_annotations_reject_malformed_names_and_unsupported_placements() {
    for argument in [
        "",
        "meta::calls",
        "meta.calls.",
        "meta..calls",
        "meta.calls, other.rule",
        "\"meta.calls\"",
        "meta.r#type",
        "méta.calls",
        "meta.2calls",
    ] {
        let index = index(&format!(
            "#[test] #[sage::test({argument})] fn check() {{}}"
        ));
        assert!(index.tests.is_empty(), "{argument}");
        assert_eq!(
            index.diagnostics.len(),
            1,
            "{argument}: {:?}",
            index.diagnostics
        );
        assert!(
            index.diagnostics[0]
                .message
                .contains("dot-separated anchor name")
        );
    }
    for source in [
        "#[sage::test(meta.rule)] fn helper() {}",
        "#[sage::test(meta.rule)] struct Type;",
        "#[sage::test(meta.rule)] mod module {}",
        "impl Type { #[test] #[sage::test(meta.rule)] fn method() {} }",
        "fn outer() { #[test] #[sage::test(meta.rule)] fn nested() {} }",
        "fn outer() { mod inner { #[test] #[sage::test(meta.rule)] fn nested() {} } }",
        "#[tokio::test] #[sage::test(meta.rule)] async fn unsupported_adapter() {}",
    ] {
        let index = index(source);
        assert!(index.tests.is_empty(), "{source}");
        assert_eq!(
            index.diagnostics.len(),
            1,
            "{source}: {:?}",
            index.diagnostics
        );
        assert!(
            index.diagnostics[0]
                .message
                .contains("module-level #[test]")
        );
    }
}
}

See more source ↗

Implemented sage_meta::tests_from_different_crates_can_reference_the_same_specification_rule

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

#![allow(unused)]
fn main() {
#[test]
#[sage::test(meta.anchors.test_references)]
fn tests_from_different_crates_can_reference_the_same_specification_rule() {
    let spec = sage_meta::spec::SpecIndex::from_sources(&[sage_meta::spec::SpecSource {
        file: "design/crates/library/api.md".into(),
        source: "{anchor}`crates.library.api.rule` A library guarantee.".into(),
    }]);
    let sources = ["library", "application"].map(|crate_name| RustSource {
        crate_name: crate_name.into(),
        target: format!("test:{crate_name}"),
        file: format!("crates/{crate_name}/tests/api.rs"),
        source: "#[test] #[sage::test(crates.library.api.rule)] fn verifies_api() {}".into(),
    });
    let rust = CorrespondenceIndex::from_sources(&sources).unwrap();
    assert!(spec.diagnostics.is_empty());
    assert!(rust.diagnostics.is_empty(), "{:?}", rust.diagnostics);
    let sites = &rust.tests["crates.library.api.rule"];
    assert_eq!(sites.len(), 2);
    assert_eq!(sites[0].crate_name, "library");
    assert_eq!(sites[1].crate_name, "application");
    assert!(spec.validate(&rust.tests).is_empty());
}
}

See more source ↗

Implemented sage_meta::test_coverage_is_bidirectional_and_allows_many_to_many_links

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

#![allow(unused)]
fn main() {
#[test]
#[sage::test(meta.anchors.test_coverage)]
#[sage::test(meta.anchors.test_references)]
fn test_coverage_is_bidirectional_and_allows_many_to_many_links() {
    let index = SpecIndex::from_sources(&[source(
        "rules.md",
        "{anchor}`meta.first` First requirement.\n\n{anchor}`meta.second` Second requirement.",
    )]);
    let mut tests = BTreeMap::from([
        ("meta.first".into(), vec![test_site(), test_site()]),
        ("meta.second".into(), vec![test_site()]),
    ]);
    assert!(index.validate(&tests).is_empty());
    tests.get_mut("meta.second").unwrap().clear();
    tests.insert("meta.typo".into(), vec![test_site()]);
    let diagnostics = index.validate(&tests);
    assert_eq!(diagnostics.len(), 2);
    assert_eq!(diagnostics[0].file, "rules.md");
    assert!(diagnostics[0].message.contains("meta.second"));
    assert!(diagnostics[0].message.contains("no associated Rust test"));
    assert_eq!(diagnostics[1].file, "tests/rules.rs");
    assert_eq!(diagnostics[1].span, test_site().annotation_span);
    assert!(
        diagnostics[1]
            .message
            .contains("unknown specification anchor `meta.typo`")
    );
}
}

See more source ↗

Review: Accepted · /root/final_quality.

Fresh reassessment of meta.anchors.test_references: current complete claim, both implementation entries and five ordinary tests. Whole-file inputs include registration, target loading, name parsing and ignored-test helpers; test source/index helpers were additionally captured. No TODO/N/A entries. No source edits, build or tests run. Latest association-only changes do not alter the inspected reference validation; full claim accounting follows rather than reusing a verdict.

Reference validity: correspondence::record_tests recognizes sage::test attributes, parses exactly one dot-separated ASCII anchor name, requires a module-level Function with built-in #[test], rejects functions nested inside another function, requires target.test and standard harness eligibility, and rejects unconditional or recursively cfg_attr-wrapped ignore. Each accepted attribute appends its own site to that rule's vector, so repeated attributes can associate one test with multiple rules and multiple sites can associate with one rule. It applies no crate-ownership restriction. spec::validate_test_references then checks every rule key against the specification inventory and reports each dangling site's annotation span, independently of missing-rule test coverage. Thus correspondence syntax/placement errors and unresolved specification references remain distinct errors.

Target/context helpers: Cargo target loading combines metadata's test flag with parsed manifest harness settings and carries that context into module traversal, including integration support modules. The record path retains target/crate/file identity. AnchorName consumes the full attribute argument stream and validates each component; potentially_ignored recursively checks cfg_attr branches rather than assuming a condition is disabled. These helpers are in the captured correspondence file and were re-inspected.

All five tests: cargo_discovers_unit_and_integration_tests_and_excludes_disabled_harnesses creates a real package with unit, integration and support-module tests plus test=false and harness=false targets. It requires exactly three indexed rules with correct targets/files and exactly two target-eligibility diagnostics. ignored_tests_cannot_supply_specification_coverage checks plain, reasoned, conditional and nested conditional ignore forms, requiring no indexed tests and an ignored diagnostic. test_annotations_reject_malformed_names_and_unsupported_placements checks empty/path/comma/string/raw/non-ASCII/numeric malformed arguments and helper/struct/module/method/nested-function/nested-module/alternate-adapter placements; each requires no entry and the specific validation diagnostic. tests_from_different_crates_can_reference_the_same_specification_rule asserts two distinct crate sites for one library rule and successful validation. test_coverage_is_bidirectional_and_allows_many_to_many_links supplies several sites for a rule and the same test identity across rules, validates them, then creates missing coverage and a dangling typo and checks both diagnostics including the typo annotation span. The many-to-many synthetic test validates inventory semantics; the source registration loop visibly supplies the corresponding multi-attribute construction mechanism. Together these cover every qualification of eligibility, multiplicity, cross-crate use and dangling/misplaced rejection. No concrete new defect or requested edit found.

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