refactor(test): reuse shared skill writer in skills e2e

This commit is contained in:
Peter Steinberger
2026-02-21 18:55:54 +00:00
parent f086245afe
commit 0876fbde19
2 changed files with 12 additions and 32 deletions

View File

@@ -7,15 +7,21 @@ export async function writeSkill(params: {
description: string;
metadata?: string;
body?: string;
frontmatterExtra?: string;
}) {
const { dir, name, description, metadata, body } = params;
const { dir, name, description, metadata, body, frontmatterExtra } = params;
await fs.mkdir(dir, { recursive: true });
const frontmatter = [
`name: ${name}`,
`description: ${description}`,
metadata ? `metadata: ${metadata}` : "",
frontmatterExtra ?? "",
]
.filter((line) => line.trim().length > 0)
.join("\n");
await fs.writeFile(
path.join(dir, "SKILL.md"),
`---
name: ${name}
description: ${description}${metadata ? `\nmetadata: ${metadata}` : ""}
---
`---\n${frontmatter}\n---
${body ?? `# ${name}\n`}
`,

View File

@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import { writeSkill } from "./skills.e2e-test-helpers.js";
import {
applySkillEnvOverrides,
applySkillEnvOverridesFromSnapshot,
@@ -11,15 +12,6 @@ import {
loadWorkspaceSkillEntries,
} from "./skills.js";
type SkillFixture = {
dir: string;
name: string;
description: string;
metadata?: string;
body?: string;
frontmatterExtra?: string;
};
const tempDirs: string[] = [];
const makeWorkspace = async () => {
@@ -28,24 +20,6 @@ const makeWorkspace = async () => {
return workspaceDir;
};
const writeSkill = async (params: SkillFixture) => {
const { dir, name, description, metadata, body, frontmatterExtra } = params;
await fs.mkdir(dir, { recursive: true });
const frontmatter = [
`name: ${name}`,
`description: ${description}`,
metadata ? `metadata: ${metadata}` : "",
frontmatterExtra ?? "",
]
.filter((line) => line.trim().length > 0)
.join("\n");
await fs.writeFile(
path.join(dir, "SKILL.md"),
`---\n${frontmatter}\n---\n\n${body ?? `# ${name}\n`}`,
"utf-8",
);
};
const withClearedEnv = <T>(
keys: string[],
run: (original: Record<string, string | undefined>) => T,