mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-20 21:23:23 +00:00
fix(ci): repair contracts and whatsapp regressions
This commit is contained in:
@@ -10,8 +10,6 @@ import {
|
||||
toWhatsappJid,
|
||||
} from "./text-runtime.js";
|
||||
|
||||
const CONFIG_DIR = path.join(process.env.HOME ?? os.tmpdir(), ".openclaw");
|
||||
|
||||
async function withTempDir<T>(
|
||||
prefix: string,
|
||||
run: (dir: string) => T | Promise<T>,
|
||||
@@ -81,17 +79,29 @@ describe("toWhatsappJid", () => {
|
||||
});
|
||||
|
||||
describe("jidToE164", () => {
|
||||
it("maps @lid using reverse mapping file", () => {
|
||||
const mappingPath = path.join(CONFIG_DIR, "credentials", "lid-mapping-123_reverse.json");
|
||||
const original = fs.readFileSync;
|
||||
const spy = vi.spyOn(fs, "readFileSync").mockImplementation((...args) => {
|
||||
if (args[0] === mappingPath) {
|
||||
return `"5551234"`;
|
||||
it("maps @lid using reverse mapping file", async () => {
|
||||
await withTempDir("openclaw-state-", async (stateDir) => {
|
||||
const previousStateDir = process.env.OPENCLAW_STATE_DIR;
|
||||
const credentialsDir = path.join(stateDir, "credentials");
|
||||
fs.mkdirSync(credentialsDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(credentialsDir, "lid-mapping-123_reverse.json"),
|
||||
JSON.stringify("5551234"),
|
||||
);
|
||||
process.env.OPENCLAW_STATE_DIR = stateDir;
|
||||
vi.resetModules();
|
||||
try {
|
||||
const { jidToE164: freshJidToE164 } = await import("./text-runtime.js");
|
||||
expect(freshJidToE164("123@lid")).toBe("+5551234");
|
||||
} finally {
|
||||
if (previousStateDir) {
|
||||
process.env.OPENCLAW_STATE_DIR = previousStateDir;
|
||||
} else {
|
||||
delete process.env.OPENCLAW_STATE_DIR;
|
||||
}
|
||||
vi.resetModules();
|
||||
}
|
||||
return original(...args);
|
||||
});
|
||||
expect(jidToE164("123@lid")).toBe("+5551234");
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it("maps @lid from authDir mapping files", async () => {
|
||||
|
||||
@@ -6,10 +6,10 @@ import type {
|
||||
BundledChannelSetupEntryContract,
|
||||
} from "../../plugin-sdk/channel-entry-contract.js";
|
||||
import {
|
||||
listBundledPluginMetadata,
|
||||
resolveBundledPluginGeneratedPath,
|
||||
type BundledPluginMetadata,
|
||||
} from "../../plugins/bundled-plugin-metadata.js";
|
||||
listBundledChannelPluginMetadata,
|
||||
resolveBundledChannelGeneratedPath,
|
||||
type BundledChannelPluginMetadata,
|
||||
} from "../../plugins/bundled-channel-runtime.js";
|
||||
import type { PluginRuntime } from "../../plugins/runtime/types.js";
|
||||
import { isJavaScriptModulePath, loadChannelPluginModule } from "./module-loader.js";
|
||||
import type { ChannelId, ChannelPlugin } from "./types.js";
|
||||
@@ -74,7 +74,7 @@ function resolveChannelSetupModuleEntry(
|
||||
}
|
||||
|
||||
function resolveBundledChannelBoundaryRoot(params: {
|
||||
metadata: BundledPluginMetadata;
|
||||
metadata: BundledChannelPluginMetadata;
|
||||
modulePath: string;
|
||||
}): string {
|
||||
const distRoot = path.resolve(
|
||||
@@ -90,10 +90,10 @@ function resolveBundledChannelBoundaryRoot(params: {
|
||||
}
|
||||
|
||||
function loadGeneratedBundledChannelModule(params: {
|
||||
metadata: BundledPluginMetadata;
|
||||
entry: BundledPluginMetadata["source"] | BundledPluginMetadata["setupSource"];
|
||||
metadata: BundledChannelPluginMetadata;
|
||||
entry: BundledChannelPluginMetadata["source"] | BundledChannelPluginMetadata["setupSource"];
|
||||
}): unknown {
|
||||
const modulePath = resolveBundledPluginGeneratedPath(
|
||||
const modulePath = resolveBundledChannelGeneratedPath(
|
||||
OPENCLAW_PACKAGE_ROOT,
|
||||
params.entry,
|
||||
params.metadata.dirName,
|
||||
@@ -119,7 +119,7 @@ function loadGeneratedBundledChannelModule(params: {
|
||||
function loadGeneratedBundledChannelEntries(): readonly GeneratedBundledChannelEntry[] {
|
||||
const entries: GeneratedBundledChannelEntry[] = [];
|
||||
|
||||
for (const metadata of listBundledPluginMetadata({
|
||||
for (const metadata of listBundledChannelPluginMetadata({
|
||||
includeChannelConfigs: false,
|
||||
includeSyntheticChannelConfigs: false,
|
||||
})) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import { resolveBundledPluginWorkspaceSourcePath } from "../../../plugins/bundled-plugin-metadata.js";
|
||||
import { resolveBundledChannelWorkspacePath } from "../../../plugins/bundled-channel-runtime.js";
|
||||
import {
|
||||
resolvePluginRuntimeModulePath,
|
||||
resolvePluginRuntimeRecord,
|
||||
@@ -14,7 +14,7 @@ function resolveBundledChannelWorkspaceArtifactPath(
|
||||
entryBaseName: string,
|
||||
): string | null {
|
||||
const normalizedEntryBaseName = entryBaseName.replace(/\.(?:[cm]?js|ts)$/u, "");
|
||||
const pluginRoot = resolveBundledPluginWorkspaceSourcePath({
|
||||
const pluginRoot = resolveBundledChannelWorkspacePath({
|
||||
rootDir: REPO_ROOT,
|
||||
pluginId,
|
||||
});
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import {
|
||||
applyOpencodeZenModelDefault,
|
||||
OPENCODE_ZEN_DEFAULT_MODEL,
|
||||
} from "../../extensions/opencode/api.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
} from "../plugin-sdk/opencode.js";
|
||||
import type { WizardPrompter } from "../wizard/prompts.js";
|
||||
import { applyDefaultModelChoice } from "./auth-choice.default-model.js";
|
||||
|
||||
|
||||
4
src/plugin-sdk/opencode.ts
Normal file
4
src/plugin-sdk/opencode.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export {
|
||||
applyOpencodeZenModelDefault,
|
||||
OPENCODE_ZEN_DEFAULT_MODEL,
|
||||
} from "../../extensions/opencode/api.js";
|
||||
31
src/plugins/bundled-channel-runtime.ts
Normal file
31
src/plugins/bundled-channel-runtime.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import {
|
||||
listBundledPluginMetadata,
|
||||
resolveBundledPluginGeneratedPath,
|
||||
resolveBundledPluginWorkspaceSourcePath,
|
||||
type BundledPluginMetadata,
|
||||
} from "./bundled-plugin-metadata.js";
|
||||
|
||||
export type BundledChannelPluginMetadata = BundledPluginMetadata;
|
||||
|
||||
export function listBundledChannelPluginMetadata(params?: {
|
||||
rootDir?: string;
|
||||
includeChannelConfigs?: boolean;
|
||||
includeSyntheticChannelConfigs?: boolean;
|
||||
}): readonly BundledChannelPluginMetadata[] {
|
||||
return listBundledPluginMetadata(params);
|
||||
}
|
||||
|
||||
export function resolveBundledChannelGeneratedPath(
|
||||
rootDir: string,
|
||||
entry: BundledPluginMetadata["source"] | BundledPluginMetadata["setupSource"],
|
||||
pluginDirName?: string,
|
||||
): string | null {
|
||||
return resolveBundledPluginGeneratedPath(rootDir, entry, pluginDirName);
|
||||
}
|
||||
|
||||
export function resolveBundledChannelWorkspacePath(params: {
|
||||
rootDir: string;
|
||||
pluginId: string;
|
||||
}): string | null {
|
||||
return resolveBundledPluginWorkspaceSourcePath(params);
|
||||
}
|
||||
Reference in New Issue
Block a user