lean-ctx-cloud 3.12.13

The LeanCTX connector: enrollment, bus, knowledge sync, tasks and policy on top of LeanCTX | OSS.
Documentation
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
// SPDX-License-Identifier: Apache-2.0
//! Local vault resolutions that no longer fit their checkout (dogfood
//! 5.11.: one repository split across two vaults without a warning).
//!
//! `projects.json` ([`VaultMap`]) remembers which vault Cloud resolved for a
//! checkout. That memory goes stale when
//! - the link file now names another vault (`cloud link` after `cloud
//!   connect`, or a pulled commit that changed `.lean-ctx-cloud.json`), or
//! - the checkout's identity changed: a `.lean-ctx-id` that an earlier
//!   `cloud link` wrote (32 random hex characters) no longer outranks the git
//!   origin ([`crate::vault::project_identity`]), so every checkout of one
//!   origin is one repository again.
//!
//! A stale record is never used: it is dropped, and the next resolve maps
//! the checkout again (with the person's first-share consent where the gate
//! holds). When Cloud still answers with another vault than the link file
//! names, the resolve is refused ([`refuse_unlinked`]): nothing syncs into
//! a vault the link file does not name.

use std::path::Path;

use lean_ctx::core::pathutil::same_project;
use lean_ctx_protocol::cloud::status::CloudStatusVaultMismatchV1;
use lean_ctx_protocol::cloud::vault::{VaultRefV1, stable_identity};

use super::CloudError;
use super::link::read_link;
use super::state::CloudStore;
use super::vault::{VaultMap, VaultRecord, project_identity};

/// Why a recorded resolution does not fit the checkout any more.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum StaleReason {
    /// The link file names `linked` (`ns/name`).
    Link { linked: String },
    /// The checkout's identity is not the one the record was resolved for.
    Identity,
}

/// A resolution of `root` to `resolved` (`ns/name`) that does not hold.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Stale {
    pub root: String,
    pub resolved: String,
    pub reason: StaleReason,
}

impl Stale {
    /// The linked vault, when the link file is the reason.
    pub fn linked(&self) -> Option<&str> {
        match &self.reason {
            StaleReason::Link { linked } => Some(linked),
            StaleReason::Identity => None,
        }
    }

    /// `vault_mismatch` of `cloud status --json`.
    pub fn wire(&self) -> CloudStatusVaultMismatchV1 {
        CloudStatusVaultMismatchV1 {
            project_root: self.root.clone(),
            resolved: self.resolved.clone(),
            linked: self.linked().map(str::to_string),
            reason: match self.reason {
                StaleReason::Link { .. } => "link",
                StaleReason::Identity => "identity",
            }
            .into(),
        }
    }

    /// One line for people (status, connect, link, sync).
    pub fn describe(&self) -> String {
        match &self.reason {
            StaleReason::Link { linked } => format!(
                "this machine resolved {} to the vault {}, but its link file names {linked}",
                self.root, self.resolved
            ),
            StaleReason::Identity => format!(
                "this machine resolved {} to the vault {} under an identity the checkout no longer has (a `.lean-ctx-id` written by an earlier `cloud link`; the git origin counts now)",
                self.root, self.resolved
            ),
        }
    }
}

fn address(record: &VaultRecord) -> String {
    format!("{}/{}", record.ns, record.name)
}

/// The record `root` uses (its own, or its main checkout's), its key and
/// the recorded root it was found by.
fn recorded<'a>(map: &'a VaultMap, root: &Path) -> Option<(&'a str, &'a VaultRecord, String)> {
    let find = |root: &str| {
        map.vaults.iter().find_map(|(key, record)| {
            record
                .roots
                .iter()
                .find(|known| same_project(known, root))
                .map(|known| (key.as_str(), record, known.clone()))
        })
    };
    let root_str = root.to_string_lossy();
    find(&root_str).or_else(|| {
        let main = super::link::main_worktree_root(root)?;
        find(&main.to_string_lossy())
    })
}

/// Whether the recorded resolution of `root` is stale. Local files only;
/// changes nothing.
pub fn stale_for_root(map: &VaultMap, root: &Path) -> Option<Stale> {
    let (key, record, _) = recorded(map, root)?;
    let resolved = address(record);
    let stale = |reason| Stale {
        root: root.to_string_lossy().into_owned(),
        resolved: resolved.clone(),
        reason,
    };
    // A damaged link file is refused where the link is used; here it says
    // nothing about the record.
    if let Ok(Some(link)) = read_link(root)
        && (link.vault.ns != record.ns || link.vault.name != record.name)
    {
        return Some(stale(StaleReason::Link {
            linked: format!("{}/{}", link.vault.ns, link.vault.name),
        }));
    }
    let current = project_identity(root).map(|identity| stable_identity(&identity));
    if current.is_some_and(|current| current != key) {
        return Some(stale(StaleReason::Identity));
    }
    None
}

