Download runtime/tools/test-guards.mjs from cdismus4/chimera-jev-full-duplex: direct link, hf CLI and curl.
- Browser
- Download file 4.59 kB
-
https://huggingface.co/cdismus4/chimera-jev-full-duplex/resolve/main/runtime/tools/test-guards.mjs
- Command line
-
hf download hf://cdismus4/chimera-jev-full-duplex/runtime/tools/test-guards.mjs
-
curl -L -o test-guards.mjs https://huggingface.co/cdismus4/chimera-jev-full-duplex/resolve/main/runtime/tools/test-guards.mjs
4.59 kB
| // ガード系の小テスト(Neon 監修の指摘対応): | |
| // (1) 先頭が長音「ー」の入力が例外なく棄却されること(仕様 integration-spec | |
| // §3.2「文頭に『ー』は置けない」)。 | |
| // (2) quietOnly: true の状況意図が TAKE_TURN 経路に吸い込まれず保持され、 | |
| // 静かなティック(SILENT_LISTEN)でバーク配送されること。 | |
| // 耳・反射・ドライバはスタブ(runTick / runDriver 差し替え)で代替し、 | |
| // 口のプランナだけ実物を使う。資産はパックのレイアウトから読む | |
| // (環境変数 JEV_ASSET_ROOT で差し替え可、test-body.mjs と同じ方式)。 | |
| import { readFileSync } from 'node:fs'; | |
| import { fileURLToPath } from 'node:url'; | |
| import { dirname, join } from 'node:path'; | |
| const HERE = dirname(fileURLToPath(import.meta.url)); | |
| const KIT = join(HERE, '..'); | |
| const PACK = process.env.JEV_ASSET_ROOT || join(KIT, '..'); | |
| let simNow = 0; | |
| globalThis.performance = { now: () => simNow, timeOrigin: 0 }; | |
| const { BodyCore, makeMoraSplitter, buildDriverInputs } = await import('../src/body-core.js'); | |
| const { ChimeraPlanner } = await import('../src/mouth.js'); | |
| const tables = JSON.parse(readFileSync(join(PACK, 'driver', 'driver_tables.json'), 'utf8')); | |
| const bank = JSON.parse(readFileSync(join(PACK, 'lexicon', 'jev-lexical-bank-v1.json'), 'utf8')); | |
| const planner = await ChimeraPlanner.create(readFileSync(join(PACK, 'mouth', 'chimera.wasm'))); | |
| let pass = 0, fail = 0; | |
| const check = (name, cond) => { console.log((cond ? 'PASS' : 'FAIL') + ' ' + name); cond ? pass++ : fail++; }; | |
| // ---------- (1) 先頭「ー」の棄却 ---------- | |
| const split = makeMoraSplitter(tables); | |
| check('分割:先頭「ー」のみは棄却(null)', split('ー') === null); | |
| check('分割:先頭「ー」+本文は棄却(null)', split('ーあい') === null); | |
| const mid = split('あーい'); | |
| check('分割:文中・文末の「ー」は正常に分割できる', Array.isArray(mid) && mid.length === 3); | |
| let threw = false; | |
| try { buildDriverInputs(tables, ['ー', 'あ']); } catch { threw = true; } | |
| check('ドライバ前処理:先頭「ー」を直接渡しても例外にならない', !threw); | |
| // ---------- (2) quietOnly 意図の TAKE_TURN バイパス防止 ---------- | |
| // 反射スタブ:argmax をテスト側で切り替える。状態はゼロのまま回す。 | |
| let argmax = 2; // TAKE_TURN | |
| const runTick = async () => { | |
| const logits = new Float32Array(6); | |
| logits[argmax] = 1; | |
| return { | |
| earMs: 0, reflexMs: 0, logits, | |
| queryVec: new Float32Array(128), | |
| stateOut: new Float32Array(4 * 384), | |
| zStateOut: new Float32Array(8), | |
| }; | |
| }; | |
| const runDriver = async ({ segMora }) => ({ | |
| driverMs: 0, | |
| ov: new Float32Array(segMora.length * 19), | |
| logDur: new Float32Array(segMora.length), | |
| }); | |
| const said = []; | |
| const core = new BodyCore({ | |
| ort: null, earSess: null, reflexSess: null, driverSess: null, | |
| runTick, runDriver, tables, bank, planner, | |
| speakOut: async () => ({ durationSec: 0.5, peakRms: 0.1 }), | |
| log: () => {}, | |
| onUtterance: (text) => said.push(text), | |
| }); | |
| const silence = new Float32Array(7680); | |
| const INTENT_TEXT = 'ごめんもいちどいって'; | |
| check('前提:意図テキストがモーラ分割できる', split(INTENT_TEXT) !== null); | |
| check('前提:意図テキストは語彙バンクに無い言葉', !bank.entries.some((e) => e.kana === INTENT_TEXT)); | |
| // quietOnly が既定で付く tag 'overlap' で状況意図を預ける | |
| core.setSituationIntent('overlap', { text: INTENT_TEXT }); | |
| check('前提:overlap 意図は quietOnly', core.intents.intent && core.intents.intent.quietOnly === true); | |
| // TAKE_TURN が続く間、意図は消費されず・発話もされないこと | |
| for (let t = 0; t < 40; t++) { simNow = t * 80; await core.tick(silence, simNow); } | |
| check('TAKE_TURN 経路で quietOnly 意図が消費されない', !!core.intents.intent && core.intents.intent.tag === 'overlap'); | |
| check('TAKE_TURN 経路で quietOnly 意図が発話されない', !said.includes(INTENT_TEXT)); | |
| // 静かなティックではバークで届くこと(発話ブロック明けまで回す) | |
| argmax = 0; // SILENT_LISTEN | |
| let route = null; | |
| for (let t = 40; t < 160 && route !== 'bark'; t++) { | |
| simNow = t * 80; | |
| const r = await core.tick(silence, simNow); | |
| if (r && r.said === INTENT_TEXT) route = r.route; | |
| } | |
| check('静かなティックで quietOnly 意図がバーク配送される', route === 'bark' && said.includes(INTENT_TEXT)); | |
| console.log(`--- ${pass} PASS / ${fail} FAIL`); | |
| process.exit(fail ? 1 : 0); | |