mirror of
https://github.com/Fission-AI/OpenSpec.git
synced 2026-10-21 06:29:34 +08:00
* fix(skills): use skill references in skills-only delivery mode When delivery is configured as 'skills', generated SKILL.md files contained hardcoded /opsx:* command references pointing to commands that were never generated, breaking cross-skill workflows. Add transformToSkillReferences() with the explicit command-to-skill mapping (kept in sync with WORKFLOW_TO_SKILL_DIR) and wire it in init and update wherever skill content is generated, following the approach outlined in #881. Closes #881 Closes #879 Generated with Claude (Cowork) using claude-fable-5; verified with the full vitest suite (1683 tests passing). * fix(skills): wire skill references in workspace skill generation Review follow-up for the skills-only delivery fix: workspace skill setup (src/core/workspace/skills.ts) generates SKILL.md via the same generateSkillContent path but was not wired with transformToSkillReferences, leaving dangling /opsx:* references when delivery is 'skills'. Wire both call sites, add a regression test (verified to fail against the unwired code), strengthen the update skills-only test with content assertions, and correct the COMMAND_TO_SKILL_REFERENCE comment (WORKFLOW_TO_SKILL_DIR exists in both profile-sync-drift.ts and init.ts). Generated with Claude (Cowork) using claude-fable-5; verified with eslint and targeted vitest suites (144 tests passing). * refactor(skills): extract transformer selection into getTransformerForTool Address CodeRabbit review: the tool/delivery transformer selection was duplicated at five call sites across init.ts, update.ts, and workspace/skills.ts. Extract it into a documented helper in command-references.ts with unit tests locking the selection matrix (opencode/pi precedence, skills-only delivery, default). Generated with Claude (Cowork) using claude-fable-5; verified with eslint, tsc, and targeted vitest suites (147 tests passing). * fix(skills): prioritize skill references over hyphen commands in skills-only delivery Address review: getTransformerForTool returned transformToHyphenCommands for opencode/pi before checking delivery, so skills-only delivery still emitted /opsx-* references to commands that were never generated. Check delivery === 'skills' first so skill references win for every tool, and keep the hyphen transform for opencode/pi only when commands are generated. Add unit coverage for the opencode/pi selection matrix and an opencode skills-only init integration test asserting no /opsx: or /opsx- references remain. Generated with Claude (Cowork) using claude-fable-5; verified with eslint, tsc, and targeted vitest suites (148 tests passing). * docs(skills): add docstrings to init/update generation entry points * test(skills): reject stale hyphenated references in skills-only assertions * fix(skills): add missing update entry to command-to-skill reference map COMMAND_TO_SKILL_REFERENCE was missing the update workflow, so a /opsx:update reference in any skill template would survive skills-only transformation untouched. Align the map with the canonical 12-entry WORKFLOW_TO_SKILL_DIR and assert the generated openspec-update-change skill carries no raw command references.
194 lines
7.3 KiB
TypeScript
194 lines
7.3 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import {
|
|
getTransformerForTool,
|
|
transformToHyphenCommands,
|
|
transformToSkillReferences,
|
|
} from '../../src/utils/command-references.js';
|
|
|
|
describe('transformToHyphenCommands', () => {
|
|
describe('basic transformations', () => {
|
|
it('should transform single command reference', () => {
|
|
expect(transformToHyphenCommands('/opsx:new')).toBe('/opsx-new');
|
|
});
|
|
|
|
it('should transform multiple command references', () => {
|
|
const input = '/opsx:new and /opsx:apply';
|
|
const expected = '/opsx-new and /opsx-apply';
|
|
expect(transformToHyphenCommands(input)).toBe(expected);
|
|
});
|
|
|
|
it('should transform command reference in context', () => {
|
|
const input = 'Use /opsx:apply to implement tasks';
|
|
const expected = 'Use /opsx-apply to implement tasks';
|
|
expect(transformToHyphenCommands(input)).toBe(expected);
|
|
});
|
|
|
|
it('should handle backtick-quoted commands', () => {
|
|
const input = 'Run `/opsx:continue` to proceed';
|
|
const expected = 'Run `/opsx-continue` to proceed';
|
|
expect(transformToHyphenCommands(input)).toBe(expected);
|
|
});
|
|
});
|
|
|
|
describe('edge cases', () => {
|
|
it('should return unchanged text with no command references', () => {
|
|
const input = 'This is plain text without commands';
|
|
expect(transformToHyphenCommands(input)).toBe(input);
|
|
});
|
|
|
|
it('should return empty string unchanged', () => {
|
|
expect(transformToHyphenCommands('')).toBe('');
|
|
});
|
|
|
|
it('should not transform similar but non-matching patterns', () => {
|
|
const input = '/ops:new opsx: /other:command';
|
|
expect(transformToHyphenCommands(input)).toBe(input);
|
|
});
|
|
|
|
it('should handle multiple occurrences on same line', () => {
|
|
const input = '/opsx:new /opsx:continue /opsx:apply';
|
|
const expected = '/opsx-new /opsx-continue /opsx-apply';
|
|
expect(transformToHyphenCommands(input)).toBe(expected);
|
|
});
|
|
});
|
|
|
|
describe('multiline content', () => {
|
|
it('should transform references across multiple lines', () => {
|
|
const input = `Use /opsx:new to start
|
|
Then /opsx:continue to proceed
|
|
Finally /opsx:apply to implement`;
|
|
const expected = `Use /opsx-new to start
|
|
Then /opsx-continue to proceed
|
|
Finally /opsx-apply to implement`;
|
|
expect(transformToHyphenCommands(input)).toBe(expected);
|
|
});
|
|
});
|
|
|
|
describe('all known commands', () => {
|
|
const commands = [
|
|
'new',
|
|
'continue',
|
|
'apply',
|
|
'update',
|
|
'ff',
|
|
'sync',
|
|
'archive',
|
|
'bulk-archive',
|
|
'verify',
|
|
'explore',
|
|
'onboard',
|
|
];
|
|
|
|
for (const cmd of commands) {
|
|
it(`should transform /opsx:${cmd}`, () => {
|
|
expect(transformToHyphenCommands(`/opsx:${cmd}`)).toBe(`/opsx-${cmd}`);
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('transformToSkillReferences', () => {
|
|
describe('all known commands', () => {
|
|
const mappings: Array<[string, string]> = [
|
|
['explore', '/openspec-explore'],
|
|
['new', '/openspec-new-change'],
|
|
['continue', '/openspec-continue-change'],
|
|
['apply', '/openspec-apply-change'],
|
|
['update', '/openspec-update-change'],
|
|
['ff', '/openspec-ff-change'],
|
|
['sync', '/openspec-sync-specs'],
|
|
['archive', '/openspec-archive-change'],
|
|
['bulk-archive', '/openspec-bulk-archive-change'],
|
|
['verify', '/openspec-verify-change'],
|
|
['onboard', '/openspec-onboard'],
|
|
['propose', '/openspec-propose'],
|
|
];
|
|
|
|
for (const [cmd, skillRef] of mappings) {
|
|
it(`should transform /opsx:${cmd} to ${skillRef}`, () => {
|
|
expect(transformToSkillReferences(`/opsx:${cmd}`)).toBe(skillRef);
|
|
});
|
|
}
|
|
});
|
|
|
|
describe('basic transformations', () => {
|
|
it('should transform command reference in context', () => {
|
|
const input = 'Use /opsx:apply to implement tasks';
|
|
const expected = 'Use /openspec-apply-change to implement tasks';
|
|
expect(transformToSkillReferences(input)).toBe(expected);
|
|
});
|
|
|
|
it('should transform multiple command references', () => {
|
|
const input = 'Run /opsx:apply then /opsx:archive';
|
|
const expected = 'Run /openspec-apply-change then /openspec-archive-change';
|
|
expect(transformToSkillReferences(input)).toBe(expected);
|
|
});
|
|
|
|
it('should handle backtick-quoted commands', () => {
|
|
const input = 'Run `/opsx:continue` to proceed';
|
|
const expected = 'Run `/openspec-continue-change` to proceed';
|
|
expect(transformToSkillReferences(input)).toBe(expected);
|
|
});
|
|
|
|
it('should transform references across multiple lines', () => {
|
|
const input = `Use /opsx:new to start
|
|
Then /opsx:apply to implement`;
|
|
const expected = `Use /openspec-new-change to start
|
|
Then /openspec-apply-change to implement`;
|
|
expect(transformToSkillReferences(input)).toBe(expected);
|
|
});
|
|
});
|
|
|
|
describe('edge cases', () => {
|
|
it('should return unchanged text with no command references', () => {
|
|
const input = 'This is plain text without commands';
|
|
expect(transformToSkillReferences(input)).toBe(input);
|
|
});
|
|
|
|
it('should return empty string unchanged', () => {
|
|
expect(transformToSkillReferences('')).toBe('');
|
|
});
|
|
|
|
it('should leave unknown command references unchanged', () => {
|
|
const input = 'Try /opsx:unknown-command here';
|
|
expect(transformToSkillReferences(input)).toBe(input);
|
|
});
|
|
|
|
it('should not transform similar but non-matching patterns', () => {
|
|
const input = '/ops:new opsx: /other:command';
|
|
expect(transformToSkillReferences(input)).toBe(input);
|
|
});
|
|
|
|
it('should transform longest matching command (bulk-archive vs archive)', () => {
|
|
const input = '/opsx:bulk-archive and /opsx:archive';
|
|
const expected = '/openspec-bulk-archive-change and /openspec-archive-change';
|
|
expect(transformToSkillReferences(input)).toBe(expected);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('getTransformerForTool', () => {
|
|
it('selects skill references for skills-only delivery for every tool', () => {
|
|
expect(getTransformerForTool('claude', 'skills')).toBe(transformToSkillReferences);
|
|
expect(getTransformerForTool('codex', 'skills')).toBe(transformToSkillReferences);
|
|
// hyphen-command tools must not fall back to hyphen commands when no commands are generated
|
|
expect(getTransformerForTool('opencode', 'skills')).toBe(transformToSkillReferences);
|
|
expect(getTransformerForTool('pi', 'skills')).toBe(transformToSkillReferences);
|
|
expect(getTransformerForTool('oh-my-pi', 'skills')).toBe(transformToSkillReferences);
|
|
});
|
|
|
|
it('selects hyphen commands for opencode, pi, and oh-my-pi when commands are generated', () => {
|
|
expect(getTransformerForTool('opencode', 'both')).toBe(transformToHyphenCommands);
|
|
expect(getTransformerForTool('opencode', 'commands')).toBe(transformToHyphenCommands);
|
|
expect(getTransformerForTool('pi', 'both')).toBe(transformToHyphenCommands);
|
|
expect(getTransformerForTool('pi', 'commands')).toBe(transformToHyphenCommands);
|
|
expect(getTransformerForTool('oh-my-pi', 'both')).toBe(transformToHyphenCommands);
|
|
expect(getTransformerForTool('oh-my-pi', 'commands')).toBe(transformToHyphenCommands);
|
|
});
|
|
|
|
it('selects no transformer for other tools when commands are generated', () => {
|
|
expect(getTransformerForTool('claude', 'both')).toBeUndefined();
|
|
expect(getTransformerForTool('claude', 'commands')).toBeUndefined();
|
|
});
|
|
});
|