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

推荐订阅源

P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
B
Blog
月光博客
月光博客
博客园 - 【当耐特】
WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
I
InfoQ
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
Jina AI
Jina AI
博客园 - Franky
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Last Week in AI
Last Week in AI
B
Blog RSS Feed
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 plugin sdk package guardrails · ...
vincentkoc · 2026-05-16 · via Recent Commits to openclaw:main

@@ -1,7 +1,8 @@

1-

import { existsSync, readdirSync, readFileSync } from "node:fs";

1+

import { spawnSync } from "node:child_process";

2+

import fs from "node:fs";

23

import { dirname, join, relative, resolve } from "node:path";

34

import { fileURLToPath } from "node:url";

4-

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

5+

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

56

import {

67

deprecatedBarrelPluginSdkEntrypoints,

78

deprecatedPublicPluginSdkEntrypoints,

@@ -55,9 +56,57 @@ const MATRIX_RUNTIME_DEPS = [

5556

"matrix-js-sdk",

5657

"music-metadata",

5758

] as const;

59+

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

60+61+

function toRepoRelativePath(filePath: string): string {

62+

return relative(REPO_ROOT, filePath).replaceAll("\\", "/");

63+

}

64+65+

function isSkippedTrackedPath(repoRelativePath: string): boolean {

66+

return repoRelativePath

67+

.split("/")

68+

.some((part) => part === "dist" || part === "node_modules" || part === ".git");

69+

}

70+71+

function isCodeFile(filePath: string): boolean {

72+

return /\.(?:[cm]?ts|tsx|mts|cts)$/.test(filePath);

73+

}

74+75+

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

76+

const relativeRoot = toRepoRelativePath(root);

77+

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

78+

return null;

79+

}

80+

if (trackedFilesByRoot.has(relativeRoot)) {

81+

const files = trackedFilesByRoot.get(relativeRoot);

82+

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

83+

}

84+

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

85+

cwd: REPO_ROOT,

86+

encoding: "utf8",

87+

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

88+

});

89+

if (result.status !== 0) {

90+

trackedFilesByRoot.set(relativeRoot, null);

91+

return null;

92+

}

93+

const files = result.stdout

94+

.split("\n")

95+

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

96+

.filter((line) => line.length > 0 && !isSkippedTrackedPath(line))

97+

.map((line) => resolve(REPO_ROOT, line))

98+

.toSorted();

99+

trackedFilesByRoot.set(relativeRoot, files);

100+

return [...files];

101+

}

102+103+

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

104+

const files = listTrackedFiles(root);

105+

return files?.filter(isCodeFile) ?? null;

106+

}

5810759108

