Download web/tests/plan-checks.test.mjs from loveaa/OneAlign: direct link, hf CLI and curl.
- Browser
- Download file 4.08 kB
-
https://huggingface.co/spaces/loveaa/OneAlign/resolve/main/web/tests/plan-checks.test.mjs
- Command line
-
hf download hf://spaces/loveaa/OneAlign/web/tests/plan-checks.test.mjs
-
curl -L -o plan-checks.test.mjs https://huggingface.co/spaces/loveaa/OneAlign/resolve/main/web/tests/plan-checks.test.mjs
4.08 kB
| import test from 'node:test' | |
| import assert from 'node:assert/strict' | |
| import {explicitDurations,explicitTimes,semanticIssues} from '../server/plan-checks.mjs' | |
| import {validateContract} from '../server/planner.mjs' | |
| const plan=()=>({version:1,status:'ready',title:'观察',summary_zh:'观察当前画面',clarification_questions:[],assumptions:[],observers:[{id:'q1',title:'人物',question_en:'Is a person visible in this view?',input:'single',options:{target:'A person is visible',other:'No person is visible',unknown:'Insufficient evidence'},labels_zh:{target:'有人',other:'无人',unknown:'无法确认'}}],rules:[{id:'r1',title:'提醒',mode:'occurrence',condition:{operator:'all',terms:[{observer:'q1',values:['target']}]},then:null,duration_seconds:0,within_seconds:0,time_window:null,exclude_window:null,requires:[],notify:'realtime',level:1,confirmation_frames:2,cooldown_seconds:1800}]}) | |
| test('Chinese durations and clock windows preserve numerical values',()=>{ | |
| assert.deepEqual(explicitDurations('停留四十五秒,一分钟,半小时').map(x=>x.seconds),[45,60,1800]) | |
| assert.deepEqual(explicitTimes('晚上8点到8点半'),['20:00','20:30']) | |
| assert.deepEqual(explicitTimes('19:15到19:45'),['19:15','19:45']) | |
| }) | |
| test('wrong duration is rejected even when JSON is valid',()=>{ | |
| const p=plan();p.rules[0].mode='duration';p.rules[0].duration_seconds=60 | |
| assert.equal(validateContract(p).status,'ready') | |
| assert.ok(semanticIssues('门口有人停留超过30秒提醒我',p).length) | |
| p.rules[0].duration_seconds=30 | |
| assert.deepEqual(semanticIssues('门口有人停留超过30秒提醒我',p),[]) | |
| }) | |
| test('away, rain and doorbell cannot be invented from images',()=>{ | |
| const p=plan();assert.equal(semanticIssues('我不在家时下雨且有人按门铃提醒我',p).length,3) | |
| p.rules[0].requires=['away','rain','doorbell'];assert.deepEqual(semanticIssues('我不在家时下雨且有人按门铃提醒我',p),[]) | |
| }) | |
| test('entry and package interaction retain action semantics',()=>{ | |
| const p=plan();assert.ok(semanticIssues('有人从玄关进家告诉我',p).length) | |
| assert.ok(semanticIssues('有人动门口的包裹告诉我',p).length) | |
| p.observers[0].question_en='Is a person touching or handling the package?' | |
| assert.deepEqual(semanticIssues('有人动门口的包裹告诉我',p),[]) | |
| p.rules[0].mode='change';assert.ok(semanticIssues('有人动门口的包裹告诉我',p).length) | |
| }) | |
| test('unconfirmed homework proxy and unregistered reference are rejected',()=>{ | |
| const p=plan();assert.ok(semanticIssues('孩子写作业了没',p).length) | |
| p.observers[0].input='reference';assert.ok(semanticIssues('有人出现告诉我',p).length) | |
| p.status='needs_clarification';p.clarification_questions=['是否改为观察桌前写字?'] | |
| assert.deepEqual(semanticIssues('孩子写作业了没',p),[]) | |
| }) | |
| test('sequence cannot silently drop its time bound',()=>{ | |
| const p=plan();p.rules[0].mode='sequence';p.rules[0].then=p.rules[0].condition;p.rules[0].within_seconds=600 | |
| assert.ok(semanticIssues('有人离开后五分钟内又回来提醒我',p).length) | |
| p.rules[0].within_seconds=300;assert.deepEqual(semanticIssues('有人离开后五分钟内又回来提醒我',p),[]) | |
| }) | |
| test('exclude window and summary delivery remain explicit',()=>{ | |
| const p=plan();assert.ok(semanticIssues('每天10:00到10:30那段不用提醒',p).length) | |
| p.rules[0].exclude_window={start:'10:00',end:'10:30'} | |
| assert.deepEqual(semanticIssues('每天10:00到10:30那段不用提醒',p),[]) | |
| assert.ok(semanticIssues('晚上8点到8点半,到点告诉我结果',p).length) | |
| p.rules[0].mode='window_summary';p.rules[0].notify='summary';p.rules[0].time_window={start:'20:00',end:'20:30'} | |
| assert.deepEqual(semanticIssues('晚上8点到8点半,到点告诉我结果',p),[]) | |
| }) | |
| test('contract rejects dangling observations and missing Unknown',()=>{ | |
| const p=plan();p.rules[0].condition.terms[0].observer='missing';assert.throws(()=>validateContract(p)) | |
| p.rules[0].condition.terms[0].observer='q1';delete p.observers[0].options.unknown;assert.throws(()=>validateContract(p)) | |
| }) | |