{
  "protocol": {
    "synthetic": true,
    "scope": "Read-only queries against our own127.0.0.1fixture. No customer systems, no Think2integration.",
    "expected": {
      "reference": "D-17",
      "status": "PENDING"
    },
    "scenarios": [
      "baseline:oldselector/oldschema",
      "selectorchange:DOMrenamed/APIunchanged",
      "schemachange:UIunchanged/APIstatusrenamed",
      "denied:HTTP401both"
    ],
    "checks": "Fail closed on empty selector/missing status/non2xx. Body text200 is not a sufficient success criterion.",
    "limits": "HeadlessDOMquery is only a small UI automation pattern, not full desktopRPA; no browserclicks/OCR/login/writes/concurrency/productioncostmeasured."
  },
  "date": "2026-11-16T19:23:52Z",
  "results": [
    {
      "scenario": "baseline",
      "api": {
        "http": 200,
        "value": {
          "reference": "D-17",
          "status": "PENDING"
        },
        "contract_passed": true
      },
      "ui": {
        "http": 200,
        "value": {
          "reference": "D-17",
          "status": "PENDING"
        },
        "contract_passed": true
      }
    },
    {
      "scenario": "selectorchange",
      "api": {
        "http": 200,
        "value": {
          "reference": "D-17",
          "status": "PENDING"
        },
        "contract_passed": true
      },
      "ui": {
        "http": 200,
        "value": {
          "reference": "D-17",
          "status": null
        },
        "contract_passed": false
      }
    },
    {
      "scenario": "schemachange",
      "api": {
        "http": 200,
        "value": {
          "reference": "D-17",
          "state": "PENDING"
        },
        "contract_passed": false
      },
      "ui": {
        "http": 200,
        "value": {
          "reference": "D-17",
          "status": "PENDING"
        },
        "contract_passed": true
      }
    },
    {
      "scenario": "denied",
      "api": {
        "http": 401,
        "value": {
          "error": "unauthorized"
        },
        "contract_passed": false
      },
      "ui": {
        "http": 401,
        "value": {},
        "contract_passed": false
      }
    }
  ],
  "scripts": {
    "t03-prueba.py": "import json,threading,subprocess,tempfile,time,hashlib,sys,argparse,os\nfrom http.server import ThreadingHTTPServer,BaseHTTPRequestHandler\nfrom pathlib import Path\nparser=argparse.ArgumentParser();parser.add_argument('--out',required=True);args=parser.parse_args();p=Path(args.out).resolve();p.mkdir(parents=True,exist_ok=True);script_dir=Path(__file__).resolve().parent\nprotocol={'synthetic':True,'scope':'Read-only queries against our own127.0.0.1fixture. No customer systems, no Think2integration.','expected':{'reference':'D-17','status':'PENDING'},'scenarios':['baseline:oldselector/oldschema','selectorchange:DOMrenamed/APIunchanged','schemachange:UIunchanged/APIstatusrenamed','denied:HTTP401both'],'checks':'Fail closed on empty selector/missing status/non2xx. Body text200 is not a sufficient success criterion.','limits':'HeadlessDOMquery is only a small UI automation pattern, not full desktopRPA; no browserclicks/OCR/login/writes/concurrency/productioncostmeasured.'}\n(p/'protocolo.json').write_text(json.dumps(protocol,indent=2)+'\\n')\nclass H(BaseHTTPRequestHandler):\n def log_message(self,*args):pass\n def do_GET(self):\n  scenario=self.path.split('?')[-1];api=self.path.startswith('/api');code=401 if scenario=='denied' else 200\n  if api: body=json.dumps({'error':'unauthorized'} if code==401 else {'reference':'D-17',('state' if scenario=='schemachange' else 'status'):'PENDING'});ctype='application/json'\n  else:\n   ident='new-status' if scenario=='selectorchange' else 'status';body=('<html><body>Unauthorized</body></html>' if code==401 else f'<html><body><p>Reference: D-17</p><span id=\"{ident}\">PENDING</span></body></html>');ctype='text/html'\n  self.send_response(code);self.send_header('Content-Type',ctype);self.end_headers();\n  try:self.wfile.write(body.encode())\n  except (BrokenPipeError,ConnectionResetError):pass\ns=ThreadingHTTPServer(('127.0.0.1',0),H);threading.Thread(target=s.serve_forever,daemon=True).start();port=s.server_port\nfrom urllib.request import urlopen\nfrom urllib.error import HTTPError\nresults=[]\nfor scenario in ['baseline','selectorchange','schemachange','denied']:\n row={'scenario':scenario}\n for mode in ['api','ui']:\n  u=f'http://127.0.0.1:{port}/{mode}?{scenario}'\n  try:\n   with urlopen(u) as r:code=r.status;body=r.read().decode()\n  except HTTPError as e:code=e.code;body=e.read().decode()\n  if mode=='ui' and code==200:\n   proc=subprocess.run(['node',str(script_dir/'t03-dom.mjs'),u,str(p/f'{scenario}.dom.html')],capture_output=True,text=True,timeout=25)\n   if proc.returncode:raise RuntimeError(proc.stderr)\n   value=json.loads(proc.stdout)\n  elif mode=='api':value=json.loads(body)\n  else:value={}\n  ok=code==200 and value.get('reference')=='D-17' and value.get('status')=='PENDING';row[mode]={'http':code,'value':value,'contract_passed':ok}\n results.append(row);print(json.dumps(row),flush=True)\ns.shutdown();e={'protocol':protocol,'date':time.strftime('%Y-%m-%dT%H:%M:%SZ',time.gmtime()),'results':results};(p/'seo178-t03-prueba-16nov.json').write_text(json.dumps(e,indent=2)+'\\n')\nassert [[r[m]['contract_passed'] for m in ['api','ui']] for r in results]==[[True,True],[True,False],[False,True],[False,False]]\nprint('PASS4scenarios/8queries; noexternalserviceused',flush=True)\n",
    "t03-dom.mjs": "import {spawn} from 'node:child_process';import fs from 'node:fs';import os from 'node:os';import path from 'node:path';\nconst dir=fs.mkdtempSync(path.join(os.tmpdir(),'seo178-t03-cdp-'));const port=0;const proc=spawn(process.env.CHROMIUM_BIN||'chromium',['--headless','--no-sandbox','--disable-gpu','--disable-dev-shm-usage','--disable-background-networking','--no-proxy-server','--no-first-run','--disable-extensions','--remote-debugging-port='+port,'--user-data-dir='+dir,'about:blank'],{stdio:'ignore',detached:true});let ws;\ntry{let tabs,actualPort;for(let i=0;i<40;i++){try{actualPort=fs.readFileSync(path.join(dir,'DevToolsActivePort'),'utf8').split('\\n')[0];tabs=await(await fetch('http://127.0.0.1:'+actualPort+'/json/list')).json();break;}catch{}await new Promise(r=>setTimeout(r,250));}if(!tabs)throw Error('CDP unavailable');ws=new WebSocket(tabs.find(t=>t.type==='page').webSocketDebuggerUrl);await new Promise((r,j)=>{ws.onopen=r;ws.onerror=j;});let n=0;const pending=new Map();ws.onmessage=e=>{const d=JSON.parse(e.data);if(d.id){pending.get(d.id)?.(d);pending.delete(d.id);}};const call=(method,params={})=>new Promise((r,j)=>{const id=++n;pending.set(id,r);ws.send(JSON.stringify({id,method,params}));setTimeout(()=>{if(pending.has(id)){pending.delete(id);j(Error('CDP timeout '+method));}},6000).unref();});await call('Page.enable');await call('Page.navigate',{url:process.argv[2]});let value;for(let i=0;i<30;i++){await new Promise(r=>setTimeout(r,100));const d=await call('Runtime.evaluate',{expression:'document.querySelector(\"p\") ? JSON.stringify({reference:document.querySelector(\"p\").textContent.replace(\"Reference: \",\"\"),status:document.querySelector(\"#status\")?.textContent??null}) : null',returnByValue:true});value=d.result?.result?.value;if(value)break;}if(!value)throw Error('No result element');const dom=await call('Runtime.evaluate',{expression:'document.documentElement.outerHTML',returnByValue:true});if(process.argv[3])fs.writeFileSync(process.argv[3],dom.result.result.value);console.log(value);}\ncatch(e){console.error(e.message);process.exitCode=1;}finally{ws?.close();try{process.kill(-proc.pid,'SIGTERM');}catch{}await new Promise(r=>setTimeout(r,300));fs.rmSync(dir,{recursive:true,force:true});}\n"
  },
  "dom": {
    "schemachange.dom.html": "<html><head></head><body><p>Reference: D-17</p><span id=\"status\">PENDING</span></body></html>",
    "selectorchange.dom.html": "<html><head></head><body><p>Reference: D-17</p><span id=\"new-status\">PENDING</span></body></html>",
    "baseline.dom.html": "<html><head></head><body><p>Reference: D-17</p><span id=\"status\">PENDING</span></body></html>"
  },
  "environment": {
    "python": "3.13",
    "node": "22.23.3",
    "chromium": "154.0.8037.92",
    "address": "127.0.0.1only",
    "screen_used": false
  },
  "history": "Initialdump-domlaunches timedout,cleanupfailed;CDPclientreadcorrected,finalreadDOMbyclientnotpage-script. Fixture401doesnotimplementWWW-Authenticate. No login/authproductionvalidation.",
  "original_evidence_sha256": "5267e99fa4ee56241b39888155cb05c873872b47f29cd06385ad889157fd140e",
  "portability": {
    "requirements": "Linux/macOSPOSIX,Python3.10+stdlibrary,Node22+conWebSocketglobal,Chromiuminstalado. No dependenciasnpm/pip. Ejemplo comprobadoLinuxPython3.13/Node22.23.3/Chromium154.0.8037.92;no garantíaotrosentornos.",
    "security": "Scripts propios ofrecidos como datos para revisión. Descargar en directorio nuevo vacío. Extraer scripts a otro directorio propio;no ejecutardentro de directorio descargado. Python-I. CHROMIUM_BINes rutaalbinarioejecutable, no claves. Headless usa--no-sandbox para esta fixturelocal sin datoscliente; no usarpara websajenas. No instala ni llama servicios externos.",
    "instructions": [
      "Guardar este JSON como paquete.json en un directorio nuevo para datos.",
      "Crear directorio hermano propio run-scripts y outputs. Revisar los dos textos bajo scripts antesde ejecutar.",
      "Extraer exactamente las claves t03-prueba.py y t03-dom.mjs a run-scripts mediante extractorstdlib deabajo.",
      "Definir CHROMIUM_BIN con la ruta completa de un binarioChromium (no un lanzador que agregue perfilprincipal). NODEenPATH.",
      "Desde cualquierdirectoriodistinto aldedescarga: python3 -I /ruta/run-scripts/t03-prueba.py --out /ruta/outputs.",
      "Verificar cuatrofilas TT/TF/FT/FF yPASS. Resultadosnuevosvanoutputs,no sobrescribirevidenciaoriginalincluidaenJSON."
    ],
    "extraction_python": "import json,sys\nfrom pathlib import Path\nd=json.loads(Path(sys.argv[1]).read_text());out=Path(sys.argv[2]).resolve();out.mkdir(parents=True,exist_ok=True)\nfor name in [\"t03-prueba.py\",\"t03-dom.mjs\"]:(out/name).write_text(d[\"scripts\"][name])\n",
    "extraction_command": "python3 -I /ruta/a/extractor-propio.py /ruta/datos/paquete.json /ruta/run-scripts",
    "run_command": "CHROMIUM_BIN=/ruta/al/binario/chromium python3 -I /ruta/run-scripts/t03-prueba.py --out /ruta/outputs",
    "separation": "Resultadosoriginales2026-11-16T19:23 no regenerados; nueva ejecución portability_test se incorporará por separado."
  },
  "portability_test": {
    "job": "tmwjnpepd2cbf",
    "execution": {
      "protocol": {
        "synthetic": true,
        "scope": "Read-only queries against our own127.0.0.1fixture. No customer systems, no Think2integration.",
        "expected": {
          "reference": "D-17",
          "status": "PENDING"
        },
        "scenarios": [
          "baseline:oldselector/oldschema",
          "selectorchange:DOMrenamed/APIunchanged",
          "schemachange:UIunchanged/APIstatusrenamed",
          "denied:HTTP401both"
        ],
        "checks": "Fail closed on empty selector/missing status/non2xx. Body text200 is not a sufficient success criterion.",
        "limits": "HeadlessDOMquery is only a small UI automation pattern, not full desktopRPA; no browserclicks/OCR/login/writes/concurrency/productioncostmeasured."
      },
      "date": "2026-11-16T19:28:46Z",
      "results": [
        {
          "scenario": "baseline",
          "api": {
            "http": 200,
            "value": {
              "reference": "D-17",
              "status": "PENDING"
            },
            "contract_passed": true
          },
          "ui": {
            "http": 200,
            "value": {
              "reference": "D-17",
              "status": "PENDING"
            },
            "contract_passed": true
          }
        },
        {
          "scenario": "selectorchange",
          "api": {
            "http": 200,
            "value": {
              "reference": "D-17",
              "status": "PENDING"
            },
            "contract_passed": true
          },
          "ui": {
            "http": 200,
            "value": {
              "reference": "D-17",
              "status": null
            },
            "contract_passed": false
          }
        },
        {
          "scenario": "schemachange",
          "api": {
            "http": 200,
            "value": {
              "reference": "D-17",
              "state": "PENDING"
            },
            "contract_passed": false
          },
          "ui": {
            "http": 200,
            "value": {
              "reference": "D-17",
              "status": "PENDING"
            },
            "contract_passed": true
          }
        },
        {
          "scenario": "denied",
          "api": {
            "http": 401,
            "value": {
              "error": "unauthorized"
            },
            "contract_passed": false
          },
          "ui": {
            "http": 401,
            "value": {},
            "contract_passed": false
          }
        }
      ]
    },
    "original_results_preserved": true,
    "execution_count": 1,
    "extraction_and_run_followed_instructions": true,
    "output_nested_parents_created": true,
    "input_scripts_different_directories": true,
    "source_of_environment": "LinuxPython3.13/Node22.23.3/Chromium154.0.8037.92",
    "new_result_sha256": "fd20bf87eb03204608ee2e85cfe2753ea3896efc4c61e093f503474d55a27133"
  }
}
