1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! CLI-owned runtime state for root output serialization.
use std::sync::Mutex;
static TELEMETRY_ANALYSIS_RUN_ID: Mutex<Option<String>> = Mutex::new(None);
/// The baseline this run loaded, recorded for the `recheck-baseline` next step.
static LOADED_BASELINE: Mutex<Option<LoadedBaselineRecheck>> = Mutex::new(None);
/// What the `recheck-baseline` next step needs about the loaded baseline.
///
/// Recorded at load time rather than threaded through the render layer. Every
/// JSON render site already receives the staleness object, but none of them
/// receives the path the caller wrote, and the path is the only part a
/// consumer cannot reconstruct from the envelope. One slot per process is
/// honest because a standalone command loads at most one baseline; `command`
/// is what keeps a `dupes` render from offering a `dead-code` path when a
/// single process ran both.
#[derive(Clone, Debug)]
pub struct LoadedBaselineRecheck {
/// The command that loaded it, as `fallow <command>` spells it.
pub command: &'static str,
/// The `--baseline` path exactly as the caller wrote it.
pub path: String,
/// Entries the baseline carried.
pub baseline_entries: usize,
/// The channels that narrowed the run this baseline was compared against.
pub scope_reasons: fallow_output::BaselineScopeReasons,
}
pub fn set_loaded_baseline(loaded: LoadedBaselineRecheck) {
if let Ok(mut current) = LOADED_BASELINE.lock() {
*current = Some(loaded);
}
}
/// The loaded baseline, when `command` is the command that loaded it.
#[must_use]
pub fn loaded_baseline_for(command: &str) -> Option<LoadedBaselineRecheck> {
LOADED_BASELINE
.lock()
.ok()
.and_then(|loaded| loaded.clone())
.filter(|loaded| loaded.command == command)
}
#[must_use]
pub fn current_root_envelope_mode() -> fallow_output::RootEnvelopeMode {
fallow_output::RootEnvelopeMode::Tagged
}
#[allow(
dead_code,
reason = "used by the CLI binary and output contract tests; the library target only reads runtime output state"
)]
pub fn set_telemetry_analysis_run_id(run_id: Option<String>) {
if let Ok(mut current) = TELEMETRY_ANALYSIS_RUN_ID.lock() {
*current = run_id;
}
}
#[must_use]
pub fn telemetry_analysis_run_id() -> Option<String> {
TELEMETRY_ANALYSIS_RUN_ID
.lock()
.ok()
.and_then(|id| id.clone())
}