refactor: expose plugin test helpers via sdk

This commit is contained in:
Peter Steinberger
2026-04-27 23:45:08 +01:00
parent 6f09039b0c
commit 0df6e5a473
126 changed files with 659 additions and 349 deletions

View File

@@ -43,14 +43,19 @@ const MOCK_RELATIVE_MODULE_PATTERN =
const RELATIVE_CORE_HINT =
"Use openclaw/plugin-sdk/testing or a focused plugin-sdk test/runtime subpath instead of core internals.";
const EXTENSION_TEST_HELPER_BRIDGE_FILES = [
const RETIRED_EXTENSION_TEST_HELPER_BRIDGE_FILES = [
"test/helpers/plugins/env.ts",
"test/helpers/plugins/fetch-mock.ts",
"test/helpers/plugins/frozen-time.ts",
"test/helpers/plugins/media-understanding.ts",
"test/helpers/plugins/mock-http-response.ts",
"test/helpers/plugins/plugin-registration.ts",
"test/helpers/plugins/plugin-registry.ts",
"test/helpers/plugins/provider-registration.ts",
"test/helpers/plugins/provider-usage-fetch.ts",
"test/helpers/plugins/runtime-taskflow.ts",
"test/helpers/plugins/runtime-env.ts",
"test/helpers/plugins/setup-wizard.ts",
"test/helpers/plugins/temp-dir.ts",
"test/helpers/plugins/temp-home.ts",
"test/helpers/plugins/typed-cases.ts",
@@ -122,14 +127,20 @@ function collectRelativeCoreImportOffenders(
function main() {
const extensionsDir = path.join(process.cwd(), "extensions");
const files = [
...collectExtensionTestFiles(extensionsDir),
...EXTENSION_TEST_HELPER_BRIDGE_FILES.map((file) => path.join(process.cwd(), file)).filter(
(file) => fs.existsSync(file),
),
];
const files = collectExtensionTestFiles(extensionsDir);
const offenders: Offender[] = [];
for (const file of RETIRED_EXTENSION_TEST_HELPER_BRIDGE_FILES) {
const filePath = path.join(process.cwd(), file);
if (!fs.existsSync(filePath)) {
continue;
}
offenders.push({
file: filePath,
hint: "Import the helper directly from openclaw/plugin-sdk/testing instead of recreating this bridge.",
});
}
for (const file of files) {
const content = fs.readFileSync(file, "utf8");
for (const rule of FORBIDDEN_PATTERNS) {
@@ -147,9 +158,7 @@ function main() {
}
if (offenders.length > 0) {
console.error(
"Extension test files and helper bridges must stay on public plugin-sdk surfaces.",
);
console.error("Extension test files must stay on public plugin-sdk surfaces.");
for (const offender of offenders.toSorted((a, b) => a.file.localeCompare(b.file))) {
const location = offender.line
? `${relativeToCwd(offender.file)}:${offender.line}`
@@ -161,7 +170,7 @@ function main() {
}
console.log(
`OK: extension test files, support helpers, and helper bridges avoid direct core test/internal imports (${files.length} checked).`,
`OK: extension test files and support helpers avoid direct core test/internal imports (${files.length} checked).`,
);
}