/// Drop the stale resolution of `root` from `map`, if any. A link file that
/// names another vault drops the whole record: one identity has one vault,
/// so every checkout of it resolves again. An identity change drops only
/// this checkout from the record of its old identity.
pub fn forget_stale(map: &mut VaultMap, root: &Path) -> Option<Stale> {
    let stale = stale_for_root(map, root)?;
    let (key, _, known) = recorded(map, root)?;
    let key = key.to_string();
    match stale.reason {
        StaleReason::Link { .. } => {
            map.vaults.remove(&key);
        }
        StaleReason::Identity => {
            if let Some(record) = map.vaults.get_mut(&key) {
                record.roots.retain(|r| r != &known);
                if record.roots.is_empty() {
                    map.vaults.remove(&key);
                }
            }
        }
    }
    Some(stale)
}

/// [`forget_stale`] for every checkout `map` knows.
pub fn forget_all_stale(map: &mut VaultMap) -> Vec<Stale> {
    let roots: Vec<String> = map
        .vaults
        .values()
        .flat_map(|record| record.roots.iter().cloned())
        .collect();
    roots
        .iter()
        .filter_map(|root| forget_stale(map, Path::new(root)))
        .collect()
}

/// The vault map at `data_dir` without stale resolutions, as `scope` (the
/// connected Cloud and account, [`crate::vault::vault_scope`]; `None` when
/// not connected) sees it; the file is rewritten when one was dropped. What
/// every pass that sends (sync, task proposals) reads, so none sends into a
/// vault the checkout left, nor one of another Cloud or account (rc3-81,
/// bd 39540: a pass during `cloud connect` elsewhere sends nothing).
pub fn load_current(
    data_dir: &Path,
    scope: Option<&str>,
) -> Result<(VaultMap, Vec<Stale>), CloudError> {
    let (dropped, map) = super::vault::update_map(data_dir, forget_all_stale)?;
    for stale in &dropped {
        tracing::info!(
            "cloud: dropped a stale vault resolution: {}",
            stale.describe()
        );
    }
    Ok((super::vault::in_scope(map, scope), dropped))
}

/// Drop the stale resolution of `root` in the map at `data_dir`.
pub fn forget_stale_at(data_dir: &Path, root: &Path) -> Result<Option<Stale>, CloudError> {
    super::vault::update_map(data_dir, |map| forget_stale(map, root)).map(|(stale, _)| stale)
}

/// The vault the checkout at `root` sends to, from the map of `store` as
/// the connected Cloud and account see it (rc3-81): `None` when it has none
/// (or only one of another Cloud or account), refused (`vault_mismatch`)
/// when its record is stale. The one lookup of every caller that writes to a vault (tasks, bus
/// posts and leases, docs, the live bus), so a record the link file or the
/// identity no longer backs is never written to, also before link, connect
/// or sync dropped it (a `git pull` that changed the link file).
pub fn vault_for_root(store: &CloudStore, root: &Path) -> Result<Option<VaultRecord>, CloudError> {
    // A folder the person stopped sharing (`cloud unlink`) has no vault,
    // also not through its main checkout or another checkout (rc4-6).
    if crate::unlinked::contains(store.data_dir(), root) {
        return Ok(None);
    }
    vault_in(&super::vault::connected_map(store), root).map(Option::<&VaultRecord>::cloned)
}

/// The map at `data_dir` without its stale records, the file unchanged, as
/// `scope` sees it (see [`load_current`]): what the live bus subscribes and
/// announces from, so it never joins a vault a checkout left, nor one of
/// another Cloud or account.
pub fn current_view(data_dir: &Path, scope: Option<&str>) -> VaultMap {
    let mut map = super::vault::in_scope(VaultMap::load(data_dir), scope);
    forget_all_stale(&mut map);
    map
}

/// [`vault_for_root`] in a loaded `map`.
pub fn vault_in<'a>(map: &'a VaultMap, root: &Path) -> Result<Option<&'a VaultRecord>, CloudError> {
    if let Some(stale) = stale_for_root(map, root) {
        return Err(refuse_stale(&stale));
    }
    Ok(map.for_root(&root.to_string_lossy()))
}

