subc-daemon 0.55.0

Embeddable subc daemon: bootstrap, module supervision, and opaque-byte splice routing.
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
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
use super::*;
use crate::operator_apps::dev_builds::TrustedBuilds;
use crate::operator_confirm::{OperatorLimits, OperatorProvider, OperatorWithdraw, ProviderResult};
use crate::FrameSink;
use serde_json::{json, Value};
use subc_os::local_peer::fixture::{SignedAppFixture, SignedPeerFixture};

struct Presence {
    result: ProviderResult,
    prompts: Mutex<Vec<String>>,
}

impl OperatorProvider for Presence {
    fn prompt(
        &self,
        _: &str,
        _: Box<dyn FnOnce(Arc<dyn OperatorWithdraw>) + Send>,
    ) -> ProviderResult {
        panic!("app trust must require interactive presence")
    }

    fn prompt_gate(
        &self,
        text: &str,
        _: Box<dyn FnOnce(Arc<dyn OperatorWithdraw>) + Send>,
    ) -> ProviderResult {
        self.prompts.lock().unwrap().push(text.into());
        self.result.clone()
    }
}

fn handler(result: ProviderResult) -> (ControlHandler, Arc<Presence>) {
    let mut handler = ControlHandler::default();
    handler.operator_app_policy.trusted_builds = Arc::new(TrustedBuilds::memory_for_tests());
    let provider = Arc::new(Presence {
        result,
        prompts: Mutex::default(),
    });
    handler
        .forwarding
        .operator_confirms()
        .configure(provider.clone(), OperatorLimits::default());
    (handler, provider)
}

fn ctx(
    id: u64,
) -> (
    RouteCtx,
    tokio::sync::mpsc::Receiver<crate::router::OutboundFrame>,
) {
    let (tx, rx) = tokio::sync::mpsc::channel(8);
    (
        RouteCtx {
            connection_id: ConnectionId::new(id),
            egress: FrameSink::new(tx),
        },
        rx,
    )
}

fn owner(handler: &ControlHandler, ctx: &RouteCtx) {
    handler.record_local_connection(ctx.connection_id);
    handler.observed_peers.lock().unwrap().insert(
        ctx.connection_id,
        ObservedPeer::observed_uid(subc_os::effective_uid()),
    );
}

async fn request(
    handler: &ControlHandler,
    ctx: &RouteCtx,
    body: Value,
    expected: FrameType,
) -> Value {
    static CORR: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1);
    let frame = Frame::build(
        FrameType::Request,
        control_flags(),
        0,
        0,
        CORR.fetch_add(1, std::sync::atomic::Ordering::Relaxed),
        serde_json::to_vec(&body).unwrap(),
    )
    .unwrap();
    let replies = handler.handle_control_frame(ctx, frame).await.unwrap();
    assert_eq!(replies.len(), 1, "{body}");
    let reply = &replies[0];
    let value: Value = serde_json::from_slice(&reply.body).unwrap();
    assert_eq!(reply.header.ty, expected, "request {body}, reply {value}");
    value
}

fn capture(
    handler: &ControlHandler,
    ctx: &RouteCtx,
    process: &mut SignedPeerFixture,
) -> std::os::unix::net::UnixStream {
    let (socket, peer) = process.connect();
    handler.record_local_connection(ctx.connection_id);
    handler.record_captured_peer(ctx.connection_id, peer);
    socket
}

