mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-26 04:15:48 -06:00
refactor(install): remove obsolete Baileys media hotfix (#129751)
This commit is contained in:
committed by
GitHub
parent
3d09235b0f
commit
b5fcae34fe
@@ -7,7 +7,6 @@ import { fileURLToPath } from "node:url";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { writePackageDistInventory } from "../../scripts/lib/package-dist-inventory.ts";
|
||||
import {
|
||||
applyBaileysEncryptedStreamFinishHotfix,
|
||||
collectLegacyPluginRuntimeDepsStateRoots,
|
||||
isSourceCheckoutRoot,
|
||||
isDirectPostinstallInvocation,
|
||||
@@ -53,20 +52,6 @@ async function writePluginPackage(
|
||||
}
|
||||
}
|
||||
|
||||
async function writeBaileysMediaFile(packageRoot: string, text: string) {
|
||||
const mediaFile = path.join(
|
||||
packageRoot,
|
||||
"node_modules",
|
||||
"baileys",
|
||||
"lib",
|
||||
"Utils",
|
||||
"messages-media.js",
|
||||
);
|
||||
await fs.mkdir(path.dirname(mediaFile), { recursive: true });
|
||||
await fs.writeFile(mediaFile, text);
|
||||
return mediaFile;
|
||||
}
|
||||
|
||||
describe("bundled plugin postinstall", () => {
|
||||
it("resolves TypeScript from NODE_PATH during external modules-dir installs", async () => {
|
||||
const packageRoot = await createTempDirAsync("openclaw-postinstall-node-path-");
|
||||
@@ -203,118 +188,6 @@ describe("bundled plugin postinstall", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it("patches the Baileys upload helper dispatcher guard", async () => {
|
||||
const packageRoot = await createTempDirAsync("openclaw-baileys-postinstall-");
|
||||
const mediaFile = await writeBaileysMediaFile(
|
||||
packageRoot,
|
||||
[
|
||||
"import { once } from 'events';",
|
||||
"const encryptedStream = async () => {",
|
||||
" encFileWriteStream.write(mac);",
|
||||
" const encFinishPromise = once(encFileWriteStream, 'finish');",
|
||||
" const originalFinishPromise = originalFileStream ? once(originalFileStream, 'finish') : Promise.resolve();",
|
||||
" encFileWriteStream.end();",
|
||||
" originalFileStream?.end?.();",
|
||||
" stream.destroy();",
|
||||
" await encFinishPromise;",
|
||||
" await originalFinishPromise;",
|
||||
" logger?.debug('encrypted data successfully');",
|
||||
"};",
|
||||
"const uploadWithFetch = async ({ url, filePath, headers, timeoutMs, agent }) => {",
|
||||
" const nodeStream = createReadStream(filePath);",
|
||||
" const webStream = Readable.toWeb(nodeStream);",
|
||||
" const response = await fetch(url, {",
|
||||
" dispatcher: agent,",
|
||||
" method: 'POST',",
|
||||
" body: webStream,",
|
||||
" headers,",
|
||||
" duplex: 'half',",
|
||||
" signal: timeoutMs ? AbortSignal.timeout(timeoutMs) : undefined",
|
||||
" });",
|
||||
"};",
|
||||
"",
|
||||
].join("\n"),
|
||||
);
|
||||
|
||||
expect(applyBaileysEncryptedStreamFinishHotfix({ packageRoot })).toEqual({
|
||||
applied: true,
|
||||
reason: "patched",
|
||||
targetPath: mediaFile,
|
||||
});
|
||||
const patchedText = await fs.readFile(mediaFile, "utf8");
|
||||
expect(patchedText).toContain(
|
||||
"...(typeof agent?.dispatch === 'function' ? { dispatcher: agent } : {}),",
|
||||
);
|
||||
expect(patchedText).not.toContain(" dispatcher: agent,");
|
||||
});
|
||||
|
||||
it("recognizes already patched Baileys upload helpers", async () => {
|
||||
const packageRoot = await createTempDirAsync("openclaw-baileys-postinstall-");
|
||||
await writeBaileysMediaFile(
|
||||
packageRoot,
|
||||
[
|
||||
"import { once } from 'events';",
|
||||
"const encryptedStream = async () => {",
|
||||
" encFileWriteStream.write(mac);",
|
||||
" const encFinishPromise = once(encFileWriteStream, 'finish');",
|
||||
" const originalFinishPromise = originalFileStream ? once(originalFileStream, 'finish') : Promise.resolve();",
|
||||
" encFileWriteStream.end();",
|
||||
" originalFileStream?.end?.();",
|
||||
" stream.destroy();",
|
||||
" await encFinishPromise;",
|
||||
" await originalFinishPromise;",
|
||||
" logger?.debug('encrypted data successfully');",
|
||||
"};",
|
||||
"const uploadWithFetch = async ({ url, filePath, headers, timeoutMs, agent }) => {",
|
||||
" const response = await fetch(url, {",
|
||||
" ...(typeof agent?.dispatch === 'function' ? { dispatcher: agent } : {}),",
|
||||
" method: 'POST',",
|
||||
" });",
|
||||
"};",
|
||||
"",
|
||||
].join("\n"),
|
||||
);
|
||||
|
||||
expect(applyBaileysEncryptedStreamFinishHotfix({ packageRoot })).toEqual({
|
||||
applied: false,
|
||||
reason: "already_patched",
|
||||
});
|
||||
});
|
||||
|
||||
it("recognizes Baileys upload helpers with a prepared dispatcher", async () => {
|
||||
const packageRoot = await createTempDirAsync("openclaw-baileys-postinstall-");
|
||||
await writeBaileysMediaFile(
|
||||
packageRoot,
|
||||
[
|
||||
"import { once } from 'events';",
|
||||
"const encryptedStream = async () => {",
|
||||
" encFileWriteStream.write(mac);",
|
||||
" const encFinishPromise = once(encFileWriteStream, 'finish');",
|
||||
" const originalFinishPromise = originalFileStream ? once(originalFileStream, 'finish') : Promise.resolve();",
|
||||
" encFileWriteStream.end();",
|
||||
" originalFileStream?.end?.();",
|
||||
" stream.destroy();",
|
||||
" await encFinishPromise;",
|
||||
" await originalFinishPromise;",
|
||||
" logger?.debug('encrypted data successfully');",
|
||||
"};",
|
||||
"const uploadWithFetch = async ({ url, filePath, headers, timeoutMs, agent }) => {",
|
||||
" const dispatcher = typeof agent?.dispatch === 'function' ? agent : undefined;",
|
||||
" const response = await fetch(url, {",
|
||||
" ...(dispatcher ? { dispatcher } : {}),",
|
||||
" method: 'POST',",
|
||||
" });",
|
||||
"};",
|
||||
"",
|
||||
].join("\n"),
|
||||
);
|
||||
|
||||
expect(applyBaileysEncryptedStreamFinishHotfix({ packageRoot })).toEqual({
|
||||
applied: false,
|
||||
reason: "already_patched",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not classify published packages with source files as source checkouts", () => {
|
||||
const packageRoot = "/pkg";
|
||||
const existingPaths = new Set([
|
||||
|
||||
Reference in New Issue
Block a user