From 0e52b782c375214798fd0cf17f30f3fc928a6825 Mon Sep 17 00:00:00 2001 From: amoussa1229 <166072409+amoussa1229@users.noreply.github.com> Date: Thu, 16 Jul 2026 19:10:05 +0000 Subject: [PATCH] style: apply ruff formatting to fix CI check --- lambdas/wo/email_processor/handler.py | 7 ++++--- .../tests/test_bedrock_fallback.py | 16 +++++++++++++--- .../tests/test_validation_gate.py | 12 ++++++++++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lambdas/wo/email_processor/handler.py b/lambdas/wo/email_processor/handler.py index 742b301..b2fa4e6 100644 --- a/lambdas/wo/email_processor/handler.py +++ b/lambdas/wo/email_processor/handler.py @@ -144,8 +144,7 @@ def extract_with_bedrock(email_data: dict) -> dict: { "role": "user", "content": ( - f"{EXTRACTION_PROMPT}\n\n" - f"\n{email_text}\n" + f"{EXTRACTION_PROMPT}\n\n\n{email_text}\n" ), } ], @@ -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 diff --git a/lambdas/wo/email_processor/tests/test_bedrock_fallback.py b/lambdas/wo/email_processor/tests/test_bedrock_fallback.py index f9361cf..a3f9be8 100644 --- a/lambdas/wo/email_processor/tests/test_bedrock_fallback.py +++ b/lambdas/wo/email_processor/tests/test_bedrock_fallback.py @@ -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 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) diff --git a/lambdas/wo/email_processor/tests/test_validation_gate.py b/lambdas/wo/email_processor/tests/test_validation_gate.py index c324201..354bad0 100644 --- a/lambdas/wo/email_processor/tests/test_validation_gate.py +++ b/lambdas/wo/email_processor/tests/test_validation_gate.py @@ -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"