memstead_base/binding_run.rs
1//! Binding-run resolution — turning a declared binding into the resolved
2//! form a run works from (sources with their bases and change strategies,
3//! the process mem a binding writes into), with the typed refusals a
4//! malformed declaration earns.
5//!
6//! Kernel, not loop: the health surface resolves the process mem for its
7//! projection axis and the read surface resolves a binding run before it
8//! reports findings, so the resolution lives beside the binding store it
9//! reads. Moved here from `ingest::resolve` on 2026-09-10; the loop and
10//! every consumer path reach it through `ingest::resolve`.
11
12use std::path::{Path, PathBuf};
13
14use crate::binding::{Binding, BuildMode, medium_capabilities};
15pub use crate::pipeline::Source;
16use crate::pipeline::{IngestTrigger, MediumType};
17
18/// A binding source resolved to what the run needs: a **primary** inline
19/// source (the territory to read and write back), or a read-only
20/// **reference** mem supplying cross-mem context.
21#[derive(Debug, Clone, PartialEq, Eq)]
22pub enum ResolvedSource {
23 /// An inline primary source (both halves: where it lives / which part).
24 Primary(Source),
25 /// A read-only reference mem (cross-mem context, never written).
26 Reference {
27 /// The reference mem's id.
28 mem: String,
29 },
30}
31
32/// A v2 binding unpacked into the runtime shape the orchestration stages
33/// (cursor, brief, selection) consume.
34#[derive(Debug, Clone, PartialEq, Eq)]
35pub struct ResolvedIngest {
36 /// The run's identity — the canonical binding id `<mem>/<stem>`, the
37 /// string every downstream key (sync_state, selection cache, brief header)
38 /// derives from.
39 pub name: String,
40 /// The build mode — discovery / one-shot (`refinement` is deleted).
41 /// Defaults to discovery when the binding declares no `build` block.
42 pub mode: BuildMode,
43 /// Loop / manual / on-event.
44 pub trigger: IngestTrigger,
45 /// How many artifacts a single run processes.
46 pub batch_size: u32,
47 /// Paths excluded for this binding's runs, on top of source scope.
48 pub deny_paths: Vec<String>,
49 /// The binding id verbatim (`"<mem>/<name>"`).
50 pub projection_ref: String,
51 /// The binding's owning mem (the part before the `/`).
52 pub projection_mem: String,
53 /// The binding's name (the part after the `/`).
54 pub projection_name: String,
55 /// The binding's intent — prose for the agent (the brief's "about
56 /// the source" block).
57 pub intent: Option<String>,
58 /// The resolved sources, in declaration order: inline primaries first,
59 /// then reference mems.
60 pub sources: Vec<ResolvedSource>,
61 /// The single mem this binding writes into.
62 pub destination_mem: String,
63 /// Free-form binding rules (e.g. one-shot lens `routing`).
64 pub rules: Option<serde_json::Value>,
65 /// Free-form post-run actions (e.g. one-shot `archive_source`).
66 pub post_actions: Option<serde_json::Value>,
67}
68
69/// Why a binding could not be resolved. With inline sources the only
70/// structural failures left are identity-level: an unknown binding id, or a
71/// malformed one.
72#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
73pub enum ResolveError {
74 /// No binding with the given id in the store.
75 #[error("binding '{name}' not found; available: {}", fmt_list(available))]
76 BindingNotFound {
77 /// The requested binding id.
78 name: String,
79 /// The binding ids that do exist.
80 available: Vec<String>,
81 },
82 /// The binding id is not the required `"<mem>/<name>"`.
83 #[error("malformed binding id '{projection}'; expected \"<mem>/<name>\"")]
84 MalformedProjectionRef {
85 /// The binding whose id is malformed.
86 ingest: String,
87 /// The malformed value.
88 projection: String,
89 },
90 /// A source's scope carries a pattern its medium's namespace cannot
91 /// express, so the declared selection reaches nothing. Refused when the
92 /// binding is resolved for a run, not only when it is edited: a scope
93 /// nothing interprets is decorative wherever it came from, and
94 /// hand-editing the record is a route the CLI's own refusal text
95 /// recommends.
96 #[error("binding '{binding}' cannot run: {reason}")]
97 UninterpretableScope {
98 /// The binding whose scope cannot be interpreted.
99 binding: String,
100 /// What is wrong and how to fix it.
101 reason: String,
102 },
103}
104
105/// Render a name list for an error message: `a, b, c` or `(none)`.
106fn fmt_list(names: &[String]) -> String {
107 if names.is_empty() {
108 "(none)".to_string()
109 } else {
110 names.join(", ")
111 }
112}
113
114/// Unpack a **v2 binding** (by canonical id) into the runtime
115/// [`ResolvedIngest`] shape the orchestration stages (cursor, brief,
116/// selection) consume.
117///
118/// The binding *is* the whole declaration: its inline sources become the
119/// primary [`ResolvedSource`]s verbatim, its `operations.build` supplies the
120/// run mode / trigger / batch / post-actions, and `deny_paths` / `intent` /
121/// `rules` come straight off the record. `binding_id` is the canonical
122/// `<mem>/<stem>`, which becomes the resolved ingest's `name` and
123/// `projection_ref` — every downstream key (sync_state, selection cache,
124/// brief header) is derived from it. A malformed `binding_id` is
125/// [`ResolveError::MalformedProjectionRef`]. Pure — no I/O.
126pub fn resolve_binding_run(
127 binding_id: &str,
128 binding: &Binding,
129) -> Result<ResolvedIngest, ResolveError> {
130 let (mem, name) = crate::pipeline_store::parse_binding_id(binding_id).ok_or_else(|| {
131 ResolveError::MalformedProjectionRef {
132 ingest: binding_id.to_string(),
133 projection: binding_id.to_string(),
134 }
135 })?;
136 let mem = mem.to_string();
137 let name = name.to_string();
138
139 // A scope rule nothing interprets is refused HERE, on the run path, and
140 // not only on the edit paths that call `validate_binding`. Scaffolding the
141 // right shape only protects bindings this engine wrote: every graph
142 // binding scaffolded before the entity vocabulary existed carries the path
143 // glob `**/*`, and a hand-edited record is a route the CLI's own
144 // name-collision refusal points people at. Left unguarded, such a binding
145 // ran clean over an S(D) of zero and recorded a `#verified` baseline for a
146 // measurement that never happened.
147 for source in &binding.sources {
148 match source.medium_type {
149 crate::pipeline::MediumType::Graph => {
150 for rule in &source.scope {
151 if crate::source_scope::parse_entity_selector(&rule.path).is_none() {
152 return Err(ResolveError::UninterpretableScope {
153 binding: binding_id.to_string(),
154 reason: format!(
155 "source '{}' is a graph medium, but its scope pattern '{}' is \
156 not an entity selector — a graph source selects entities, not \
157 paths. Write '*' for the whole mem, 'type:<entity_type>', or \
158 'id:<glob>'",
159 source.name, rule.path
160 ),
161 });
162 }
163 }
164 }
165 // A web source has no scope vocabulary at all, so any rule on it
166 // is uninterpretable — the same class, and gating the run-path
167 // refusal on graph alone is how it survived the declaration gate
168 // being graph-only.
169 crate::pipeline::MediumType::Web => {
170 if let Some(rule) = source.scope.first() {
171 return Err(ResolveError::UninterpretableScope {
172 binding: binding_id.to_string(),
173 reason: format!(
174 "source '{}' is a web medium, which has no scope vocabulary — its \
175 scope pattern '{}' would select nothing while looking like \
176 selection. Remove the scope rule",
177 source.name, rule.path
178 ),
179 });
180 }
181 }
182 crate::pipeline::MediumType::Codebase
183 | crate::pipeline::MediumType::Filesystem
184 | crate::pipeline::MediumType::Git => {}
185 }
186 }
187
188 let mut sources = Vec::with_capacity(binding.sources.len() + binding.reference_mems.len());
189 for source in &binding.sources {
190 sources.push(ResolvedSource::Primary(source.clone()));
191 }
192 for reference_mem in &binding.reference_mems {
193 sources.push(ResolvedSource::Reference {
194 mem: reference_mem.clone(),
195 });
196 }
197
198 // The build op supplies mode / trigger / batch / post-actions. An absent
199 // build block (a not-yet-built obligation) resolves to sane defaults — the
200 // build-path refusal is enforced at the brief entry point, not here, so
201 // read-only callers (status) keep working.
202 let build = binding.operations.build.as_ref();
203 let mode = build.map_or(BuildMode::Discovery, |b| b.mode);
204 let trigger = build.map_or(IngestTrigger::Loop, |b| b.trigger);
205 let batch_size = build.map_or(20, |b| b.batch_size);
206 let post_actions = build.and_then(|b| b.post_actions.clone());
207
208 Ok(ResolvedIngest {
209 name: binding_id.to_string(),
210 mode,
211 trigger,
212 batch_size,
213 deny_paths: binding.deny_paths.clone(),
214 projection_ref: binding_id.to_string(),
215 projection_mem: mem,
216 projection_name: name,
217 intent: binding.intent.clone(),
218 sources,
219 destination_mem: binding.destination_mem.clone(),
220 rules: binding.rules.clone(),
221 post_actions,
222 })
223}
224
225/// A primary source's resolved change-detection strategy — how "what
226/// changed since the last synced pass" is computed for it.
227#[derive(Debug, Clone, Copy, PartialEq, Eq)]
228pub enum ChangeStrategy {
229 /// No change detection — the source is re-roamed whole (inert signal).
230 None,
231 /// Git-commit diff between the baseline commit and current `HEAD`.
232 Git,
233 /// Filesystem `(mtime, size)` stat-map digest + diff.
234 Mtime,
235 /// Graph snapshot diff (the source mem's snapshot token).
236 Graph,
237}
238
239/// Resolve a primary source's [`ChangeStrategy`]. A graph-typed source
240/// always uses [`Graph`] (its signal is the source mem's snapshot token,
241/// which the engine provides). Otherwise the source's declared strategy wins
242/// (`none`/`git`/`mtime`); `auto` — the default when unset, and any
243/// unrecognized value — probes for a git work tree over the source pointer
244/// (resolved against `workspace_root`): present → [`Git`], absent →
245/// [`Mtime`].
246///
247/// [`Graph`]: ChangeStrategy::Graph
248/// [`Git`]: ChangeStrategy::Git
249/// [`Mtime`]: ChangeStrategy::Mtime
250pub fn resolve_change_strategy(source: &Source, workspace_root: &Path) -> ChangeStrategy {
251 if source.medium_type == MediumType::Graph {
252 return ChangeStrategy::Graph;
253 }
254 // A detection-less medium (per the capability matrix: `web`)
255 // has no change signal: it resolves to the visible NoSignal (`none`), never
256 // a fabricated `mtime`/`git` token. This mirrors the graph special case
257 // above — the medium type overrides any declared value.
258 if !medium_capabilities(source.medium_type).change_signal {
259 return ChangeStrategy::None;
260 }
261 match source.change_detection.as_deref() {
262 Some("none") => ChangeStrategy::None,
263 // A declared strategy is NOT second-guessed here: this resolver maps
264 // the declaration, and an author who writes `git` means git. Whether
265 // the checkout can actually deliver that signal is a question about
266 // this pass, not about the binding — a `git archive` or Docker `COPY`
267 // has the sources and no `.git`, and the honest place to say so is the
268 // freshness row, which reports what the run observed. See
269 // `FacetFreshness::change_detectable`.
270 Some("git") => ChangeStrategy::Git,
271 Some("mtime") => ChangeStrategy::Mtime,
272 // `auto`, unset, or any unrecognized value: probe the filesystem.
273 _ => {
274 if find_git_root(&source_base_path(source, workspace_root)).is_some() {
275 ChangeStrategy::Git
276 } else {
277 ChangeStrategy::Mtime
278 }
279 }
280 }
281}
282
283/// The on-disk base directory a path-based primary source resolves to: the
284/// source pointer joined onto the workspace root (`Path::join` yields the
285/// pointer verbatim when it is absolute), or the workspace root itself for
286/// an empty pointer. Only meaningful for path-namespaced mediums
287/// (codebase / filesystem / git) — a graph pointer is a mem id and a web
288/// pointer a URL.
289pub fn source_base_path(source: &Source, workspace_root: &Path) -> PathBuf {
290 if source.pointer.is_empty() {
291 workspace_root.to_path_buf()
292 } else {
293 workspace_root.join(&source.pointer)
294 }
295}
296
297/// Walk up from `start` looking for a `.git` entry (a directory *or* a file
298/// — a submodule/worktree gitlink is a file), returning the directory that
299/// contains it (the git work-tree root), or `None`. Bounded to 64 ancestors.
300/// Pure filesystem, no subprocess — deterministic for tests.
301pub fn find_git_root(start: &Path) -> Option<PathBuf> {
302 let mut dir = start.to_path_buf();
303 for _ in 0..64 {
304 if dir.join(".git").exists() {
305 return Some(dir);
306 }
307 match dir.parent() {
308 Some(parent) => dir = parent.to_path_buf(),
309 None => break,
310 }
311 }
312 None
313}
314
315#[cfg(test)]
316mod tests {
317 use super::*;
318 use crate::binding::{BINDING_VERSION, BuildOperation, Operations};
319 use crate::pipeline::{PatternEntry, PatternMode};
320
321 fn source(
322 name: &str,
323 medium_type: MediumType,
324 pointer: &str,
325 declared: Option<&str>,
326 ) -> Source {
327 Source {
328 name: name.to_string(),
329 medium_type,
330 pointer: pointer.to_string(),
331 change_detection: declared.map(str::to_string),
332 scope: vec![],
333 engagement: None,
334 preparation: None,
335 }
336 }
337
338 fn allow(path: &str) -> PatternEntry {
339 PatternEntry {
340 path: path.to_string(),
341 mode: PatternMode::Allow,
342 }
343 }
344
345 fn v2_binding(dest: &str, sources: Vec<Source>) -> Binding {
346 Binding {
347 version: BINDING_VERSION,
348 intent: Some("prose".to_string()),
349 sources,
350 reference_mems: vec![],
351 destination_mem: dest.to_string(),
352 deny_paths: vec![],
353 coverage_semantics: None,
354 rules: None,
355 prune: None,
356 operations: Operations {
357 build: Some(BuildOperation {
358 mode: BuildMode::Discovery,
359 trigger: IngestTrigger::Loop,
360 batch_size: 20,
361 post_actions: None,
362 }),
363 sync: None,
364 verify: None,
365 },
366 }
367 }
368
369 /// `resolve_binding_run` produces the runtime shape from a v2 binding
370 /// without any join: the id becomes `name`/`projection_ref`, `build.mode`
371 /// maps to the run mode, deny_paths / trigger / batch / post_actions come
372 /// off the build op, and each inline source carries over verbatim;
373 /// reference mems follow the primaries.
374 #[test]
375 fn resolve_binding_run_produces_runtime_shape() {
376 let mut swift_source = source("source-tree", MediumType::Codebase, "../app", None);
377 swift_source.scope = vec![allow("../app/**/*.swift")];
378 let mut binding = v2_binding("app", vec![swift_source.clone()]);
379 binding.intent = Some("swift".to_string());
380 binding.reference_mems = vec!["engine".to_string()];
381 binding.deny_paths = vec!["**/VISION.md".to_string()];
382 binding.operations.build.as_mut().unwrap().post_actions =
383 Some(serde_json::json!({ "archive_source": true }));
384
385 let r = resolve_binding_run("app/graph", &binding).unwrap();
386 assert_eq!(r.name, "app/graph");
387 assert_eq!(r.projection_ref, "app/graph");
388 assert_eq!(r.projection_mem, "app");
389 assert_eq!(r.projection_name, "graph");
390 assert_eq!(r.mode, BuildMode::Discovery);
391 assert_eq!(r.batch_size, 20);
392 assert_eq!(r.deny_paths, ["**/VISION.md"]);
393 assert_eq!(r.destination_mem, "app");
394 assert_eq!(r.intent.as_deref(), Some("swift"));
395 assert_eq!(
396 r.post_actions,
397 Some(serde_json::json!({ "archive_source": true }))
398 );
399 assert_eq!(r.sources.len(), 2);
400 assert_eq!(r.sources[0], ResolvedSource::Primary(swift_source));
401 assert_eq!(
402 r.sources[1],
403 ResolvedSource::Reference {
404 mem: "engine".to_string()
405 }
406 );
407 }
408
409 /// A one-shot binding maps to the one-shot run mode.
410 #[test]
411 fn resolve_binding_run_maps_one_shot() {
412 let mut binding = v2_binding("m", vec![]);
413 let build = binding.operations.build.as_mut().unwrap();
414 build.mode = BuildMode::OneShot;
415 build.trigger = IngestTrigger::Manual;
416 build.batch_size = 5;
417 let r = resolve_binding_run("m/lens", &binding).unwrap();
418 assert_eq!(r.mode, BuildMode::OneShot);
419 assert_eq!(r.batch_size, 5);
420 }
421
422 /// A malformed binding id (no `/`) is a located error.
423 #[test]
424 fn resolve_binding_run_malformed_id_errors() {
425 let binding = v2_binding("m", vec![]);
426 let err = resolve_binding_run("noslash", &binding).unwrap_err();
427 assert!(matches!(err, ResolveError::MalformedProjectionRef { .. }));
428 }
429
430 /// The convention-derived process mem: the binding id itself for a
431 /// single-component destination (unchanged), the last separator
432 /// hyphenated for a nested one, so a git-branch workspace can hold
433 /// the derived name beside the destination's own branch.
434 #[test]
435 fn derived_process_mem_name_keeps_flat_ids_and_hyphenates_nested_ones() {
436 assert_eq!(derived_process_mem_name("engine/graph"), "engine/graph");
437 assert_eq!(
438 derived_process_mem_name("library/sample/notes"),
439 "library/sample-notes"
440 );
441 assert_eq!(
442 derived_process_mem_name("planning/plan-first-sample/notes"),
443 "planning/plan-first-sample-notes"
444 );
445 assert_eq!(derived_process_mem_name("a/b/c/d"), "a/b/c-d");
446 // A malformed id passes through: nothing to derive from.
447 assert_eq!(derived_process_mem_name("noslash"), "noslash");
448 assert_eq!(derived_process_mem_name(""), "");
449 }
450
451 /// An absent build block resolves to sane defaults (read-only callers
452 /// keep working; the mutating-op refusal is enforced at the brief entry).
453 #[test]
454 fn absent_build_resolves_to_defaults() {
455 let mut binding = v2_binding("m", vec![]);
456 binding.operations.build = None;
457 let r = resolve_binding_run("m/p", &binding).unwrap();
458 assert_eq!(r.mode, BuildMode::Discovery);
459 assert_eq!(r.trigger, IngestTrigger::Loop);
460 assert_eq!(r.batch_size, 20);
461 assert_eq!(r.post_actions, None);
462 }
463
464 /// A graph-typed source always resolves to the graph strategy,
465 /// regardless of any declared value.
466 #[test]
467 fn graph_source_always_uses_graph_strategy() {
468 let root = Path::new("/nonexistent");
469 assert_eq!(
470 resolve_change_strategy(&source("f", MediumType::Graph, "", None), root),
471 ChangeStrategy::Graph
472 );
473 // Even a declared override does not change a graph source.
474 assert_eq!(
475 resolve_change_strategy(&source("f", MediumType::Graph, "", Some("mtime")), root),
476 ChangeStrategy::Graph
477 );
478 }
479
480 /// A `web` source (detection-less per the capability matrix) resolves to
481 /// the visible NoSignal `None` regardless of any declared value —
482 /// `status` renders `signal: none`, never a fabricated `mtime`/`git`
483 /// token.
484 #[test]
485 fn web_source_resolves_to_none_signal() {
486 let root = Path::new("/nonexistent");
487 assert_eq!(
488 resolve_change_strategy(
489 &source("w", MediumType::Web, "https://example.com", None),
490 root
491 ),
492 ChangeStrategy::None
493 );
494 // Even a declared override does not fabricate a signal for web.
495 assert_eq!(
496 resolve_change_strategy(
497 &source("w", MediumType::Web, "https://example.com", Some("mtime")),
498 root
499 ),
500 ChangeStrategy::None
501 );
502 }
503
504 /// A declared `none`/`git`/`mtime` wins for a non-graph source.
505 #[test]
506 fn declared_strategy_wins_for_non_graph() {
507 let root = Path::new("/nonexistent");
508 for (declared, expected) in [
509 ("none", ChangeStrategy::None),
510 ("git", ChangeStrategy::Git),
511 ("mtime", ChangeStrategy::Mtime),
512 ] {
513 assert_eq!(
514 resolve_change_strategy(
515 &source("f", MediumType::Codebase, "x", Some(declared)),
516 root
517 ),
518 expected,
519 "declared '{declared}'"
520 );
521 }
522 }
523
524 /// `auto` (unset, or an unrecognized value) probes the filesystem: a
525 /// pointer under a git work tree → git, otherwise → mtime.
526 #[test]
527 fn auto_probes_for_a_git_work_tree() {
528 let git = tempfile::tempdir().unwrap();
529 std::fs::create_dir(git.path().join(".git")).unwrap();
530 std::fs::create_dir(git.path().join("sub")).unwrap();
531 let plain = tempfile::tempdir().unwrap();
532
533 // Unset → auto → probe. Pointer resolves under the git root → Git.
534 assert_eq!(
535 resolve_change_strategy(&source("f", MediumType::Codebase, "sub", None), git.path()),
536 ChangeStrategy::Git
537 );
538 // An unrecognized declared value also falls through to the probe.
539 assert_eq!(
540 resolve_change_strategy(
541 &source("f", MediumType::Codebase, "sub", Some("weird")),
542 git.path()
543 ),
544 ChangeStrategy::Git
545 );
546 // No git work tree over the pointer → Mtime.
547 assert_eq!(
548 resolve_change_strategy(
549 &source("f", MediumType::Filesystem, ".", None),
550 plain.path()
551 ),
552 ChangeStrategy::Mtime
553 );
554 }
555
556 /// `find_git_root` returns the containing directory of a `.git` entry,
557 /// walking up from a nested start, and `None` when there is none.
558 #[test]
559 fn find_git_root_walks_up() {
560 let root = tempfile::tempdir().unwrap();
561 std::fs::create_dir(root.path().join(".git")).unwrap();
562 let nested = root.path().join("a/b/c");
563 std::fs::create_dir_all(&nested).unwrap();
564
565 assert_eq!(
566 find_git_root(&nested).as_deref(),
567 Some(root.path()),
568 "walks up to the work-tree root"
569 );
570
571 let plain = tempfile::tempdir().unwrap();
572 assert_eq!(find_git_root(plain.path()), None, "no .git anywhere above");
573 }
574}
575
576/// How a destination mem's process mem was resolved: by explicit declaration (`MemConfig.process_mem` on the
577/// destination — wins where present) or by the binding-name
578/// convention (the fallback, byte-identical to the pre-declaration
579/// behaviour). One resolution function for every consumer — the
580/// brief renderer and the open-questions health axis read this and
581/// nothing else, so pairing can never drift between surfaces.
582#[derive(Debug, Clone, PartialEq, Eq)]
583pub struct ProcessMemResolution {
584 /// The resolved process-mem name.
585 pub mem: String,
586 /// Whether that mem is actually mounted.
587 pub mounted: bool,
588 /// True when the name came from the destination's declaration
589 /// rather than the naming convention. A declared-but-unmounted
590 /// resolution is a typed finding for the caller to surface —
591 /// never a silent fallback to derivation.
592 pub declared: bool,
593}
594
595/// The schema family every process mem pins: a declared process mem
596/// must carry an `ingest@*` pin, whatever its version.
597pub const PROCESS_MEM_SCHEMA_NAME: &str = "ingest";
598
599/// The convention-derived process mem name for a binding, the fallback
600/// where the destination declares none. For a single-component
601/// destination it is the binding id itself (`engine/graph`), unchanged
602/// since the convention was set. For a nested destination
603/// (`library/sample`) the id's last separator becomes a hyphen
604/// (`library/sample-notes`): a sibling of the destination in the
605/// same namespace directory, because git keeps refs as files in
606/// directories and cannot hold `library/sample/notes` beside the
607/// branch `library/sample`. The one derivation every consumer uses
608/// (the brief renderer, the open-questions health axis), so the two
609/// cannot pair differently. A malformed id passes through unchanged.
610pub fn derived_process_mem_name(binding_id: &str) -> String {
611 match crate::pipeline_store::parse_binding_id(binding_id) {
612 Some((mem, stem)) if mem.contains('/') => format!("{mem}-{stem}"),
613 _ => binding_id.to_string(),
614 }
615}
616
617/// Resolve the process mem for `destination_mem`. `derived_name` is
618/// the convention-derived candidate ([`derived_process_mem_name`] of
619/// the binding id); pass it even when a declaration might exist — the
620/// declaration wins, the derivation remains the fallback.
621pub fn resolve_process_mem(
622 engine: &crate::Engine,
623 destination_mem: &str,
624 derived_name: &str,
625) -> ProcessMemResolution {
626 let mounted_names = engine.mem_names();
627 if let Some(declared) = engine
628 .mem_config_for(destination_mem)
629 .and_then(|c| c.process_mem.clone())
630 {
631 let mounted = mounted_names.iter().any(|m| *m == declared);
632 return ProcessMemResolution {
633 mem: declared,
634 mounted,
635 declared: true,
636 };
637 }
638 let mounted = mounted_names.contains(&derived_name);
639 ProcessMemResolution {
640 mem: derived_name.to_string(),
641 mounted,
642 declared: false,
643 }
644}