interprex-github 7.0.1

GitHub provider for all Interprex development-platform domains
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
use std::collections::BTreeSet;

use interprex::{
    CheckConclusion, CheckRun, CheckStatus, ProviderError, PublishedCheckConclusion, Repository,
    Result,
};
use serde::Deserialize;

use crate::GithubProvider;

use super::actors::{GithubApp, normalize_app};

/// The page size every check-runs request asks for, and the size a short page
/// is measured against.
const CHECK_RUNS_PER_PAGE: usize = 100;

/// One page of GitHub's check-runs envelope.
///
/// GitHub returns the runs under `check_runs` beside the complete
/// `total_count`, not as a bare array. Octocrab's `Page` recognizes a fixed
/// set of envelope keys that does not include this one, so this read pages by
/// number instead of following `Link` headers through `all_pages`.
#[derive(Deserialize)]
struct GithubCheckRunPage {
    total_count: u64,
    check_runs: Vec<GithubCheckRun>,
}

#[derive(Deserialize)]
struct GithubCheckSuitePage {
    total_count: u64,
    check_suites: Vec<GithubCheckSuite>,
}

#[derive(Deserialize)]
struct GithubCheckSuite {
    id: u64,
    head_sha: String,
}

#[derive(Deserialize)]
struct GithubCheckSuiteReference {
    id: u64,
}

#[derive(Deserialize)]
pub(crate) struct GithubCheckRun {
    #[serde(default)]
    id: Option<u64>,
    name: String,
    head_sha: String,
    status: String,
    conclusion: Option<String>,
    completed_at: Option<chrono::DateTime<chrono::Utc>>,
    /// The app that published the run. It carries the same identifier a
    /// ruleset reports as `integration_id`.
    app: Option<GithubApp>,
    #[serde(default)]
    check_suite: Option<GithubCheckSuiteReference>,
    html_url: Option<String>,
    output: Option<GithubCheckRunOutput>,
}

#[derive(Deserialize)]
struct GithubCheckRunOutput {
    summary: Option<String>,
}

fn normalize_check_conclusion(value: &str) -> Result<CheckConclusion> {
    match value {
        "success" => Ok(CheckConclusion::Success),
        "failure" => Ok(CheckConclusion::Failure),
        "neutral" => Ok(CheckConclusion::Neutral),
        "cancelled" => Ok(CheckConclusion::Cancelled),
        "timed_out" => Ok(CheckConclusion::TimedOut),
        "action_required" => Ok(CheckConclusion::ActionRequired),
        "skipped" => Ok(CheckConclusion::Skipped),
        "stale" => Ok(CheckConclusion::Stale),
        other => Err(ProviderError::Unrepresentable {
            provider: "github",
            fact: format!("unknown check run conclusion {other}"),
        }),
    }
}

pub(crate) fn normalize_check_run(value: GithubCheckRun) -> Result<CheckRun> {
    let unfinished = match value.status.as_str() {
        "requested" => Some(CheckStatus::Requested),
        "queued" => Some(CheckStatus::Queued),
        "pending" => Some(CheckStatus::Pending),
        "waiting" => Some(CheckStatus::Waiting),
        "in_progress" => Some(CheckStatus::InProgress),
        "completed" => None,
        other => {
            return Err(ProviderError::Unrepresentable {
                provider: "github",
                fact: format!("unknown check run status {other}"),
            });
        }
    };
    let status = if let Some(unfinished) = unfinished {
        if let Some(conclusion) = value.conclusion {
            return Err(ProviderError::Unrepresentable {
                provider: "github",
                fact: format!(
                    "check run {} is {} and has conclusion {conclusion}",
                    value.name, value.status
                ),
            });
        }
        if value.completed_at.is_some() {
            return Err(ProviderError::Unrepresentable {
                provider: "github",
                fact: format!(
                    "check run {} is {} and has a completion time",
                    value.name, value.status
                ),
            });
        }
        unfinished
    } else {
        let conclusion = value
            .conclusion
            .ok_or_else(|| ProviderError::Unrepresentable {
                provider: "github",
                fact: format!("completed check run {} has no conclusion", value.name),
            })?;
        let completed_at = value
            .completed_at
            .ok_or_else(|| ProviderError::Unrepresentable {
                provider: "github",
                fact: format!("completed check run {} has no completion time", value.name),
            })?;
        CheckStatus::Completed {
            conclusion: normalize_check_conclusion(&conclusion)?,
            completed_at,
        }
    };
    Ok(CheckRun {
        name: value.name,
        head_sha: value.head_sha,
        via_app: value.app.map(normalize_app).transpose()?,
        status,
        summary: value
            .output
            .and_then(|output| output.summary)
            .filter(|summary| !summary.trim().is_empty()),
        html_url: value.html_url,
    })
}

