pitboard-core 0.19.0

The engine behind Pitboard: switches Claude Code, Codex and Claude Desktop between accounts by parking and restoring their logins. Its API serves Pitboard's own front ends.
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
705
706
use super::*;

fn at(percent: u8) -> crate::watch_service::Switching {
    crate::watch_service::Switching::At(crate::duty::autoswitch::Policy {
        threshold: crate::duty::autoswitch::Threshold::new(percent).expect("a share"),
        order: crate::usage::Order::MostLeft,
    })
}

#[test]
fn a_schedule_is_judged_by_whether_the_pitboard_it_runs_is_still_there() {
    let mut f = facts();
    assert!(
        evaluate(&f).iter().all(|c| c.code != "schedule"),
        "nothing is said where there is no schedule"
    );

    f.schedule = Some(ScheduleFact {
        location: Location::File(PathBuf::from(
            "/home/x/Library/LaunchAgents/com.datlechin.pitboard.renew.plist",
        )),
        task: None,
        program: Some(PathBuf::from("/opt/homebrew/bin/pitboard")),
        program_found: true,
        network: direct(),
        network_differs: false,
        outdated: false,
        refused: None,
    });
    let checks = evaluate(&f);
    let found = check(&checks, "schedule");
    assert_eq!(found.level, Level::Ok);
    assert_eq!(
        found.detail,
        words::runs_daily("/opt/homebrew/bin/pitboard")
    );

    f.schedule.as_mut().expect("set above").program_found = false;
    let checks = evaluate(&f);
    let gone = check(&checks, "schedule");
    assert_eq!(gone.level, Level::Fail, "every renewal from now on fails");
    assert_eq!(
        gone.detail,
        words::runs_what_is_gone("/opt/homebrew/bin/pitboard")
    );
    assert_eq!(gone.advice, again(crate::host::OS));

    f.schedule = Some(ScheduleFact {
        location: Location::File(PathBuf::from(
            "/home/x/Library/LaunchAgents/com.datlechin.pitboard.renew.plist",
        )),
        task: None,
        program: Some(PathBuf::from(
            "/Applications/Pitboard.app/Contents/MacOS/Pitboard",
        )),
        program_found: true,
        network: direct(),
        network_differs: false,
        outdated: false,
        refused: None,
    });
    f.os = Os::MacOs;
    let checks = evaluate(&f);
    let the_app = check(&checks, "schedule");
    assert_eq!(
        the_app.level,
        Level::Fail,
        "0.3.0's app renews nothing when started with `renew`"
    );
    assert_eq!(
        the_app.detail,
        words::runs_the_app("/Applications/Pitboard.app/Contents/MacOS/Pitboard")
    );
    f.schedule.as_mut().expect("set above").program = Some(PathBuf::from(
        "/Applications/Pitboard.app/Contents/Helpers/pitboard",
    ));
    assert_eq!(
        check(&evaluate(&f), "schedule").level,
        Level::Ok,
        "the command line an app comes with is a command line"
    );
    f.os = Os::Linux;
    for (program, level) in [
        ("/usr/bin/pitboard-app", Level::Fail),
        ("/usr/bin/pitboard", Level::Ok),
    ] {
        f.schedule.as_mut().expect("set above").program = Some(PathBuf::from(program));
        assert_eq!(check(&evaluate(&f), "schedule").level, level, "{program}");
    }
    f.os = crate::host::OS;

    f.schedule.as_mut().expect("set above").program = None;
    let checks = evaluate(&f);
    let unread = check(&checks, "schedule");
    assert_eq!(unread.level, Level::Warn);
    assert_eq!(
        (unread.detail.clone(), unread.advice.as_str()),
        (
            words::does_not_say_which_pitboard(&f.schedule.as_ref().expect("set above").location),
            again(crate::host::OS)
        )
    );
}