/// Refused (`vault_mismatch`) when `record`, which a caller is about to
/// sync for the checkout at `root`, is not what the checkout resolves to
/// now: its link file names another vault, or the map's record of `root`
/// at `data_dir` is stale, or the map there belongs to another Cloud or
/// account than `scope` (the session's, [`crate::vault::vault_scope`]) now
/// (rc3-81, bd 39540). The guard of every vault sync (background pass and
/// `cloud sync`), whatever map snapshot the caller planned from.
pub fn refuse_stale_record(
    data_dir: &Path,
    scope: &str,
    record: &VaultRecord,
    root: &Path,
) -> Result<(), CloudError> {
    if let Ok(Some(link)) = read_link(root)
        && (link.vault.ns != record.ns || link.vault.name != record.name)
    {
        return Err(refuse_stale(&Stale {
            root: root.to_string_lossy().into_owned(),
            resolved: address(record),
            reason: StaleReason::Link {
                linked: format!("{}/{}", link.vault.ns, link.vault.name),
            },
        }));
    }
    let map = VaultMap::load(data_dir);
    if !map.belongs_to(scope) {
        return Err(CloudError::Local(
            "this machine's vault records belong to another Cloud or account now; nothing was synced"
                .into(),
        ));
    }
    match stale_for_root(&map, root) {
        Some(stale) => Err(refuse_stale(&stale)),
        None => Ok(()),
    }
}

/// The refusal for a write into the stale resolution `stale`.
pub fn refuse_stale(stale: &Stale) -> CloudError {
    CloudError::Refused(format!(
        "vault_mismatch: {}. Nothing is sent to {} any more: run `lean-ctx cloud connect` here to resolve the project again",
        stale.describe(),
        stale.resolved
    ))
}

/// Cloud answered `answered` for the checkout at `root`: refused when its
/// link file names another vault. Cloud keeps the first binding of an
/// identity (another Instance of the workspace may have made it), so a
/// link to another vault cannot move it; syncing anyway would split the
/// repository silently.
pub fn refuse_unlinked(root: &Path, answered: &VaultRefV1) -> Result<(), CloudError> {
    let Some(link) = read_link(root)? else {
        return Ok(());
    };
    if link.vault == *answered {
        return Ok(());
    }
    Err(CloudError::Refused(format!(
        "vault_mismatch: the Cloud keeps this repository in the vault {}/{} (bound there first, possibly by another Instance of the workspace), but {} names {}/{}. Nothing syncs for it until both agree: run `lean-ctx cloud link {}/{}` here, or move the repository to {}/{} in the Cloud and run `lean-ctx cloud connect` again",
        answered.ns,
        answered.name,
        super::link::LINK_FILE,
        link.vault.ns,
        link.vault.name,
        answered.ns,
        answered.name,
        link.vault.ns,
        link.vault.name,
    )))
}

#[cfg(test)]
mod tests {
    use super::*;

    fn checkout(base: &Path, name: &str, origin: Option<&str>) -> std::path::PathBuf {
        let root = base.join(name);
        std::fs::create_dir_all(root.join(".git")).unwrap();
        let config = origin.map_or(String::new(), |url| {
            format!("[remote \"origin\"]\n\turl = {url}\n")
        });
        std::fs::write(root.join(".git/config"), config).unwrap();
        root
    }

    fn record(map: &mut VaultMap, key: &str, vault: &str, roots: &[&Path]) {
        let (ns, name) = vault.split_once('/').unwrap();
        map.vaults.insert(
            key.into(),
            VaultRecord {
                vault_id: format!("id-{name}"),
                ns: ns.into(),
                name: name.into(),
                sealed: false,
                roots: roots
                    .iter()
                    .map(|r| r.to_string_lossy().into_owned())
                    .collect(),
            },
        );
    }

    fn stable(root: &Path) -> String {
        stable_identity(&project_identity(root).unwrap())
    }

    /// The scope of the connected Cloud and account in these tests.
    const HERE: &str = "https://cloud.example#org=org_a";

