Pedro commited on
Commit
fccd7f6
·
1 Parent(s): f8fbe60

add tool tester_run_project_verification and validation to enforce that the verifications occur before moving to the next node

Browse files
src/multi_agent_sdlc/agents/tester/context.py CHANGED
@@ -1,18 +1,11 @@
1
  from multi_agent_sdlc.state import DevState
2
- from typing import Any
3
 
4
 
5
- def build_tester_context(state: DevState) -> dict[str, Any]:
6
-
7
- plan = state.get("plan")
8
- coder_tasks = [
9
- task.model_dump(mode="json") for task in plan.tasks if task.owner == "tester"
10
- ]
11
 
12
  return {
13
- "request": state.get("request"),
14
- "project_directory": state.get("project_directory"),
15
- "assumptions": plan.assumptions,
16
- "out_of_scope": plan.out_of_scope,
17
- "tasks": coder_tasks,
18
  }
 
1
  from multi_agent_sdlc.state import DevState
 
2
 
3
 
4
+ def build_tester_context(state: DevState) -> dict[str, object]:
5
+ plan = state["plan"]
 
 
 
 
6
 
7
  return {
8
+ "project_directory": state["project_directory"],
9
+ "plan": plan.model_dump(mode="json"),
10
+ "coder_summary": state["current_coder_summary"].model_dump(mode="json"),
 
 
11
  }
src/multi_agent_sdlc/agents/tester/node.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from langchain_core.messages import HumanMessage
2
  from multi_agent_sdlc.models import TesterStatus
3
  from multi_agent_sdlc.models import CoderStatus
@@ -18,7 +19,7 @@ def tester_node(state: DevState) -> dict:
18
 
19
  tester_messages = state.get("tester_messages", [])
20
  tester_status = state["tester_status"]
21
- current_coder_summary = state.get("current_coder_summary")
22
 
23
  if not tester_messages:
24
  return _initialize_tester_conversation(state)
