style: apply ruff formatting to fix CI check

This commit is contained in:
amoussa1229 2026-07-16 19:10:05 +00:00
parent 23a67f7254
commit 0e52b782c3
3 changed files with 27 additions and 8 deletions

View file

@ -144,8 +144,7 @@ def extract_with_bedrock(email_data: dict) -> dict:
{
"role": "user",
"content": (
f"{EXTRACTION_PROMPT}\n\n"
f"<email>\n{email_text}\n</email>"
f"{EXTRACTION_PROMPT}\n\n<email>\n{email_text}\n</email>"
),
}
],
@ -378,7 +377,9 @@ def handler(event, context):
f"AI-fallback validation failed ({val_reason}), skipping: {key}"
)
emit_parse_metric(
"ai_fallback_rejected", template_id, val_reason,
"ai_fallback_rejected",
template_id,
val_reason,
parsed.get("work_order_id"),
)
continue

View file

@ -152,7 +152,9 @@ def test_ai_path_non_numeric_wo_id_is_skipped(fake_dynamo, metric_spy, monkeypat
assert comments is None or not comments.puts
def test_ai_fallback_injected_email_type_is_rejected(fake_dynamo, metric_spy, monkeypatch):
def test_ai_fallback_injected_email_type_is_rejected(
fake_dynamo, metric_spy, monkeypatch
):
"""A prompt-injected model output with a non-enum email_type must fail
the validation gate before any DynamoDB write."""
injected = dict(AI_17_KEY, email_type="exploit")
@ -191,17 +193,25 @@ def test_ai_fallback_injected_status_is_rejected(fake_dynamo, metric_spy, monkey
def test_extract_with_bedrock_wraps_email_in_xml_block(monkeypatch):
"""The Bedrock prompt must delimit the untrusted email body in an <email>
tag so the model treats it as data, not instructions."""
class SpyBedrock:
def invoke_model(self, modelId, body): # noqa: N803
self.last_body = body
return {
"body": FakeBody(json.dumps({"content": [{"text": json.dumps(AI_17_KEY)}]}).encode())
"body": FakeBody(
json.dumps({"content": [{"text": json.dumps(AI_17_KEY)}]}).encode()
)
}
spy = SpyBedrock()
monkeypatch.setattr(handler, "bedrock", spy)
email_data = {
"subject": "s", "sender": "a", "to": "b", "cc": "", "date": "d", "body": "b"
"subject": "s",
"sender": "a",
"to": "b",
"cc": "",
"date": "d",
"body": "b",
}
handler.extract_with_bedrock(email_data)
body = json.loads(spy.last_body)

View file

@ -209,8 +209,16 @@ def test_ai_fallback_bad_status_enum():
def test_ai_fallback_valid_status_ok():
for status in ("new", "assigned", "in_progress", "on_hold", "completed",
"cancelled", "unknown", None):
for status in (
"new",
"assigned",
"in_progress",
"on_hold",
"completed",
"cancelled",
"unknown",
None,
):
cand = _ai_candidate()
cand["work_order_id"] = "12345"
cand["email_type"] = "update"