Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
node test/check-test-chain.mjs
node test/check-route-guard.mjs
node test/check-client-imports.mjs
node test/check-secrets.mjs

# 并行 runner:从 package.json 解析全部套件,并发 4 跑(ubuntu-latest 4 vCPU)
# 串行 npm test 的命令保留在 package.json,本地照样可用
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@
}
},
"scripts": {
"test": "node test/memory-bulk-move.mjs && node test/safe-download.mjs && node test/douyin-exact-id.mjs && node test/douyin-pb-init.mjs && node test/douyin-conversation.mjs && node test/douyin-inbox.mjs && node test/douyin-quarantine.mjs && node test/douyin-send-target.mjs && node test/douyin-send-exclusive.mjs && node test/douyin-gap-dedupe.mjs && node test/douyin-message-id-dedupe.mjs && node test/douyin-read-fail-retry.mjs && node test/douyin-read-cache.mjs && node test/douyin-dm-media-conv.mjs && node test/douyin-read-fail-retry-poll.mjs && node test/douyin-inbox-contract.mjs && node test/person-attribution.mjs && node test/memory-owner-reassign.mjs && node test/douyin-poll-and-timer-safety.mjs && node test/p2-limits.mjs && node test/resource-safety.mjs && node test/leftover-edge-cases.mjs && node test/douyin-master-person-merge.mjs && node test/douyin-master-uid.mjs && node test/douyin-identity-e2e.mjs && node test/douyin-post-jobs.mjs && node test/retrieval-filtered-vectors.mjs && node test/security-boundaries.mjs && node test/douyin-cdp-cursor.mjs && node test/douyin-nav-timeout.mjs && node test/persona-isolation.mjs && node test/smoke.mjs && node test/douyin-browser.mjs && node test/douyin-page-alive.mjs && node test/douyin-eval-timeout.mjs && node test/douyin-bridge-timeout.mjs && node test/douyin-goto-budget.mjs && node test/douyin-music.mjs && node test/startup-gate.mjs && node test/outbox.mjs && node test/import-coverage.mjs && node test/update-check.mjs && node test/issue-fixes.mjs && node test/import-resume.mjs && node test/maibot-extras.mjs && node test/worldinfo.mjs && node test/memory-bulk.mjs && node test/memory-tiers.mjs && node test/memory-weekly.mjs && node test/issue-98-self-archive.mjs && node test/issue-99-memory-order.mjs && node test/issue-115-memory-date.mjs && node test/issue-119-memory-page.mjs && node test/issue-125-memory-filter.mjs && node test/issue-78-diagnostic.mjs && node test/memory-storage.mjs && node test/memory-storage-restore.mjs && node test/backup-restore.mjs && node test/douyin-group.mjs && node test/review-fixes.mjs && node test/at-reads-video.mjs && node test/search-source.mjs && node test/followups.mjs && node test/detail-config.mjs && node test/qq-send-any-image.mjs && node test/qq-read-attachment.mjs && node test/qq-batch-window.mjs && node test/comment-video.mjs && node test/frames.mjs && node test/face-name.mjs && node test/comment-reply.mjs && node test/chat-comment.mjs && node test/at-target.mjs && node test/quota-caps.mjs && node test/client-lint.mjs && node test/client-panels.mjs && node test/dsh-desktop.mjs && node test/group-mention-only.mjs && node test/qq-private-allowlist.mjs && node test/issue-59-interject.mjs && node test/issue-59-diagnose.mjs && node test/sticker-backfill.mjs && node test/issue-118-sticker-diagnostics.mjs && node test/sticker-manage.mjs && node test/bili-emotes.mjs && node test/qq-outbound-sanitize.mjs && node test/person-delete.mjs && node test/qq-group-admin.mjs && node test/douyin-recovery.mjs && node test/session-preset.mjs && node test/qq-connect-error.mjs && node test/douyin-comment-bridge.mjs && node test/douyin-comment-write-unknown.mjs && node test/douyin-reply-verify-status.mjs && node test/bili-comment-emoji.mjs && node test/douyin-state-echo.mjs && node test/issue-75-proactive.mjs && node test/issue-76-capability.mjs && node test/douyin-http-browse.mjs && node test/douyin-verify-backoff.mjs && node test/douyin-digg-bridge.mjs && node test/memory-evidence-transcript.mjs && node test/chat-archive-default.mjs && node test/issue-113-desktop-archive.mjs && node test/dream-transcript-wire.mjs && node test/douyin-frames-collect.mjs && node test/master-qq-uin-rebind.mjs && node test/douyin-session-health.mjs && node test/douyin-delivered.mjs && node test/douyin-card-share.mjs && node test/douyin-push-drop.mjs && node test/douyin-stranger-dm.mjs && node test/douyin-uid-binding.mjs && node test/image-webp-fallback.mjs && node test/douyin-emoji-fallback.mjs && node test/relay-other-platform.mjs && node test/issue-101-voice-files.mjs && node test/voice-volcengine.mjs && node test/voice-minimax-dashscope.mjs && node test/bili-switch-persist.mjs && node test/cross-channel-context.mjs && node test/reply-target.mjs && node test/shared-session.mjs && node test/memory-source-label.mjs && node test/pending-delivery.mjs && node test/recall-window-78.mjs && node test/memory-recall-recent-78.mjs && node test/client-syntax.mjs && node test/diag-log.mjs && node test/check-rings.mjs && node test/release-workflow.mjs && node test/sticker-import-gif.mjs && node test/sticker-real-gif.mjs && node test/sticker-upload-binary.mjs && node test/sticker-vision-tags.mjs && node test/sticker-manual-tags.mjs && node test/sticker-auto-name.mjs && node test/self-update.mjs && node test/group-list.mjs && node test/douyin-inbox-noise.mjs && node test/douyin-inbox-diag.mjs && node test/douyin-inbox-stuck.mjs && node test/reply-window.mjs && node test/douyin-sticker-heuristic.mjs && node test/douyin-image-boundary.mjs && node test/media-image-boundary.mjs && node test/douyin-comment-identity-cid.mjs && node test/qq-mention-only-echo.mjs && node test/bili-panel-pagination.mjs && node test/bili-allowlist.mjs && node test/douyin-master-uid-mismatch.mjs && node test/check-test-chain.mjs && node test/check-route-guard.mjs && node test/check-client-imports.mjs"
"test": "node test/memory-bulk-move.mjs && node test/safe-download.mjs && node test/douyin-exact-id.mjs && node test/douyin-pb-init.mjs && node test/douyin-conversation.mjs && node test/douyin-inbox.mjs && node test/douyin-quarantine.mjs && node test/douyin-send-target.mjs && node test/douyin-send-exclusive.mjs && node test/douyin-gap-dedupe.mjs && node test/douyin-message-id-dedupe.mjs && node test/douyin-read-fail-retry.mjs && node test/douyin-read-cache.mjs && node test/douyin-dm-media-conv.mjs && node test/douyin-read-fail-retry-poll.mjs && node test/douyin-inbox-contract.mjs && node test/person-attribution.mjs && node test/memory-owner-reassign.mjs && node test/douyin-poll-and-timer-safety.mjs && node test/p2-limits.mjs && node test/resource-safety.mjs && node test/leftover-edge-cases.mjs && node test/douyin-master-person-merge.mjs && node test/douyin-master-uid.mjs && node test/douyin-identity-e2e.mjs && node test/douyin-post-jobs.mjs && node test/retrieval-filtered-vectors.mjs && node test/security-boundaries.mjs && node test/douyin-cdp-cursor.mjs && node test/douyin-nav-timeout.mjs && node test/persona-isolation.mjs && node test/smoke.mjs && node test/douyin-browser.mjs && node test/douyin-page-alive.mjs && node test/douyin-eval-timeout.mjs && node test/douyin-bridge-timeout.mjs && node test/douyin-goto-budget.mjs && node test/douyin-music.mjs && node test/startup-gate.mjs && node test/outbox.mjs && node test/import-coverage.mjs && node test/update-check.mjs && node test/issue-fixes.mjs && node test/import-resume.mjs && node test/maibot-extras.mjs && node test/worldinfo.mjs && node test/memory-bulk.mjs && node test/memory-tiers.mjs && node test/memory-weekly.mjs && node test/issue-98-self-archive.mjs && node test/issue-99-memory-order.mjs && node test/issue-115-memory-date.mjs && node test/issue-119-memory-page.mjs && node test/issue-125-memory-filter.mjs && node test/issue-78-diagnostic.mjs && node test/memory-storage.mjs && node test/memory-storage-restore.mjs && node test/backup-restore.mjs && node test/douyin-group.mjs && node test/review-fixes.mjs && node test/at-reads-video.mjs && node test/search-source.mjs && node test/followups.mjs && node test/detail-config.mjs && node test/qq-send-any-image.mjs && node test/qq-read-attachment.mjs && node test/qq-batch-window.mjs && node test/comment-video.mjs && node test/frames.mjs && node test/face-name.mjs && node test/comment-reply.mjs && node test/chat-comment.mjs && node test/at-target.mjs && node test/quota-caps.mjs && node test/client-lint.mjs && node test/client-panels.mjs && node test/dsh-desktop.mjs && node test/group-mention-only.mjs && node test/qq-private-allowlist.mjs && node test/issue-59-interject.mjs && node test/issue-59-diagnose.mjs && node test/sticker-backfill.mjs && node test/issue-118-sticker-diagnostics.mjs && node test/sticker-manage.mjs && node test/bili-emotes.mjs && node test/qq-outbound-sanitize.mjs && node test/person-delete.mjs && node test/qq-group-admin.mjs && node test/douyin-recovery.mjs && node test/session-preset.mjs && node test/qq-connect-error.mjs && node test/douyin-comment-bridge.mjs && node test/douyin-comment-write-unknown.mjs && node test/douyin-reply-verify-status.mjs && node test/bili-comment-emoji.mjs && node test/douyin-state-echo.mjs && node test/issue-75-proactive.mjs && node test/issue-76-capability.mjs && node test/douyin-http-browse.mjs && node test/douyin-verify-backoff.mjs && node test/douyin-digg-bridge.mjs && node test/memory-evidence-transcript.mjs && node test/chat-archive-default.mjs && node test/issue-113-desktop-archive.mjs && node test/dream-transcript-wire.mjs && node test/douyin-frames-collect.mjs && node test/master-qq-uin-rebind.mjs && node test/douyin-session-health.mjs && node test/douyin-delivered.mjs && node test/douyin-card-share.mjs && node test/douyin-push-drop.mjs && node test/douyin-stranger-dm.mjs && node test/douyin-uid-binding.mjs && node test/image-webp-fallback.mjs && node test/douyin-emoji-fallback.mjs && node test/relay-other-platform.mjs && node test/issue-101-voice-files.mjs && node test/voice-volcengine.mjs && node test/voice-minimax-dashscope.mjs && node test/bili-switch-persist.mjs && node test/cross-channel-context.mjs && node test/reply-target.mjs && node test/shared-session.mjs && node test/memory-source-label.mjs && node test/pending-delivery.mjs && node test/recall-window-78.mjs && node test/memory-recall-recent-78.mjs && node test/client-syntax.mjs && node test/diag-log.mjs && node test/check-rings.mjs && node test/release-workflow.mjs && node test/sticker-import-gif.mjs && node test/sticker-real-gif.mjs && node test/sticker-upload-binary.mjs && node test/sticker-vision-tags.mjs && node test/sticker-manual-tags.mjs && node test/sticker-auto-name.mjs && node test/self-update.mjs && node test/group-list.mjs && node test/douyin-inbox-noise.mjs && node test/douyin-inbox-diag.mjs && node test/douyin-inbox-stuck.mjs && node test/reply-window.mjs && node test/douyin-sticker-heuristic.mjs && node test/douyin-image-boundary.mjs && node test/media-image-boundary.mjs && node test/douyin-comment-identity-cid.mjs && node test/qq-mention-only-echo.mjs && node test/bili-panel-pagination.mjs && node test/bili-allowlist.mjs && node test/douyin-master-uid-mismatch.mjs && node test/check-test-chain.mjs && node test/check-route-guard.mjs && node test/check-client-imports.mjs && node test/check-secrets.mjs"
}
}
50 changes: 50 additions & 0 deletions scripts/gen-secrets-baseline.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* 生成 test/check-secrets.baseline.txt:把仓库里**现有**的真实身份标识符记成 baseline。
*
* 只在「确认存量、准备单独立项清理」时跑一次。之后 baseline 只减不增
* (check-secrets.mjs 会拦新增命中)。
*
* 用法:node scripts/gen-secrets-baseline.mjs
*/
import { createHash } from 'node:crypto';
import { readFileSync, writeFileSync, readdirSync, statSync } from 'node:fs';
import { join, relative, sep } from 'node:path';

