mirror of
https://github.com/Sea-Haven-Industries/procurement-ingest.git
synced 2026-10-07 16:08:54 +00:00
style: apply ruff formatting to fix CI check
This commit is contained in:
parent
23a67f7254
commit
0e52b782c3
3 changed files with 27 additions and 8 deletions
|
|
@ -144,8 +144,7 @@ def extract_with_bedrock(email_data: dict) -> dict:
|
||||||
{
|
{
|
||||||
"role": "user",
|
"role": "user",
|
||||||
"content": (
|
"content": (
|
||||||
f"{EXTRACTION_PROMPT}\n\n"
|
f"{EXTRACTION_PROMPT}\n\n<email>\n{email_text}\n</email>"
|
||||||
f"<email>\n{email_text}\n</email>"
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
@ -378,7 +377,9 @@ def handler(event, context):
|
||||||
f"AI-fallback validation failed ({val_reason}), skipping: {key}"
|
f"AI-fallback validation failed ({val_reason}), skipping: {key}"
|
||||||
)
|
)
|
||||||
emit_parse_metric(
|
emit_parse_metric(
|
||||||
"ai_fallback_rejected", template_id, val_reason,
|
"ai_fallback_rejected",
|
||||||
|
template_id,
|
||||||
|
val_reason,
|
||||||
parsed.get("work_order_id"),
|
parsed.get("work_order_id"),
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -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
|
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
|
"""A prompt-injected model output with a non-enum email_type must fail
|
||||||
the validation gate before any DynamoDB write."""
|
the validation gate before any DynamoDB write."""
|
||||||
injected = dict(AI_17_KEY, email_type="exploit")
|
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):
|
def test_extract_with_bedrock_wraps_email_in_xml_block(monkeypatch):
|
||||||
"""The Bedrock prompt must delimit the untrusted email body in an <email>
|
"""The Bedrock prompt must delimit the untrusted email body in an <email>
|
||||||
tag so the model treats it as data, not instructions."""
|
tag so the model treats it as data, not instructions."""
|
||||||
|
|
||||||
class SpyBedrock:
|
class SpyBedrock:
|
||||||
def invoke_model(self, modelId, body): # noqa: N803
|
def invoke_model(self, modelId, body): # noqa: N803
|
||||||
self.last_body = body
|
self.last_body = body
|
||||||
return {
|
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()
|
spy = SpyBedrock()
|
||||||
monkeypatch.setattr(handler, "bedrock", spy)
|
monkeypatch.setattr(handler, "bedrock", spy)
|
||||||
email_data = {
|
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)
|
handler.extract_with_bedrock(email_data)
|
||||||
body = json.loads(spy.last_body)
|
body = json.loads(spy.last_body)
|
||||||
|
|
|
||||||
|
|
@ -209,8 +209,16 @@ def test_ai_fallback_bad_status_enum():
|
||||||
|
|
||||||
|
|
||||||
def test_ai_fallback_valid_status_ok():
|
def test_ai_fallback_valid_status_ok():
|
||||||
for status in ("new", "assigned", "in_progress", "on_hold", "completed",
|
for status in (
|
||||||
"cancelled", "unknown", None):
|
"new",
|
||||||
|
"assigned",
|
||||||
|
"in_progress",
|
||||||
|
"on_hold",
|
||||||
|
"completed",
|
||||||
|
"cancelled",
|
||||||
|
"unknown",
|
||||||
|
None,
|
||||||
|
):
|
||||||
cand = _ai_candidate()
|
cand = _ai_candidate()
|
||||||
cand["work_order_id"] = "12345"
|
cand["work_order_id"] = "12345"
|
||||||
cand["email_type"] = "update"
|
cand["email_type"] = "update"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue