File size: 1,302 Bytes
f0634fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import { execFileSync } from 'node:child_process';
import { readFile } from 'node:fs/promises';
import { mkdtemp, mkdir, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { extractZip } from '#/app/plugin/archive';
describe('plugin archive extraction', () => {
let dir: string;
beforeEach(async () => {
dir = await mkdtemp(join(tmpdir(), 'plugin-archive-test-'));
});
afterEach(async () => {
await rm(dir, { recursive: true, force: true });
});
it('extracts a zip and detects a nested plugin root', async () => {
const source = join(dir, 'source');
const nested = join(source, 'plugin');
await mkdir(nested, { recursive: true });
await writeFile(join(nested, 'kimi.plugin.json'), JSON.stringify({ name: 'zip-demo' }), 'utf8');
const zipPath = join(dir, 'plugin.zip');
execFileSync('zip', ['-qr', zipPath, '.'], { cwd: source });
const outDir = join(dir, 'out');
const detectedRoot = await extractZip(await readFile(zipPath), outDir);
expect(detectedRoot).toBe(join(outDir, 'plugin'));
await expect(readFile(join(detectedRoot, 'kimi.plugin.json'), 'utf8')).resolves.toContain('zip-demo');
});
});
|