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

推荐订阅源

D
DataBreaches.Net
F
Fortinet All Blogs
D
Docker
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
罗磊的独立博客
Y
Y Combinator Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
J
Java Code Geeks
T
The Blog of Author Tim Ferriss
U
Unit 42
N
Netflix TechBlog - Medium
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
云风的 BLOG
云风的 BLOG
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
Hugging Face - Blog
Hugging Face - Blog
Stack Overflow Blog
Stack Overflow Blog
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
P
Proofpoint News Feed
G
Google Developers Blog
H
Help Net Security

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
fix(test): avoid walking extension runtime dependency sca...
vincentkoc · 2026-05-16 · via Recent Commits to openclaw:main

@@ -1,9 +1,11 @@

1+

import { spawnSync } from "node:child_process";

12

import fs from "node:fs";

23

import { builtinModules } from "node:module";

34

import path from "node:path";

4-

import { describe, expect, it } from "vitest";

5+

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

5667

const EXTENSION_ROOT = "extensions";

8+

const REPO_ROOT = path.resolve(import.meta.dirname, "../../..");

79

const EXTENSION_RUNTIME_FILE_EXTENSIONS = new Set([".cjs", ".js", ".jsx", ".mjs", ".ts", ".tsx"]);

810

const BUILTIN_MODULES = new Set(builtinModules.map((moduleId) => moduleId.replace(/^node:/, "")));

911

const OPTIONAL_UNDECLARED_RUNTIME_IMPORTS = new Map<string, Set<string>>([

@@ -53,16 +55,51 @@ type PackageManifest = {

5355

optionalDependencies?: Record<string, string>;

5456

peerDependencies?: Record<string, string>;

5557

};

58+

const trackedFilesByRoot = new Map<string, readonly string[] | null>();

56595760

function toPosixPath(filePath: string): string {

5861

return filePath.split(path.sep).join("/");

5962

}

60636164

function readPackageManifest(filePath: string): PackageManifest {

62-

return JSON.parse(fs.readFileSync(filePath, "utf8")) as PackageManifest;

65+

return JSON.parse(fs.readFileSync(path.resolve(REPO_ROOT, filePath), "utf8")) as PackageManifest;

66+

}

67+68+

function listTrackedFiles(root: string): string[] | null {

69+

const relativeRoot = toPosixPath(path.relative(REPO_ROOT, path.resolve(REPO_ROOT, root)));

70+

if (!relativeRoot || relativeRoot.startsWith("..")) {

71+

return null;

72+

}

73+

if (trackedFilesByRoot.has(relativeRoot)) {

74+

const files = trackedFilesByRoot.get(relativeRoot);

75+

return files ? [...files] : null;

76+

}

77+

const result = spawnSync("git", ["ls-files", "--", relativeRoot], {

78+

cwd: REPO_ROOT,

79+

encoding: "utf8",

80+

stdio: ["ignore", "pipe", "ignore"],

81+

});

82+

if (result.status !== 0) {

83+

trackedFilesByRoot.set(relativeRoot, null);

84+

return null;

85+

}

86+

const files = result.stdout

87+

.split("\n")

88+

.map((line) => line.trim().replaceAll("\\", "/"))

89+

.filter((line) => line.length > 0)

90+

.toSorted();

91+

trackedFilesByRoot.set(relativeRoot, files);

92+

return [...files];

6393

}

64946595

function listPackageManifests(root: string): string[] {

96+

const trackedFiles = listTrackedFiles(root);

97+

if (trackedFiles) {

98+

return trackedFiles

99+

.filter((filePath) => /^extensions\/[^/]+\/package\.json$/u.test(filePath))

100+

.toSorted();

101+

}

102+66103

const entries = fs.readdirSync(root, { withFileTypes: true });

67104

const manifests: string[] = [];

68105

for (const entry of entries) {

@@ -94,6 +131,17 @@ function shouldSkipRuntimeFile(filePath: string): boolean {

94131

}

9513296133

function listRuntimeFiles(root: string): string[] {

134+

const trackedFiles = listTrackedFiles(root);

135+

if (trackedFiles) {

136+

return trackedFiles

137+

.filter(

138+

(filePath) =>

139+

EXTENSION_RUNTIME_FILE_EXTENSIONS.has(path.extname(filePath)) &&

140+

!shouldSkipRuntimeFile(filePath),

141+

)

142+

.toSorted();

143+

}

144+97145

const files: string[] = [];

98146

const visit = (dir: string) => {

99147

for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {

@@ -118,7 +166,8 @@ function listRuntimeFiles(root: string): string[] {

118166119167

function readManifestText(root: string): string {

120168

const manifestPath = path.join(root, "openclaw.plugin.json");

121-

return fs.existsSync(manifestPath) ? fs.readFileSync(manifestPath, "utf8") : "";

169+

const resolvedManifestPath = path.resolve(REPO_ROOT, manifestPath);

170+

return fs.existsSync(resolvedManifestPath) ? fs.readFileSync(resolvedManifestPath, "utf8") : "";

122171

}

123172124173

function packageNameForSpecifier(specifier: string): string | null {

@@ -156,7 +205,7 @@ function isTypeOnlyClause(clause: string | undefined): boolean {

156205

}

157206158207

function collectRuntimeImports(filePath: string): string[] {

159-

const source = fs.readFileSync(filePath, "utf8");

208+

const source = fs.readFileSync(path.resolve(REPO_ROOT, filePath), "utf8");

160209

const imports = new Set<string>();

161210

const importRegex =

162211

/(import|export)\s+([^'";]*?\s+from\s+)?["']([^"']+)["']|import\s*\(\s*["']([^"']+)["']\s*\)|require\s*\(\s*["']([^"']+)["']\s*\)/g;

@@ -226,6 +275,20 @@ describe("Discord dependency ownership", () => {

226275

});

227276228277

describe("extension runtime dependency manifests", () => {

278+

it("lists extension dependency inputs from git without walking extension dirs", () => {

279+

const readDir = vi.spyOn(fs, "readdirSync");

280+

try {

281+

const manifests = listPackageManifests(EXTENSION_ROOT);

282+

const runtimeFiles = listRuntimeFiles("extensions/discord");

283+284+

expect(manifests.length).toBeGreaterThan(0);

285+

expect(runtimeFiles.length).toBeGreaterThan(0);

286+

expect(readDir).not.toHaveBeenCalled();

287+

} finally {

288+

readDir.mockRestore();

289+

}

290+

});

291+229292

it("keeps json5 in memory-core for packaged runtime config parsing", () => {

230293

const manifest = readPackageManifest("extensions/memory-core/package.json");

231294

@@ -271,7 +334,7 @@ describe("extension runtime dependency manifests", () => {

271334

].toSorted();

272335

const allowedIndirect = INDIRECT_RUNTIME_DEPENDENCIES.get(extensionDir) ?? new Set<string>();

273336

const runtimeText = listRuntimeFiles(extensionDir)

274-

.map((filePath) => fs.readFileSync(filePath, "utf8"))

337+

.map((filePath) => fs.readFileSync(path.resolve(REPO_ROOT, filePath), "utf8"))

275338

.concat(readManifestText(extensionDir))

276339

.join("\n");

277340