const root = join(import.meta.dirname, '..');
const h = (s) => createHash('sha256').update(s).digest('hex').slice(0, 16);

// 与 test/check-secrets.mjs 同一份黑名单(只存哈希,不存真值)
const BLOCKED = new Set([
'ffd02f553314b7f4', '5dd6571f762b5f39', '72b75cbde2cc73ef', 'f45897f1b90c4e18'
]);

const SKIP_DIRS = new Set(['node_modules', '.git', '.alma-snapshots', 'probe-scratch', 'probe-group', 'probe-gid', 'probe-group-uid', 'probe-webp-tmp', '.benchmark']);
const SCAN_EXT = /\.(mjs|js|json|md|yml|yaml|txt|css|html|sh)$/;
function walk(dir, out = []) {
for (const name of readdirSync(dir)) {
if (SKIP_DIRS.has(name)) continue;
const full = join(dir, name);
let st;
try { st = statSync(full); } catch { continue; }
if (st.isDirectory()) walk(full, out);
else if (SCAN_EXT.test(name)) out.push(full);
}
return out;
}

const rows = new Set();
for (const full of walk(root)) {
const rel = relative(root, full).split(sep).join('/');
// 生成器与检查脚本自身跳开:它们只存哈希,不该出现在 baseline 里
if (rel === 'test/check-secrets.mjs' || rel === 'scripts/gen-secrets-baseline.mjs') continue;
let src;
try { src = readFileSync(full, 'utf8'); } catch { continue; }
for (const line of src.split('\n')) {
for (const m of line.matchAll(/(?<!\d)(\d{8,20})(?!\d)/g)) {
if (BLOCKED.has(h(m[1]))) rows.add(`${rel}\t${h(m[1])}`);
}
}
}
const sorted = [...rows].sort();
writeFileSync(join(root, 'test', 'check-secrets.baseline.txt'), sorted.join('\n') + '\n');
console.log(`baseline 写入 ${sorted.length} 行`);
32 changes: 32 additions & 0 deletions test/check-secrets.baseline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
CHANGELOG.md 72b75cbde2cc73ef
CHANGELOG.md f45897f1b90c4e18
docs/handoff.md 5dd6571f762b5f39
docs/handoff.md 72b75cbde2cc73ef
docs/handoff.md f45897f1b90c4e18
history/2026-11.md 5dd6571f762b5f39
history/2026-11.md ffd02f553314b7f4
lib/gateway.js 5dd6571f762b5f39
lib/gateway.js ffd02f553314b7f4
scripts/fix-douyin-master-split.mjs f45897f1b90c4e18
scripts/parse-uid-precise.mjs 72b75cbde2cc73ef
scripts/parse-uid-precise.mjs f45897f1b90c4e18
test/douyin-conversation.mjs f45897f1b90c4e18
test/douyin-identity-e2e.mjs f45897f1b90c4e18
test/douyin-inbox-contract.mjs f45897f1b90c4e18
test/douyin-inbox-diag.mjs f45897f1b90c4e18
test/douyin-master-person-merge.mjs 5dd6571f762b5f39
test/douyin-master-person-merge.mjs ffd02f553314b7f4
test/douyin-master-uid-mismatch.mjs 5dd6571f762b5f39
test/douyin-master-uid.mjs f45897f1b90c4e18
test/douyin-master-uid.mjs ffd02f553314b7f4
test/douyin-poll-and-timer-safety.mjs f45897f1b90c4e18
test/douyin-push-drop.mjs f45897f1b90c4e18
test/douyin-read-fail-retry.mjs f45897f1b90c4e18
test/douyin-stranger-dm.mjs 5dd6571f762b5f39
test/douyin-uid-binding.mjs f45897f1b90c4e18
test/leftover-edge-cases.mjs 5dd6571f762b5f39
test/leftover-edge-cases.mjs 72b75cbde2cc73ef
test/master-qq-uin-rebind.mjs ffd02f553314b7f4
test/shared-session.mjs f45897f1b90c4e18
test/shared-session.mjs ffd02f553314b7f4
test/smoke-social.mjs f45897f1b90c4e18
80 changes: 80 additions & 0 deletions test/check-secrets.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* 静态检查:真实身份标识符(QQ 号 / 抖音 uid)不进仓库。
*
* 为什么要有这个测试:
* 仓库是公开的。真实 QQ 号 / 抖音 uid 一旦提交,历史里永久留存、不可撤回。
* 靠「提交前记得 git status 逐个看」在真机上证明是不够的 —— 已经漏过(见 baseline)。
*
* 设计要点:
* 黑名单只存**哈希**,不存真值 —— 否则这个脚本自己就是泄漏源。
* baseline 记「已知存量」的文件+哈希,让存量可见、新增被拦,
* 不用一次性改一堆测试夹具(存量清理单独立项)。
*
* 判据:精确匹配整个数字 token(哈希比对),不靠长度/模式猜 —— 零误报。
*/
import assert from 'node:assert/strict';
import { createHash } from 'node:crypto';
import { readFileSync, existsSync, readdirSync, statSync } from 'node:fs';
import { join, relative } from 'node:path';

