File size: 4,169 Bytes
88750f0
878b473
2bf281f
 
878b473
88750f0
878b473
2bf281f
 
 
 
 
 
 
878b473
 
 
 
 
 
 
 
 
 
e526aa8
878b473
 
76e192b
 
878b473
 
 
 
 
 
76e192b
 
 
 
 
 
 
 
 
 
 
 
 
 
878b473
 
76e192b
 
878b473
 
 
 
76e192b
878b473
 
 
e526aa8
 
 
 
878b473
c6231ab
 
 
 
 
 
 
 
 
 
 
 
 
878b473
 
 
 
 
 
 
 
 
e526aa8
878b473
 
e526aa8
878b473
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e526aa8
 
76e192b
e526aa8
 
878b473
 
 
 
 
 
 
 
 
 
 
 
 
 
e526aa8
 
 
 
76e192b
878b473
e526aa8
878b473
 
 
76e192b
 
878b473
 
 
76e192b
878b473
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fccd7f6
 
 
 
 
 
 
 
88750f0
fccd7f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
from typing import NotRequired
import re
from typing import Annotated

from pydantic import AfterValidator, Field, StringConstraints
from typing import TypedDict

from multi_agent_sdlc.runtime.validation import (
    create_entry_point_validator,
    create_testing_dependency_validator,
    validate_application_arguments,
    validate_file_content,
    validate_project_relative_path,
)

MODULE_PATTERN = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*$")

DEPENDENCY_PATTERN = re.compile(
    r"^[A-Za-z0-9][A-Za-z0-9._-]*"
    r"(?:\[[A-Za-z0-9._,-]+\])?"
    r"(?:(?:===|==|~=|!=|<=|>=|<|>)[A-Za-z0-9.*+!_-]+)?$"
)


PROHIBITED_TESTER_ENTRY_POINTS = {
    "pip",
    "pip3",
    "pipenv",
    "poetry",
    "bash",
    "sh",
    "zsh",
    "fish",
    "powershell",
    "pwsh",
    "twine",
    "docker",
    "kubectl",
    "terraform",
}


PROHIBITED_TESTER_DEPENDENCIES = {
    "pip",
    "uv",
    "virtualenv",
    "pipenv",
    "poetry",
    "twine",
}


PROHIBITED_TESTER_PYTHON_MODULES = {
    "pip",
    "ensurepip",
    "venv",
    "subprocess",
    "twine",
}


validate_tester_entry_point = create_entry_point_validator(
    role="Tester",
    prohibited_entry_points=PROHIBITED_TESTER_ENTRY_POINTS,
)

StandardInput = Annotated[
    str,
    Field(
        min_length=1,
        max_length=10_000,
        description=(
            "Text sent to the application's standard input. Separate "
            "interactive responses with newline characters. Omit this "
            "argument when no standard input is required."
        ),
    ),
]


EntryPoint = Annotated[
    str,
    StringConstraints(
        strip_whitespace=True,
        min_length=1,
        max_length=100,
        pattern=r"[A-Za-z0-9][A-Za-z0-9._-]*",
    ),
    AfterValidator(validate_tester_entry_point),
]


ApplicationArguments = Annotated[
    list[str],
    Field(
        max_length=50,
        description="Arguments passed directly to the application.",
    ),
    AfterValidator(validate_application_arguments),
]

ExecutionTimeout = Annotated[
    int,
    Field(
        ge=1,
        le=200,
        description="Maximum application execution time in seconds.",
    ),
]

validate_module_name = create_entry_point_validator(
    role="Tester",
    prohibited_entry_points=PROHIBITED_TESTER_PYTHON_MODULES,
)

PythonModuleName = Annotated[
    str,
    Field(
        min_length=1,
        max_length=200,
        description=(
            "A dotted Python module belonging to the generated application. "
            "Testing, package-management, environment-management, and "
            "process-execution modules are prohibited."
        ),
    ),
    AfterValidator(validate_module_name),
]

validate_testing_dependency = create_testing_dependency_validator(
    role="Tester", prohibited_tester_dependencies=PROHIBITED_TESTER_DEPENDENCIES
)

VerificationDependency = Annotated[
    str,
    AfterValidator(validate_testing_dependency),
]


VerificationDependencies = Annotated[
    list[VerificationDependency],
    Field(
        min_length=1,
        max_length=20,
        description="Verification dependencies to add with uv.",
    ),
]

ProjectRelativePath = Annotated[
    str,
    Field(
        min_length=1,
        max_length=500,
        description=(
            "A path relative to the project directory. "
            "Absolute paths and parent-directory traversal are prohibited."
        ),
    ),
    AfterValidator(validate_project_relative_path),
]

FileContent = Annotated[
    str,
    Field(
        max_length=500_000,
        description="Complete UTF-8 text content to write to the file.",
    ),
    AfterValidator(validate_file_content),
]


class ProcessResult(TypedDict):
    command: list[str]
    exit_code: int | None
    stdout: str
    stderr: str
    timed_out: bool
    message: NotRequired[str]


class ProjectVerificationResult(TypedDict):
    verification_type: str
    passed: bool
    overall_exit_code: int
    checks: list[ProcessResult]


from pydantic import StringConstraints

NonBlankStr = Annotated[
    str,
    StringConstraints(
        strip_whitespace=True,
        min_length=1,
    ),
]