MCPcopy Create free account
hub / github.com/base/base / validate

Method validate

acceptance/src/report.rs:235–313  ·  view source on GitHub ↗

Validates reporting schema, resource bounds, identifiers, and artifact paths.

(run: &RunResult)

Source from the content-addressed store, hash-verified

233
234 /// Validates reporting schema, resource bounds, identifiers, and artifact paths.
235 pub fn validate(run: &RunResult) -> Result<()> {
236 if run.schema_version != 1 {
237 bail!("unsupported result schema {}", run.schema_version);
238 }
239 Self::bounded("run_id", &run.run_id, 200)?;
240 Self::bounded("tested_sha", &run.tested_sha, 200)?;
241 if run.scenarios.is_empty() || run.scenarios.len() > 100 {
242 bail!("result must contain 1..=100 scenarios");
243 }
244 let mut scenario_ids = HashSet::new();
245 let mut total_checks = 0usize;
246 let mut total_samples = 0usize;
247 for scenario in &run.scenarios {
248 Self::valid_id("scenario", &scenario.id)?;
249 if !scenario_ids.insert(&scenario.id) {
250 bail!("duplicate scenario id {}", scenario.id);
251 }
252 if scenario.checks.len() > 1_000 || scenario.stages.len() > 100 {
253 bail!("scenario {} exceeds record bounds", scenario.id);
254 }
255 total_checks += scenario.checks.len();
256 total_samples += scenario.samples.len();
257 if total_checks > 5_000 || total_samples > 50_000 {
258 bail!("result exceeds reporting bounds");
259 }
260 let mut stage_ids = HashSet::new();
261 for stage in &scenario.stages {
262 Self::valid_id("stage", &stage.id)?;
263 Self::bounded("stage message", &stage.message, 65_536)?;
264 Self::reject_secret("stage message", &stage.message)?;
265 if !stage_ids.insert(&stage.id) {
266 bail!("duplicate stage id {}", stage.id);
267 }
268 }
269 let mut check_ids = HashSet::new();
270 for check in &scenario.checks {
271 Self::valid_id("check", &check.id)?;
272 Self::bounded("check kind", &check.kind, 100)?;
273 for (name, value) in [("message", &check.message), ("next_step", &check.next_step)]
274 {
275 Self::bounded(name, value, 65_536)?;
276 Self::reject_secret(name, value)?;
277 }
278 if !check_ids.insert(&check.id) {
279 bail!("duplicate check id {}", check.id);
280 }
281 for path in &check.evidence {
282 Self::validate_evidence_path(path)?;
283 }
284 Self::validate_value(&check.expected, 0)?;
285 Self::validate_value(&check.observed, 0)?;
286 }
287 Self::validate_value(&scenario.config, 0)?;
288 Self::bounded("reproduction", &scenario.reproduction, 4_096)?;
289 Self::reject_secret("reproduction", &scenario.reproduction)?;
290 for diagnostic in &scenario.diagnostics {
291 Self::bounded("diagnostic", diagnostic, 65_536)?;
292 Self::reject_secret("diagnostic", diagnostic)?;

Callers

nothing calls this directly

Calls 5

is_someMethod · 0.80
newFunction · 0.50
is_emptyMethod · 0.45
lenMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected