Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/extension/pythonTestingPipeline/scripts/pipeline/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ def run(
4. IMPORT source modules directly for coverage (add project root to sys.path first)
5. Use mocking for side effects (network, file I/O)
6. Use proc.terminate() instead of signal.SIGINT for stopping processes
7. Avoid top-level imports of source modules when they trigger optional dependencies or side effects; import lazily inside tests after patching
8. Do not leave global state dirty; avoid raw os.chdir when possible and restore cwd/env if you must change them

Generate a complete, executable PyTest file."""

Expand Down Expand Up @@ -309,12 +311,15 @@ def improve_tests(
coverage_percentage: float,
uncovered_areas: str,
syntax_errors: str = "",
validation_errors: str = "",
security_issues: List[SecurityIssue] = None,
) -> Tuple[str, Path]:
"""Generates additional tests to improve coverage and address security issues."""
reasons = []
if coverage_percentage < 90.0:
reasons.append(f"coverage ({coverage_percentage:.1f}%) below 90%")
if validation_errors:
reasons.append("semantic validation failed")
if security_issues:
severe = [
si for si in security_issues if si.severity in ("critical", "high")
Expand Down Expand Up @@ -353,6 +358,19 @@ def improve_tests(
- Ensure all strings are properly closed
- Ensure all parentheses, brackets, and braces are balanced
- Make sure indentation is consistent (use 4 spaces)
"""

validation_context = ""
if validation_errors:
validation_context = f"""\n\nCRITICAL: The previous test file failed semantic validation and must be fixed:
{validation_errors}

Common issues to avoid:
- The suite must pass `python -m py_compile`
- The suite must be collectable with `pytest --collect-only`
- Avoid top-level imports of source modules with optional dependencies or side effects
- Use lazy imports after patching optional dependencies
- Do not leave cwd, env vars, or other process-global state dirty
"""

# Build security context if there are security issues
Expand Down Expand Up @@ -397,7 +415,7 @@ def improve_tests(
- NEVER use `signal.SIGINT` to stop processes (not supported on Windows)
- Use `proc.terminate()` or `proc.kill()` to stop subprocesses
- For keyboard interrupt tests, mock the behavior instead of sending real signals
{error_context}{security_context}
{error_context}{validation_context}{security_context}
Existing tests (may have errors - fix them):
{existing_tests[:1500]}

Expand All @@ -414,6 +432,8 @@ def improve_tests(
4. Each test function must start with 'test_'
5. Use mocking for side effects (network, file I/O)
6. Use proc.terminate() instead of signal.SIGINT for stopping processes
7. Avoid top-level imports of source modules when they trigger optional dependencies or side effects; import lazily inside tests after patching
8. Do not leave global state dirty; avoid raw os.chdir when possible and restore cwd/env if you must change them

Generate a complete, executable PyTest file that:
1. Fixes any existing syntax errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def get_audit_trail(self) -> dict:
failure_breakdown[key] = failure_breakdown.get(key, 0) + 1

return {
"governance_version": "1.1",
"governance_version": "1.2",
"pipeline_start": time.strftime(
"%Y-%m-%d %H:%M:%S", time.localtime(self._start)
),
Expand All @@ -141,7 +141,7 @@ def get_audit_trail(self) -> dict:
"failed_validations": failed,
"total_failures": len(self.failures),
"failure_breakdown": failure_breakdown,
"status": "PASS" if failed == 0 else "REVIEW_NEEDED",
"status": "PASS" if failed == 0 and not self.failures else "REVIEW_NEEDED",
},
}

Expand Down
Loading
Loading