Spaces:
Sleeping
Sleeping
Download test_subtasks.mjs from Mushari440/benchmark: direct link, hf CLI and curl.
- Browser
- Download file 2.31 kB
-
https://huggingface.co/spaces/Mushari440/benchmark/resolve/main/test_subtasks.mjs
- Command line
-
hf download hf://spaces/Mushari440/benchmark/test_subtasks.mjs
-
curl -L -o test_subtasks.mjs https://huggingface.co/spaces/Mushari440/benchmark/resolve/main/test_subtasks.mjs
2.31 kB
| // A missing detail renderer, unsafe labels, zero-score hiding, or cross-version | |
| // reuse must fail these tests. Existing DOM/Hub startup is isolated by the same | |
| // harness as smoke_board; assertions exercise production HTML rendering. | |
| import fs from 'node:fs'; | |
| import assert from 'node:assert/strict'; | |
| const here=new URL('.',import.meta.url); | |
| const smoke=fs.readFileSync(new URL('smoke_board.mjs',here),'utf8'); | |
| const setup=smoke.slice(smoke.indexOf('const el ='),smoke.indexOf('let threw =')); | |
| new Function(setup)(); | |
| const script=fs.readFileSync(new URL('index.html',here),'utf8').match(/<script>([\s\S]*)<\/script>/)[1]; | |
| const ctx=new Function(script+';return {details:typeof subtaskDetailsHTML==="function"?subtaskDetailsHTML:null};')(); | |
| assert.equal(typeof ctx.details,'function','Clicking a row needs the subtask details renderer'); | |
| const data={version:'v12',split:'test',primary_score_policy:'failures_as_zero',expected_count:5,rows:[ | |
| {task_id:'arabic',task_label:'Arabic language understanding',subtask_id:'correction',label:'Text correction: MSA / mixed Arabic-English',score:0,count:2,unresolved_count:1,error_count:1}, | |
| {task_id:'arabic',task_label:'Arabic language understanding',subtask_id:'diacritization',label:'Arabic diacritization',score:1,count:3,unresolved_count:0,error_count:0} | |
| ]}; | |
| let result=ctx.details(data,'v12'); | |
| assert.match(result,/Text correction: MSA \/ mixed Arabic-English/); | |
| assert.match(result,/0\.00%/,'A zero score must remain a scored result'); | |
| assert.match(result,/100\.00%/); | |
| assert.match(result,/60\.00%/,'The task score must be item weighted: 3/5, not 1/2'); | |
| assert.match(result,/Unresolved/); | |
| assert.equal((result.match(/class="subtask-result"/g)||[]).length,2); | |
| assert.match(ctx.details(null,'v12'),/not available/i,'Old reports must not invent subtasks'); | |
| assert.match(ctx.details(data,'v11'),/not available/i,'v12 rows must never appear on v11'); | |
| const hostile=structuredClone(data);hostile.rows[0].label='<img src=x onerror=alert(1)>';hostile.rows[0].task_label='<script>alert(1)</script>'; | |
| result=ctx.details(hostile,'v12');assert.ok(!result.includes('<img'));assert.ok(!result.includes('<script>'));assert.match(result,/<img/); | |
| console.log('PASS: zero/full scores, weighted groups, unavailable/version boundaries and escaped labels'); | |
| process.exit(0); | |