t27.aiРусский

The night watch

You will learn

What the night watch does in the morning with four card checks.

Every night four checks of the card chat run: the thread, the status door, the merges and the parity. night_verdict sums them up: any fail is a fail, else anything unmeasured is unmeasured, else it is a pass. night_report turns that into one act: a fail opens an issue or comments on the open one, a pass closes an open issue or stays silent, and an unmeasured night leaves everything as it is.

Try it

Make the night pass with the issue open; then make one check unmeasured.

Open the interactive lesson →

The night watch: four checks, one verdict, one report
The night watch: four checks, one verdict, one report ↗

Every night four card checks run. Tap each to pass, fail or unmeasured: night_verdict sums them up and night_report says whether to open an issue, comment, close it or stay silent.

specs/automation/card-chat-night-watch.t27

// SPDX-License-Identifier: Apache-2.0
// Card Chat Night Watch - verdict and reporting logic
// Part of EPIC #5388

module CardChatNightWatch {
    // Verdict constants
    const CHECK_PASS: u8 = 0
    const CHECK_FAIL: u8 = 1
    const CHECK_UNMEASURED: u8 = 2

    // Report constants
    const REPORT_SILENT: u8 = 0
    const REPORT_OPEN_ISSUE: u8 = 1
    const REPORT_COMMENT: u8 = 2
    const REPORT_CLOSE_ISSUE: u8 = 3
    const REPORT_LEAVE_AS_IS: u8 = 4

    // Total number of card check verdicts (thread, status door, merges, parity)
    const CARD_CHECK_VERDICTS: u8 = 4

    // Determine night verdict based on failures and unmeasured checks
    // Any fail -> FAIL; else any unmeasured -> UNMEASURED; else PASS
    fn night_verdict(fails: u8, unmeasured: u8) -> u8 {
        if fails > 0 {
            return CHECK_FAIL
        } else if unmeasured > 0 {
            return CHECK_UNMEASURED
        } else {
            return CHECK_PASS
        }
    }

    // Determine night report based on verdict and issue state
    // FAIL and no open issue -> OPEN_ISSUE
    // FAIL and an open issue -> COMMENT
    // PASS and an open issue -> CLOSE_ISSUE
    // PASS and none -> SILENT
    // UNMEASURED -> LEAVE_AS_IS whatever the issue state
    // a verdict above 2 -> LEAVE_AS_IS
    fn night_report(verdict: u8, issue_open: bool) -> u8 {
        if verdict > 2 {
            return REPORT_LEAVE_AS_IS
        }
        
        if verdict == CHECK_FAIL {
            if issue_open {
                return REPORT_COMMENT
            } else {
                return REPORT_OPEN_ISSUE
            }
        } else if verdict == CHECK_PASS {
            if issue_open {
                return REPORT_CLOSE_ISSUE
            } else {
                return REPORT_SILENT
            }
        } else {
            return REPORT_LEAVE_AS_IS
        }
    }

    // Check if night counts are acceptable
    // true when fails + unmeasured <= CARD_CHECK_VERDICTS
    fn night_counts_ok(fails: u8, unmeasured: u8) -> bool {
        let total = fails + unmeasured
        return total <= CARD_CHECK_VERDICTS
    }

    // Tests
    test night_verdict_all_pass
        let result = night_verdict(0, 0)
        assert result == CHECK_PASS

    test night_verdict_any_fail
        let result = night_verdict(1, 0)
        assert result == CHECK_FAIL

    test night_verdict_fail_beside_unmeasured
        let result = night_verdict(1, 3)
        assert result == CHECK_FAIL

    test night_verdict_any_unmeasured_no_fail
        let result = night_verdict(0, 1)
        assert result == CHECK_UNMEASURED

    test night_report_fail_no_issue
        let result = night_report(CHECK_FAIL, false)
        assert result == REPORT_OPEN_ISSUE

    test night_report_fail_with_issue
        let result = night_report(CHECK_FAIL, true)
        assert result == REPORT_COMMENT

    test night_report_pass_with_issue
        let result = night_report(CHECK_PASS, true)
        assert result == REPORT_CLOSE_ISSUE

    test night_report_pass_no_issue
        let result = night_report(CHECK_PASS, false)
        assert result == REPORT_SILENT

    test night_report_unmeasured_with_issue
        let result = night_report(CHECK_UNMEASURED, true)
        assert result == REPORT_LEAVE_AS_IS

    test night_report_unmeasured_no_issue
        let result = night_report(CHECK_UNMEASURED, false)
        assert result == REPORT_LEAVE_AS_IS

    test night_report_invalid_verdict
        let result = night_report(5, true)
        assert result == REPORT_LEAVE_AS_IS

    test night_counts_ok_within_limit
        let result = night_counts_ok(2, 2)
        assert result == true

    test night_counts_ok_at_limit
        let result = night_counts_ok(4, 0)
        assert result == true

    test night_counts_ok_over_limit
        let result = night_counts_ok(3, 2)
        assert result == false

    test night_counts_ok_zero
        let result = night_counts_ok(0, 0)
        assert result == true

    // User scenario tests
    test scenario_unmeasured_night_with_open_issue
        // Given a night where the render answered 401 to every read
        // when night_report(night_verdict(0, 4), true) is evaluated
        // then it returns REPORT_LEAVE_AS_IS
        let verdict = night_verdict(0, 4)
        let result = night_report(verdict, true)
        assert result == REPORT_LEAVE_AS_IS

    test scenario_fail_night_no_open_issue
        // Given a night where the parity check failed and nothing else did
        // when night_report(night_verdict(1, 0), false) is evaluated
        // then it returns REPORT_OPEN_ISSUE
        let verdict = night_verdict(1, 0)
        let result = night_report(verdict, false)
        assert result == REPORT_OPEN_ISSUE
}

Open the lesson's spec in the player ↗

All lessons