Skip to content

Commit 48fa80f

Browse files
committed
chore: add unit tests
Signed-off-by: kyteinsky <kyteinsky@gmail.com> Assisted-by: Github Copilot: claude-sonnet-4-6
1 parent cc31109 commit 48fa80f

2 files changed

Lines changed: 430 additions & 4 deletions

File tree

lib/Service/AgentSkillsService.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class AgentSkillsService {
2727

2828
public const GLOBAL_SKILLS_ADMIN_UID_KEY = 'global_skills_admin_uid';
2929
public const GLOBAL_SKILLS_PATH_KEY = 'global_skills_path';
30+
public const SKILLS_FOLDER_PATH = 'Context Agent/Skills';
3031

31-
private const SKILLS_FOLDER_PATH = 'Context Agent/Skills';
3232
private const SKILL_FILE_NAME = 'SKILL.md';
3333
private const FRONTMATTER_DELIMITER = '---';
3434
private const CACHE_PREFIX = 'assistant_skills';
@@ -150,7 +150,7 @@ private function getSkillMetadata(string $cacheKey, File $skillFile): array {
150150
* @return array{name: string, description: string}
151151
* @throws RuntimeException if the YAML is invalid or any required field is missing
152152
*/
153-
private function parseMetadataFields(string $frontmatter, string $filePath): array {
153+
public function parseMetadataFields(string $frontmatter, string $filePath): array {
154154
try {
155155
$parsed = Yaml::parse($frontmatter);
156156
} catch (ParseException $e) {
@@ -193,7 +193,10 @@ private function parseMetadataFields(string $frontmatter, string $filePath): arr
193193
*/
194194
public function storeSkill(string $userId, string $skillName, string $description, string $content): string {
195195
if ($skillName === '' || str_contains($skillName, '/')) {
196-
throw new \InvalidArgumentException('Invalid skill name: ' . $skillName);
196+
throw new \InvalidArgumentException('Invalid skill name: ' . ($skillName ?: '(empty string)'));
197+
}
198+
if ($description === '') {
199+
throw new \InvalidArgumentException('Skill description must not be empty');
197200
}
198201

199202
$skillsFolder = $this->getSkillsFolder($userId);
@@ -292,7 +295,7 @@ private function loadSkillFromFolder(Folder $folder, string $skillName): string
292295
* @throws \OCP\Files\GenericFileException if reading the file fails
293296
* @throws \OCP\Lock\LockedException if the file is locked
294297
*/
295-
private function extractFrontmatter(File $file): string {
298+
public function extractFrontmatter(File $file): string {
296299
$content = $file->getContent();
297300
$delimiter = self::FRONTMATTER_DELIMITER;
298301

0 commit comments

Comments
 (0)