惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 聂微东
GbyAI
GbyAI
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 叶小钗
A
About on SuperTechFans
M
MIT News - Artificial intelligence
宝玉的分享
宝玉的分享
雷峰网
雷峰网
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Martin Fowler
Martin Fowler
Google DeepMind News
Google DeepMind News
博客园 - Franky
B
Blog RSS Feed
Y
Y Combinator Blog
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
Last Week in AI
Last Week in AI
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
S
SegmentFault 最新的问题
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
test: generate hook install archives · openclaw/openclaw@...
steipete · 2026-05-06 · via Recent Commits to openclaw:main

@@ -1,6 +1,8 @@

11

import { createHash, randomUUID } from "node:crypto";

22

import fs from "node:fs";

33

import path from "node:path";

4+

import JSZip from "jszip";

5+

import * as tar from "tar";

46

import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";

57

import { expectSingleNpmPackIgnoreScriptsCall } from "../test-utils/exec-assertions.js";

68

import {

@@ -32,13 +34,23 @@ let tempDirIndex = 0;

3234

const sharedArchivePathByName = new Map<string, string>();

33353436

const fixturesDir = path.resolve(process.cwd(), "test", "fixtures", "hooks-install");

35-

const zipHooksBuffer = fs.readFileSync(path.join(fixturesDir, "zip-hooks.zip"));

36-

const zipTraversalBuffer = fs.readFileSync(path.join(fixturesDir, "zip-traversal.zip"));

37+

const zipHooksBuffer = await createZipHookPackBuffer({

38+

packageName: "@openclaw/zip-hooks",

39+

hookName: "zip-hook",

40+

hookDescription: "Zip hook",

41+

heading: "Zip Hook",

42+

});

43+

const zipTraversalBuffer = await createZipBuffer([{ path: "../pwned.txt", contents: "pwned" }]);

3744

const tarHooksBuffer = fs.readFileSync(path.join(fixturesDir, "tar-hooks.tar"));

3845

const tarTraversalBuffer = fs.readFileSync(path.join(fixturesDir, "tar-traversal.tar"));

3946

const tarEvilIdBuffer = fs.readFileSync(path.join(fixturesDir, "tar-evil-id.tar"));

4047

const tarReservedIdBuffer = fs.readFileSync(path.join(fixturesDir, "tar-reserved-id.tar"));

41-

const npmPackHooksBuffer = fs.readFileSync(path.join(fixturesDir, "npm-pack-hooks.tgz"));

48+

const npmPackHooksBuffer = await createTarGzHookPackBuffer({

49+

packageName: "@openclaw/test-hooks",

50+

hookName: "one-hook",

51+

hookDescription: "One hook",

52+

heading: "One Hook",

53+

});

42544355

function makeTempDir() {

4456

const dir = path.join(fixtureRoot, `case-${tempDirIndex++}`);

@@ -110,6 +122,95 @@ function writeHookPackManifest(params: {

110122

);

111123

}

112124125+

async function createZipBuffer(entries: Array<{ path: string; contents: string }>) {

126+

const zip = new JSZip();

127+

for (const entry of entries) {

128+

zip.file(entry.path, entry.contents);

129+

}

130+

return Buffer.from(await zip.generateAsync({ type: "nodebuffer", compression: "STORE" }));

131+

}

132+133+

function writeHookPackFiles(params: {

134+

pkgDir: string;

135+

packageName: string;

136+

hookName: string;

137+

hookDescription: string;

138+

heading: string;

139+

}) {

140+

writeHookPackManifest({

141+

pkgDir: params.pkgDir,

142+

hooks: [`./hooks/${params.hookName}`],

143+

});

144+

const hookDir = path.join(params.pkgDir, "hooks", params.hookName);

145+

fs.mkdirSync(hookDir, { recursive: true });

146+

fs.writeFileSync(

147+

path.join(hookDir, "HOOK.md"),

148+

[

149+

"---",

150+

`name: ${params.hookName}`,

151+

`description: ${params.hookDescription}`,

152+

'metadata: {"openclaw":{"events":["command:new"]}}',

153+

"---",

154+

"",

155+

`# ${params.heading}`,

156+

].join("\n"),

157+

"utf-8",

158+

);

159+

fs.writeFileSync(path.join(hookDir, "handler.ts"), "export default async () => {};\n", "utf-8");

160+161+

const manifestPath = path.join(params.pkgDir, "package.json");

162+

const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8")) as Record<string, unknown>;

163+

manifest.name = params.packageName;

164+

fs.writeFileSync(manifestPath, JSON.stringify(manifest), "utf-8");

165+

}

166+167+

async function createZipHookPackBuffer(params: {

168+

packageName: string;

169+

hookName: string;

170+

hookDescription: string;

171+

heading: string;

172+

}) {

173+

const packageJson = JSON.stringify({

174+

name: params.packageName,

175+

version: "0.0.1",

176+

openclaw: { hooks: [`./hooks/${params.hookName}`] },

177+

});

178+

return createZipBuffer([

179+

{ path: "package/package.json", contents: packageJson },

180+

{

181+

path: `package/hooks/${params.hookName}/HOOK.md`,

182+

contents: [

183+

"---",

184+

`name: ${params.hookName}`,

185+

`description: ${params.hookDescription}`,

186+

'metadata: {"openclaw":{"events":["command:new"]}}',

187+

"---",

188+

"",

189+

`# ${params.heading}`,

190+

].join("\n"),

191+

},

192+

{

193+

path: `package/hooks/${params.hookName}/handler.ts`,

194+

contents: "export default async () => {};\n",

195+

},

196+

]);

197+

}

198+199+

async function createTarGzHookPackBuffer(params: {

200+

packageName: string;

201+

hookName: string;

202+

hookDescription: string;

203+

heading: string;

204+

}) {

205+

const workDir = path.join(fixtureRoot, "_generated", `pack-${randomUUID()}`);

206+

const packageDir = path.join(workDir, "package");

207+

fs.mkdirSync(packageDir, { recursive: true });

208+

writeHookPackFiles({ pkgDir: packageDir, ...params });

209+

const archivePath = path.join(workDir, "pack.tgz");

210+

await tar.c({ cwd: workDir, file: archivePath, gzip: true }, ["package"]);

211+

return fs.readFileSync(archivePath);

212+

}

213+113214

async function installArchiveFixture(params: { fileName: string; contents: Buffer }) {

114215

const fixture = writeArchiveFixture(params);

115216

const result = await installHooksFromArchive({