Files
oh-my-pi/packages/coding-agent/test/sdk-skills.test.ts
T
can1357 51d39e7eea refactor(imports): migrated node module imports to namespace imports
- Converted named imports from node modules (fs, path, os) to namespace imports across all packages.
- Extended extension loader error handling with isEacces and hasFsCode type guards.
2026-01-24 03:37:59 +01:00

88 lines
2.6 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it } from "bun:test";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import type { Skill } from "@oh-my-pi/pi-coding-agent/sdk";
import { createAgentSession } from "@oh-my-pi/pi-coding-agent/sdk";
import { SessionManager } from "@oh-my-pi/pi-coding-agent/session/session-manager";
describe("createAgentSession skills option", () => {
let tempDir: string;
let skillsDir: string;
beforeEach(() => {
tempDir = path.join(os.tmpdir(), `pi-sdk-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
// Create skill in .omp/skills/ for native project-level discovery
skillsDir = path.join(tempDir, ".omp", "skills", "test-skill");
fs.mkdirSync(skillsDir, { recursive: true });
// Create a test skill in the pi skills directory
fs.writeFileSync(
path.join(skillsDir, "SKILL.md"),
`---
name: test-skill
description: A test skill for SDK tests.
---
# Test Skill
This is a test skill.
`,
);
});
afterEach(() => {
if (tempDir) {
fs.rmSync(tempDir, { recursive: true, force: true });
}
});
it("should discover skills by default and expose them on session.skills", async () => {
const { session } = await createAgentSession({
cwd: tempDir,
agentDir: tempDir,
sessionManager: SessionManager.inMemory(),
});
// Skills should be discovered and exposed on the session
expect(session.skills.length).toBeGreaterThan(0);
expect(session.skills.some((s: Skill) => s.name === "test-skill")).toBe(true);
});
it("should have empty skills when options.skills is empty array (--no-skills)", async () => {
const { session } = await createAgentSession({
cwd: tempDir,
agentDir: tempDir,
sessionManager: SessionManager.inMemory(),
skills: [], // Explicitly empty - like --no-skills
});
// session.skills should be empty
expect(session.skills).toEqual([]);
// No warnings since we didn't discover
expect(session.skillWarnings).toEqual([]);
});
it("should use provided skills when options.skills is explicitly set", async () => {
const customSkill: Skill = {
name: "custom-skill",
description: "A custom skill",
filePath: "/fake/path/SKILL.md",
baseDir: "/fake/path",
source: "custom" as const,
};
const { session } = await createAgentSession({
cwd: tempDir,
agentDir: tempDir,
sessionManager: SessionManager.inMemory(),
skills: [customSkill],
});
// session.skills should contain only the provided skill
expect(session.skills).toEqual([customSkill]);
// No warnings since we didn't discover
expect(session.skillWarnings).toEqual([]);
});
});