#[tokio::test]
async fn app_trust_recognizes_only_the_approved_build_and_revokes_new_stamps() {
    let (handler, presence) = handler(ProviderResult::Approved);
    let (owner_ctx, _owner_rx) = ctx(1);
    owner(&handler, &owner_ctx);
    let root = cortexkit_test_support::ScratchDir::new("trusted-operator-app");
    let requester = SignedAppFixture::new(
        &root.join("requester"),
        "net.example.requester",
        Some("1.0.0"),
        true,
        None,
    );
    let mut requester_process = requester.launch();
    let _requester_socket = capture(&handler, &owner_ctx, &mut requester_process);
    let bundle = SignedAppFixture::new(
        &root.join("approved"),
        IDENTIFIER,
        Some("1.2.3"),
        true,
        None,
    );
    let other = SignedAppFixture::new(
        &root.join("different"),
        IDENTIFIER,
        Some("1.2.4"),
        true,
        None,
    );
    let mut process = bundle.launch();
    let mut idle_process = bundle.launch();
    let mut other_process = other.launch();
    let expected_hash = dev_builds::format_hash(
        check_dev_app_bundle(bundle.bundle(), IDENTIFIER)
            .unwrap()
            .cdhash,
    );
    let different_hash = dev_builds::format_hash(
        check_dev_app_bundle(other.bundle(), IDENTIFIER)
            .unwrap()
            .cdhash,
    );
    assert_ne!(expected_hash, different_hash);

    let (unapproved, _rx) = ctx(2);
    let _unapproved_socket = capture(&handler, &unapproved, &mut process);
    let (idle, _rx) = ctx(6);
    let _idle_socket = capture(&handler, &idle, &mut idle_process);
    let describe = json!({"op":"connection.describe"});
    let facts = request(&handler, &unapproved, describe.clone(), FrameType::Response).await;
    assert_eq!(
        facts["dev_build"],
        json!({"status":"untrusted","cdhash":expected_hash})
    );
    assert!(facts.get("operator_app").is_none());
    assert!(
        presence.prompts.lock().unwrap().is_empty(),
        "recognition never prompts"
    );

    let trust = json!({"op":"app.trust","path":bundle.bundle()});
    let reply = request(&handler, &owner_ctx, trust.clone(), FrameType::Response).await;
    assert_eq!(reply["entry"]["cdhash"], expected_hash);
    assert_eq!(reply["entry"]["identifier"], IDENTIFIER);
    assert_eq!(reply["entry"]["version"], "1.2.3");
    assert_eq!(reply["entry"]["build_time"], "2026-11-29T12:00:00Z");
    assert!(reply["entry"]["added_ms"].as_u64().unwrap() > 0);
    assert_eq!(
        request(&handler, &owner_ctx, trust, FrameType::Response).await,
        reply
    );
    let listed = request(
        &handler,
        &owner_ctx,
        json!({"op":"app.trusted"}),
        FrameType::Response,
    )
    .await;
    assert_eq!(listed["entries"], json!([reply["entry"]]));
    for previous in [&unapproved, &idle] {
        let facts = request(&handler, previous, describe.clone(), FrameType::Response).await;
        assert_eq!(
            facts["dev_build"],
            json!({"status":"untrusted","cdhash":expected_hash})
        );
        assert!(facts.get("operator_app").is_none());
    }

    let (approved, _rx) = ctx(3);
    let mut approved_process = bundle.launch();
    let approved_socket = capture(&handler, &approved, &mut approved_process);
    let mut closed = handler
        .forwarding
        .register_connection_close(approved.connection_id);
    let facts = request(&handler, &approved, describe.clone(), FrameType::Response).await;
    assert_eq!(
        facts["operator_app"],
        json!({"app":"alfonso-desktop","pid":approved_process.pid()})
    );
    assert!(facts.get("dev_build").is_none());
    let caps = serde_json::from_value(json!({"provides":["operator-app/v1"]})).unwrap();
    let bind_stamp = handler
        .route_operator_app(approved.connection_id, Some(&caps), "test", "test")
        .await
        .and_then(|candidate| candidate.into_current_stamp())
        .unwrap();
    assert_eq!(
        serde_json::to_value(bind_stamp.app).unwrap(),
        facts["operator_app"]
    );
    assert!(!handler
        .config_desktop_stamps
        .lock()
        .unwrap()
        .contains_key(&approved.connection_id));
    let (also_approved, _rx) = ctx(7);
    let mut also_approved_process = bundle.launch();
    let _also_approved_socket = capture(&handler, &also_approved, &mut also_approved_process);
    let mut also_closed = handler
        .forwarding
        .register_connection_close(also_approved.connection_id);
    let facts = request(
        &handler,
        &also_approved,
        describe.clone(),
        FrameType::Response,
    )
    .await;
    assert_eq!(facts["operator_app"]["pid"], also_approved_process.pid());

    let (different, _rx) = ctx(4);
    let _different_socket = capture(&handler, &different, &mut other_process);
    let mut other_close = handler
        .forwarding
        .register_connection_close(different.connection_id);
    let facts = request(&handler, &different, describe.clone(), FrameType::Response).await;
    assert_eq!(
        facts["dev_build"],
        json!({"status":"untrusted","cdhash":different_hash})
    );
    assert!(facts.get("operator_app").is_none());

    let untrust = json!({"op":"app.untrust","cdhash":expected_hash});
    assert_eq!(
        request(&handler, &owner_ctx, untrust.clone(), FrameType::Response).await["removed"],
        true
    );
    assert_eq!(
        request(&handler, &owner_ctx, untrust, FrameType::Response).await["removed"],
        false
    );
    assert!(handler
        .route_operator_app(approved.connection_id, Some(&caps), "test", "test")
        .await
        .and_then(|candidate| candidate.into_current_stamp())
        .is_none());
    assert!(closed
        .try_recv()
        .unwrap()
        .to_string()
        .starts_with("app_untrusted:"));
    assert!(matches!(
        other_close.try_recv(),
        Err(tokio::sync::oneshot::error::TryRecvError::Empty)
    ));
    assert!(also_closed
        .try_recv()
        .unwrap()
        .to_string()
        .starts_with("app_untrusted:"));
    let revoked_facts = request(&handler, &approved, describe.clone(), FrameType::Response).await;
    assert_eq!(
        revoked_facts["dev_build"],
        json!({"status":"untrusted", "cdhash":expected_hash})
    );
    assert!(revoked_facts.get("operator_app").is_none());
    drop(approved_socket);
    let (revoked, _rx) = ctx(5);
    let _revoked_socket = capture(&handler, &revoked, &mut approved_process);
    let facts = request(&handler, &revoked, describe, FrameType::Response).await;
    assert_eq!(
        facts["dev_build"],
        json!({"status":"untrusted","cdhash":expected_hash})
    );
    assert!(facts.get("operator_app").is_none());
    let prompts = presence.prompts.lock().unwrap();
    assert_eq!(prompts.len(), 1);
    assert!(prompts[0].contains("Alfonso Desktop development build"));
    assert!(prompts[0].contains(&format!("App: {}\n", bundle.bundle().display())));
    assert!(prompts[0].contains(&format!(
        "Requested by: Fixture ({})\n",
        requester.bundle().join("Contents/MacOS/Fixture").display()
    )));
    assert!(prompts[0].contains("Version: 1.2.3"));
    assert!(prompts[0].contains("Build time: 2026-11-29T12:00:00Z"));
    assert!(prompts[0].contains(&format!("Code hash: {}\n", &expected_hash[..16])));
    assert!(prompts[0].contains("Only approve a build you just built or installed."));
}

