crates.sage_test_harness.compile_tests.blessing_gate

Before any expectation in one test invocation is compared in updating mode, the runner completes fixture validation, compilation, annotation validation, observation collection, independent exhaustive diagnostic matching for both Sage and rustc, requested query projection, and rendering of every requested output. All resulting snapshot strings are prepared before any updating expectation assertion runs. A failure in any of those steps prevents all snapshot writes for that invocation. After they succeed, UPDATE_EXPECT=1 may update observation, diagnostic, and requested query representations. It never adds source markers, changes compiler conditions, or accepts an unmatched diagnostic. Other independent Cargo tests may update their own expectations; this is not a workspace-wide filesystem transaction.

The implementation separates preparation from expectation comparison. Preparation returns either all validated, rendered results or a failure, without invoking expect-test assertions. The caller stops on failure and compares the returned results against the supplied expectations only on success. An implementation comment at that boundary explains why this ordering prevents partial updates when preparation fails; no separate transaction mechanism is required.

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

Implementation

Implemented crates/sage-test-harness/src/compile/observe.rs:20–25

sage_test_harness::compile::observe · lib:sage_test_harness

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_test_harness.compile_tests.blessing_gate`
// {anchor}`crates.sage_test_harness.compile_tests.coordinates`
pub(super) fn collect(
    context: &SageContext<'_>,
    markers: &[Marker],
    queries: bool,

}

See more source ↗

Implemented crates/sage-test-harness/src/compile/rustc.rs:13–18

sage_test_harness::compile::rustc · lib:sage_test_harness

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_test_harness.compile_tests.blessing_gate`
// {anchor}`crates.sage_test_harness.compile_tests.rustc_execution`
// {anchor}`crates.sage_test_harness.compile_tests.rustc_lints`
// {anchor}`crates.sage_test_harness.compile_tests.compiler_conditions`
// {anchor}`crates.sage_test_harness.compile_tests.edition`
// {anchor}`crates.sage_test_harness.compile_tests.project_isolation`

}

See more source ↗

Implemented crates/sage-test-harness/src/compile/mod.rs:79–99

sage_test_harness::compile · lib:sage_test_harness

Preparation has no access to expectation assertions. Only a successful return of ALL validated, rendered outputs can reach expect-test, whose assertions may write snapshots when UPDATE_EXPECT is set.

#![allow(unused)]
fn main() {
    // {anchor}`crates.sage_test_harness.compile_tests.blessing_gate`<<
    // Preparation has no access to expectation assertions. Only a successful
    // return of ALL validated, rendered outputs can reach expect-test, whose
    // assertions may write snapshots when UPDATE_EXPECT is set.
    // {anchor}`crates.sage_test_harness.compile_tests.callsite_updates`
    // {anchor}`crates.sage_test_harness.compile_tests.review_visibility`
    pub fn run(self) {
        let output = self
            .prepare()
            .unwrap_or_else(|error| panic!("compile_test: {error}"));
        if let Some(expect) = self.observations {
            expect.assert_eq(&output.observations);
        }
        if let Some(expect) = self.diagnostics {
            expect.assert_eq(&output.diagnostics);
        }
        if let Some(expect) = self.queries {
            expect.assert_eq(&output.queries);
        }
    }
    // >>

}

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::blessing_edits_the_inline_callsite_and_then_passes_without_updates

