ADR0008 Finished and ADR0009 finalizing Stream test corrected

This commit is contained in:
rafa-ruiz 2026-04-13 20:32:43 -07:00
parent 6af0a84f4c
commit 6118a77078
2 changed files with 38 additions and 14 deletions

View File

@ -162,6 +162,25 @@ def _call_parser(text: str, test_inputs: dict = None, test_list: list = None) ->
failed_logs = [l for l in data.get("logs", []) if not l.get("success")]
if failed_logs:
error = failed_logs[0].get("error", "runtime error")
# Detect a KeyError from assertion evaluation — pattern: "'variable_name'"
# This means the assertion referenced a variable that doesn't exist in scope
# (e.g. str(result) when the code never assigns `result`).
# The code itself is fine; drop the bad assertion and re-validate.
_key_err_m = _re.match(r"^'([A-Za-z_]\w*)'$", error or "")
if _key_err_m and test_list:
bad_var = _key_err_m.group(1)
logger.warning(
f"[ptvl] assertion KeyError: variable '{bad_var}' not in scope — "
"dropping affected assertions (test defect, not code defect)"
)
filtered = [a for a in test_list if f"str({bad_var})" not in a]
if filtered != test_list:
# Retry with the cleaned assertion list
return _call_parser(text, test_inputs=test_inputs, test_list=filtered)
# All assertions referenced the bad variable — code execution was fine
return True, ""
return False, error or "runtime error"
# Execution succeeded — check assertion result if assertions were provided

View File

@ -249,18 +249,22 @@ TEST_GENERATION_PROMPT = (
"</role>\n\n"
"<avap_variables_rule>\n"
"In AVAP, variables assigned during execution are available after execution.\n"
"Two distinct naming roles exist — do NOT confuse them:\n\n"
"1. addParam(\"request_param_name\", avap_variable_name)\n"
" - \"request_param_name\" (first arg, a string literal) is the HTTP request parameter. "
"Use it as the KEY in test_inputs.\n"
" - avap_variable_name (second arg, an identifier) is the AVAP variable that receives "
"the value. Use it (unquoted) in assertions.\n\n"
" Example: addParam(\"client_id\", id_interno)\n"
" → test_inputs key: \"client_id\"\n"
" → assertion variable: id_interno\n\n"
"2. Direct assignments (e.g. msg = \"Hello\", result = a + b) — use the left-hand "
"variable name (unquoted) in assertions. These variables need no test_inputs entry.\n"
"In AVAP, only variables that are EXPLICITLY ASSIGNED are available after execution.\n"
"Three ways a variable is assigned:\n"
" a) addParam(\"request_param_name\", avap_variable_name) — reads the request parameter\n"
" into avap_variable_name. Use \"request_param_name\" as the key in test_inputs;\n"
" use avap_variable_name (unquoted) in assertions.\n"
" Example: addParam(\"client_id\", id_interno)\n"
" → test_inputs key: \"client_id\"\n"
" → assertion variable: id_interno\n"
" b) Direct assignment: x = value or addVar(x, value) — use x (unquoted) in assertions.\n"
" c) addVar(\"name\", value) — use name (unquoted) in assertions.\n\n"
"CRITICAL — do NOT assert on these:\n"
" - addResult(x) — sends x to the HTTP response body. It does NOT create a variable.\n"
" Never write str(result) or reference any name that only appears inside addResult().\n"
" - _status — HTTP status code field, not a user variable.\n"
" - Any identifier that does not appear as the LEFT side of an assignment or as the\n"
" SECOND argument of addParam().\n"
"</avap_variables_rule>\n\n"
"<assertion_format>\n"
@ -276,10 +280,11 @@ TEST_GENERATION_PROMPT = (
"Output ONLY a valid JSON object with exactly two keys. "
"Every item in test_list MUST be a quoted string. Raw JSON only — "
"no explanation, no markdown, no code block.\n\n"
"Example — code uses addParam(\"client_id\", id_interno):\n"
"Example — code: addParam(\"client_id\", id_interno) / addResult(id_interno):\n"
"{{\"test_inputs\": {{\"client_id\": \"12345\"}}, "
"\"test_list\": [\"re.match(r'^\\\\d+$', str(id_interno))\"]}}\n"
"Note: test_inputs key is \"client_id\" (request param), assertion uses id_interno (AVAP variable).\n"
"CORRECT: asserts id_interno (assigned by addParam). "
"WRONG: asserting str(result) or str(id_interno_result) — addResult() creates NO variable.\n"
"</output_rule>\n\n"
"<user_request>{user_request}</user_request>\n\n"