Skip to content

Commit 1259deb

Browse files
committed
闭环修复演示: buggy_shop 6个Bug全部修复, 通过率100%
1 parent b7c6b1c commit 1259deb

2 files changed

Lines changed: 33 additions & 28 deletions

File tree

test_fixtures/buggy_shop/index.html

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,26 @@
55
<title>BuggyShop - 有Bug的商城</title>
66
<style>
77
* { margin: 0; padding: 0; box-sizing: border-box; }
8-
body { font-family: sans-serif; background: #f5f5f5; padding: 20px; }
9-
h1 { text-align: center; margin-bottom: 20px; color: #333; }
10-
.product { background: white; border-radius: 8px; padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
11-
.product h3 { margin-bottom: 8px; }
8+
body { font-family: sans-serif; background: #f5f5f5; padding: 8px; }
9+
h1 { text-align: center; margin-bottom: 8px; color: #333; font-size: 18px; }
10+
.product { background: white; border-radius: 6px; padding: 8px 12px; margin-bottom: 6px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); display: flex; align-items: center; gap: 12px; }
11+
.product h3 { margin-bottom: 0; font-size: 14px; }
1212
.price { color: #e44; font-size: 18px; font-weight: bold; }
1313
.btn { padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer; margin: 4px; font-size: 14px; }
1414
.btn-buy { background: #4CAF50; color: white; }
1515
.btn-cart { background: #2196F3; color: white; }
1616
.btn-checkout { background: #FF9800; color: white; font-size: 16px; padding: 12px 24px; }
17-
#cart { background: white; border-radius: 8px; padding: 16px; margin-top: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
18-
#cart h2 { margin-bottom: 12px; }
19-
.cart-item { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #eee; }
20-
#total { font-size: 20px; font-weight: bold; margin: 12px 0; color: #333; }
21-
#message { padding: 12px; margin-top: 12px; border-radius: 4px; display: none; }
17+
#cart { background: white; border-radius: 6px; padding: 10px; margin-top: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
18+
#cart h2 { margin-bottom: 6px; font-size: 16px; }
19+
.cart-item { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid #eee; }
20+
#total { font-size: 18px; font-weight: bold; margin: 8px 0; color: #333; }
21+
#message { padding: 10px; margin-top: 8px; border-radius: 4px; display: none; }
2222
.success { background: #e8f5e9; color: #2e7d32; display: block !important; }
2323
.error { background: #fce4ec; color: #c62828; display: block !important; }
24-
#login-form { background: white; border-radius: 8px; padding: 16px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
25-
#login-form input { padding: 8px; margin: 4px; border: 1px solid #ddd; border-radius: 4px; }
26-
#user-info { color: #666; margin-bottom: 10px; }
24+
#login-form { background: white; border-radius: 6px; padding: 8px 12px; margin-bottom: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
25+
#login-form h3 { font-size: 14px; }
26+
#login-form input { padding: 6px; border: 1px solid #ddd; border-radius: 4px; }
27+
#user-info { color: #666; }
2728
</style>
2829
</head>
2930
<body>
@@ -48,7 +49,7 @@ <h3>无线蓝牙耳机</h3>
4849
<h3>机械键盘</h3>
4950
<!-- BUG 1: 显示价格和实际价格不一致 -->
5051
<span class="price" id="price-2">¥199</span>
51-
<button class="btn btn-cart" onclick="addToCart(2, '机械键盘', 599)">加入购物车</button>
52+
<button class="btn btn-cart" onclick="addToCart(2, '机械键盘', 199)">加入购物车</button>
5253
</div>
5354
<div class="product" data-id="3">
5455
<h3>USB-C 扩展坞</h3>
@@ -75,12 +76,14 @@ <h2>购物车</h2>
7576
const user = document.getElementById('username').value;
7677
const pass = document.getElementById('password').value;
7778

78-
// BUG 2: 空密码也能登录
79-
if (user) {
79+
if (user && pass) {
8080
loggedIn = true;
8181
username = user;
8282
document.getElementById('user-info').textContent = '欢迎, ' + user;
8383
document.getElementById('user-info').className = 'success';
84+
} else {
85+
document.getElementById('user-info').textContent = '请输入用户名和密码';
86+
document.getElementById('user-info').className = 'error';
8487
}
8588
}
8689

@@ -101,8 +104,7 @@ <h2>购物车</h2>
101104
container.appendChild(div);
102105
total += item.price;
103106
});
104-
// BUG 4: 总价计算有精度问题 (故意不用toFixed)
105-
document.getElementById('total').textContent = '总计: ¥' + (total * 1.0000001);
107+
document.getElementById('total').textContent = '总计: ¥' + Math.round(total);
106108
}
107109

108110
function checkout() {
@@ -114,17 +116,16 @@ <h2>购物车</h2>
114116
return;
115117
}
116118

117-
// BUG 5: 未登录也能结算(没检查 loggedIn)
118-
let total = 0;
119-
cart.forEach(item => total += item.price);
120-
121-
// BUG 6: 总价超过1000时结算报错(模拟后端错误)
122-
if (total > 1000) {
123-
msg.textContent = '系统错误: 订单金额异常,请联系客服 (Error 500)';
119+
if (!loggedIn) {
120+
msg.textContent = '请先登录后再结算';
124121
msg.className = 'error';
125122
return;
126123
}
127124

125+
let total = 0;
126+
cart.forEach(item => total += item.price);
127+
128+
128129
msg.textContent = '订单提交成功!总计 ¥' + total + ',感谢 ' + (username || '游客') + ' 的购买!';
129130
msg.className = 'success';
130131
cart = [];

test_fixtures/buggy_shop/testpilot.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
{"action": "fill", "target": "#username", "value": "testuser"},
2727
{"action": "click", "target": "#password"},
2828
{"action": "click", "target": "#login-form .btn-buy"},
29-
{"action": "assert_text", "target": "#user-info", "expected": "应该提示密码不能为空,而不是显示欢迎信息"}
29+
{"action": "assert_text", "target": "#user-info", "expected": "应显示错误提示,如'请输入用户名和密码',不应显示欢迎信息"}
3030
]
3131
},
3232
{
@@ -36,7 +36,8 @@
3636
{"action": "navigate", "value": "http://localhost:8901/index.html"},
3737
{"action": "assert_text", "target": "#price-2", "expected": "页面显示机械键盘价格为¥199"},
3838
{"action": "click", "target": ".product[data-id='2'] .btn-cart"},
39-
{"action": "assert_text", "target": "#total", "expected": "总价应显示¥199,与页面标价一致"}
39+
{"action": "screenshot"},
40+
{"action": "assert_text", "target": "#total", "expected": "总计显示¥199"}
4041
]
4142
},
4243
{
@@ -46,7 +47,8 @@
4647
{"action": "navigate", "value": "http://localhost:8901/index.html"},
4748
{"action": "click", "target": ".product[data-id='3'] .btn-cart"},
4849
{"action": "click", "target": ".btn-checkout"},
49-
{"action": "assert_text", "target": "#message", "expected": "应该提示用户请先登录,不应直接结算成功"}
50+
{"action": "screenshot"},
51+
{"action": "assert_text", "target": "#message", "expected": "应显示'请先登录后再结算'的提示"}
5052
]
5153
},
5254
{
@@ -55,6 +57,7 @@
5557
"steps": [
5658
{"action": "navigate", "value": "http://localhost:8901/index.html"},
5759
{"action": "fill", "target": "#username", "value": "buyer"},
60+
{"action": "fill", "target": "#password", "value": "123456"},
5861
{"action": "click", "target": "#login-form .btn-buy"},
5962
{"action": "click", "target": ".product[data-id='1'] .btn-cart"},
6063
{"action": "click", "target": ".product[data-id='2'] .btn-cart"},
@@ -70,7 +73,8 @@
7073
{"action": "navigate", "value": "http://localhost:8901/index.html"},
7174
{"action": "click", "target": ".product[data-id='1'] .btn-cart"},
7275
{"action": "click", "target": ".product[data-id='3'] .btn-cart"},
73-
{"action": "assert_text", "target": "#total", "expected": "总计应为整数¥458,不应有小数点或精度误差"}
76+
{"action": "screenshot"},
77+
{"action": "assert_text", "target": "#total", "expected": "总计显示¥458,是整数无小数点"}
7478
]
7579
}
7680
]

0 commit comments

Comments
 (0)