mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 19:50:43 +00:00
94 lines
2.8 KiB
TypeScript
94 lines
2.8 KiB
TypeScript
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
import { dirname, join } from "node:path";
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import {
|
|
resolveAugmentedPluginNpmManifest,
|
|
withAugmentedPluginNpmManifestForPackage,
|
|
} from "../scripts/lib/plugin-npm-package-manifest.mjs";
|
|
import { cleanupTempDirs, makeTempRepoRoot, writeJsonFile } from "./helpers/temp-repo.js";
|
|
|
|
const tempDirs: string[] = [];
|
|
|
|
afterEach(() => {
|
|
cleanupTempDirs(tempDirs);
|
|
});
|
|
|
|
function writeGeneratedChannelMetadata(repoDir: string): void {
|
|
const metadataPath = join(
|
|
repoDir,
|
|
"src",
|
|
"config",
|
|
"bundled-channel-config-metadata.generated.ts",
|
|
);
|
|
mkdirSync(join(repoDir, "src", "config"), { recursive: true });
|
|
writeFileText(
|
|
metadataPath,
|
|
`export const GENERATED_BUNDLED_CHANNEL_CONFIG_METADATA = [
|
|
{
|
|
pluginId: "twitch",
|
|
channelId: "twitch",
|
|
label: "Twitch",
|
|
description: "Twitch chat integration",
|
|
schema: {
|
|
type: "object",
|
|
required: ["channelName"],
|
|
properties: {
|
|
channelName: { type: "string" },
|
|
},
|
|
},
|
|
},
|
|
] as const;
|
|
`,
|
|
);
|
|
}
|
|
|
|
function writeFileText(filePath: string, text: string): void {
|
|
mkdirSync(dirname(filePath), { recursive: true });
|
|
// writeJsonFile intentionally owns JSON formatting only.
|
|
writeFileSync(filePath, text, "utf8");
|
|
}
|
|
|
|
describe("plugin npm package manifest staging", () => {
|
|
it("overlays generated channel configs while packing and restores source manifest", () => {
|
|
const repoDir = makeTempRepoRoot(tempDirs, "openclaw-plugin-npm-package-manifest-");
|
|
const packageDir = join(repoDir, "extensions", "twitch");
|
|
mkdirSync(packageDir, { recursive: true });
|
|
const sourceManifest = {
|
|
id: "twitch",
|
|
channels: ["twitch"],
|
|
configSchema: {
|
|
type: "object",
|
|
additionalProperties: false,
|
|
properties: {},
|
|
},
|
|
};
|
|
writeJsonFile(join(packageDir, "openclaw.plugin.json"), sourceManifest);
|
|
writeGeneratedChannelMetadata(repoDir);
|
|
|
|
const resolved = resolveAugmentedPluginNpmManifest({
|
|
repoRoot: repoDir,
|
|
packageDir,
|
|
});
|
|
expect(resolved.changed).toBe(true);
|
|
expect(resolved.manifest).toMatchObject({
|
|
channelConfigs: {
|
|
twitch: {
|
|
label: "Twitch",
|
|
schema: {
|
|
required: ["channelName"],
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
const originalText = readFileSync(join(packageDir, "openclaw.plugin.json"), "utf8");
|
|
withAugmentedPluginNpmManifestForPackage({ repoRoot: repoDir, packageDir }, () => {
|
|
const stagedManifest = JSON.parse(
|
|
readFileSync(join(packageDir, "openclaw.plugin.json"), "utf8"),
|
|
);
|
|
expect(stagedManifest.channelConfigs.twitch.description).toBe("Twitch chat integration");
|
|
});
|
|
expect(readFileSync(join(packageDir, "openclaw.plugin.json"), "utf8")).toBe(originalText);
|
|
});
|
|
});
|