Pipeline controller: plan 2 (hard +, error +50 %), backlog throttle, 2 trajectory workers, stop rules, summaries every 50; budget reserve

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Kral
2026-10-05 13:35:54 +02:00
parent 1c4667a0fc
commit 13360292dd
781 changed files with 50211 additions and 22 deletions

View File

@@ -0,0 +1,90 @@
CLASS {{p}}snow_fee_hidden DEFINITION PUBLIC FINAL CREATE PUBLIC
FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
DATA mo_cut TYPE REF TO {{p}}snow_fee.
METHODS setup.
METHODS assert_fee
IMPORTING iv_area TYPE {{p}}snow_fee=>ty_area
iv_priority TYPE {{p}}snow_fee=>ty_priority
iv_distance TYPE {{p}}snow_fee=>ty_distance
iv_expected TYPE {{p}}snow_fee=>ty_fee.
METHODS minimum_charge FOR TESTING.
METHODS small_area_rate FOR TESTING.
METHODS mid_area_rate FOR TESTING.
METHODS mid_area_upper FOR TESTING.
METHODS large_area_rate FOR TESTING.
METHODS express_surcharge FOR TESTING.
METHODS emergency_surcharge FOR TESTING.
METHODS unknown_priority FOR TESTING.
METHODS minimum_with_express FOR TESTING.
METHODS travel_charged FOR TESTING.
METHODS travel_not_surcharged FOR TESTING.
METHODS zero_area_returns_zero FOR TESTING.
ENDCLASS.
CLASS {{p}}snow_fee_hidden IMPLEMENTATION.
METHOD setup.
mo_cut = NEW {{p}}snow_fee( ).
ENDMETHOD.
METHOD assert_fee.
DATA lv_expected TYPE {{p}}snow_fee=>ty_fee.
lv_expected = iv_expected.
cl_abap_unit_assert=>assert_equals(
exp = lv_expected
act = mo_cut->calculate( iv_area = iv_area
iv_priority = iv_priority
iv_distance = iv_distance ) ).
ENDMETHOD.
METHOD minimum_charge.
assert_fee( iv_area = 100 iv_priority = 'S' iv_distance = 0 iv_expected = '45.00' ).
ENDMETHOD.
METHOD small_area_rate.
assert_fee( iv_area = 500 iv_priority = 'S' iv_distance = 0 iv_expected = '100.00' ).
ENDMETHOD.
METHOD mid_area_rate.
assert_fee( iv_area = 501 iv_priority = 'S' iv_distance = 0 iv_expected = '80.16' ).
ENDMETHOD.
METHOD mid_area_upper.
assert_fee( iv_area = 2000 iv_priority = 'S' iv_distance = 0 iv_expected = '320.00' ).
ENDMETHOD.
METHOD large_area_rate.
assert_fee( iv_area = 2001 iv_priority = 'S' iv_distance = 0 iv_expected = '240.12' ).
ENDMETHOD.
METHOD express_surcharge.
assert_fee( iv_area = 1000 iv_priority = 'E' iv_distance = 0 iv_expected = '200.00' ).
ENDMETHOD.
METHOD emergency_surcharge.
assert_fee( iv_area = 1000 iv_priority = 'X' iv_distance = 0 iv_expected = '240.00' ).
ENDMETHOD.
METHOD unknown_priority.
assert_fee( iv_area = 1000 iv_priority = 'Z' iv_distance = 0 iv_expected = '160.00' ).
ENDMETHOD.
METHOD minimum_with_express.
assert_fee( iv_area = 100 iv_priority = 'E' iv_distance = 0 iv_expected = '56.25' ).
ENDMETHOD.
METHOD travel_charged.
assert_fee( iv_area = 1000 iv_priority = 'S' iv_distance = 30 iv_expected = '168.00' ).
ENDMETHOD.
METHOD travel_not_surcharged.
assert_fee( iv_area = 1000 iv_priority = 'E' iv_distance = 30 iv_expected = '208.00' ).
ENDMETHOD.
METHOD zero_area_returns_zero.
assert_fee( iv_area = 0 iv_priority = 'X' iv_distance = 30 iv_expected = '0.00' ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,86 @@
CLASS {{p}}snow_fee DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
TYPES ty_area TYPE i.
TYPES ty_priority TYPE c LENGTH 1.
TYPES ty_distance TYPE i.
TYPES ty_fee TYPE p LENGTH 9 DECIMALS 2.
METHODS calculate
IMPORTING iv_area TYPE ty_area
iv_priority TYPE ty_priority
iv_distance TYPE ty_distance
RETURNING VALUE(rv_fee) TYPE ty_fee.
PRIVATE SECTION.
CONSTANTS:
c_rate_small TYPE ty_fee VALUE '0.20',
c_rate_medium TYPE ty_fee VALUE '0.16',
c_rate_large TYPE ty_fee VALUE '0.12',
c_rate_per_km TYPE ty_fee VALUE '0.40',
c_minimum_fee TYPE ty_fee VALUE '45.00',
c_free_km TYPE ty_distance VALUE 10,
c_priority_expr TYPE ty_priority VALUE 'E',
c_priority_emerg TYPE ty_priority VALUE 'X'.
METHODS base_fee
IMPORTING iv_area TYPE ty_area
iv_priority TYPE ty_priority
RETURNING VALUE(rv_fee) TYPE ty_fee.
METHODS rate_per_sqm
IMPORTING iv_area TYPE ty_area
RETURNING VALUE(rv_rate) TYPE ty_fee.
METHODS surcharge_factor
IMPORTING iv_priority TYPE ty_priority
RETURNING VALUE(rv_factor) TYPE i.
METHODS travel_cost
IMPORTING iv_distance TYPE ty_distance
RETURNING VALUE(rv_cost) TYPE ty_fee.
ENDCLASS.
CLASS {{p}}snow_fee IMPLEMENTATION.
METHOD calculate.
IF iv_area <= 0.
rv_fee = 0.
RETURN.
ENDIF.
rv_fee = base_fee( iv_area = iv_area iv_priority = iv_priority )
+ travel_cost( iv_distance = iv_distance ).
ENDMETHOD.
METHOD base_fee.
DATA(lv_amount) = iv_area * rate_per_sqm( iv_area ).
IF lv_amount < c_minimum_fee.
lv_amount = c_minimum_fee.
ENDIF.
rv_fee = lv_amount * surcharge_factor( iv_priority ) / 100.
ENDMETHOD.
METHOD rate_per_sqm.
IF iv_area <= 500.
rv_rate = c_rate_small.
ELSEIF iv_area <= 2000.
rv_rate = c_rate_medium.
ELSE.
rv_rate = c_rate_large.
ENDIF.
ENDMETHOD.
METHOD surcharge_factor.
CASE iv_priority.
WHEN c_priority_expr.
rv_factor = 125.
WHEN c_priority_emerg.
rv_factor = 150.
WHEN OTHERS.
rv_factor = 100.
ENDCASE.
ENDMETHOD.
METHOD travel_cost.
DATA(lv_chargeable_km) = iv_distance - c_free_km.
IF lv_chargeable_km > 0.
rv_cost = lv_chargeable_km * c_rate_per_km.
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,59 @@
CLASS ltc_snow_fee DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
DATA mo_cut TYPE REF TO {{p}}snow_fee.
METHODS setup.
METHODS assert_fee
IMPORTING iv_area TYPE {{p}}snow_fee=>ty_area
iv_priority TYPE {{p}}snow_fee=>ty_priority
iv_distance TYPE {{p}}snow_fee=>ty_distance
iv_expected TYPE {{p}}snow_fee=>ty_fee.
METHODS minimum_charge FOR TESTING.
METHODS small_area_rate FOR TESTING.
METHODS express_surcharge FOR TESTING.
METHODS travel_charged FOR TESTING.
METHODS zero_area_returns_zero FOR TESTING.
METHODS unknown_priority FOR TESTING.
ENDCLASS.
CLASS ltc_snow_fee IMPLEMENTATION.
METHOD setup.
mo_cut = NEW {{p}}snow_fee( ).
ENDMETHOD.
METHOD assert_fee.
DATA lv_expected TYPE {{p}}snow_fee=>ty_fee.
lv_expected = iv_expected.
cl_abap_unit_assert=>assert_equals(
exp = lv_expected
act = mo_cut->calculate( iv_area = iv_area
iv_priority = iv_priority
iv_distance = iv_distance ) ).
ENDMETHOD.
METHOD minimum_charge.
assert_fee( iv_area = 100 iv_priority = 'S' iv_distance = 0 iv_expected = '45.00' ).
ENDMETHOD.
METHOD small_area_rate.
assert_fee( iv_area = 500 iv_priority = 'S' iv_distance = 0 iv_expected = '100.00' ).
ENDMETHOD.
METHOD express_surcharge.
assert_fee( iv_area = 1000 iv_priority = 'E' iv_distance = 0 iv_expected = '200.00' ).
ENDMETHOD.
METHOD travel_charged.
assert_fee( iv_area = 1000 iv_priority = 'S' iv_distance = 30 iv_expected = '168.00' ).
ENDMETHOD.
METHOD zero_area_returns_zero.
assert_fee( iv_area = 0 iv_priority = 'X' iv_distance = 30 iv_expected = '0.00' ).
ENDMETHOD.
METHOD unknown_priority.
assert_fee( iv_area = 1000 iv_priority = 'Z' iv_distance = 0 iv_expected = '160.00' ).
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,64 @@
CLASS {{p}}snow_fee DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
TYPES ty_area TYPE i.
TYPES ty_priority TYPE c LENGTH 1.
TYPES ty_distance TYPE i.
TYPES ty_fee TYPE p LENGTH 9 DECIMALS 2.
METHODS calculate
IMPORTING iv_area TYPE ty_area
iv_priority TYPE ty_priority
iv_distance TYPE ty_distance
RETURNING VALUE(rv_fee) TYPE ty_fee.
ENDCLASS.
CLASS {{p}}snow_fee IMPLEMENTATION.
METHOD calculate.
" legacy implementation - the result must not change
DATA: lv_rate TYPE ty_fee,
lv_base TYPE ty_fee,
lv_sum TYPE ty_fee,
lv_km TYPE ty_distance.
rv_fee = 0.
IF iv_area > 0.
IF iv_area <= 500.
lv_rate = '0.20'.
ELSE.
IF iv_area <= 2000.
lv_rate = '0.16'.
ELSE.
lv_rate = '0.12'.
ENDIF.
ENDIF.
lv_base = iv_area * lv_rate.
IF lv_base < 45.
lv_base = 45.
ENDIF.
IF iv_priority = 'E'.
lv_base = lv_base * 125 / 100.
ELSE.
IF iv_priority = 'X'.
lv_base = lv_base * 150 / 100.
ENDIF.
ENDIF.
lv_sum = lv_base.
lv_km = iv_distance - 10.
IF lv_km > 0.
lv_rate = '0.40'.
lv_sum = lv_sum + lv_km * lv_rate.
ENDIF.
rv_fee = lv_sum.
ENDIF.
ENDMETHOD.
ENDCLASS.

View File

@@ -0,0 +1,52 @@
# 1. Goal
A winter service clears snow from the roads of its clients. The dispatcher calls
the class {{P}}SNOW_FEE for each snow clearing job. The class is in package $TMP
and is active. The code is legacy code: one long method, deep nesting and
hardcoded numbers. Refactor the class in place. The class name, the public types
and the public method stay the same. The behavior stays the same.
# 2. Open questions
None.
# 3. Context
- The class {{P}}SNOW_FEE is in package $TMP. It is active.
- The dispatcher calls the method CALCULATE for each job.
- The dispatcher gives the area of the site in square metres, the priority of the
job and the distance to the site in kilometres.
- The class is legacy code. No user reports an error. This is a refactoring
task: the result of the method must not change.
# 4. Contract
- The class {{P}}SNOW_FEE stays in package $TMP. Do not rename it.
- The class is public and final. It has a public constructor without parameters.
- The public section keeps these types:
- TY_AREA (TYPE i)
- TY_PRIORITY (TYPE c LENGTH 1)
- TY_DISTANCE (TYPE i)
- TY_FEE (TYPE p LENGTH 9 DECIMALS 2)
- The public section keeps one method:
CALCULATE
IMPORTING iv_area TYPE ty_area
iv_priority TYPE ty_priority
iv_distance TYPE ty_distance
RETURNING VALUE(rv_fee) TYPE ty_fee.
- Do not add other public methods. Do not change the signature.
# 5. Business rules
- The behavior of the class must stay exactly the same. The current
implementation is the only source of the rules.
- Read the legacy code before you change it. Keep every threshold, every
surcharge, every minimum and every special case.
- The hidden tests call the public method with the same input as the legacy code
and compare the result.
# 6. Constraints
- Release target: ABAP Platform 2025 (SAP_BASIS 816).
- Coding standards: Clean ABAP. Each method below 40 statements. No deep
nesting. Use constants for the numbers. No comment that restates the code.
- Out of scope: do not change the public interface; do not create other objects.
# 7. Acceptance
- The class is active and has no syntax error.
- The hidden tests pass.
- Write your own ABAP Unit tests for the class.

View File

@@ -0,0 +1,48 @@
{
"id": "G1042",
"category": "E",
"object_type": "CLAS",
"difficulty": 2,
"release_target": "v816",
"expected_outcome": "implement",
"budget": {
"max_tool_calls": 70,
"max_activations": 20
},
"seed": [
{
"type": "CLAS",
"name": "{{P}}SNOW_FEE",
"file": "seed/snow_fee.clas.abap",
"description": "Legacy class that calculates the fee of one snow clearing job"
}
],
"contract": [
{
"type": "CLAS",
"name": "{{P}}SNOW_FEE"
}
],
"out_of_scope": [],
"hidden_tests": [
{
"type": "CLAS",
"name": "{{P}}SNOW_FEE_HIDDEN",
"file": "hidden/snow_fee_hidden.clas.abap",
"description": "Hidden tests for the unchanged behavior of {{P}}SNOW_FEE"
}
],
"reference": [
{
"type": "CLAS",
"name": "{{P}}SNOW_FEE",
"file": "reference/snow_fee.clas.abap",
"description": "Refactored snow clearing fee calculation",
"testclasses_file": "reference/snow_fee.testclasses.abap"
}
],
"craft_checks": [
"method_length",
"db_operation_in_loop"
]
}