crates.sage_test_harness.compile_tests.callsite_updates

Expectations passed through compile_test! retain their author-written source locations. Blessing edits those expectation literals at the test call site, not the macro implementation or a generated temporary file. Normal test runs compare expectations without modifying sources. Updates must be verified with an independent subsequent run with updating disabled.

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

Implementation

Implemented crates/sage-test-harness/src/compile/mod.rs:83–88

sage_test_harness::compile · lib:sage_test_harness

#![allow(unused)]
fn main() {
    // {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}"));

}

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 ↗

Review: Accepted · /root/final_quality.

Fresh review of the complete callsite_updates claim, its one ordinary implementation entry (CompileTest::run in compile/mod.rs) and its one ordinary test (blessing_edits_the_inline_callsite_and_then_passes_without_updates). No TODO or N/A entry is present. Read the complete captured implementation file and test body plus captured blessing_gate design and the accepted RFD's ordinary-test/expectation-tooling rationale. No Rust edits, build or test execution in this review; the statements about test coverage describe inspected assertions, not a fresh test result.

Author-written locations and update destination: compile_test forwards each user expression directly into its field setter. observations, diagnostics and queries store the original expect_test::Expect values; neither the macro nor run constructs replacement expectations or temporary-file snapshots. run calls assert_eq on those same values only after preparation succeeds. Moving the Expect value through the builder preserves its callsite information. All three fields follow this identical storage/assertion mechanism. Temporary fixture files contain the evaluated Rust source, not recreated expectation macros. This realizes the RFD's decision to retain existing expect-test tooling and callsite literals.

The complete associated test exercises an actual downstream caller: it writes a disposable Cargo package with a visible compile_test invocation, an empty observation literal and an empty diagnostics literal. Its closure launches separate cargo test processes with the local harness dependency, pinned rustc, reused repository lock resolution and offline mode. The updating process explicitly sets UPDATE_EXPECT; each ordinary process removes it rather than inheriting the surrounding test environment. A stale ordinary run must fail with expect-test failure text and leave the caller source byte-for-byte unchanged. A successful updating run must write the rendered literal-22/u16 observation into that same caller source, retain the source annotation and the diagnostics expectation, and include exactly one rendered literal entry. This is direct evidence that the inline expectation is updated at the author-written location rather than only a temporary compiled fixture or the harness macro definition. Source inspection of unchanged Expect forwarding establishes why the macro implementation is not the destination.

Independent verification and ordinary immutability: after reading the blessed caller text, the test launches another independent non-updating cargo test process, requires success, and asserts the caller remains exactly equal to the blessed text. It therefore checks both ordinary mismatch/no-write behavior and ordinary success/no-write behavior, and does not mistake successful blessing alone for verification. The same test first introduces an unmarked rustc warning while updating, requires the compiler-marker failure and byte-for-byte unchanged source. That additional assertion supports the captured preparation boundary: only successfully prepared outputs can reach snapshot assertions. No claim that every snapshot field is separately integration-tested: the concrete update scenario covers observations and preservation of diagnostics, while inspection verifies common Expect handling for all fields. This coverage is adequate for the location/update-mode claim; no concrete defect or requested edit found.

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