const root = join(import.meta.dirname, '..');
const h = (s) => createHash('sha256').update(s).digest('hex').slice(0, 16);

// ── 黑名单:只存 sha256 前 16 位,**不存真值**(存真值等于这个脚本自己就是泄漏源)。
// 加新值时算出哈希再贴进来:
// node -e "console.log(require('crypto').createHash('sha256').update('要拦的值').digest('hex').slice(0,16))"
const BLOCKED = new Map([
['ffd02f553314b7f4', '主人 QQ 号'],
['5dd6571f762b5f39', '主人抖音 uid'],
['72b75cbde2cc73ef', '机器人自己抖音 uid'],
['f45897f1b90c4e18', '抖音 uid 的 Number 截断值(可反推真实 uid 前 16 位)']
]);

// ── baseline:已知存量(文件路径 → 该文件里允许出现的值哈希)。只减不增。
const BASELINE_FILE = join(import.meta.dirname, 'check-secrets.baseline.txt');
const baseline = new Map(); // file → Set<hash>
if (existsSync(BASELINE_FILE)) {
for (const line of readFileSync(BASELINE_FILE, 'utf8').split('\n')) {
const [file, hash] = line.trim().split('\t');
if (!file || !hash) continue;
if (!baseline.has(file)) baseline.set(file, new Set());
baseline.get(file).add(hash);
}
}

