File size: 5,200 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.img_present_keep",
    "adapter_state.img_present_default"
  ],
  "execution_mode": "node",
  "expected_page_errors": [],
  "instance_id": "buriy_python-readability_pr190",
  "language": "python",
  "payload": {},
  "predicate_description": "The summary with keep_all_images=True contains an img tag and the default summary does not.",
  "predicate_js": "(s) => s.adapter_state.img_present_keep === true && s.adapter_state.img_present_default === false",
  "product_output_kind": "rendered_document",
  "program_js": "import base64\nimport json\nimport os\nimport sys\n\nsys.path.insert(0, \"/testbed\")\n\nfrom readability import Document\n\n# The framework passes base64-encoded JSON in sys.argv[1].\ninput_payload = json.loads(base64.b64decode(sys.argv[1]).decode(\"utf-8\"))\noutput_path = sys.argv[2]\n\n# Sample HTML from the issue's test fixture, inlined so the probe never reads test files.\nSAMPLE_HTML = \"\"\"<!DOCTYPE html>\n<html lang=\"en\">\n<head></head>\n<body>\n<h2>\n    <span>\n        H2 Headline H2 Headline H2 Headline H2 Headline H2 Headline H2 Headline H2 Headline H2 Headline H2 Headline H2 Headline\n    </span>\n</h2>\n<p>\n    <spa>\n        Text Text Text Text Text Text Text Text Text Text\n    </spa>\n</p>\n<div>\n    <span>\n        <a>\n            <img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAABhGlDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw1AUhU9TpSLVDnYQcchQnSyIFXHUKhShQqgVWnUweekfNDEkKS6OgmvBwZ/FqoOLs64OroIg+APiLjgpukiJ9yWFFjFeeLyP8+45vHcfIDSqTLO6xgFNt81MKinm8iti6BUBhBFBPxIys4xZSUrDt77uqZvqLs6z/Pv+rD61YDEgIBLPMMO0ideJpzZtg/M+cZSVZZX4nHjMpAsSP3Jd8fiNc8llgWdGzWxmjjhKLJY6WOlgVjY14knimKrplC/kPFY5b3HWqjXWuid/YbigLy9xndYwUljAIiSIUFBDBVXYiNOuk2IhQ+dJH/+Q65fIpZCrAkaOeWxAg+z6wf/g92ytYmLCSwonge4Xx/kYAUK7QLPuON/HjtM8AYLPwJXe9m80gOlP0uttLXYERLaBi+u2puwBlzvA4JMhm7IrBWkJxSLwfkbflAcGboHeVW9urXOcPgBZmlX6Bjg4BEZLlL3m8+6ezrn929Oa3w9e03KfJqsuOAAAAAlwSFlzAAAuIwAALiMBeKU/dgAAAAd0SU1FB+kBDA8PKt1W5MYAAAAZdEVYdENvbW1lbnQAQ3JlYXRlZCB3aXRoIEdJTVBXgQ4XAAAAFUlEQVQY02P8x+rFgBswMeAFI1UaAJ65AWFYB2G5AAAAAElFTkSuQmCC\"\n            />\n         </a>\n    </span>\n</div>\n<p>\n    <spa>\n        Text Text Text Text Text Text Text Text Text Text\n    </spa>\n</p>\n</body>\n</html>\"\"\"\n\nrender_ok = False\nerror = None\nsummary_keep = \"\"\nsummary_default = \"\"\n\ntry:\n    doc = Document(SAMPLE_HTML)\n    summary_keep = doc.summary(keep_all_images=True)\n    # Create a fresh Document because summary() mutates internal state.\n    doc2 = Document(SAMPLE_HTML)\n    summary_default = doc2.summary()\n    render_ok = True\nexcept Exception as exc:\n    error = {\"name\": type(exc).__name__, \"message\": str(exc)}\n\nimg_present_keep = \"<img\" in summary_keep\nimg_present_default = \"<img\" in summary_default\n\nstate = {\n    \"render_ok\": render_ok,\n    \"error\": error,\n    \"img_present_keep\": img_present_keep,\n    \"img_present_default\": img_present_default,\n    \"summary_keep\": summary_keep,\n    \"summary_default\": summary_default,\n}\n\ndef esc_html(text):\n    return (\n        text.replace(\"&\", \"&amp;\")\n        .replace(\"<\", \"&lt;\")\n        .replace(\">\", \"&gt;\")\n        .replace('\"', \"&quot;\")\n    )\n\npage = f\"\"\"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<title>{esc_html(input_payload.get(\"title\", \"readability keep_all_images\"))}</title>\n<style>\nbody {{ font-family: Georgia, serif; margin: 2em; }}\n.column {{ width: 45%; float: left; margin-right: 5%; border: 1px solid #ccc; padding: 1em; box-sizing: border-box; }}\nh3 {{ margin-top: 0; }}\n.clear {{ clear: both; }}\n</style>\n</head>\n<body>\n<h2>Readability summary output</h2>\n<div class=\"column\">\n<h3>keep_all_images=True</h3>\n{summary_keep if render_ok else '<p style=\"color:red\">' + esc_html(error[\"name\"] + \": \" + error[\"message\"]) + '</p>'}\n</div>\n<div class=\"column\">\n<h3>keep_all_images=False (default)</h3>\n{summary_default if render_ok else '<p style=\"color:red\">' + esc_html(error[\"name\"] + \": \" + error[\"message\"]) + '</p>'}\n</div>\n<div class=\"clear\"></div>\n<script>\nwindow.__WM_STATE__ = {json.dumps(state)};\nwindow.__WM_READY__ = true;\n</script>\n</body>\n</html>\"\"\"\n\nwith open(output_path, \"w\", encoding=\"utf-8\") as fh:\n    fh.write(page)\n\ntrace_path = os.environ.get(\"WMMB_MODULE_TRACE_PATH\")\nif trace_path:\n    loaded = 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    )\n    with open(trace_path, \"w\", encoding=\"utf-8\") as fh:\n        json.dump({\"repository_modules_loaded\": loaded}, fh)",
  "rationale": "Document.summary() on the issue's sample HTML strips the image by default; the fix adds keep_all_images=True so the image is retained.",
  "repo": "buriy/python-readability",
  "schema_version": "worldmodelmmbench.render-probe.v3",
  "title": "keep_all_images preserves image in readability summary",
  "viewport": [
    1280,
    960
  ],
  "volatile_fields": []
}