调用回执
- ' + content + '
"""Original response-body controls for the is_silent_failure Noul contract.""" import argparse from collections import Counter import hashlib from html import escape import json from pathlib import Path import random from .api import compile_request from .data import SPLITS, _hash, _write_dataset, split_group VERSION = "silent-failure-control-v1" QUESTION = ( "Does this response body show that the current operation failed or did not deliver " "its stated required result? Judge only the body. Maintenance or a sign-in page " "replacing the requested result counts as failure, even when a field claims success. " "A valid empty result, explicitly accepted asynchronous work, allowed partial data, " "quoted error text, or an earlier incident that has recovered does not by itself count." ) SOURCE_COMMIT = "c490e0dc7830758f84bd9d5acb806655e327113e" SOURCE_URL = ( "https://github.com/Vicente-MD/jev-resilience/blob/" + SOURCE_COMMIT + "/src/main/java/ai/jev/resilience/client/JevEvaluationService.java#L50-L55" ) SPLIT_POLICY = "whole_provider_contract_family_and_counterfactual_pairs; hash_id_splits; reserved_zh_schema_layout_and_wording_ood" PAIRS = ( "html_maintenance", "html_login", "business_rejection", "required_receipt", "empty_search", "history_current", "quoted_error", "async_job", "partial_batch", "error_count", "freshness", "complete_segments", ) RULES = { "business_rejection": ("The reservation must be confirmed for this operation to succeed.", "只有预订状态为已确认,才算本次操作完成。"), "required_receipt": ("This operation requires a receipt with a nonempty receipt_id.", "本次操作必须返回回执,且 receipt_id 不能为空。"), "empty_search": ("A completed search may return no matches; an unfinished search is not a valid result.", "检索已完成时可以没有匹配项;未完成的检索不满足要求。"), "history_current": ("Only the event marked current describes this call; previous events are historical.", "仅标为本次的事件代表当前调用;先前事件只作历史记录。"), "quoted_error": ("Return the requested document. Text inside the document or example is quoted content, not the status of this fetch.", "应返回所请求的文档。文档及示例里的文字是引用内容,不表示本次读取的状态。"), "async_job": ("Acceptance into the queue with a job_id is a valid result; completed output is not required yet.", "进入队列并获得 job_id 即满足本次请求;暂不要求任务完成后的输出。"), "partial_batch": ("Return all requested items unless partial_allowed explicitly permits a smaller nonempty result.", "应返回全部请求项;只有 partial_allowed 明确允许时,才接受少量但非空的部分结果。"), "error_count": ("All required checks in the current checks object must pass. Archive counts are from a previous run.", "本次 checks 中的全部必需检查都要通过。archive 计数属于上次运行。"), "freshness": ("The delivered revision must be at least the minimum revision; a cache hit alone does not meet this requirement.", "返回修订号必须不低于最低修订号;命中缓存本身不代表满足要求。"), "complete_segments": ("Every requested segment must be delivered; archived failures belong to an earlier request.", "必须交付全部请求片段;历史失败数属于更早的请求。"), "document": ("Return the requested document in the Document field.", "请在文档字段内返回所请求的文档。"), } CURRENT = { "html_maintenance": (("Service available; maintenance has ended.", "Service offline for maintenance; no requested document was produced."), ("维护已经结束,服务可用。", "服务正在停机维护,尚未生成所请求的文档。")), "html_login": (("Requested document returned; the sign-in link is informational.", "Sign-in is required; this page replaces the requested document."), ("已返回所请求的文档;登录链接只是页面说明。", "需要登录;当前页面取代了所请求的文档。")), } SUBJECTS = ("orchid", "granite", "cedar", "amber", "willow", "coral", "maple", "quartz") def silent_failure_request(body: str) -> dict: """Preserve the actual body string; transport status and references stay outside.""" if not isinstance(body, str) or not body.strip(): raise ValueError("body must be a nonempty stringified response body") return {"state": body, "questions": {"is_silent_failure": {"type": "noul", "instructions": QUESTION}}} def _ordered(mapping, nonce): keys = list(mapping) random.Random(nonce).shuffle(keys) return {key: mapping[key] for key in keys} def _json_body(context, pair, failed, zh, nonce, count, layout): provider, request_id, action = context receipt_id = "r-" + _hash([request_id, "receipt"])[:12] job_id = "j-" + _hash([request_id, "job"])[:12] terms = RULES[pair][zh] if pair == "business_rejection": data = {"success": True, "reservation": {"status": (("confirmed", "rejected"), ("已确认", "已拒绝"))[zh][failed], "reason": (("capacity exhausted", "预约容量已用尽")[zh] if failed else None), "receipt_id": None if failed else receipt_id}} elif pair == "required_receipt": # The visible terms establish the requirement; {} alone would be ambiguous. shells = ({}, None, {"receipt_id": ""}, {"receipt_id": None}, {"receipt_id": " "}) data = {"success": True, "receipt": shells[int(nonce[:4], 16) % len(shells)] if failed else {"receipt_id": receipt_id}} elif pair == "empty_search": data = {"success": True, "search": {"matches": [], "complete": not failed, "error": (("index unavailable; search not executed", "索引不可用,检索尚未执行")[zh] if failed else None)}} elif pair == "history_current": status = (("completed", "failed"), ("已完成", "失败"))[zh] scopes = ("previous", "current") if not zh else ("先前", "本次") events = [{"scope": scopes[0], "status": status[not failed]}, {"scope": scopes[1], "status": status[failed]}] random.Random(nonce).shuffle(events) data = {"events": events} elif pair == "quoted_error": quote = ("Example only: 'ERROR: upstream unavailable'. This line explains a diagnostic message.", "仅为示例:『错误:上游不可用』。这段话是在解释诊断信息。")[zh] data = {"fetch": {"complete": not failed}, "document": None if failed else {"title": action, "text": quote}, "documentation_example": quote, "error": (("requested document could not be read", "无法读取所请求的文档")[zh] if failed else None)} elif pair == "async_job": data = {"success": True, "job": {"status": (("queued", "rejected"), ("已入队", "已拒绝"))[zh][failed], "job_id": None if failed else job_id}, "result": None} elif pair == "partial_batch": data = {"success": True, "policy": {"partial_allowed": not failed, "requested": count}, "items": ["i-" + _hash([request_id, i])[:10] for i in range(count - 1)]} elif pair == "error_count": errors = min(count, 1 + int(nonce[:4], 16) % 3) if failed else 0 data = {"success": True, "checks": {"required": count, "passed": count - errors, "failed": errors}, "archive": {"failed": 0 if failed else count}} else: raise ValueError("unsupported JSON pair") data = _ordered(data, nonce) if layout == "flat_en": body = {"provider": provider, "request_id": request_id, "operation": action, "terms": terms, "response": data} elif layout == "envelope_en": body = {"request": {"provider": provider, "id": request_id, "operation": action}, "contract": terms, "body": data} elif layout == "entries_zh": entries = [{"栏目": key, "内容": value} for key, value in (("约定", terms), ("返回", data))] random.Random(nonce).shuffle(entries) body = {"调用信息": {"服务": provider, "标识": request_id, "动作": action}, "条目": entries} elif layout == "nested_zh": body = {"服务": provider, "调用": {"标识": request_id, "动作": action, "交付": {"约定": terms, "返回": data}}} else: raise ValueError("unsupported JSON layout") return json.dumps(_ordered(body, nonce), ensure_ascii=False, indent=2 if int(nonce[0], 16) % 2 else None) def _document_body(context, pair, failed, zh, nonce): provider, request_id, action = context labels = ("Provider", "Request", "Operation", "Requirement", "Current", "Document") if not zh else ("服务", "调用", "动作", "约定", "现在", "文档") values = (provider, request_id, action, RULES["document"][zh], CURRENT[pair][zh][failed], "" if failed else action + " / " + request_id) fields = _ordered(dict(zip(labels, values)), nonce) if zh: content = "".join(f"
{key}: {escape(value)}
" for key, value in fields.items()) return '