pub(super) fn conclusion(value: &PublishedCheckConclusion) -> &'static str {
    match value {
        PublishedCheckConclusion::Success => "success",
        PublishedCheckConclusion::Failure => "failure",
        PublishedCheckConclusion::Neutral => "neutral",
        PublishedCheckConclusion::Cancelled => "cancelled",
        PublishedCheckConclusion::TimedOut => "timed_out",
        PublishedCheckConclusion::ActionRequired => "action_required",
        PublishedCheckConclusion::Skipped => "skipped",
    }
}

impl GithubProvider {
    pub(crate) async fn github_check_runs(
        &self,
        repository: &Repository,
        head_sha: &str,
    ) -> Result<Vec<GithubCheckRun>> {
        let mut collected: Vec<GithubCheckRun> = Vec::new();
        let mut page = 1_u32;
        loop {
            let response: GithubCheckRunPage = self
                .user()?
                .get(
                    format!("/repos/{repository}/commits/{head_sha}/check-runs"),
                    Some(&[
                        ("per_page", CHECK_RUNS_PER_PAGE.to_string()),
                        ("page", page.to_string()),
                        // GitHub's default, sent explicitly: within each check
                        // suite on the commit, its current run of each check.
                        // Suites remain separate, so runs can share a name.
                        ("filter", "latest".to_owned()),
                    ]),
                )
                .await
                .map_err(|error| {
                    crate::client::read_error(
                        "read check runs",
                        format!("commit {head_sha} in {repository}"),
                        error,
                    )
                })?;
            let received = response.check_runs.len();
            collected.extend(response.check_runs);
            if received < CHECK_RUNS_PER_PAGE || collected.len() as u64 >= response.total_count {
                return Ok(collected);
            }
            page += 1;
        }
    }

    pub(crate) async fn complete_github_check_runs(
        &self,
        repository: &Repository,
        head_sha: &str,
    ) -> Result<Vec<GithubCheckRun>> {
        let suites = self.github_check_suites(repository, head_sha).await?;
        validate_check_suites(&suites, head_sha)?;
        let mut runs = Vec::new();
        let mut run_ids = BTreeSet::new();
        for suite in suites {
            for run in self
                .github_check_runs_for_suite(repository, suite.id)
                .await?
            {
                let run_id = run.id.ok_or_else(|| {
                    unrepresentable(format!("check run in suite {} has no id", suite.id))
                })?;
                if run_id == 0 || !run_ids.insert(run_id) {
                    return Err(unrepresentable(format!(
                        "check run id {run_id} is zero or repeated"
                    )));
                }
                let observed_suite = run.check_suite.as_ref().ok_or_else(|| {
                    unrepresentable(format!("check run {run_id} has no check-suite identity"))
                })?;
                if observed_suite.id != suite.id {
                    return Err(unrepresentable(format!(
                        "check run {run_id} names suite {} instead of {}",
                        observed_suite.id, suite.id
                    )));
                }
                if run.head_sha != head_sha {
                    return Err(unrepresentable(format!(
                        "check run {run_id} names revision {} instead of {head_sha}",
                        run.head_sha
                    )));
                }
                runs.push(run);
            }
        }
        Ok(runs)
    }

    async fn github_check_suites(
        &self,
        repository: &Repository,
        head_sha: &str,
    ) -> Result<Vec<GithubCheckSuite>> {
        let mut collected = Vec::new();
        let mut page = 1_u32;
        let mut expected_total = None;
        loop {
            let response: GithubCheckSuitePage = self
                .user()?
                .get(
                    format!("/repos/{repository}/commits/{head_sha}/check-suites"),
                    Some(&[
                        ("per_page", CHECK_RUNS_PER_PAGE.to_string()),
                        ("page", page.to_string()),
                    ]),
                )
                .await
                .map_err(|error| {
                    crate::client::read_error(
                        "read check suites",
                        format!("commit {head_sha} in {repository}"),
                        error,
                    )
                })?;
            match expected_total {
                Some(total) if total != response.total_count => {
                    return Err(unrepresentable(format!(
                        "check-suite total changed from {total} to {} while paging",
                        response.total_count
                    )));
                }
                None => expected_total = Some(response.total_count),
                Some(_) => {}
            }
            let received = response.check_suites.len();
            collected.extend(response.check_suites);
            let expected_total = expected_total.unwrap_or(response.total_count);
            if collected.len() as u64 > expected_total {
                return Err(unrepresentable(format!(
                    "check suites reported {expected_total} records but returned at least {}",
                    collected.len()
                )));
            }
            if collected.len() as u64 >= expected_total {
                return Ok(collected);
            }
            if received < CHECK_RUNS_PER_PAGE {
                return Err(unrepresentable(format!(
                    "check suites reported {expected_total} records but returned only {}",
                    collected.len()
                )));
            }
            page += 1;
        }
    }

