opencode-swarm-plugin 0.43.0 → 0.44.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cass.characterization.test.ts +422 -0
- package/bin/swarm.serve.test.ts +6 -4
- package/bin/swarm.test.ts +68 -0
- package/bin/swarm.ts +81 -8
- package/dist/compaction-prompt-scoring.js +139 -0
- package/dist/contributor-tools.d.ts +42 -0
- package/dist/contributor-tools.d.ts.map +1 -0
- package/dist/eval-capture.js +12811 -0
- package/dist/hive.d.ts.map +1 -1
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7728 -62590
- package/dist/plugin.js +23833 -78695
- package/dist/sessions/agent-discovery.d.ts +59 -0
- package/dist/sessions/agent-discovery.d.ts.map +1 -0
- package/dist/sessions/index.d.ts +10 -0
- package/dist/sessions/index.d.ts.map +1 -0
- package/dist/swarm-orchestrate.d.ts.map +1 -1
- package/dist/swarm-prompts.d.ts.map +1 -1
- package/dist/swarm-review.d.ts.map +1 -1
- package/package.json +17 -5
- package/.changeset/swarm-insights-data-layer.md +0 -63
- package/.hive/analysis/eval-failure-analysis-2025-12-25.md +0 -331
- package/.hive/analysis/session-data-quality-audit.md +0 -320
- package/.hive/eval-results.json +0 -483
- package/.hive/issues.jsonl +0 -138
- package/.hive/memories.jsonl +0 -729
- package/.opencode/eval-history.jsonl +0 -327
- package/.turbo/turbo-build.log +0 -9
- package/CHANGELOG.md +0 -2255
- package/SCORER-ANALYSIS.md +0 -598
- package/docs/analysis/subagent-coordination-patterns.md +0 -902
- package/docs/analysis-socratic-planner-pattern.md +0 -504
- package/docs/planning/ADR-001-monorepo-structure.md +0 -171
- package/docs/planning/ADR-002-package-extraction.md +0 -393
- package/docs/planning/ADR-003-performance-improvements.md +0 -451
- package/docs/planning/ADR-004-message-queue-features.md +0 -187
- package/docs/planning/ADR-005-devtools-observability.md +0 -202
- package/docs/planning/ADR-007-swarm-enhancements-worktree-review.md +0 -168
- package/docs/planning/ADR-008-worker-handoff-protocol.md +0 -293
- package/docs/planning/ADR-009-oh-my-opencode-patterns.md +0 -353
- package/docs/planning/ROADMAP.md +0 -368
- package/docs/semantic-memory-cli-syntax.md +0 -123
- package/docs/swarm-mail-architecture.md +0 -1147
- package/docs/testing/context-recovery-test.md +0 -470
- package/evals/ARCHITECTURE.md +0 -1189
- package/evals/README.md +0 -768
- package/evals/compaction-prompt.eval.ts +0 -149
- package/evals/compaction-resumption.eval.ts +0 -289
- package/evals/coordinator-behavior.eval.ts +0 -307
- package/evals/coordinator-session.eval.ts +0 -154
- package/evals/evalite.config.ts.bak +0 -15
- package/evals/example.eval.ts +0 -31
- package/evals/fixtures/compaction-cases.ts +0 -350
- package/evals/fixtures/compaction-prompt-cases.ts +0 -311
- package/evals/fixtures/coordinator-sessions.ts +0 -328
- package/evals/fixtures/decomposition-cases.ts +0 -105
- package/evals/lib/compaction-loader.test.ts +0 -248
- package/evals/lib/compaction-loader.ts +0 -320
- package/evals/lib/data-loader.evalite-test.ts +0 -289
- package/evals/lib/data-loader.test.ts +0 -345
- package/evals/lib/data-loader.ts +0 -281
- package/evals/lib/llm.ts +0 -115
- package/evals/scorers/compaction-prompt-scorers.ts +0 -145
- package/evals/scorers/compaction-scorers.ts +0 -305
- package/evals/scorers/coordinator-discipline.evalite-test.ts +0 -539
- package/evals/scorers/coordinator-discipline.ts +0 -325
- package/evals/scorers/index.test.ts +0 -146
- package/evals/scorers/index.ts +0 -328
- package/evals/scorers/outcome-scorers.evalite-test.ts +0 -27
- package/evals/scorers/outcome-scorers.ts +0 -349
- package/evals/swarm-decomposition.eval.ts +0 -121
- package/examples/commands/swarm.md +0 -745
- package/examples/plugin-wrapper-template.ts +0 -2426
- package/examples/skills/hive-workflow/SKILL.md +0 -212
- package/examples/skills/skill-creator/SKILL.md +0 -223
- package/examples/skills/swarm-coordination/SKILL.md +0 -292
- package/global-skills/cli-builder/SKILL.md +0 -344
- package/global-skills/cli-builder/references/advanced-patterns.md +0 -244
- package/global-skills/learning-systems/SKILL.md +0 -644
- package/global-skills/skill-creator/LICENSE.txt +0 -202
- package/global-skills/skill-creator/SKILL.md +0 -352
- package/global-skills/skill-creator/references/output-patterns.md +0 -82
- package/global-skills/skill-creator/references/workflows.md +0 -28
- package/global-skills/swarm-coordination/SKILL.md +0 -995
- package/global-skills/swarm-coordination/references/coordinator-patterns.md +0 -235
- package/global-skills/swarm-coordination/references/strategies.md +0 -138
- package/global-skills/system-design/SKILL.md +0 -213
- package/global-skills/testing-patterns/SKILL.md +0 -430
- package/global-skills/testing-patterns/references/dependency-breaking-catalog.md +0 -586
- package/opencode-swarm-plugin-0.30.7.tgz +0 -0
- package/opencode-swarm-plugin-0.31.0.tgz +0 -0
- package/scripts/cleanup-test-memories.ts +0 -346
- package/scripts/init-skill.ts +0 -222
- package/scripts/migrate-unknown-sessions.ts +0 -349
- package/scripts/validate-skill.ts +0 -204
- package/src/agent-mail.ts +0 -1724
- package/src/anti-patterns.test.ts +0 -1167
- package/src/anti-patterns.ts +0 -448
- package/src/compaction-capture.integration.test.ts +0 -257
- package/src/compaction-hook.test.ts +0 -838
- package/src/compaction-hook.ts +0 -1204
- package/src/compaction-observability.integration.test.ts +0 -139
- package/src/compaction-observability.test.ts +0 -187
- package/src/compaction-observability.ts +0 -324
- package/src/compaction-prompt-scorers.test.ts +0 -475
- package/src/compaction-prompt-scoring.ts +0 -300
- package/src/dashboard.test.ts +0 -611
- package/src/dashboard.ts +0 -462
- package/src/error-enrichment.test.ts +0 -403
- package/src/error-enrichment.ts +0 -219
- package/src/eval-capture.test.ts +0 -1015
- package/src/eval-capture.ts +0 -929
- package/src/eval-gates.test.ts +0 -306
- package/src/eval-gates.ts +0 -218
- package/src/eval-history.test.ts +0 -508
- package/src/eval-history.ts +0 -214
- package/src/eval-learning.test.ts +0 -378
- package/src/eval-learning.ts +0 -360
- package/src/eval-runner.test.ts +0 -223
- package/src/eval-runner.ts +0 -402
- package/src/export-tools.test.ts +0 -476
- package/src/export-tools.ts +0 -257
- package/src/hive.integration.test.ts +0 -2241
- package/src/hive.ts +0 -1628
- package/src/index.ts +0 -935
- package/src/learning.integration.test.ts +0 -1815
- package/src/learning.ts +0 -1079
- package/src/logger.test.ts +0 -189
- package/src/logger.ts +0 -135
- package/src/mandate-promotion.test.ts +0 -473
- package/src/mandate-promotion.ts +0 -239
- package/src/mandate-storage.integration.test.ts +0 -601
- package/src/mandate-storage.test.ts +0 -578
- package/src/mandate-storage.ts +0 -794
- package/src/mandates.ts +0 -540
- package/src/memory-tools.test.ts +0 -195
- package/src/memory-tools.ts +0 -344
- package/src/memory.integration.test.ts +0 -334
- package/src/memory.test.ts +0 -158
- package/src/memory.ts +0 -527
- package/src/model-selection.test.ts +0 -188
- package/src/model-selection.ts +0 -68
- package/src/observability-tools.test.ts +0 -359
- package/src/observability-tools.ts +0 -871
- package/src/output-guardrails.test.ts +0 -438
- package/src/output-guardrails.ts +0 -381
- package/src/pattern-maturity.test.ts +0 -1160
- package/src/pattern-maturity.ts +0 -525
- package/src/planning-guardrails.test.ts +0 -491
- package/src/planning-guardrails.ts +0 -438
- package/src/plugin.ts +0 -23
- package/src/post-compaction-tracker.test.ts +0 -251
- package/src/post-compaction-tracker.ts +0 -237
- package/src/query-tools.test.ts +0 -636
- package/src/query-tools.ts +0 -324
- package/src/rate-limiter.integration.test.ts +0 -466
- package/src/rate-limiter.ts +0 -774
- package/src/replay-tools.test.ts +0 -496
- package/src/replay-tools.ts +0 -240
- package/src/repo-crawl.integration.test.ts +0 -441
- package/src/repo-crawl.ts +0 -610
- package/src/schemas/cell-events.test.ts +0 -347
- package/src/schemas/cell-events.ts +0 -807
- package/src/schemas/cell.ts +0 -257
- package/src/schemas/evaluation.ts +0 -166
- package/src/schemas/index.test.ts +0 -199
- package/src/schemas/index.ts +0 -286
- package/src/schemas/mandate.ts +0 -232
- package/src/schemas/swarm-context.ts +0 -115
- package/src/schemas/task.ts +0 -161
- package/src/schemas/worker-handoff.test.ts +0 -302
- package/src/schemas/worker-handoff.ts +0 -131
- package/src/skills.integration.test.ts +0 -1192
- package/src/skills.test.ts +0 -643
- package/src/skills.ts +0 -1549
- package/src/storage.integration.test.ts +0 -341
- package/src/storage.ts +0 -884
- package/src/structured.integration.test.ts +0 -817
- package/src/structured.test.ts +0 -1046
- package/src/structured.ts +0 -762
- package/src/swarm-decompose.test.ts +0 -188
- package/src/swarm-decompose.ts +0 -1302
- package/src/swarm-deferred.integration.test.ts +0 -157
- package/src/swarm-deferred.test.ts +0 -38
- package/src/swarm-insights.test.ts +0 -214
- package/src/swarm-insights.ts +0 -459
- package/src/swarm-mail.integration.test.ts +0 -970
- package/src/swarm-mail.ts +0 -739
- package/src/swarm-orchestrate.integration.test.ts +0 -282
- package/src/swarm-orchestrate.test.ts +0 -548
- package/src/swarm-orchestrate.ts +0 -3084
- package/src/swarm-prompts.test.ts +0 -1270
- package/src/swarm-prompts.ts +0 -2077
- package/src/swarm-research.integration.test.ts +0 -701
- package/src/swarm-research.test.ts +0 -698
- package/src/swarm-research.ts +0 -472
- package/src/swarm-review.integration.test.ts +0 -285
- package/src/swarm-review.test.ts +0 -879
- package/src/swarm-review.ts +0 -709
- package/src/swarm-strategies.ts +0 -407
- package/src/swarm-worktree.test.ts +0 -501
- package/src/swarm-worktree.ts +0 -575
- package/src/swarm.integration.test.ts +0 -2377
- package/src/swarm.ts +0 -38
- package/src/tool-adapter.integration.test.ts +0 -1221
- package/src/tool-availability.ts +0 -461
- package/tsconfig.json +0 -28
package/src/skills.test.ts
DELETED
|
@@ -1,643 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for skills.ts
|
|
3
|
-
*
|
|
4
|
-
* Tests core functionality:
|
|
5
|
-
* - Frontmatter parsing
|
|
6
|
-
* - Path traversal protection
|
|
7
|
-
* - Skill discovery
|
|
8
|
-
* - ES module compatibility
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { describe, expect, it, beforeEach, afterEach, vi } from "vitest";
|
|
12
|
-
import { join, resolve, relative } from "path";
|
|
13
|
-
import { mkdirSync, writeFileSync, rmSync, existsSync } from "fs";
|
|
14
|
-
import {
|
|
15
|
-
parseFrontmatter,
|
|
16
|
-
discoverSkills,
|
|
17
|
-
getSkill,
|
|
18
|
-
listSkills,
|
|
19
|
-
setSkillsProjectDirectory,
|
|
20
|
-
invalidateSkillsCache,
|
|
21
|
-
type Skill,
|
|
22
|
-
type SkillRef,
|
|
23
|
-
} from "./skills";
|
|
24
|
-
|
|
25
|
-
// ============================================================================
|
|
26
|
-
// Test Fixtures
|
|
27
|
-
// ============================================================================
|
|
28
|
-
|
|
29
|
-
// Use unique temp dir per test run to avoid collisions
|
|
30
|
-
const TEST_RUN_ID = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
31
|
-
const TEST_DIR = join(process.cwd(), `.test-skills-${TEST_RUN_ID}`);
|
|
32
|
-
const SKILLS_DIR = join(TEST_DIR, ".opencode", "skills");
|
|
33
|
-
|
|
34
|
-
const VALID_SKILL_MD = `---
|
|
35
|
-
name: test-skill
|
|
36
|
-
description: A test skill for unit testing
|
|
37
|
-
tags:
|
|
38
|
-
- testing
|
|
39
|
-
- unit-test
|
|
40
|
-
tools:
|
|
41
|
-
- Read
|
|
42
|
-
- Write
|
|
43
|
-
---
|
|
44
|
-
|
|
45
|
-
# Test Skill
|
|
46
|
-
|
|
47
|
-
This is a test skill for unit testing purposes.
|
|
48
|
-
|
|
49
|
-
## Instructions
|
|
50
|
-
|
|
51
|
-
1. Do the thing
|
|
52
|
-
2. Verify the thing
|
|
53
|
-
`;
|
|
54
|
-
|
|
55
|
-
const MINIMAL_SKILL_MD = `---
|
|
56
|
-
name: minimal-skill
|
|
57
|
-
description: Minimal skill with only required fields
|
|
58
|
-
---
|
|
59
|
-
|
|
60
|
-
# Minimal Skill
|
|
61
|
-
|
|
62
|
-
Just the basics.
|
|
63
|
-
`;
|
|
64
|
-
|
|
65
|
-
const INVALID_FRONTMATTER_MD = `---
|
|
66
|
-
name:
|
|
67
|
-
description: Missing name value
|
|
68
|
-
---
|
|
69
|
-
|
|
70
|
-
# Invalid
|
|
71
|
-
|
|
72
|
-
This has invalid frontmatter.
|
|
73
|
-
`;
|
|
74
|
-
|
|
75
|
-
const NO_FRONTMATTER_MD = `# No Frontmatter
|
|
76
|
-
|
|
77
|
-
This file has no YAML frontmatter at all.
|
|
78
|
-
`;
|
|
79
|
-
|
|
80
|
-
// ============================================================================
|
|
81
|
-
// Setup / Teardown
|
|
82
|
-
// ============================================================================
|
|
83
|
-
|
|
84
|
-
function setupTestSkillsDir() {
|
|
85
|
-
// Create test directory structure
|
|
86
|
-
mkdirSync(SKILLS_DIR, { recursive: true });
|
|
87
|
-
mkdirSync(join(SKILLS_DIR, "test-skill"), { recursive: true });
|
|
88
|
-
mkdirSync(join(SKILLS_DIR, "minimal-skill"), { recursive: true });
|
|
89
|
-
mkdirSync(join(SKILLS_DIR, "invalid-skill"), { recursive: true });
|
|
90
|
-
|
|
91
|
-
// Write test skill files
|
|
92
|
-
writeFileSync(join(SKILLS_DIR, "test-skill", "SKILL.md"), VALID_SKILL_MD);
|
|
93
|
-
writeFileSync(
|
|
94
|
-
join(SKILLS_DIR, "minimal-skill", "SKILL.md"),
|
|
95
|
-
MINIMAL_SKILL_MD,
|
|
96
|
-
);
|
|
97
|
-
writeFileSync(
|
|
98
|
-
join(SKILLS_DIR, "invalid-skill", "SKILL.md"),
|
|
99
|
-
INVALID_FRONTMATTER_MD,
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function cleanupTestSkillsDir() {
|
|
104
|
-
if (existsSync(TEST_DIR)) {
|
|
105
|
-
rmSync(TEST_DIR, { recursive: true, force: true });
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// ============================================================================
|
|
110
|
-
// Tests: parseFrontmatter
|
|
111
|
-
// ============================================================================
|
|
112
|
-
|
|
113
|
-
describe("parseFrontmatter", () => {
|
|
114
|
-
it("parses valid frontmatter with all fields", () => {
|
|
115
|
-
const result = parseFrontmatter(VALID_SKILL_MD);
|
|
116
|
-
|
|
117
|
-
expect(result).not.toBeNull();
|
|
118
|
-
expect(result.metadata.name).toBe("test-skill");
|
|
119
|
-
expect(result.metadata.description).toBe("A test skill for unit testing");
|
|
120
|
-
expect(result.metadata.tags).toEqual(["testing", "unit-test"]);
|
|
121
|
-
expect(result.metadata.tools).toEqual(["Read", "Write"]);
|
|
122
|
-
expect(result.body).toContain("# Test Skill");
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it("parses minimal frontmatter with only required fields", () => {
|
|
126
|
-
const result = parseFrontmatter(MINIMAL_SKILL_MD);
|
|
127
|
-
|
|
128
|
-
expect(result).not.toBeNull();
|
|
129
|
-
expect(result.metadata.name).toBe("minimal-skill");
|
|
130
|
-
expect(result.metadata.description).toBe(
|
|
131
|
-
"Minimal skill with only required fields",
|
|
132
|
-
);
|
|
133
|
-
expect(result.metadata.tags).toBeUndefined();
|
|
134
|
-
expect(result.metadata.tools).toBeUndefined();
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it("returns null for missing name value", () => {
|
|
138
|
-
const result = parseFrontmatter(INVALID_FRONTMATTER_MD);
|
|
139
|
-
// gray-matter/YAML parses "name: " (empty value) as null
|
|
140
|
-
// Validation happens later in loadSkill
|
|
141
|
-
expect(result.metadata.name).toBeNull();
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("returns empty result for content without frontmatter", () => {
|
|
145
|
-
const result = parseFrontmatter(NO_FRONTMATTER_MD);
|
|
146
|
-
// No frontmatter means empty metadata
|
|
147
|
-
expect(Object.keys(result.metadata).length).toBe(0);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it("returns empty result for empty content", () => {
|
|
151
|
-
const result = parseFrontmatter("");
|
|
152
|
-
expect(Object.keys(result.metadata).length).toBe(0);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("handles frontmatter with extra fields", () => {
|
|
156
|
-
const content = `---
|
|
157
|
-
name: extra-fields
|
|
158
|
-
description: Has extra fields
|
|
159
|
-
custom_field: should be preserved
|
|
160
|
-
another: also preserved
|
|
161
|
-
---
|
|
162
|
-
|
|
163
|
-
Body content.
|
|
164
|
-
`;
|
|
165
|
-
const result = parseFrontmatter(content);
|
|
166
|
-
expect(result.metadata.name).toBe("extra-fields");
|
|
167
|
-
expect(result.metadata.custom_field).toBe("should be preserved");
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it("handles multiline description", () => {
|
|
171
|
-
// Note: The simple YAML parser doesn't handle | multiline syntax
|
|
172
|
-
// Use inline multiline instead
|
|
173
|
-
const content = `---
|
|
174
|
-
name: multiline
|
|
175
|
-
description: This is a description
|
|
176
|
-
---
|
|
177
|
-
|
|
178
|
-
Body.
|
|
179
|
-
`;
|
|
180
|
-
const result = parseFrontmatter(content);
|
|
181
|
-
expect(result.metadata.name).toBe("multiline");
|
|
182
|
-
expect(result.metadata.description).toBe("This is a description");
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
// ============================================================================
|
|
187
|
-
// Tests: Skill Discovery
|
|
188
|
-
// ============================================================================
|
|
189
|
-
|
|
190
|
-
describe("discoverSkills", () => {
|
|
191
|
-
beforeEach(() => {
|
|
192
|
-
cleanupTestSkillsDir();
|
|
193
|
-
setupTestSkillsDir();
|
|
194
|
-
setSkillsProjectDirectory(TEST_DIR);
|
|
195
|
-
invalidateSkillsCache();
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
afterEach(() => {
|
|
199
|
-
cleanupTestSkillsDir();
|
|
200
|
-
invalidateSkillsCache();
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
it("discovers skills in project directory", async () => {
|
|
204
|
-
const skills = await discoverSkills();
|
|
205
|
-
|
|
206
|
-
// discoverSkills returns a Map<string, Skill>
|
|
207
|
-
expect(skills.has("test-skill")).toBe(true);
|
|
208
|
-
expect(skills.has("minimal-skill")).toBe(true);
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
it("skips skills with invalid frontmatter", async () => {
|
|
212
|
-
const skills = await discoverSkills();
|
|
213
|
-
|
|
214
|
-
// invalid-skill has empty name, should be skipped
|
|
215
|
-
expect(skills.has("invalid-skill")).toBe(false);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it("caches discovered skills", async () => {
|
|
219
|
-
const skills1 = await discoverSkills();
|
|
220
|
-
const skills2 = await discoverSkills();
|
|
221
|
-
|
|
222
|
-
// Should return same cached Map
|
|
223
|
-
expect(skills1).toBe(skills2);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it("invalidates cache when requested", async () => {
|
|
227
|
-
const skills1 = await discoverSkills();
|
|
228
|
-
invalidateSkillsCache();
|
|
229
|
-
const skills2 = await discoverSkills();
|
|
230
|
-
|
|
231
|
-
// Should be different Map instances after cache invalidation
|
|
232
|
-
expect(skills1).not.toBe(skills2);
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
describe("getSkill", () => {
|
|
237
|
-
beforeEach(() => {
|
|
238
|
-
cleanupTestSkillsDir();
|
|
239
|
-
setupTestSkillsDir();
|
|
240
|
-
setSkillsProjectDirectory(TEST_DIR);
|
|
241
|
-
invalidateSkillsCache();
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
afterEach(() => {
|
|
245
|
-
cleanupTestSkillsDir();
|
|
246
|
-
invalidateSkillsCache();
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
it("returns skill by exact name", async () => {
|
|
250
|
-
const skill = await getSkill("test-skill");
|
|
251
|
-
|
|
252
|
-
expect(skill).not.toBeNull();
|
|
253
|
-
expect(skill!.metadata.name).toBe("test-skill");
|
|
254
|
-
expect(skill!.metadata.description).toBe("A test skill for unit testing");
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it("returns null for non-existent skill", async () => {
|
|
258
|
-
const skill = await getSkill("non-existent-skill");
|
|
259
|
-
expect(skill).toBeNull();
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
it("returns null for empty name", async () => {
|
|
263
|
-
const skill = await getSkill("");
|
|
264
|
-
expect(skill).toBeNull();
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
describe("listSkills", () => {
|
|
269
|
-
beforeEach(() => {
|
|
270
|
-
cleanupTestSkillsDir();
|
|
271
|
-
setupTestSkillsDir();
|
|
272
|
-
setSkillsProjectDirectory(TEST_DIR);
|
|
273
|
-
invalidateSkillsCache();
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
afterEach(() => {
|
|
277
|
-
cleanupTestSkillsDir();
|
|
278
|
-
invalidateSkillsCache();
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
it("returns skill refs with name, description, and path", async () => {
|
|
282
|
-
const refs = await listSkills();
|
|
283
|
-
|
|
284
|
-
const testSkillRef = refs.find((r) => r.name === "test-skill");
|
|
285
|
-
expect(testSkillRef).toBeDefined();
|
|
286
|
-
expect(testSkillRef!.description).toBe("A test skill for unit testing");
|
|
287
|
-
expect(testSkillRef!.path).toContain("test-skill");
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
// ============================================================================
|
|
292
|
-
// Tests: Path Traversal Protection
|
|
293
|
-
// ============================================================================
|
|
294
|
-
|
|
295
|
-
describe("path traversal protection", () => {
|
|
296
|
-
it("detects basic path traversal attempts", () => {
|
|
297
|
-
const maliciousPaths = [
|
|
298
|
-
"../../../etc/passwd",
|
|
299
|
-
"..\\..\\windows\\system32",
|
|
300
|
-
"foo/../../../bar",
|
|
301
|
-
"/etc/passwd",
|
|
302
|
-
"C:\\Windows\\System32",
|
|
303
|
-
];
|
|
304
|
-
|
|
305
|
-
for (const path of maliciousPaths) {
|
|
306
|
-
// These should be caught by the initial check
|
|
307
|
-
const hasTraversal =
|
|
308
|
-
path.includes("..") || path.startsWith("/") || path.includes(":\\");
|
|
309
|
-
expect(hasTraversal).toBe(true);
|
|
310
|
-
}
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
it("allows valid relative paths", () => {
|
|
314
|
-
const validPaths = [
|
|
315
|
-
"examples.md",
|
|
316
|
-
"templates/component.tsx",
|
|
317
|
-
"reference/api.md",
|
|
318
|
-
"scripts/setup.sh",
|
|
319
|
-
];
|
|
320
|
-
|
|
321
|
-
for (const path of validPaths) {
|
|
322
|
-
const hasTraversal = path.includes("..") || path.startsWith("/");
|
|
323
|
-
expect(hasTraversal).toBe(false);
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
it("resolve + relative check catches encoded traversal", () => {
|
|
328
|
-
// Even if initial check is bypassed, resolve + relative catches it
|
|
329
|
-
const skillDir = "/home/user/skills/my-skill";
|
|
330
|
-
const maliciousFile = "foo/../../etc/passwd";
|
|
331
|
-
|
|
332
|
-
const resolved = resolve(skillDir, maliciousFile);
|
|
333
|
-
const rel = relative(skillDir, resolved);
|
|
334
|
-
|
|
335
|
-
// The relative path starts with ".." meaning it escapes
|
|
336
|
-
expect(rel.startsWith("..")).toBe(true);
|
|
337
|
-
});
|
|
338
|
-
});
|
|
339
|
-
|
|
340
|
-
// ============================================================================
|
|
341
|
-
// Tests: ES Module Compatibility
|
|
342
|
-
// ============================================================================
|
|
343
|
-
|
|
344
|
-
describe("ES module compatibility", () => {
|
|
345
|
-
it("import.meta.url is available", () => {
|
|
346
|
-
// This test verifies we're running in an ES module context
|
|
347
|
-
expect(import.meta.url).toBeDefined();
|
|
348
|
-
// Check for file protocol and skills.test in path (works across runners)
|
|
349
|
-
expect(import.meta.url).toMatch(/skills\.test/);
|
|
350
|
-
expect(import.meta.url).toMatch(/^file:|^bun:|^\//); // file://, bun://, or absolute path
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
it("can construct path from import.meta.url", () => {
|
|
354
|
-
const currentDir = new URL(".", import.meta.url).pathname;
|
|
355
|
-
expect(currentDir).toBeDefined();
|
|
356
|
-
expect(currentDir.endsWith("/")).toBe(true);
|
|
357
|
-
});
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
// ============================================================================
|
|
361
|
-
// Tests: CSO Validation
|
|
362
|
-
// ============================================================================
|
|
363
|
-
|
|
364
|
-
import { validateCSOCompliance } from "./skills";
|
|
365
|
-
|
|
366
|
-
describe("validateCSOCompliance", () => {
|
|
367
|
-
describe("description validation", () => {
|
|
368
|
-
it("passes for CSO-compliant description with 'Use when'", () => {
|
|
369
|
-
const warnings = validateCSOCompliance(
|
|
370
|
-
"testing-async",
|
|
371
|
-
"Use when tests have race conditions - replaces arbitrary timeouts with condition polling",
|
|
372
|
-
);
|
|
373
|
-
|
|
374
|
-
expect(warnings.critical).toHaveLength(0);
|
|
375
|
-
expect(warnings.suggestions).toHaveLength(0);
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
it("warns when missing 'Use when...' pattern", () => {
|
|
379
|
-
const warnings = validateCSOCompliance(
|
|
380
|
-
"testing-async",
|
|
381
|
-
"For async testing patterns",
|
|
382
|
-
);
|
|
383
|
-
|
|
384
|
-
expect(warnings.critical).toContain(
|
|
385
|
-
"Description should include 'Use when...' to focus on triggering conditions",
|
|
386
|
-
);
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
it("warns for first-person voice", () => {
|
|
390
|
-
const warnings = validateCSOCompliance(
|
|
391
|
-
"testing-async",
|
|
392
|
-
"I can help you with async tests when I detect race conditions",
|
|
393
|
-
);
|
|
394
|
-
|
|
395
|
-
expect(warnings.critical.some((w) => w.includes("first-person"))).toBe(
|
|
396
|
-
true,
|
|
397
|
-
);
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
it("warns for second-person voice", () => {
|
|
401
|
-
const warnings = validateCSOCompliance(
|
|
402
|
-
"testing-async",
|
|
403
|
-
"Use when you need to test async code and your tests have race conditions",
|
|
404
|
-
);
|
|
405
|
-
|
|
406
|
-
expect(warnings.critical.some((w) => w.includes("second-person"))).toBe(
|
|
407
|
-
true,
|
|
408
|
-
);
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
it("rejects description > 1024 chars", () => {
|
|
412
|
-
const longDesc = "a".repeat(1025);
|
|
413
|
-
const warnings = validateCSOCompliance("test", longDesc);
|
|
414
|
-
|
|
415
|
-
expect(
|
|
416
|
-
warnings.critical.some(
|
|
417
|
-
(w) => w.includes("1025") && w.includes("max 1024"),
|
|
418
|
-
),
|
|
419
|
-
).toBe(true);
|
|
420
|
-
});
|
|
421
|
-
|
|
422
|
-
it("suggests improvement for description > 500 chars", () => {
|
|
423
|
-
const mediumDesc = "Use when testing. " + "a".repeat(490);
|
|
424
|
-
const warnings = validateCSOCompliance("test", mediumDesc);
|
|
425
|
-
|
|
426
|
-
expect(warnings.critical).toHaveLength(0); // Not critical
|
|
427
|
-
expect(warnings.suggestions.some((w) => w.includes("aim for <500"))).toBe(
|
|
428
|
-
true,
|
|
429
|
-
);
|
|
430
|
-
});
|
|
431
|
-
|
|
432
|
-
it("accepts description < 500 chars with no length warnings", () => {
|
|
433
|
-
const shortDesc =
|
|
434
|
-
"Use when tests have race conditions - replaces timeouts";
|
|
435
|
-
const warnings = validateCSOCompliance("testing-async", shortDesc);
|
|
436
|
-
|
|
437
|
-
const hasLengthWarning =
|
|
438
|
-
warnings.critical.some((w) => w.includes("chars")) ||
|
|
439
|
-
warnings.suggestions.some((w) => w.includes("chars"));
|
|
440
|
-
|
|
441
|
-
expect(hasLengthWarning).toBe(false);
|
|
442
|
-
});
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
describe("name validation", () => {
|
|
446
|
-
it("accepts gerund-based names", () => {
|
|
447
|
-
const warnings = validateCSOCompliance(
|
|
448
|
-
"testing-async",
|
|
449
|
-
"Use when testing async code",
|
|
450
|
-
);
|
|
451
|
-
|
|
452
|
-
const hasNameWarning = warnings.suggestions.some((w) =>
|
|
453
|
-
w.includes("verb-first"),
|
|
454
|
-
);
|
|
455
|
-
expect(hasNameWarning).toBe(false);
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
it("accepts verb-first names", () => {
|
|
459
|
-
const warnings = validateCSOCompliance(
|
|
460
|
-
"validate-schemas",
|
|
461
|
-
"Use when validating schemas",
|
|
462
|
-
);
|
|
463
|
-
|
|
464
|
-
const hasNameWarning = warnings.suggestions.some((w) =>
|
|
465
|
-
w.includes("verb-first"),
|
|
466
|
-
);
|
|
467
|
-
expect(hasNameWarning).toBe(false);
|
|
468
|
-
});
|
|
469
|
-
|
|
470
|
-
it("accepts action verbs", () => {
|
|
471
|
-
const actionVerbs = [
|
|
472
|
-
"test-runner",
|
|
473
|
-
"debug-tools",
|
|
474
|
-
"scan-code",
|
|
475
|
-
"check-types",
|
|
476
|
-
"build-artifacts",
|
|
477
|
-
];
|
|
478
|
-
|
|
479
|
-
for (const name of actionVerbs) {
|
|
480
|
-
const warnings = validateCSOCompliance(name, "Use when testing");
|
|
481
|
-
const hasNameWarning = warnings.suggestions.some((w) =>
|
|
482
|
-
w.includes("verb-first"),
|
|
483
|
-
);
|
|
484
|
-
expect(hasNameWarning).toBe(false);
|
|
485
|
-
}
|
|
486
|
-
});
|
|
487
|
-
|
|
488
|
-
it("suggests verb-first for noun-first names", () => {
|
|
489
|
-
const warnings = validateCSOCompliance(
|
|
490
|
-
"async-test",
|
|
491
|
-
"Use when testing async",
|
|
492
|
-
);
|
|
493
|
-
|
|
494
|
-
expect(
|
|
495
|
-
warnings.suggestions.some((w) =>
|
|
496
|
-
w.includes("doesn't follow verb-first"),
|
|
497
|
-
),
|
|
498
|
-
).toBe(true);
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
it("warns for name > 64 chars", () => {
|
|
502
|
-
const longName = "a".repeat(65);
|
|
503
|
-
const warnings = validateCSOCompliance(longName, "Use when testing");
|
|
504
|
-
|
|
505
|
-
expect(warnings.critical.some((w) => w.includes("64 character"))).toBe(
|
|
506
|
-
true,
|
|
507
|
-
);
|
|
508
|
-
});
|
|
509
|
-
|
|
510
|
-
it("warns for invalid name format", () => {
|
|
511
|
-
const warnings = validateCSOCompliance(
|
|
512
|
-
"Invalid_Name",
|
|
513
|
-
"Use when testing",
|
|
514
|
-
);
|
|
515
|
-
|
|
516
|
-
expect(
|
|
517
|
-
warnings.critical.some((w) =>
|
|
518
|
-
w.includes("lowercase letters, numbers, and hyphens"),
|
|
519
|
-
),
|
|
520
|
-
).toBe(true);
|
|
521
|
-
});
|
|
522
|
-
});
|
|
523
|
-
|
|
524
|
-
describe("comprehensive examples", () => {
|
|
525
|
-
it("perfect CSO compliance", () => {
|
|
526
|
-
const warnings = validateCSOCompliance(
|
|
527
|
-
"testing-race-conditions",
|
|
528
|
-
"Use when tests have race conditions - replaces arbitrary timeouts with condition polling and retry logic",
|
|
529
|
-
);
|
|
530
|
-
|
|
531
|
-
expect(warnings.critical).toHaveLength(0);
|
|
532
|
-
expect(warnings.suggestions).toHaveLength(0);
|
|
533
|
-
});
|
|
534
|
-
|
|
535
|
-
it("multiple critical issues", () => {
|
|
536
|
-
const warnings = validateCSOCompliance(
|
|
537
|
-
"BadName_123",
|
|
538
|
-
"I can help you test async code when you need to avoid race conditions. " +
|
|
539
|
-
"a".repeat(1000),
|
|
540
|
-
);
|
|
541
|
-
|
|
542
|
-
expect(warnings.critical.length).toBeGreaterThan(2);
|
|
543
|
-
expect(warnings.critical.some((w) => w.includes("first-person"))).toBe(
|
|
544
|
-
true,
|
|
545
|
-
);
|
|
546
|
-
expect(warnings.critical.some((w) => w.includes("second-person"))).toBe(
|
|
547
|
-
true,
|
|
548
|
-
);
|
|
549
|
-
expect(warnings.critical.some((w) => w.includes("lowercase"))).toBe(true);
|
|
550
|
-
});
|
|
551
|
-
});
|
|
552
|
-
});
|
|
553
|
-
|
|
554
|
-
// ============================================================================
|
|
555
|
-
// Tests: Deprecation Warnings
|
|
556
|
-
// ============================================================================
|
|
557
|
-
|
|
558
|
-
describe("deprecation warnings", () => {
|
|
559
|
-
beforeEach(() => {
|
|
560
|
-
cleanupTestSkillsDir();
|
|
561
|
-
setupTestSkillsDir();
|
|
562
|
-
setSkillsProjectDirectory(TEST_DIR);
|
|
563
|
-
invalidateSkillsCache();
|
|
564
|
-
});
|
|
565
|
-
|
|
566
|
-
afterEach(() => {
|
|
567
|
-
cleanupTestSkillsDir();
|
|
568
|
-
invalidateSkillsCache();
|
|
569
|
-
});
|
|
570
|
-
|
|
571
|
-
it("listSkills emits deprecation warning", async () => {
|
|
572
|
-
const warnSpy = vi.spyOn(console, "warn");
|
|
573
|
-
|
|
574
|
-
await listSkills();
|
|
575
|
-
|
|
576
|
-
// Verify warning was emitted (for listSkills internal function)
|
|
577
|
-
// The actual tool warning happens in skills_list tool execute
|
|
578
|
-
warnSpy.mockRestore();
|
|
579
|
-
});
|
|
580
|
-
|
|
581
|
-
it("getSkill does NOT emit deprecation warning (internal function)", async () => {
|
|
582
|
-
const warnSpy = vi.spyOn(console, "warn");
|
|
583
|
-
|
|
584
|
-
await getSkill("test-skill");
|
|
585
|
-
|
|
586
|
-
// getSkill is internal, should not have DEPRECATED warnings
|
|
587
|
-
const deprecationCalls = warnSpy.mock.calls.filter(call =>
|
|
588
|
-
call.some(arg => String(arg).includes("[DEPRECATED]"))
|
|
589
|
-
);
|
|
590
|
-
expect(deprecationCalls.length).toBe(0);
|
|
591
|
-
warnSpy.mockRestore();
|
|
592
|
-
});
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
// ============================================================================
|
|
596
|
-
// Tests: Edge Cases
|
|
597
|
-
// ============================================================================
|
|
598
|
-
|
|
599
|
-
describe("edge cases", () => {
|
|
600
|
-
beforeEach(() => {
|
|
601
|
-
cleanupTestSkillsDir();
|
|
602
|
-
invalidateSkillsCache();
|
|
603
|
-
});
|
|
604
|
-
|
|
605
|
-
afterEach(() => {
|
|
606
|
-
cleanupTestSkillsDir();
|
|
607
|
-
invalidateSkillsCache();
|
|
608
|
-
});
|
|
609
|
-
|
|
610
|
-
it("handles non-existent skills directory gracefully", async () => {
|
|
611
|
-
setSkillsProjectDirectory("/non/existent/path");
|
|
612
|
-
invalidateSkillsCache();
|
|
613
|
-
|
|
614
|
-
// Should not throw, just return empty or global skills only
|
|
615
|
-
const skills = await discoverSkills();
|
|
616
|
-
expect(skills instanceof Map).toBe(true);
|
|
617
|
-
});
|
|
618
|
-
|
|
619
|
-
it("handles empty skills directory", async () => {
|
|
620
|
-
mkdirSync(SKILLS_DIR, { recursive: true });
|
|
621
|
-
setSkillsProjectDirectory(TEST_DIR);
|
|
622
|
-
invalidateSkillsCache();
|
|
623
|
-
|
|
624
|
-
// Should not throw
|
|
625
|
-
const skills = await discoverSkills();
|
|
626
|
-
expect(skills instanceof Map).toBe(true);
|
|
627
|
-
});
|
|
628
|
-
|
|
629
|
-
it("handles skill directory without SKILL.md", async () => {
|
|
630
|
-
mkdirSync(join(SKILLS_DIR, "empty-skill"), { recursive: true });
|
|
631
|
-
writeFileSync(
|
|
632
|
-
join(SKILLS_DIR, "empty-skill", "README.md"),
|
|
633
|
-
"# Not a skill",
|
|
634
|
-
);
|
|
635
|
-
setSkillsProjectDirectory(TEST_DIR);
|
|
636
|
-
invalidateSkillsCache();
|
|
637
|
-
|
|
638
|
-
const skills = await discoverSkills();
|
|
639
|
-
|
|
640
|
-
// Should not include the directory without SKILL.md
|
|
641
|
-
expect(skills.has("empty-skill")).toBe(false);
|
|
642
|
-
});
|
|
643
|
-
});
|