t27.aiРусский

A branch is a safe try

You will learn

How a try on a branch is thrown away or merged, and why main is untouched until you choose.

A branch is a copy of your line of work where you can try something, and the main line stays as it was until you decide. In branch.t27 main holds 10 and an agent's try turns it into 99 on its own branch. If the try is bad you delete the branch and main still holds 10. If it is good you merge it and main holds 99. While you try there are 2 lines of work, main and the try; after either ending there is 1. Ask an agent for a risky change on a branch, not on main.

Try it

In the widget, compare the two endings in the table and say which one changes main; then in the spec frame plant the bug MAIN_AFTER_DISCARD = 99 and see which tests turn red.

Open the interactive lesson →

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;
}

Open the lesson's spec in the player ↗

All lessons