    async fn github_check_runs_for_suite(
        &self,
        repository: &Repository,
        suite_id: u64,
    ) -> Result<Vec<GithubCheckRun>> {
        let mut collected = Vec::new();
        let mut page = 1_u32;
        let mut expected_total = None;
        loop {
            let response: GithubCheckRunPage = self
                .user()?
                .get(
                    format!("/repos/{repository}/check-suites/{suite_id}/check-runs"),
                    Some(&[
                        ("per_page", CHECK_RUNS_PER_PAGE.to_string()),
                        ("page", page.to_string()),
                        ("filter", "latest".to_owned()),
                    ]),
                )
                .await
                .map_err(|error| {
                    crate::client::read_error(
                        "read check runs in suite",
                        format!("check suite {suite_id} in {repository}"),
                        error,
                    )
                })?;
            match expected_total {
                Some(total) if total != response.total_count => {
                    return Err(unrepresentable(format!(
                        "check-run total for suite {suite_id} changed from {total} to {} while paging",
                        response.total_count
                    )));
                }
                None => expected_total = Some(response.total_count),
                Some(_) => {}
            }
            let received = response.check_runs.len();
            collected.extend(response.check_runs);
            let expected_total = expected_total.unwrap_or(response.total_count);
            if collected.len() as u64 > expected_total {
                return Err(unrepresentable(format!(
                    "check suite {suite_id} reported {expected_total} runs but returned at least {}",
                    collected.len()
                )));
            }
            if collected.len() as u64 >= expected_total {
                return Ok(collected);
            }
            if received < CHECK_RUNS_PER_PAGE {
                return Err(unrepresentable(format!(
                    "check suite {suite_id} reported {expected_total} runs but returned only {}",
                    collected.len()
                )));
            }
            page += 1;
        }
    }
}

fn validate_check_suites(suites: &[GithubCheckSuite], expected_head: &str) -> Result<()> {
    let mut ids = BTreeSet::new();
    for suite in suites {
        if suite.id == 0 || !ids.insert(suite.id) {
            return Err(unrepresentable(format!(
                "check suite id {} is zero or repeated",
                suite.id
            )));
        }
        if suite.head_sha != expected_head {
            return Err(unrepresentable(format!(
                "check suite {} names revision {} instead of {expected_head}",
                suite.id, suite.head_sha
            )));
        }
    }
    Ok(())
}

fn unrepresentable(fact: impl Into<String>) -> ProviderError {
    ProviderError::Unrepresentable {
        provider: "github",
        fact: fact.into(),
    }
}

#[cfg(test)]
mod tests {
    use std::{collections::BTreeMap, sync::Arc};

    use interprex::{
        CheckConclusion, CheckOutcome, CheckStatus, CodeReviewsProvider, ConfigurationSource,
        ProviderError, PublishedCheckConclusion, Repository, Result,
    };
    use tokio::{
        io::{AsyncReadExt, AsyncWriteExt},
        net::TcpListener,
        sync::oneshot,
    };

    use super::{
        GithubCheckRun, GithubCheckRunPage, GithubCheckSuite, conclusion, normalize_check_run,
        validate_check_suites,
    };
    use crate::{GithubProvider, client::ConfiguredApp};

    fn check_run(status: &str, conclusion: Option<&str>) -> GithubCheckRun {
        GithubCheckRun {
            id: None,
            name: "quality".to_owned(),
            head_sha: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_owned(),
            status: status.to_owned(),
            conclusion: conclusion.map(str::to_owned),
            completed_at: conclusion
                .is_some()
                .then(|| "2026-08-24T10:04:00Z".parse().expect("completion time")),
            app: None,
            check_suite: None,
            html_url: None,
            output: None,
        }
    }