crates/sage-test-harness/tests/callsite_updates.rs · test:callsite_updates

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_test_harness.compile_tests.annotation_validation)]
#[sage::test(crates.sage_test_harness.compile_tests.callsite_updates)]
#[sage::test(crates.sage_test_harness.compile_tests.invocation)]
#[sage::test(crates.sage_test_harness.compile_tests.blessing_gate)]
#[sage::test(crates.sage_test_harness.compile_tests.review_visibility)]
fn blessing_edits_the_inline_callsite_and_then_passes_without_updates() {
    // Compile a disposable copy: expect-test must never update this test suite
    // while exercising update mode. The complete fixture and assertion remain
    // visibly inside the annotated function's source for anchor review.
    let project = tempfile::tempdir().unwrap();
    let harness = std::path::Path::new(env!("CARGO_MANIFEST_DIR"));
    std::fs::create_dir(project.path().join("src")).unwrap();
    std::fs::write(
        project.path().join("Cargo.toml"),
        format!(
            r#"
[package]
name = "inline_callsite_probe"
version = "0.0.0"
edition = "2024"
[workspace]
[dependencies]
sage-test-harness = {{ path = {:?} }}
expect-test = "1.5.1"
[patch.crates-io]
salsa = {{ path = {:?} }}
"#,
            harness,
            harness.join("../../vendor/salsa")
        ),
    )
    .unwrap();
    // Reuse the repository's pinned dependency resolution, not a fresh online
    // resolution of the disposable package's transitive dependencies.
    std::fs::copy(
        harness.join("../../Cargo.lock"),
        project.path().join("Cargo.lock"),
    )
    .unwrap();
    let source = r##"#![feature(rustc_private)]
use sage_test_harness::compile_test;
use expect_test::expect;
#[test]
fn inline_source() {
    compile_test! {
        source: "fn answer() -> u16 {\n    22 //# ty\n}",
        observations: expect![[r#""#]],
        diagnostics: expect![""],
    }
}
"##;
    let path = project.path().join("src/lib.rs");
    std::fs::write(&path, source).unwrap();
    let target = harness.join("../../target");
    let run = |update, expected_success| {
        let mut command = Command::new("cargo");
        command
            .args(["test", "--offline", "--lib", "--quiet"])
            .current_dir(project.path())
            .env("CARGO_TARGET_DIR", &target)
            .env("RUSTC", sage_host::metadata::our_rustc());
        if update {
            command.env("UPDATE_EXPECT", "1");
        } else {
            command.env_remove("UPDATE_EXPECT");
        }
        let output = command.output().unwrap();
        assert_eq!(
            output.status.success(),
            expected_success,
            "{}\n{}",
            String::from_utf8_lossy(&output.stdout),
            String::from_utf8_lossy(&output.stderr)
        );
        String::from_utf8_lossy(&output.stdout).to_string()
    };
    // A rustc-only warning is an unexpected diagnostic even with UPDATE_EXPECT.
    // The stale observation must remain byte-for-byte unchanged on failure.
    let unexpected = source.replace("fn answer()", "#[warn(dead_code)] fn answer()");
    std::fs::write(&path, &unexpected).unwrap();
    let failure = run(true, false);
    assert!(
        failure.contains("Rustc diagnostic markers do not match"),
        "{failure}"
    );
    assert_eq!(std::fs::read_to_string(&path).unwrap(), unexpected);
    std::fs::write(&path, source).unwrap();
    let stale = run(false, false);
    assert!(stale.contains("expect test failed"), "{stale}");
    assert_eq!(std::fs::read_to_string(&path).unwrap(), source);
    run(true, true);
    let blessed = std::fs::read_to_string(&path).unwrap();
    assert!(
        blessed.contains("src/lib.rs: literal `22`") && blessed.contains("type: u16"),
        "{blessed}"
    );
    assert!(blessed.contains("22 //# ty"));
    assert!(blessed.contains("diagnostics: expect![\"\"]"));
    assert_eq!(blessed.matches("src/lib.rs: literal").count(), 1);
    run(false, true);
    assert_eq!(std::fs::read_to_string(path).unwrap(), blessed);
}
}

See more source ↗

Implemented sage_test_harness::blessing_gate_is_justified_by_implementation_structure

crates/sage-test-harness/tests/compile_tests.rs · test:compile_tests

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_test_harness.compile_tests.blessing_gate)]
fn blessing_gate_is_justified_by_implementation_structure() {
    // Implementation-only justification, not executable behavioral evidence:
    // CompileTest::prepare returns all validated, rendered results or an error.
    // It never invokes expect-test assertions. CompileTest::run stops on that
    // error; only its success branch can compare (and possibly update) values.
    // Review the associated implementation and this explanatory no-op together.
    // This structural argument avoids failure-injection tests at every stage.
}
}

