Datasets:
Download code/evaluation-code/ent400-a06a1576/apps/console/web/tests/script-aside.test.ts from VEHwang/cocogni4d: direct link, hf CLI and curl.
- Browser
- Download file 7.48 kB
-
https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/evaluation-code/ent400-a06a1576/apps/console/web/tests/script-aside.test.ts
- Command line
-
hf download hf://datasets/VEHwang/cocogni4d/code/evaluation-code/ent400-a06a1576/apps/console/web/tests/script-aside.test.ts
-
curl -L -o script-aside.test.ts https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/evaluation-code/ent400-a06a1576/apps/console/web/tests/script-aside.test.ts
7.48 kB
| import test from 'node:test'; | |
| import assert from 'node:assert/strict'; | |
| import type {Intent, ReviewEvent, ScriptReview, SegmentView} from '../src/contract.ts'; | |
| import {readFileSync} from 'node:fs'; | |
| import {createElement} from 'react'; | |
| import {renderToStaticMarkup} from 'react-dom/server'; | |
| import {Review} from '../src/Review.tsx'; | |
| import {adjacentEvent, arrangementList, entityScript, groupSituations, splitLine} from '../src/script-aside.ts'; | |
| const event = (id: string, kind: string, entity_ids=['actor-000'], start=0): ReviewEvent => ({ | |
| id, kind, entity_ids, label: id, span_s: [start, start+1], status: 'NOT_CHECKED', | |
| source: '测试夹具', basis: '', regions_uv: [], | |
| }); | |
| test('段页显示源朝向缺失提醒,时间轴容器与样式选择器一致', () => { | |
| const view = { | |
| schema: 'segment-view/6', builder_version: 'review-import/2', tracks_max_error_m: 0, | |
| segment: {id: 'source/segment', script_id: 'segment', world_id: 'world', span_s: [0, 1], duration_s: 1, control_hz: 20}, | |
| provenance: {generator_version: 'source', artifact_sha256: '0'.repeat(64)}, | |
| actors: [{id: 'actor-000', kind: 'robot', order: 0}], observers: {}, discards: [], | |
| tracks: {'actor-000': {t_s: [0, 1], u_m: [0, 0], v_m: [0, 0], speed_mps: [0, 0]}}, states: {'actor-000': []}, intents: {'actor-000': []}, | |
| basemap: {bounds_uv: [[0, 0], [1, 1]], raster: {url: '/basemap.png'}, rooms: [], doorways: [], stop_points: [], occluder_contours_uv: []}, | |
| generation: {method: 'source_without_intent_records', events: [], event_counts: {}, budgets: [], observer_generation: {omitted: []}}, | |
| construction: {discard_groups: []}, metric_units: {}, warnings: [{code: 'SOURCE_BODY_YAW_MISSING', message: 'source warning'}], | |
| review: {planned: [], actual_arrangements: null, situations: [], questions: [], question_counts: {PASS: 0, FAIL: 0, UNKNOWN: 0}, situation_missing: []}, | |
| } as unknown as SegmentView; | |
| const previous = Object.getOwnPropertyDescriptor(globalThis, 'location'); | |
| Object.defineProperty(globalThis, 'location', {configurable: true, value: {hash: ''}}); | |
| try { | |
| const render = () => renderToStaticMarkup(createElement(Review, {view, media: null, mediaError: '', initialTime: 0, initialActors: null})); | |
| const html = render(), css = readFileSync(new URL('../src/motion-timelines.css', import.meta.url), 'utf8'); | |
| assert.match(html, /<p class="future-data">原意图:无数据。机身朝向:无数据。/); | |
| assert.match(html, /<details class="review-timelines" open=""><summary>时间轴:状态、安排与情形<\/summary>/); | |
| assert.match(css, /\.review-timelines\s*\{/); | |
| assert.match(css, /\.review-timelines\s*>\s*summary\s*\{/); | |
| view.warnings = []; | |
| assert.doesNotMatch(render().match(/<p class="future-data">[^<]*/)?.[0] || '', /机身朝向:无数据。/); | |
| } finally {if (previous) Object.defineProperty(globalThis, 'location', previous); else Reflect.deleteProperty(globalThis, 'location');} | |
| }); | |
| test('安排清单收计划、情形和动作安排,默认只列没生效和偏了的(设计 3-3)', () => { | |
| const s = (id: string, status: ReviewEvent['status'], kind = '停在某处') => ({...event(id, kind), status}); | |
| const review = {planned: [event('p', 'observer_body')], situations: [], actual_arrangements: [s('a', 'effective'), s('b', 'ineffective'), s('c', 'deviated', '两者相遇'), s('d', 'deviated', '标定视角')]}; | |
| const problems = arrangementList(review, false), all = arrangementList(review, true); | |
| assert.deepEqual([problems.total, problems.problems], [5, 2]); | |
| assert.deepEqual(problems.groups.map(g => [g.kind, g.events.map(e => e.id)]), [['停在某处', ['b']], ['两者相遇', ['c']]]); | |
| assert.deepEqual(all.groups.flatMap(g => g.events.map(e => e.id)).sort(), ['a', 'b', 'c', 'd', 'p']); | |
| assert.deepEqual(arrangementList(undefined, false), {groups: [], total: 0, problems: 0}); | |
| }); | |
| test('安排情形合并后按 id 去重,按 kind 汇总并保留未知类别与未绑定时段', () => { | |
| // 服务端给的 kind 已是中文名(segment_conversion.generator_arrangements 取 GENERATOR_TYPE_LABELS),台里不另译 | |
| const planned = [event('p','共视区域'), event('x','看到对方本体')]; | |
| const situations = [event('p','共视区域'), event('s','共视区域'), {...event('u','新情形'),span_s:null}]; | |
| const before = JSON.stringify([planned,situations]); | |
| const groups = groupSituations(planned,situations); | |
| assert.deepEqual(groups.map(g=>[g.label,g.count,g.events.map(e=>e.id)]), [ | |
| ['共视区域',2,['p','s']],['看到对方本体',1,['x']],['新情形',1,['u']], | |
| ]); | |
| assert.equal(groups.reduce((n,g)=>n+g.count,0),4); | |
| assert.equal(groups[0].events[0],planned[0]); | |
| assert.deepEqual(groupSituations([],[]),[]); | |
| assert.equal(JSON.stringify([planned,situations]),before); | |
| }); | |
| test('主体剧本仅匹配首个实体并按起点排序,含观察者;仅缺 review 时回退原意图', () => { | |
| const rows=[event('late','前往',['observer-000'],20),event('other','前往',['actor-000','observer-000'],0),event('early','停留',['observer-000'],2),{...event('unbound','前往',['observer-000']),span_s:null}]; | |
| const review={actual_arrangements:rows} as ScriptReview; | |
| const intents={'observer-000':[ | |
| {intent_index:2,kind:'stay',start_s:7,end_s:10,target:null,status:'truncated'}, | |
| {intent_index:1,kind:'go_to',start_s:0,end_s:7,target:{stop_id:'站35'},status:'completed'}, | |
| ] as Intent[]}; | |
| assert.deepEqual(entityScript(review,intents,'observer-000').map(e=>e.id),['early','late','unbound']); | |
| assert.deepEqual(rows.map(e=>e.id),['late','other','early','unbound']); | |
| assert.deepEqual(entityScript(review,intents,'missing'),[]); | |
| assert.deepEqual(entityScript({...review,actual_arrangements:null},intents,'observer-000'),[]); | |
| const fallback=entityScript(undefined,intents,'observer-000'); | |
| assert.deepEqual(fallback.map(e=>[e.kind,e.span_s,e.label,e.statusLabel]),[ | |
| ['前往',[0,7],'站35','完成'],['停留',[7,10],'原地','截断'], | |
| ]); | |
| assert(fallback.every(e=>e.status==='NOT_CHECKED'&&e.entity_ids[0]==='observer-000')); | |
| assert.equal(new Set(fallback.map(e=>e.id)).size,2); | |
| assert.deepEqual(entityScript(undefined,{},'missing'),[]); | |
| }); | |
| test('上一条下一条在首尾夹紧;空列表、单条与未选中均有明确结果', () => { | |
| const rows=[event('a','a'),event('b','b'),event('c','c')]; | |
| for (const [id,direction,expected] of [['a',-1,'a'],['a',1,'b'],['b',-1,'a'],['b',1,'c'],['c',1,'c'],['c',-1,'b'],[null,1,'a'],['missing',-1,'a']] as const) { | |
| assert.equal(adjacentEvent(rows,id,direction)?.id,expected); | |
| } | |
| for (const direction of [-1,1] as const) { | |
| assert.equal(adjacentEvent([],null,direction),null); | |
| assert.equal(adjacentEvent([rows[0]],'a',direction),rows[0]); | |
| } | |
| }); | |
| test('录像错开:两路记的同一件事只写一句;不错开、排不开、没有记录各自分开', () => { | |
| const time = {layer: 'time' as const, mover: 'actor-001', first_s: 12.34, second_s: 51, early_view: 'A'}; | |
| assert.equal(splitLine({A: {split: time}, B: {split: time}}), '录像按时间错开:actor-001 两次过门 12.3 s、51.0 s,先录的是 A'); | |
| assert.equal(splitLine({A: {split: {layer: 'none', drawn: true}}}), '录像不错开:抽中了按时间错开,但排不开'); | |
| assert.equal(splitLine({A: {split: {layer: 'none'}}}), '录像不错开'); | |
| assert.equal(splitLine({A: {}, B: {}}), null); | |
| assert.equal(splitLine(undefined), null); | |
| }); | |