akm-cli 0.6.1 → 0.7.0-rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -0
- package/dist/{cli.js → src/cli.js} +620 -26
- package/dist/{commands → src/commands}/config-cli.js +5 -4
- package/dist/src/commands/distill.js +283 -0
- package/dist/src/commands/events.js +108 -0
- package/dist/src/commands/history.js +120 -0
- package/dist/{commands → src/commands}/installed-stashes.js +1 -1
- package/dist/src/commands/proposal.js +119 -0
- package/dist/src/commands/propose.js +171 -0
- package/dist/src/commands/reflect.js +193 -0
- package/dist/{commands → src/commands}/registry-search.js +2 -1
- package/dist/{commands → src/commands}/remember.js +12 -0
- package/dist/{commands → src/commands}/search.js +74 -1
- package/dist/{commands → src/commands}/self-update.js +4 -3
- package/dist/{commands → src/commands}/show.js +44 -0
- package/dist/{core → src/core}/asset-ref.js +5 -5
- package/dist/{core → src/core}/asset-spec.js +12 -0
- package/dist/{core → src/core}/common.js +1 -1
- package/dist/{core → src/core}/config.js +175 -121
- package/dist/{core → src/core}/errors.js +4 -0
- package/dist/src/core/events.js +239 -0
- package/dist/src/core/lesson-lint.js +86 -0
- package/dist/src/core/proposals.js +406 -0
- package/dist/src/core/warn.js +72 -0
- package/dist/{core → src/core}/write-source.js +80 -5
- package/dist/{indexer → src/indexer}/db-search.js +113 -24
- package/dist/{indexer → src/indexer}/db.js +76 -23
- package/dist/{indexer → src/indexer}/file-context.js +0 -3
- package/dist/src/indexer/graph-boost.js +179 -0
- package/dist/src/indexer/graph-extraction.js +212 -0
- package/dist/{indexer → src/indexer}/indexer.js +73 -6
- package/dist/src/indexer/memory-inference.js +263 -0
- package/dist/{indexer → src/indexer}/metadata.js +111 -3
- package/dist/src/integrations/agent/config.js +292 -0
- package/dist/src/integrations/agent/detect.js +94 -0
- package/dist/src/integrations/agent/index.js +17 -0
- package/dist/src/integrations/agent/profiles.js +65 -0
- package/dist/src/integrations/agent/prompts.js +167 -0
- package/dist/src/integrations/agent/spawn.js +221 -0
- package/dist/{integrations → src/integrations}/lockfile.js +0 -26
- package/dist/{llm → src/llm}/client.js +33 -2
- package/dist/src/llm/feature-gate.js +108 -0
- package/dist/src/llm/graph-extract.js +107 -0
- package/dist/src/llm/index-passes.js +35 -0
- package/dist/src/llm/memory-infer.js +86 -0
- package/dist/{output → src/output}/renderers.js +60 -1
- package/dist/src/output/shapes.js +516 -0
- package/dist/{output → src/output}/text.js +447 -4
- package/dist/{registry → src/registry}/build-index.js +14 -4
- package/dist/{registry → src/registry}/factory.js +0 -8
- package/dist/{registry → src/registry}/providers/static-index.js +3 -2
- package/dist/{registry → src/registry}/resolve.js +68 -2
- package/dist/{setup → src/setup}/setup.js +43 -5
- package/dist/{sources → src/sources}/providers/git.js +7 -15
- package/dist/tests/add-website-source.test.js +119 -0
- package/dist/tests/agent/agent-config-loader.test.js +70 -0
- package/dist/tests/agent/agent-config.test.js +221 -0
- package/dist/tests/agent/agent-detect.test.js +100 -0
- package/dist/tests/agent/agent-spawn.test.js +234 -0
- package/dist/tests/agent-output.test.js +186 -0
- package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +103 -0
- package/dist/tests/architecture/agent-spawn-seam.test.js +193 -0
- package/dist/tests/architecture/llm-stateless-seam.test.js +112 -0
- package/dist/tests/asset-ref.test.js +192 -0
- package/dist/tests/asset-registry.test.js +103 -0
- package/dist/tests/asset-spec.test.js +241 -0
- package/dist/tests/bench/attribution.test.js +995 -0
- package/dist/tests/bench/cleanup-sigint.test.js +83 -0
- package/dist/tests/bench/cleanup.js +203 -0
- package/dist/tests/bench/cleanup.test.js +166 -0
- package/dist/tests/bench/cli.js +683 -0
- package/dist/tests/bench/cli.test.js +177 -0
- package/dist/tests/bench/compare.test.js +556 -0
- package/dist/tests/bench/corpus.js +314 -0
- package/dist/tests/bench/corpus.test.js +258 -0
- package/dist/tests/bench/driver.js +346 -0
- package/dist/tests/bench/driver.test.js +443 -0
- package/dist/tests/bench/evolve-metrics.js +179 -0
- package/dist/tests/bench/evolve-metrics.test.js +187 -0
- package/dist/tests/bench/evolve.js +580 -0
- package/dist/tests/bench/evolve.test.js +616 -0
- package/dist/tests/bench/failure-modes.test.js +300 -0
- package/dist/tests/bench/feedback-integrity.test.js +456 -0
- package/dist/tests/bench/leakage.test.js +125 -0
- package/dist/tests/bench/learning-curve.test.js +133 -0
- package/dist/tests/bench/metrics.js +2319 -0
- package/dist/tests/bench/metrics.test.js +1144 -0
- package/dist/tests/bench/no-os-tmpdir-invariant.test.js +43 -0
- package/dist/tests/bench/report.js +1821 -0
- package/dist/tests/bench/report.test.js +989 -0
- package/dist/tests/bench/runner.js +536 -0
- package/dist/tests/bench/runner.test.js +958 -0
- package/dist/tests/bench/search-bridge.test.js +331 -0
- package/dist/tests/bench/tmp.js +41 -0
- package/dist/tests/bench/trajectory.js +116 -0
- package/dist/tests/bench/trajectory.test.js +127 -0
- package/dist/tests/bench/verifier.js +109 -0
- package/dist/tests/bench/verifier.test.js +118 -0
- package/dist/tests/bench/workflow-evaluator.js +557 -0
- package/dist/tests/bench/workflow-evaluator.test.js +421 -0
- package/dist/tests/bench/workflow-spec.js +358 -0
- package/dist/tests/bench/workflow-spec.test.js +363 -0
- package/dist/tests/bench/workflow-trace.js +438 -0
- package/dist/tests/bench/workflow-trace.test.js +254 -0
- package/dist/tests/benchmark-search-quality.js +536 -0
- package/dist/tests/benchmark-suite.js +1441 -0
- package/dist/tests/capture-cli.test.js +112 -0
- package/dist/tests/cli-errors.test.js +203 -0
- package/dist/tests/commands/events.test.js +370 -0
- package/dist/tests/commands/history.test.js +223 -0
- package/dist/tests/commands/import.test.js +103 -0
- package/dist/tests/commands/proposal-cli.test.js +209 -0
- package/dist/tests/commands/reflect-propose-cli.test.js +333 -0
- package/dist/tests/commands/remember.test.js +97 -0
- package/dist/tests/commands/scope-flags.test.js +300 -0
- package/dist/tests/commands/search.test.js +537 -0
- package/dist/tests/commands/show-indexer-parity.test.js +117 -0
- package/dist/tests/commands/show.test.js +294 -0
- package/dist/tests/common.test.js +266 -0
- package/dist/tests/completions.test.js +142 -0
- package/dist/tests/config-cli.test.js +193 -0
- package/dist/tests/config-llm-features.test.js +139 -0
- package/dist/tests/config.test.js +544 -0
- package/dist/tests/contracts/migration-baseline.test.js +43 -0
- package/dist/tests/contracts/reflect-propose-envelope.test.js +139 -0
- package/dist/tests/contracts/spec-helpers.js +46 -0
- package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +228 -0
- package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +56 -0
- package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +34 -0
- package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +94 -0
- package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +39 -0
- package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +44 -0
- package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +47 -0
- package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +40 -0
- package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +58 -0
- package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +34 -0
- package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +75 -0
- package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +36 -0
- package/dist/tests/core/write-source.test.js +366 -0
- package/dist/tests/curate-command.test.js +87 -0
- package/dist/tests/db-scoring.test.js +201 -0
- package/dist/tests/db.test.js +654 -0
- package/dist/tests/distill-cli-flag.test.js +208 -0
- package/dist/tests/distill.test.js +515 -0
- package/dist/tests/docker-install.test.js +120 -0
- package/dist/tests/e2e.test.js +1398 -0
- package/dist/tests/embedder.test.js +340 -0
- package/dist/tests/embedding-model-config.test.js +379 -0
- package/dist/tests/feedback-command.test.js +172 -0
- package/dist/tests/file-context.test.js +552 -0
- package/dist/tests/fixtures/scripts/git/summarize-diff.js +9 -0
- package/dist/tests/fixtures/scripts/lint/eslint-check.js +7 -0
- package/dist/tests/fixtures/stashes/load.js +166 -0
- package/dist/tests/fixtures/stashes/load.test.js +88 -0
- package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +12 -0
- package/dist/tests/frontmatter.test.js +190 -0
- package/dist/tests/fts-field-weighting.test.js +254 -0
- package/dist/tests/fuzzy-search.test.js +230 -0
- package/dist/tests/git-provider-clone.test.js +45 -0
- package/dist/tests/github.test.js +161 -0
- package/dist/tests/graph-boost-ranking.test.js +305 -0
- package/dist/tests/graph-extraction.test.js +282 -0
- package/dist/tests/helpers/usage-events.js +8 -0
- package/dist/tests/index-pass-llm.test.js +161 -0
- package/dist/tests/indexer.test.js +559 -0
- package/dist/tests/info-command.test.js +166 -0
- package/dist/tests/init.test.js +69 -0
- package/dist/tests/install-script.test.js +246 -0
- package/dist/tests/integration/agent-real-profile.test.js +94 -0
- package/dist/tests/issue-36-repro.test.js +304 -0
- package/dist/tests/issues-191-194.test.js +160 -0
- package/dist/tests/lesson-lint.test.js +111 -0
- package/dist/tests/llm-client.test.js +115 -0
- package/dist/tests/llm-feature-gate.test.js +151 -0
- package/dist/tests/llm.test.js +139 -0
- package/dist/tests/lockfile.test.js +216 -0
- package/dist/tests/manifest.test.js +205 -0
- package/dist/tests/markdown.test.js +126 -0
- package/dist/tests/matchers-unit.test.js +189 -0
- package/dist/tests/memory-inference.test.js +299 -0
- package/dist/tests/merge-scoring.test.js +136 -0
- package/dist/tests/metadata.test.js +313 -0
- package/dist/tests/migration-help.test.js +89 -0
- package/dist/tests/origin-resolve.test.js +124 -0
- package/dist/tests/output-baseline.test.js +217 -0
- package/dist/tests/output-shapes-unit.test.js +476 -0
- package/dist/tests/parallel-search.test.js +272 -0
- package/dist/tests/parameter-metadata.test.js +365 -0
- package/dist/tests/paths.test.js +177 -0
- package/dist/tests/progressive-disclosure.test.js +280 -0
- package/dist/tests/proposals.test.js +279 -0
- package/dist/tests/proposed-quality.test.js +271 -0
- package/dist/tests/provider-registry.test.js +32 -0
- package/dist/tests/ranking-regression.test.js +548 -0
- package/dist/tests/reflect-propose.test.js +455 -0
- package/dist/tests/registry-build-index.test.js +378 -0
- package/dist/tests/registry-cli.test.js +290 -0
- package/dist/tests/registry-index-v2.test.js +430 -0
- package/dist/tests/registry-install.test.js +728 -0
- package/dist/tests/registry-providers/parity.test.js +189 -0
- package/dist/tests/registry-providers/skills-sh.test.js +309 -0
- package/dist/tests/registry-providers/static-index.test.js +204 -0
- package/dist/tests/registry-resolve.test.js +126 -0
- package/dist/tests/registry-search.test.js +723 -0
- package/dist/tests/remember-frontmatter.test.js +380 -0
- package/dist/tests/remember-unit.test.js +123 -0
- package/dist/tests/ripgrep-install.test.js +251 -0
- package/dist/tests/ripgrep-resolve.test.js +108 -0
- package/dist/tests/ripgrep.test.js +163 -0
- package/dist/tests/save-command.test.js +94 -0
- package/dist/tests/save-trust-qa-fixes.test.js +270 -0
- package/dist/tests/scoring-pipeline.test.js +648 -0
- package/dist/tests/search-include-proposed-cli.test.js +118 -0
- package/dist/tests/self-update.test.js +442 -0
- package/dist/tests/semantic-search-e2e.test.js +512 -0
- package/dist/tests/semantic-status.test.js +471 -0
- package/dist/tests/setup-run.integration.js +877 -0
- package/dist/tests/setup-wizard.test.js +198 -0
- package/dist/tests/setup.test.js +131 -0
- package/dist/tests/source-add.test.js +11 -0
- package/dist/tests/source-clone.test.js +254 -0
- package/dist/tests/source-manage.test.js +366 -0
- package/dist/tests/source-providers/filesystem.test.js +82 -0
- package/dist/tests/source-providers/git.test.js +252 -0
- package/dist/tests/source-providers/website.test.js +128 -0
- package/dist/tests/source-qa-fixes.test.js +268 -0
- package/dist/tests/source-registry.test.js +350 -0
- package/dist/tests/source-resolve.test.js +100 -0
- package/dist/tests/source-source.test.js +221 -0
- package/dist/tests/source.test.js +533 -0
- package/dist/tests/tar-utils-scan.test.js +73 -0
- package/dist/tests/toggle-components.test.js +73 -0
- package/dist/tests/usage-telemetry.test.js +265 -0
- package/dist/tests/utility-scoring.test.js +558 -0
- package/dist/tests/vault-load-error.test.js +78 -0
- package/dist/tests/vault-qa-fixes.test.js +194 -0
- package/dist/tests/vault.test.js +429 -0
- package/dist/tests/vector-search.test.js +608 -0
- package/dist/tests/walker.test.js +252 -0
- package/dist/tests/wave2-cluster-bc.test.js +228 -0
- package/dist/tests/wave2-cluster-d.test.js +180 -0
- package/dist/tests/wave2-cluster-e.test.js +179 -0
- package/dist/tests/wiki-qa-fixes.test.js +270 -0
- package/dist/tests/wiki.test.js +529 -0
- package/dist/tests/workflow-cli.test.js +271 -0
- package/dist/tests/workflow-markdown.test.js +171 -0
- package/dist/tests/workflow-path-escape.test.js +132 -0
- package/dist/tests/workflow-qa-fixes.test.js +377 -0
- package/dist/tests/workflows/indexer-rejection.test.js +213 -0
- package/docs/README.md +8 -0
- package/docs/migration/release-notes/0.7.0.md +244 -0
- package/package.json +2 -2
- package/dist/core/warn.js +0 -27
- package/dist/output/shapes.js +0 -212
- /package/dist/{commands → src/commands}/completions.js +0 -0
- /package/dist/{commands → src/commands}/curate.js +0 -0
- /package/dist/{commands → src/commands}/info.js +0 -0
- /package/dist/{commands → src/commands}/init.js +0 -0
- /package/dist/{commands → src/commands}/install-audit.js +0 -0
- /package/dist/{commands → src/commands}/migration-help.js +0 -0
- /package/dist/{commands → src/commands}/source-add.js +0 -0
- /package/dist/{commands → src/commands}/source-clone.js +0 -0
- /package/dist/{commands → src/commands}/source-manage.js +0 -0
- /package/dist/{commands → src/commands}/vault.js +0 -0
- /package/dist/{core → src/core}/asset-registry.js +0 -0
- /package/dist/{core → src/core}/frontmatter.js +0 -0
- /package/dist/{core → src/core}/markdown.js +0 -0
- /package/dist/{core → src/core}/paths.js +0 -0
- /package/dist/{indexer → src/indexer}/manifest.js +0 -0
- /package/dist/{indexer → src/indexer}/matchers.js +0 -0
- /package/dist/{indexer → src/indexer}/search-fields.js +0 -0
- /package/dist/{indexer → src/indexer}/search-source.js +0 -0
- /package/dist/{indexer → src/indexer}/semantic-status.js +0 -0
- /package/dist/{indexer → src/indexer}/usage-events.js +0 -0
- /package/dist/{indexer → src/indexer}/walker.js +0 -0
- /package/dist/{integrations → src/integrations}/github.js +0 -0
- /package/dist/{llm → src/llm}/embedder.js +0 -0
- /package/dist/{llm → src/llm}/embedders/cache.js +0 -0
- /package/dist/{llm → src/llm}/embedders/local.js +0 -0
- /package/dist/{llm → src/llm}/embedders/remote.js +0 -0
- /package/dist/{llm → src/llm}/embedders/types.js +0 -0
- /package/dist/{llm → src/llm}/metadata-enhance.js +0 -0
- /package/dist/{output → src/output}/cli-hints.js +0 -0
- /package/dist/{output → src/output}/context.js +0 -0
- /package/dist/{registry → src/registry}/create-provider-registry.js +0 -0
- /package/dist/{registry → src/registry}/origin-resolve.js +0 -0
- /package/dist/{registry → src/registry}/providers/index.js +0 -0
- /package/dist/{registry → src/registry}/providers/skills-sh.js +0 -0
- /package/dist/{registry → src/registry}/providers/types.js +0 -0
- /package/dist/{registry → src/registry}/types.js +0 -0
- /package/dist/{setup → src/setup}/detect.js +0 -0
- /package/dist/{setup → src/setup}/ripgrep-install.js +0 -0
- /package/dist/{setup → src/setup}/ripgrep-resolve.js +0 -0
- /package/dist/{setup → src/setup}/steps.js +0 -0
- /package/dist/{sources → src/sources}/include.js +0 -0
- /package/dist/{sources → src/sources}/provider-factory.js +0 -0
- /package/dist/{sources → src/sources}/provider.js +0 -0
- /package/dist/{sources → src/sources}/providers/filesystem.js +0 -0
- /package/dist/{sources → src/sources}/providers/index.js +0 -0
- /package/dist/{sources → src/sources}/providers/install-types.js +0 -0
- /package/dist/{sources → src/sources}/providers/npm.js +0 -0
- /package/dist/{sources → src/sources}/providers/provider-utils.js +0 -0
- /package/dist/{sources → src/sources}/providers/sync-from-ref.js +0 -0
- /package/dist/{sources → src/sources}/providers/tar-utils.js +0 -0
- /package/dist/{sources → src/sources}/providers/website.js +0 -0
- /package/dist/{sources → src/sources}/resolve.js +0 -0
- /package/dist/{sources → src/sources}/types.js +0 -0
- /package/dist/{templates → src/templates}/wiki-templates.js +0 -0
- /package/dist/{version.js → src/version.js} +0 -0
- /package/dist/{wiki → src/wiki}/wiki.js +0 -0
- /package/dist/{workflows → src/workflows}/authoring.js +0 -0
- /package/dist/{workflows → src/workflows}/cli.js +0 -0
- /package/dist/{workflows → src/workflows}/db.js +0 -0
- /package/dist/{workflows → src/workflows}/document-cache.js +0 -0
- /package/dist/{workflows → src/workflows}/parser.js +0 -0
- /package/dist/{workflows → src/workflows}/renderer.js +0 -0
- /package/dist/{workflows → src/workflows}/runs.js +0 -0
- /package/dist/{workflows → src/workflows}/schema.js +0 -0
- /package/dist/{workflows → src/workflows}/validator.js +0 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for setup wizard interactive logic:
|
|
3
|
+
* - onCancel: Escape on confirmation should stay, not exit
|
|
4
|
+
* - stepAddSources: recommended GitHub repos multiselect, cancel returns to menu
|
|
5
|
+
*/
|
|
6
|
+
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
7
|
+
// ── Mock plumbing ────────────────────────────────────────────────────────────
|
|
8
|
+
/** Sentinel returned by mocked prompts when simulating Escape / Ctrl-C. */
|
|
9
|
+
const CANCEL = Symbol("clack:cancel");
|
|
10
|
+
/** Per-test response queues — shift one value per prompt call. */
|
|
11
|
+
const q = {
|
|
12
|
+
confirms: [],
|
|
13
|
+
selects: [],
|
|
14
|
+
texts: [],
|
|
15
|
+
multiselects: [],
|
|
16
|
+
logged: [],
|
|
17
|
+
};
|
|
18
|
+
function reset() {
|
|
19
|
+
q.confirms.length = 0;
|
|
20
|
+
q.selects.length = 0;
|
|
21
|
+
q.texts.length = 0;
|
|
22
|
+
q.multiselects.length = 0;
|
|
23
|
+
q.logged.length = 0;
|
|
24
|
+
}
|
|
25
|
+
// Must be called **before** any module that imports @clack/prompts is loaded.
|
|
26
|
+
mock.module("@clack/prompts", () => ({
|
|
27
|
+
isCancel: (v) => v === CANCEL,
|
|
28
|
+
cancel: (msg) => {
|
|
29
|
+
q.logged.push(`[cancel] ${msg}`);
|
|
30
|
+
},
|
|
31
|
+
confirm: async () => q.confirms.shift() ?? false,
|
|
32
|
+
select: async () => q.selects.shift() ?? "done",
|
|
33
|
+
text: async () => q.texts.shift() ?? "",
|
|
34
|
+
multiselect: async () => q.multiselects.shift() ?? [],
|
|
35
|
+
spinner: () => ({ start: () => { }, stop: () => { } }),
|
|
36
|
+
log: {
|
|
37
|
+
info: (msg) => {
|
|
38
|
+
q.logged.push(msg);
|
|
39
|
+
},
|
|
40
|
+
success: (msg) => {
|
|
41
|
+
q.logged.push(msg);
|
|
42
|
+
},
|
|
43
|
+
warn: (msg) => {
|
|
44
|
+
q.logged.push(msg);
|
|
45
|
+
},
|
|
46
|
+
step: () => { },
|
|
47
|
+
},
|
|
48
|
+
intro: () => { },
|
|
49
|
+
outro: () => { },
|
|
50
|
+
note: (msg, title) => {
|
|
51
|
+
q.logged.push(`[note] ${title ?? ""} ${msg}`.trim());
|
|
52
|
+
},
|
|
53
|
+
}));
|
|
54
|
+
// ── onCancel tests ───────────────────────────────────────────────────────────
|
|
55
|
+
describe("onCancel – escape handling", () => {
|
|
56
|
+
beforeEach(reset);
|
|
57
|
+
test("pressing Escape on the exit-confirmation stays in the wizard", async () => {
|
|
58
|
+
const { onCancel } = await import("../src/setup/setup");
|
|
59
|
+
// Simulate: user already pressed Escape in a prompt (value = CANCEL),
|
|
60
|
+
// then presses Escape again on the "Exit the wizard?" confirmation.
|
|
61
|
+
q.confirms.push(CANCEL);
|
|
62
|
+
const stayed = await onCancel(CANCEL);
|
|
63
|
+
expect(stayed).toBe(true);
|
|
64
|
+
});
|
|
65
|
+
test("choosing No on the exit-confirmation stays in the wizard", async () => {
|
|
66
|
+
const { onCancel } = await import("../src/setup/setup");
|
|
67
|
+
q.confirms.push(false);
|
|
68
|
+
const stayed = await onCancel(CANCEL);
|
|
69
|
+
expect(stayed).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
test("choosing Yes on the exit-confirmation calls bail (exits)", async () => {
|
|
72
|
+
const { onCancel } = await import("../src/setup/setup");
|
|
73
|
+
q.confirms.push(true);
|
|
74
|
+
// bail() calls process.exit — mock it so it throws instead of killing the runner
|
|
75
|
+
const originalExit = process.exit;
|
|
76
|
+
process.exit = ((code) => {
|
|
77
|
+
throw new Error(`EXIT:${code}`);
|
|
78
|
+
});
|
|
79
|
+
try {
|
|
80
|
+
await expect(onCancel(CANCEL)).rejects.toThrow("EXIT:0");
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
process.exit = originalExit;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
test("non-cancel input is a no-op (returns false)", async () => {
|
|
87
|
+
const { onCancel } = await import("../src/setup/setup");
|
|
88
|
+
const stayed = await onCancel("normal-value");
|
|
89
|
+
expect(stayed).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
// ── stepAddSources tests ───────────────────────────────────────────────────
|
|
93
|
+
describe("stepAddSources – recommended GitHub repos", () => {
|
|
94
|
+
beforeEach(reset);
|
|
95
|
+
test("with no recommended repos configured, the multiselect prompt is skipped", async () => {
|
|
96
|
+
const { stepAddSources } = await import("../src/setup/setup");
|
|
97
|
+
// No multiselect should be consumed because the recommended-repos array
|
|
98
|
+
// is empty. Only the "Add another source?" select should be needed.
|
|
99
|
+
q.selects.push("done");
|
|
100
|
+
const result = await stepAddSources({ sources: [] });
|
|
101
|
+
expect(result).toEqual([]);
|
|
102
|
+
// multiselect queue should still be empty (nothing pushed, nothing consumed)
|
|
103
|
+
expect(q.multiselects.length).toBe(0);
|
|
104
|
+
});
|
|
105
|
+
test("preserves an existing git stash that points at the legacy context-hub URL", async () => {
|
|
106
|
+
const { stepAddSources } = await import("../src/setup/setup");
|
|
107
|
+
const ctxHubUrl = "https://github.com/andrewyng/context-hub";
|
|
108
|
+
const cfg = {
|
|
109
|
+
sources: [{ type: "git", url: ctxHubUrl, name: "context-hub" }],
|
|
110
|
+
};
|
|
111
|
+
q.selects.push("done");
|
|
112
|
+
const result = await stepAddSources(cfg);
|
|
113
|
+
const hub = result.find((s) => s.url === ctxHubUrl);
|
|
114
|
+
expect(hub).toBeDefined();
|
|
115
|
+
expect(hub?.type).toBe("git");
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
describe("semantic search setup", () => {
|
|
119
|
+
beforeEach(reset);
|
|
120
|
+
test("should list local model and sqlite-vec guidance when describing semantic search assets", async () => {
|
|
121
|
+
const { describeSemanticSearchAssets } = await import("../src/setup/setup");
|
|
122
|
+
const assets = describeSemanticSearchAssets();
|
|
123
|
+
expect(assets[0]).toContain("Local embedding model");
|
|
124
|
+
expect(assets[0]).toContain("download");
|
|
125
|
+
expect(assets[1]).toContain("sqlite-vec");
|
|
126
|
+
});
|
|
127
|
+
test("stepSemanticSearch returns disabled when user opts out", async () => {
|
|
128
|
+
const { stepSemanticSearch } = await import("../src/setup/setup");
|
|
129
|
+
q.confirms.push(false);
|
|
130
|
+
const result = await stepSemanticSearch({ semanticSearchMode: "auto" });
|
|
131
|
+
expect(result).toEqual({ mode: "off", prepareAssets: false });
|
|
132
|
+
});
|
|
133
|
+
test("stepSemanticSearch shows assets and allows asset preparation", async () => {
|
|
134
|
+
const { stepSemanticSearch } = await import("../src/setup/setup");
|
|
135
|
+
q.confirms.push(true, true);
|
|
136
|
+
const result = await stepSemanticSearch({ semanticSearchMode: "auto" });
|
|
137
|
+
expect(result).toEqual({ mode: "auto", prepareAssets: true });
|
|
138
|
+
expect(q.logged.some((entry) => entry.includes("Semantic Search Assets"))).toBe(true);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
describe("stepAddSources – custom GitHub repo", () => {
|
|
142
|
+
beforeEach(reset);
|
|
143
|
+
test("adds a custom GitHub repo with type 'git'", async () => {
|
|
144
|
+
const { stepAddSources } = await import("../src/setup/setup");
|
|
145
|
+
// multiselect recommended repos → none
|
|
146
|
+
q.multiselects.push([]);
|
|
147
|
+
// select "Add another source?" → "github-repo"
|
|
148
|
+
q.selects.push("github-repo");
|
|
149
|
+
// text: GitHub URL
|
|
150
|
+
q.texts.push("https://github.com/owner/repo");
|
|
151
|
+
// text: name
|
|
152
|
+
q.texts.push("my-repo");
|
|
153
|
+
// select → done
|
|
154
|
+
q.selects.push("done");
|
|
155
|
+
const result = await stepAddSources({ sources: [] });
|
|
156
|
+
const repo = result.find((s) => s.url === "https://github.com/owner/repo");
|
|
157
|
+
expect(repo).toBeDefined();
|
|
158
|
+
expect(repo?.type).toBe("git");
|
|
159
|
+
expect(repo?.name).toBe("my-repo");
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
describe("stepAddSources – cancel within sub-actions", () => {
|
|
163
|
+
beforeEach(reset);
|
|
164
|
+
test("pressing Escape on a sub-action text prompt returns to menu", async () => {
|
|
165
|
+
const { stepAddSources } = await import("../src/setup/setup");
|
|
166
|
+
// multiselect recommended → none
|
|
167
|
+
q.multiselects.push([]);
|
|
168
|
+
// select → github-repo
|
|
169
|
+
q.selects.push("github-repo");
|
|
170
|
+
// text: press Escape (cancel) → should return to menu, not re-prompt
|
|
171
|
+
q.texts.push(CANCEL);
|
|
172
|
+
// back at menu → done
|
|
173
|
+
q.selects.push("done");
|
|
174
|
+
const result = await stepAddSources({ sources: [] });
|
|
175
|
+
// No repo was added because the user cancelled
|
|
176
|
+
expect(result).toEqual([]);
|
|
177
|
+
});
|
|
178
|
+
test("pressing Escape on filesystem path returns to menu", async () => {
|
|
179
|
+
const { stepAddSources } = await import("../src/setup/setup");
|
|
180
|
+
q.multiselects.push([]);
|
|
181
|
+
q.selects.push("filesystem");
|
|
182
|
+
q.texts.push(CANCEL); // cancel the path prompt
|
|
183
|
+
q.selects.push("done");
|
|
184
|
+
const result = await stepAddSources({ sources: [] });
|
|
185
|
+
expect(result).toEqual([]);
|
|
186
|
+
});
|
|
187
|
+
test("pressing Escape on name prompt returns to menu without adding", async () => {
|
|
188
|
+
const { stepAddSources } = await import("../src/setup/setup");
|
|
189
|
+
q.multiselects.push([]);
|
|
190
|
+
q.selects.push("github-repo");
|
|
191
|
+
q.texts.push("https://github.com/owner/repo"); // provide URL
|
|
192
|
+
q.texts.push(CANCEL); // cancel on name prompt
|
|
193
|
+
q.selects.push("done");
|
|
194
|
+
const result = await stepAddSources({ sources: [] });
|
|
195
|
+
// Repo was NOT added because user cancelled at the name step
|
|
196
|
+
expect(result).toEqual([]);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
// ── detect.ts tests ─────────────────────────────────────────────────────────
|
|
6
|
+
describe("detectAgentPlatforms", () => {
|
|
7
|
+
let testHome;
|
|
8
|
+
const originalHome = process.env.HOME;
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
testHome = fs.mkdtempSync(path.join(os.tmpdir(), "akm-detect-"));
|
|
11
|
+
process.env.HOME = testHome;
|
|
12
|
+
});
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
process.env.HOME = originalHome;
|
|
15
|
+
fs.rmSync(testHome, { recursive: true, force: true });
|
|
16
|
+
});
|
|
17
|
+
test("returns empty array when no platforms found", async () => {
|
|
18
|
+
const { detectAgentPlatforms } = await import("../src/setup/detect");
|
|
19
|
+
const result = detectAgentPlatforms();
|
|
20
|
+
expect(result).toEqual([]);
|
|
21
|
+
});
|
|
22
|
+
test("detects .claude directory", async () => {
|
|
23
|
+
fs.mkdirSync(path.join(testHome, ".claude"), { recursive: true });
|
|
24
|
+
// Re-import to pick up fresh HOME
|
|
25
|
+
const { detectAgentPlatforms } = await import("../src/setup/detect");
|
|
26
|
+
const result = detectAgentPlatforms();
|
|
27
|
+
const claude = result.find((p) => p.name === "Claude Code");
|
|
28
|
+
expect(claude).toBeDefined();
|
|
29
|
+
expect(claude?.path).toBe(path.join(testHome, ".claude"));
|
|
30
|
+
});
|
|
31
|
+
test("detects .config/opencode directory", async () => {
|
|
32
|
+
fs.mkdirSync(path.join(testHome, ".config", "opencode"), { recursive: true });
|
|
33
|
+
const { detectAgentPlatforms } = await import("../src/setup/detect");
|
|
34
|
+
const result = detectAgentPlatforms();
|
|
35
|
+
const opencode = result.find((p) => p.name === "OpenCode");
|
|
36
|
+
expect(opencode).toBeDefined();
|
|
37
|
+
expect(opencode?.path).toBe(path.join(testHome, ".config", "opencode"));
|
|
38
|
+
});
|
|
39
|
+
test("detects multiple platforms", async () => {
|
|
40
|
+
fs.mkdirSync(path.join(testHome, ".claude"), { recursive: true });
|
|
41
|
+
fs.mkdirSync(path.join(testHome, ".cursor"), { recursive: true });
|
|
42
|
+
fs.mkdirSync(path.join(testHome, ".continue"), { recursive: true });
|
|
43
|
+
const { detectAgentPlatforms } = await import("../src/setup/detect");
|
|
44
|
+
const result = detectAgentPlatforms();
|
|
45
|
+
expect(result.length).toBeGreaterThanOrEqual(3);
|
|
46
|
+
});
|
|
47
|
+
test("ignores files (only detects directories)", async () => {
|
|
48
|
+
fs.writeFileSync(path.join(testHome, ".claude"), "not a directory");
|
|
49
|
+
const { detectAgentPlatforms } = await import("../src/setup/detect");
|
|
50
|
+
const result = detectAgentPlatforms();
|
|
51
|
+
const claude = result.find((p) => p.name === "Claude Code");
|
|
52
|
+
expect(claude).toBeUndefined();
|
|
53
|
+
});
|
|
54
|
+
test("returns empty when HOME and USERPROFILE are both unset", async () => {
|
|
55
|
+
delete process.env.HOME;
|
|
56
|
+
delete process.env.USERPROFILE;
|
|
57
|
+
const { detectAgentPlatforms } = await import("../src/setup/detect");
|
|
58
|
+
const result = detectAgentPlatforms();
|
|
59
|
+
expect(result).toEqual([]);
|
|
60
|
+
});
|
|
61
|
+
test("falls back to USERPROFILE when HOME is unset (Windows)", async () => {
|
|
62
|
+
delete process.env.HOME;
|
|
63
|
+
process.env.USERPROFILE = testHome;
|
|
64
|
+
fs.mkdirSync(path.join(testHome, ".claude"), { recursive: true });
|
|
65
|
+
const { detectAgentPlatforms } = await import("../src/setup/detect");
|
|
66
|
+
const result = detectAgentPlatforms();
|
|
67
|
+
const claude = result.find((p) => p.name === "Claude Code");
|
|
68
|
+
expect(claude).toBeDefined();
|
|
69
|
+
expect(claude?.path).toBe(path.join(testHome, ".claude"));
|
|
70
|
+
delete process.env.USERPROFILE;
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe("detectOllama", () => {
|
|
74
|
+
let originalFetch;
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
originalFetch = globalThis.fetch;
|
|
77
|
+
});
|
|
78
|
+
afterEach(() => {
|
|
79
|
+
globalThis.fetch = originalFetch;
|
|
80
|
+
});
|
|
81
|
+
test("returns available=true with models from API", async () => {
|
|
82
|
+
globalThis.fetch = (async (input) => {
|
|
83
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
|
|
84
|
+
if (url.includes("/api/tags")) {
|
|
85
|
+
return new Response(JSON.stringify({
|
|
86
|
+
models: [{ name: "llama3.2:latest" }, { name: "nomic-embed-text:latest" }, { name: "codellama:latest" }],
|
|
87
|
+
}), { status: 200 });
|
|
88
|
+
}
|
|
89
|
+
return new Response("", { status: 404 });
|
|
90
|
+
});
|
|
91
|
+
const { detectOllama } = await import("../src/setup/detect");
|
|
92
|
+
const result = await detectOllama();
|
|
93
|
+
expect(result.available).toBe(true);
|
|
94
|
+
expect(result.models).toContain("llama3.2");
|
|
95
|
+
expect(result.models).toContain("nomic-embed-text");
|
|
96
|
+
expect(result.models).toContain("codellama");
|
|
97
|
+
});
|
|
98
|
+
test("strips :latest suffix from model names", async () => {
|
|
99
|
+
globalThis.fetch = (async () => {
|
|
100
|
+
return new Response(JSON.stringify({
|
|
101
|
+
models: [{ name: "llama3.2:latest" }, { name: "phi3:v2" }],
|
|
102
|
+
}), { status: 200 });
|
|
103
|
+
});
|
|
104
|
+
const { detectOllama } = await import("../src/setup/detect");
|
|
105
|
+
const result = await detectOllama();
|
|
106
|
+
expect(result.models).toContain("llama3.2");
|
|
107
|
+
expect(result.models).toContain("phi3:v2");
|
|
108
|
+
expect(result.models).not.toContain("llama3.2:latest");
|
|
109
|
+
});
|
|
110
|
+
test("returns available=false when fetch fails", async () => {
|
|
111
|
+
globalThis.fetch = (async () => {
|
|
112
|
+
throw new Error("Connection refused");
|
|
113
|
+
});
|
|
114
|
+
const { detectOllama } = await import("../src/setup/detect");
|
|
115
|
+
const result = await detectOllama();
|
|
116
|
+
// May still be available=true if `ollama list` CLI works, or false if both fail
|
|
117
|
+
// Just verify it doesn't throw
|
|
118
|
+
expect(typeof result.available).toBe("boolean");
|
|
119
|
+
expect(Array.isArray(result.models)).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
test("returns sorted model names", async () => {
|
|
122
|
+
globalThis.fetch = (async () => {
|
|
123
|
+
return new Response(JSON.stringify({
|
|
124
|
+
models: [{ name: "zephyr:latest" }, { name: "alpaca:latest" }, { name: "mistral:latest" }],
|
|
125
|
+
}), { status: 200 });
|
|
126
|
+
});
|
|
127
|
+
const { detectOllama } = await import("../src/setup/detect");
|
|
128
|
+
const result = await detectOllama();
|
|
129
|
+
expect(result.models).toEqual(["alpaca", "mistral", "zephyr"]);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { shouldAddAsWebsiteUrl } from "../src/commands/source-add";
|
|
3
|
+
describe("shouldAddAsWebsiteUrl", () => {
|
|
4
|
+
test("treats docs-style URLs as website sources", () => {
|
|
5
|
+
expect(shouldAddAsWebsiteUrl("https://docs.example.com/guide")).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
test("keeps known git hosts on the registry install path", () => {
|
|
8
|
+
expect(shouldAddAsWebsiteUrl("https://gitlab.com/acme/project")).toBe(false);
|
|
9
|
+
expect(shouldAddAsWebsiteUrl("https://example.com/acme/project.git")).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { akmClone } from "../src/commands/source-clone";
|
|
6
|
+
import { saveConfig } from "../src/core/config";
|
|
7
|
+
import { UsageError } from "../src/core/errors";
|
|
8
|
+
const originalStashDir = process.env.AKM_STASH_DIR;
|
|
9
|
+
const originalXdgConfigHome = process.env.XDG_CONFIG_HOME;
|
|
10
|
+
const originalXdgCacheHome = process.env.XDG_CACHE_HOME;
|
|
11
|
+
let testConfigDir = "";
|
|
12
|
+
let testCacheDir = "";
|
|
13
|
+
let stashDir = "";
|
|
14
|
+
let searchPathDir = "";
|
|
15
|
+
function writeFile(filePath, content) {
|
|
16
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
17
|
+
fs.writeFileSync(filePath, content);
|
|
18
|
+
}
|
|
19
|
+
function createStashDir(prefix) {
|
|
20
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
21
|
+
for (const sub of ["skills", "commands", "agents", "knowledge", "scripts"]) {
|
|
22
|
+
fs.mkdirSync(path.join(dir, sub), { recursive: true });
|
|
23
|
+
}
|
|
24
|
+
return dir;
|
|
25
|
+
}
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
testConfigDir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-clone-config-"));
|
|
28
|
+
testCacheDir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-clone-cache-"));
|
|
29
|
+
stashDir = createStashDir("akm-clone-working-");
|
|
30
|
+
searchPathDir = createStashDir("akm-clone-searchpath-");
|
|
31
|
+
process.env.XDG_CONFIG_HOME = testConfigDir;
|
|
32
|
+
process.env.XDG_CACHE_HOME = testCacheDir;
|
|
33
|
+
process.env.AKM_STASH_DIR = stashDir;
|
|
34
|
+
saveConfig({
|
|
35
|
+
semanticSearchMode: "off",
|
|
36
|
+
sources: [{ type: "filesystem", path: searchPathDir }],
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
afterEach(() => {
|
|
40
|
+
process.env.AKM_STASH_DIR = originalStashDir ?? undefined;
|
|
41
|
+
if (originalXdgConfigHome === undefined)
|
|
42
|
+
delete process.env.XDG_CONFIG_HOME;
|
|
43
|
+
else
|
|
44
|
+
process.env.XDG_CONFIG_HOME = originalXdgConfigHome;
|
|
45
|
+
if (originalXdgCacheHome === undefined)
|
|
46
|
+
delete process.env.XDG_CACHE_HOME;
|
|
47
|
+
else
|
|
48
|
+
process.env.XDG_CACHE_HOME = originalXdgCacheHome;
|
|
49
|
+
for (const dir of [testConfigDir, testCacheDir, stashDir, searchPathDir]) {
|
|
50
|
+
if (dir)
|
|
51
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
describe("akmClone", () => {
|
|
55
|
+
test("clones a script from search path to primary stash", async () => {
|
|
56
|
+
writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "#!/bin/bash\necho deploy\n");
|
|
57
|
+
const result = await akmClone({ sourceRef: "script:deploy.sh" });
|
|
58
|
+
expect(result.destination.ref).toContain("script:deploy.sh");
|
|
59
|
+
expect(result.overwritten).toBe(false);
|
|
60
|
+
expect(fs.existsSync(path.join(stashDir, "scripts", "deploy.sh"))).toBe(true);
|
|
61
|
+
expect(fs.readFileSync(path.join(stashDir, "scripts", "deploy.sh"), "utf8")).toBe("#!/bin/bash\necho deploy\n");
|
|
62
|
+
});
|
|
63
|
+
test("clones a skill directory", async () => {
|
|
64
|
+
writeFile(path.join(searchPathDir, "skills", "review", "SKILL.md"), "# Review Skill\n");
|
|
65
|
+
writeFile(path.join(searchPathDir, "skills", "review", "helper.md"), "# Helper\n");
|
|
66
|
+
const result = await akmClone({ sourceRef: "skill:review" });
|
|
67
|
+
expect(result.overwritten).toBe(false);
|
|
68
|
+
expect(fs.existsSync(path.join(stashDir, "skills", "review", "SKILL.md"))).toBe(true);
|
|
69
|
+
expect(fs.existsSync(path.join(stashDir, "skills", "review", "helper.md"))).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
test("clones with a new name", async () => {
|
|
72
|
+
writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo deploy\n");
|
|
73
|
+
const result = await akmClone({ sourceRef: "script:deploy.sh", newName: "my-deploy.sh" });
|
|
74
|
+
expect(fs.existsSync(path.join(stashDir, "scripts", "my-deploy.sh"))).toBe(true);
|
|
75
|
+
expect(result.destination.ref).toContain("my-deploy.sh");
|
|
76
|
+
});
|
|
77
|
+
test("throws when asset already exists without --force", async () => {
|
|
78
|
+
writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo original\n");
|
|
79
|
+
writeFile(path.join(stashDir, "scripts", "deploy.sh"), "echo existing\n");
|
|
80
|
+
await expect(akmClone({ sourceRef: `${searchPathDir}//script:deploy.sh` })).rejects.toThrow("already exists");
|
|
81
|
+
});
|
|
82
|
+
test("overwrites with --force", async () => {
|
|
83
|
+
writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo updated\n");
|
|
84
|
+
writeFile(path.join(stashDir, "scripts", "deploy.sh"), "echo old\n");
|
|
85
|
+
const result = await akmClone({ sourceRef: `${searchPathDir}//script:deploy.sh`, force: true });
|
|
86
|
+
expect(result.overwritten).toBe(true);
|
|
87
|
+
expect(fs.readFileSync(path.join(stashDir, "scripts", "deploy.sh"), "utf8")).toBe("echo updated\n");
|
|
88
|
+
});
|
|
89
|
+
test("force overwrite removes stale files from skill directory", async () => {
|
|
90
|
+
// Source skill has only SKILL.md
|
|
91
|
+
writeFile(path.join(searchPathDir, "skills", "review", "SKILL.md"), "# Updated\n");
|
|
92
|
+
// Existing working skill has an extra file
|
|
93
|
+
writeFile(path.join(stashDir, "skills", "review", "SKILL.md"), "# Old\n");
|
|
94
|
+
writeFile(path.join(stashDir, "skills", "review", "stale.md"), "# Stale\n");
|
|
95
|
+
await akmClone({ sourceRef: `${searchPathDir}//skill:review`, force: true });
|
|
96
|
+
expect(fs.existsSync(path.join(stashDir, "skills", "review", "SKILL.md"))).toBe(true);
|
|
97
|
+
expect(fs.existsSync(path.join(stashDir, "skills", "review", "stale.md"))).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
test("throws when source asset not found", async () => {
|
|
100
|
+
await expect(akmClone({ sourceRef: "script:nonexistent.sh" })).rejects.toThrow();
|
|
101
|
+
});
|
|
102
|
+
test("clones from working stash to itself with new name", async () => {
|
|
103
|
+
writeFile(path.join(stashDir, "scripts", "original.sh"), "echo original\n");
|
|
104
|
+
const _result = await akmClone({ sourceRef: "script:original.sh", newName: "copy.sh" });
|
|
105
|
+
expect(fs.existsSync(path.join(stashDir, "scripts", "copy.sh"))).toBe(true);
|
|
106
|
+
});
|
|
107
|
+
test("throws when self-cloning a script without rename", async () => {
|
|
108
|
+
writeFile(path.join(stashDir, "scripts", "deploy.sh"), "echo deploy\n");
|
|
109
|
+
await expect(akmClone({ sourceRef: "script:deploy.sh" })).rejects.toThrow("same path");
|
|
110
|
+
// Verify the file was not destroyed
|
|
111
|
+
expect(fs.readFileSync(path.join(stashDir, "scripts", "deploy.sh"), "utf8")).toBe("echo deploy\n");
|
|
112
|
+
});
|
|
113
|
+
test("throws when self-cloning a skill without rename", async () => {
|
|
114
|
+
writeFile(path.join(stashDir, "skills", "review", "SKILL.md"), "# Review\n");
|
|
115
|
+
await expect(akmClone({ sourceRef: "skill:review" })).rejects.toThrow("same path");
|
|
116
|
+
// Verify the skill was not destroyed
|
|
117
|
+
expect(fs.existsSync(path.join(stashDir, "skills", "review", "SKILL.md"))).toBe(true);
|
|
118
|
+
});
|
|
119
|
+
describe("newName validation", () => {
|
|
120
|
+
beforeEach(() => {
|
|
121
|
+
writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo deploy\n");
|
|
122
|
+
writeFile(path.join(searchPathDir, "skills", "review", "SKILL.md"), "# Review\n");
|
|
123
|
+
});
|
|
124
|
+
test("throws on empty string newName", async () => {
|
|
125
|
+
await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "" })).rejects.toThrow(UsageError);
|
|
126
|
+
await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "" })).rejects.toThrow(/empty/);
|
|
127
|
+
});
|
|
128
|
+
test("throws on '.' as newName", async () => {
|
|
129
|
+
await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "." })).rejects.toThrow(UsageError);
|
|
130
|
+
await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "." })).rejects.toThrow(/Unsafe/);
|
|
131
|
+
});
|
|
132
|
+
test("throws on '..' as newName", async () => {
|
|
133
|
+
await expect(akmClone({ sourceRef: "script:deploy.sh", newName: ".." })).rejects.toThrow(UsageError);
|
|
134
|
+
await expect(akmClone({ sourceRef: "script:deploy.sh", newName: ".." })).rejects.toThrow(/Unsafe/);
|
|
135
|
+
});
|
|
136
|
+
test("throws on path-traversal newName", async () => {
|
|
137
|
+
await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "../escape.sh" })).rejects.toThrow(UsageError);
|
|
138
|
+
await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "../escape.sh" })).rejects.toThrow(/Unsafe/);
|
|
139
|
+
});
|
|
140
|
+
test("throws on absolute path as newName", async () => {
|
|
141
|
+
await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "/etc/evil.sh" })).rejects.toThrow(UsageError);
|
|
142
|
+
await expect(akmClone({ sourceRef: "script:deploy.sh", newName: "/etc/evil.sh" })).rejects.toThrow(/Unsafe/);
|
|
143
|
+
});
|
|
144
|
+
test("empty newName does not wipe the type directory for skills", async () => {
|
|
145
|
+
writeFile(path.join(stashDir, "skills", "existing", "SKILL.md"), "# Existing\n");
|
|
146
|
+
await expect(akmClone({ sourceRef: "skill:review", newName: "", force: true })).rejects.toThrow(UsageError);
|
|
147
|
+
// Existing skill must be untouched
|
|
148
|
+
expect(fs.existsSync(path.join(stashDir, "skills", "existing", "SKILL.md"))).toBe(true);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
describe("akmClone --dest", () => {
|
|
153
|
+
let customDest;
|
|
154
|
+
beforeEach(() => {
|
|
155
|
+
customDest = fs.mkdtempSync(path.join(os.tmpdir(), "akm-clone-dest-"));
|
|
156
|
+
});
|
|
157
|
+
afterEach(() => {
|
|
158
|
+
if (customDest)
|
|
159
|
+
fs.rmSync(customDest, { recursive: true, force: true });
|
|
160
|
+
});
|
|
161
|
+
test("clones script to custom destination preserving type dir structure", async () => {
|
|
162
|
+
writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "#!/bin/bash\necho deploy\n");
|
|
163
|
+
const result = await akmClone({ sourceRef: "script:deploy.sh", dest: customDest });
|
|
164
|
+
expect(result.destination.path).toBe(path.join(customDest, "scripts", "deploy.sh"));
|
|
165
|
+
expect(fs.existsSync(path.join(customDest, "scripts", "deploy.sh"))).toBe(true);
|
|
166
|
+
expect(fs.readFileSync(path.join(customDest, "scripts", "deploy.sh"), "utf8")).toBe("#!/bin/bash\necho deploy\n");
|
|
167
|
+
// Working stash should NOT have the file
|
|
168
|
+
expect(fs.existsSync(path.join(stashDir, "scripts", "deploy.sh"))).toBe(false);
|
|
169
|
+
});
|
|
170
|
+
test("clones skill directory to custom destination", async () => {
|
|
171
|
+
writeFile(path.join(searchPathDir, "skills", "review", "SKILL.md"), "# Review Skill\n");
|
|
172
|
+
writeFile(path.join(searchPathDir, "skills", "review", "helper.md"), "# Helper\n");
|
|
173
|
+
const result = await akmClone({ sourceRef: "skill:review", dest: customDest });
|
|
174
|
+
expect(fs.existsSync(path.join(customDest, "skills", "review", "SKILL.md"))).toBe(true);
|
|
175
|
+
expect(fs.existsSync(path.join(customDest, "skills", "review", "helper.md"))).toBe(true);
|
|
176
|
+
expect(result.overwritten).toBe(false);
|
|
177
|
+
});
|
|
178
|
+
test("--dest does not require a working stash", async () => {
|
|
179
|
+
writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo deploy\n");
|
|
180
|
+
// Point AKM_STASH_DIR to a non-existent directory to simulate no working stash
|
|
181
|
+
process.env.AKM_STASH_DIR = path.join(os.tmpdir(), `nonexistent-stash-${Date.now()}`);
|
|
182
|
+
const result = await akmClone({
|
|
183
|
+
sourceRef: `${searchPathDir}//script:deploy.sh`,
|
|
184
|
+
dest: customDest,
|
|
185
|
+
});
|
|
186
|
+
expect(fs.existsSync(path.join(customDest, "scripts", "deploy.sh"))).toBe(true);
|
|
187
|
+
expect(result.destination.path).toBe(path.join(customDest, "scripts", "deploy.sh"));
|
|
188
|
+
});
|
|
189
|
+
test("--dest with --force overwrites at custom destination", async () => {
|
|
190
|
+
writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo updated\n");
|
|
191
|
+
writeFile(path.join(customDest, "scripts", "deploy.sh"), "echo old\n");
|
|
192
|
+
const result = await akmClone({
|
|
193
|
+
sourceRef: `${searchPathDir}//script:deploy.sh`,
|
|
194
|
+
force: true,
|
|
195
|
+
dest: customDest,
|
|
196
|
+
});
|
|
197
|
+
expect(result.overwritten).toBe(true);
|
|
198
|
+
expect(fs.readFileSync(path.join(customDest, "scripts", "deploy.sh"), "utf8")).toBe("echo updated\n");
|
|
199
|
+
});
|
|
200
|
+
test("throws when asset exists at --dest without --force", async () => {
|
|
201
|
+
writeFile(path.join(searchPathDir, "scripts", "deploy.sh"), "echo new\n");
|
|
202
|
+
writeFile(path.join(customDest, "scripts", "deploy.sh"), "echo existing\n");
|
|
203
|
+
await expect(akmClone({ sourceRef: `${searchPathDir}//script:deploy.sh`, dest: customDest })).rejects.toThrow("already exists at destination");
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
describe("akmClone remote", () => {
|
|
207
|
+
let remoteFixtureDir;
|
|
208
|
+
beforeEach(() => {
|
|
209
|
+
// Create a fixture directory that simulates a remote package
|
|
210
|
+
remoteFixtureDir = createStashDir("akm-clone-remote-fixture-");
|
|
211
|
+
writeFile(path.join(remoteFixtureDir, "scripts", "remote-tool.sh"), "#!/bin/bash\necho remote\n");
|
|
212
|
+
writeFile(path.join(remoteFixtureDir, "skills", "remote-skill", "SKILL.md"), "# Remote Skill\n");
|
|
213
|
+
});
|
|
214
|
+
afterEach(() => {
|
|
215
|
+
if (remoteFixtureDir)
|
|
216
|
+
fs.rmSync(remoteFixtureDir, { recursive: true, force: true });
|
|
217
|
+
});
|
|
218
|
+
test("clones a script from a remote origin via installRegistryRef", async () => {
|
|
219
|
+
// Use bare path as origin — not in stashes, so isRemoteOrigin returns true
|
|
220
|
+
const result = await akmClone({
|
|
221
|
+
sourceRef: `${remoteFixtureDir}//script:remote-tool.sh`,
|
|
222
|
+
});
|
|
223
|
+
expect(result.remoteFetched).toBeDefined();
|
|
224
|
+
expect(result.remoteFetched?.origin).toBe(remoteFixtureDir);
|
|
225
|
+
expect(fs.existsSync(path.join(stashDir, "scripts", "remote-tool.sh"))).toBe(true);
|
|
226
|
+
expect(fs.readFileSync(path.join(stashDir, "scripts", "remote-tool.sh"), "utf8")).toBe("#!/bin/bash\necho remote\n");
|
|
227
|
+
});
|
|
228
|
+
test("returns remoteFetched metadata", async () => {
|
|
229
|
+
const result = await akmClone({
|
|
230
|
+
sourceRef: `${remoteFixtureDir}//script:remote-tool.sh`,
|
|
231
|
+
});
|
|
232
|
+
expect(result.remoteFetched).toBeDefined();
|
|
233
|
+
expect(result.remoteFetched?.stashRoot).toBeTruthy();
|
|
234
|
+
expect(result.remoteFetched?.cacheDir).toBeTruthy();
|
|
235
|
+
});
|
|
236
|
+
test("throws when remote fetch succeeds but asset not found in package", async () => {
|
|
237
|
+
await expect(akmClone({ sourceRef: `${remoteFixtureDir}//script:nonexistent.sh` })).rejects.toThrow("not found");
|
|
238
|
+
});
|
|
239
|
+
test("clones from remote origin to custom destination", async () => {
|
|
240
|
+
const customDest = fs.mkdtempSync(path.join(os.tmpdir(), "akm-clone-remote-dest-"));
|
|
241
|
+
try {
|
|
242
|
+
const result = await akmClone({
|
|
243
|
+
sourceRef: `${remoteFixtureDir}//script:remote-tool.sh`,
|
|
244
|
+
dest: customDest,
|
|
245
|
+
});
|
|
246
|
+
expect(result.remoteFetched).toBeDefined();
|
|
247
|
+
expect(fs.existsSync(path.join(customDest, "scripts", "remote-tool.sh"))).toBe(true);
|
|
248
|
+
expect(result.destination.path).toBe(path.join(customDest, "scripts", "remote-tool.sh"));
|
|
249
|
+
}
|
|
250
|
+
finally {
|
|
251
|
+
fs.rmSync(customDest, { recursive: true, force: true });
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
});
|