t27.aiEnglish

Ветка это безопасная проба

Вы узнаете

Как проба на ветке отбрасывается или вливается и почему main не тронут, пока вы не решите.

Ветка это копия вашей линии работы, где можно что-то пробовать, а основная линия остаётся прежней, пока вы не решите. В branch.t27 в main лежит 10, а проба агента превращает это в 99 на своей ветке. Если проба плохая, вы удаляете ветку, и в main по-прежнему 10. Если хорошая, вы вливаете её, и в main лежит 99. Пока вы пробуете, линий работы 2, main и проба; после любого из двух исходов она 1. Просите агента о рискованной правке на ветке, а не в main.

Попробуйте

В виджете сравните два исхода в таблице и скажите, какой меняет main; затем в окне спецификации подложите ошибку MAIN_AFTER_DISCARD = 99 и посмотрите, какие тесты покраснеют.

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

A branch is a safe try ↗

Two endings of one try on a branch: thrown away, the main line stays as it was; merged, the main line takes the change. Lesson 8 of the course Vibecoding from zero with t27.

specs/vibecoding/branch.t27

// SPDX-License-Identifier: Apache-2.0
; specs/vibecoding/branch.t27 -- lesson "A branch is a safe try" of the course "Vibecoding from zero with t27"
; A branch is a copy of your line of work where you can try something. If the try is bad, delete
; the branch and the main line is exactly as it was. If it is good, merge it in. Here the main
; line is one number and a try changes it to another.
; ASCII only, English only.

module vibecoding_branch;

; The main line before the try, and what the agent's try turned it into on its own branch.
pub const MAIN_BEFORE : u8 = 10;
pub const TRY_VALUE : u8 = 99;

; The try went wrong and was thrown away: the main line is untouched.
pub const MAIN_AFTER_DISCARD : u8 = 10;
; The try went well and was merged: the main line takes its value.
pub const MAIN_AFTER_MERGE : u8 = 99;

; Lines of work alive while you try (main and the try), then after the try is deleted.
pub const BRANCHES_WHILE_TRYING : u8 = 2;
pub const BRANCHES_AFTER_DELETE : u8 = 1;

test a_thrown_away_try_leaves_main_alone {
    assert MAIN_AFTER_DISCARD == MAIN_BEFORE;
}

test a_merged_try_changes_main {
    assert MAIN_AFTER_MERGE == TRY_VALUE;
    assert MAIN_AFTER_MERGE != MAIN_BEFORE;
}

test deleting_the_try_leaves_only_main {
    assert BRANCHES_WHILE_TRYING - 1 == BRANCHES_AFTER_DELETE;
}

; Negative control: plant the bug "the discarded try leaked into main" (MAIN_AFTER_DISCARD = 99)
; and the first test turns red; with the line as written it stays green.
test negative_control_a_discarded_try_is_not_the_try {
    assert MAIN_AFTER_DISCARD != TRY_VALUE;
}

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

Все уроки