// ── 收集要扫的文件:常见源码后缀(跳过 node_modules / .git / 探针目录 / 快照)
const SKIP_DIRS = new Set(['node_modules', '.git', '.alma-snapshots', 'probe-scratch', 'probe-group', 'probe-gid', 'probe-group-uid', 'probe-webp-tmp', '.benchmark']);
const SCAN_EXT = /\.(mjs|js|json|md|yml|yaml|txt|css|html|sh)$/;
function walk(dir, out = []) {
for (const name of readdirSync(dir)) {
if (SKIP_DIRS.has(name)) continue;
const full = join(dir, name);
let st;
try { st = statSync(full); } catch { continue; }
if (st.isDirectory()) walk(full, out);
else if (SCAN_EXT.test(name)) out.push(full);
}
return out;
}

const hits = []; // 新增命中(要报错)
const known = []; // 存量(baseline 覆盖)
for (const full of walk(root)) {
const rel = relative(root, full).split('\\').join('/');
let src;
try { src = readFileSync(full, 'utf8'); } catch { continue; }
const lines = src.split('\n');
for (let i = 0; i < lines.length; i++) {
// 只认「整个数字 token」:前后不是数字
for (const m of lines[i].matchAll(/(?<!\d)(\d{8,20})(?!\d)/g)) {
const hash = h(m[1]);
if (!BLOCKED.has(hash)) continue;
const where = `${rel}:${i + 1}`;
if (baseline.get(rel)?.has(hash)) { known.push(`${where}(${BLOCKED.get(hash)},存量)`); continue; }
hits.push(`${where} 出现${BLOCKED.get(hash)}`);
}
}
}

assert.deepEqual(hits, [], `这些地方出现了真实身份标识符(仓库是公开的,提交后不可撤回):\n${hits.join('\n')}\n\n改法:换成明显假的占位符(如 12345678 / 1234567890123456789)。`);
console.log(`✓ 真实身份脱敏检查:新增命中 0 处;存量 ${known.length} 处(baseline 覆盖,待清理)`);
Loading