t27.aiEnglish

Ночной дозор

Вы узнаете

Что ночной дозор делает утром с четырьмя проверками карточек.

Каждую ночь идут четыре проверки чата карточек: тред, дверь статуса, слияния и паритет. night_verdict подводит итог: любое падение — это падение, иначе любое неизмеренное — неизмерено, иначе всё прошло. night_report превращает это в одно действие: падение открывает задачу или комментирует открытую, успех закрывает открытую задачу или молчит, а неизмеренная ночь оставляет всё как есть.

Попробовать

Сделайте ночь успешной при открытой задаче; затем сделайте одну проверку неизмеренной.

Открыть интерактивный урок →

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
}

Открыть спеку урока в плеере ↗

Все уроки