Add agent rehearsal harness, findings, and per-run evidence for split-loop-with-lambda

Six scripted pi sub-agent runs (3 tool regimes × 2 models) rehearsed the
exercise; deterministic gate = solution test + approved file. Key results:
mandated CLI triples cost on the strong model (4:06 vs 0:39, PASS both);
weak model fails only under the mandate (A+Q), passes when free or optional.
Drift documented with code: scorer.updateSelection left inside the extracted
method (A+Q, C+Q). Harness in tools/rehearse; summary in
rehearsal-findings.md; per-run evidence in rehearsal-runs/; cheat sheet in
rehearse-with-agent.md corrected (lambda-typed parameters unsupported).
This commit is contained in:
Your Name
2026-09-27 17:36:19 +00:00
parent a27e32688a
commit b993f25c53
51 changed files with 2281 additions and 2 deletions
@@ -0,0 +1,69 @@
Done. All three refactoring steps are complete; after each one `mvn -q test` compiled successfully (the remaining test failures are the pre-existing ones caused by `Scorer`'s use of `new Random().nextBoolean()` — the expected untestability, not a compile problem). Stopping here as instructed.
There's no git repo in the workspace, so here is the final state and a manual diff summary of `LongRangeForecasts.java`:
```java
package codingdojo;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.function.LongFunction;
public class LongRangeForecasts {
private final Scorer scorer = new Scorer();
public Map<IceCream, Integer> longRangeForecast() {
return longRangeForecast(daysForward -> {
scorer.updateSelection();
return scorer.lookupWeather(daysForward);
});
}
public Map<IceCream, Integer> longRangeForecast(LongFunction<Boolean> dayOffsetToWeather) {
var result = new HashMap<IceCream, Integer>();
for (IceCream flavour : IceCream.values()) {
result.put(flavour, 0);
}
List<Boolean> expectedWeather = collectExpectedWeather(dayOffsetToWeather);
for (IceCream flavour : result.keySet()) {
result.put(flavour, result.get(flavour) + 10);
var sunnyHolidays = expectedWeather.stream().filter(s -> s).count();
if (sunnyHolidays > 2 && flavour == IceCream.Vanilla) {
result.put(flavour, result.get(flavour) + 5);
}
if (sunnyHolidays > 1 && expectedWeather.get(1)) {
result.put(flavour, result.get(flavour) + 2);
}
}
return result;
}
private List<Boolean> collectExpectedWeather(LongFunction<Boolean> dayOffsetToWeather) {
List<Instant> interestingDates = List.of(
Instant.parse("2023-05-01T14:00:00.000-07:00"),
Instant.parse("2023-05-18T14:00:00.000-07:00"),
Instant.parse("2023-06-05T14:00:00.000-07:00"),
Instant.parse("2023-06-23T14:00:00.000-07:00")
);
List<Boolean> expectedWeather = new ArrayList<>();
for (Instant interestingDate : interestingDates) {
var forecastDate = Instant.parse("2023-04-26T14:00:00.000-07:00");
long daysForward = ChronoUnit.DAYS.between(forecastDate, interestingDate);
Boolean lookupWeather = dayOffsetToWeather.apply(daysForward);
expectedWeather.add(lookupWeather);
}
return expectedWeather;
}
}
```
**Diff summary** (relative to the original):
1. Added import `java.util.function.LongFunction`.
2. The scorer-dependent code (`scorer.updateSelection()` + `scorer.lookupWeather(daysForward)`) was extracted into a lambda, now passed in as `dayOffsetToWeather` (`LongFunction<Boolean>`); the invocation site (`dayOffsetToWeather.apply(daysForward)`) stayed in the loop.
3. The weather-collection loop (with `interestingDates`) moved into new private method `collectExpectedWeather(LongFunction<Boolean> dayOffsetToWeather)` returning `List<Boolean>`.
4. Signature changed from `longRangeForecast(String quarter)` to `longRangeForecast(LongFunction<Boolean> dayOffsetToWeather)`; the `String quarter` parameter and its `Q1`/`Q4` block were removed, and a public no-arg overload was added that delegates and wraps the `scorer` field in a lambda.
**Note:** the test call site in `src/test/java/codingdojo/LongRangeForecastsTest.java` was updated (`longRangeForecast(quarter)` → `longRangeForecast()`) so the project still compiles after the signature change.