from pathlib import Path def test_cancel_job_import_is_lazy_to_avoid_app_crash_on_cached_hub_versions(): jobs = Path("src/jobs.py").read_text(encoding="utf-8") first_lines = "\n".join(jobs.splitlines()[:12]) assert "cancel_job" not in first_lines assert "from huggingface_hub import cancel_job" in jobs assert "huggingface_hub.cancel_job is unavailable" in jobs def test_custom_static_scripts_have_no_syntax_errors(): import subprocess for path in Path("web/static").glob("*.js"): result = subprocess.run(["node", "--check", str(path)], capture_output=True, text=True) assert result.returncode == 0, result.stderr def test_frontend_loads_with_minimal_dom_without_throwing(): import subprocess script = r""" const fs=require('fs'); class El{ constructor(id){this.id=id;this.value='';this.textContent='';this.innerHTML='';this.dataset={};this.classList={add(){},remove(){},toggle(){}};this.style={setProperty(){}};this.attributes={};this.disabled=false;this.hidden=false;this.href='';this.open=false;this.clientHeight=100;this.scrollHeight=100;this.scrollTop=0;} addEventListener(){} setAttribute(k,v){this.attributes[k]=v} removeAttribute(k){delete this.attributes[k]} querySelectorAll(){return[]} querySelector(){return new El('child')} scrollIntoView(){} } const ids = Array.from(fs.readFileSync('web/index.html','utf8').matchAll(/id="([^"]+)"/g)).map(m=>m[1]); const map={}; for(const id of ids) map[id]=new El(id); global.document={getElementById(id){return map[id]||null},querySelectorAll(sel){if(sel.includes('filter')) return ['all','running','failed'].map(s=>{let e=new El('filter');e.dataset={status:s};return e}); return [];}}; global.window={setTimeout,setInterval,clearInterval}; global.localStorage={getItem(){return null},setItem(){},removeItem(){}}; global.confirm=()=>true; global.fetch=async()=>({ok:false,text:async()=>'forced error',json:async()=>({})}); for(const f of ['web/static/components.js','web/static/api.js','web/static/progress.js','web/static/runs.js','web/static/app.js']) global.eval(fs.readFileSync(f,'utf8')); setTimeout(()=>process.exit(0), 25); """ result = subprocess.run(["node", "-e", script], capture_output=True, text=True, timeout=5) assert result.returncode == 0, result.stderr def test_app_version_v61(): assert '"version": "v74-grouped-timeline-rings"' in Path("app.py").read_text(encoding="utf-8")