See more source ↗

Review: Accepted · Codex anchor_001 final-source reviewer.

Fresh source assessment of the complete blessing_gate claim, all three ordinary implementation associations, and both complete associated tests. No TODO/N/A entries are present. This refresh ran review start/read/record and source inspection only; root owns test execution, and I make no claim of running the final-source suites.

The required barrier is explicit in CompileTest::run: prepare must return Output before any observation, diagnostic, or query expect-test assertion runs. Its boundary comment explains that only ALL validated, rendered results may reach assertions capable of updating snapshots. prepare validates fixture paths/root/conflicts and edition, parses source directives, checks observation/expectation agreement, materializes the private project, runs independent rustc checking, opens Sage, clears setup events, and invokes collect. Errors and panics during these preparation stages stop the caller before assertions. The final result match accepts only simultaneous Sage and rustc success; a rendered Sage result cannot hide rustc failure, and rustc success cannot hide Sage failure. Omitted diagnostic expectations with emitted diagnostics also fail before comparison.

observe::collect checks the local crate, collects ordinary and accumulated signature diagnostics, verifies marker files belong to the crate, freezes query events, and performs exhaustive Sage matching. It then validates selected observations, rejects invalid/incomplete type rows or invalid symbol correspondence, builds observation strings, projects requested query events and serializes them, and renders diagnostics into an owned Output. All of these operations precede return to run. The current enum-discriminant unsupported diagnostics are produced during check_crate and join the same pre-comparison matching barrier. Query projection and rendering are eager; no deferred output work appears in expectation comparison.

The current rustc adapter separates execute from validate_output: execution failures propagate; output validation rejects non-UTF-8 stderr, unexpected stdout, malformed diagnostics, and abnormal/inconsistent exit status before invoking compiler-aware matching. This refactoring preserves the preparation barrier. Both compiler paths use the matcher in observe.rs, which filters applicable markers, builds severity/location edges, uses augmenting assignment for one-to-one matching, and rejects unmatched markers or diagnostics. The captured parser reads compiler qualifiers from source without mutating source; markers are borrowed immutably downstream. Updating cannot add markers, change conditions, or bypass either compiler's matcher. After successful preparation, run can update all three supplied representation kinds. Its scope is one invocation; there is no global transaction or rollback promise for independent tests or later snapshot I/O.

The complete callsite_updates test visibly prepares a disposable source file and runs it with UPDATE_EXPECT set. A rustc-only warning is introduced while observations are stale; the test requires a Rustc diagnostic mismatch and byte-for-byte unchanged source. This specifically catches the plausible regression of updating Sage observations before accepting the rustc result. It additionally verifies stale comparison fails without updates, a successful updating run inserts the expected literal/type representation, retains the original source marker and empty diagnostic expectation, inserts the observation once, and passes again without updating or further file changes. These are meaningful behavioral assertions, not just associations. The second associated test explicitly documents a structural justification and is a no-op; its pass is not behavioral evidence. The captured RFD permits this structural argument instead of failure injection at every stage. The actual barrier inspected here accounts for fixture, compiler, annotation, observation, matching, projection, and rendering failures for all output kinds. Both test entries and all implementation entries are accounted for. No production change or additional association is required for this anchor, and no unresolved behavioral concern was found. Final refresh after coordinated assertion tightening: inspected the newly captured inputs. The only changed initial source fragment tightens two unselected_private_body_still_reports_errors assertions to require the Sage diagnostic mismatch prefix, excluding rustc-only false positives. Production preparation/comparison code, the blessing claim, both associated test bodies, and association metadata remain unchanged. This strengthens surrounding evidence without introducing a new updating path. Re-captured parser and complete relevant RFD rationale before recording. A subsequent fresh-start diff additionally tightens unresolved_paths_still_require_error_markers to require the Sage prefix. I inspected that sole further change; it likewise strengthens a surrounding assertion without changing the gate or its associated tests. Dependencies were recaptured again for this recording.

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