Files
openclaw/scripts/test-built-status-message-runtime.mjs
neilofneils404 482ff924ef fix: pass directories to provider stream wrappers (#67843)
* fix: pass directories to provider stream wrappers

* fix: pass directories to provider stream wrappers

---------

Co-authored-by: neilofneils404 <258699186+neilofneils404@users.noreply.github.com>
Co-authored-by: vincentkoc <25068+vincentkoc@users.noreply.github.com>
2026-04-27 15:43:38 -07:00

48 lines
1.6 KiB
JavaScript

import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { pathToFileURL } from "node:url";
import { parsePackageRootArg } from "./lib/package-root-args.mjs";
const STATUS_MESSAGE_RUNTIME_RE = /^status-message\.runtime(?:-[A-Za-z0-9_-]+)?\.js$/u;
const { packageRoot } = parsePackageRootArg(
process.argv.slice(2),
"OPENCLAW_STATUS_MESSAGE_RUNTIME_ROOT",
);
function findBuiltStatusMessageRuntimePath(distDir) {
const candidates = fs
.readdirSync(distDir, { withFileTypes: true })
.filter((entry) => entry.isFile() && STATUS_MESSAGE_RUNTIME_RE.test(entry.name))
.map((entry) => entry.name)
.toSorted((left, right) => {
const leftHasHash = left !== "status-message.runtime.js";
const rightHasHash = right !== "status-message.runtime.js";
if (leftHasHash !== rightHasHash) {
return leftHasHash ? -1 : 1;
}
return left.localeCompare(right);
});
assert.ok(candidates.length > 0, `missing built status-message runtime bundle under ${distDir}`);
return path.join(distDir, candidates[0]);
}
const runtimePath = findBuiltStatusMessageRuntimePath(path.join(packageRoot, "dist"));
const runtimeModule = await import(pathToFileURL(runtimePath).href);
assert.equal(
typeof runtimeModule.loadStatusMessageRuntimeModule,
"function",
`built status-message runtime did not export loadStatusMessageRuntimeModule: ${runtimePath}`,
);
const statusModule = await runtimeModule.loadStatusMessageRuntimeModule();
assert.equal(
typeof statusModule.buildStatusMessage,
"function",
"status-message runtime did not load buildStatusMessage",
);