57 lines
2.4 KiB
TypeScript
57 lines
2.4 KiB
TypeScript
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
import { tmpdir } from 'node:os';
|
|
import path from 'node:path';
|
|
import { afterEach, describe, expect, it } from 'vitest';
|
|
import { isSuperpowersEnabledForDirectory, SuperpowersPlugin } from '../../resources/skills/superpowers/.opencode/plugins/superpowers.js';
|
|
|
|
const temporaryDirectories: string[] = [];
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(temporaryDirectories.splice(0).map((directory) => rm(directory, { recursive: true, force: true })));
|
|
});
|
|
|
|
async function createProjectConfig(superpowersEnabled?: boolean): Promise<string> {
|
|
const projectPath = await mkdtemp(path.join(tmpdir(), 'niancode-superpowers-plugin-'));
|
|
temporaryDirectories.push(projectPath);
|
|
await mkdir(path.join(projectPath, '.niancode'), { recursive: true });
|
|
await writeFile(
|
|
path.join(projectPath, '.niancode', 'project.json'),
|
|
JSON.stringify({ schemaVersion: 1, ...(typeof superpowersEnabled === 'boolean' ? { superpowersEnabled } : {}) }),
|
|
'utf8',
|
|
);
|
|
return projectPath;
|
|
}
|
|
|
|
describe('bundled Superpowers plugin project gating', () => {
|
|
it('uses only the explicit project setting', async () => {
|
|
const defaultPath = await createProjectConfig();
|
|
const disabledPath = await createProjectConfig(false);
|
|
const enabledPath = await createProjectConfig(true);
|
|
|
|
expect(isSuperpowersEnabledForDirectory(defaultPath)).toBe(true);
|
|
expect(isSuperpowersEnabledForDirectory(disabledPath)).toBe(false);
|
|
expect(isSuperpowersEnabledForDirectory(enabledPath)).toBe(true);
|
|
});
|
|
|
|
it('returns no hooks when a project disables Superpowers', async () => {
|
|
const projectPath = await createProjectConfig(false);
|
|
|
|
await expect(SuperpowersPlugin({ directory: projectPath })).resolves.toEqual({});
|
|
});
|
|
|
|
it('registers the Skills path and bootstrap when a project enables Superpowers', async () => {
|
|
const projectPath = await createProjectConfig(true);
|
|
const hooks = await SuperpowersPlugin({ directory: projectPath });
|
|
const config = { skills: { paths: [] as string[] } };
|
|
|
|
await hooks.config?.(config);
|
|
expect(config.skills.paths.some((entry) => entry.endsWith(`${path.sep}superpowers${path.sep}skills`))).toBe(true);
|
|
|
|
const output = {
|
|
messages: [{ info: { role: 'user' }, parts: [{ type: 'text', text: 'hello' }] }],
|
|
};
|
|
await hooks['experimental.chat.messages.transform']?.({}, output);
|
|
expect(output.messages[0].parts[0].text).toContain('using-superpowers');
|
|
});
|
|
});
|