t27.aiРусский

Read the diff before you accept it

You will learn

How to read an agent's diff against your request and spot a change nobody asked for.

An agent says done and shows a diff: the lines it removed and the lines it added. Read it against what you asked for. If you asked for a change to lines 10 to 20 and the diff also touches line 40, that is a change nobody requested, and now you have to read it. Accept a diff whose every touched line is in the request. Send back one that is not, or ask why. Even a clean diff still goes through the tests.

Try it

Read the two diffs against the request for lines 10 to 20, mark the lines outside it, then accept one diff and send the other back. In the spec, find the line number the sprawling diff touches outside the request.

Open the interactive lesson →

Vibecoding 18: read the diff before you accept it ↗

Two diffs, one request: see which touched lines fall outside what you asked for, and accept one diff and send the other back. Lesson 18 of the vibecoding course.

specs/vibecoding/read_diff.t27

// SPDX-License-Identifier: Apache-2.0
; specs/vibecoding/read_diff.t27 -- vibecoding lesson: read the diff before you accept it
; An agent was asked to change lines 10 to 20 of a file. Its diff lists the lines it touched.
; Before you accept, look for touched lines outside the ask: each one is a change you did
; not request and now have to read. A clean diff has none. outside_the_ask is the check
; written as code; the tests walk the two diffs below line by line.
; phi^2 + 1/phi^2 = 3 | TRINITY

module vibecoding_read_diff;

pub const ASK_FROM : u8 = 10;
pub const ASK_TO : u8 = 20;
pub const CLEAN_DIFF : [4]u8 = [10, 12, 15, 20];
pub const SPRAWLING_DIFF : [4]u8 = [12, 13, 14, 40];

pub fn outside_the_ask(line: u8) -> u8 {
    if (line < ASK_FROM) {
        return 1;
    }
    if (line > ASK_TO) {
        return 1;
    }
    return 0;
}

test a_clean_diff_stays_inside_the_ask {
    assert CLEAN_DIFF[0] >= ASK_FROM;
    assert CLEAN_DIFF[3] <= ASK_TO;
    assert CLEAN_DIFF[1] >= ASK_FROM;
    assert CLEAN_DIFF[2] <= ASK_TO;
}

test the_edges_of_the_ask_are_inside {
    assert ASK_FROM >= ASK_FROM;
    assert ASK_TO <= ASK_TO;
    assert ASK_FROM - 1 < ASK_FROM;
    assert ASK_TO + 1 > ASK_TO;
}

test negative_control_a_sprawling_diff_is_flagged {
    assert SPRAWLING_DIFF[3] > ASK_TO;
    assert SPRAWLING_DIFF[0] <= ASK_TO;
}

Open the lesson's spec in the player ↗

All lessons