37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import { afterEach, describe, expect, it } from 'vitest';
|
|
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import { join } from 'node:path';
|
|
|
|
import { cleanupOpenClawRuntimeNativeClipboard } from '@electron/utils/optional-native-cleanup';
|
|
|
|
describe('optional native cleanup', () => {
|
|
const root = join(tmpdir(), 'clawx-tests', 'optional-native-cleanup');
|
|
|
|
afterEach(() => {
|
|
rmSync(root, { recursive: true, force: true });
|
|
});
|
|
|
|
it('removes optional native clipboard packages from a managed OpenClaw runtime', () => {
|
|
const nodeModules = join(root, 'openclaw', 'node_modules');
|
|
const scope = join(nodeModules, '@mariozechner');
|
|
const nativeClipboard = join(scope, 'clipboard-darwin-arm64');
|
|
const genericClipboard = join(scope, 'clipboard');
|
|
const codingAgent = join(scope, 'pi-coding-agent');
|
|
const unrelated = join(nodeModules, '@example', 'clipboard-darwin-arm64');
|
|
|
|
for (const dir of [nativeClipboard, genericClipboard, codingAgent, unrelated]) {
|
|
mkdirSync(dir, { recursive: true });
|
|
writeFileSync(join(dir, 'package.json'), '{}\n');
|
|
}
|
|
|
|
const removed = cleanupOpenClawRuntimeNativeClipboard(join(root, 'openclaw'));
|
|
|
|
expect(removed).toBe(2);
|
|
expect(existsSync(nativeClipboard)).toBe(false);
|
|
expect(existsSync(genericClipboard)).toBe(false);
|
|
expect(existsSync(codingAgent)).toBe(true);
|
|
expect(existsSync(unrelated)).toBe(true);
|
|
});
|
|
});
|