@@ -109,6 +110,27 @@ def _process_tester_summary_call(
109
 
110
  tester_summary = TesterSummary.model_validate(tool_call["args"]["summary"])
111
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  verification_history = state.get(
113
  "verification_history",
114
  [],
@@ -143,3 +165,17 @@ def _process_tester_summary_call(
143
  update["coder_status"] = CoderStatus.REPAIRING
144
 
145
  return update
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from multi_agent_sdlc.tools.tester.validation import ProjectVerificationResult
2
  from langchain_core.messages import HumanMessage
3
  from multi_agent_sdlc.models import TesterStatus
4
  from multi_agent_sdlc.models import CoderStatus
 
19
 
20
  tester_messages = state.get("tester_messages", [])
21
  tester_status = state["tester_status"]
22
+ current_coder_summary = state["current_coder_summary"]
23
 
24
  if not tester_messages:
25
  return _initialize_tester_conversation(state)
 
110
 
111
  tester_summary = TesterSummary.model_validate(tool_call["args"]["summary"])
112
 
113
+ latest_project_verification = state.get("current_project_verification_result")
114
+
115
+ if tester_summary.overall_status == "passed":
116
+ if latest_project_verification is None or not project_verification_passed(
117
+ latest_project_verification
118
+ ):
119
+ return {
120
+ "tester_messages": [
121
+ response,
122
+ HumanMessage(
123
+ content=(
124
+ "The Tester summary cannot report `passed`. "
125
+ "Run `tester_run_project_verification` and ensure "
126
+ "the complete Ruff, Mypy, and Pytest checks all "
127
+ "finish successfully before submitting the "
128
+ "summary again."
129
+ )
130
+ ),
131
+ ],
132
+ }
133
+
134
  verification_history = state.get(
135
  "verification_history",
136
  [],
 
165
  update["coder_status"] = CoderStatus.REPAIRING
166
 
167
  return update
168
+
169
+
170
+ def project_verification_passed(
171
+ result: ProjectVerificationResult,
172
+ ) -> bool:
173
+ return (
174
+ result["verification_type"] == "complete_project_verification"
175
+ and result["passed"]
176
+ and result["overall_exit_code"] == 0
177
+ and all(
178
+ not check["timed_out"] and check["exit_code"] == 0
179
+ for check in result["checks"]
180
+ )
181
+ )
src/multi_agent_sdlc/models.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from enum import StrEnum
2
  from typing import Literal
3
  from enum import Enum
@@ -129,14 +130,103 @@ class CoderSummary(BaseModel):
129
  )
130
 
131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  class TesterSummary(BaseModel):
133
  """Final structured handoff from the Tester to the Reviewer or Coder."""
134
 
135
  model_config = ConfigDict(extra="forbid")
136
 
137
- completed_task_ids: list[str] = Field(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  description=(
139
- "Tester-owned task identifiers completed with supporting evidence."
 
140
  )
141
  )
142
 
@@ -148,87 +238,61 @@ class TesterSummary(BaseModel):
148
 
149
  development_dependencies_added: list[str] = Field(
150
  description=(
151
- "Development or verification dependencies actually added or changed."
 
 
152
  )
153
  )
154
-
155
- verification_results: list[dict[str, object]] = Field(
156
  description=(
157
- "Verification operations actually executed. Each item should include "
158
- "`verification_type`, `command`, `status`, `exit_code`, `summary`, "
159
- "and `related_task_ids`. Status must be `passed`, `failed`, "
160
- "`blocked`, or `not_executed`. This field must contain sufficient "
161
- "successful verification evidence when `overall_status` is `passed`."
162
  )
163
  )
164
 
165
- acceptance_criteria_results: list[dict[str, object]] = Field(
166
  description=(
167
- "Results for approved acceptance criteria. Each item should include "
168
- "`task_id`, `criterion`, `status`, and `evidence`. This field must "
169
- "contain results for all applicable acceptance criteria when "
170
  "`overall_status` is `passed`."
171
  )
172
  )
173
 
174
- tester_repairs: list[dict[str, object]] = Field(
175
  description=(
176
- "Repairs made only to Tester-owned files or verification "
177
- "configuration. Each item should include `description`, "
178
- "`files_modified`, and `verification_result`."
179
  )
180
  )
181
 
182
- implementation_failures: list[dict[str, object]] = Field(
183
  description=(
184
- "Observed failures attributed to Coder-owned production code or "
185
- "configuration. Each item should include `description`, "
186
- "`related_task_ids`, and `evidence`. This field must contain at least "
187
- "one evidenced production failure when `overall_status` is `failed`; "
188
- "it must be empty when `overall_status` is `passed`."
189
  )
190
  )
191
 
192
- unresolved_issues: list[dict[str, object]] = Field(
193
  description=(
194
- "Remaining failures, blockers, incomplete verification, or "
195
- "environment limitations. Each item should include `owner`, "
196
- "`description`, `related_task_ids`, and `evidence`. Owner must be "
197
- "`coder`, `tester`, `environment`, or `unknown`. This field must "
198
- "contain at least one unresolved blocker when `overall_status` is "
199
- "`blocked`; it must be empty when `overall_status` is `passed`."
200
  )
201
  )
202
 
203
- overall_status: Literal[
204
- "passed",
205
- "failed",
206
- "blocked",
207
- ] = Field(
208
  description=(
209
- "Overall outcome of the Tester stage. Use `passed` only when all "
210
- "required verification and applicable acceptance criteria completed "
211
- "successfully; `verification_results` and "
212
- "`acceptance_criteria_results` must provide supporting evidence, while "
213
- "`implementation_failures`, `coder_repair_requests`, and "
214
- "`unresolved_issues` must be empty. Use `failed` only when verification "
215
- "identified at least one evidenced Coder-owned production defect; "
216
- "`implementation_failures` and `coder_repair_requests` must both be "
217
- "non-empty. Use `blocked` only when required verification could not be "
218
- "completed because of a blocker the Tester cannot safely resolve; "
219
- "`unresolved_issues` must be non-empty."
220
  )
221
  )
222
 
223
- coder_repair_requests: list[dict[str, object]] = Field(
224
- description=(
225
- "Production defects requiring Coder repair. Each item must include "
226
- "`related_task_ids`, `affected_files`, `failed_criteria`, "
227
- "`observed_behavior`, `expected_behavior`, and `evidence`. This field "
228
- "must contain at least one focused repair request when `overall_status` "
229
- "is `failed`; it must be empty when `overall_status` is `passed` or "
230
- "`blocked`."
231
- )
232
  )
233
 
234
 
 
1
+ from multi_agent_sdlc.tools.tester.validation import NonBlankStr
2
  from enum import StrEnum
3
  from typing import Literal
4
  from enum import Enum
 
130
  )
131
 
132
 
133
+ from typing import Literal, Self
134
+
135
+ from pydantic import BaseModel, ConfigDict, Field, model_validator
136
+
137
+
138
+ class VerificationType(StrEnum):
139
+ SYNC = "sync"
140
+ ENTRY_POINT = "entry_point"
141
+ PYTEST = "pytest"
142
+ RUFF_CHECK = "ruff_check"
143
+ RUFF_FORMAT_CHECK = "ruff_format_check"
144
+ MYPY = "mypy"
145
+ COMPLETE_PROJECT_VERIFICATION = "complete_project_verification"
146
+
147
+
148
+ class VerificationResult(BaseModel):
149
+ model_config = ConfigDict(extra="forbid")
150
+
151
+ verification_type: VerificationType
152
+ command: list[str] = Field(min_length=1)
153
+ status: Literal["passed", "failed", "blocked", "not_executed"]
154
+ exit_code: int | None
155
+ summary: str = Field(min_length=1)
156
+ related_task_ids: list[str]
157
+
158
+
159
+ class AcceptanceCriterionResult(BaseModel):
160
+ model_config = ConfigDict(extra="forbid")
161
+
162
+ task_id: str = Field(min_length=1)
163
+ criterion: str = Field(min_length=1)
164
+ status: Literal["passed", "failed", "blocked", "not_executed"]
165
+ evidence: str = Field(min_length=1)
166
+
167
+
168
+ class TesterRepair(BaseModel):
169
+ model_config = ConfigDict(extra="forbid")
170
+
171
+ description: str = Field(min_length=1)
172
+ files_modified: list[str] = Field(min_length=1)
173
+ verification_result: str = Field(min_length=1)
174
+
175
+
176
+ class ImplementationFailure(BaseModel):
177
+ model_config = ConfigDict(extra="forbid")
178
+
179
+ description: str = Field(min_length=1)
180
+ related_task_ids: list[str] = Field(min_length=1)
181
+ evidence: str = Field(min_length=1)
182
+
183
+
184
+ class UnresolvedIssue(BaseModel):
185
+ model_config = ConfigDict(extra="forbid")
186
+
187
+ owner: Literal["coder", "tester", "environment", "unknown"]
188
+ description: str = Field(min_length=1)
189
+ related_task_ids: list[str]
190
+ evidence: str = Field(min_length=1)
191
+
192
+
193
+ class CoderRepairRequest(BaseModel):
194
+ model_config = ConfigDict(extra="forbid")
195
+
196
+ related_task_ids: list[str] = Field(min_length=1)
197
+ affected_files: list[str] = Field(min_length=1)
198
+ failed_criteria: list[str] = Field(min_length=1)
199
+ observed_behavior: str = Field(min_length=1)
200
+ expected_behavior: str = Field(min_length=1)
201
+ evidence: str = Field(min_length=1)
202
+
203
+
204
  class TesterSummary(BaseModel):
205
  """Final structured handoff from the Tester to the Reviewer or Coder."""
206
 
207
  model_config = ConfigDict(extra="forbid")
208
 
209
+ addressed_task_ids: list[str] = Field(
210
+ description=(
211
+ "Task identifiers the Tester actively worked on during this cycle, "
212
+ "including test implementation, verification, investigation, or "
213
+ "Tester-owned repairs. Inclusion does not mean the task passed or "
214
+ "was fully verified."
215
+ )
216
+ )
217
+
218
+ passed_task_ids: list[str] = Field(
219
+ description=(
220
+ "Task identifiers for which all applicable acceptance criteria "
221
+ "completed successfully with supporting evidence. Do not include "
222
+ "tasks with any failed, blocked, incomplete, or unresolved criterion."
223
+ )
224
+ )
225
+
226
+ related_task_ids: list[str] = Field(
227
  description=(
228
+ "Relevant task identifiers. Use an empty list only for project-wide "
229
+ "verification that does not map to a specific approved task."
230
  )
231
  )
232
 
 
238
 
239
  development_dependencies_added: list[str] = Field(
240
  description=(
241
+ "Development dependencies newly added by the Tester during this cycle. "
242
+ "Do not include dependencies that were already present or merely used. "
243
+ "Include version constraints exactly as written in project configuration."
244
  )
245
  )
246
+ verification_results: list[VerificationResult] = Field(
 
247
  description=(
248
+ "Verification operations actually executed. This field must contain "
249
+ "sufficient successful evidence when `overall_status` is `passed`."
 
 
 
250
  )
251
  )
252
 
253
+ acceptance_criteria_results: list[AcceptanceCriterionResult] = Field(
254
  description=(
255
+ "Results for all applicable approved acceptance criteria when "
 
 
256
  "`overall_status` is `passed`."
257
  )
258
  )
259
 
260
+ tester_repairs: list[TesterRepair] = Field(
261
  description=(
262
+ "Repairs made only to Tester-owned files or verification configuration."
 
 
263
  )
264
  )
265
 
266
+ implementation_failures: list[ImplementationFailure] = Field(
267
  description=(
268
+ "Failures attributed to Coder-owned production code or configuration."
 
 
 
 
269
  )
270
  )
271
 
272
+ unresolved_issues: list[UnresolvedIssue] = Field(
273
  description=(
274
+ "Issues that remain unresolved, could not be safely classified, or "
275
+ "prevented required verification from completing. Do not duplicate "
276
+ "confirmed Coder-owned defects already recorded in "
277
+ "`implementation_failures` and `coder_repair_requests`. This field "
278
+ "should normally be non-empty only when `overall_status` is `blocked`."
 
279
  )
280
  )
281
 
282
+ overall_status: Literal["passed", "failed", "blocked"] = Field(
 
 
 
 
283
  description=(
284
+ "Final Tester outcome. Use `passed` only when the latest complete "
285
+ "project verification passed and every applicable acceptance criterion "
286
+ "passed. Use `failed` when verification produced evidence of at least "
287
+ "one Coder-owned production defect requiring repair. Use `blocked` only "
288
+ "when required verification could not be completed or a failure could "
289
+ "not be safely classified because of an external, environmental, tool, "
290
+ "dependency, or access limitation."
 
 
 
 
291
  )
292
  )
293
 
294
+ coder_repair_requests: list[CoderRepairRequest] = Field(
295
+ description=("Focused production defects requiring repair by the Coder.")
 
 
 
 
 
 
 
296
  )
297
 
298
 
src/multi_agent_sdlc/state.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from multi_agent_sdlc.models import CoderStatus
2
  from multi_agent_sdlc.models import TesterStatus
3
  from multi_agent_sdlc.models import CoderMode
@@ -34,3 +35,4 @@ class DevState(TypedDict):
34
  list[VerificationCycle],
35
  add,
36
  ]
 
 
1
+ from multi_agent_sdlc.tools.tester.validation import ProjectVerificationResult
2
  from multi_agent_sdlc.models import CoderStatus
3
  from multi_agent_sdlc.models import TesterStatus
4
  from multi_agent_sdlc.models import CoderMode
 
35
  list[VerificationCycle],
36
  add,
37
  ]
