Files
adolf/scripts/test-built-bundled-channel-entry-smoke.mjs
alvis bedb527145
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Vendor OpenClaw source as Adolf fork baseline
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11),
free to diverge. Tree copied sans upstream .git; upstream remote added for
future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19.
Preserves docs/ARCHITECTURE.md.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
2026-07-05 09:36:54 +00:00

260 lines
8.0 KiB
JavaScript

// Smoke-tests packaged bundled channel entrypoints in source and installed
// package layouts.
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { fileURLToPath, pathToFileURL } from "node:url";
import { collectRootPackageExcludedExtensionDirs } from "./lib/bundled-plugin-build-entries.mjs";
import { parsePackageRootArg } from "./lib/package-root-args.mjs";
import { installProcessWarningFilter } from "./process-warning-filter.mjs";
installProcessWarningFilter();
process.env.OPENCLAW_DISABLE_BUNDLED_ENTRY_SOURCE_FALLBACK ??= "1";
const { packageRoot } = parsePackageRootArg(
process.argv.slice(2),
"OPENCLAW_BUNDLED_CHANNEL_SMOKE_ROOT",
);
const distExtensionsRoot = path.join(packageRoot, "dist", "extensions");
const excludedPackageExtensionDirs = collectRootPackageExcludedExtensionDirs({ cwd: packageRoot });
const installedLayoutEnv = "OPENCLAW_BUNDLED_CHANNEL_SMOKE_INSTALLED_LAYOUT";
function collectExcludedDistExtensionIds() {
const packageJsonPath = path.join(packageRoot, "package.json");
if (!fs.existsSync(packageJsonPath)) {
return new Set();
}
const packageJson = readJson(packageJsonPath);
const files = Array.isArray(packageJson.files) ? packageJson.files : [];
const excludedIds = new Set();
for (const entry of files) {
if (typeof entry !== "string") {
continue;
}
const match = /^!dist\/extensions\/([^/*]+)\/\*\*$/u.exec(entry.replaceAll("\\", "/"));
if (match) {
excludedIds.add(match[1]);
}
}
return excludedIds;
}
function packageRootLooksInstalled(root) {
return root.replaceAll("\\", "/").endsWith("/node_modules/openclaw");
}
function smokeInInstalledLayoutIfNeeded() {
if (process.env[installedLayoutEnv] === "1" || packageRootLooksInstalled(packageRoot)) {
return;
}
const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-channel-entry-smoke-"));
const nodeModulesRoot = path.join(tempRoot, "node_modules");
const installedPackageRoot = path.join(nodeModulesRoot, "openclaw");
fs.mkdirSync(nodeModulesRoot, { recursive: true });
fs.symlinkSync(packageRoot, installedPackageRoot, "dir");
try {
const result = spawnSync(
process.execPath,
[
"--preserve-symlinks",
fileURLToPath(import.meta.url),
"--package-root",
installedPackageRoot,
],
{
env: { ...process.env, [installedLayoutEnv]: "1" },
stdio: "inherit",
},
);
process.exit(result.status ?? 1);
} finally {
fs.rmSync(tempRoot, { recursive: true, force: true });
}
}
smokeInInstalledLayoutIfNeeded();
async function importBuiltModule(absolutePath) {
return import(pathToFileURL(absolutePath).href);
}
function readJson(pathname) {
return JSON.parse(fs.readFileSync(pathname, "utf8"));
}
function extensionEntryToDistFilename(entry) {
return entry.replace(/^\.\//u, "").replace(/\.[^.]+$/u, ".js");
}
function collectBundledChannelEntryFiles() {
const files = [];
const excludedDistExtensionIds = collectExcludedDistExtensionIds();
for (const dirent of fs.readdirSync(distExtensionsRoot, { withFileTypes: true })) {
if (!dirent.isDirectory()) {
continue;
}
if (excludedDistExtensionIds.has(dirent.name)) {
continue;
}
const extensionRoot = path.join(distExtensionsRoot, dirent.name);
const packageJsonPath = path.join(extensionRoot, "package.json");
if (!fs.existsSync(packageJsonPath)) {
continue;
}
const packageJson = readJson(packageJsonPath);
if (!packageJson.openclaw?.channel) {
continue;
}
if (excludedPackageExtensionDirs.has(dirent.name)) {
continue;
}
const extensionEntries =
Array.isArray(packageJson.openclaw.extensions) && packageJson.openclaw.extensions.length > 0
? packageJson.openclaw.extensions
: ["./index.ts"];
for (const entry of extensionEntries) {
if (typeof entry !== "string" || entry.trim().length === 0) {
continue;
}
files.push({
id: dirent.name,
kind: "channel",
path: path.join(extensionRoot, extensionEntryToDistFilename(entry)),
});
}
const setupEntry = packageJson.openclaw.setupEntry;
if (typeof setupEntry === "string" && setupEntry.trim().length > 0) {
files.push({
id: dirent.name,
kind: "setup",
path: path.join(extensionRoot, extensionEntryToDistFilename(setupEntry)),
});
}
const channelEntryPath = path.join(extensionRoot, "channel-entry.js");
if (fs.existsSync(channelEntryPath)) {
files.push({
id: dirent.name,
kind: "channel",
path: channelEntryPath,
});
}
}
return files.toSorted((left, right) =>
`${left.id}:${left.kind}:${left.path}`.localeCompare(`${right.id}:${right.kind}:${right.path}`),
);
}
function assertSecretContractShape(secrets, context) {
assert.ok(secrets && typeof secrets === "object", `${context}: missing secrets contract`);
assert.equal(
typeof secrets.collectRuntimeConfigAssignments,
"function",
`${context}: collectRuntimeConfigAssignments must be a function`,
);
assert.ok(
Array.isArray(secrets.secretTargetRegistryEntries),
`${context}: secretTargetRegistryEntries must be an array`,
);
}
function assertEntryFileExists(entry) {
assert.ok(
fs.existsSync(entry.path),
`${entry.id} ${entry.kind} entry missing from packed dist: ${entry.path}`,
);
}
async function smokeChannelEntry(entryFile) {
assertEntryFileExists(entryFile);
let entry;
try {
entry = (await importBuiltModule(entryFile.path)).default;
} catch (error) {
throw new Error(
`${entryFile.id} ${entryFile.kind} entry failed to import ${entryFile.path}: ${error instanceof Error ? error.message : String(error)}`,
{ cause: error },
);
}
assert.equal(entry.kind, "bundled-channel-entry", `${entryFile.id} channel entry kind mismatch`);
assert.equal(
typeof entry.loadChannelPlugin,
"function",
`${entryFile.id} channel entry missing loadChannelPlugin`,
);
const plugin = entry.loadChannelPlugin();
assert.equal(plugin?.id, entryFile.id, `${entryFile.id} channel plugin failed to load`);
if (entry.loadChannelSecrets) {
assertSecretContractShape(
entry.loadChannelSecrets(),
`${entryFile.id} channel entry packaged secrets`,
);
}
}
async function smokeSetupEntry(entryFile) {
assertEntryFileExists(entryFile);
let entry;
try {
entry = (await importBuiltModule(entryFile.path)).default;
} catch (error) {
throw new Error(
`${entryFile.id} ${entryFile.kind} entry failed to import ${entryFile.path}: ${error instanceof Error ? error.message : String(error)}`,
{ cause: error },
);
}
if (entry?.kind !== "bundled-channel-setup-entry") {
return false;
}
assert.equal(
entry.kind,
"bundled-channel-setup-entry",
`${entryFile.id} setup entry kind mismatch`,
);
assert.equal(
typeof entry.loadSetupPlugin,
"function",
`${entryFile.id} setup entry missing loadSetupPlugin`,
);
const plugin = entry.loadSetupPlugin();
assert.equal(plugin?.id, entryFile.id, `${entryFile.id} setup plugin failed to load`);
if (entry.loadSetupSecrets) {
assertSecretContractShape(
entry.loadSetupSecrets(),
`${entryFile.id} setup entry packaged secrets`,
);
}
return true;
}
const entryFiles = collectBundledChannelEntryFiles();
let channelCount = 0;
let setupCount = 0;
let legacySetupCount = 0;
for (const entryFile of entryFiles) {
if (entryFile.kind === "channel") {
await smokeChannelEntry(entryFile);
channelCount += 1;
continue;
}
if (await smokeSetupEntry(entryFile)) {
setupCount += 1;
} else {
legacySetupCount += 1;
}
}
assert.ok(channelCount > 0, "no bundled channel entries found");
process.stdout.write(
`[build-smoke] bundled channel entry smoke passed packageRoot=${packageRoot} channel=${channelCount} setup=${setupCount} legacySetup=${legacySetupCount}\n`,
);