#[test]
fn the_watch_service_is_judged_by_its_pitboard_and_its_last_run() {
    let mut f = facts();
    assert!(
        evaluate(&f).iter().all(|c| c.code != "watch_service"),
        "nothing is said where there is no service"
    );
    let service = |program: Option<&str>, task: Option<Task>| WatchServiceFact {
        location: Location::File(PathBuf::from(
            "/home/x/Library/LaunchAgents/com.datlechin.pitboard.watch.plist",
        )),
        program: program.map(PathBuf::from),
        program_found: true,
        switching: Some(at(90)),
        task,
        outdated: false,
        refused: None,
    };

    f.watch_service = Some(service(Some("/opt/homebrew/bin/pitboard"), None));
    let checks = evaluate(&f);
    let found = check(&checks, "watch_service");
    assert_eq!(found.level, Level::Ok);
    assert_eq!(
        found.detail,
        words::runs_from_sign_in(Some(at(90)), "/opt/homebrew/bin/pitboard")
    );
    assert_eq!(found.name, "watch service");
    assert_eq!(section("watch_service"), None, "Pitboard's own");

    f.watch_service.as_mut().expect("set above").program_found = false;
    let checks = evaluate(&f);
    let gone = check(&checks, "watch_service");
    assert_eq!(gone.level, Level::Fail, "it switches nothing from now on");
    assert_eq!(gone.advice, words::INSTALL_THE_SERVICE_AGAIN);

    f.watch_service = Some(service(None, None));
    assert_eq!(check(&evaluate(&f), "watch_service").level, Level::Warn);

    let ran = Task {
        last_run: Some(NOW - 60),
        last_result: Some(1),
        drifted: Vec::new(),
    };
    f.watch_service = Some(service(Some(r"C:\bin\pitboard.exe"), Some(ran)));
    let checks = evaluate(&f);
    let failed = check(&checks, "watch_service");
    assert_eq!(failed.level, Level::Warn);
    assert_eq!(
        (failed.detail.clone(), failed.advice.as_str()),
        (
            words::last_run_ended(
                &words::runs_from_sign_in(Some(at(90)), r"C:\bin\pitboard.exe"),
                None,
                1
            ),
            words::WATCH_TO_SEE_WHY
        )
    );
}

#[test]
fn a_task_is_judged_by_its_settings_and_its_last_run() {
    let mut f = facts();
    f.os = Os::Windows;
    let program = r"C:\Users\x\scoop\apps\pitboard\current\pitboard.exe";
    let task = |last_run: Option<i64>, last_result: i32, drifted: Vec<Drift>| ScheduleFact {
        location: Location::Task(r"\Pitboard\Renew S-1-5-21-1".into()),
        task: Some(Task {
            last_run,
            last_result: Some(last_result),
            drifted,
        }),
        program: Some(PathBuf::from(program)),
        program_found: true,
        network: direct(),
        network_differs: false,
        outdated: false,
        refused: None,
    };
    let judged = |f: &Facts| {
        evaluate(f)
            .into_iter()
            .find(|c| c.code == "schedule")
            .expect("the schedule's line")
    };

    f.schedule = Some(task(None, 0x0004_1303, Vec::new()));
    let fresh = judged(&f);
    assert_eq!(fresh.level, Level::Ok);
    let runs = words::runs_daily(program);
    assert_eq!(fresh.detail, words::not_run_yet(&runs));

    let an_hour_ago = Some(f.now - 3_660);
    for fine in [0, 0x0004_1301] {
        f.schedule = Some(task(an_hour_ago, fine, Vec::new()));
        let ran = judged(&f);
        assert_eq!(ran.level, Level::Ok, "{fine:#x}");
        assert_eq!(ran.detail, words::last_ran(&runs, 3_660));
    }

    for result in [1, 0x8007_10E0_u32 as i32] {
        f.schedule = Some(task(an_hour_ago, result, Vec::new()));
        let failed = judged(&f);
        assert_eq!(failed.level, Level::Warn);
        assert_eq!(
            (failed.detail, failed.advice.as_str()),
            (
                words::last_run_ended(&runs, Some(3_660), result),
                words::RENEW_TO_SEE_WHY
            )
        );
    }

    f.schedule = Some(task(
        an_hour_ago,
        0,
        vec![Drift::OnAcPowerOnly, Drift::Disabled],
    ));
    let drifted = judged(&f);
    assert_eq!(drifted.level, Level::Warn);
    assert_eq!(
        drifted.detail,
        words::drifted_in_task_scheduler(
            &runs,
            &[
                words::drift(&Drift::OnAcPowerOnly),
                words::drift(&Drift::Disabled)
            ]
        )
    );
    assert_eq!(drifted.advice, again(Os::Windows));
}

