Git Bisect Exercise: Campus Coffee Calculator

Scenario

The Campus Coffee Calculator is used by a fictional campus coffee cart to calculate order totals. It handles drink prices, size surcharges, alternative milk, extra shots, discounts, coupons, and tax.

Recently, someone noticed that some coffee orders are being undercharged. The current version of the repository is broken, but there is a known-good version tagged known-good.

Your job is to use git bisect to find the commit that introduced the bug.

Expected Behaviour

A large oat latte with one extra shot should cost $6.80.

Item Amount
Latte base price $4.20
Large size surcharge $1.10
Oat milk surcharge $0.60
Extra shot $0.90
Total $6.80

In R, this should pass:

line_total("latte", size = "large", milk = "oat", shots = 2)

Expected result:

6.8

Unexpected Behaviour

The current version gives the wrong price:

expected 6.8, got 6.4

This means the large oat latte with an extra shot is being undercharged by 40 cents. Order totals that include large drinks may also be wrong.

Test Command

You can test any commit with:

Rscript tests/test-pricing.R

A good commit passes this command. A bad commit fails it.

Your Task

Use git bisect to find the first commit that introduced the pricing bug.

Start the bisect with:

git bisect start HEAD known-good

Then run the test automatically across commits:

git bisect run Rscript tests/test-pricing.R

When you are finished, reset your repository:

git bisect reset

Questions

  1. What is the hash and commit message of the first bad commit?
  2. Which file changed in that commit?
  3. What behaviour was the commit trying to add?
  4. What mistake caused the unexpected pricing behaviour?
  5. What extra test would have caught this bug earlier?