Makelore 2.0 initial clean snapshot
This commit is contained in:
56
tests/unit/superpowers-plugin.test.ts
Normal file
56
tests/unit/superpowers-plugin.test.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
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(templateId: string, 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({ templateId, ...(typeof superpowersEnabled === 'boolean' ? { superpowersEnabled } : {}) }),
|
||||
'utf8',
|
||||
);
|
||||
return projectPath;
|
||||
}
|
||||
|
||||
describe('bundled Superpowers plugin project gating', () => {
|
||||
it('uses the project setting and template fallback', async () => {
|
||||
const gamePath = await createProjectConfig('game-development');
|
||||
const standardPath = await createProjectConfig('standard-development');
|
||||
const explicitGamePath = await createProjectConfig('game-development', true);
|
||||
|
||||
expect(isSuperpowersEnabledForDirectory(gamePath)).toBe(false);
|
||||
expect(isSuperpowersEnabledForDirectory(standardPath)).toBe(true);
|
||||
expect(isSuperpowersEnabledForDirectory(explicitGamePath)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns no hooks when a project disables Superpowers', async () => {
|
||||
const projectPath = await createProjectConfig('game-development', 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('standard-development', 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');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user