From acf28495b1ae8b911c38a9980eea303709f7a64f Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 2 Aug 2026 03:29:21 +0800 Subject: [PATCH] fix(ci): repair plugin prerelease validation (#117562) --- scripts/lib/state-schema-inline-plugin.d.mts | 9 ++++ scripts/lib/state-schema-inline-plugin.mjs | 40 ++++++++++++++++++ .../capability-provider-runtime.test.ts | 4 +- .../migration-provider-runtime.test.ts | 2 +- ...s.runtime.consult-current-snapshot.test.ts | 4 +- .../web-fetch-providers.runtime.test.ts | 7 ++-- test/vitest/vitest.shared.config.ts | 2 + tsdown.config.ts | 42 +++---------------- 8 files changed, 65 insertions(+), 45 deletions(-) create mode 100644 scripts/lib/state-schema-inline-plugin.d.mts create mode 100644 scripts/lib/state-schema-inline-plugin.mjs diff --git a/scripts/lib/state-schema-inline-plugin.d.mts b/scripts/lib/state-schema-inline-plugin.d.mts new file mode 100644 index 000000000000..329eaf70ac1a --- /dev/null +++ b/scripts/lib/state-schema-inline-plugin.d.mts @@ -0,0 +1,9 @@ +export const STATE_SCHEMA_INLINE_PLUGIN_NAME: string; + +export function createStateSchemaInlinePlugin(rootDir?: string): { + name: string; + load( + this: { addWatchFile(id: string): void }, + id: string, + ): { code: string; moduleType: "js" } | null; +}; diff --git a/scripts/lib/state-schema-inline-plugin.mjs b/scripts/lib/state-schema-inline-plugin.mjs new file mode 100644 index 000000000000..fb48b55d8f0d --- /dev/null +++ b/scripts/lib/state-schema-inline-plugin.mjs @@ -0,0 +1,40 @@ +import fs from "node:fs"; +import path from "node:path"; + +export const STATE_SCHEMA_INLINE_PLUGIN_NAME = "openclaw:inline-state-schemas"; + +const STATE_SCHEMA_MODULES = [ + { + modulePath: "src/state/openclaw-state-schema.ts", + schemaPath: "src/state/openclaw-state-schema.sql", + exportName: "OPENCLAW_STATE_SCHEMA_SQL", + }, + { + modulePath: "src/state/openclaw-agent-schema.ts", + schemaPath: "src/state/openclaw-agent-schema.sql", + exportName: "OPENCLAW_AGENT_SCHEMA_SQL", + }, +]; + +/** Inline canonical schema bytes so bundled consumers need no SQL asset. */ +export function createStateSchemaInlinePlugin(rootDir = process.cwd()) { + const schemasByModulePath = new Map( + STATE_SCHEMA_MODULES.map((schema) => [path.resolve(rootDir, schema.modulePath), schema]), + ); + + return { + name: STATE_SCHEMA_INLINE_PLUGIN_NAME, + load(id) { + const schema = schemasByModulePath.get(path.resolve(id)); + if (!schema) { + return null; + } + const schemaPath = path.resolve(rootDir, schema.schemaPath); + this.addWatchFile(schemaPath); + return { + code: `export const ${schema.exportName} = ${JSON.stringify(fs.readFileSync(schemaPath, "utf8"))};\n`, + moduleType: "js", + }; + }, + }; +} diff --git a/src/plugins/capability-provider-runtime.test.ts b/src/plugins/capability-provider-runtime.test.ts index 7f9ddd94cba3..9aacbec76877 100644 --- a/src/plugins/capability-provider-runtime.test.ts +++ b/src/plugins/capability-provider-runtime.test.ts @@ -80,8 +80,8 @@ vi.mock("./manifest-registry.js", async (importOriginal) => { }; }); -vi.mock("./plugin-registry.js", async (importOriginal) => { - const actual = await importOriginal(); +vi.mock("./plugin-registry-snapshot.js", async (importOriginal) => { + const actual = await importOriginal(); return { ...actual, loadPluginRegistrySnapshot: mocks.loadPluginRegistrySnapshot, diff --git a/src/plugins/migration-provider-runtime.test.ts b/src/plugins/migration-provider-runtime.test.ts index ab91bc697aa0..fa710f244440 100644 --- a/src/plugins/migration-provider-runtime.test.ts +++ b/src/plugins/migration-provider-runtime.test.ts @@ -61,7 +61,7 @@ vi.mock("./active-runtime-registry.js", () => ({ }, })); -vi.mock("./plugin-registry.js", () => ({ +vi.mock("./plugin-registry-snapshot.js", () => ({ loadPluginRegistrySnapshot: mocks.loadPluginRegistrySnapshot, loadPluginRegistrySnapshotWithMetadata: mocks.loadPluginRegistrySnapshotWithMetadata, })); diff --git a/src/plugins/providers.runtime.consult-current-snapshot.test.ts b/src/plugins/providers.runtime.consult-current-snapshot.test.ts index da2fa927c1f0..b08058ccfe5c 100644 --- a/src/plugins/providers.runtime.consult-current-snapshot.test.ts +++ b/src/plugins/providers.runtime.consult-current-snapshot.test.ts @@ -16,8 +16,8 @@ import { resetPluginRuntimeStateForTest } from "./runtime.js"; const loadPluginRegistrySnapshotWithMetadata = vi.hoisted(() => vi.fn()); const loadPluginManifestRegistryForInstalledIndex = vi.hoisted(() => vi.fn()); -vi.mock("./plugin-registry.js", async (importOriginal) => { - const actual = await importOriginal(); +vi.mock("./plugin-registry-snapshot.js", async (importOriginal) => { + const actual = await importOriginal(); return { ...actual, loadPluginRegistrySnapshotWithMetadata: (params: unknown) => diff --git a/src/plugins/web-fetch-providers.runtime.test.ts b/src/plugins/web-fetch-providers.runtime.test.ts index 5b010654b66d..9ded1713f780 100644 --- a/src/plugins/web-fetch-providers.runtime.test.ts +++ b/src/plugins/web-fetch-providers.runtime.test.ts @@ -104,9 +104,10 @@ function createRuntimeWebFetchProvider() { describe("resolvePluginWebFetchProviders", () => { beforeAll(async () => { - vi.doMock("./plugin-registry.js", async () => { - const actual = - await vi.importActual("./plugin-registry.js"); + vi.doMock("./plugin-registry-snapshot.js", async () => { + const actual = await vi.importActual( + "./plugin-registry-snapshot.js", + ); return { ...actual, loadPluginRegistrySnapshotWithMetadata: () => ({ diff --git a/test/vitest/vitest.shared.config.ts b/test/vitest/vitest.shared.config.ts index 5da7b85e5c85..33d2fbe5e696 100644 --- a/test/vitest/vitest.shared.config.ts +++ b/test/vitest/vitest.shared.config.ts @@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url"; import acpCorePackageJson from "../../packages/acp-core/package.json" with { type: "json" }; import { pluginSdkSubpaths } from "../../scripts/lib/plugin-sdk-entries.mjs"; import privateLocalOnlyPluginSdkSubpaths from "../../scripts/lib/plugin-sdk-private-local-only-subpaths.json" with { type: "json" }; +import { createStateSchemaInlinePlugin } from "../../scripts/lib/state-schema-inline-plugin.mjs"; import { detectVitestHostInfo as detectVitestHostInfoImpl, isCiLikeEnv, @@ -158,6 +159,7 @@ if (!isCI && localScheduling.throttledBySystem && shouldPrintVitestThrottle(proc export const sharedVitestConfig = { root: repoRoot, envDir: false as const, + plugins: [createStateSchemaInlinePlugin(repoRoot)], resolve: { alias: [ { diff --git a/tsdown.config.ts b/tsdown.config.ts index 1ca9275f7644..2dcafbe5956d 100644 --- a/tsdown.config.ts +++ b/tsdown.config.ts @@ -11,6 +11,10 @@ import { pluginSdkEntrypoints, productionPluginSdkEntrypoints, } from "./scripts/lib/plugin-sdk-entries.mjs"; +import { + createStateSchemaInlinePlugin, + STATE_SCHEMA_INLINE_PLUGIN_NAME, +} from "./scripts/lib/state-schema-inline-plugin.mjs"; import { TSDOWN_PACKAGE_CONFIG_GROUP, TSDOWN_UNIFIED_CONFIG_GROUP, @@ -46,43 +50,7 @@ const env = { const OUTPUT_SOURCE_MAPS = process.env.OUTPUT_SOURCE_MAPS === "1"; const RUN_NODE_SKIP_DTS_BUILD = process.env.OPENCLAW_RUN_NODE_SKIP_DTS_BUILD === "1"; const TSDOWN_DECLARATIONS = !RUN_NODE_SKIP_DTS_BUILD; -export const STATE_SCHEMA_INLINE_PLUGIN_NAME = "openclaw:inline-state-schemas"; - -const STATE_SCHEMA_MODULES = [ - { - modulePath: "src/state/openclaw-state-schema.ts", - schemaPath: "src/state/openclaw-state-schema.sql", - exportName: "OPENCLAW_STATE_SCHEMA_SQL", - }, - { - modulePath: "src/state/openclaw-agent-schema.ts", - schemaPath: "src/state/openclaw-agent-schema.sql", - exportName: "OPENCLAW_AGENT_SCHEMA_SQL", - }, -] as const; - -/** Inline canonical schema bytes so packaged database opens need no SQL asset. */ -export function createStateSchemaInlinePlugin(rootDir: string = process.cwd()) { - const schemasByModulePath = new Map( - STATE_SCHEMA_MODULES.map((schema) => [path.resolve(rootDir, schema.modulePath), schema]), - ); - - return { - name: STATE_SCHEMA_INLINE_PLUGIN_NAME, - load(this: { addWatchFile(id: string): void }, id: string) { - const schema = schemasByModulePath.get(path.resolve(id)); - if (!schema) { - return null; - } - const schemaPath = path.resolve(rootDir, schema.schemaPath); - this.addWatchFile(schemaPath); - return { - code: `export const ${schema.exportName} = ${JSON.stringify(fs.readFileSync(schemaPath, "utf8"))};\n`, - moduleType: "js" as const, - }; - }, - }; -} +export { createStateSchemaInlinePlugin, STATE_SCHEMA_INLINE_PLUGIN_NAME }; const SUPPRESSED_EVAL_WARNING_PATHS = [ "@protobufjs/inquire/index.js",