feat: a work breakdown structure with a computed timeline (iteration 10)
Some checks failed
validation / verify (push) Failing after 10s

A new Deliverable in the packaging Phase, produced by a delivery planner
after validation.

- The planner writes the plan as data: work packages that name the Elements
  they deliver, and activities with days, what each follows, and whether the
  team or the customer owns it.
- Code checks the plan against the design: every Element belongs to a work
  package, and the activities can be scheduled.
- Code computes the schedule, with no more of the team's activities at once
  than the team has people, and the critical path.
- Code writes the WBS dictionary (a work package is done when the Checks on
  its Elements pass), the activity sequence and a timeline on a relative axis
  from Day 0.
- The plan is checked against the delivery window from the agreed scope; over
  it, the Deliverable says by how much and names the critical path.
- With a start date it also gives calendar dates and a Mermaid Gantt chart.
- The timeline is added to the solution guide, and the plan's length is in
  execution.json and the packaging Approval.

Not run with real models.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-11 19:54:17 +01:00
parent 0f80cb642f
commit f54af24169
21 changed files with 1108 additions and 12 deletions

View File

@@ -103,9 +103,14 @@ def test_inputs_are_earlier_phases_plus_indirect_dependencies_in_graph_order():
assert inputs_of(DeliverableKind.DEPLOYMENT_GUIDANCE) == design
assert inputs_of(DeliverableKind.ARCHITECTURE_DESCRIPTION) == design
assert inputs_of(DeliverableKind.TARGET_ARCHITECTURE) == design[:5]
# The plan is produced beside the guide, not before it: neither reads the other.
assert set(inputs_of(DeliverableKind.SOLUTION_GUIDE)) == set(DeliverableKind) - {
DeliverableKind.SOLUTION_GUIDE
DeliverableKind.SOLUTION_GUIDE,
DeliverableKind.WORK_BREAKDOWN,
}
assert DeliverableKind.SOLUTION_GUIDE not in inputs_of(
DeliverableKind.WORK_BREAKDOWN
)
def sections_missing(kind: DeliverableKind, content: str) -> list[str]:

View File

@@ -247,7 +247,7 @@ def test_finish_is_allowed_only_once_packaging_is_approved():
through_phase_three(ledger)
assert not ledger.can_finish()
produce(ledger, K.SOLUTION_GUIDE)
produce(ledger, K.WORK_BREAKDOWN, K.SOLUTION_GUIDE)
approve(ledger, P.PACKAGING)
assert ledger.can_finish()

View File

