crates.sage_test_harness.compile_tests.query_capture

An optional query expectation observes a cold run in a fresh Sage database. Project/provider setup finishes before capture begins, without pre-demanding the fixture’s local semantic products. Capture covers local crate discovery, signature and body demands under the checking policy, and semantic reads needed to collect requested observations. It ends before rendering or comparing frozen outputs. Observation-related work is retained rather than hidden, while the set of checked bodies remains selector-independent. Warm runs, edits, and explicit point demands are later extensions.

Read in specification context · design/crates/sage_test_harness/compile-tests.md

Implementation

Implemented crates/sage-ir/src/db.rs:2–7

sage_ir::db · lib:sage_ir

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_test_harness.compile_tests.query_capture`
use std::collections::HashMap;

use crate::source::SourceFile;
use crate::tcx::{NoopTcxDb, TcxDb};
use salsa::Setter as _;

}

See more source ↗

Implemented crates/sage-test-harness/src/compile/observe.rs:117–122

sage_test_harness::compile::observe · lib:sage_test_harness

#![allow(unused)]
fn main() {
    // {anchor}`crates.sage_test_harness.compile_tests.query_capture`
    // {anchor}`crates.sage_test_harness.compile_tests.query_projection`
    let queries = if queries {
        let trace = sage_host::trace::snapshot_trace(events);
        serde_json::to_string_pretty(&trace).map_err(|e| e.to_string())? + "\n"
    } else {

}

See more source ↗

Implemented crates/sage-test-harness/src/compile/symbols.rs:4–9

sage_test_harness::compile::symbols · lib:sage_test_harness

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_test_harness.compile_tests.query_capture`
use sage_ir::{
    Db,
    scope::ScopeSymbol,
    symbol::*,
    tytree::{LocalVar, PathResolution},

}

See more source ↗

Implemented crates/sage-test-harness/src/compile/types.rs:6–11

sage_test_harness::compile::types · lib:sage_test_harness

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_test_harness.compile_tests.query_capture`
use sage_ir::{
    Db,
    cst::Mutability,
    symbol::{Symbol, TypeAliasSymbol},
    ty::{AliasTy, Const, Ty},

}

See more source ↗

Implemented crates/sage-test-harness/src/compile/mod.rs:102–107

sage_test_harness::compile · lib:sage_test_harness

#![allow(unused)]
fn main() {
    // {anchor}`crates.sage_test_harness.compile_tests.query_capture`
    // {anchor}`crates.sage_test_harness.compile_tests.coordinates`
    fn prepare(&self) -> Result<Output, String> {
        let files = validate_files(self.files.as_deref().ok_or("missing source or files")?)?;
        let edition = self.edition.as_deref().unwrap_or("2024");
        // {anchor}`crates.sage_test_harness.compile_tests.edition`

}

See more source ↗

Implemented crates/sage-host/src/driver.rs:12–17

sage_host::driver · lib:sage_host

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_test_harness.compile_tests.query_capture`
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::mpsc;

use rustc_driver::{Callbacks, Compilation};

}

See more source ↗

Tests and review

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

Implemented sage_test_harness::compile::query_capture_review_tests::cold_capture_includes_discovery_and_observation_reads_without_changing_bodies

crates/sage-test-harness/src/compile/mod.rs · lib:sage_test_harness

#![allow(unused)]
fn main() {
#[test]
    #[sage::test(crates.sage_test_harness.compile_tests.query_capture)]
    #[sage::test(crates.sage_test_harness.compile_tests.resolved_symbols)]
    fn cold_capture_includes_discovery_and_observation_reads_without_changing_bodies() {
        let source = "fn selected() -> std::cmp::Ordering {\n std::cmp::Ordering::Equal // SELECT\n}\nfn unselected() -> u16 { 33 }";
        let mut plain = CompileTest::default();
        plain.source(source);
        plain.queries(expect_test::expect![""]);
        let plain = plain.prepare().unwrap();
        let mut selected = CompileTest::default();
        selected.source(source.replace("// SELECT", "//# sym"));
        selected.observations(expect_test::expect![""]);
        selected.queries(expect_test::expect![""]);
        let selected = selected.prepare().unwrap();
        assert!(
            selected
                .observations
                .contains("symbol: variant std::cmp::Ordering::Equal"),
            "{}",
            selected.observations
        );
        // Selecting an observation must not alter the checked body set or hide
        // semantic reads performed while freezing external definition names.
        assert_eq!(plain.queries, selected.queries);
        let trace: serde_json::Value = serde_json::from_str(&selected.queries).unwrap();
        fn collect<'a>(nodes: &'a serde_json::Value, out: &mut Vec<&'a serde_json::Value>) {
            for node in nodes.as_array().unwrap() {
                out.push(node);
                collect(&node["children"], out);
            }
        }
        let mut nodes = Vec::new();
        collect(&trace, &mut nodes);
        for operation in ["setup_root_module", "::sig_", "::body_", "tcx::def_path"] {
            assert!(
                nodes.iter().any(
                    |node| node["operation"].as_str().unwrap().ends_with(operation)
                        && node["disposition"] == "executed"
                ),
                "missing cold {operation}: {}",
                selected.queries
            );
        }
        assert_eq!(
            nodes
                .iter()
                .filter(
                    |node| node["operation"].as_str().unwrap().ends_with("::body_")
                        && node["disposition"] == "executed"
                )
                .count(),
            2
        );
    }
}