#[test]
fn app_trust_prompt_abbreviates_home_and_escapes_untrusted_path_text() {
    use std::path::{Path, PathBuf};
    let entry = TrustedAppBuild::new(
        IDENTIFIER.into(),
        "0123456789abcdef".repeat(3),
        "1.0".into(),
        None,
        0,
    );
    let caller = CallerIdentity::from_lookup_result(Some(subc_os::socket_peer::SocketPeer {
        pid: 42,
        executable: PathBuf::from("/Users/test/bin/helper"),
    }));
    let prompt = trust_prompt(
        &entry,
        Path::new("/Users/test/build\nVersion: spoof.app"),
        &caller,
        Some(Path::new("/Users/test")),
    );
    assert!(prompt.starts_with("trust an Alfonso Desktop development build.\n"));
    assert!(prompt
        .contains("\nApp: ~/build\\nVersion: spoof.app\nRequested by: helper (~/bin/helper)\n"));
    assert!(!prompt.contains("/Users/test"));
    assert!(prompt.contains("Code hash: 0123456789abcdef\n"));
}

#[tokio::test]
async fn app_trust_store_failure_is_unavailable_and_later_describe_retries() {
    use std::sync::atomic::Ordering;
    let (handler, presence) = handler(ProviderResult::Approved);
    let (client, _rx) = ctx(1);
    let root = cortexkit_test_support::ScratchDir::new("unavailable-app-store");
    let app = SignedAppFixture::new(&root, IDENTIFIER, Some("1.0.0"), true, None);
    let mut process = app.launch();
    let _socket = capture(&handler, &client, &mut process);
    let store = &handler.operator_app_policy.trusted_builds;
    store.fail_reads.store(true, Ordering::Relaxed);
    let describe = json!({"op":"connection.describe"});
    let facts = request(&handler, &client, describe.clone(), FrameType::Response).await;
    assert_eq!(facts["dev_build"]["status"], "unavailable");
    assert!(facts["dev_build"]["reason"]
        .as_str()
        .unwrap()
        .contains("keychain"));
    assert!(facts.get("operator_app").is_none());
    store.fail_reads.store(false, Ordering::Relaxed);
    let facts = request(&handler, &client, describe, FrameType::Response).await;
    assert_eq!(facts["dev_build"]["status"], "untrusted");
    assert!(presence.prompts.lock().unwrap().is_empty());
}

