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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
//! Audit module trait and supporting types (scaffold for #330 / Phase A1).
//!
//! Defines the shape that every audit module will conform to once Phase A is
//! complete. This file is purely additive — no existing module uses it yet and
//! `pipeline.rs` is untouched. Migration of the 15 existing modules onto this
//! trait happens in A3 (collection modules) and A4 (post-processing modules).
//!
//! Design choices:
//! - `async_trait` is used so the trait stays dyn-compatible — A2 builds a
//! `Vec<Box<dyn AuditModule>>` registry on top of this scaffold.
//! - `ModuleData` is a closed enum with one variant per existing `Results`
//! struct. We deliberately do not introduce a uniform `Score`/`Findings`
//! shape across modules; each module keeps its native result type and the
//! normalizer continues to fan them out.
//! - `collect` and `derive` both default to no-ops so a module only needs to
//! implement the phase it actually participates in.
use async_trait;
use Page;
use crateAXTree;
use crateAiVisibilityAnalysis;
use cratePipelineConfig;
use crate;
use crateBestPracticesAnalysis;
use crateContentVisibilityAnalysis;
use crateDarkModeAnalysis;
use crateResult;
use crateJourneyAnalysis;
use crateMobileFriendliness;
use crateSecurityAnalysis;
use crateSeoAnalysis;
use crateSourceQualityAnalysis;
use crateTechStackAnalysis;
use crateUxAnalysis;
/// Viewport pass currently driving the audit.
///
/// Mirrors the desktop/mobile split that `pipeline.rs` already performs. Kept
/// as a small, owned enum so the trait does not pull in viewport setup
/// machinery from the pipeline module.
/// Inputs handed to an `AuditModule::collect` call.
///
/// Borrowed by the catalog (A2) for the duration of one viewport pass. Modules
/// must not retain references past the call; the borrow only outlives the
/// async collection itself.
/// Payload returned by an `AuditModule::collect` call.
///
/// One variant per existing module result type. `None` is the trait default
/// (a module that only participates in the `derive` phase, or whose collection
/// was skipped because the module is inactive). Adding a new audit module
/// means extending this enum, which intentionally forces the compiler to flag
/// any consumer that has not been taught about the new variant.
/// Contract every audit module will implement.
///
/// Two phases:
/// 1. `collect` — runs while a browser page is loaded. CDP-bound modules
/// (performance, SEO, security, …) produce a `ModuleData` variant here.
/// 2. `derive` — runs after the `NormalizedReport` exists. Aggregate modules
/// (source quality, AI visibility, content visibility) read the report and
/// write their own field via a side effect on `&mut NormalizedReport`.
///
/// A module typically implements one of the two phases; the other stays at
/// its default no-op.
///
/// Example skeleton (not wired up — Phase A3/A4 will migrate concrete modules):
///
/// ```
/// use async_trait::async_trait;
/// use auditmysite::audit::module::{AuditModule, ModuleContext, ModuleData};
/// use auditmysite::audit::PipelineConfig;
/// use auditmysite::error::Result;
///
/// struct NoopModule;
///
/// #[async_trait]
/// impl AuditModule for NoopModule {
/// fn id(&self) -> &'static str { "noop" }
/// fn is_enabled(&self, _cfg: &PipelineConfig) -> bool { false }
/// }
/// ```