Conditional source: #[cfg(test)]

See more source ↗

Implemented sage_test_harness::compile::tests::cold_queries_are_stable_across_isolated_projects

crates/sage-test-harness/src/compile/mod.rs · lib:sage_test_harness

#![allow(unused)]
fn main() {
#[test]
    #[sage::test(crates.sage_test_harness.compile_tests.query_capture)]
    #[sage::test(crates.sage_test_harness.compile_tests.query_projection)]
    #[sage::test(crates.sage_test_harness.compile_tests.project_isolation)]
    #[sage::test(crates.sage_test_harness.compile_tests.rendering)]
    fn cold_queries_are_stable_across_isolated_projects() {
        let mut first = CompileTest::default();
        first.source("fn f() -> u16 { 22 }");
        first.queries(expect![""]);
        let first = first.prepare().unwrap();
        let mut second = CompileTest::default();
        second.source("fn f() -> u16 { 22 }");
        second.queries(expect![""]);
        let second = second.prepare().unwrap();
        assert_eq!(first.queries, second.queries);
        assert!(first.queries.contains("executed"), "{}", first.queries);
        assert!(first.queries.contains("body"), "{}", first.queries);
        assert!(!first.queries.contains("/tmp/"));
        assert!(!first.queries.contains("Id("));
    }
}

Conditional source: #[cfg(test)]

See more source ↗

Review: Accepted · anchor_016.

Fresh source review of crates.sage_test_harness.compile_tests.query_capture against current captured claim, six ordinary implementation entries, and the complete two-test set. No TODO or N/A entries are present. This refresh executes only review start/read/record and source inspection; relevant test execution is centralized by root, so this report does not claim a new test run.

Cold/fresh setup: CompileTest::prepare materializes each project, performs independent rustc checking, opens a new SageHost, and drains setup events before entering with_context. Host open waits for metadata-provider readiness, constructs new Database storage/logs via with_proxy_and_cfgs, and registers configuration and source inputs. It does not demand the fixture root semantic products; setup_root_module is first called by with_context after the drain. The database association supplies actual request events/dispositions and mem::take drain semantics. Thus capture starts after project/provider setup but before local discovery.

Covered work: with_context performs tracked root discovery; collect calls check_crate and reads accumulated signature diagnostics before draining events. check_crate recursively visits the selected local modules and supported symbols, requests function signatures and bodies regardless of marker presence, and freezes body observations. Selector processing occurs only after this checking. The symbols implementation resolves local identities and external def_path names during walk_expr; FrozenType::read resolves recursive type names into owned values before the drain. Neither name-reading path is hidden from the log. Type and symbol observations share this pre-drain collection, and the returned TypeRows contain frozen values rather than deferred semantic lookups.

End boundary and optional behavior: collect takes the inspection log before matching/rendering frozen diagnostics and observations. FrozenType formatting receives no database, symbol fields are owned strings, and the captured trace projection consumes owned events with no database access. run compares expectations only after prepare returns. This control-flow/data-ownership inspection establishes the rendering/comparison boundary in addition to the real trace tests; no boundary-injection test is claimed. Queries are emitted only when an optional query expectation is present; omission returns an empty query output. Warm/edit/point-demand behavior is explicitly outside this v1 claim.

Complete tests: cold_queries_are_stable_across_isolated_projects separately prepares identical fixtures, checks equal nonempty executed body traces and absence of temporary paths and IDs. cold_capture_includes_discovery_and_observation_reads_without_changing_bodies prepares a fixture with an external Ordering variant and an unselected private function twice, with and without a symbol selector. It asserts the correct external variant identity, equality of the actual traces, executed setup_root_module, signature, body and tcx::def_path operations, and exactly two executed bodies. These are visible assertions over real production results, not wrapper-only or annotation-only evidence. They would catch omitted cold discovery/signatures, lost name-reading work, or selector-limited body checking for the exercised scenario. Inspection of the marker-independent recursive checker supports the general policy beyond this fixture.