#[tokio::test]
async fn app_trust_refuses_a_second_request_while_presence_is_open() {
    struct HeldPresence {
        entered: tokio::sync::Notify,
        release: Mutex<std::sync::mpsc::Receiver<()>>,
    }
    impl OperatorProvider for HeldPresence {
        fn prompt(
            &self,
            _: &str,
            _: Box<dyn FnOnce(Arc<dyn OperatorWithdraw>) + Send>,
        ) -> ProviderResult {
            self.entered.notify_one();
            let _ = self.release.lock().unwrap().recv();
            ProviderResult::Declined
        }
    }
    let mut handler = ControlHandler::default();
    handler.operator_app_policy.trusted_builds = Arc::new(TrustedBuilds::memory_for_tests());
    let (release, held) = std::sync::mpsc::channel();
    let presence = Arc::new(HeldPresence {
        entered: tokio::sync::Notify::new(),
        release: Mutex::new(held),
    });
    handler
        .forwarding
        .operator_confirms()
        .configure(presence.clone(), OperatorLimits::default());
    let (first, _rx) = ctx(1);
    let (second, _rx) = ctx(2);
    owner(&handler, &first);
    owner(&handler, &second);
    let root = cortexkit_test_support::ScratchDir::new("single-app-trust-prompt");
    let app = SignedAppFixture::new(&root, IDENTIFIER, Some("1.0.0"), true, None);
    let trust = json!({"op":"app.trust", "path":app.bundle()});
    let (first_reply, ()) =
        tokio::join!(request(&handler, &first, trust, FrameType::Error), async {
            tokio::time::timeout(Duration::from_secs(3), presence.entered.notified())
                .await
                .unwrap();
            // A bogus path distinguishes a busy refusal from beginning another scan.
            let second_reply = request(
                &handler,
                &second,
                json!({"op":"app.trust", "path":"/not-scanned.app"}),
                FrameType::Error,
            )
            .await;
            release.send(()).unwrap();
            assert_eq!(second_reply["code"], "app_trust_busy");
        });
    assert_eq!(first_reply["code"], error_codes::OPERATOR_DECLINED);
}

#[tokio::test]
async fn app_untrust_and_list_do_not_need_a_bundle_scan_slot() {
    let (handler, _) = handler(ProviderResult::Approved);
    let (client, _rx) = ctx(1);
    owner(&handler, &client);
    let store = &handler.operator_app_policy.trusted_builds;
    let hash = "a".repeat(40);
    store
        .add(TrustedAppBuild::new(
            IDENTIFIER.into(),
            hash.clone(),
            "1.0".into(),
            None,
            0,
        ))
        .unwrap();
    let slots = scan_slots(store).clone();
    let _occupied = slots
        .clone()
        .try_acquire_many_owned(slots.available_permits().try_into().unwrap())
        .unwrap();
    let refused = request(
        &handler,
        &client,
        json!({"op":"app.trust", "path":"/not-scanned.app"}),
        FrameType::Error,
    )
    .await;
    assert_eq!(refused["code"], "app_trust_busy");
    let listed = request(
        &handler,
        &client,
        json!({"op":"app.trusted"}),
        FrameType::Response,
    )
    .await;
    assert_eq!(listed["entries"][0]["cdhash"], hash);
    let removed = request(
        &handler,
        &client,
        json!({"op":"app.untrust", "cdhash":hash}),
        FrameType::Response,
    )
    .await;
    assert_eq!(removed["removed"], true);
}

