QA and Test Automation · Lab 3 of 35
Write a bug report with evidence: DevTools Network, SQL and a curl repro
Reproduce a real ShopRung bug, capture the request and response in the DevTools Network tab, prove it in the database with SQL, narrow it to a minimal repro, set severity and priority with reasons, write a Jira-style report, and repeat it from the API with curl, Java and Python.
⏱ 60 minBeginner💸 Free9 stepsJava + Python
ShopRung (bug switch)Chrome DevTools Network tabSQL consolecurlJava 21 (no libraries)Python 3.12 (no libraries)
Overview video
What you will build
A bug report a developer can act on in minutes: a clear title, the environment, steps from a known start, expected vs actual with the requirement id, severity and priority with reasons, and attachments that prove every claim.
The evidence behind it: the request and response from the browser's Network tab, SQL queries run before and after, a table of variations that narrows the bug down and shows its real impact, and a repro script that fails while the bug is there and passes once it is fixed.
You report the bug stock-not-reduced (placing an order does not reduce the stock). The last step shows the key evidence for a second bug, order-leak, to write up on your own.
Before you start
- ShopRung installed, as in lab 1 setup.
- Read Bug reports and the defect life cycle and Severity vs priority. Browser DevTools for testers and SQL for testers help with steps 2 and 3.
- Chrome or Edge (the steps name Chrome's DevTools; Firefox has the same Network tab with slightly different labels).
- Optional for step 8: Java 21 or Python 3.12. Neither needs any libraries.
Setup
S1Start ShopRung (lab 1)
Start ShopRung exactly as in lab 1, Setup and leave that terminal running. Open a second terminal for the commands below. If you still have mystery mode on from the last lab, that is fine: the next step replaces it.
S2Switch on the bug you will report
Reset the data, then switch on exactly one bug: stock-not-reduced. Here you know the bug in advance on purpose: the skill in this lab is proving and reporting it. On Windows, stop ShopRung (Ctrl+C) and start it with the bug instead; the reset line works in any terminal.
curl -X POST http://localhost:8080/api/test/reset
curl -X POST http://localhost:8080/api/test/bugs -H "Content-Type: application/json" -d '{"enabled":["stock-not-reduced"]}'curl -X POST http://localhost:8080/api/test/reset
curl -X POST http://localhost:8080/api/test/bugs -H "Content-Type: application/json" -d '{"enabled":["stock-not-reduced"]}'# in the ShopRung terminal, after Ctrl+C:
$env:SHOPRUNG_BUGS="stock-not-reduced"; npm start
# then in the second terminal:
curl.exe -X POST http://localhost:8080/api/test/reset {"status":"reset"}
{"mystery":false,"active":["stock-not-reduced"],"known":{...}} S3Check the bar in the shop
Open http://localhost:8080. A yellow bar under the header says Bug switch on: stock-not-reduced. (On Windows the second line of the expected output above is not printed; the bar is your check.)
S4A folder for the evidence
Make a folder called bug-101 with an evidence folder inside it. Every file in this lab goes there, so the report and its proof travel together.
mkdir -p bug-101/evidence && cd bug-101mkdir -p bug-101/evidence && cd bug-101mkdir bug-101\evidence; cd bug-101 Reproduce it three times from a clean start
See the bug with your own eyes, and prove it happens every time from the same starting data.
A bug you saw once is a rumour. A bug you can repeat from a known start is a fact. Do this in the browser:
- On the Products page, find The Bug Hunter's Diary: it says 3 in stock.
- Click Log in and log in as alice@shoprung.test / Alice123!.
- Click The Bug Hunter's Diary to open its page, type 2 in Quantity, click Add to cart.
- Click Cart. You see Subtotal $37.98, Shipping $4.99, Total $42.97. Click Place order.
- The page says Order #3 and Thank you! Your order is placed., status PLACED.
- Click Products. The Bug Hunter's Diary still says 3 in stock. The rule (ORD-2) says it should be 1.
Now reset (curl -X POST http://localhost:8080/api/test/reset, Windows curl.exe), reload the page and do it twice more. You stay logged in through a reset. Fill in the log below and save it as evidence/repro-log.md. Take a screenshot of the product list after the order and save it as after-order.png.
# Reproduction log: stock not reduced after an order
Build: ShopRung 1.0.0 (GET /api/health) Browser: <your browser and version>
Account: alice@shoprung.test Product: The Bug Hunter's Diary (BK-103, $18.99)
| Try | Start | Stock before | Ordered | Order | Total | Stock after | Expected |
| --- | ---------------- | ------------ | ------- | ----- | ------ | ----------- | -------- |
| 1 | after reset | 3 | 2 | #3 | $42.97 | 3 | 1 |
| 2 | after reset | 3 | 2 | #3 | $42.97 | 3 | 1 |
| 3 | after reset | 3 | 2 | #3 | $42.97 | 3 | 1 |
Result: reproduced 3 of 3 times. - The build and the browser. "Works on my machine" arguments end here.line 3
- Write down the numbers, not "it did not change". Numbers can be compared; words get argued about.line 8
- The reproduction rate goes in the report. "3 of 3" gets fixed sooner than "happened once".line 12
Stuck on this step?
- The order number is not #3
- You placed other orders since the last reset. Order numbers keep counting up. Reset, and the first new order is #3 again (Alice's seed orders are #1 and #2).
- The stock does go down to 1
- The bug is off. Check the yellow bar; if it is missing, run setup step 2 again. Then reset and repeat.
Capture the request and response in the Network tab
Record exactly what the browser sent and what the server answered, so nobody has to guess whether it is a UI or a server bug.
Everything the shop does goes through its API, so the Network tab shows the real conversation. Reset the data first, then:
- Press F12 (Mac: Cmd+Option+I) to open DevTools and click the Network tab.
- Click the Fetch/XHR filter, so you see API calls only.
- Tick Preserve log, so the list survives page changes.
- Click the Clear button (the circle with a line through it) to start empty.
- Repeat steps 3 to 5 of the previous step: add 2 copies of The Bug Hunter's Diary and place the order.
Click the row named orders. On the Headers tab check Request URL http://localhost:8080/api/orders, Request Method POST, Status Code 201 Created. Click the Response tab to see the order as JSON. Then click Products in the shop, open The Bug Hunter's Diary, and click the new row named 3 (GET /api/products/3): its response has "stock":3.
That proves the server stored the wrong stock, not just the page showing it wrongly. Save what you saw as evidence/network.http, like below. Remove the token from the Authorization header: it is a password for Alice's account for the next two hours.
Two quick ways to grab the exact request: right-click the row, Copy > Copy as cURL (it includes the token, so remove it before you share), or export the whole list with the Export HAR button (the download arrow at the top of the Network tab). Recent Chrome versions leave sensitive headers such as Authorization out of the export unless you change a setting; keep it that way.
### 1. Place the order (Network tab: the row named "orders")
POST http://localhost:8080/api/orders
Content-Type: application/json
Authorization: Bearer <token removed>
# Status: 201 Created
# Response headers: Content-Type: application/json; charset=utf-8, Content-Length: 306
# Response body:
# {"id":3,"userId":1,"status":"PLACED","subtotalCents":3798,"discountCents":0,
# "shippingCents":499,"totalCents":4297,"total":"$42.97","couponCode":null,
# "createdAt":"<now>","updatedAt":"<now>",
# "items":[{"productId":3,"name":"The Bug Hunter's Diary","priceCents":1899,"quantity":2}]}
### 2. Open the product again (Network tab: the row named "3")
GET http://localhost:8080/api/products/3
# Status: 200 OK
# Response body:
# {"id":3,"sku":"BK-103","name":"The Bug Hunter's Diary","category":"Books",
# "priceCents":1899,"price":"$18.99","stock":3,"inStock":true}
# Expected "stock":1 (3 - 2), per ORD-2. - Method and full URL, straight from the Headers tab.line 2
- Never paste a real token into a ticket. Tickets are read by many people and kept for years.line 4
- 201 Created: the server says the order worked. So the bug is not an error message: it is a wrong side effect.line 6
- The proof from the server itself, right after the order.line 20
Stuck on this step?
- The Network list is empty
- DevTools must be open before you click. Leave it open, then place the order again. Check the filter is Fetch/XHR or All, not Img or CSS.
- The list cleared itself when the page changed
- Tick Preserve log at the top of the Network tab.
- Firefox: I cannot find Fetch/XHR
- Firefox calls the filter XHR and puts Persist Logs in the gear menu. Request and response are on the Headers and Response tabs too.
Prove it in the database with SQL
Run the same query before and after the order, so the report shows the stored data, not just the screen.
Testers check the data behind the screen. Reset the data and open http://localhost:8080/sql in a new tab. It runs one read-only SELECT at a time, so you cannot break anything.
Paste query 1, click Run query, and note the result. Place the order in the shop again (2 copies, as before). Then run queries 2 and 3. Save the queries and their results as evidence/database.sql.
-- BUG-101 evidence from the SQL console (http://localhost:8080/sql)
-- ShopRung 1.0.0, seed data after POST /api/test/reset
-- 1. Before the order
SELECT id, sku, name, stock FROM products WHERE sku = 'BK-103';
-- id | sku | name | stock
-- 3 | BK-103 | The Bug Hunter's Diary | 3
-- 2. After Alice's order: the order and its line are saved correctly ...
SELECT o.id, o.user_id, o.status, i.product_id, i.quantity
FROM orders o JOIN order_items i ON i.order_id = o.id
WHERE o.id = 3;
-- id | user_id | status | product_id | quantity
-- 3 | 1 | PLACED | 3 | 2
-- 3. ... but the stock did not change. Expected 1.
SELECT id, sku, name, stock FROM products WHERE sku = 'BK-103';
-- id | sku | name | stock
-- 3 | BK-103 | The Bug Hunter's Diary | 3 - Before and after, with the same query. The difference (or the missing difference) is the evidence.line 4
- A join of the order and its lines: it shows what was saved correctly. Saying what works narrows the search for the developer.line 11
- Same query as step 1, same answer. ORD-2 says it should now be 1.line 16
Stuck on this step?
- "The console runs one SELECT query at a time"
- Paste one query only. Comments and a final
;are fine; a second statement is not. - Query 2 returns no rows
- Your order has another number. Run
SELECT id, user_id, status FROM orders ORDER BY idand use the newest id.
Narrow it to a minimal repro, and find the real impact
Find out what the bug depends on, the shortest steps that show it, and how much damage it does.
Before writing the report, change one thing at a time and see if the bug stays: another product, another quantity, another customer, a coupon, the API instead of the UI. If the bug survives every change, it is general and serious. If it disappears, you have found a condition to put in the title.
Reset once, then do these in order (Alice in the browser, the rest with the API is fine) and fill in the table. For the last one, log in as bob@shoprung.test / Bob12345! in a private window and order 3 copies of The Bug Hunter's Diary after Alice's 2. Then cancel Alice's order (#3, Cancel order on its page) and read the stock once more.
Finish with the impact query at the bottom of the sheet in the SQL console. It adds up what was ordered and compares it with the stock: more copies sold than ever existed.
# Narrowing it down
Question: what is the smallest set of steps that shows the bug, and how far does it reach?
All tries in one run, starting from a reset, with the stock-not-reduced build.
| Order | Who | What | Through | Stock before | Stock after | Bug? |
| ----- | ----- | ---------------------------------- | ------- | ------------ | ----------- | ---- |
| #3 | Alice | 2 x BK-103 | UI | 3 | 3 | yes |
| #4 | Alice | 1 x BK-101 (Clean Code Notebook) | API | 40 | 40 | yes |
| #5 | Bob | 1 x MS-402 (Wireless Mouse) | API | 20 | 20 | yes |
| #6 | Alice | 5 x BK-101 with SAVE10 | API | 40 | 40 | yes |
| #7 | Bob | 3 x BK-103, after Alice's 2 | API | 3 | 3 | yes, and accepted |
Then: cancel order #3 (2 copies of BK-103). Stock goes from 3 to 5.
## What it tells us
- Every product, any quantity, any customer, with or without a coupon, UI and API: it is every order.
- Minimal repro: reset, log in, add 2 x BK-103, place the order, read the stock.
- Impact 1 (ORD-3): the shop oversells. 5 copies of BK-103 ordered, only 3 ever existed.
- Impact 2 (ORD-6): cancelling adds back stock that was never taken, so the count grows past reality.
## Impact query (after order #7)
SELECT p.sku, p.stock, SUM(i.quantity) AS ordered
FROM products p
JOIN order_items i ON i.product_id = p.id
JOIN orders o ON o.id = i.order_id
WHERE p.sku = 'BK-103' AND o.status <> 'CANCELLED'
GROUP BY p.sku;
-- sku | stock | ordered
-- BK-103 | 3 | 5 - Another product and the API instead of the UI: still broken. So it is the server, and it is not about one product.line 9
- The real damage: the order is accepted although only 3 copies ever existed. This line raises the severity.line 12
- A second symptom from the same cause. Mention it in the same report, not as a new bug.line 14
- The shortest steps that still show it. Developers start from this line.line 18
- Cancelled orders do not count, so this is what customers are waiting for.line 27
Decide severity and priority, with reasons
Separate how bad the bug is from how soon it must be fixed, and write down why for both.
Severity is the impact when the bug happens: data loss, wrong money, a crash, or a cosmetic glitch. The tester sets it from the evidence. Priority is how soon to fix it compared with other work. The tester proposes it; the product owner or the triage meeting decides.
They often match, but not always: a typo in the shop's name on the home page is low severity and high priority; a crash in a rarely used admin export can be high severity and lower priority. Names differ between teams. Jira's built-in Priority field uses Highest, High, Medium, Low and Lowest, and teams usually add Severity as a custom field.
Save the reasoning below as evidence/triage.md. The comparison table puts this bug next to others from the exploratory session, which is how a triage meeting sees it.
# Severity and priority for BUG-101
## Severity: Critical (how bad is it when it happens?)
- Data integrity: the stock in the database is wrong after every single order.
- It causes a second failure: the shop sells copies it does not have (ORD-3).
- Every customer and every product, with no workaround for customers.
## Priority: P1, Highest (how soon must it be fixed?)
- Checkout is the main money path. Each day live means more orders that cannot be shipped,
refunds and support tickets.
- Fix before the next release; it blocks sign-off of the checkout feature.
## For comparison
| Bug | Severity | Priority | Why |
| ------------------------------------------- | -------- | -------- | --- |
| Stock not reduced (BUG-101) | Critical | Highest | wrong data on every order, overselling |
| Customer can open another's order (ORD-7) | Critical | Highest | privacy: one customer sees another's data |
| SAVE10 refused at exactly $50.00 (PRICE-3) | Major | High | wrong price at one boundary, workaround: add an item |
| Order page shows "Discount -$0.00" | Trivial | Low | cosmetic, numbers are right | - Severity answers "how bad?" and comes from the evidence, not from how annoyed you are.line 3
- The overselling you found in step 4 is what makes this Critical rather than Major.line 5
- Priority answers "how soon?". It weighs business impact and the release plan.line 8
- Showing a trivial bug next to a critical one makes your scale believable.line 19
Write the report
One page a developer can act on without asking you a single question.
Most trackers (Jira, Azure DevOps, GitHub Issues, Linear) have the same parts. Save the report below as BUG-101-stock-not-reduced.md and fill in the angle-bracket fields with your own details.
Check it with these questions: Does the title say what is wrong and where, without opening the ticket? Do the steps start from a known state and use exact values? Is expected tied to a requirement id? Does actual give numbers? Is every claim backed by an attachment? Is there anything a developer would have to ask you?
# BUG-101: Placing an order does not reduce product stock, so the shop oversells
| Field | Value |
| --------------- | ----- |
| Type | Bug |
| Component | Orders / inventory |
| Affects version | ShopRung 1.0.0 |
| Requirement | ORD-2 (also breaks ORD-3 and ORD-6) |
| Severity | Critical |
| Priority | Highest (P1) |
| Reproducible | Always: 3 of 3 tries, in the UI and the API |
| Reporter | <your name> |
| Labels | inventory, checkout, data-integrity |
## Environment
- ShopRung 1.0.0 (GET /api/health), local, http://localhost:8080, started with npm start
- Node.js <version>, <your OS and version>, <your browser and version>
- Data: seed data after POST /api/test/reset
- Bug switch: stock-not-reduced on
## Steps to reproduce
1. Reset the data: POST /api/test/reset
2. Open the shop. The Bug Hunter's Diary (BK-103) shows "3 in stock".
3. Log in as alice@shoprung.test.
4. Open The Bug Hunter's Diary, set Quantity to 2, click Add to cart.
5. Open Cart, click Place order.
6. Click Products and look at The Bug Hunter's Diary again.
## Expected
"1 in stock". ORD-2: "Placing an order reduces each product's stock by the quantity ordered."
## Actual
The order is placed (Order #3, PLACED, total $42.97), but the product still shows "3 in stock".
The API (GET /api/products/3) and the database (products.stock for BK-103) both still say 3.
## Impact
- Overselling (ORD-3): after Alice's order, Bob could order 3 more. 5 copies ordered, 3 exist.
- Cancelling adds stock that was never taken (ORD-6): cancelling order #3 sets the stock to 5.
- Happens on every order, product, customer and coupon, through the UI and the API.
## Attachments
1. evidence/network.http: POST /api/orders (201) and GET /api/products/3 (stock 3)
2. evidence/database.sql: the queries and their results, before and after
3. evidence/narrowing.md: the variations tried and the impact query
4. repro.sh: one command that reproduces it (exits 1 while the bug is present)
5. after-order.png: the product list after the order, still "3 in stock"
## Notes
- The orders and order_items rows are written correctly. Only products.stock is not updated.
- Not checked: admin ship and deliver (no stock change is expected there). - What is wrong, where, and why it matters, in one line. Search finds it later by these words.line 1
- The requirement id turns "I think this is wrong" into "this breaks rule ORD-2".line 8
- From the reproduction log in step 1.line 11
- Version, how it was run, the data and the switch state. Leave out nothing a developer needs to get the same result.line 15
- Steps start from a known state. Without step 1, the order number and stock could be anything.line 22
- Expected, quoted from the requirement. No opinion needed.line 30
- Saying the API and the database agree tells the developer it is a server bug, not a display bug.line 34
- Every claim above has a file here. Name files by what they show.line 41
- A hint from the SQL evidence, not a guess at the code. Report facts; leave the fix to the developer.line 49
Stuck on this step?
- My report is getting long
- Keep the top short (title, fields, steps, expected, actual) and move detail to attachments. A developer reads the top 20 lines first.
Repeat it from the API with curl
One command that reproduces the bug, so anyone can check it, and later check the fix.
Steps in a browser take a minute and can go wrong. A script takes a second and does the same thing every time. This one resets the data, reads the stock, logs in as Alice, adds 2 copies, places the order and reads the stock again. It exits with 1 while the bug is there and 0 once it is fixed, so it can become an automated check later.
Save it as repro.sh in the bug-101 folder and run it. On Windows run it from Git Bash (it comes with Git for Windows); the Java and Python versions in the next step run anywhere.
#!/usr/bin/env bash
# BUG-101 repro: placing an order must reduce the product's stock (ShopRung requirement ORD-2).
# Run: bash repro.sh Another port: BASE=http://localhost:8081 bash repro.sh
set -euo pipefail
BASE="${BASE:-http://localhost:8080}"
JSON='Content-Type: application/json'
stock() { curl -fsS "$BASE/api/products/3" | sed -E 's/.*"stock":([0-9]+).*/\1/'; }
curl -fsS -X POST "$BASE/api/test/reset" > /dev/null
BEFORE=$(stock)
TOKEN=$(curl -fsS "$BASE/api/auth/login" -H "$JSON" \
-d '{"email":"alice@shoprung.test","password":"Alice123!"}' | sed -E 's/.*"token":"([^"]+)".*/\1/')
curl -fsS "$BASE/api/cart/items" -H "$JSON" -H "Authorization: Bearer $TOKEN" \
-d '{"productId":3,"quantity":2}' > /dev/null
ORDER=$(curl -fsS -X POST "$BASE/api/orders" -H "Authorization: Bearer $TOKEN" | sed -E 's/^\{"id":([0-9]+).*/\1/')
AFTER=$(stock)
echo "Order $ORDER placed for 2 copies. Stock before: $BEFORE, after: $AFTER, expected: $((BEFORE - 2))"
if [ "$AFTER" -ne $((BEFORE - 2)) ]; then
echo "BUG-101 REPRODUCED: the stock did not go down (ORD-2)"
exit 1
fi
echo "OK: the stock went down by 2" - Stop at the first failing command, so a broken step cannot look like a pass.line 4
-fmakes curl fail on a 4xx or 5xx.sedpicks the number after"stock":out of the JSON.line 8- Start from the seed data, like step 1 of the report.line 10
- Log in and keep the token. It is only in memory, never printed.line 12
- The check: the exit code says whether the bug is there. That is what a CI job reads.line 20
bash repro.sh; echo "exit code: $?" Order 3 placed for 2 copies. Stock before: 3, after: 3, expected: 1 BUG-101 REPRODUCED: the stock did not go down (ORD-2) exit code: 1
Stuck on this step?
curl: (7) Failed to connect- ShopRung is not running on that port. Start it, or run
BASE=http://localhost:8081 bash repro.shif it is on 8081. curl: (22) The requested URL returned error: 401- The login failed, so the token is empty. Check the email and password in the script; the
!must stay inside single quotes.
The same repro as a small program
The repro in Java or Python with no libraries: the first step from a bug report to an automated test.
Developers and SDETs often attach a repro in the project's language. This one does exactly what repro.sh does, with only what comes with Java 21 or Python 3.12, so there is nothing to install. Switch between Java and Python at the top of the steps.
Java 11 and later can run a single source file directly, without compiling it first: java path/to/File.java. The pom.xml in the download only marks the folder as a Java project for your IDE.
package repro;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** BUG-101 repro: placing an order must reduce the product's stock (ShopRung requirement ORD-2). */
public class StockNotReduced {
static final String BASE = System.getenv().getOrDefault("BASE", "http://localhost:8080");
static final HttpClient HTTP = HttpClient.newHttpClient();
public static void main(String[] args) throws Exception {
send("POST", "/api/test/reset", null, null);
int before = stock(3);
String login = send("POST", "/api/auth/login", "{\"email\":\"alice@shoprung.test\",\"password\":\"Alice123!\"}", null);
String token = field(login, "token");
send("POST", "/api/cart/items", "{\"productId\":3,\"quantity\":2}", token);
String order = send("POST", "/api/orders", null, token);
int after = stock(3);
System.out.printf("Order %s placed for 2 copies. Stock before: %d, after: %d, expected: %d%n",
field(order, "id"), before, after, before - 2);
if (after != before - 2) {
System.out.println("BUG-101 REPRODUCED: the stock did not go down (ORD-2)");
System.exit(1);
}
System.out.println("OK: the stock went down by 2");
}
static int stock(int productId) throws Exception {
return Integer.parseInt(field(send("GET", "/api/products/" + productId, null, null), "stock"));
}
/** Sends one request and returns the body. Any 4xx or 5xx stops the repro with the status and the body. */
static String send(String method, String path, String json, String token) throws Exception {
HttpRequest.Builder b = HttpRequest.newBuilder(URI.create(BASE + path))
.header("Content-Type", "application/json")
.method(method, json == null ? HttpRequest.BodyPublishers.noBody() : HttpRequest.BodyPublishers.ofString(json));
if (token != null) b.header("Authorization", "Bearer " + token);
HttpResponse<String> r = HTTP.send(b.build(), HttpResponse.BodyHandlers.ofString());
if (r.statusCode() >= 400) throw new IllegalStateException(method + " " + path + " -> " + r.statusCode() + " " + r.body());
return r.body();
}
/** The first value called name in a JSON text. Enough for a repro; a test project uses a JSON library. */
static String field(String json, String name) {
Matcher m = Pattern.compile("\"" + name + "\":\"?([^\",}]+)").matcher(json);
if (!m.find()) throw new IllegalStateException("No " + name + " in " + json);
return m.group(1);
}
} - The address comes from the BASE environment variable, so the same file works on another port or a test server.line 12
- Start from the seed data, as in the report's step 1.line 16
- The assertion. Exit code 1 while the bug is there; a test framework would turn this into a failing test.line 26
- Any error stops the repro with the status and the body, so a login problem is never mistaken for the bug.line 44
- A tiny regular expression instead of a JSON library keeps it dependency-free. Real test projects use Jackson or REST Assured.line 50
"""BUG-101 repro: placing an order must reduce the product's stock (ShopRung requirement ORD-2)."""
import json
import os
import sys
import urllib.request
BASE = os.environ.get("BASE", "http://localhost:8080")
def send(method, path, body=None, token=None):
"""Send one request and return the JSON reply. A 4xx or 5xx raises an HTTPError with the status."""
data = json.dumps(body).encode() if body is not None else None
req = urllib.request.Request(BASE + path, data=data, method=method, headers={"Content-Type": "application/json"})
if token:
req.add_header("Authorization", f"Bearer {token}")
with urllib.request.urlopen(req, timeout=10) as resp:
return json.load(resp)
def stock(product_id):
return send("GET", f"/api/products/{product_id}")["stock"]
send("POST", "/api/test/reset")
before = stock(3)
token = send("POST", "/api/auth/login", {"email": "alice@shoprung.test", "password": "Alice123!"})["token"]
send("POST", "/api/cart/items", {"productId": 3, "quantity": 2}, token)
order = send("POST", "/api/orders", token=token)
after = stock(3)
print(f"Order {order['id']} placed for 2 copies. Stock before: {before}, after: {after}, expected: {before - 2}")
if after != before - 2:
print("BUG-101 REPRODUCED: the stock did not go down (ORD-2)")
sys.exit(1)
print("OK: the stock went down by 2") - The address comes from the BASE environment variable, so the same file works on another port.line 7
urllibcomes with Python. It raisesHTTPErrorfor 4xx and 5xx, so a failed login stops the script.line 16- Start from the seed data, as in the report's step 1.line 24
- The assertion. In pytest this becomes
assert after == before - 2.line 32
Python version of this step:
java src/main/java/repro/StockNotReduced.java; echo "exit code: $?" Order 3 placed for 2 copies. Stock before: 3, after: 3, expected: 1 BUG-101 REPRODUCED: the stock did not go down (ORD-2) exit code: 1
python3 repro.py; echo "exit code: $?" Order 3 placed for 2 copies. Stock before: 3, after: 3, expected: 1 BUG-101 REPRODUCED: the stock did not go down (ORD-2) exit code: 1
Stuck on this step?
- Windows:
echo "exit code: $?"prints True or False - In PowerShell use
java src/main/java/repro/StockNotReduced.java; echo "exit code: $LASTEXITCODE"(andpython repro.pyinstead ofpython3). java.net.ConnectExceptionorURLError: Connection refused- ShopRung is not running on port 8080. Start it, or set
BASEto the right address first.
Retest the fix, then write up order-leak yourself
Close the loop the way a tester does after a fix, and practise the whole report on a second bug.
When a developer says "fixed", you retest: run the same repro on the new build and check the original steps in the UI. Here, switching the bug off plays the part of the fix (Windows: stop ShopRung, run Remove-Item Env:SHOPRUNG_BUGS, then npm start):
curl -X POST http://localhost:8080/api/test/bugs -H "Content-Type: application/json" -d '{"enabled":[]}'
bash repro.sh; echo "exit code: $?"
The repro now prints OK and exits with 0. Do the UI steps once more too: the stock goes from 3 to 1. Then you would close BUG-101, and the repro becomes a regression test in the automated suite so the bug cannot come back unnoticed.
Your turn: order-leak. Switch it on with {"enabled":["order-leak"]}, reset, log in as Bob and open http://localhost:8080/#/order/1: Bob sees Alice's order #1 (Green Build Mug x2, $34.99). In the Network tab, GET /api/orders/1 with Bob's token returns 200 and "userId":1. With the bug off, the same request returns 404 {"error":"not_found","message":"No order with id 1"} (ORD-7). Bob can also click Cancel order on Alice's orders that are still PLACED or PAID. Write BUG-102 with the same template: requirement, evidence, severity and priority with reasons.
bash repro.sh; echo "exit code: $?" Order 3 placed for 2 copies. Stock before: 3, after: 1, expected: 1 OK: the stock went down by 2 exit code: 0
Stuck on this step?
- The repro still says REPRODUCED after switching off
- Check
curl http://localhost:8080/api/test/bugsshows"active":[]. On Windows the environment variable is still set in the ShopRung window: stop it, runRemove-Item Env:SHOPRUNG_BUGS, and start again.
Check it works
Your report is ready when every line is true:
The title says what is wrong and where, and the report names ORD-2.
The steps start from a reset and give exact values (product, quantity, account).
Expected quotes the requirement; actual gives numbers (stock 3, expected 1).
Severity and priority each have a reason, and they are separate decisions.
evidence/has the reproduction log, the network capture (token removed), the SQL before and after, and the narrowing table.The repro fails (exit code 1) with the bug on and passes (exit code 0) with it off.
bash repro.sh; echo "exit code: $?" Order 3 placed for 2 copies. Stock before: 3, after: 3, expected: 1 BUG-101 REPRODUCED: the stock did not go down (ORD-2) exit code: 1
Troubleshooting
The yellow bar shows other bugs too
Something else is switched on (for example mystery mode from the last lab). Send {"enabled":["stock-not-reduced"]} again: it replaces the whole list.
My numbers differ from the lab (order #5, stock 1)
The data was not reset, or the bug is off. Reset, check the yellow bar, and start again from step 1 of the report.
Windows: curl -X POST fails in PowerShell
In Windows PowerShell 5, curl is a different command. Use curl.exe. For the JSON body, the Java and Python repros are easier than quoting JSON in PowerShell.
The SQL console shows old numbers
Click Run query again after each action; the result does not refresh by itself.
bash: repro.sh: No such file or directory
Run it from the bug-101 folder where you saved it, or give the full path.
What changes in production
- Reports link to requirements and tests. At work the ticket links the user story or requirement, and once fixed, the repro becomes an automated regression test linked from the ticket.
- Evidence is cleaned before it is shared. Tokens, cookies, passwords and real customer data are removed from screenshots, cURL copies and HAR files. Many teams have a rule against attaching raw HAR files at all.
- Triage decides priority. Testers propose severity and priority; a regular triage meeting (or the product owner) sets priority against everything else in the backlog.
- On real systems you rarely have a bug switch or a reset endpoint. You start from a test account and test data you can recreate, and you add logs or a request id from the response headers so the developer can find your exact request.
Interview angle
“What makes a good bug report? Walk me through one you wrote.”
A good report lets a developer reproduce the bug without asking me anything. I start from a known state, give exact steps and values, and state expected versus actual, with expected tied to a requirement. Then evidence: the request and response from the Network tab, so it is clear whether the server or the UI is wrong, and a database query before and after. Before writing I narrow it down by changing one thing at a time, which gives the minimal repro and the real impact. For example, an order that did not reduce stock looked minor until I showed it also let a second customer buy copies that did not exist, which made it critical. I set severity from the impact and propose priority with a reason, and I attach a small script that fails while the bug is there, so retesting the fix is one command.
Clean up
Switch the bugs off (step 9) and stop ShopRung with Ctrl+C. Keep the bug-101 folder: later labs turn repro.py and StockNotReduced.java into real automated tests.
Practice
These run in your browser and check your answer.
Check a report before you send it
Write missing_sections(report) that returns the required headings a Markdown bug report is missing, in this order: "## Environment", "## Steps to reproduce", "## Expected", "## Actual", "## Attachments". A heading counts only when it is a whole line on its own (spaces at the end are fine). Return an empty list when nothing is missing.
REQUIRED = ["## Environment", "## Steps to reproduce", "## Expected", "## Actual", "## Attachments"]
def missing_sections(report):
missing = []
# your code here
return missing
print(missing_sections("# BUG-1\n## Expected\nok\n## Actual\nnot ok\n"))
Hint
Split the report into lines, strip the spaces at the end of each line with `rstrip()`, put them in a set, and keep each required heading that is not in it.
The full project
Every file from this lab, as it is after the last step.