@botlearn/refactor 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +35 -0
- package/knowledge/anti-patterns.md +92 -0
- package/knowledge/best-practices.md +147 -0
- package/knowledge/domain.md +193 -0
- package/manifest.json +28 -0
- package/package.json +38 -0
- package/skill.md +48 -0
- package/strategies/main.md +150 -0
- package/tests/benchmark.json +496 -0
- package/tests/smoke.json +64 -0
package/tests/smoke.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.0.1",
|
|
3
|
+
"timeout": 60,
|
|
4
|
+
"tasks": [
|
|
5
|
+
{
|
|
6
|
+
"id": "smoke-01",
|
|
7
|
+
"description": "Refactor a class with multiple code smells including Long Method, Feature Envy, and duplicated logic to improve readability and reduce complexity",
|
|
8
|
+
"input": "Refactor the following OrderProcessor class. It has a single 80-line processOrder method that handles validation, discount calculation, tax computation, inventory checks, and email notifications. The discount logic is duplicated in both processOrder and a separate generateQuote method. The method accesses customer.address, customer.loyaltyTier, and customer.email more than its own fields (Feature Envy). Cyclomatic complexity is 25. Target: reduce complexity by at least 40%, eliminate duplication, and resolve Feature Envy while maintaining identical order processing behavior.\n\n```python\nclass OrderProcessor:\n def __init__(self, db, mailer, inventory):\n self.db = db\n self.mailer = mailer\n self.inventory = inventory\n\n def process_order(self, order, customer):\n # Validate order\n if not order.items:\n raise ValueError(\"Empty order\")\n for item in order.items:\n if item.quantity <= 0:\n raise ValueError(f\"Invalid quantity for {item.name}\")\n if item.price < 0:\n raise ValueError(f\"Invalid price for {item.name}\")\n stock = self.inventory.check(item.sku)\n if stock < item.quantity:\n raise ValueError(f\"Insufficient stock for {item.name}\")\n\n # Calculate subtotal\n subtotal = 0\n for item in order.items:\n subtotal += item.price * item.quantity\n\n # Apply discount (DUPLICATED in generate_quote)\n discount = 0\n if customer.loyalty_tier == \"gold\":\n if subtotal > 500:\n discount = subtotal * 0.15\n elif subtotal > 200:\n discount = subtotal * 0.10\n else:\n discount = subtotal * 0.05\n elif customer.loyalty_tier == \"silver\":\n if subtotal > 500:\n discount = subtotal * 0.10\n elif subtotal > 200:\n discount = subtotal * 0.07\n else:\n discount = subtotal * 0.03\n elif customer.loyalty_tier == \"bronze\":\n if subtotal > 300:\n discount = subtotal * 0.05\n else:\n discount = subtotal * 0.02\n\n discounted = subtotal - discount\n\n # Calculate tax based on address\n if customer.address.state in [\"CA\", \"NY\", \"TX\"]:\n tax_rate = 0.08\n elif customer.address.state in [\"OR\", \"MT\", \"NH\"]:\n tax_rate = 0.0\n else:\n tax_rate = 0.06\n tax = discounted * tax_rate\n total = discounted + tax\n\n # Reserve inventory\n for item in order.items:\n self.inventory.reserve(item.sku, item.quantity)\n\n # Save order\n order.subtotal = subtotal\n order.discount = discount\n order.tax = tax\n order.total = total\n order.status = \"confirmed\"\n self.db.save(order)\n\n # Send confirmation\n self.mailer.send(\n to=customer.email,\n subject=f\"Order {order.id} Confirmed\",\n body=f\"Total: ${total:.2f} (discount: ${discount:.2f})\"\n )\n return order\n\n def generate_quote(self, order, customer):\n subtotal = sum(i.price * i.quantity for i in order.items)\n # DUPLICATED discount logic\n discount = 0\n if customer.loyalty_tier == \"gold\":\n if subtotal > 500:\n discount = subtotal * 0.15\n elif subtotal > 200:\n discount = subtotal * 0.10\n else:\n discount = subtotal * 0.05\n elif customer.loyalty_tier == \"silver\":\n if subtotal > 500:\n discount = subtotal * 0.10\n elif subtotal > 200:\n discount = subtotal * 0.07\n else:\n discount = subtotal * 0.03\n elif customer.loyalty_tier == \"bronze\":\n if subtotal > 300:\n discount = subtotal * 0.05\n else:\n discount = subtotal * 0.02\n return {\"subtotal\": subtotal, \"discount\": discount, \"total\": subtotal - discount}\n```",
|
|
9
|
+
"rubric": [
|
|
10
|
+
{
|
|
11
|
+
"criterion": "Smell Detection",
|
|
12
|
+
"weight": 0.2,
|
|
13
|
+
"scoring": {
|
|
14
|
+
"5": "Identifies all major smells: Long Method, Feature Envy (customer access), duplicated discount logic, Switch Statements (loyalty tier), and computes baseline cyclomatic complexity",
|
|
15
|
+
"3": "Identifies 2-3 smells but misses some or does not compute metrics",
|
|
16
|
+
"1": "Identifies only 1 smell or describes issues vaguely without naming specific smells",
|
|
17
|
+
"0": "No smell detection performed"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"criterion": "Refactoring Plan Quality",
|
|
22
|
+
"weight": 0.2,
|
|
23
|
+
"scoring": {
|
|
24
|
+
"5": "Presents ordered, incremental steps: extract discount calculation, extract tax calculation, extract validation, move discount logic to customer/strategy, eliminate duplication; each step has clear rationale",
|
|
25
|
+
"3": "Provides a refactoring plan but steps are not well-ordered or some are missing",
|
|
26
|
+
"1": "Vague suggestions like 'split the method' without specific steps",
|
|
27
|
+
"0": "No plan provided; jumps directly to rewriting"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"criterion": "Transformation Quality",
|
|
32
|
+
"weight": 0.25,
|
|
33
|
+
"scoring": {
|
|
34
|
+
"5": "Extracted methods/classes are well-named and cohesive; discount duplication eliminated via shared method or Strategy pattern; Feature Envy resolved by moving logic to appropriate class; complexity significantly reduced",
|
|
35
|
+
"3": "Some extractions performed but naming is poor, or duplication is only partially resolved",
|
|
36
|
+
"1": "Minimal structural changes; code is rearranged but smells remain",
|
|
37
|
+
"0": "No meaningful transformation applied"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"criterion": "Behavioral Equivalence",
|
|
42
|
+
"weight": 0.2,
|
|
43
|
+
"scoring": {
|
|
44
|
+
"5": "Explicitly verifies that all discount calculations, tax rates, validation errors, inventory reservations, and email sending produce identical results; notes which tests would cover each behavior",
|
|
45
|
+
"3": "Claims equivalence but does not verify specific behaviors or misses edge cases",
|
|
46
|
+
"1": "No equivalence verification; changes may alter behavior",
|
|
47
|
+
"0": "Introduces obvious behavioral changes without acknowledging them"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"criterion": "Quality Metrics Improvement",
|
|
52
|
+
"weight": 0.15,
|
|
53
|
+
"scoring": {
|
|
54
|
+
"5": "Reports before/after cyclomatic complexity, cognitive complexity, and duplication metrics; achieves 40%+ complexity reduction; duplication eliminated",
|
|
55
|
+
"3": "Reports some metrics but improvement is modest (20-39%) or not all metrics are measured",
|
|
56
|
+
"1": "No metrics reported; improvement is claimed but not quantified",
|
|
57
|
+
"0": "No measurement performed"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
],
|
|
61
|
+
"passThreshold": 60
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
}
|