#[tokio::test]
async fn app_trust_decline_does_not_add_the_build() {
    let (handler, presence) = handler(ProviderResult::Declined);
    let (owner_ctx, _rx) = ctx(1);
    owner(&handler, &owner_ctx);
    let root = cortexkit_test_support::ScratchDir::new("declined-operator-app");
    let app = SignedAppFixture::new(&root, IDENTIFIER, Some("1.0.0"), true, None);
    let reply = request(
        &handler,
        &owner_ctx,
        json!({"op":"app.trust","path":app.bundle()}),
        FrameType::Error,
    )
    .await;
    assert_eq!(reply["code"], error_codes::OPERATOR_DECLINED);
    assert_eq!(presence.prompts.lock().unwrap().len(), 1);
    let listed = request(
        &handler,
        &owner_ctx,
        json!({"op":"app.trusted"}),
        FrameType::Response,
    )
    .await;
    assert_eq!(listed["entries"], json!([]));
}

#[tokio::test]
async fn app_trust_refuses_broken_rules_without_prompting() {
    let (handler, presence) = handler(ProviderResult::Approved);
    let (owner_ctx, _rx) = ctx(1);
    owner(&handler, &owner_ctx);
    let root = cortexkit_test_support::ScratchDir::new("ineligible-operator-app");
    for (label, runtime, entitlement, reason) in [
        (
            "debug",
            true,
            Some(("com.apple.security.get-task-allow", true)),
            "get-task-allow",
        ),
        ("no-runtime", false, None, "hardened runtime"),
        ("resource", true, None, "bundle seal is invalid"),
    ] {
        let app = SignedAppFixture::new(
            &root.join(label),
            IDENTIFIER,
            Some("1.0.0"),
            runtime,
            entitlement,
        );
        if label == "resource" {
            std::fs::write(
                app.bundle().join("Contents/Resources/index.html"),
                "changed resource",
            )
            .unwrap();
        }
        let error = request(
            &handler,
            &owner_ctx,
            json!({"op":"app.trust","path":app.bundle()}),
            FrameType::Error,
        )
        .await;
        assert_eq!(error["code"], "app_build_ineligible");
        assert!(
            error["message"].as_str().unwrap().contains(reason),
            "{error}"
        );
        if label == "no-runtime" {
            let mut process = app.launch();
            let (client, _rx) = ctx(2);
            let _socket = capture(&handler, &client, &mut process);
            let facts = request(
                &handler,
                &client,
                json!({"op":"connection.describe"}),
                FrameType::Response,
            )
            .await;
            assert!(facts.get("operator_app").is_none());
            assert_eq!(facts["dev_build"]["status"], "ineligible");
            assert!(facts["dev_build"]["reason"]
                .as_str()
                .unwrap()
                .contains(reason));
        }
    }
    assert!(presence.prompts.lock().unwrap().is_empty());
    let listed = request(
        &handler,
        &owner_ctx,
        json!({"op":"app.trusted"}),
        FrameType::Response,
    )
    .await;
    assert_eq!(listed["entries"], json!([]));
}

#[tokio::test]
async fn app_trusted_ops_require_an_owner_local_connection() {
    let (handler, presence) = handler(ProviderResult::Approved);
    let (client, _rx) = ctx(1);
    for op in [ops::APP_TRUST, ops::APP_TRUSTED, ops::APP_UNTRUST] {
        assert!(super::super::server_describe::subc_ops().contains(&op.to_string()));
        let response = request(&handler, &client, json!({"op":op}), FrameType::Error).await;
        assert_eq!(response["code"], "caller_not_authorized");
    }
    handler.record_local_connection(client.connection_id);
    handler.observed_peers.lock().unwrap().insert(
        client.connection_id,
        ObservedPeer::observed_uid(subc_os::effective_uid().wrapping_add(1)),
    );
    let response = request(
        &handler,
        &client,
        json!({"op":"app.trusted"}),
        FrameType::Error,
    )
    .await;
    assert_eq!(response["code"], "caller_not_authorized");
    assert!(presence.prompts.lock().unwrap().is_empty());
}

