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; description: string;
metadata?: string; metadata?: string;
body?: 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 }); 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( await fs.writeFile(
path.join(dir, "SKILL.md"), path.join(dir, "SKILL.md"),
`--- `---\n${frontmatter}\n---
name: ${name}
description: ${description}${metadata ? `\nmetadata: ${metadata}` : ""}
---
${body ?? `# ${name}\n`} ${body ?? `# ${name}\n`}
`, `,

View File

@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
import os from "node:os"; import os from "node:os";
import path from "node:path"; import path from "node:path";
import { afterEach, describe, expect, it } from "vitest"; import { afterEach, describe, expect, it } from "vitest";
import { writeSkill } from "./skills.e2e-test-helpers.js";
import { import {
applySkillEnvOverrides, applySkillEnvOverrides,
applySkillEnvOverridesFromSnapshot, applySkillEnvOverridesFromSnapshot,
@@ -11,15 +12,6 @@ import {
loadWorkspaceSkillEntries, loadWorkspaceSkillEntries,
} from "./skills.js"; } from "./skills.js";
type SkillFixture = {
dir: string;
name: string;
description: string;
metadata?: string;
body?: string;
frontmatterExtra?: string;
};
const tempDirs: string[] = []; const tempDirs: string[] = [];
const makeWorkspace = async () => { const makeWorkspace = async () => {
@@ -28,24 +20,6 @@ const makeWorkspace = async () => {
return workspaceDir; 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>( const withClearedEnv = <T>(
keys: string[], keys: string[],
run: (original: Record<string, string | undefined>) => T, run: (original: Record<string, string | undefined>) => T,