refactor(package): publish skvlt cli

This commit is contained in:
xixu-me committed 2026-03-25 12:12:25 +08:00
commit 32545773c9
22 files changed
+2548

No files matched your search

+105
View File
@@ -0,0 +1,105 @@
import { expect, test } from "bun:test";
import { runBackup } from "../src/commands/backup";
import { parseBackupArgs } from "../src/internal/args/parse-backup-args";
import { buildManifest } from "../src/internal/manifest/build-manifest";
import { defaultGlobalLockFilePath } from "../src/internal/paths/defaults";
test("rejects flag-like values for backup paths", () => {
expect(() => parseBackupArgs(["--output", "--dry-run"])).toThrow(
"--output requires a path",
);
expect(() => parseBackupArgs(["--lock-file", "--dry-run"])).toThrow(
"--lock-file requires a path",
);
});
test("treats an explicit default lock file as provided", () => {
const options = parseBackupArgs([
"--project-scope",
"--lock-file",
defaultGlobalLockFilePath,
]);
expect(options.lockFilePath).toBe(defaultGlobalLockFilePath);
expect(options.lockFileProvided).toBe(true);
});
test("prints deterministic manifest YAML during backup dry-run", async () => {
let writeCalls = 0;
const result = await runBackup(["--dry-run"], {
getInstalledSkillNames: async () => ["zulu", "alpha", "beta"],
readLockFile: () => ({
skills: {
alpha: { source: "beta/source" },
beta: { source: "alpha/source" },
zulu: { source: "beta/source" },
},
}),
writeManifest: () => {
writeCalls += 1;
},
});
expect(result.exitCode).toBe(0);
expect(writeCalls).toBe(0);
expect(result.stdout).toBe(
[
"total_sources: 2",
"total_skills: 3",
"",
"sources:",
" 'alpha/source':",
" count: 1",
" skills:",
" - 'beta'",
"",
" 'beta/source':",
" count: 2",
" skills:",
" - 'alpha'",
" - 'zulu'",
"",
].join("\n") + "\n",
);
});
test("shows help before project-scope validation", async () => {
const result = await runBackup(["--help", "--project-scope"]);
expect(result.exitCode).toBe(0);
expect(result.stdout).toContain("Usage:");
});
test("builds a grouped manifest with stable source and skill ordering", () => {
const manifest = buildManifest(
["zulu", "alpha", "beta"],
{
skills: {
alpha: { source: "beta/source" },
beta: { source: "alpha/source" },
zulu: { source: "beta/source" },
},
},
);
expect(manifest.totalSources).toBe(2);
expect(manifest.totalSkills).toBe(3);
expect(manifest.yaml).toBe(
[
"total_sources: 2",
"total_skills: 3",
"",
"sources:",
" 'alpha/source':",
" count: 1",
" skills:",
" - 'beta'",
"",
" 'beta/source':",
" count: 2",
" skills:",
" - 'alpha'",
" - 'zulu'",
"",
].join("\n") + "\n",
);
});