/// A timer an earlier Pitboard wrote counts only time awake, and a service it wrote fails
/// once its Pitboard is gone, which installing again mends. Read from the disk on Linux, the
/// one system whose jobs say so.
#[test]
fn a_unit_an_earlier_pitboard_wrote_is_said_by_doctor() {
    let mut f = facts();
    let program = "/usr/local/bin/pitboard";
    f.schedule = Some(ScheduleFact {
        outdated: true,
        refused: None,
        ..scheduled(direct(), false)
    });
    f.watch_service = Some(WatchServiceFact {
        location: Location::File(PathBuf::from(
            "/home/x/.config/systemd/user/pitboard-watch.service",
        )),
        program: Some(PathBuf::from(program)),
        program_found: true,
        switching: None,
        task: None,
        outdated: true,
        refused: None,
    });
    let checks = evaluate(&f);
    let renewal = check(&checks, "schedule");
    assert_eq!(
        (
            renewal.level,
            renewal.detail.clone(),
            renewal.advice.as_str()
        ),
        (
            Level::Warn,
            words::renews_by_time_awake(&words::runs_daily(program)),
            again(f.os)
        )
    );
    let watch = check(&checks, "watch_service");
    assert_eq!(
        (watch.level, watch.detail.clone(), watch.advice.as_str()),
        (
            Level::Warn,
            words::fails_once_its_pitboard_is_gone(&words::runs_from_sign_in(None, program)),
            words::INSTALL_THE_SERVICE_AGAIN
        )
    );
    f.schedule.as_mut().expect("set above").program_found = false;
    assert_eq!(
        check(&evaluate(&f), "schedule").level,
        Level::Fail,
        "a Pitboard gone is said first"
    );

    #[cfg(target_os = "linux")]
    {
        let scratch = tempfile::tempdir().expect("a scratch home");
        let home = scratch.path().to_path_buf();
        let program = home.join("bin/pitboard");
        std::fs::create_dir_all(program.parent().expect("its folder")).expect("a bin");
        std::fs::write(&program, "").expect("a Pitboard");
        let ctx = Context::new(home.clone())
            .with_memory_stores(crate::host::memory::MemoryHost::new())
            .with_schedule_program(program.clone());
        let units = home.join(".config/systemd/user");
        std::fs::create_dir_all(&units).expect("made");
        for (file, body) in [
            (
                "pitboard-renew.timer",
                "[Timer]\nOnUnitActiveSec=86400\nOnStartupSec=900\nPersistent=true\n".to_string(),
            ),
            (
                "pitboard-renew.service",
                format!(
                    "[Service]\nType=oneshot\nExecStart={} renew --scheduled\n",
                    program.display()
                ),
            ),
            (
                "pitboard-watch.service",
                format!(
                    "[Service]\nExecStart={} watch --scheduled --at 90\n",
                    program.display()
                ),
            ),
        ] {
            std::fs::write(units.join(file), body).expect("as an earlier Pitboard wrote it");
        }
        assert!(schedule_fact(&ctx).expect("installed").outdated);
        assert!(watch_service_fact(&ctx).expect("installed").outdated);

        crate::schedule::install(&ctx, Permit::for_a_test()).expect("installed again");
        crate::watch_service::install(&ctx, Permit::for_a_test(), at(90)).expect("installed again");
        assert!(!schedule_fact(&ctx).expect("installed").outdated);
        assert!(!watch_service_fact(&ctx).expect("installed").outdated);
    }
}

#[test]
fn a_broken_schedule_is_written_again_by_whatever_this_machine_has() {
    for os in [Os::MacOs, Os::Windows] {
        assert_eq!(again(os), words::AGAIN_IN_THE_APP_OR_A_TERMINAL, "{os:?}");
    }
    assert_eq!(
        again(Os::Linux),
        words::AGAIN_IN_A_TERMINAL,
        "there is no app here"
    );
}

