Files
QLinker/tools/probe/record-decoder-probe.mjs
T
xiaowang a2a781ab4c docs(p1): 补齐 record/私聊/转发读回三证据,定性合并转发不可还原
- 新增 forward-readback-probe(只读):对 history 全部 8 条外层 multimsg 逐条
  重试 get_forward_msg,含数分钟前的 seq=3115,19 种参数组合全失败,
  排除「消息已过期」解释,确认为接口能力缺口(第 20.2 旧依据就地标注缺陷)
- 关键发现:news[].text 能否 parse 成段数组取决于当初 node.content 传数组还是
  JSON 字符串,唯一能 parse 的两条恰是发送形态用错的那两条 ⇒ 属字面文本假象,
  非还原能力。正确形态下段类型与嵌套结构不可逆丢失(GC-012, severity high)
- 未采边界显式登记:正确形态样本节点全是 text,媒体节点降级形态无实测依据,
  不得宣称「只是降级为文本」
- get_msg 实测 9/9 retcode=0 ⇒ 新增 OP-get-msg,作为不依赖 history 窗口分页的
  单条定点读回路径,用于兜底 file 段零事件与私聊 history 分页缺口
- resid 非恒定存在(tsum=0 的静默失效消息 detail_keys 无 resid)⇒ 按可空建模
- record 定性收紧为 MSG-record / MSG-record-silk / MSG-record-transcode 三项;
  私聊段矩阵第三证据 6/6 一致;门禁缺测项 1 → 0
- 能力基线 29 → 30 项、globalConstraints 11 → 12;capability-check 识别
  forwardReadback 自动源。结构校验 0 错误 0 警告,漂移比对自动 21 项、
  漂移 0、缺测 0、人工确认 4 → PASS
2026-10-29 16:27:51 +08:00