#[test]
fn app_trust_store_caps_the_list_without_evicting_existing_builds() {
    let store = TrustedBuilds::memory_for_tests();
    let entry = |index| {
        TrustedAppBuild::new(
            IDENTIFIER.into(),
            format!("{index:040x}"),
            "1.0.0".into(),
            None,
            0,
        )
    };
    for index in 0..64 {
        store.add(entry(index)).unwrap();
    }
    let before = store.list().unwrap();
    assert!(store.add(entry(64)).unwrap_err().contains("64 builds"));
    assert_eq!(store.add(entry(0)).unwrap(), before[0]);
    assert_eq!(store.list().unwrap(), before);
    assert!(store.remove(&entry(0).cdhash).unwrap());
    assert_eq!(store.add(entry(64)).unwrap().cdhash, entry(64).cdhash);
}

#[tokio::test]
async fn app_trust_vectors_match_macos_daemon() {
    use crate::control::app_trust_vectors::{check_daemon_sample, hello_ack_ops};
    use std::sync::atomic::Ordering;

    check_daemon_sample("hello-ack-subc-ops-macos.json", hello_ack_ops());

    let (daemon, presence) = handler(ProviderResult::Declined);
    let (client, _rx) = ctx(1);
    let request_body = json!({"op":"app.trust", "path":"/not-scanned.app"});
    check_daemon_sample(
        "app-trust-caller-not-authorized.json",
        request(&daemon, &client, request_body.clone(), FrameType::Error).await,
    );

    owner(&daemon, &client);
    let store = &daemon.operator_app_policy.trusted_builds;
    {
        let _review = store.approval.try_lock().unwrap();
        check_daemon_sample(
            "app-trust-busy.json",
            request(&daemon, &client, request_body, FrameType::Error).await,
        );
    }

    let root = cortexkit_test_support::ScratchDir::new("app-trust-vectors");
    let wrong_identifier = SignedAppFixture::new(
        &root.join("wrong-identifier"),
        "net.example.ineligible",
        Some("0.1.0"),
        true,
        None,
    );
    check_daemon_sample(
        "app-trust-build-ineligible.json",
        request(
            &daemon,
            &client,
            json!({"op":"app.trust", "path":wrong_identifier.bundle()}),
            FrameType::Error,
        )
        .await,
    );

    let eligible = SignedAppFixture::new(
        &root.join("eligible"),
        IDENTIFIER,
        Some("0.1.0"),
        true,
        None,
    );
    let trust = json!({"op":"app.trust", "path":eligible.bundle()});
    store.fail_reads.store(true, Ordering::Relaxed);
    check_daemon_sample(
        "app-trust-store-unavailable.json",
        request(&daemon, &client, trust.clone(), FrameType::Error).await,
    );
    assert!(presence.prompts.lock().unwrap().is_empty());
    store.fail_reads.store(false, Ordering::Relaxed);
    check_daemon_sample(
        "app-trust-operator-declined.json",
        request(&daemon, &client, trust.clone(), FrameType::Error).await,
    );

    let (no_presence, _) = handler(ProviderResult::NoPresence);
    owner(&no_presence, &client);
    check_daemon_sample(
        "app-trust-no-presence.json",
        request(&no_presence, &client, trust.clone(), FrameType::Error).await,
    );

    struct HeldPrompt(Mutex<std::sync::mpsc::Receiver<()>>);
    impl OperatorProvider for HeldPrompt {
        fn prompt(
            &self,
            _: &str,
            _: Box<dyn FnOnce(Arc<dyn OperatorWithdraw>) + Send>,
        ) -> ProviderResult {
            let _ = self.0.lock().unwrap().recv();
            ProviderResult::Declined
        }
    }
    // Keep the provider from answering until after the daemon's deadline.
    let (release, held) = std::sync::mpsc::channel();
    let (timing_out, _) = handler(ProviderResult::Declined);
    timing_out.forwarding.operator_confirms().configure(
        Arc::new(HeldPrompt(Mutex::new(held))),
        OperatorLimits {
            prompt_timeout: Duration::from_millis(10),
            ..OperatorLimits::default()
        },
    );
    owner(&timing_out, &client);
    let timed_out = tokio::time::timeout(
        Duration::from_secs(4),
        request(&timing_out, &client, trust, FrameType::Error),
    )
    .await
    .expect("daemon must reply while the presence provider is still blocked");
    drop(release);
    check_daemon_sample("app-trust-timeout.json", timed_out);
}