#[test]
fn a_schedule_whose_pitboard_is_gone_is_found_on_the_disk() {
    let scratch = tempfile::tempdir().expect("a scratch home");
    let root = scratch.path().to_path_buf();

    let program = root.join("bin/pitboard");
    let ctx = Context::new(root.clone())
        .with_memory_stores(crate::host::memory::MemoryHost::new())
        .with_schedule_program(program.clone());
    assert!(schedule_fact(&ctx).is_none(), "nothing installed yet");

    std::fs::create_dir_all(root.join("bin")).expect("a bin");
    std::fs::write(&program, "").expect("a Pitboard");
    crate::schedule::install(&ctx, Permit::for_a_test()).expect("installed");
    let fact = schedule_fact(&ctx).expect("installed");
    assert_eq!(fact.program.as_deref(), Some(program.as_path()));
    assert!(fact.program_found);

    std::fs::remove_file(&program).expect("taken away");
    assert!(!schedule_fact(&ctx).expect("still installed").program_found);

    assert!(
        schedule_fact(&ctx.with_pitboard_home(root.join("elsewhere"))).is_none(),
        "a Pitboard pointed at another home has no schedule"
    );
}

// Through the pretend Task Scheduler, on any system; a reinstall is the fix doctor names.
#[test]
fn a_task_changed_in_task_scheduler_is_read_where_it_is_kept() {
    let scratch = tempfile::tempdir().expect("a scratch home");
    let home = scratch.path().to_string_lossy().into_owned();
    let program = scratch.path().join("bin").join("pitboard.exe");
    std::fs::create_dir_all(program.parent().expect("its folder")).expect("a bin");
    std::fs::write(&program, "").expect("a Pitboard");
    let env: crate::context::Environment =
        [("HOME", home.as_str()), ("USERPROFILE", home.as_str())]
            .into_iter()
            .collect();
    let ctx = Context::for_command_line(&env)
        .with_memory_stores(crate::host::memory::MemoryHost::scheduling_tasks(
            "S-1-5-21-1",
        ))
        .with_schedule_program(program);
    crate::schedule::install(&ctx, Permit::for_a_test()).expect("installed");
    let fresh = Task {
        last_run: None,
        last_result: Some(0x0004_1303),
        drifted: Vec::new(),
    };
    let read = |ctx: &Context| schedule_fact(ctx).expect("installed").task;
    assert_eq!(read(&ctx), Some(fresh.clone()));

    let kept = crate::schedule::path(&ctx).expect("the task's file");
    let xml = std::fs::read_to_string(&kept).expect("written");
    std::fs::write(
        &kept,
        xml.replace(
            "<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>",
            "<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>",
        ),
    )
    .expect("changed by hand");
    assert_eq!(
        read(&ctx).map(|task| task.drifted),
        Some(vec![Drift::StopsOnBattery])
    );

    crate::schedule::install(&ctx, Permit::for_a_test()).expect("installed again");
    assert_eq!(read(&ctx), Some(fresh));
}

#[test]
fn a_schedule_whose_proxy_differs_from_this_runs_is_said() {
    let mut f = facts();
    f.schedule = Some(scheduled(direct(), false));
    assert!(
        evaluate(&f).iter().all(|c| c.code != "schedule_proxy"),
        "nothing is said where they go the same way"
    );

    f.schedule = Some(scheduled(by(through(None, &[])), true));
    let checks = evaluate(&f);
    let line = check(&checks, "schedule_proxy");
    let installed = || words::installed_with(&words::proxy_named(&through(None, &[])));
    assert_eq!(
        (line.level, line.name.as_str(), line.detail.clone()),
        (
            Level::Warn,
            "renewal schedule's proxy",
            words::installed_and_here(&installed(), &words::goes_directly("this run"))
        )
    );
    assert_eq!(line.advice, words::INSTALL_AGAIN_FROM_HERE);

    let on_loopback = || ProxyFact {
        variable: "ALL_PROXY",
        address: "http://127.0.0.1:3128".into(),
        server: "127.0.0.1:3128".into(),
        on_loopback: true,
        ..through(Some("NO_PROXY"), &["chatgpt.com"])
    };
    f.network = by(on_loopback());
    f.schedule = Some(scheduled(direct(), true));
    assert_eq!(
        check(&evaluate(&f), "schedule_proxy").detail,
        words::installed_and_here(
            words::INSTALLED_WITH_NO_PROXY,
            &words::goes_through("this run", &words::proxy_named(&on_loopback()))
        )
    );

    // Installed again from here, the schedule would be given a SOCKS proxy that fails too.
    let socks = || ProxyFact {
        address: "socks5h://127.0.0.1:1080".into(),
        server: "127.0.0.1:1080".into(),
        socks: true,
        fails: true,
        ..on_loopback()
    };
    f.network = by(socks());
    let checks = evaluate(&f);
    let line = check(&checks, "schedule_proxy");
    assert_eq!(
        (line.detail.clone(), line.advice.clone()),
        (
            words::installed_and_here(
                words::INSTALLED_WITH_NO_PROXY,
                &words::is_given("this run", &words::proxy_named(&socks()))
            ),
            words::socks_would_fail("ALL_PROXY")
        )
    );
    f.network = by(ProxyFact {
        exempt: [
            "api.anthropic.com",
            "platform.claude.com",
            "auth.openai.com",
            "chatgpt.com",
        ]
        .map(String::from)
        .to_vec(),
        fails: false,
        ..socks()
    });
    let checks = evaluate(&f);
    assert_eq!(
        check(&checks, "schedule_proxy").advice,
        words::INSTALL_AGAIN_FROM_HERE
    );

    f.network = by(through(None, &[]));
    f.schedule = Some(scheduled(by(through(None, &[])), true));
    assert_eq!(
        check(&evaluate(&f), "schedule_proxy").detail,
        words::another_user_or_password("this run", &words::proxy_named(&through(None, &[])))
    );
}

