refactor(examples): replace sector-specific example material with generic, fictitious examples
The context sets, the packaged knowledge bases and the example bundles are replaced by one fictitious example set about IT operations in an invented organisation: three context sets (serverrom-2027, driftsavtale-2027 and the two-base drift-og-avtale-2027), two synthetic knowledge bases under src/portfolio_optimiser/data/kunnskapsbaser and two example bundles under src/portfolio_optimiser/data/bundles. Numbers, codes and structural values in tests and fixtures are kept; names, ids and wording change. Dated measurement documents that only recorded runs on the replaced material are deleted. Gate figures measured on the new set are not comparable with earlier ones. The exclusion gate from the previous commit is green: 0 tracked files hit outside the shared/ subtree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
058dd25570
commit
37547fe292
1147 changed files with 24138 additions and 9503 deletions
|
|
@ -51,11 +51,12 @@ from portfolio_optimiser.simulation import ScriptedChatClient
|
|||
from portfolio_optimiser.verdicts import VerdictStore
|
||||
|
||||
_EXAMPLES = Path(__file__).resolve().parents[1] / "shared" / "examples"
|
||||
_BUNDLES = Path(__file__).resolve().parents[1] / "src" / "portfolio_optimiser" / "data" / "bundles"
|
||||
#: Three bases with three DISTINCT project ids — which is what makes "the project comes from the
|
||||
#: base, not from the caller" a claim a test can actually falsify.
|
||||
_BYGG = _EXAMPLES / "bygg-energi-mikro" # BYGG-KONTOR-NORD
|
||||
_TUNNEL = _EXAMPLES / "tunnel-hauglia" # TUNNEL-HAUGLIA
|
||||
_VEGLYS = _EXAMPLES / "veglys-fv-soer" # VEGLYS-FV-SOER
|
||||
_KJOLING = _BUNDLES / "driftssenter-kjoling" # DRIFTSSENTER-KJOLING
|
||||
_KLIENTPARK = _BUNDLES / "klientpark-energi" # KLIENTPARK-ENERGI
|
||||
|
||||
_VERDICT_INPUT = {"decision": "approved", "rationale": "expert reviewed (sim)"}
|
||||
|
||||
|
|
@ -74,7 +75,10 @@ def test_an_approach_records_which_knowledge_base_it_belongs_to() -> None:
|
|||
one base to name.
|
||||
"""
|
||||
assert Approach(id="a", label="A").bundle_id == ""
|
||||
assert Approach(id="a", label="A", bundle_id="tunnel-hauglia").bundle_id == "tunnel-hauglia"
|
||||
assert (
|
||||
Approach(id="a", label="A", bundle_id="driftssenter-kjoling").bundle_id
|
||||
== "driftssenter-kjoling"
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------
|
||||
|
|
@ -93,13 +97,13 @@ def test_the_router_partitions_the_mandate_one_sub_mandate_per_named_base() -> N
|
|||
approaches, so the dispatch's spend order is a property of how the run was configured and not
|
||||
of how a model happened to sequence its hypotheses.
|
||||
"""
|
||||
a = Approach(id="a", label="A", bundle_id="tunnel-hauglia")
|
||||
b = Approach(id="b", label="B", bundle_id="veglys-fv-soer")
|
||||
c = Approach(id="c", label="C", bundle_id="tunnel-hauglia")
|
||||
a = Approach(id="a", label="A", bundle_id="driftssenter-kjoling")
|
||||
b = Approach(id="b", label="B", bundle_id="klientpark-energi")
|
||||
c = Approach(id="c", label="C", bundle_id="driftssenter-kjoling")
|
||||
|
||||
routed = route_by_bundle(_mandate(a, b, c), ("veglys-fv-soer", "tunnel-hauglia"))
|
||||
routed = route_by_bundle(_mandate(a, b, c), ("klientpark-energi", "driftssenter-kjoling"))
|
||||
|
||||
assert [bundle_id for bundle_id, _ in routed] == ["veglys-fv-soer", "tunnel-hauglia"]
|
||||
assert [bundle_id for bundle_id, _ in routed] == ["klientpark-energi", "driftssenter-kjoling"]
|
||||
assert [ap.id for ap in routed[0][1].approaches] == ["b"]
|
||||
assert [ap.id for ap in routed[1][1].approaches] == ["a", "c"]
|
||||
# The commission's own fields travel with every partition: each sub-run is still working on the
|
||||
|
|
@ -115,9 +119,9 @@ def test_a_single_base_absorbs_every_unassigned_approach() -> None:
|
|||
``_bundle_index`` already guarantees the id is unique. This is what keeps a single-base
|
||||
mandate (every mandate that exists today) dispatchable unchanged.
|
||||
"""
|
||||
routed = route_by_bundle(_mandate(Approach(id="a", label="A")), ("tunnel-hauglia",))
|
||||
routed = route_by_bundle(_mandate(Approach(id="a", label="A")), ("driftssenter-kjoling",))
|
||||
|
||||
assert [bundle_id for bundle_id, _ in routed] == ["tunnel-hauglia"]
|
||||
assert [bundle_id for bundle_id, _ in routed] == ["driftssenter-kjoling"]
|
||||
assert [ap.id for ap in routed[0][1].approaches] == ["a"]
|
||||
|
||||
|
||||
|
|
@ -130,7 +134,9 @@ def test_an_unassigned_approach_among_several_bases_is_refused_not_guessed() ->
|
|||
report would then describe work nobody ordered.
|
||||
"""
|
||||
with pytest.raises(MandateRoutingError) as exc:
|
||||
route_by_bundle(_mandate(Approach(id="a", label="A")), ("tunnel-hauglia", "veglys-fv-soer"))
|
||||
route_by_bundle(
|
||||
_mandate(Approach(id="a", label="A")), ("driftssenter-kjoling", "klientpark-energi")
|
||||
)
|
||||
|
||||
# The REPR, never the bare letter: "a" is a substring of almost any English sentence, so an
|
||||
# assertion on it would hold against a refusal raised for an entirely different reason.
|
||||
|
|
@ -145,11 +151,11 @@ def test_an_approach_naming_an_unconfigured_base_is_refused_by_name() -> None:
|
|||
"""
|
||||
approach = Approach(id="a", label="A", bundle_id="does-not-exist")
|
||||
with pytest.raises(MandateRoutingError) as exc:
|
||||
route_by_bundle(_mandate(approach), ("tunnel-hauglia", "veglys-fv-soer"))
|
||||
route_by_bundle(_mandate(approach), ("driftssenter-kjoling", "klientpark-energi"))
|
||||
|
||||
message = str(exc.value)
|
||||
assert "does-not-exist" in message
|
||||
assert "tunnel-hauglia" in message
|
||||
assert "driftssenter-kjoling" in message
|
||||
|
||||
|
||||
def test_the_routing_refusal_is_a_value_error() -> None:
|
||||
|
|
@ -279,14 +285,14 @@ async def test_a_marked_hypothesis_may_name_its_base_and_the_mandate_carries_it(
|
|||
result = await explore.explore(
|
||||
_PROMPT,
|
||||
contract=_CONTRACT,
|
||||
bundle_dirs=(str(_TUNNEL), str(_VEGLYS)),
|
||||
bundle_dirs=(str(_KJOLING), str(_KLIENTPARK)),
|
||||
client_factory=_factory(
|
||||
ledgers=_two_round_ledgers(),
|
||||
hypothesiser=[_hypothesis_line("LED retrofit", "old fixtures", "veglys-fv-soer")],
|
||||
hypothesiser=[_hypothesis_line("PC-utskifting", "old desktops", "klientpark-energi")],
|
||||
),
|
||||
)
|
||||
|
||||
assert [a.bundle_id for a in result.mandate.approaches] == ["veglys-fv-soer"]
|
||||
assert [a.bundle_id for a in result.mandate.approaches] == ["klientpark-energi"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -300,14 +306,14 @@ async def test_with_one_base_a_marker_that_names_none_still_yields_an_assigned_a
|
|||
result = await explore.explore(
|
||||
_PROMPT,
|
||||
contract=_CONTRACT,
|
||||
bundle_dirs=(str(_TUNNEL),),
|
||||
bundle_dirs=(str(_KJOLING),),
|
||||
client_factory=_factory(
|
||||
ledgers=_two_round_ledgers(),
|
||||
hypothesiser=[_hypothesis_line("LED retrofit", "old fixtures")],
|
||||
hypothesiser=[_hypothesis_line("PC-utskifting", "old desktops")],
|
||||
),
|
||||
)
|
||||
|
||||
assert [a.bundle_id for a in result.mandate.approaches] == ["tunnel-hauglia"]
|
||||
assert [a.bundle_id for a in result.mandate.approaches] == ["driftssenter-kjoling"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -322,10 +328,10 @@ async def test_with_several_bases_a_marker_that_names_none_is_refused() -> None:
|
|||
await explore.explore(
|
||||
_PROMPT,
|
||||
contract=_CONTRACT,
|
||||
bundle_dirs=(str(_TUNNEL), str(_VEGLYS)),
|
||||
bundle_dirs=(str(_KJOLING), str(_KLIENTPARK)),
|
||||
client_factory=_factory(
|
||||
ledgers=_two_round_ledgers(),
|
||||
hypothesiser=[_hypothesis_line("LED retrofit", "old fixtures")],
|
||||
hypothesiser=[_hypothesis_line("PC-utskifting", "old desktops")],
|
||||
),
|
||||
)
|
||||
|
||||
|
|
@ -341,7 +347,7 @@ async def test_a_marker_naming_an_unconfigured_base_is_refused() -> None:
|
|||
await explore.explore(
|
||||
_PROMPT,
|
||||
contract=_CONTRACT,
|
||||
bundle_dirs=(str(_TUNNEL), str(_VEGLYS)),
|
||||
bundle_dirs=(str(_KJOLING), str(_KLIENTPARK)),
|
||||
client_factory=_factory(
|
||||
ledgers=_two_round_ledgers(),
|
||||
hypothesiser=[_hypothesis_line("LED", "old fixtures", "no-such-base")],
|
||||
|
|
@ -363,7 +369,7 @@ async def test_a_seed_naming_an_unknown_base_is_refused_before_the_first_model_c
|
|||
await explore.explore(
|
||||
_PROMPT,
|
||||
contract=_CONTRACT,
|
||||
bundle_dirs=(str(_TUNNEL), str(_VEGLYS)),
|
||||
bundle_dirs=(str(_KJOLING), str(_KLIENTPARK)),
|
||||
seed_approaches=(Approach(id="s1", label="Seed", bundle_id="no-such-base"),),
|
||||
client_factory=_factory(ledgers=_two_round_ledgers(), hypothesiser=[], sink=sink),
|
||||
)
|
||||
|
|
@ -384,7 +390,7 @@ async def test_an_unassigned_seed_with_several_bases_is_refused_before_the_first
|
|||
await explore.explore(
|
||||
_PROMPT,
|
||||
contract=_CONTRACT,
|
||||
bundle_dirs=(str(_TUNNEL), str(_VEGLYS)),
|
||||
bundle_dirs=(str(_KJOLING), str(_KLIENTPARK)),
|
||||
seed_approaches=(Approach(id="s1", label="Seed"),),
|
||||
client_factory=_factory(ledgers=_two_round_ledgers(), hypothesiser=[], sink=sink),
|
||||
)
|
||||
|
|
@ -406,7 +412,7 @@ async def test_a_seed_is_never_rewritten_only_validated() -> None:
|
|||
result = await explore.explore(
|
||||
_PROMPT,
|
||||
contract=_CONTRACT,
|
||||
bundle_dirs=(str(_TUNNEL),),
|
||||
bundle_dirs=(str(_KJOLING),),
|
||||
seed_approaches=(seed,),
|
||||
client_factory=_factory(ledgers=_two_round_ledgers(), hypothesiser=[]),
|
||||
)
|
||||
|
|
@ -465,18 +471,18 @@ async def test_the_dispatch_runs_one_pipeline_per_base_with_that_bases_approache
|
|||
monkeypatch.setattr(run_module, "run_project", _recorder(calls))
|
||||
|
||||
mandate = _mandate(
|
||||
Approach(id="a", label="A", bundle_id="tunnel-hauglia"),
|
||||
Approach(id="b", label="B", bundle_id="veglys-fv-soer"),
|
||||
Approach(id="a", label="A", bundle_id="driftssenter-kjoling"),
|
||||
Approach(id="b", label="B", bundle_id="klientpark-energi"),
|
||||
)
|
||||
await run_mandate_across_bundles(
|
||||
mandate,
|
||||
(str(_TUNNEL), str(_VEGLYS)),
|
||||
(str(_KJOLING), str(_KLIENTPARK)),
|
||||
verdict_input=_VERDICT_INPUT,
|
||||
store=VerdictStore(verdicts=[]),
|
||||
)
|
||||
|
||||
assert len(calls) == 2
|
||||
assert [c["bundle_dir"] for c in calls] == [str(_TUNNEL), str(_VEGLYS)]
|
||||
assert [c["bundle_dir"] for c in calls] == [str(_KJOLING), str(_KLIENTPARK)]
|
||||
assert [[ap.id for ap in c["mandate"].approaches] for c in calls] == [["a"], ["b"]]
|
||||
|
||||
|
||||
|
|
@ -495,17 +501,17 @@ async def test_each_bases_project_id_comes_from_that_base_not_from_the_caller(
|
|||
monkeypatch.setattr(run_module, "run_project", _recorder(calls))
|
||||
|
||||
mandate = _mandate(
|
||||
Approach(id="a", label="A", bundle_id="tunnel-hauglia"),
|
||||
Approach(id="b", label="B", bundle_id="veglys-fv-soer"),
|
||||
Approach(id="a", label="A", bundle_id="driftssenter-kjoling"),
|
||||
Approach(id="b", label="B", bundle_id="klientpark-energi"),
|
||||
)
|
||||
await run_mandate_across_bundles(
|
||||
mandate,
|
||||
(str(_TUNNEL), str(_VEGLYS)),
|
||||
(str(_KJOLING), str(_KLIENTPARK)),
|
||||
verdict_input=_VERDICT_INPUT,
|
||||
store=VerdictStore(verdicts=[]),
|
||||
)
|
||||
|
||||
assert [c["project_id"] for c in calls] == ["TUNNEL-HAUGLIA", "VEGLYS-FV-SOER"]
|
||||
assert [c["project_id"] for c in calls] == ["DRIFTSSENTER-KJOLING", "KLIENTPARK-ENERGI"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -523,7 +529,7 @@ async def test_one_base_is_dispatched_exactly_as_a_single_run(
|
|||
|
||||
await run_mandate_across_bundles(
|
||||
_mandate(Approach(id="a", label="A"), Approach(id="b", label="B")),
|
||||
(str(_TUNNEL),),
|
||||
(str(_KJOLING),),
|
||||
verdict_input=_VERDICT_INPUT,
|
||||
store=VerdictStore(verdicts=[]),
|
||||
)
|
||||
|
|
@ -549,10 +555,10 @@ async def test_a_base_that_cannot_be_funded_is_never_started_and_its_approaches_
|
|||
|
||||
result = await run_mandate_across_bundles(
|
||||
_mandate(
|
||||
Approach(id="a", label="A", bundle_id="tunnel-hauglia"),
|
||||
Approach(id="b", label="B", bundle_id="veglys-fv-soer"),
|
||||
Approach(id="a", label="A", bundle_id="driftssenter-kjoling"),
|
||||
Approach(id="b", label="B", bundle_id="klientpark-energi"),
|
||||
),
|
||||
(str(_TUNNEL), str(_VEGLYS)),
|
||||
(str(_KJOLING), str(_KLIENTPARK)),
|
||||
verdict_input=_VERDICT_INPUT,
|
||||
store=VerdictStore(verdicts=[]),
|
||||
portfolio_meter=meter,
|
||||
|
|
@ -560,7 +566,7 @@ async def test_a_base_that_cannot_be_funded_is_never_started_and_its_approaches_
|
|||
|
||||
# Base 1 is funded (1000 left, 500 required) and spends 600; base 2 then has 400 left against a
|
||||
# 500 reserve. The SECOND base is the one that must never start.
|
||||
assert [c["bundle_dir"] for c in calls] == [str(_TUNNEL)]
|
||||
assert [c["bundle_dir"] for c in calls] == [str(_KJOLING)]
|
||||
assert result.stopped_early is True
|
||||
assert result.budget_stop is not None
|
||||
assert {row.id for row in result.unreached} == {"b"}
|
||||
|
|
@ -579,7 +585,7 @@ async def test_a_pass_that_can_fund_nothing_at_all_is_refused_at_startup() -> No
|
|||
with pytest.raises(BudgetRefused):
|
||||
await run_mandate_across_bundles(
|
||||
_mandate(Approach(id="a", label="A")),
|
||||
(str(_TUNNEL),),
|
||||
(str(_KJOLING),),
|
||||
verdict_input=_VERDICT_INPUT,
|
||||
store=VerdictStore(verdicts=[]),
|
||||
portfolio_meter=meter,
|
||||
|
|
@ -606,7 +612,7 @@ async def test_the_dispatch_composes_with_the_real_run_project(tmp_path: Path) -
|
|||
Driven against two real bases end to end, offline, through the scripted client seam.
|
||||
"""
|
||||
bases = []
|
||||
for src in (_BYGG, _TUNNEL):
|
||||
for src in (_BYGG, _KJOLING):
|
||||
dst = tmp_path / src.name
|
||||
shutil.copytree(src, dst)
|
||||
bases.append(str(dst))
|
||||
|
|
@ -620,7 +626,7 @@ async def test_the_dispatch_composes_with_the_real_run_project(tmp_path: Path) -
|
|||
result = await run_mandate_across_bundles(
|
||||
_mandate(
|
||||
Approach(id="a", label="A", bundle_id="bygg-energi-mikro"),
|
||||
Approach(id="b", label="B", bundle_id="tunnel-hauglia"),
|
||||
Approach(id="b", label="B", bundle_id="driftssenter-kjoling"),
|
||||
),
|
||||
tuple(bases),
|
||||
"local",
|
||||
|
|
@ -630,8 +636,8 @@ async def test_the_dispatch_composes_with_the_real_run_project(tmp_path: Path) -
|
|||
max_rounds=1,
|
||||
)
|
||||
|
||||
assert [r.bundle_id for r in result.runs] == ["bygg-energi-mikro", "tunnel-hauglia"]
|
||||
assert [r.project_id for r in result.runs] == ["BYGG-KONTOR-NORD", "TUNNEL-HAUGLIA"]
|
||||
assert [r.bundle_id for r in result.runs] == ["bygg-energi-mikro", "driftssenter-kjoling"]
|
||||
assert [r.project_id for r in result.runs] == ["BYGG-KONTOR-NORD", "DRIFTSSENTER-KJOLING"]
|
||||
assert all(isinstance(r.result, RunResult) for r in result.runs)
|
||||
# Each run answered for ITS OWN commissioned approach, and for nobody else's.
|
||||
assert [{row.id for row in r.result.coverage} for r in result.runs] == [
|
||||
|
|
@ -662,10 +668,10 @@ async def test_one_store_is_threaded_across_every_base(
|
|||
store = VerdictStore(verdicts=[])
|
||||
await run_mandate_across_bundles(
|
||||
_mandate(
|
||||
Approach(id="a", label="A", bundle_id="tunnel-hauglia"),
|
||||
Approach(id="b", label="B", bundle_id="veglys-fv-soer"),
|
||||
Approach(id="a", label="A", bundle_id="driftssenter-kjoling"),
|
||||
Approach(id="b", label="B", bundle_id="klientpark-energi"),
|
||||
),
|
||||
(str(_TUNNEL), str(_VEGLYS)),
|
||||
(str(_KJOLING), str(_KLIENTPARK)),
|
||||
verdict_input=_VERDICT_INPUT,
|
||||
store=store,
|
||||
)
|
||||
|
|
@ -688,7 +694,7 @@ async def test_exploration_and_dispatch_close_the_loop_over_two_bases(tmp_path:
|
|||
expert actually reads: an approach that reached the wrong base would still appear evaluated.
|
||||
"""
|
||||
bases = []
|
||||
for src in (_BYGG, _TUNNEL):
|
||||
for src in (_BYGG, _KJOLING):
|
||||
dst = tmp_path / src.name
|
||||
shutil.copytree(src, dst)
|
||||
bases.append(str(dst))
|
||||
|
|
@ -705,14 +711,18 @@ async def test_exploration_and_dispatch_close_the_loop_over_two_bases(tmp_path:
|
|||
hypothesiser=[
|
||||
_hypothesis_line("Behovsstyrt lys", "fixtures are 1990s", "bygg-energi-mikro")
|
||||
+ "\n"
|
||||
+ _hypothesis_line("Nattsenking", "the tunnel runs lit all night", "tunnel-hauglia")
|
||||
+ _hypothesis_line(
|
||||
"Nattsenking",
|
||||
"the cooling runs at full level all night",
|
||||
"driftssenter-kjoling",
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
assert [a.bundle_id for a in exploration.mandate.approaches] == [
|
||||
"bygg-energi-mikro",
|
||||
"tunnel-hauglia",
|
||||
"driftssenter-kjoling",
|
||||
]
|
||||
|
||||
def factory(role: str) -> BaseChatClient:
|
||||
|
|
@ -731,7 +741,7 @@ async def test_exploration_and_dispatch_close_the_loop_over_two_bases(tmp_path:
|
|||
max_rounds=1,
|
||||
)
|
||||
|
||||
assert [r.bundle_id for r in result.runs] == ["bygg-energi-mikro", "tunnel-hauglia"]
|
||||
assert [r.bundle_id for r in result.runs] == ["bygg-energi-mikro", "driftssenter-kjoling"]
|
||||
assert [{row.id for row in r.result.coverage} for r in result.runs] == [
|
||||
{"hypothesis-1", "own-proposal"},
|
||||
{"hypothesis-2", "own-proposal"},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue