mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:10:45 +00:00
test(plugin-sdk): use narrow config runtime mocks
This commit is contained in:
@@ -7,6 +7,16 @@ import { collectFilesSync, isCodeFile, relativeToCwd } from "./check-file-utils.
|
||||
// imports/exports, require/dynamic import, and test mocks (vi.mock/jest.mock).
|
||||
const ROOT_IMPORT_PATTERN = /["']openclaw\/plugin-sdk["']/;
|
||||
const LEGACY_COMPAT_IMPORT_PATTERN = /["']openclaw\/plugin-sdk\/compat["']/;
|
||||
const LEGACY_BROAD_SUBPATH_PATTERNS = [
|
||||
{
|
||||
pattern: /["']openclaw\/plugin-sdk\/channel-runtime["']/,
|
||||
label: "openclaw/plugin-sdk/channel-runtime",
|
||||
},
|
||||
{
|
||||
pattern: /["']openclaw\/plugin-sdk\/config-runtime["']/,
|
||||
label: "openclaw/plugin-sdk/config-runtime",
|
||||
},
|
||||
] as const;
|
||||
|
||||
function hasMonolithicRootImport(content: string): boolean {
|
||||
return ROOT_IMPORT_PATTERN.test(content);
|
||||
@@ -16,6 +26,12 @@ function hasLegacyCompatImport(content: string): boolean {
|
||||
return LEGACY_COMPAT_IMPORT_PATTERN.test(content);
|
||||
}
|
||||
|
||||
function findLegacyBroadSubpathImports(content: string): string[] {
|
||||
return LEGACY_BROAD_SUBPATH_PATTERNS.filter(({ pattern }) => pattern.test(content)).map(
|
||||
({ label }) => label,
|
||||
);
|
||||
}
|
||||
|
||||
function collectPluginSourceFiles(rootDir: string): string[] {
|
||||
const srcDir = path.join(rootDir, "src");
|
||||
if (!fs.existsSync(srcDir)) {
|
||||
@@ -71,6 +87,7 @@ function main() {
|
||||
|
||||
const monolithicOffenders: string[] = [];
|
||||
const legacyCompatOffenders: string[] = [];
|
||||
const legacyBroadSubpathOffenders = new Map<string, string[]>();
|
||||
for (const entryFile of filesToCheck) {
|
||||
let content = "";
|
||||
try {
|
||||
@@ -84,9 +101,17 @@ function main() {
|
||||
if (hasLegacyCompatImport(content)) {
|
||||
legacyCompatOffenders.push(entryFile);
|
||||
}
|
||||
const legacyBroadSubpaths = findLegacyBroadSubpathImports(content);
|
||||
if (legacyBroadSubpaths.length > 0) {
|
||||
legacyBroadSubpathOffenders.set(entryFile, legacyBroadSubpaths);
|
||||
}
|
||||
}
|
||||
|
||||
if (monolithicOffenders.length > 0 || legacyCompatOffenders.length > 0) {
|
||||
if (
|
||||
monolithicOffenders.length > 0 ||
|
||||
legacyCompatOffenders.length > 0 ||
|
||||
legacyBroadSubpathOffenders.size > 0
|
||||
) {
|
||||
if (monolithicOffenders.length > 0) {
|
||||
console.error("Bundled plugin source files must not import monolithic openclaw/plugin-sdk.");
|
||||
for (const file of monolithicOffenders.toSorted()) {
|
||||
@@ -101,9 +126,23 @@ function main() {
|
||||
console.error(`- ${relativeToCwd(file)}`);
|
||||
}
|
||||
}
|
||||
if (monolithicOffenders.length > 0 || legacyCompatOffenders.length > 0) {
|
||||
if (legacyBroadSubpathOffenders.size > 0) {
|
||||
console.error(
|
||||
"Use openclaw/plugin-sdk/<domain> or openclaw/plugin-sdk/<channel> subpaths for bundled plugins; root and compat are legacy surfaces only.",
|
||||
"Bundled plugin source files must not import deprecated broad plugin-sdk subpaths.",
|
||||
);
|
||||
for (const [file, labels] of [...legacyBroadSubpathOffenders.entries()].toSorted(
|
||||
([left], [right]) => left.localeCompare(right),
|
||||
)) {
|
||||
console.error(`- ${relativeToCwd(file)} (${labels.join(", ")})`);
|
||||
}
|
||||
}
|
||||
if (
|
||||
monolithicOffenders.length > 0 ||
|
||||
legacyCompatOffenders.length > 0 ||
|
||||
legacyBroadSubpathOffenders.size > 0
|
||||
) {
|
||||
console.error(
|
||||
"Use focused openclaw/plugin-sdk/<domain> subpaths for bundled plugins; root, compat, and broad runtime barrels are legacy surfaces only.",
|
||||
);
|
||||
}
|
||||
process.exit(1);
|
||||
|
||||
@@ -32,6 +32,12 @@ const PROCESS_BOUNDARY_DIRECT_CONFIG_LOAD_FILES = new Set([
|
||||
"src/cli/daemon-cli/status.gather.ts",
|
||||
]);
|
||||
|
||||
const BROAD_CONFIG_RUNTIME_COMPAT_FILES = new Set([
|
||||
"scripts/check-no-monolithic-plugin-sdk-entry-imports.ts",
|
||||
"src/plugins/bundled-capability-runtime.test.ts",
|
||||
"src/plugins/contracts/config-boundary-guard.test.ts",
|
||||
]);
|
||||
|
||||
function collectTypeScriptFiles(dir) {
|
||||
if (!existsSync(dir)) {
|
||||
return [];
|
||||
@@ -176,6 +182,19 @@ function pushBroadConfigRuntimeBarrelViolations(violations, files) {
|
||||
}
|
||||
}
|
||||
|
||||
function pushBroadConfigRuntimeSpecifierViolations(violations, files) {
|
||||
const moduleSpecifierPattern = /["']openclaw\/plugin-sdk\/config-runtime["']/g;
|
||||
|
||||
for (const { filePath, relPath } of files) {
|
||||
const source = readFileSync(filePath, "utf8");
|
||||
for (const line of findMatchLineNumbers(source, moduleSpecifierPattern)) {
|
||||
violations.push(
|
||||
`${relPath}:${line} use narrow plugin-sdk config subpaths instead of openclaw/plugin-sdk/config-runtime`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function collectDeprecatedInternalConfigApiViolations({
|
||||
repoRoot = DEFAULT_REPO_ROOT,
|
||||
} = {}) {
|
||||
@@ -246,6 +265,13 @@ export function collectDeprecatedInternalConfigApiViolations({
|
||||
!relPath.startsWith("test/"),
|
||||
),
|
||||
);
|
||||
pushBroadConfigRuntimeSpecifierViolations(
|
||||
violations,
|
||||
repoFiles.filter(
|
||||
({ relPath }) =>
|
||||
!isCompatConfigApiFile(relPath) && !BROAD_CONFIG_RUNTIME_COMPAT_FILES.has(relPath),
|
||||
),
|
||||
);
|
||||
|
||||
for (const { filePath, relPath } of repoFiles.filter(
|
||||
({ relPath }) => !isCompatConfigApiFile(relPath),
|
||||
@@ -354,7 +380,7 @@ export function collectDeprecatedInternalConfigApiViolations({
|
||||
);
|
||||
}
|
||||
|
||||
return violations;
|
||||
return [...new Set(violations)];
|
||||
}
|
||||
|
||||
const CHANNEL_EXTENSION_IDS = new Set([
|
||||
|
||||
Reference in New Issue
Block a user