// The app's environment names no proxy a shell set, so the line is no warning there.
#[test]
fn in_the_app_a_schedules_other_proxy_is_said_without_a_warning() {
    let mut f = facts();
    f.in_the_app = true;
    f.schedule = Some(scheduled(direct(), false));
    assert!(evaluate(&f).iter().all(|c| c.code != "schedule_proxy"));

    f.schedule = Some(scheduled(by(through(None, &[])), true));
    let checks = evaluate(&f);
    let line = check(&checks, "schedule_proxy");
    let proxy = || words::proxy_named(&through(None, &[]));
    assert_eq!(
        (line.level, line.name.as_str(), line.detail.clone()),
        (
            Level::Ok,
            "renewal schedule's proxy",
            words::installed_and_here(
                &words::installed_with(&proxy()),
                &words::goes_directly("the app")
            )
        )
    );
    assert_eq!(line.advice, words::THE_APPS_OWN_ENVIRONMENT);

    f.network = by(through(None, &[]));
    assert_eq!(
        check(&evaluate(&f), "schedule_proxy").detail,
        words::another_user_or_password("the app", &proxy())
    );
}

#[test]
fn the_schedules_proxy_is_read_from_what_install_wrote() {
    let scratch = tempfile::tempdir().expect("a scratch home");
    let root = scratch.path().to_path_buf();
    let program = root.join("bin/pitboard");
    std::fs::create_dir_all(root.join("bin")).expect("a bin");
    std::fs::write(&program, "").expect("a Pitboard");
    let machine = crate::host::memory::MemoryHost::new();
    let home = root.to_string_lossy().into_owned();
    let run = |proxy: Option<&str>| {
        let env: crate::context::Environment =
            [("HOME", home.as_str()), ("USERPROFILE", home.as_str())]
                .into_iter()
                .chain(proxy.map(|address| ("HTTPS_PROXY", address)))
                .collect();
        Context::for_command_line(&env)
            .with_memory_stores(Arc::clone(&machine))
            .with_schedule_program(program.clone())
    };
    let gathered = |ctx: &Context| {
        let mut f = facts();
        f.schedule = schedule_fact(ctx);
        f.network = network_fact(&ctx.proxy);
        f
    };
    let installer = run(Some("http://alice:s3cret@proxy.example.com:3128"));
    crate::schedule::install(&installer, Permit::for_a_test()).expect("installed");

    let same = gathered(&installer);
    assert!(!same.schedule.as_ref().expect("installed").network_differs);
    assert!(evaluate(&same).iter().all(|c| c.code != "schedule_proxy"));

    let changed = gathered(&run(Some("http://alice:changed@proxy.example.com:3128")));
    let detail = check(&evaluate(&changed), "schedule_proxy").detail.clone();
    assert_eq!(
        detail,
        words::another_user_or_password(
            "this run",
            &words::proxy_named(changed.network.proxy.as_ref().expect("a proxy"))
        )
    );
    for secret in ["alice", "s3cret", "changed"] {
        assert!(!detail.contains(secret), "{secret}: {detail}");
    }

    let direct = run(None);
    let f = gathered(&direct);
    let detail = check(&evaluate(&f), "schedule_proxy").detail.clone();
    assert_eq!(
        detail,
        words::installed_and_here(
            &words::installed_with(&words::proxy_named(
                f.schedule
                    .as_ref()
                    .and_then(|schedule| schedule.network.proxy.as_ref())
                    .expect("installed with a proxy")
            )),
            &words::goes_directly("this run")
        )
    );
    let hidden = redaction_for(&direct, &f).over(&detail);
    assert!(
        hidden.starts_with("the schedule was installed with http://***:***@<proxy ")
            && !hidden.contains("proxy.example.com"),
        "{hidden}"
    );
}