All six implementation associations are accounted for: driver establishes setup/demand boundary; db supplies fresh capture state and event drain; compile prepares and later compares; observe checks/freezes/drains/renders in that order; symbols and types freeze semantic names before capture ends. The additional trace dependency is captured through review read and inspected for owned-event-only projection. Current evidence adequately supports the complete claim. No source edits or outstanding concerns arose in this refresh.

Browse crates anchors

139 anchors

Specification anchors and declared coverage
AnchorImplementationTests
crates (139)114 Implemented37 TODO2 N/A74 Implemented107 TODO
crates.sage_inspector (15)13 Implemented1 TODO2 N/A3 Implemented15 TODO
crates.sage_inspector.inspection (15)13 Implemented1 TODO2 N/A3 Implemented15 TODO
balanced_tracesImplementedTODO
canonical_ownershipImplementedImplementedTODO
derive_reflectionImplementedImplementedTODO
detail_free_indexImplementedTODO
deterministic_traceImplementedTODO
durable_navigationN/ATODO
generic_browserN/ATODO
owned_reflectionImplementedImplementedTODO
product_availabilityImplementedTODO
revision_and_demandImplementedTODO
semantic_phase_boundaryImplementedTODO
source_evidenceImplementedTODO
typed_serviceImplementedTODO
unknown_workImplementedTODOTODO
workspace_actorImplementedTODO
crates.sage_ir (90)67 Implemented34 TODO40 Implemented88 TODO
crates.sage_ir.checking (12)12 Implemented3 TODO5 Implemented12 TODO
crates.sage_ir.checking.body (5)5 Implemented2 TODO3 Implemented5 TODO
elaborationImplementedImplementedTODO
expected_typesImplementedTODOTODO
interface_dependenciesImplementedImplementedTODO
isolated_completionImplementedImplementedTODO
operator_callsImplementedTODOTODO
identity_mintingImplementedTODO
owned_productsImplementedImplementedTODO
crates.sage_ir.checking.signature (4)4 Implemented1 TODO1 Implemented4 TODO
body_independenceImplementedTODO
narrow_detailImplementedTODOTODO
owner_binderImplementedImplementedTODO
storageImplementedTODO
symbol_keyed_interfacesImplementedTODO
crates.sage_ir.crate (9)9 TODO9 TODO
explicit_restrictionsTODOTODO
identity_before_detailTODOTODO
incremental_evidenceTODOTODO
narrow_demandsTODOTODO
reexecution_and_invalidationTODOTODO
represented_completenessTODOTODO
restrictions_and_gapsTODOTODO
semantic_query_boundariesTODOTODO
terminal_incompletenessTODOTODO
crates.sage_ir.inference (8)8 Implemented6 Implemented8 TODO
atomic_checkingImplementedImplementedTODO
body_local_quiescenceImplementedImplementedTODO
canonical_boundaryImplementedImplementedTODO
completed_body_boundaryImplementedTODO
numeric_domainsImplementedImplementedTODO
subtyping_and_coercionImplementedImplementedTODO
terminal_obligationsImplementedTODO
transaction_isolationImplementedImplementedTODO
crates.sage_ir.metadata (4)4 Implemented1 TODO4 TODO
explicit_incompletenessImplementedTODO
keyed_reuseImplementedTODOTODO
product_boundariesImplementedTODO
provider_authorityImplementedTODO
crates.sage_ir.modules (8)7 Implemented1 TODO4 Implemented8 TODO
crates.sage_ir.modules.expand (4)4 Implemented2 Implemented4 TODO
completenessImplementedImplementedTODO
dependenciesImplementedTODO
direct_membersImplementedTODO
recursion_and_fixpointImplementedImplementedTODO
crates.sage_ir.modules.parse (4)3 Implemented1 TODO2 Implemented4 TODO
dependenciesImplementedTODO
detail_firewallImplementedImplementedTODO
recovery_completenessTODOTODO
syntax_identitiesImplementedImplementedTODO
crates.sage_ir.resolution (5)5 Implemented1 TODO3 Implemented4 TODO
crates.sage_ir.resolution.lookup (5)5 Implemented1 TODO3 Implemented4 TODO
completenessImplementedTODOImplementedTODO
dependenciesImplementedTODO
expansion_import_ambiguityImplementedImplemented
identity_onlyImplementedTODO
precedenceImplementedImplementedTODO
crates.sage_ir.solver (9)7 Implemented7 TODO5 Implemented9 TODO
alternative_isolationImplementedTODOImplementedTODO
bounded_completenessImplementedTODOTODO
candidate_completenessImplementedTODO
canonical_cyclesTODOTODO
canonical_outputsImplementedImplementedTODO
local_index_firewallTODOTODO
normalization_demandImplementedTODOImplementedTODO
schedule_independenceImplementedTODOImplementedTODO
shared_final_resultImplementedTODOImplementedTODO
crates.sage_ir.symbols (8)8 Implemented4 Implemented7 TODO
associated_identityImplementedImplemented
associated_interfacesImplementedTODO
body_interfacesImplementedImplementedTODO
definition_identityImplementedTODO
external_fact_queriesImplementedTODO
external_identityImplementedTODO
kind_wrappersImplementedImplementedTODO
local_identityImplementedImplementedTODO
crates.sage_ir.types (27)16 Implemented12 TODO13 Implemented27 TODO
crates.sage_ir.types.aliases (2)1 Implemented1 TODO1 Implemented2 TODO
identityImplementedImplementedTODO
revelationTODOTODO
crates.sage_ir.types.binder (1)1 Implemented1 TODO1 Implemented1 TODO
owner_parametersImplementedTODOImplementedTODO
crates.sage_ir.types.body (13)4 Implemented9 TODO3 Implemented13 TODO
awaitTODOTODO
closuresTODOTODO
conditional_patternsTODOTODO
coroutinesTODOTODO
diagnosed_recoveryImplementedImplementedTODO
elaboratedTODOImplementedTODO
for_iterationTODOTODO
indexingTODOTODO
macro_expansionTODOTODO
no_inferenceImplementedImplementedTODO
resolved_referencesImplementedTODO
try_residualTODOTODO
typed_provenanceImplementedTODO
crates.sage_ir.types.calls (2)1 Implemented1 TODO1 Implemented2 TODO
dispatch_familiesTODOTODO
selected_semanticsImplementedImplementedTODO
crates.sage_ir.types.lifetimes (2)2 Implemented2 Implemented2 TODO
dummyImplementedImplementedTODO
unchecked_borrowsImplementedImplementedTODO
crates.sage_ir.types.operators (2)2 Implemented1 Implemented2 TODO
lazy_control_flowImplementedTODO
trait_callsImplementedImplementedTODO
scoped_identitiesImplementedTODO
crates.sage_ir.types.spans (4)4 Implemented4 Implemented4 TODO
generated_identityImplementedImplementedTODO
item_originImplementedImplementedTODO
offset_reuseImplementedImplementedTODO
relative_compositionImplementedImplementedTODO
crates.sage_oracle_harness (4)4 Implemented2 TODO1 Implemented4 TODO
crates.sage_oracle_harness.crate (4)4 Implemented2 TODO1 Implemented4 TODO
deterministic_emissionImplementedTODO
exact_comparisonImplementedTODOImplementedTODO
fixed_projectionImplementedTODO
independent_coverageImplementedTODOTODO
crates.sage_stash (5)5 Implemented5 Implemented
crates.sage_stash.storage (5)5 Implemented5 Implemented
handle_ownershipImplementedImplemented
immutable_entriesImplementedImplemented
query_valueImplementedImplemented
rooted_equalityImplementedImplemented
typed_interningImplementedImplemented
crates.sage_test_harness (25)25 Implemented25 Implemented
crates.sage_test_harness.compile_tests (25)25 Implemented25 Implemented
annotation_validationImplementedImplemented
blessing_gateImplementedImplemented
callsite_updatesImplementedImplemented
checking_scopeImplementedImplemented
compiler_conditionsImplementedImplemented
completed_typesImplementedImplemented
coordinatesImplementedImplemented
dependenciesImplementedImplemented
diagnostic_countsImplementedImplemented
diagnostic_locationsImplementedImplemented
editionImplementedImplemented
fixturesImplementedImplemented
grouped_observationsImplementedImplemented
invocationImplementedImplemented
production_executionImplementedImplemented
project_isolationImplementedImplemented
query_captureImplementedImplemented
query_projectionImplementedImplemented
renderingImplementedImplemented
resolved_symbolsImplementedImplemented
review_visibilityImplementedImplemented
rustc_executionImplementedImplemented
rustc_lintsImplementedImplemented
starting_expressionsImplementedImplemented
target_lineImplementedImplemented