96 lines
5.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// record 解码能力的决定性验证(全部只读,不发送任何消息)。
//
// 此前 record 发送侧全部失败,错误为「Failed to open input: Invalid data found」,
// 只能定性为「疑似受 NapCat 运行环境解码能力限制」,但缺少旁证。
// 本脚本改用 NapCat **自己的** get_record(官方文档:获取语音文件信息并支持格式转换):
// 输入使用群里**真实存在**的 record 段的 file / file_id / url / path,
// 若转换成功 → 说明 NapCat 侧 silk/amr 解码链路可用,record 发送失败应归因于
// 发送路径的入参形态;若同样失败 → 才支持「运行环境解码能力受限」的结论。
//
// 凭据只从环境变量读取。
import fs from 'node:fs';
import path from 'node:path';
const WS_URL = process.env.NAPCAT_WS_URL || 'ws://192.168.5.32:16099';
const TOKEN = process.env.NAPCAT_WS_TOKEN;
const GROUP = Number(process.env.PROBE_GROUP || 933280401);
const OUT_DIR = process.env.PROBE_OUT || 'local';
if (!TOKEN) { console.error('缺少环境变量 NAPCAT_WS_TOKEN。凭据不得硬编码。'); process.exit(1); }
const stamp = new Date().toISOString().replace(/[:.]/g, '-');
fs.mkdirSync(OUT_DIR, { recursive: true });
const OUT = path.join(OUT_DIR, `record-decoder-${stamp}.jsonl`);
const say = (...a) => console.log(...a);
const ws = new WebSocket(`${WS_URL.replace(/\/$/, '')}/?access_token=${encodeURIComponent(TOKEN)}`);
const pending = new Map();
let opened = false, authed = false;
ws.onopen = () => { opened = true; };
ws.onmessage = (ev) => {
let o; try { o = JSON.parse(String(ev.data)); } catch { return; }
if (o.echo && pending.has(o.echo)) { pending.get(o.echo).resolve(o); pending.delete(o.echo); return; }
if (o.post_type === 'meta_event' && o.meta_event_type === 'lifecycle') authed = true;
};
for (let i = 0; i < 100 && !opened; i++) await new Promise((r) => setTimeout(r, 100));
if (!opened) { console.error('连接超时'); process.exit(1); }
for (let i = 0; i < 100 && !authed; i++) await new Promise((r) => setTimeout(r, 100));
say('认证=' + authed);
const api = (action, params, ms = 40000) => new Promise((resolve) => {
const echo = `rd-${action}-${Date.now()}-${Math.random().toString(36).slice(2, 6)}`;
const to = setTimeout(() => { pending.delete(echo); resolve({ __timeout: true }); }, ms);
pending.set(echo, { resolve: (o) => { clearTimeout(to); resolve(o); }, to });
ws.send(JSON.stringify({ action, params, echo }));
});
// 现场取真实 record 段(record 的 url 含时效 rkey,必须现取现用)
const h = await api('get_group_msg_history', { group_id: GROUP, count: 80 });
let rec = null;
for (const m of h?.data?.messages ?? []) {
const s = (m.message ?? []).find((x) => x.type === 'record');
if (s) { rec = { seq: m.real_seq, ...s.data }; break; }
}
if (!rec) { say('history 中未找到 record 段,无法验证解码能力。'); try { ws.close(); } catch {} process.exit(3); }
say(`取到 record: seq=${rec.seq} file=${rec.file} file_id=${rec.file_id ?? '-'}`);
fs.appendFileSync(OUT, JSON.stringify({ kind: 'source_record_seg', seq: rec.seq, data: rec }) + '\n');
// 群文件直链(只读):验证 file 类媒体的下载读回路径
const rf = await api('get_group_root_files', { group_id: GROUP });
const firstFile = rf?.data?.files?.[0];
say(`取到群文件: file_id=${firstFile?.file_id ?? '-'} name=${firstFile?.file_name ?? '-'}`);
fs.appendFileSync(OUT, JSON.stringify({ kind: 'source_group_file', data: firstFile ?? null }) + '\n');
const CASES = [];
for (const fmt of ['mp3', 'wav', 'silk']) {
if (rec.file) CASES.push({ id: `get_record.file.${fmt}`, p: { file: rec.file, out_format: fmt } });
if (rec.file_id) CASES.push({ id: `get_record.file_id.${fmt}`, p: { file_id: rec.file_id, out_format: fmt } });
if (rec.url) CASES.push({ id: `get_record.url.${fmt}`, p: { file: rec.url, out_format: fmt } });
if (rec.path) CASES.push({ id: `get_record.path.${fmt}`, p: { file: rec.path, out_format: fmt } });
}
if (firstFile?.file_id) {
CASES.push({ id: 'get_group_file_url.real', p: { group_id: GROUP, file_id: firstFile.file_id } });
}
const rows = [];
for (const c of CASES) {
const r = await api(c.id.startsWith('get_group_file_url') ? 'get_group_file_url' : 'get_record', c.p);
const rc = r.__timeout ? 'TIMEOUT' : r.retcode;
const msg = String(r.message ?? r.wording ?? '');
const rec2 = { id: c.id, params_preview: JSON.stringify(c.p).slice(0, 160),
retcode: rc, message: msg,
data_preview: JSON.stringify(r.data ?? null).slice(0, 400) };
rows.push(rec2);
fs.appendFileSync(OUT, JSON.stringify({ kind: 'probe', ...rec2 }) + '\n');
say(`${c.id.padEnd(28)} retcode=${String(rc).padEnd(7)} ${msg.slice(0, 52).padEnd(54)} ${rec2.data_preview.slice(0, 60)}`);
}
const ok = rows.filter((r) => r.retcode === 0 && r.id.startsWith('get_record'));
say(`\n判定:get_record 成功 ${ok.length} 次 / 共 ${rows.filter((r) => r.id.startsWith('get_record')).length} 次`);
say(ok.length > 0
? '→ NapCat 侧 silk/amr 解码链路可用,record 发送失败应归因于发送路径入参形态,不得写「环境缺解码器」'
: '→ get_record 同样无法解码,支持「受 NapCat 运行环境解码能力限制」的定性');
say('\n结果 -> ' + OUT);
try { ws.close(); } catch {}
process.exit(0);