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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//! The serializable view of one resolved run: each decision with its source.
use std::path::PathBuf;
use fallow_config::{CommandKind, Surface};
use fallow_types::sourced::Sourced;
use serde::Serialize;
/// The schema version of [`ResolvedRunView`].
pub const RESOLVED_RUN_VIEW_SCHEMA_VERSION: u32 = 1;
/// Schema projection for the exact version of the resolved run view.
#[cfg(feature = "schema")]
#[expect(dead_code, reason = "schema-only type used by the field projection")]
#[derive(schemars::JsonSchema)]
#[schemars(extend("const" = RESOLVED_RUN_VIEW_SCHEMA_VERSION))]
struct ResolvedRunViewSchemaVersion(u32);
/// Every decision of one run, with the input that gave it.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[cfg_attr(
feature = "schema",
schemars(title = "fallow config --resolved --format json")
)]
pub struct ResolvedRunView {
/// The schema version of this view.
#[cfg_attr(feature = "schema", schemars(with = "ResolvedRunViewSchemaVersion"))]
pub schema_version: u32,
/// The kind discriminator: always `resolved-run`.
pub kind: ResolvedRunKind,
/// The surface that started the run.
pub surface: Surface,
/// The command of the run.
pub command: CommandKind,
/// The project root.
pub root: Sourced<PathBuf>,
/// The config file. `null` when the run uses the default config.
pub config_file: Sourced<Option<PathBuf>>,
/// The decisions of each analysis.
pub analyses: AnalysesView,
/// The settings of the run.
pub settings: RunSettingsView,
/// The environment variables of the run, by name. The view never holds a
/// value.
pub env: EnvView,
/// Whether the run uses the default config because the discovered config
/// failed.
pub fell_back: bool,
}
/// The kind discriminator of [`ResolvedRunView`].
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub enum ResolvedRunKind {
/// The only value: `resolved-run`.
ResolvedRun,
}
/// The decisions of each analysis.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct AnalysesView {
/// The dead-code analysis.
pub dead_code: AnalysisView,
/// The duplication analysis.
pub duplication: AnalysisView,
/// The health analysis.
pub health: AnalysisView,
}
/// The decisions of one analysis.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct AnalysisView {
/// Whether the analysis runs.
pub selection: Sourced<SelectionView>,
/// The production mode of the analysis.
pub production: Sourced<bool>,
}
/// Whether an analysis runs, and why it does not.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "kebab-case")]
pub enum SelectionView {
/// The analysis runs.
Run,
/// The request excludes the analysis.
NotRequested,
/// A config key turns the analysis off.
OffByConfig,
}
/// The settings of one run.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct RunSettingsView {
/// The number of worker threads.
pub threads: Sourced<usize>,
/// Whether the run bypasses the parse cache.
pub no_cache: Sourced<bool>,
/// Whether the `extends` chain can name `https://` entries.
pub allow_remote_extends: Sourced<bool>,
/// The largest file to analyze, in bytes. `null` means no limit.
pub max_file_size_bytes: Sourced<Option<u64>>,
/// The cache directory.
pub cache_dir: Sourced<PathBuf>,
/// The size limit of the parse cache, in megabytes.
pub cache_max_size_mb: Sourced<Option<u32>>,
/// Whether the run reads `workspaces.changedSince`.
pub package_baselines: Sourced<bool>,
/// Whether the run reports unused exports of entry files.
pub include_entry_exports: Sourced<bool>,
/// Whether the run refines its findings with the type-aware companion.
/// `null` when `FALLOW_TYPE_AWARE` or `FALLOW_TYPE_AWARE_REQUIRE` has a
/// value that the run cannot use.
pub type_aware: Option<Sourced<bool>>,
/// The base ref of an audit that the caller or `FALLOW_AUDIT_BASE`
/// names. `null` when the audit detects the base, and for another
/// command.
pub audit_base: Option<Sourced<String>>,
/// The base ref of an audit that detects no base: `FALLOW_CHANGED_SINCE`
/// on the MCP server. `null` when there is none.
pub audit_base_fallback: Option<Sourced<String>>,
}
/// The environment variables of one run, by name.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct EnvView {
/// The set variables that the run reads.
pub read: Vec<&'static str>,
/// The set variables that the run ignores: a variable that the run does
/// not read on its surface and command, and a variable whose value the
/// run rejects, such as a production variable that is not a bool.
pub ignored: Vec<&'static str>,
}
#[cfg(test)]
mod tests {
use fallow_types::sourced::{Scope, Source};
use super::*;
#[test]
fn analysis_view_serializes_the_value_and_the_source() {
let view = AnalysisView {
selection: Sourced::new(
SelectionView::OffByConfig,
Source::ConfigFile {
file: PathBuf::from("project/.fallowrc.json"),
key: "duplicates.enabled",
},
Scope::Analysis,
),
production: Sourced::new(
true,
Source::Environment {
name: "FALLOW_PRODUCTION",
},
Scope::Global,
),
};
assert_eq!(
serde_json::to_value(&view).expect("view serializes"),
serde_json::json!({
"selection": {
"value": "off-by-config",
"source": {
"kind": "config-file",
"file": "project/.fallowrc.json",
"key": "duplicates.enabled",
},
"scope": "analysis",
},
"production": {
"value": true,
"source": { "kind": "environment", "name": "FALLOW_PRODUCTION" },
"scope": "global",
},
})
);
}
}