@@ -0,0 +1,308 @@
"""The work breakdown structure: a plan checked, scheduled and drawn by code."""
import json
from langgraph.checkpoint.memory import InMemorySaver
from app.adk.fake_runtime import SAMPLE_DATA, Call, FakeAgentRuntime, sample_submission
from app.adk.runtime import NoDecider, RoleSpec
from app.agent import ExecutionEngine
from app.nodes.router import Router, Thresholds
from app.recorder import InMemoryRecorder
from app.workflows.deliverables import DEPENDENCY_GRAPH
from app.workflows.deliverables import DeliverableKind as K
from app.workflows.work_breakdown import (
check_work_breakdown,
mermaid,
render,
schedule,
summary,
)
GRAPH = SAMPLE_DATA["target-architecture.json"] # Elements E-1 and E-2
PLANNER = DEPENDENCY_GRAPH[K.WORK_BREAKDOWN].specialist
def upstream(**delivery) -> dict:
scope = {"stated": {"delivery": delivery}, "assumed": []}
return {
"target_architecture": {"attachments": {"target-architecture.json": GRAPH}},
"scope": {"attachments": {"scope.json": json.dumps(scope)}},
}
def plan(packages=None, activities=None) -> dict[str, str]:
data = json.loads(SAMPLE_DATA["work-breakdown.json"])
if packages is not None:
data["work_packages"] = packages
if activities is not None:
data["activities"] = activities
return {"work-breakdown.json": json.dumps(data)}
def activity(ident: str, days: float, *after: str, **more) -> dict:
return {
"id": ident,
"work_package": "WP-1",
"name": f"Do {ident}",
"days": days,
"after": list(after),
**more,
}
PACKAGE = json.loads(SAMPLE_DATA["work-breakdown.json"])["work_packages"][0]
# --- the plan is checked against the design ---------------------------------------------
def test_a_plan_that_covers_the_design_is_accepted():
assert check_work_breakdown(plan(), upstream()) == []
def test_every_element_of_the_design_belongs_to_a_work_package():
only_one = [{**PACKAGE, "elements": ["E-1"]}]
invented = [{**PACKAGE, "elements": ["E-1", "E-2", "E-9"]}]
(left_out,) = check_work_breakdown(plan(only_one), upstream())
(unknown,) = check_work_breakdown(plan(invented), upstream())
assert "no work package delivers E-2" in left_out
assert "WP-1 delivers E-9, which is not an Element" in unknown
def test_a_plan_that_cannot_be_scheduled_is_refused_with_the_reason():
def problems(*activities):
return check_work_breakdown(plan(activities=list(activities)), upstream())
assert any(
"depend on each other in a circle" in p
for p in problems(activity("A-1", 1, "A-2"), activity("A-2", 1, "A-1"))
)
assert any(
"comes after A-9, which is not an activity" in p
for p in problems(activity("A-1", 1, "A-9"))
)
assert any(
"needs `days`, a number above 0" in p for p in problems(activity("A-1", 0))
)
assert any("split anything over" in p for p in problems(activity("A-1", 400)))
assert any(
"owner must be one of" in p
for p in problems(activity("A-1", 1, owner="vendor"))
)
assert any(
"is in WP-7, not a work package" in p
for p in problems({**activity("A-1", 1), "work_package": "WP-7"})
)
def test_a_work_package_holds_work_or_other_work_packages():
parent = {**PACKAGE, "id": "WP-0", "elements": []}
child = {**PACKAGE, "parent": "WP-0"}
idle = {**PACKAGE, "id": "WP-2", "elements": []}
assert check_work_breakdown(plan([parent, child]), upstream()) == []
assert any(
"WP-2 has no activity and no work package beneath it" in p
for p in check_work_breakdown(
plan([child | {"parent": None}, idle]), upstream()
)
)
assert any(
"has parent WP-9, which does not exist" in p
for p in check_work_breakdown(plan([{**PACKAGE, "parent": "WP-9"}]), upstream())
)
# --- the schedule is computed -----------------------------------------------------------
def test_an_activity_starts_when_what_it_follows_has_finished():
placed = schedule(
[activity("A-1", 2), activity("A-2", 3, "A-1"), activity("A-3", 1, "A-2")]
)
assert [(p.start, p.finish) for p in placed.values()] == [(0, 2), (2, 5), (5, 6)]
assert all(p.critical for p in placed.values())
def test_independent_work_runs_at_once_up_to_the_size_of_the_team():
work = [activity("A-1", 4), activity("A-2", 4), activity("A-3", 4)]
two = schedule(work, team_size=2)
three = schedule(work, team_size=3)
assert max(p.finish for p in two.values()) == 8
assert sorted(p.start for p in two.values()) == [0, 0, 4]
assert max(p.finish for p in three.values()) == 4
def test_what_the_customer_owns_takes_nobody_from_the_team():
work = [
activity("A-1", 10, owner="customer"),
activity("A-2", 3),
activity("A-3", 2, "A-1", "A-2"),
]
placed = schedule(work, team_size=1)
# The lead time and the team's work run together; the end waits on the longer.
assert placed["A-2"].start == 0 and placed["A-3"].start == 10
assert placed["A-1"].critical and placed["A-3"].critical
assert not placed["A-2"].critical
def test_when_people_are_short_the_longest_chain_goes_first():
work = [activity("A-1", 1), activity("A-2", 1), activity("A-3", 5, "A-2")]
placed = schedule(work, team_size=1)
assert placed["A-2"].start == 0 and placed["A-1"].start > 0
# --- the views are written from the plan ------------------------------------------------
def test_the_three_views_are_written_from_the_data():
text = render(plan(), upstream(team_size=2))
assert "## WBS dictionary" in text
# Acceptance is the Checks on the work package's Elements, read from the design.
assert (
"| WP-1 | Ingress | The service and its identity. | a running service | E-1, E-2 | K-1, K-2 |"
in text
)
assert (
"| A-2 | Deploy the service | WP-1 | 2 | A-1 | Day 1 | Day 3 | team | yes |"
in text
)
assert "## Timeline" in text and "Day 0" in text
assert "3 working days, about 0.6 weeks, with a team of 2 and a 5-day week." in text
assert "indicative" in text
def test_a_plan_over_the_delivery_window_says_so_and_names_the_critical_path():
long = plan(activities=[activity("A-1", 20), activity("A-2", 15, "A-1")])
over = render(long, upstream(team_size=2, window_weeks=4))
inside = render(long, upstream(team_size=2, window_weeks=10))
assert "**That is 3.0 weeks over the 4-week delivery window.**" in over
assert "The critical path is A-1 -> A-2" in over
assert "inside the 10-week delivery window, with 3.0 weeks to spare" in inside
assert summary(long, upstream(window_weeks=4))["within_window"] is False
def test_an_assumed_team_size_is_said_to_be_assumed():
assert "(assumed; the scope gives no team size)" in render(plan(), upstream())
def test_a_customers_lead_time_is_shown_as_theirs():
waiting = plan(
activities=[
activity(
"A-1", 30, owner="customer", assumption="The carrier takes six weeks."
),
activity("A-2", 2, "A-1"),
]
)
text = render(waiting, upstream(team_size=2))
assert "The customer owns these, and the plan waits on them:" in text
assert "- A-1 Do A-1: 30 days. The carrier takes six weeks." in text
assert "░" in text and "█" in text
def test_calendar_dates_and_a_chart_appear_only_with_a_start_date():
dated = upstream(team_size=2, target_start_date="2026-11-02") # a Monday
assert mermaid(plan(), upstream(team_size=2)) == ""
assert "Dates" not in render(plan(), upstream(team_size=2))
chart = mermaid(plan(), dated)
assert chart.startswith("gantt\n dateFormat YYYY-MM-DD")
assert "Deploy the service :crit, A-2, 2026-11-03, 2d" in chart
assert "| 2026-11-03 to 2026-11-04 |" in render(plan(), dated)
def test_a_week_of_working_days_skips_the_weekend():
week = plan(activities=[activity("A-1", 5), activity("A-2", 1, "A-1")])
text = render(week, upstream(team_size=1, target_start_date="2026-11-02"))
# Five working days from Monday end on Friday; the next starts on Monday.
assert "| 2026-11-02 to 2026-11-06 |" in text
assert "| 2026-11-09 to 2026-11-09 |" in text
# --- in an Execution --------------------------------------------------------------------
async def test_an_execution_delivers_a_plan_and_adds_its_timeline_to_the_guide(
tmp_path,
):
roles = {
"orchestrator": RoleSpec("orchestrator", "Unused.", budget=40),
**{
spec.specialist: RoleSpec(spec.specialist, "Produce.", budget=15)
for spec in DEPENDENCY_GRAPH.values()
},
}
runtime = FakeAgentRuntime(
{
spec.specialist: [[sample_submission(kind)]]
for kind, spec in DEPENDENCY_GRAPH.items()
}
)
engine = ExecutionEngine(
runtime=runtime,
roles=roles,
recorder=InMemoryRecorder(),
checkpointer=InMemorySaver(),
output_root=tmp_path,
orchestrator=Router(NoDecider(), None, Thresholds()),
)
result = await engine.start("Ingest", customer_case="acme", pre_approved=True)
assert result.status == "completed"
out = next(tmp_path.rglob("execution.json")).parent
breakdown = (out / "deliverables" / "work_breakdown.md").read_text()
assert "## WBS dictionary" in breakdown and "## Activity sequence" in breakdown
assert (out / "work-breakdown.json").is_file()
guide = (out / "solution-architecture-guide.md").read_text()
assert "## Delivery plan" in guide and "A-2 Deploy the service" in guide
manifest = json.loads((out / "execution.json").read_text())
assert manifest["delivery_plan"]["working_days"] == 3
assert manifest["delivery_plan"]["critical_path"] == ["A-1", "A-2"]
# The planner was given the design and the code to plan from, in full.
planner = next(run for run in runtime.runs if run.role == PLANNER)
given = planner.task.context["dependencies"]
assert "content" in given["target_architecture"]
assert "content" in given["deployment_guidance"]
async def test_a_plan_that_leaves_an_element_out_is_returned_to_the_planner(tmp_path):
from app.tools.execution import specialist_tools
(submit,) = (
tool
for tool in specialist_tools(
K.WORK_BREAKDOWN, (), allow_cloud_read=False, upstream=upstream()
)
if tool.name == "submit_deliverable"
)
partial = Call(
"submit_deliverable",
{
"content": "## Approach\nIn order.\n",
"attachments": plan([{**PACKAGE, "elements": ["E-1"]}]),
},
)
refused = await submit.handler(**partial.args)
assert refused.outcome is None
assert "no work package delivers E-2" in refused.message