    #[test]
    fn check_suite_validation_has_no_false_one_thousand_suite_limit() {
        for count in [1_000_u64, 1_001] {
            let suites = (1..=count)
                .map(|id| GithubCheckSuite {
                    id,
                    head_sha: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_owned(),
                })
                .collect::<Vec<_>>();
            validate_check_suites(&suites, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
                .expect("every suite is accounted for independently of count");
        }
    }

    #[test]
    fn check_suite_validation_rejects_wrong_revisions_and_repeated_ids() {
        for suites in [
            vec![
                GithubCheckSuite {
                    id: 7,
                    head_sha: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_owned(),
                },
                GithubCheckSuite {
                    id: 7,
                    head_sha: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_owned(),
                },
            ],
            vec![GithubCheckSuite {
                id: 7,
                head_sha: "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb".to_owned(),
            }],
        ] {
            assert!(matches!(
                validate_check_suites(&suites, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
                Err(ProviderError::Unrepresentable { .. })
            ));
        }
    }
    #[test]
    fn check_run_fixture_keeps_a_running_check_separate_from_a_completed_one() {
        let page: GithubCheckRunPage =
            serde_json::from_str(include_str!("../../tests/fixtures/check_runs.json"))
                .expect("check run fixture");
        assert_eq!(page.total_count, 3);
        let runs = page
            .check_runs
            .into_iter()
            .map(normalize_check_run)
            .collect::<Result<Vec<_>>>()
            .expect("normalizes");

        assert_eq!(
            runs.iter().map(|run| run.name.as_str()).collect::<Vec<_>>(),
            ["quality", "integration", "docs"]
        );
        assert_eq!(
            runs[0].status,
            CheckStatus::Completed {
                conclusion: CheckConclusion::Failure,
                completed_at: "2026-08-24T10:04:00Z".parse().expect("completion time"),
            }
        );
        assert_eq!(
            runs[0].summary.as_deref(),
            Some("clippy reported one warning")
        );
        let publisher = runs[0].via_app.as_ref().expect("publishing app");
        assert_eq!(publisher.id.as_str(), "1042");
        assert_eq!(publisher.slug, "quality-app");
        assert_eq!(
            runs[0].html_url.as_deref(),
            Some("https://github.com/civitas-forge/interprex-sandbox/runs/41")
        );
        assert_eq!(runs[1].status, CheckStatus::InProgress);
        assert_eq!(runs[1].summary, None);
        assert_eq!(
            runs[2].status,
            CheckStatus::Completed {
                conclusion: CheckConclusion::Skipped,
                completed_at: "2026-08-24T10:01:00Z".parse().expect("completion time"),
            }
        );
        assert_eq!(runs[2].summary, None, "blank output text is not a summary");
        assert_eq!(runs[2].via_app, None);
        assert_eq!(runs[2].html_url, None);
    }
    #[test]
    fn every_status_github_reports_before_completion_keeps_its_own_meaning() {
        for (reported, expected) in [
            ("requested", CheckStatus::Requested),
            ("queued", CheckStatus::Queued),
            ("pending", CheckStatus::Pending),
            ("waiting", CheckStatus::Waiting),
            ("in_progress", CheckStatus::InProgress),
        ] {
            assert_eq!(
                normalize_check_run(check_run(reported, None))
                    .expect("normalizes")
                    .status,
                expected
            );
        }
    }
    #[test]
    fn a_check_suite_conclusion_is_not_a_check_run_conclusion() {
        assert!(matches!(
            normalize_check_run(check_run("completed", Some("startup_failure")))
                .expect_err("a check suite conclusion must be unrepresentable on a run"),
            ProviderError::Unrepresentable { fact, .. }
                if fact.contains("unknown check run conclusion startup_failure")
        ));
    }
    #[test]
    fn every_check_conclusion_github_reports_is_representable() {
        for (reported, expected) in [
            ("success", CheckConclusion::Success),
            ("failure", CheckConclusion::Failure),
            ("neutral", CheckConclusion::Neutral),
            ("cancelled", CheckConclusion::Cancelled),
            ("timed_out", CheckConclusion::TimedOut),
            ("action_required", CheckConclusion::ActionRequired),
            ("skipped", CheckConclusion::Skipped),
            ("stale", CheckConclusion::Stale),
        ] {
            let run = normalize_check_run(check_run("completed", Some(reported)))
                .expect("normalizes every reported conclusion");
            assert!(matches!(
                run.status,
                CheckStatus::Completed { conclusion, .. } if conclusion == expected
            ));
        }
    }
    #[test]
    fn unknown_check_statuses_and_conclusions_are_unrepresentable() {
        let unknown_status = normalize_check_run(check_run("paused", None))
            .expect_err("unknown status must be unrepresentable");
        assert!(matches!(
            unknown_status,
            ProviderError::Unrepresentable { fact, .. } if fact.contains("unknown check run status paused")
        ));

        let unknown_conclusion = normalize_check_run(check_run("completed", Some("abandoned")))
            .expect_err("unknown conclusion must be unrepresentable");
        assert!(matches!(
            unknown_conclusion,
            ProviderError::Unrepresentable { fact, .. }
                if fact.contains("unknown check run conclusion abandoned")
        ));
    }
    #[test]
    fn a_check_run_contradicting_its_own_status_is_unrepresentable() {
        let mut missing_conclusion = check_run("completed", Some("success"));
        missing_conclusion.conclusion = None;
        assert!(matches!(
            normalize_check_run(missing_conclusion)
                .expect_err("completed run without a conclusion must be unrepresentable"),
            ProviderError::Unrepresentable { fact, .. } if fact.contains("has no conclusion")
        ));

        let mut missing_time = check_run("completed", Some("success"));
        missing_time.completed_at = None;
        assert!(matches!(
            normalize_check_run(missing_time)
                .expect_err("completed run without a completion time must be unrepresentable"),
            ProviderError::Unrepresentable { fact, .. } if fact.contains("has no completion time")
        ));

        assert!(matches!(
            normalize_check_run(check_run("in_progress", Some("success")))
                .expect_err("running check run with a conclusion must be unrepresentable"),
            ProviderError::Unrepresentable { fact, .. }
                if fact.contains("is in_progress and has conclusion success")
        ));

        let mut completed_while_queued = check_run("queued", None);
        completed_while_queued.completed_at =
            Some("2026-08-24T10:04:00Z".parse().expect("completion time"));
        assert!(matches!(
            normalize_check_run(completed_while_queued)
                .expect_err("queued check run with a completion time must be unrepresentable"),
            ProviderError::Unrepresentable { fact, .. }
                if fact.contains("is queued and has a completion time")
        ));
    }
    #[test]
    fn every_publishable_conclusion_maps_to_a_value_github_accepts_from_a_client() {
        for (publishable, expected) in [
            (PublishedCheckConclusion::Success, "success"),
            (PublishedCheckConclusion::Failure, "failure"),
            (PublishedCheckConclusion::Neutral, "neutral"),
            (PublishedCheckConclusion::Cancelled, "cancelled"),
            (PublishedCheckConclusion::TimedOut, "timed_out"),
            (PublishedCheckConclusion::ActionRequired, "action_required"),
            (PublishedCheckConclusion::Skipped, "skipped"),
        ] {
            let written = conclusion(&publishable);
            assert_eq!(written, expected);
            assert_ne!(
                written, "stale",
                "GitHub sets stale itself and refuses it from a client"
            );
        }
    }
    #[tokio::test]
    async fn app_only_check_uses_the_named_app_client() {
        let listener = TcpListener::bind("127.0.0.1:0")
            .await
            .expect("bind test server");
        let address = listener.local_addr().expect("address");
        let (sender, receiver) = oneshot::channel();
        tokio::spawn(async move {
            let (mut stream, _) = listener.accept().await.expect("accept request");
            let mut request = Vec::new();
            let mut buffer = [0_u8; 4096];
            loop {
                let count = stream.read(&mut buffer).await.expect("read request");
                request.extend_from_slice(&buffer[..count]);
                if count == 0 || String::from_utf8_lossy(&request).contains("\r\n\r\n{") {
                    break;
                }
            }
            stream
                .write_all(b"HTTP/1.1 201 Created\r\ncontent-type: application/json\r\ncontent-length: 2\r\nconnection: close\r\n\r\n{}")
                .await
                .expect("write response");
            sender.send(String::from_utf8(request).expect("UTF-8")).ok();
        });
        let client = octocrab::Octocrab::builder()
            .base_uri(format!("http://{address}"))
            .expect("base URI")
            .personal_token("app-installation-token")
            .build()
            .expect("client");
        let provider = GithubProvider {
            user: None,
            streaming_user: None,
            apps: BTreeMap::from([(
                "automation".to_owned(),
                ConfiguredApp {
                    app_id: 12,
                    read: Arc::new(client.clone()),
                    write: Arc::new(client),
                    source: ConfigurationSource::Direct,
                },
            )]),
            source: ConfigurationSource::Direct,
        };
        let repository = Repository::new("civitas-forge", "interprex-sandbox").expect("repository");
        provider
            .publish_check(
                &repository,
                "automation",
                &CheckOutcome {
                    name: "reviewer".to_owned(),
                    head_sha: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_owned(),
                    conclusion: PublishedCheckConclusion::Success,
                    summary: "settled".to_owned(),
                },
            )
            .await
            .expect("publish check");
        let request = receiver.await.expect("captured request");
        assert!(request.starts_with("POST /repos/civitas-forge/interprex-sandbox/check-runs "));
        assert!(
            request
                .to_ascii_lowercase()
                .contains("authorization: bearer app-installation-token")
        );
        assert!(request.contains("\"conclusion\":\"success\""));
    }
}