// A run at boot can find the store locked, and doctor runs where it is open: what the run kept
// is said, with when, below what a gone Pitboard or an earlier one's unit says.
#[test]
fn a_run_that_could_not_open_the_store_is_said_with_when() {
    let mut f = facts();
    let mut schedule = scheduled(direct(), false);
    schedule.refused = Some(crate::schedule::Refused {
        at: NOW - 33_120,
        vault: Some(crate::host::Vault::SecretService),
        codes: ["credential_store_locked".to_string()].into(),
    });
    f.schedule = Some(schedule);
    for os in [Os::Linux, Os::MacOs, Os::Windows] {
        f.os = os;
        let checks = evaluate(&f);
        let refused = check(&checks, "schedule");
        assert_eq!(refused.level, Level::Warn, "{os:?}");
        assert_eq!(
            (refused.detail.as_str(), refused.advice.as_str()),
            (
                words::could_not_open(
                    &words::runs_daily("/usr/local/bin/pitboard"),
                    33_120,
                    Some(crate::host::Vault::SecretService),
                    true,
                    LOGIN
                )
                .as_str(),
                words::runs_again(os)
            ),
            "{os:?}"
        );
        if os == Os::Linux {
            for said in [&refused.detail, &refused.advice] {
                assert!(!crate::words::names_what_linux_has_not(said), "{said}");
            }
        }
    }

    let schedule = f.schedule.as_mut().expect("set above");
    schedule.outdated = true;
    assert_eq!(
        check(&evaluate(&f), "schedule").detail,
        words::renews_by_time_awake(&words::runs_daily("/usr/local/bin/pitboard"))
    );
    let schedule = f.schedule.as_mut().expect("set above");
    schedule.program_found = false;
    assert_eq!(check(&evaluate(&f), "schedule").level, Level::Fail);
}

// The watch service never asks to unlock the store either, and runs for days: what one of its
// switches or warm-ups could not open is said, with when, until one opens it.
#[test]
fn a_switch_of_the_watch_service_that_could_not_open_the_store_is_said_with_when() {
    let mut f = facts();
    let program = "/usr/local/bin/pitboard";
    f.watch_service = Some(WatchServiceFact {
        location: Location::File(PathBuf::from(
            "/home/x/.config/systemd/user/pitboard-watch.service",
        )),
        program: Some(PathBuf::from(program)),
        program_found: true,
        switching: Some(at(90)),
        task: None,
        outdated: false,
        refused: Some(crate::schedule::Refused {
            at: NOW - 600,
            vault: Some(crate::host::Vault::SecretService),
            codes: ["credential_store_locked".to_string()].into(),
        }),
    });
    for os in [Os::Linux, Os::MacOs, Os::Windows] {
        f.os = os;
        let checks = evaluate(&f);
        let refused = check(&checks, "watch_service");
        assert_eq!(refused.level, Level::Warn, "{os:?}");
        assert_eq!(
            (refused.detail.as_str(), refused.advice.as_str()),
            (
                words::switch_could_not_open(
                    &words::runs_from_sign_in(Some(at(90)), program),
                    600,
                    Some(crate::host::Vault::SecretService),
                    true,
                    LOGIN
                )
                .as_str(),
                words::TRIES_AGAIN_AT_ITS_NEXT_SWITCH
            ),
            "{os:?}"
        );
    }

    let service = f.watch_service.as_mut().expect("set above");
    service.outdated = true;
    assert_eq!(
        check(&evaluate(&f), "watch_service").detail,
        words::fails_once_its_pitboard_is_gone(&words::runs_from_sign_in(Some(at(90)), program))
    );
}