Skip to main content

devscout_rs/graph/compiler_facts/
expectations.rs

1// What a candidate artifact is admitted against: the engine revision,
2// contract version and dependency fingerprint pinned to the shipped engine
3// build (compiled-in constants, following the crate's existing exact-pin
4// convention in Cargo.toml), the profile the caller requested, and the
5// source-snapshot identity read from this checkout's own git HEAD via the
6// crate's one existing `git` shell-out (`manifest::git_head`) -- no new
7// shell-out site is added anywhere in this crate.
8
9use std::path::Path;
10
11use crate::manifest;
12
13use super::artifact::{Profile, COMPILER_FACTS_CONTRACT_VERSION};
14
15/// The producer name this admission path accepts. Keeps the contract
16/// additive and producer-tagged: a later outcome that adds or substitutes a
17/// producer format changes this constant (and the token it is compared
18/// under), never the admission path itself.
19pub const EXPECTED_PRODUCER_NAME: &str = "scout-semantic";
20
21/// The engine-protocol revision this admission path expects. Distinct from
22/// [`super::artifact::COMPILER_FACTS_CONTRACT_VERSION`]: this names the
23/// engine's own analysis behaviour, the contract names the wire shape.
24/// Bump together with a corresponding change on the engine side. "2" means
25/// the engine this admission path expects can emit occurrence facts.
26pub const EXPECTED_ENGINE_REVISION: &str = "2";
27
28/// The sha256 digest of `tools/scout-semantic/packages.lock.json` as of the
29/// engine build this admission path expects. Recompute
30/// (`shasum -a 256 tools/scout-semantic/packages.lock.json`) and update this
31/// constant whenever that lock file changes.
32pub const EXPECTED_DEPENDENCY_FINGERPRINT: &str =
33    "1b08b298ead60b49666b3bfa8d389386770d87dc150a9b1eced58896652f3d43";
34
35/// The compilation-context envelope version this admission path recognises.
36/// A candidate embedding any other version is refused without this module
37/// ever parsing the envelope's internal shape.
38pub const EXPECTED_CONTEXT_SCHEMA_VERSION: u64 = 1;
39
40/// What one admission call checks a candidate against.
41#[derive(Debug, Clone)]
42pub struct AdmissionExpectations {
43    /// The wire-contract version the candidate must declare.
44    pub contract_version: u64,
45    /// The producer name the candidate must declare.
46    pub producer_name: &'static str,
47    /// The engine revision the candidate must report.
48    pub engine_revision: &'static str,
49    /// The dependency fingerprint the candidate must report.
50    pub dependency_fingerprint: &'static str,
51    /// The compilation-context envelope version the candidate must embed.
52    pub context_schema_version: u64,
53    /// The profile the caller requested of the engine.
54    pub profile: Profile,
55    /// This checkout's own HEAD commit, or `None` outside a git repository.
56    /// `None` skips the source-snapshot check rather than refusing every
57    /// candidate on a checkout admission cannot identify.
58    pub head_sha: Option<String>,
59}
60
61/// Builds the expectations a `compiler-facts run`/`import` admits against,
62/// for the checkout at `root` and the profile the caller requested.
63pub fn expectations_for(root: &Path, profile: Profile) -> AdmissionExpectations {
64    AdmissionExpectations {
65        contract_version: COMPILER_FACTS_CONTRACT_VERSION,
66        producer_name: EXPECTED_PRODUCER_NAME,
67        engine_revision: EXPECTED_ENGINE_REVISION,
68        dependency_fingerprint: EXPECTED_DEPENDENCY_FINGERPRINT,
69        context_schema_version: EXPECTED_CONTEXT_SCHEMA_VERSION,
70        profile,
71        head_sha: manifest::git_head(root),
72    }
73}