File size: 4,232 Bytes
ea621d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{
  "build_script": "",
  "build_workdir": ".",
  "bundle_artifact": "",
  "decision_relevant_fields": [
    "adapter_state.warning_present",
    "adapter_state.render_ok"
  ],
  "execution_mode": "node",
  "expected_page_errors": [],
  "instance_id": "cloud-custodian_cel-python_pr130",
  "language": "python",
  "payload": {},
  "predicate_description": "The rendered README no longer contains the Apple Silicon warning block and rendered without errors.",
  "predicate_js": "(s) => s.adapter_state.render_ok === true && s.adapter_state.warning_present === false",
  "product_output_kind": "rendered_document",
  "program_js": "import base64\nimport json\nimport os\nimport re\nimport sys\nfrom pathlib import Path\n\nsys.path.insert(0, \"/testbed\")\nsys.path.insert(0, \"/testbed/src\")\n\noutput_path = sys.argv[2]\n\npayload = json.loads(base64.b64decode(sys.argv[1]).decode(\"utf-8\"))\ntitle = payload.get(\"title\", \"cel-python README\")\n\n# Execute the library under test via a CEL match() expression.\nmatch_result = None\nmatch_error = None\ntry:\n    import celpy\n\n    env = celpy.Environment()\n    ast = env.compile('\"hello\".matches(\"h.*o\")')\n    prgm = env.program(ast)\n    match_result = repr(prgm.evaluate({}))\nexcept Exception as exc:\n    match_error = f\"{type(exc).__name__}: {exc}\"\n\n# Render README.rst with docutils.\nrender_ok = False\nrender_error = None\nhtml = \"\"\ntry:\n    from docutils.core import publish_string\n\n    readme_src = Path(\"/testbed/README.rst\").read_text(encoding=\"utf-8\")\n    html_bytes = publish_string(\n        readme_src,\n        writer_name=\"html\",\n        settings_overrides={\"initial_header_level\": 1},\n    )\n    html = html_bytes.decode(\"utf-8\")\n\n    # Avoid any external network requests from the browser: remove all <img> tags.\n    html = re.sub(r\"<img[^>]*\\/?>\", \"\", html, flags=re.IGNORECASE)\n\n    # Normalize to HTML5 doctype.\n    html = re.sub(r\"<!DOCTYPE[^>]*>\", \"<!DOCTYPE html>\", html, count=1, flags=re.IGNORECASE)\n\n    # Block any remaining external resource fetches via CSP.\n    csp = '<meta http-equiv=\"Content-Security-Policy\" content=\"default-src \\'none\\'; style-src \\'unsafe-inline\\'; script-src \\'unsafe-inline\\';\">'\n    html = html.replace(\"</head>\", csp + \"</head>\", 1)\n\n    render_ok = True\nexcept Exception as exc:\n    render_error = f\"{type(exc).__name__}: {exc}\"\n    html = (\n        \"<!DOCTYPE html><html><head>\"\n        f'<meta charset=\"utf-8\"><title>{title}</title></head>'\n        f\"<body><pre>{render_error}</pre></body></html>\"\n    )\n\nwarning_present = False\nif render_ok:\n    lower_html = html.lower()\n    warning_present = (\n        \"apple silicon and python 3.13\" in lower_html\n        or \"built-in ``re`` is used as a fall-back\" in lower_html\n    )\n\nstate = {\n    \"render_ok\": render_ok,\n    \"render_error\": render_error,\n    \"warning_present\": warning_present,\n    \"match_result\": match_result,\n    \"match_error\": match_error,\n}\n\nscript = (\n    \"<script>window.__WM_STATE__=\"\n    + json.dumps(state).replace(\"<\", \"\\\\u003c\")\n    + \";window.__WM_READY__=true;</script>\"\n)\n\nif \"</body>\" in html:\n    html = html.replace(\"</body>\", script + \"</body>\", 1)\nelse:\n    html = html + script\n\nwith open(output_path, \"w\", encoding=\"utf-8\") as fh:\n    fh.write(html)\n\n# Record repository execution evidence.\nloaded = sorted(\n    {\n        m.__file__\n        for m in sys.modules.values()\n        if getattr(m, \"__file__\", None) and \"/testbed/\" in m.__file__\n    }\n)\ntrace_path = os.environ.get(\"WMMB_MODULE_TRACE_PATH\")\nif trace_path:\n    with open(trace_path, \"w\", encoding=\"utf-8\") as fh:\n        json.dump({\"repository_modules_loaded\": loaded}, fh)",
  "rationale": "Rendering the project's README.rst with docutils shows the Apple Silicon warning admonition in base and removes it in gold; remote images are stripped so the page makes no network requests.",
  "repo": "cloud-custodian/cel-python",
  "schema_version": "worldmodelmmbench.render-probe.v3",
  "title": "README reStructuredText warning block removal",
  "viewport": [
    1280,
    960
  ],
  "volatile_fields": []
}