Files
weixin-plugin-test/weixin-plugin/weixin/storage/sync-buf.ts
zyh 77019ec050 feat: 初始化微信插件独立测试环境
添加完整的微信插件测试框架,包含:
- 微信插件源码(weixin-plugin/)
- TypeScript 类型定义(types.ts)
- 插件编译脚本(scripts/build-weixin-plugin.sh)
- 简化测试脚本(scripts/test-weixin-simple.js)
- 完整测试脚本(scripts/test-weixin-plugin.js)
- 项目配置和依赖管理(package.json)
- 使用说明文档(README.md)

主要功能:
- 支持二维码登录认证
- HTTP 长轮询消息接收
- 文本、图片、视频、文件消息收发
- 自动回复测试
- 运行状态统计

Generated with [Claude Code](https://claude.com/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
2026-03-30 07:14:00 +00:00

46 lines
1.4 KiB
TypeScript

import fs from "node:fs";
import path from "node:path";
import os from "node:os";
export function resolvePreferredOpenClawTmpDir(): string {
const envOverride = process.env.OPENCLAW_TMP_DIR?.trim();
if (envOverride) return envOverride;
const stateDir = process.env.OPENCLAW_STATE_DIR?.trim() ||
process.env.CLAWDBOT_STATE_DIR?.trim() ||
path.join(os.homedir(), ".openclaw");
return path.join(stateDir, "tmp");
}
export function resolveWeixinAccountDataDir(): string {
const stateDir = process.env.OPENCLAW_STATE_DIR?.trim() ||
process.env.CLAWDBOT_STATE_DIR?.trim() ||
path.join(os.homedir(), ".openclaw");
return path.join(stateDir, "openclaw-weixin");
}
export function resolveWeixinAccountsDir(): string {
return path.join(resolveWeixinAccountDataDir(), "accounts");
}
export function resolveSyncBufFilePath(accountId: string): string {
return path.join(resolveWeixinAccountsDir(), `${accountId}.sync.json`);
}
export function resolveTmpDir(): string {
return resolvePreferredOpenClawTmpDir();
}
export function loadGetUpdatesBuf(filePath: string): string | null {
try {
if (fs.existsSync(filePath)) {
return fs.readFileSync(filePath, "utf-8");
}
} catch { /* ignore */ }
return null;
}
export function saveGetUpdatesBuf(filePath: string, buf: string): void {
const dir = path.dirname(filePath);
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(filePath, buf, "utf-8");
}