function collectPluginSdkPackageExports(): string[] {

60-

const packageJson = JSON.parse(readFileSync(resolve(REPO_ROOT, "package.json"), "utf8")) as {

109+

const packageJson = JSON.parse(fs.readFileSync(resolve(REPO_ROOT, "package.json"), "utf8")) as {

61110

exports?: Record<string, unknown>;

62111

};

63112

const exports = packageJson.exports ?? {};

@@ -78,7 +127,7 @@ function collectPluginSdkPackageExports(): string[] {

78127

function collectPluginSdkSubpathReferences() {

79128

const references: Array<{ file: string; subpath: string }> = [];

80129

for (const file of PUBLIC_CONTRACT_REFERENCE_FILES) {

81-

const source = readFileSync(resolve(REPO_ROOT, file), "utf8");

130+

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

82131

for (const match of source.matchAll(PLUGIN_SDK_SUBPATH_PATTERN)) {

83132

const subpath = match[1];

84133

if (!subpath) {

@@ -91,7 +140,7 @@ function collectPluginSdkSubpathReferences() {

91140

}

9214193142

function collectDocumentedSdkSubpaths(): Set<string> {

94-

const source = readFileSync(resolve(REPO_ROOT, SDK_SUBPATH_DOC_FILE), "utf8");

143+

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

95144

return new Set(

96145

[...source.matchAll(/`plugin-sdk\/([a-z0-9][a-z0-9-]*)`/g)]

97146

.map((match) => match[1])

@@ -100,7 +149,20 @@ function collectDocumentedSdkSubpaths(): Set<string> {

100149

}

101150102151

function collectBundledPluginIds(): string[] {

103-

return readdirSync(resolve(REPO_ROOT, "extensions"), { withFileTypes: true })

152+

const trackedFiles = listTrackedFiles(resolve(REPO_ROOT, "extensions"));

153+

if (trackedFiles) {

154+

return [

155+

...new Set(

156+

trackedFiles

157+

.map((file) => toRepoRelativePath(file).split("/"))

158+

.filter((parts) => parts.length > 2)

159+

.map((parts) => parts[1])

160+

.filter((pluginId): pluginId is string => Boolean(pluginId)),

161+

),

162+

].toSorted((a, b) => b.length - a.length || a.localeCompare(b));

163+

}

164+

return fs

165+

.readdirSync(resolve(REPO_ROOT, "extensions"), { withFileTypes: true })

104166

.filter((entry) => entry.isDirectory())

105167

.map((entry) => entry.name)

106168

.toSorted((a, b) => b.length - a.length || a.localeCompare(b));

@@ -142,7 +204,7 @@ function collectBundledFacadeSdkEntrypoints(): string[] {

142204

const entrypoints: string[] = [];

143205

for (const entrypoint of pluginSdkEntrypoints) {

144206

const filePath = resolve(REPO_ROOT, "src/plugin-sdk", `${entrypoint}.ts`);

145-

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

207+

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

146208

if (BUNDLED_PLUGIN_FACADE_LOADER_PATTERN.test(source)) {

147209

entrypoints.push(entrypoint);

148210

}

@@ -154,7 +216,7 @@ function collectPrivateBundledSdkSurfaceEntrypoints(): string[] {

154216

const entrypoints: string[] = [];

155217

for (const entrypoint of pluginSdkEntrypoints) {

156218

const filePath = resolve(REPO_ROOT, "src/plugin-sdk", `${entrypoint}.ts`);

157-

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

219+

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

158220

if (PRIVATE_BUNDLED_SDK_SURFACE_PATTERN.test(source)) {

159221

entrypoints.push(entrypoint);

160222

}

@@ -165,7 +227,7 @@ function collectPrivateBundledSdkSurfaceEntrypoints(): string[] {

165227

function collectGenericCoreOwnerNameLeaks(): Array<{ file: string; match: string }> {

166228

const leaks: Array<{ file: string; match: string }> = [];

167229

for (const file of GENERIC_CORE_HELPER_FILES) {

168-

const source = readFileSync(resolve(REPO_ROOT, file), "utf8");

230+

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

169231

for (const match of source.matchAll(GENERIC_CORE_PLUGIN_OWNER_NAME_PATTERN)) {

170232

const ownerName = match[0];

171233

if (!ownerName) {

@@ -182,7 +244,7 @@ function readRootPackageJson(): {

182244

optionalDependencies?: Record<string, string>;

183245

files?: string[];

184246

} {

185-

return JSON.parse(readFileSync(resolve(REPO_ROOT, "package.json"), "utf8")) as {

247+

return JSON.parse(fs.readFileSync(resolve(REPO_ROOT, "package.json"), "utf8")) as {

186248

dependencies?: Record<string, string>;

187249

optionalDependencies?: Record<string, string>;

188250

files?: string[];

@@ -193,7 +255,9 @@ function readMatrixPackageJson(): {

193255

dependencies?: Record<string, string>;

194256

optionalDependencies?: Record<string, string>;

195257

} {

196-

return JSON.parse(readFileSync(resolve(REPO_ROOT, "extensions/matrix/package.json"), "utf8")) as {

258+

return JSON.parse(

259+

fs.readFileSync(resolve(REPO_ROOT, "extensions/matrix/package.json"), "utf8"),

260+

) as {

197261

dependencies?: Record<string, string>;

198262

optionalDependencies?: Record<string, string>;

199263

};

@@ -210,7 +274,12 @@ function collectRuntimeDependencySpecs(packageJson: {

210274

}

211275212276

function collectExtensionFiles(dir: string): string[] {

213-

const entries = readdirSync(dir, { withFileTypes: true });

277+

const trackedFiles = listTrackedCodeFiles(dir);

278+

if (trackedFiles) {

279+

return trackedFiles;

280+

}

281+282+

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

214283

const files: string[] = [];

215284

for (const entry of entries) {

216285

if (entry.name === "dist" || entry.name === "node_modules") {

@@ -252,7 +321,7 @@ function collectExtensionCoreImportLeaks(): Array<{ file: string; specifier: str

252321

}

253322

const extensionRootMatch = /^(.*?\/extensions\/[^/]+)/.exec(file.replaceAll("\\", "/"));

254323

const extensionRoot = extensionRootMatch?.[1];

255-

const source = readFileSync(file, "utf8");

324+

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

256325

for (const match of source.matchAll(importPattern)) {

257326

const specifier = match[1];

258327

if (!specifier) {

@@ -283,7 +352,7 @@ function collectExtensionTestHelperImportLeaks(): Array<{ file: string; specifie

283352

if (isExtensionTestOrSupportPath(repoRelativePath)) {

284353

continue;

285354

}

286-

const source = readFileSync(file, "utf8");

355+

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

287356

for (const importPattern of importPatterns) {

288357

for (const match of source.matchAll(importPattern)) {

289358

const specifier = match[1];

@@ -309,7 +378,7 @@ function collectDeprecatedExtensionSdkImports(): Array<{ file: string; specifier

309378

];

310379

for (const file of collectExtensionFiles(resolve(REPO_ROOT, "extensions"))) {

311380

const repoRelativePath = relative(REPO_ROOT, file).replaceAll("\\", "/");

312-

const source = readFileSync(file, "utf8");

381+

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

313382

for (const importPattern of importPatterns) {

314383

for (const match of source.matchAll(importPattern)) {

315384

const specifier = match[1];

@@ -327,8 +396,13 @@ function collectDeprecatedExtensionSdkImports(): Array<{ file: string; specifier

327396

}

328397329398

function collectCodeFiles(dir: string): string[] {

399+

const trackedFiles = listTrackedCodeFiles(dir);

400+

if (trackedFiles) {

401+

return trackedFiles;

402+

}

403+330404

const files: string[] = [];

331-

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

405+

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

332406

if (entry.name === "dist" || entry.name === "node_modules" || entry.name === ".git") {

333407

continue;

334408

}

@@ -358,7 +432,7 @@ function collectDeprecatedTestBarrelImports(): Array<{ file: string; specifier:

358432

if (DEPRECATED_TEST_BARREL_ALLOWED_REFERENCE_FILES.has(repoRelativePath)) {

359433

continue;

360434

}

361-

const source = readFileSync(file, "utf8");

435+

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

362436

for (const importPattern of importPatterns) {

363437

for (const match of source.matchAll(importPattern)) {

364438

const specifier = match[1];

@@ -377,7 +451,7 @@ function collectDeprecatedTestBarrelImports(): Array<{ file: string; specifier:

377451

}

378452379453

function collectDeprecatedPackageTestingBridgeDrift(): string[] {

380-

const source = readFileSync(

454+

const source = fs.readFileSync(

381455

resolve(REPO_ROOT, "packages/plugin-sdk/src/testing.ts"),

382456

"utf8",

383457

).trim();

@@ -422,7 +496,7 @@ function collectWorkspaceCodeFiles(): string[] {

422496

const files: string[] = [];

423497

for (const root of ["src", "test", "extensions", "packages", "scripts"]) {

424498

const dir = resolve(REPO_ROOT, root);

425-

if (existsSync(dir)) {

499+

if (fs.existsSync(dir)) {

426500

files.push(...collectCodeFiles(dir));

427501

}

428502

}

@@ -443,7 +517,7 @@ function collectUnusedExtensionTestApiExports(): Array<{ file: string; exportNam

443517

const exportNames = new Set<string>();

444518445519

for (const file of testApiFiles) {

446-

const source = readFileSync(file, "utf8");

520+

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

447521

const namedExports = parseTestApiNamedExports(source);

448522

testApiExports.set(file, namedExports);

449523

for (const exportName of namedExports) {

@@ -463,7 +537,7 @@ function collectUnusedExtensionTestApiExports(): Array<{ file: string; exportNam

463537

const selfReferenceCounts = new Map<string, Map<string, number>>();

464538465539

for (const file of workspaceCodeFiles) {

466-

const source = readFileSync(file, "utf8");

540+

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

467541

const selfCounts = testApiExports.has(file) ? new Map<string, number>() : undefined;

468542

for (const match of source.matchAll(identifierPattern)) {

469543

const exportName = match[1];

@@ -510,7 +584,7 @@ function collectCrossOwnerReservedSdkImports(): Array<{

510584

for (const file of collectExtensionFiles(resolve(REPO_ROOT, "extensions"))) {

511585

const repoRelativePath = relative(REPO_ROOT, file).replaceAll("\\", "/");

512586

const pluginId = repoRelativePath.split("/")[1];

513-

const source = readFileSync(file, "utf8");

587+

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

514588

for (const match of source.matchAll(importPattern)) {

515589

const subpath = match[1];

516590

if (!subpath || !reserved.has(subpath)) {

@@ -541,7 +615,7 @@ function collectReservedSdkSubpathImports(): string[] {

541615542616

for (const root of ["src", "test", "extensions", "packages", "scripts"]) {

543617

for (const file of collectCodeFiles(resolve(REPO_ROOT, root))) {

544-

const source = readFileSync(file, "utf8");

618+

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

545619

for (const importPattern of importPatterns) {

546620

for (const match of source.matchAll(importPattern)) {

547621

const subpath = match[1];

@@ -557,7 +631,7 @@ function collectReservedSdkSubpathImports(): string[] {

557631

}

558632559633

function hasWildcardReexport(entrypoint: string): boolean {

560-

const source = readFileSync(resolve(REPO_ROOT, "src/plugin-sdk", `${entrypoint}.ts`), "utf8");

634+

const source = fs.readFileSync(resolve(REPO_ROOT, "src/plugin-sdk", `${entrypoint}.ts`), "utf8");

561635

return /^\s*export\s+(?:type\s+)?\*\s+from\s+["'][^"']+["']/mu.test(source);

562636

}

563637

@@ -574,7 +648,7 @@ function collectExtensionProductionSdkSubpathImports(subpaths: ReadonlySet<strin

574648

if (isExtensionTestOrSupportPath(repoRelativePath)) {

575649

continue;

576650

}

577-

const source = readFileSync(file, "utf8");

651+

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

578652

for (const importPattern of importPatterns) {

579653

for (const match of source.matchAll(importPattern)) {

580654

const subpath = match[1];

@@ -589,6 +663,22 @@ function collectExtensionProductionSdkSubpathImports(subpaths: ReadonlySet<strin

589663

}

590664591665

describe("plugin-sdk package contract guardrails", () => {

666+

it("lists package guardrail scan inputs from git without walking roots", () => {

667+

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

668+

try {

669+

const pluginIds = collectBundledPluginIds();

670+

const extensionFiles = collectExtensionFiles(resolve(REPO_ROOT, "extensions"));

671+

const workspaceFiles = collectWorkspaceCodeFiles();

672+673+

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

674+

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

675+

expect(workspaceFiles.length).toBeGreaterThan(extensionFiles.length);

676+

expect(readDir).not.toHaveBeenCalled();

677+

} finally {

678+

readDir.mockRestore();

679+

}

680+

});

681+592682

it("keeps plugin-sdk entrypoint metadata unique", () => {

593683

const counts = new Map<string, number>();

594684

for (const entrypoint of pluginSdkEntrypoints) {