diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 80ce38c..adfa0b0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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,本地照样可用 diff --git a/package.json b/package.json index ca3704a..cdcedb3 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/scripts/gen-secrets-baseline.mjs b/scripts/gen-secrets-baseline.mjs new file mode 100644 index 0000000..7cc90aa --- /dev/null +++ b/scripts/gen-secrets-baseline.mjs @@ -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(/(? 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 +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(/(?