    /// rc3-81 bd 39540 M1: a map stamped for another Cloud or account
    /// (a `cloud connect` elsewhere while a pass runs) gives no sender a
    /// vault: not the pass that sends (`load_current`), not the lookup of
    /// tasks, bus and docs (`vault_for_root`), not the live bus
    /// (`current_view`), not the guard of every vault sync.
    #[test]
    fn vault_origin_a_map_of_another_scope_gives_no_sender_a_vault() {
        let base = tempfile::tempdir().unwrap();
        let store = CloudStore::at(base.path().join("config"), base.path().join("data"));
        std::fs::create_dir_all(store.data_dir()).unwrap();
        let a = checkout(base.path(), "a", Some("https://github.com/acme/pay.git"));
        let mut map = VaultMap::default();
        record(&mut map, &stable(&a), "acme/pay", &[&a]);
        map.origin = Some(crate::vault::vault_scope("https://cloud.example", "org_b"));
        map.save(store.data_dir()).unwrap();
        let planned = map.vaults.values().next().unwrap().clone();
        let enroll = |org: &str| {
            store
                .write_config(
                    crate::state::INSTANCE_FILE,
                    &crate::state::InstanceRecord {
                        instance_id: "inst_a".into(),
                        org_id: org.into(),
                        org_name: "Acme".into(),
                        label: "mac".into(),
                        url: "https://cloud.example".into(),
                        org_salt_id: "salt".into(),
                        enrolled_at: "2026-10-24T00:00:00Z".into(),
                        web_url: None,
                        org_kind: None,
                        company_name: None,
                    },
                )
                .unwrap();
        };
        enroll("org_a");
        assert_eq!(crate::vault::connected_scope(&store).as_deref(), Some(HERE));
        let data = store.data_dir();
        let (current, _) = load_current(data, Some(HERE)).unwrap();
        assert!(current.vaults.is_empty(), "the sending pass sees nothing");
        assert_eq!(vault_for_root(&store, &a).unwrap(), None);
        assert!(current_view(data, Some(HERE)).vaults.is_empty());
        let refused = refuse_stale_record(data, HERE, &planned, &a).unwrap_err();
        assert!(
            refused.to_string().contains("another Cloud or account"),
            "{refused}"
        );
        assert_eq!(
            VaultMap::load(data).vaults.len(),
            1,
            "kept on disk for its own account"
        );

        // A switch to another account removes the local Cloud data of the
        // one before (3.12.8 account scope): the map does not come back
        // for the account it was stamped for (rc3-81's restore after the
        // return no longer holds).
        enroll("org_b");
        let there = crate::vault::vault_scope("https://cloud.example", "org_b");
        assert_eq!(crate::vault::connected_scope(&store), Some(there.clone()));
        assert_eq!(vault_for_root(&store, &a).unwrap(), None);
        assert!(
            load_current(data, Some(&there))
                .unwrap()
                .0
                .vaults
                .is_empty()
        );
        assert!(
            VaultMap::load(data).vaults.is_empty(),
            "gone after the switch"
        );
    }

    /// rc3-81 bd 39540 S-a, bd 39791 S1: a refused link puts back only the
    /// records of its checkout, and only while the map still belongs to the
    /// scope it was read for.
    #[test]
    fn vault_origin_restore_keeps_a_newer_map_of_another_scope() {
        let data = tempfile::tempdir().unwrap();
        let base = tempfile::tempdir().unwrap();
        let (a, b) = (
            checkout(base.path(), "a", None),
            checkout(base.path(), "b", None),
        );
        let a_text = a.to_string_lossy().into_owned();
        let mut snapshot = VaultMap::default();
        record(&mut snapshot, "s1", "acme/pay", &[&a]);
        record(&mut snapshot, "s2", "acme/old", &[&b]);

        // Meanwhile: a was moved to another vault, b linked anew, map
        // stamped. Only a's record comes back; b's newer state stays.
        let mut changed = VaultMap {
            origin: Some(HERE.into()),
            ..Default::default()
        };
        record(&mut changed, "s9", "acme/new", &[&a]);
        record(&mut changed, "s3", "acme/shop", &[&b]);
        changed.save(data.path()).unwrap();
        assert!(crate::vault::restore_root(data.path(), &snapshot, &a_text, HERE).unwrap());
        let map = VaultMap::load(data.path());
        assert_eq!(map.origin.as_deref(), Some(HERE));
        assert_eq!(map.for_root(&a_text).map(|r| r.name.as_str()), Some("pay"));
        assert!(!map.vaults.contains_key("s9"), "a's later record left");
        assert!(map.vaults.contains_key("s3") && !map.vaults.contains_key("s2"));

        // An enrollment elsewhere switched the map: it stays as it is.
        let elsewhere = VaultMap {
            origin: Some(crate::vault::vault_scope("https://cloud.example", "org_b")),
            ..Default::default()
        };
        elsewhere.save(data.path()).unwrap();
        assert!(!crate::vault::restore_root(data.path(), &snapshot, &a_text, HERE).unwrap());
        assert_eq!(VaultMap::load(data.path()), elsewhere);
    }