38
+ current_project_verification_result: NotRequired[ProjectVerificationResult | None]
src/multi_agent_sdlc/tools/tester/descriptions.py CHANGED
@@ -359,3 +359,43 @@ Rules:
359
  * Record the command, arguments, exit status, output, and observed result.
360
  * Treat returned results as authoritative Tester-stage verification evidence.
361
  """.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
359
  * Record the command, arguments, exit status, output, and observed result.
360
  * Treat returned results as authoritative Tester-stage verification evidence.
361
  """.strip()
362
+
363
+ TESTER_RUN_PROJECT_VERIFICATION_DESCRIPTION = """
364
+ Run the complete mandatory project verification suite inside the current
365
+ project's uv-managed environment.
366
+
367
+ The tool executes these fixed checks:
368
+
369
+ uv run ruff check .
370
+ uv run ruff format --check .
371
+ uv run mypy src
372
+ uv run pytest
373
+
374
+ All checks are attempted, even when an earlier check fails. The result includes
375
+ the command, exit code, timeout status, standard output, and standard error for
376
+ each check, together with an overall pass or fail result.
377
+
378
+ Use this tool as the authoritative final verification gate before submitting a
379
+ Tester summary with `overall_status="passed"`.
380
+
381
+ Rules:
382
+ - Run this tool after implementing or repairing Tester-owned tests and
383
+ verification configuration.
384
+ - Run it again after any change that could affect verification results.
385
+ - A successful targeted test or individual verification command does not
386
+ replace this complete project verification.
387
+ - Do not report `passed` unless the latest complete project verification
388
+ finished without timeouts and every mandatory check returned exit code 0.
389
+ - When a check fails, inspect its full result to determine whether the failure
390
+ originates from production code, Tester-owned files, verification
391
+ configuration, dependencies, or the execution environment.
392
+ - Repair failures only when they originate from Tester-owned tests or
393
+ verification configuration.
394
+ - Report valid production-code failures through focused Coder repair requests.
395
+ - Report an external or unresolvable verification obstacle as `blocked`.
396
+ - Do not weaken tests, assertions, linting rules, formatting rules,
397
+ type-checking rules, or project configuration merely to obtain a passing
398
+ result.
399
+ - Do not install dependencies, modify the environment, or execute arbitrary
400
+ commands through this tool.
401
+ """.strip()
src/multi_agent_sdlc/tools/tester/execution.py CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  from multi_agent_sdlc.tools.tester.validation import StandardInput
2
  from multi_agent_sdlc.tools.tester.descriptions import (
3
  TESTER_RUN_VERIFICATION_COMMAND_DESCRIPTION,
@@ -13,6 +17,9 @@ from multi_agent_sdlc.runtime.process import execute_process
13
  from multi_agent_sdlc.runtime.workspace import get_project_directory
14
  from multi_agent_sdlc.state import DevState
15
  from langchain.tools import ToolRuntime, tool
 
 
 
16
 
17
 
18
  @tool(
@@ -124,3 +131,51 @@ def tester_run_verification_command(
124
  project_directory=project_directory,
125
  timeout_seconds=timeout_seconds,
126
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from multi_agent_sdlc.tools.tester.validation import ProjectVerificationResult
2
+ from multi_agent_sdlc.tools.tester.descriptions import (
3
+ TESTER_RUN_PROJECT_VERIFICATION_DESCRIPTION,
4
+ )
5
  from multi_agent_sdlc.tools.tester.validation import StandardInput
6
  from multi_agent_sdlc.tools.tester.descriptions import (
7
  TESTER_RUN_VERIFICATION_COMMAND_DESCRIPTION,
 
17
  from multi_agent_sdlc.runtime.workspace import get_project_directory
18
  from multi_agent_sdlc.state import DevState
19
  from langchain.tools import ToolRuntime, tool
20
+ from langchain_core.messages import ToolMessage
21
+ from langgraph.types import Command
22
+ import json
23
 
24
 
25
  @tool(
 
131
  project_directory=project_directory,
132
  timeout_seconds=timeout_seconds,
133
  )
134
+
135
+
136
+ @tool(
137
+ "tester_run_project_verification",
138
+ description=TESTER_RUN_PROJECT_VERIFICATION_DESCRIPTION,
139
+ )
140
+ def tester_run_project_verification(
141
+ runtime: ToolRuntime[DevState],
142
+ timeout_seconds: ExecutionTimeout = 200,
143
+ ) -> ProjectVerificationResult:
144
+ commands = [
145
+ ["uv", "run", "ruff", "check", "."],
146
+ ["uv", "run", "ruff", "format", "--check", "."],
147
+ ["uv", "run", "mypy", "src"],
148
+ ["uv", "run", "pytest"],
149
+ ]
150
+
151
+ project_directory = get_project_directory(runtime)
152
+
153
+ checks = [
154
+ execute_process(
155
+ command=command,
156
+ project_directory=project_directory,
157
+ timeout_seconds=timeout_seconds,
158
+ )
159
+ for command in commands
160
+ ]
161
+
162
+ passed = all(not check["timed_out"] and check["exit_code"] == 0 for check in checks)
163
+
164
+ result: ProjectVerificationResult = {
165
+ "verification_type": "complete_project_verification",
166
+ "passed": passed,
167
+ "overall_exit_code": 0 if passed else 1,
168
+ "checks": checks,
169
+ }
170
+
171
+ return Command(
172
+ update={
173
+ "current_project_verification_result": result,
174
+ "tester_messages": [
175
+ ToolMessage(
176
+ content=json.dumps(result),
177
+ tool_call_id=runtime.tool_call_id,
178
+ )
179
+ ],
180
+ }
181
+ )
src/multi_agent_sdlc/tools/tester/registry.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from multi_agent_sdlc.tools.tester.execution import tester_run_verification_command
2
  from multi_agent_sdlc.tools.tester.finalization import submit_tester_summary
3
  from multi_agent_sdlc.tools.shared.filesystem import read_file
@@ -24,4 +25,5 @@ TESTER_TOOLS = [
24
  read_file,
25
  submit_tester_summary,
26
  tester_run_verification_command,
 
27
  ]
 
1
+ from multi_agent_sdlc.tools.tester.execution import tester_run_project_verification
2
  from multi_agent_sdlc.tools.tester.execution import tester_run_verification_command
3
  from multi_agent_sdlc.tools.tester.finalization import submit_tester_summary
4
  from multi_agent_sdlc.tools.shared.filesystem import read_file
 
25
  read_file,
26
  submit_tester_summary,
27
  tester_run_verification_command,
28
+ tester_run_project_verification,
29
  ]
src/multi_agent_sdlc/tools/tester/validation.py CHANGED
@@ -162,3 +162,32 @@ FileContent = Annotated[
162
  ),
163
  AfterValidator(validate_file_content),
164
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  ),
163
  AfterValidator(validate_file_content),
164
  ]
165
+
166
+ from typing import TypedDict
167
+
168
+
169
+ class ProcessResult(TypedDict):
170
+ command: list[str]
171
+ exit_code: int | None
172
+ stdout: str
173
+ stderr: str
174
+ timed_out: bool
175
+
176
+
177
+ class ProjectVerificationResult(TypedDict):
178
+ verification_type: str
179
+ passed: bool
180
+ overall_exit_code: int
181
+ checks: list[ProcessResult]
182
+
183
+
184
+ from pydantic import StringConstraints
185
+
186
+
187
+ NonBlankStr = Annotated[
188
+ str,
189
+ StringConstraints(
190
+ strip_whitespace=True,
191
+ min_length=1,
192
+ ),
193
+ ]