Files
openclaw-zero-token/plugins/runtime-live-state-guardrails.test.ts
sjhu 571e14a236 feat: upgrade to upstream v2026.3.28
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
2026-03-30 17:58:12 +08:00

68 lines
1.8 KiB
TypeScript

import { readFileSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { describe, expect, it } from "vitest";
const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
const LIVE_RUNTIME_STATE_GUARDS: Record<
string,
{
required: readonly string[];
forbidden: readonly string[];
}
> = {
"extensions/whatsapp/src/active-listener.ts": {
required: ["globalThis", 'Symbol.for("openclaw.whatsapp.activeListenerState")'],
forbidden: ["resolveGlobalSingleton"],
},
};
function guardAssertions() {
return Object.entries(LIVE_RUNTIME_STATE_GUARDS).flatMap(([relativePath, guard]) => [
...guard.required.map((needle) => ({
relativePath,
type: "required" as const,
needle,
message: `${relativePath} missing ${needle}`,
})),
...guard.forbidden.map((needle) => ({
relativePath,
type: "forbidden" as const,
needle,
message: `${relativePath} must not contain ${needle}`,
})),
]);
}
function expectGuardState(params: {
source: string;
type: "required" | "forbidden";
needle: string;
message: string;
}) {
if (params.type === "required") {
expect(params.source, params.message).toContain(params.needle);
return;
}
expect(params.source, params.message).not.toContain(params.needle);
}
function readGuardrailSource(relativePath: string) {
return readFileSync(resolve(repoRoot, relativePath), "utf8");
}
describe("runtime live state guardrails", () => {
it.each(guardAssertions())(
"keeps split-runtime state holders on explicit direct globals: $relativePath $type $needle",
({ relativePath, type, needle, message }) => {
expectGuardState({
source: readGuardrailSource(relativePath),
type,
needle,
message,
});
},
);
});