    /// The guard of `place::sync_vault`: a record planned from an older map
    /// is refused once the link file names another vault, also when the map
    /// on disk no longer has it.
    #[test]
    fn a_sync_of_a_record_the_link_file_left_is_refused() {
        let base = tempfile::tempdir().unwrap();
        let data = base.path().join("data");
        std::fs::create_dir_all(&data).unwrap();
        let a = checkout(
            base.path(),
            "a",
            Some("git@github.com:yves/leanctx-cloud.git"),
        );
        let mut map = VaultMap::default();
        record(&mut map, &stable(&a), "yves/cloud", &[&a]);
        map.save(&data).unwrap();
        let planned = map.vaults.values().next().unwrap().clone();
        crate::link::link(&a, "yves/cloud").unwrap();
        assert!(refuse_stale_record(&data, HERE, &planned, &a).is_ok());

        crate::link::link(&a, "yves/leanctx-cloud").unwrap();
        let refused = refuse_stale_record(&data, HERE, &planned, &a).unwrap_err();
        assert!(refused.to_string().contains("vault_mismatch"), "{refused}");
        VaultMap::default().save(&data).unwrap();
        assert!(refuse_stale_record(&data, HERE, &planned, &a).is_err());
    }

    #[test]
    fn a_link_that_names_another_vault_drops_the_whole_record() {
        let base = tempfile::tempdir().unwrap();
        let a = checkout(
            base.path(),
            "a",
            Some("git@github.com:yves/leanctx-cloud.git"),
        );
        let b = checkout(
            base.path(),
            "b",
            Some("git@github.com:yves/leanctx-cloud.git"),
        );
        let mut map = VaultMap::default();
        record(&mut map, &stable(&a), "yves/cloud", &[&a, &b]);
        assert_eq!(
            stale_for_root(&map, &a),
            None,
            "no link file: nothing to compare"
        );

        super::super::link::link(&a, "yves/leanctx-cloud").unwrap();
        let stale = stale_for_root(&map, &a).expect("stale");
        assert_eq!(stale.resolved, "yves/cloud");
        assert_eq!(stale.linked(), Some("yves/leanctx-cloud"));
        assert!(
            stale
                .describe()
                .contains("link file names yves/leanctx-cloud")
        );
        assert_eq!(forget_stale(&mut map, &a), Some(stale));
        assert!(map.vaults.is_empty(), "b is the same repository");
        assert!(map.for_root(&b.to_string_lossy()).is_none());
    }

    #[test]
    fn an_identity_change_drops_only_that_checkout() {
        let base = tempfile::tempdir().unwrap();
        let a = checkout(base.path(), "a", Some("https://github.com/acme/pay.git"));
        let mut map = VaultMap::default();
        record(&mut map, "old-random-identity", "acme/pay", &[&a]);
        let other = base.path().join("elsewhere");
        record(&mut map, &stable(&a), "acme/pay", &[&other]);
        let stale = forget_stale(&mut map, &a).expect("stale");
        assert_eq!(stale.reason, StaleReason::Identity);
        assert!(!map.vaults.contains_key("old-random-identity"));
        assert!(map.vaults.contains_key(&stable(&a)));
        assert_eq!(forget_stale(&mut map, &a), None);
    }

    #[test]
    fn load_current_rewrites_the_map_once() {
        let base = tempfile::tempdir().unwrap();
        let data = base.path().join("data");
        std::fs::create_dir_all(&data).unwrap();
        let a = checkout(base.path(), "a", Some("https://github.com/acme/pay.git"));
        let mut map = VaultMap::default();
        record(&mut map, &stable(&a), "acme/old", &[&a]);
        map.save(&data).unwrap();
        super::super::link::link(&a, "acme/pay").unwrap();
        let (map, dropped) = load_current(&data, None).unwrap();
        assert_eq!(dropped.len(), 1);
        assert!(map.vaults.is_empty());
        assert!(VaultMap::load(&data).vaults.is_empty(), "saved");
        assert!(load_current(&data, None).unwrap().1.is_empty());
    }

    #[test]
    fn cloud_answering_another_vault_than_the_link_is_refused() {
        let base = tempfile::tempdir().unwrap();
        let a = checkout(base.path(), "a", Some("https://github.com/acme/pay.git"));
        let answered = VaultRefV1 {
            ns: "acme".into(),
            name: "old".into(),
        };
        assert!(
            refuse_unlinked(&a, &answered).is_ok(),
            "no link: the Cloud decides"
        );
        super::super::link::link(&a, "acme/pay").unwrap();
        let refused = refuse_unlinked(&a, &answered).unwrap_err().to_string();
        assert!(refused.contains("vault_mismatch"), "{refused}");
        assert!(
            refused.contains("acme/old") && refused.contains("acme/pay"),
            "{refused}"
        );
        let linked = VaultRefV1 {
            ns: "acme".into(),
            name: "pay".into(),
        };
        assert!(refuse_unlinked(&a, &linked).is_ok());
    }
}