Skip to main content

memstead_schema/
source.rs

1//! Schema source-file collection for publishing mem archives.
2//!
3//! A published `.mem` archive is portable only if the schema it pins
4//! travels inside it — otherwise opening the archive on a foreign
5//! machine without the matching schema registered would fail at
6//! resolve time. `collect_schema_source` resolves a `SchemaRef` to the
7//! raw YAML bytes callers need to zip into the archive's `schema/`
8//! tree.
9//!
10//! Resolution order (first match wins):
11//! 1. `<workspace>/<schemas_dir>/<name>/` — workspace-level shared
12//!    schemas (optional; when the caller supplies a workspace path)
13//! 2. Embedded built-in (via `include_dir!`) — ships inside the binary
14//!
15//! In every case the manifest's declared version is checked against the
16//! pin; a name collision at the wrong version falls through rather than
17//! silently embedding a mismatched schema.
18
19/// Filename of the install-time provenance stamp `memstead schema
20/// install` writes INTO the sealed package when the install source was
21/// an authoring directory: `{"authoring_path": "<canonical path>"}`.
22/// The stamp is the detection basis for the authoring-drift health
23/// axis — a schema without one (sealed pre-stamp, built-in, name- or
24/// archive-sourced install) is simply not checked, because a guessed
25/// provenance is worse than an absent one. The stamp is workspace-
26/// local by design: every package collector in this module reads
27/// selectively (`schema.yaml`, `types/*.yaml`, `mem-template.json`,
28/// `README.md`) and therefore never picks it up, and the git-ref
29/// export path excludes it by name — a published `.mem` archive never
30/// carries another machine's filesystem path.
31pub const INSTALL_PROVENANCE_FILE: &str = "install-provenance.json";
32
33use std::path::{Path, PathBuf};
34
35use crate::builtins::builtin_schemas_dir;
36use crate::config::SchemaRef;
37
38/// One source file destined for the archive's `.memstead/schema/` tree.
39///
40/// `archive_path` is the relative path *inside* the archive (e.g.
41/// `"schema.yaml"` or `"types/spec.yaml"`). Callers prefix it with
42/// whatever root they want (the archive writer uses `".memstead/schema/"`);
43/// the canonical re-pack uses the same prefix so byte-identical
44/// archives round-trip.
45#[derive(Debug, Clone)]
46pub struct SchemaSourceFile {
47    pub archive_path: String,
48    pub bytes: Vec<u8>,
49}
50
51#[derive(Debug, thiserror::Error)]
52pub enum SchemaSourceError {
53    #[error(
54        "schema {schema_ref} not found — candidate paths tried: [{}]",
55        .candidates.iter().map(|p| p.display().to_string()).collect::<Vec<_>>().join(", ")
56    )]
57    NotFound {
58        schema_ref: String,
59        /// Every filesystem location consulted before falling through
60        /// to the embedded builtins. Listed in resolution order so the
61        /// error message matches the precedence the resolver walked.
62        candidates: Vec<PathBuf>,
63    },
64
65    #[error("i/o error reading schema source at {}: {source}", .path.display())]
66    Io {
67        path: PathBuf,
68        #[source]
69        source: std::io::Error,
70    },
71
72    #[error(
73        "schema manifest at {} does not declare version '{expected}' (found '{found}')",
74        .path.display()
75    )]
76    VersionMismatch {
77        path: PathBuf,
78        expected: String,
79        found: String,
80    },
81
82    #[error("schema manifest at {} is malformed: {reason}", .path.display())]
83    MalformedManifest { path: PathBuf, reason: String },
84}
85
86impl SchemaSourceError {
87    /// The wire code every surface reports for this refusal.
88    pub fn code(&self) -> &'static str {
89        match self {
90            SchemaSourceError::NotFound { .. } => "SCHEMA_NOT_FOUND",
91            SchemaSourceError::Io { .. } => "IO_ERROR",
92            SchemaSourceError::VersionMismatch { .. }
93            | SchemaSourceError::MalformedManifest { .. } => "SCHEMA_VALIDATION_FAILED",
94        }
95    }
96
97    /// The recovery payload: the paths consulted or the file at fault.
98    pub fn details(&self) -> serde_json::Value {
99        match self {
100            SchemaSourceError::NotFound {
101                schema_ref,
102                candidates,
103            } => serde_json::json!({ "schema_ref": schema_ref, "candidates": candidates }),
104            SchemaSourceError::Io { path, source } => {
105                serde_json::json!({ "path": path, "reason": source.to_string() })
106            }
107            SchemaSourceError::VersionMismatch {
108                path,
109                expected,
110                found,
111            } => serde_json::json!({ "path": path, "expected": expected, "found": found }),
112            SchemaSourceError::MalformedManifest { path, reason } => {
113                serde_json::json!({ "path": path, "reason": reason })
114            }
115        }
116    }
117}
118
119/// Resolve the schema pinned by `schema_ref` to a sorted set of source
120/// files ready to embed under `.memstead/schema/` in a mem archive.
121///
122/// The returned vector is sorted by `archive_path` so archive bytes are
123/// deterministic — callers don't need to re-sort.
124///
125/// Resolution order (first match wins):
126/// 1. `<workspace_schemas_dir>/<name>/` (when provided)
127/// 2. Embedded builtins
128///
129/// A `<workspace_root>/.memstead.cache/schemas/` layer used to sit
130/// between them, meant to hold schemas extracted from installed
131/// archives. Nothing ever populated it; the install path stages into
132/// the backend's schema source instead. `workspace_root` is kept in
133/// the signature because callers thread it and a storage-rooted layer
134/// belongs here if one returns.
135///
136/// When every filesystem layer misses, the returned `NotFound` lists
137/// every concrete path that was consulted so callers (and agents) can
138/// inspect the resolution trace without re-walking the filesystem.
139pub fn collect_schema_source(
140    _workspace_root: Option<&Path>,
141    workspace_schemas_dir: Option<&Path>,
142    schema_ref: &SchemaRef,
143) -> Result<Vec<SchemaSourceFile>, SchemaSourceError> {
144    let mut candidates: Vec<PathBuf> = Vec::new();
145
146    if let Some(ws_dir) = workspace_schemas_dir {
147        // Two directory shapes: `<name>@<version>/` is what `memstead
148        // schema install` writes; the bare `<name>/` form predates the
149        // versioned layout and stays supported for hand-authored dirs.
150        let versioned_dir = ws_dir.join(format!("{}@{}", schema_ref.name, schema_ref.version));
151        candidates.push(versioned_dir.clone());
152        if versioned_dir.is_dir()
153            && let Some(files) = try_collect_dir(&versioned_dir, schema_ref)?
154        {
155            return Ok(files);
156        }
157        let ws_schema_dir = ws_dir.join(&schema_ref.name);
158        candidates.push(ws_schema_dir.clone());
159        if ws_schema_dir.is_dir()
160            && let Some(files) = try_collect_dir(&ws_schema_dir, schema_ref)?
161        {
162            return Ok(files);
163        }
164    }
165
166    if let Some(files) = collect_builtin_source(schema_ref)? {
167        return Ok(files);
168    }
169
170    Err(SchemaSourceError::NotFound {
171        schema_ref: schema_ref.as_display(),
172        candidates,
173    })
174}
175
176/// Read `<dir>/schema.yaml` + `<dir>/types/*.yaml` and return them
177/// only if the manifest's declared version matches `schema_ref`.
178/// A mismatched version returns `Ok(None)` so the caller can fall
179/// through to the next resolution layer rather than hard-failing.
180fn try_collect_dir(
181    dir: &Path,
182    schema_ref: &SchemaRef,
183) -> Result<Option<Vec<SchemaSourceFile>>, SchemaSourceError> {
184    let manifest_path = dir.join("schema.yaml");
185    let manifest_bytes = std::fs::read(&manifest_path).map_err(|e| SchemaSourceError::Io {
186        path: manifest_path.clone(),
187        source: e,
188    })?;
189
190    if !manifest_matches(&manifest_bytes, schema_ref, &manifest_path)? {
191        return Ok(None);
192    }
193
194    let mut out = vec![SchemaSourceFile {
195        archive_path: "schema.yaml".to_string(),
196        bytes: manifest_bytes,
197    }];
198
199    // The sealed format marker rides as-found — it records the
200    // package's metadata-polarity generation, so a collected source
201    // seals with the same reading its origin carries.
202    let marker_path = dir.join(crate::loader::SCHEMA_FORMAT_MARKER_FILE);
203    if marker_path.is_file() {
204        let bytes = std::fs::read(&marker_path).map_err(|e| SchemaSourceError::Io {
205            path: marker_path.clone(),
206            source: e,
207        })?;
208        out.push(SchemaSourceFile {
209            archive_path: crate::loader::SCHEMA_FORMAT_MARKER_FILE.to_string(),
210            bytes,
211        });
212    }
213
214    let types_dir = dir.join("types");
215    if types_dir.is_dir() {
216        let entries = std::fs::read_dir(&types_dir).map_err(|e| SchemaSourceError::Io {
217            path: types_dir.clone(),
218            source: e,
219        })?;
220        for entry in entries {
221            let entry = entry.map_err(|e| SchemaSourceError::Io {
222                path: types_dir.clone(),
223                source: e,
224            })?;
225            let path = entry.path();
226            if path.extension().and_then(|s| s.to_str()) != Some("yaml") {
227                continue;
228            }
229            let Some(stem) = path.file_stem().and_then(|s| s.to_str()) else {
230                continue;
231            };
232            let bytes = std::fs::read(&path).map_err(|e| SchemaSourceError::Io {
233                path: path.clone(),
234                source: e,
235            })?;
236            out.push(SchemaSourceFile {
237                archive_path: format!("types/{stem}.yaml"),
238                bytes,
239            });
240        }
241    }
242
243    out.sort_by(|a, b| a.archive_path.cmp(&b.archive_path));
244    Ok(Some(out))
245}
246
247fn collect_builtin_source(
248    schema_ref: &SchemaRef,
249) -> Result<Option<Vec<SchemaSourceFile>>, SchemaSourceError> {
250    // Name-exact directory first — the current generation lives there.
251    if let Some(schema_dir) = builtin_schemas_dir().get_dir(schema_ref.name.as_str())
252        && let Some(files) = collect_builtin_dir(schema_dir, schema_ref)?
253    {
254        return Ok(Some(files));
255    }
256    // Retained older generations live in suffixed sibling directories
257    // (`planning` vs `planning-0.2`, …) under the append-only
258    // retention pattern — the directory name is organisational only,
259    // identity comes from each package's manifest. Scan the whole
260    // embedded catalogue for the (name, version) the ref pins; the
261    // registry registers every retained version, so the collect path
262    // must resolve them all.
263    for schema_dir in builtin_schemas_dir().dirs() {
264        if let Some(files) = collect_builtin_dir(schema_dir, schema_ref)? {
265            return Ok(Some(files));
266        }
267    }
268    Ok(None)
269}
270
271/// Collect one embedded schema directory's files when its manifest
272/// matches `schema_ref` — `Ok(None)` on a manifest mismatch (or a
273/// directory without a manifest, e.g. a non-package entry) so the
274/// caller can keep scanning.
275fn collect_builtin_dir(
276    schema_dir: &include_dir::Dir<'static>,
277    schema_ref: &SchemaRef,
278) -> Result<Option<Vec<SchemaSourceFile>>, SchemaSourceError> {
279    // `include_dir`'s paths are always relative to the include root (the
280    // `builtins/schemas` dir), so every entry's path starts with the
281    // directory name. Build lookups by constructing the same prefix.
282    let prefix = schema_dir.path().display().to_string();
283    let manifest_key = format!("{prefix}/schema.yaml");
284    let Some(manifest_file) = schema_dir.get_file(manifest_key.as_str()) else {
285        return Ok(None);
286    };
287    let manifest_bytes = manifest_file.contents().to_vec();
288    if !manifest_matches(
289        &manifest_bytes,
290        schema_ref,
291        &PathBuf::from(format!("<builtin:{prefix}>/schema.yaml")),
292    )? {
293        return Ok(None);
294    }
295
296    let mut out = vec![SchemaSourceFile {
297        archive_path: "schema.yaml".to_string(),
298        bytes: manifest_bytes,
299    }];
300
301    // The sealed format marker rides as-found (new builtin
302    // generations ship it; retained older generations don't).
303    let marker_key = format!("{prefix}/{}", crate::loader::SCHEMA_FORMAT_MARKER_FILE);
304    if let Some(marker) = schema_dir.get_file(marker_key.as_str()) {
305        out.push(SchemaSourceFile {
306            archive_path: crate::loader::SCHEMA_FORMAT_MARKER_FILE.to_string(),
307            bytes: marker.contents().to_vec(),
308        });
309    }
310
311    let types_key = format!("{prefix}/types");
312    if let Some(types_dir) = schema_dir.get_dir(types_key.as_str()) {
313        for file in types_dir.files() {
314            if file.path().extension().and_then(|s| s.to_str()) != Some("yaml") {
315                continue;
316            }
317            let Some(stem) = file.path().file_stem().and_then(|s| s.to_str()) else {
318                continue;
319            };
320            out.push(SchemaSourceFile {
321                archive_path: format!("types/{stem}.yaml"),
322                bytes: file.contents().to_vec(),
323            });
324        }
325    }
326
327    out.sort_by(|a, b| a.archive_path.cmp(&b.archive_path));
328    Ok(Some(out))
329}
330
331/// True when `manifest_bytes` parses and its `name`+`version` match
332/// `schema_ref`. Uses `serde_yaml_ng` with a narrow intermediate struct
333/// rather than the full `SchemaManifest` so callers can compare versions
334/// without paying for the full manifest validation (the caller is often
335/// the publish path, where the real loader runs separately over the
336/// source directory for full validation).
337fn manifest_matches(
338    manifest_bytes: &[u8],
339    schema_ref: &SchemaRef,
340    source_path: &Path,
341) -> Result<bool, SchemaSourceError> {
342    #[derive(serde::Deserialize)]
343    struct ManifestId {
344        name: String,
345        version: String,
346    }
347    let id: ManifestId = serde_yaml_ng::from_slice(manifest_bytes).map_err(|e| {
348        SchemaSourceError::MalformedManifest {
349            path: source_path.to_path_buf(),
350            reason: e.to_string(),
351        }
352    })?;
353    if id.name != schema_ref.name {
354        return Ok(false);
355    }
356    let declared =
357        semver::Version::parse(&id.version).map_err(|e| SchemaSourceError::MalformedManifest {
358            path: source_path.to_path_buf(),
359            reason: format!("invalid semver '{}': {e}", id.version),
360        })?;
361    if declared != schema_ref.version {
362        // Surface the mismatch as a hard error only for the on-disk
363        // paths that selected `dir` by name — a workspace author bumping
364        // the pin without editing the manifest should hear about it
365        // loudly, not get a silent fallthrough to the next layer.
366        // Builtin retention keeps every generation in sibling
367        // directories (`planning`, `planning-0.2`, …), so the
368        // `collect_builtin_source` path turns `Ok(false)` into "keep
369        // scanning; NotFound only when no directory matches". String
370        // prefix, deliberately: `Path::starts_with` is
371        // component-based and never matched the `<builtin:…>` marker
372        // (which made every non-name-exact builtin version refuse
373        // with a hard VersionMismatch instead of falling through).
374        if source_path.to_string_lossy().starts_with("<builtin:") {
375            return Ok(false);
376        }
377        return Err(SchemaSourceError::VersionMismatch {
378            path: source_path.to_path_buf(),
379            expected: schema_ref.version.to_string(),
380            found: declared.to_string(),
381        });
382    }
383    Ok(true)
384}
385
386#[cfg(test)]
387mod tests {
388    use super::*;
389    use tempfile::TempDir;
390
391    fn write_schema(dir: &Path, name: &str, version: &str, types: &[&str]) {
392        let manifest = format!(
393            r#"name: {name}
394version: {version}
395description: test
396when_to_use: test
397types:
398  - {type_list}
399relationships:
400  mode: strict
401  definitions:
402    - name: _default
403      description: default
404      default_weight: 1.0
405    - name: PART_OF
406      description: hier
407      default_weight: 3.0
408community:
409  resolution: 1.0
410  seed: 42
411"#,
412            name = name,
413            version = version,
414            type_list = types.join("\n  - "),
415        );
416        std::fs::write(dir.join("schema.yaml"), manifest).unwrap();
417        for t in types {
418            let td = format!(
419                r#"name: {t}
420description: test
421when_to_use: test
422sections:
423  - key: body
424    heading: Body
425    required: true
426    search_weight: 10.0
427    catch_all: true
428metadata_fields: []
429title_weight: 1.0
430text_fields: [body]
431hierarchy_relationship: PART_OF
432no_self_loop_relationships: []
433updatable_fields: [title, body]
434health_required_fields: [body]
435staleness_threshold_days: 30
436write_rules: []
437"#
438            );
439            std::fs::write(dir.join(format!("types/{t}.yaml")), td).unwrap();
440        }
441    }
442
443    /// The collectors carry the sealed format marker as-found: the
444    /// current builtin generation ships it, a retained pre-flip
445    /// generation doesn't — so seals stay faithful in both directions.
446    #[test]
447    fn collectors_carry_format_marker_as_found() {
448        let marked: SchemaRef = "default@1.3.0".parse().unwrap();
449        let files = collect_schema_source(None, None, &marked).unwrap();
450        assert!(
451            files
452                .iter()
453                .any(|f| f.archive_path == crate::loader::SCHEMA_FORMAT_MARKER_FILE),
454            "current generation collects its marker"
455        );
456
457        let legacy: SchemaRef = "default@1.2.0".parse().unwrap();
458        let files = collect_schema_source(None, None, &legacy).unwrap();
459        assert!(
460            !files
461                .iter()
462                .any(|f| f.archive_path == crate::loader::SCHEMA_FORMAT_MARKER_FILE),
463            "retained pre-flip generation stays unmarked"
464        );
465    }
466
467    #[test]
468    fn collects_builtin_default_source() {
469        let schema_ref = SchemaRef::new("default", semver::Version::new(1, 0, 0));
470        let files = collect_schema_source(None, None, &schema_ref).unwrap();
471
472        assert!(
473            files.iter().any(|f| f.archive_path == "schema.yaml"),
474            "embedded builtin must expose schema.yaml"
475        );
476        let type_count = files
477            .iter()
478            .filter(|f| f.archive_path.starts_with("types/"))
479            .count();
480        assert_eq!(type_count, 10, "default schema has 10 types");
481        for pair in files.windows(2) {
482            assert!(pair[0].archive_path < pair[1].archive_path, "sorted");
483        }
484    }
485
486    /// The append-only retention pattern keeps older generations in
487    /// suffixed sibling directories (`planning` holds 0.1.0,
488    /// `planning-0.3` holds 0.3.0, …). Every RETAINED version the
489    /// registry registers must resolve through the collect path — the
490    /// historical name-exact-only lookup refused every version but
491    /// the one in the name-exact directory.
492    #[test]
493    fn collects_builtin_source_for_every_retained_version() {
494        for (name, version) in [
495            ("planning", semver::Version::new(0, 2, 0)),
496            ("planning", semver::Version::new(0, 4, 0)),
497            ("ingest", semver::Version::new(0, 1, 0)),
498            ("ingest", semver::Version::new(0, 5, 0)),
499        ] {
500            let schema_ref = SchemaRef::new(name, version.clone());
501            let files = collect_schema_source(None, None, &schema_ref)
502                .unwrap_or_else(|e| panic!("{name}@{version} must resolve: {e}"));
503            let manifest = files
504                .iter()
505                .find(|f| f.archive_path == "schema.yaml")
506                .expect("manifest present");
507            let text = String::from_utf8_lossy(&manifest.bytes);
508            assert!(
509                text.contains(&format!("version: {version}")),
510                "{name}@{version}: collected manifest must carry the requested version"
511            );
512        }
513
514        // An unregistered version still refuses — the scan resolves
515        // retained versions, it never invents one.
516        let ghost = SchemaRef::new("planning", semver::Version::new(9, 9, 9));
517        assert!(matches!(
518            collect_schema_source(None, None, &ghost),
519            Err(SchemaSourceError::NotFound { .. })
520        ));
521    }
522
523    #[test]
524    fn workspace_schema_wins_over_builtin() {
525        let tmp = TempDir::new().unwrap();
526        let ws_dir = tmp.path().join("schemas");
527        let schema_dir = ws_dir.join("default");
528        std::fs::create_dir_all(schema_dir.join("types")).unwrap();
529        // Override builtin default with a skeletal variant. collect_schema_source
530        // must return this, not the 10-type builtin.
531        write_schema(&schema_dir, "default", "1.0.0", &["spec"]);
532        let schema_ref = SchemaRef::new("default", semver::Version::new(1, 0, 0));
533        let files = collect_schema_source(Some(tmp.path()), Some(&ws_dir), &schema_ref).unwrap();
534        let type_count = files
535            .iter()
536            .filter(|f| f.archive_path.starts_with("types/"))
537            .count();
538        assert_eq!(type_count, 1, "workspace override takes priority");
539    }
540
541    #[test]
542    fn workspace_mismatched_version_errors() {
543        let tmp = TempDir::new().unwrap();
544        let ws_dir = tmp.path().join("schemas");
545        let schema_dir = ws_dir.join("recipe");
546        std::fs::create_dir_all(schema_dir.join("types")).unwrap();
547        write_schema(&schema_dir, "recipe", "1.0.0", &["spec"]);
548        let schema_ref = SchemaRef::new("recipe", semver::Version::new(2, 0, 0));
549        let err = collect_schema_source(Some(tmp.path()), Some(&ws_dir), &schema_ref).unwrap_err();
550        assert!(matches!(err, SchemaSourceError::VersionMismatch { .. }));
551    }
552
553    /// The retired `.memstead.cache/schemas/` layer contributes
554    /// nothing: nothing ever wrote it, and a package sitting there is
555    /// not a resolvable schema source. Publishing resolves from the
556    /// workspace layer or the built-ins.
557    #[test]
558    fn legacy_cache_directory_is_not_a_source() {
559        let tmp = TempDir::new().unwrap();
560        let dir = tmp.path().join(".memstead.cache/schemas/recipe-1.0.0");
561        std::fs::create_dir_all(dir.join("types")).unwrap();
562        write_schema(&dir, "recipe", "1.0.0", &["spec"]);
563        let schema_ref = SchemaRef::new("recipe", semver::Version::new(1, 0, 0));
564        let err = collect_schema_source(Some(tmp.path()), None, &schema_ref).unwrap_err();
565        assert!(
566            matches!(err, SchemaSourceError::NotFound { .. }),
567            "got {err:?}"
568        );
569    }
570
571    #[test]
572    fn unknown_schema_returns_not_found() {
573        let schema_ref = SchemaRef::new("nonexistent", semver::Version::new(1, 0, 0));
574        let err = collect_schema_source(None, None, &schema_ref).unwrap_err();
575        assert!(matches!(err, SchemaSourceError::NotFound { .. }));
576    }
577
578    /// The versioned install shape (`<name>@<version>/`) is consulted
579    /// before the bare hand-authored `<name>/` form, and both win over
580    /// the built-ins.
581    #[test]
582    fn versioned_workspace_shape_wins_over_the_bare_one() {
583        let tmp = TempDir::new().unwrap();
584        let ws_dir = tmp.path().join("schemas");
585        // Bare form carries a 2-type variant.
586        let bare = ws_dir.join("software");
587        std::fs::create_dir_all(bare.join("types")).unwrap();
588        write_schema(&bare, "software", "1.0.0", &["spec", "memo"]);
589        // Versioned form carries a 1-type variant — must win.
590        let versioned = ws_dir.join("software@1.0.0");
591        std::fs::create_dir_all(versioned.join("types")).unwrap();
592        write_schema(&versioned, "software", "1.0.0", &["spec"]);
593
594        let schema_ref = SchemaRef::new("software", semver::Version::new(1, 0, 0));
595        let files = collect_schema_source(Some(tmp.path()), Some(&ws_dir), &schema_ref).unwrap();
596        let type_count = files
597            .iter()
598            .filter(|f| f.archive_path.starts_with("types/"))
599            .count();
600        assert_eq!(type_count, 1, "the versioned install shape must win");
601    }
602
603    #[test]
604    fn not_found_lists_every_candidate_path() {
605        let tmp = TempDir::new().unwrap();
606        let ws_dir = tmp.path().join("schemas");
607        std::fs::create_dir_all(&ws_dir).unwrap();
608
609        let schema_ref = SchemaRef::new("missing", semver::Version::new(2, 3, 4));
610        let err = collect_schema_source(Some(tmp.path()), Some(&ws_dir), &schema_ref).unwrap_err();
611        match err {
612            SchemaSourceError::NotFound {
613                schema_ref: name,
614                candidates,
615            } => {
616                assert_eq!(name, "missing@2.3.4");
617                // Every filesystem candidate listed in resolution
618                // order: the versioned install shape first, then the
619                // bare workspace schemas dir.
620                assert_eq!(candidates.len(), 2, "got {candidates:?}");
621                assert!(candidates[0].ends_with("schemas/missing@2.3.4"));
622                assert!(candidates[1].ends_with("schemas/missing"));
623            }
624            other => panic!("expected NotFound, got {other:?}"),
625        }
626    }
627}