Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion apps/desktop/src/pages/harness/__tests__/SyncPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ function renderPage() {
describe("SyncPage", () => {
beforeEach(() => {
vi.clearAllMocks();
// clearAllMocks keeps queued mock*Once values; a test that fails before
// using its own would hand them to the next test. mockReset drops the
// queue and restores the factory implementation.
vi.mocked(compile).mockReset();
vi.mocked(detectPlatforms).mockReset();
projectHarness = 'version: "1"';
mockReadHarnessFile.mockResolvedValue({ found: false, content: null, path: null });
mockSyncFileExists.mockResolvedValue(false);
Expand Down Expand Up @@ -202,7 +207,9 @@ describe("SyncPage", () => {
);
const palette = () => within(screen.getByRole("dialog", { name: "Command palette" }));
await screen.findByText(/Directory found/i);
const preview = palette().getByRole("option", { name: "Preview compile changes" });
// SyncPage registers its commands in an effect, which can land after the
// directory check renders.
const preview = await palette().findByRole("option", { name: "Preview compile changes" });
await waitFor(() => expect(preview).not.toHaveAttribute("aria-disabled"));
expect(palette().queryByRole("option", { name: /Apply/ })).not.toBeInTheDocument();

Expand Down
57 changes: 57 additions & 0 deletions packages/core/__tests__/import-unreadable-skill.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { describe, it, expect } from "vitest";
import { importMachine } from "../src/import/import-project.js";
import { readAdapterSkills } from "../src/import/read-skills.js";
import { MockFsProvider } from "./helpers/mock-fs.js";

const HOME = "/home/user";
const BLOCKED = `${HOME}/.claude/skills/linked/SKILL.md`;

/**
* A reader that refuses one file the way Tauri's fs scope does for a symlinked
* SKILL.md whose target lies outside the capability scope.
*/
class OneForbiddenFile extends MockFsProvider {
async readFile(path: string): Promise<string> {
if (path === BLOCKED) {
throw new Error(`forbidden path: ${path}, maybe it is not allowed on the scope`);
}
return super.readFile(path);
}
}

function machine(): OneForbiddenFile {
return new OneForbiddenFile(
{
[`${HOME}/CLAUDE.md`]: "# Global instructions\n",
[`${HOME}/.claude/skills/alpha/SKILL.md`]: "---\nname: alpha\n---\nAlpha body\n",
[BLOCKED]: "---\nname: linked\n---\nUnreachable\n",
[`${HOME}/.claude/skills/zeta/SKILL.md`]: "---\nname: zeta\n---\nZeta body\n",
},
HOME,
HOME,
);
}

describe("machine scan with an unreadable skill file", () => {
it("keeps the readable skills and reports the unreadable one as skipped", async () => {
const fragment = await readAdapterSkills(machine(), HOME, "claude-code");

expect(fragment?.skills?.skills.map((skill) => skill.name)).toEqual(["alpha", "zeta"]);
expect(fragment?.skipped).toEqual([
{ file: ".claude/skills/linked/SKILL.md", reason: expect.stringContaining("forbidden path") },
]);
});

it("completes importMachine instead of rejecting, and surfaces the skip in findings", async () => {
const result = await importMachine({ fs: machine() });

const claudeCode = result.findings.adapters.find((adapter) => adapter.adapter === "claude-code")!;
expect(claudeCode.skipped).toContainEqual({
file: ".claude/skills/linked/SKILL.md",
reason: expect.stringContaining("forbidden path"),
});
expect(result.harnessYaml).toContain("alpha");
expect(result.harnessYaml).toContain("zeta");
expect(result.harnessYaml).not.toContain("linked");
});
});
28 changes: 22 additions & 6 deletions packages/core/src/import/read-skills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export async function readAdapterSkills(
adapter: AdapterId,
): Promise<ImportedFragment | null> {
const skills: ImportedSkillRef[] = [];
const skipped: Array<{ file: string; reason: string }> = [];
const seen = new Set<string>();
const personal = projectRoot === (await fs.homedir());
const directories = personal ? GLOBAL_SKILL_DIRS[adapter] : PROJECT_SKILL_DIRS[adapter];
Expand All @@ -76,11 +77,21 @@ export async function readAdapterSkills(
const root = fs.joinPath(projectRoot, directory);
if (!(await fs.exists(root))) continue;
for (const file of (await findSkillFiles(root, fs, 8)).sort()) {
const content = await fs.readFile(file);
const relative = relativeTo(projectRoot, file);
// One unreadable skill must not abort the scan. The desktop fs scope
// refuses a SKILL.md symlinked outside it ("forbidden path"), and a
// capsule over the size limits throws too; report the skill as skipped.
let content: string;
let directoryFiles: Awaited<ReturnType<typeof collectCapsuleFiles>>;
try {
content = await fs.readFile(file);
directoryFiles = await collectCapsuleFiles(fs, dirname(file));
} catch (error) {
const reason = error instanceof Error ? error.message : String(error);
skipped.push({ file: relative, reason: `could not read skill: ${reason}` });
continue;
}
const name = frontmatterName(content, dirname(relative).split("/").pop() ?? "skill");
const sourceRoot = dirname(file);
const directoryFiles = await collectCapsuleFiles(fs, sourceRoot);
const digest = skillDirectoryDigest(directoryFiles.map((entry) => ({
path: entry.path,
digest: computeFileHash(entry.content),
Expand All @@ -100,7 +111,12 @@ export async function readAdapterSkills(
}
}

return skills.length
? { domain: "skills", config: {}, warnings: [], skills: { skills } }
: null;
if (!skills.length && !skipped.length) return null;
return {
domain: "skills",
config: {},
warnings: [],
...(skills.length ? { skills: { skills } } : {}),
...(skipped.length ? { skipped } : {}),
};
}
Loading