Files
QLinker/tools/probe/record-amr-probe.mjs
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

169 lines
9.0 KiB
JavaScript
Raw Permalink 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 发送侧的决定性重试:用**真实 amr** 载荷,而不是此前只测过的 silk。
//
// 此前 7 种传法全部失败,但素材只有一个来源:get_ai_record 产出的 silk。
// 这留下一个未排除的解释——「NapCat 只缺 silk 解码,amr 可能可用」。
// 本脚本改用群里**真实存在**的 record 段的 amr 载荷,穷举 NapCat 能拿到字节的三种途径:
// 1) file = 段里的 path(NapCat 宿主机上的本地绝对路径,它自己写的文件,必然可读)
// 2) file = 段里的 url(QQ CDN 新鲜直链,现取现用,避开 rkey 过期)
// 3) file = base64://<下载到的 amr 字节>(绕开 NapCat 的下载逻辑)
// 三者覆盖「读本地 / 自己下载 / 直接给字节」,若仍全失败,
// 「受 NapCat 运行环境解码能力限制」才成为可下笔的确定结论。
//
// 默认 dry-run,--yes 才真实发送(会向测试群发一条语音)。凭据只从环境变量读取。
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 DO_WRITE = process.argv.includes('--yes');
// 三证据补齐用:只回读 history 并落盘,不发送任何消息。
// 语音发送有真实副作用,不允许为了补一列证据而重复发一遍。
const HISTORY_ONLY = process.argv.includes('--history-only');
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-amr-${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;
const events = [];
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') { if (o.meta_event_type === 'lifecycle') authed = true; return; }
events.push({ el: Date.now(), data: o });
fs.appendFileSync(OUT, JSON.stringify({ kind: 'event', data: o }) + '\n');
};
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);
if (!authed && DO_WRITE) { console.error('未确认认证,中止。'); process.exit(2); }
const api = (action, params, ms = 45000) => new Promise((resolve) => {
const echo = `ra-${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 }));
});
// 取真实 amr 段(url 含时效 rkey,必须现取现用)
const h = await api('get_group_msg_history', { group_id: GROUP, count: 80 });
let seg = null;
for (const m of h?.data?.messages ?? []) {
const s = (m.message ?? []).find((x) => x.type === 'record');
if (s && String(s.data?.file ?? '').endsWith('.amr')) { seg = { seq: m.real_seq, ...s.data }; break; }
}
if (!seg) { say('history 中未找到 amr 形态的 record 段。'); try { ws.close(); } catch {} process.exit(3); }
say(`取到真实 amr 段: seq=${seg.seq} file=${seg.file}`);
say(` path=${seg.path ?? '-'}`);
fs.appendFileSync(OUT, JSON.stringify({ kind: 'source_amr_seg', seq: seg.seq, data: seg }) + '\n');
let amrB64 = null, amrBytes = 0, amrMagic = null, dlStatus = null;
if (seg.url) {
try {
const r = await fetch(seg.url);
const buf = Buffer.from(await r.arrayBuffer());
dlStatus = r.status; amrBytes = buf.byteLength;
amrMagic = buf.subarray(0, 8).toString('hex');
if (r.ok && buf.byteLength > 0) {
amrB64 = buf.toString('base64');
fs.writeFileSync(path.join(OUT_DIR, `record-amr-${stamp}.bin`), buf);
}
} catch (e) { dlStatus = 'ERR ' + e.message; }
}
say(` CDN 下载: HTTP ${dlStatus} ${amrBytes} 字节 magic=${amrMagic ?? '-'}`);
say(` (#!AMR 的 magic 应为 2321414d52,即 "#!AMR")`);
const CASES = [];
if (seg.path) CASES.push({ id: 'amr_localPath', desc: 'file = NapCat 宿主机本地路径(它自己写的文件)',
data: () => ({ file: seg.path }) });
if (seg.url) CASES.push({ id: 'amr_cdnUrl', desc: 'file = 新鲜 QQ CDN 直链',
data: () => ({ file: seg.url }) });
if (amrB64) {
CASES.push({ id: 'amr_b64', desc: 'file = base64://<amr 字节>',
data: () => ({ file: 'base64://' + amrB64 }) });
CASES.push({ id: 'amr_b64_fmt', desc: 'file = base64 + file_name=x.amr',
data: () => ({ file: 'base64://' + amrB64, file_name: 'probe.amr' }) });
CASES.push({ id: 'amr_b64_fmt_amr', desc: 'file = base64 + format=amr',
data: () => ({ file: 'base64://' + amrB64, format: 'amr' }) });
}
if (HISTORY_ONLY) {
const hist = await api('get_group_msg_history', { group_id: GROUP, count: 40 });
say(`\n[history-only] 只回读不发送,命中行:`);
let nHit = 0;
for (const m of hist?.data?.messages ?? []) {
const txt = (m.message ?? []).map((s) => s.data?.text ?? '').join('');
const mm = txt.match(/\[QLr:([A-Za-z0-9_]+)\]/);
if (!mm) continue;
nHit++;
const segs = (m.message ?? []).map((s) => s.type).join('+');
say(` ${mm[1].padEnd(18)} seq=${m.real_seq} 段=${segs}`);
fs.appendFileSync(OUT, JSON.stringify({ kind: 'history', id: mm[1], history_segs: segs, history_seq: m.real_seq }) + '\n');
}
say(`共 ${nHit} 条`);
try { ws.close(); } catch {}
process.exit(0);
}
say(`\n模式=${DO_WRITE ? '真实发送' : 'DRY-RUN'}\n`);
const rows = [];
for (const c of CASES) {
if (!DO_WRITE) { say(`${c.id.padEnd(18)} [计划] ${c.desc}`); continue; }
const t0 = Date.now();
const data = c.data();
const r = await api('send_group_msg', { group_id: GROUP, message: [
{ type: 'record', data }, { type: 'text', data: { text: `[QLr:${c.id}]` } }] });
await new Promise((x) => setTimeout(x, 6000));
const mid = Number(r?.data?.message_id);
const ev = events.find((e) => e.el >= t0 && Number(e.data.message_id) === mid);
const rec = { id: c.id, desc: c.desc, retcode: r.__timeout ? 'TIMEOUT' : r.retcode,
message: String(r.message ?? r.wording ?? ''), message_id: r?.data?.message_id ?? null,
event_segs: ev ? (ev.data.message || []).map((s) => s.type).join('+') : 'NO_EVENT',
event_seq: ev?.data?.real_seq ?? null };
rows.push(rec);
fs.appendFileSync(OUT, JSON.stringify({ kind: 'result', ...rec }) + '\n');
say(`${c.id.padEnd(18)} retcode=${String(rec.retcode).padEnd(6)} 事件段=${String(rec.event_segs).padEnd(12)} ${rec.message.slice(0, 56)}`);
}
if (DO_WRITE) {
// 上一版漏掉 amr_cdnUrl 的回读行,真因是标签正则 [a-z0-9_]+ 不匹配大小写混排的 case id,
// 不是窗口不足。窗口同时放宽到 40 以覆盖全部用例。
await new Promise((x) => setTimeout(x, 4000));
const hist = await api('get_group_msg_history', { group_id: GROUP, count: 40 });
say('\nhistory 回读:');
const seen = new Set();
for (const m of hist?.data?.messages ?? []) {
const hit = (m.message ?? []).some((s) => s.type === 'text' && /\[QLr:([A-Za-z0-9_]+)\]/.test(s.data?.text ?? ''));
if (!hit) continue;
const lab = (m.message ?? []).map((s) => s.data?.text ?? '').join('').match(/\[QLr:([A-Za-z0-9_]+)\]/)[1];
if (seen.has(lab)) continue;
seen.add(lab);
const segs = (m.message ?? []).map((s) => s.type).join('+');
say(` ${lab.padEnd(18)} seq=${m.real_seq} 段=${segs}`);
// 单独落一行,供门禁的 history 列自动比对(与 result 行按 id 关联)
fs.appendFileSync(OUT, JSON.stringify({ kind: 'history', id: lab, history_segs: segs, history_seq: m.real_seq }) + '\n');
const row = rows.find((x) => x.id === lab); if (row) row.history_segs = segs;
}
const miss = rows.filter((r) => r.retcode === 0 && !r.history_segs).map((r) => r.id);
if (miss.length) say(` ⚠️ 以下成功用例未在 history 窗口内回读到:${miss.join(', ')}`);
}
const ok = rows.filter((r) => r.retcode === 0);
say(`\n判定:amr 载荷成功 ${ok.length} 次 / 共 ${rows.length} 次`);
if (ok.length) say('→ 存在可用的 amr 传法,record 应改判为「受限可用」,不得写「环境缺解码器」');
else if (rows.length) say('→ 本地路径 / CDN 直链 / 直接给字节 三条途径全部失败,支持「受 NapCat 运行环境解码能力限制」');
else say('→ DRY-RUN 未实发,不下结论');
fs.appendFileSync(OUT, JSON.stringify({ __summary: true, rows, dlStatus, amrBytes, amrMagic }) + '\n');
say('\n结果 -> ' + OUT);
try { ws.close(); } catch {}
process.exit(0);