View File

@@ -386,7 +386,8 @@ def test_the_validator_reads_the_code_whole_and_the_graph_as_data():
def test_the_solution_guide_is_assembled_from_every_deliverable_whole():
given = dependencies_for(K.SOLUTION_GUIDE, submitted())
assert len(given) == len(DEPENDENCY_GRAPH) - 1
# Every Deliverable but the guide itself and the plan produced beside it.
assert len(given) == len(DEPENDENCY_GRAPH) - 2
assert all("content" in deliverable for deliverable in given.values())

View File

@@ -4,10 +4,15 @@ Every Execution now begins with the scoping Phase (ADR-0008). A test about
requirements, design or validation is not about that, so these run scoping ahead
of the test's own script and leave the test where it always started: requirements
ready, nothing recorded of how the scope was agreed.
The work breakdown structure (iteration 10) is produced beside the solution guide.
A script written before it existed delegates the guide alone; here the plan is
delegated with it, and planned without a script.
"""
from __future__ import annotations
import dataclasses
from typing import Any
from app.adk.fake_runtime import FakeAgentRuntime, sample_submission
@@ -16,9 +21,28 @@ from app.agent import ExecutionEngine, Interaction
from app.workflows.deliverables import DEPENDENCY_GRAPH, DeliverableKind, PhaseId
SCOPE_ANALYST = DEPENDENCY_GRAPH[DeliverableKind.SCOPE].specialist
PLANNER = DEPENDENCY_GRAPH[DeliverableKind.WORK_BREAKDOWN].specialist
ORCHESTRATOR = "orchestrator"
def _with_the_plan(tool): # type: ignore[no-untyped-def]
"""`delegate`, delegating the work breakdown structure whenever the solution
guide is delegated."""
if tool.name != "delegate":
return tool
guide, plan = (
DeliverableKind.SOLUTION_GUIDE.value,
DeliverableKind.WORK_BREAKDOWN.value,
)
async def delegate(kinds, **rest): # type: ignore[no-untyped-def]
if guide in kinds and plan not in kinds:
kinds = [*kinds, plan]
return await tool.handler(kinds=kinds, **rest)
return dataclasses.replace(tool, handler=delegate)
class ScopedRuntime(FakeAgentRuntime):
"""A scripted runtime that first has the scope produced and its Approval asked
for, outside the script and outside `runs`."""
@@ -29,6 +53,11 @@ class ScopedRuntime(FakeAgentRuntime):
async def run(self, role, task, tools): # type: ignore[no-untyped-def]
by_name = {tool.name: tool for tool in tools}
if role.name == PLANNER and not self.remaining(PLANNER):
call = sample_submission(DeliverableKind.WORK_BREAKDOWN)
return Submitted(call.args["content"], call.args["attachments"])
if role.name == ORCHESTRATOR and "delegate" in by_name:
tools = [_with_the_plan(tool) for tool in tools]
if role.name == SCOPE_ANALYST and not self.remaining(SCOPE_ANALYST):
# Submitted as it stands: a test about a later Deliverable's draft is
# not asking whether the scope's draft was shown first.