akm-cli 0.6.1 → 0.7.0
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} +712 -34
- package/dist/{commands → src/commands}/config-cli.js +47 -4
- package/dist/src/commands/distill.js +283 -0
- package/dist/src/commands/events.js +108 -0
- package/dist/src/commands/history.js +191 -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 +71 -7
- package/dist/{commands → src/commands}/remember.js +12 -0
- package/dist/{commands → src/commands}/search.js +104 -4
- package/dist/{commands → src/commands}/self-update.js +4 -3
- package/dist/{commands → src/commands}/show.js +73 -0
- package/dist/{commands → src/commands}/source-add.js +5 -1
- package/dist/{commands → src/commands}/source-manage.js +7 -1
- 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 +203 -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 +114 -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 +88 -7
- package/dist/{indexer → src/indexer}/matchers.js +1 -1
- package/dist/src/indexer/memory-inference.js +263 -0
- package/dist/{indexer → src/indexer}/metadata.js +111 -3
- package/dist/{indexer → src/indexer}/search-source.js +4 -2
- 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 +272 -0
- package/dist/{integrations → src/integrations}/github.js +9 -3
- package/dist/{integrations → src/integrations}/lockfile.js +0 -26
- package/dist/{llm → src/llm}/client.js +33 -2
- package/dist/{llm → src/llm}/embedders/remote.js +37 -3
- 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}/cli-hints.js +15 -2
- package/dist/{output → src/output}/renderers.js +63 -2
- package/dist/src/output/shapes.js +523 -0
- package/dist/src/output/text.js +1116 -0
- package/dist/{registry → src/registry}/build-index.js +19 -8
- package/dist/{registry → src/registry}/factory.js +0 -8
- package/dist/{registry → src/registry}/providers/static-index.js +6 -3
- package/dist/{registry → src/registry}/resolve.js +68 -2
- package/dist/{setup → src/setup}/setup.js +52 -5
- package/dist/{sources → src/sources}/providers/git.js +7 -15
- package/dist/{wiki → src/wiki}/wiki.js +54 -6
- package/dist/{workflows → src/workflows}/runs.js +37 -3
- 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 +996 -0
- package/dist/tests/bench/cleanup-sigint.test.js +83 -0
- package/dist/tests/bench/cleanup.js +234 -0
- package/dist/tests/bench/cleanup.test.js +166 -0
- package/dist/tests/bench/cli.js +1018 -0
- package/dist/tests/bench/cli.test.js +445 -0
- package/dist/tests/bench/compare.test.js +556 -0
- package/dist/tests/bench/corpus.js +317 -0
- package/dist/tests/bench/corpus.test.js +258 -0
- package/dist/tests/bench/doctor.js +525 -0
- package/dist/tests/bench/driver.js +401 -0
- package/dist/tests/bench/driver.test.js +584 -0
- package/dist/tests/bench/environment.js +233 -0
- package/dist/tests/bench/environment.test.js +199 -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 +647 -0
- package/dist/tests/bench/evolve.test.js +624 -0
- package/dist/tests/bench/failure-modes.test.js +349 -0
- package/dist/tests/bench/feedback-integrity.test.js +457 -0
- package/dist/tests/bench/leakage.test.js +228 -0
- package/dist/tests/bench/learning-curve.test.js +134 -0
- package/dist/tests/bench/metrics.js +2395 -0
- package/dist/tests/bench/metrics.test.js +1150 -0
- package/dist/tests/bench/no-os-tmpdir-invariant.test.js +43 -0
- package/dist/tests/bench/opencode-config.js +194 -0
- package/dist/tests/bench/opencode-config.test.js +370 -0
- package/dist/tests/bench/report.js +1885 -0
- package/dist/tests/bench/report.test.js +1038 -0
- package/dist/tests/bench/run-config.js +355 -0
- package/dist/tests/bench/run-config.test.js +298 -0
- package/dist/tests/bench/run-curate-test.js +32 -0
- package/dist/tests/bench/run-failing-tasks.js +56 -0
- package/dist/tests/bench/run-full-bench.js +51 -0
- package/dist/tests/bench/run-items36-targeted.js +69 -0
- package/dist/tests/bench/run-nano-quick.js +42 -0
- package/dist/tests/bench/run-waveg-targeted.js +62 -0
- package/dist/tests/bench/runner.js +699 -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 +131 -0
- package/dist/tests/bench/trajectory.js +116 -0
- package/dist/tests/bench/trajectory.test.js +127 -0
- package/dist/tests/bench/verifier.js +114 -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 +345 -0
- package/dist/tests/bench/workflow-spec.test.js +363 -0
- package/dist/tests/bench/workflow-trace.js +472 -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 +204 -0
- package/dist/tests/commands/events.test.js +370 -0
- package/dist/tests/commands/history.test.js +418 -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 +569 -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 +1419 -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 +97 -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 +570 -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 +218 -0
- package/dist/tests/output-shapes-unit.test.js +478 -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 +394 -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 +238 -0
- package/dist/tests/registry-resolve.test.js +126 -0
- package/dist/tests/registry-search.test.js +923 -0
- package/dist/tests/remember-frontmatter.test.js +378 -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 +286 -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 +281 -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 +395 -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/output/text.js +0 -520
- /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-clone.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}/search-fields.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/{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/types.js +0 -0
- /package/dist/{llm → src/llm}/metadata-enhance.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/{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}/schema.js +0 -0
- /package/dist/{workflows → src/workflows}/validator.js +0 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `akm search --include-proposed` CLI integration test (#284 GAP-HIGH 9).
|
|
3
|
+
*
|
|
4
|
+
* Spawns the real CLI against an indexed stash that contains both a
|
|
5
|
+
* `quality: stable` and a `quality: proposed` skill, and asserts that:
|
|
6
|
+
* - default search excludes the proposed entry,
|
|
7
|
+
* - `--include-proposed` retains it in the hits list.
|
|
8
|
+
*/
|
|
9
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
10
|
+
import { spawnSync } from "node:child_process";
|
|
11
|
+
import fs from "node:fs";
|
|
12
|
+
import os from "node:os";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
import { saveConfig } from "../src/core/config";
|
|
15
|
+
import { akmIndex } from "../src/indexer/indexer";
|
|
16
|
+
const tempDirs = [];
|
|
17
|
+
const savedEnv = {
|
|
18
|
+
AKM_STASH_DIR: process.env.AKM_STASH_DIR,
|
|
19
|
+
XDG_CACHE_HOME: process.env.XDG_CACHE_HOME,
|
|
20
|
+
XDG_CONFIG_HOME: process.env.XDG_CONFIG_HOME,
|
|
21
|
+
};
|
|
22
|
+
function makeTempDir(prefix) {
|
|
23
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
24
|
+
tempDirs.push(dir);
|
|
25
|
+
return dir;
|
|
26
|
+
}
|
|
27
|
+
function writeFile(filePath, content) {
|
|
28
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
29
|
+
fs.writeFileSync(filePath, content);
|
|
30
|
+
}
|
|
31
|
+
const CLI = path.join(__dirname, "..", "src", "cli.ts");
|
|
32
|
+
function runCli(args, stashDir) {
|
|
33
|
+
const result = spawnSync("bun", [CLI, ...args], {
|
|
34
|
+
encoding: "utf8",
|
|
35
|
+
timeout: 30_000,
|
|
36
|
+
env: {
|
|
37
|
+
...process.env,
|
|
38
|
+
AKM_STASH_DIR: stashDir,
|
|
39
|
+
XDG_CACHE_HOME: process.env.XDG_CACHE_HOME,
|
|
40
|
+
XDG_CONFIG_HOME: process.env.XDG_CONFIG_HOME,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
stdout: result.stdout ?? "",
|
|
45
|
+
stderr: result.stderr ?? "",
|
|
46
|
+
status: result.status ?? -1,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
if (savedEnv.AKM_STASH_DIR === undefined)
|
|
51
|
+
delete process.env.AKM_STASH_DIR;
|
|
52
|
+
else
|
|
53
|
+
process.env.AKM_STASH_DIR = savedEnv.AKM_STASH_DIR;
|
|
54
|
+
if (savedEnv.XDG_CACHE_HOME === undefined)
|
|
55
|
+
delete process.env.XDG_CACHE_HOME;
|
|
56
|
+
else
|
|
57
|
+
process.env.XDG_CACHE_HOME = savedEnv.XDG_CACHE_HOME;
|
|
58
|
+
if (savedEnv.XDG_CONFIG_HOME === undefined)
|
|
59
|
+
delete process.env.XDG_CONFIG_HOME;
|
|
60
|
+
else
|
|
61
|
+
process.env.XDG_CONFIG_HOME = savedEnv.XDG_CONFIG_HOME;
|
|
62
|
+
for (const dir of tempDirs.splice(0)) {
|
|
63
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
describe("akm search --include-proposed (CLI)", () => {
|
|
67
|
+
test("default excludes proposed entries; --include-proposed keeps them", async () => {
|
|
68
|
+
const stash = makeTempDir("akm-search-proposed-stash-");
|
|
69
|
+
process.env.XDG_CACHE_HOME = makeTempDir("akm-search-proposed-cache-");
|
|
70
|
+
process.env.XDG_CONFIG_HOME = makeTempDir("akm-search-proposed-config-");
|
|
71
|
+
for (const sub of ["skills", "commands", "agents", "knowledge", "scripts"]) {
|
|
72
|
+
fs.mkdirSync(path.join(stash, sub), { recursive: true });
|
|
73
|
+
}
|
|
74
|
+
// Curated entry
|
|
75
|
+
writeFile(path.join(stash, "skills", "stable-deploy", "SKILL.md"), "---\ndescription: deploy widgets uniformly\n---\n# Stable deploy\n");
|
|
76
|
+
writeFile(path.join(stash, "skills", "stable-deploy", ".stash.json"), JSON.stringify({
|
|
77
|
+
entries: [
|
|
78
|
+
{
|
|
79
|
+
name: "stable-deploy",
|
|
80
|
+
type: "skill",
|
|
81
|
+
description: "deploy widgets uniformly",
|
|
82
|
+
tags: ["deploy"],
|
|
83
|
+
filename: "SKILL.md",
|
|
84
|
+
quality: "curated",
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
}));
|
|
88
|
+
// Proposed entry
|
|
89
|
+
writeFile(path.join(stash, "skills", "proposed-deploy", "SKILL.md"), "---\ndescription: deploy widgets experimentally\n---\n# Proposed deploy\n");
|
|
90
|
+
writeFile(path.join(stash, "skills", "proposed-deploy", ".stash.json"), JSON.stringify({
|
|
91
|
+
entries: [
|
|
92
|
+
{
|
|
93
|
+
name: "proposed-deploy",
|
|
94
|
+
type: "skill",
|
|
95
|
+
description: "deploy widgets experimentally",
|
|
96
|
+
tags: ["deploy"],
|
|
97
|
+
filename: "SKILL.md",
|
|
98
|
+
quality: "proposed",
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
}));
|
|
102
|
+
process.env.AKM_STASH_DIR = stash;
|
|
103
|
+
saveConfig({ semanticSearchMode: "off" });
|
|
104
|
+
await akmIndex({ stashDir: stash, full: true });
|
|
105
|
+
const baseline = runCli(["search", "deploy", "--format=json"], stash);
|
|
106
|
+
expect(baseline.status).toBe(0);
|
|
107
|
+
const baselineJson = JSON.parse(baseline.stdout);
|
|
108
|
+
const baselineNames = baselineJson.hits.map((h) => h.name);
|
|
109
|
+
expect(baselineNames).toContain("stable-deploy");
|
|
110
|
+
expect(baselineNames).not.toContain("proposed-deploy");
|
|
111
|
+
const withProposed = runCli(["search", "deploy", "--include-proposed", "--format=json"], stash);
|
|
112
|
+
expect(withProposed.status).toBe(0);
|
|
113
|
+
const withProposedJson = JSON.parse(withProposed.stdout);
|
|
114
|
+
const withProposedNames = withProposedJson.hits.map((h) => h.name);
|
|
115
|
+
expect(withProposedNames).toContain("stable-deploy");
|
|
116
|
+
expect(withProposedNames).toContain("proposed-deploy");
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { afterEach, describe, expect, mock, spyOn, test } from "bun:test";
|
|
2
|
+
import * as childProcess from "node:child_process";
|
|
3
|
+
import { checkForUpdate, detectInstallMethod, getAkmBinaryName, getPackageManagerUpgradeCommand, performUpgrade, } from "../src/commands/self-update";
|
|
4
|
+
// ── Fetch mocking helper ────────────────────────────────────────────────────
|
|
5
|
+
let originalFetch;
|
|
6
|
+
function mockFetch(handler) {
|
|
7
|
+
originalFetch = globalThis.fetch;
|
|
8
|
+
globalThis.fetch = (async (input) => {
|
|
9
|
+
const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
|
10
|
+
return handler(url);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
mock.restore();
|
|
15
|
+
if (originalFetch) {
|
|
16
|
+
globalThis.fetch = originalFetch;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
function fakeRelease(tagName) {
|
|
20
|
+
return Response.json({ tag_name: tagName });
|
|
21
|
+
}
|
|
22
|
+
// ── detectInstallMethod ─────────────────────────────────────────────────────
|
|
23
|
+
describe("detectInstallMethod", () => {
|
|
24
|
+
test("returns a valid install method when running via bun run (not compiled)", () => {
|
|
25
|
+
const method = detectInstallMethod();
|
|
26
|
+
// In test context we're running from source. May be "binary" if AKM_VERSION
|
|
27
|
+
// is defined (e.g. compiled test runner), otherwise "unknown" or a package-manager install.
|
|
28
|
+
expect(["unknown", "npm", "pnpm", "bun", "binary"]).toContain(method);
|
|
29
|
+
});
|
|
30
|
+
test("does not throw", () => {
|
|
31
|
+
expect(() => detectInstallMethod()).not.toThrow();
|
|
32
|
+
});
|
|
33
|
+
test("returns 'binary' when Bun.main starts with /$bunfs/", () => {
|
|
34
|
+
const signals = {
|
|
35
|
+
bunMain: "/$bunfs/root/src/cli.ts",
|
|
36
|
+
importMetaDir: "/some/path",
|
|
37
|
+
hasAkmVersion: false,
|
|
38
|
+
};
|
|
39
|
+
expect(detectInstallMethod(signals)).toBe("binary");
|
|
40
|
+
});
|
|
41
|
+
test("returns 'binary' when AKM_VERSION is defined (fallback)", () => {
|
|
42
|
+
const signals = {
|
|
43
|
+
bunMain: "/usr/local/bin/akm",
|
|
44
|
+
importMetaDir: "/some/path",
|
|
45
|
+
hasAkmVersion: true,
|
|
46
|
+
};
|
|
47
|
+
expect(detectInstallMethod(signals)).toBe("binary");
|
|
48
|
+
});
|
|
49
|
+
test("returns 'bun' for Bun global install path", () => {
|
|
50
|
+
const signals = {
|
|
51
|
+
bunMain: "/usr/local/bin/bun",
|
|
52
|
+
importMetaDir: "/home/user/.bun/install/global/node_modules/akm-cli/dist",
|
|
53
|
+
hasAkmVersion: false,
|
|
54
|
+
};
|
|
55
|
+
expect(detectInstallMethod(signals)).toBe("bun");
|
|
56
|
+
});
|
|
57
|
+
test("returns 'bun' for Windows-style Bun global install path", () => {
|
|
58
|
+
const signals = {
|
|
59
|
+
bunMain: "C:\\Program Files\\Bun\\bun.exe",
|
|
60
|
+
importMetaDir: "C:\\Users\\me\\.bun\\install\\global\\node_modules\\akm-cli\\dist",
|
|
61
|
+
hasAkmVersion: false,
|
|
62
|
+
};
|
|
63
|
+
expect(detectInstallMethod(signals)).toBe("bun");
|
|
64
|
+
});
|
|
65
|
+
test("returns 'pnpm' for pnpm global install path", () => {
|
|
66
|
+
const signals = {
|
|
67
|
+
bunMain: "/usr/local/bin/bun",
|
|
68
|
+
importMetaDir: "/home/user/.local/share/pnpm/global/5/node_modules/akm-cli/dist",
|
|
69
|
+
hasAkmVersion: false,
|
|
70
|
+
};
|
|
71
|
+
expect(detectInstallMethod(signals)).toBe("pnpm");
|
|
72
|
+
});
|
|
73
|
+
test("returns 'pnpm' for Windows-style pnpm global install path", () => {
|
|
74
|
+
const signals = {
|
|
75
|
+
bunMain: "C:\\Program Files\\Bun\\bun.exe",
|
|
76
|
+
importMetaDir: "C:\\Users\\me\\AppData\\Local\\pnpm\\global\\5\\node_modules\\akm-cli\\dist",
|
|
77
|
+
hasAkmVersion: false,
|
|
78
|
+
};
|
|
79
|
+
expect(detectInstallMethod(signals)).toBe("pnpm");
|
|
80
|
+
});
|
|
81
|
+
test("returns 'npm' when importMetaDir contains node_modules without bun/pnpm markers", () => {
|
|
82
|
+
const signals = {
|
|
83
|
+
bunMain: "/usr/local/bin/bun",
|
|
84
|
+
importMetaDir: "/usr/local/lib/node_modules/akm-cli/dist",
|
|
85
|
+
hasAkmVersion: false,
|
|
86
|
+
};
|
|
87
|
+
expect(detectInstallMethod(signals)).toBe("npm");
|
|
88
|
+
});
|
|
89
|
+
test("package-manager detection takes priority over binary signals", () => {
|
|
90
|
+
const signals = {
|
|
91
|
+
bunMain: "/$bunfs/root/src/cli.ts",
|
|
92
|
+
importMetaDir: "/some/node_modules/akm",
|
|
93
|
+
hasAkmVersion: true,
|
|
94
|
+
};
|
|
95
|
+
expect(detectInstallMethod(signals)).toBe("npm");
|
|
96
|
+
});
|
|
97
|
+
test("returns 'unknown' when no signals match", () => {
|
|
98
|
+
const signals = {
|
|
99
|
+
bunMain: undefined,
|
|
100
|
+
importMetaDir: "/some/path",
|
|
101
|
+
hasAkmVersion: false,
|
|
102
|
+
};
|
|
103
|
+
expect(detectInstallMethod(signals)).toBe("unknown");
|
|
104
|
+
});
|
|
105
|
+
test("returns 'unknown' when Bun is present but no binary indicators", () => {
|
|
106
|
+
const signals = {
|
|
107
|
+
bunMain: "/home/user/akm/src/cli.ts",
|
|
108
|
+
importMetaDir: "/home/user/akm/src",
|
|
109
|
+
hasAkmVersion: false,
|
|
110
|
+
};
|
|
111
|
+
expect(detectInstallMethod(signals)).toBe("unknown");
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
// ── getAkmBinaryName ────────────────────────────────────────────────────────
|
|
115
|
+
describe("getAkmBinaryName", () => {
|
|
116
|
+
test("returns a string containing 'akm'", () => {
|
|
117
|
+
const name = getAkmBinaryName();
|
|
118
|
+
expect(name).toContain("akm");
|
|
119
|
+
});
|
|
120
|
+
test("returns platform-appropriate name for current platform", () => {
|
|
121
|
+
const name = getAkmBinaryName();
|
|
122
|
+
const platform = process.platform;
|
|
123
|
+
const arch = process.arch;
|
|
124
|
+
if (platform === "linux") {
|
|
125
|
+
expect(name).toStartWith("akm-linux-");
|
|
126
|
+
}
|
|
127
|
+
else if (platform === "darwin") {
|
|
128
|
+
expect(name).toStartWith("akm-darwin-");
|
|
129
|
+
}
|
|
130
|
+
else if (platform === "win32") {
|
|
131
|
+
expect(name).toStartWith("akm-windows-");
|
|
132
|
+
expect(name).toEndWith(".exe");
|
|
133
|
+
}
|
|
134
|
+
if (arch === "x64") {
|
|
135
|
+
expect(name).toContain("x64");
|
|
136
|
+
}
|
|
137
|
+
else if (arch === "arm64") {
|
|
138
|
+
expect(name).toContain("arm64");
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
// ── checkForUpdate (mocked fetch) ───────────────────────────────────────────
|
|
143
|
+
describe("checkForUpdate", () => {
|
|
144
|
+
test("returns valid UpgradeCheckResponse", async () => {
|
|
145
|
+
mockFetch(() => fakeRelease("v0.0.14"));
|
|
146
|
+
const result = await checkForUpdate("0.0.13");
|
|
147
|
+
expect(result.currentVersion).toBe("0.0.13");
|
|
148
|
+
expect(result.latestVersion).toBe("0.0.14");
|
|
149
|
+
expect(result.updateAvailable).toBe(true);
|
|
150
|
+
expect(["binary", "bun", "npm", "pnpm", "unknown"]).toContain(result.installMethod);
|
|
151
|
+
});
|
|
152
|
+
test("updateAvailable is false when current matches latest", async () => {
|
|
153
|
+
mockFetch(() => fakeRelease("v0.0.13"));
|
|
154
|
+
const result = await checkForUpdate("0.0.13");
|
|
155
|
+
expect(result.updateAvailable).toBe(false);
|
|
156
|
+
expect(result.latestVersion).toBe("0.0.13");
|
|
157
|
+
});
|
|
158
|
+
test("updateAvailable is true for an old version", async () => {
|
|
159
|
+
mockFetch(() => fakeRelease("v0.0.14"));
|
|
160
|
+
const result = await checkForUpdate("0.0.0");
|
|
161
|
+
expect(result.updateAvailable).toBe(true);
|
|
162
|
+
expect(result.currentVersion).toBe("0.0.0");
|
|
163
|
+
expect(result.latestVersion).toBe("0.0.14");
|
|
164
|
+
});
|
|
165
|
+
test("handles missing tag_name gracefully", async () => {
|
|
166
|
+
mockFetch(() => Response.json({}));
|
|
167
|
+
const result = await checkForUpdate("0.0.13");
|
|
168
|
+
expect(result.latestVersion).toBe("");
|
|
169
|
+
expect(result.updateAvailable).toBe(false);
|
|
170
|
+
});
|
|
171
|
+
test("throws on non-OK response", async () => {
|
|
172
|
+
mockFetch(() => new Response("Not Found", { status: 404, statusText: "Not Found" }));
|
|
173
|
+
await expect(checkForUpdate("0.0.13")).rejects.toThrow("Failed to check for updates");
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
// ── performUpgrade ──────────────────────────────────────────────────────────
|
|
177
|
+
describe("performUpgrade", () => {
|
|
178
|
+
test("runs npm global install for npm installs", async () => {
|
|
179
|
+
const spawnSyncSpy = spyOn(childProcess, "spawnSync").mockReturnValue({
|
|
180
|
+
status: 0,
|
|
181
|
+
stdout: "",
|
|
182
|
+
stderr: "",
|
|
183
|
+
});
|
|
184
|
+
const result = await performUpgrade({
|
|
185
|
+
currentVersion: "0.0.13",
|
|
186
|
+
latestVersion: "0.0.14",
|
|
187
|
+
updateAvailable: true,
|
|
188
|
+
installMethod: "npm",
|
|
189
|
+
});
|
|
190
|
+
expect(spawnSyncSpy).toHaveBeenCalledWith(expect.stringContaining("npm"), ["install", "-g", "akm-cli@latest"], expect.objectContaining({ encoding: "utf8", stdio: "pipe" }));
|
|
191
|
+
expect(result.upgraded).toBe(true);
|
|
192
|
+
expect(result.installMethod).toBe("npm");
|
|
193
|
+
});
|
|
194
|
+
test("runs bun global install for bun installs", async () => {
|
|
195
|
+
const spawnSyncSpy = spyOn(childProcess, "spawnSync").mockReturnValue({
|
|
196
|
+
status: 0,
|
|
197
|
+
stdout: "",
|
|
198
|
+
stderr: "",
|
|
199
|
+
});
|
|
200
|
+
const result = await performUpgrade({
|
|
201
|
+
currentVersion: "0.0.13",
|
|
202
|
+
latestVersion: "0.0.14",
|
|
203
|
+
updateAvailable: true,
|
|
204
|
+
installMethod: "bun",
|
|
205
|
+
});
|
|
206
|
+
expect(spawnSyncSpy).toHaveBeenCalledWith(expect.stringContaining("bun"), ["install", "-g", "akm-cli@latest"], expect.objectContaining({ encoding: "utf8", stdio: "pipe" }));
|
|
207
|
+
expect(result.upgraded).toBe(true);
|
|
208
|
+
expect(result.installMethod).toBe("bun");
|
|
209
|
+
});
|
|
210
|
+
test("runs pnpm global add for pnpm installs", async () => {
|
|
211
|
+
const spawnSyncSpy = spyOn(childProcess, "spawnSync").mockReturnValue({
|
|
212
|
+
status: 0,
|
|
213
|
+
stdout: "",
|
|
214
|
+
stderr: "",
|
|
215
|
+
});
|
|
216
|
+
const result = await performUpgrade({
|
|
217
|
+
currentVersion: "0.0.13",
|
|
218
|
+
latestVersion: "0.0.14",
|
|
219
|
+
updateAvailable: true,
|
|
220
|
+
installMethod: "pnpm",
|
|
221
|
+
});
|
|
222
|
+
expect(spawnSyncSpy).toHaveBeenCalledWith(expect.stringContaining("pnpm"), ["add", "-g", "akm-cli@latest"], expect.objectContaining({ encoding: "utf8", stdio: "pipe" }));
|
|
223
|
+
expect(result.upgraded).toBe(true);
|
|
224
|
+
expect(result.installMethod).toBe("pnpm");
|
|
225
|
+
});
|
|
226
|
+
test("returns guidance message for unknown install method", async () => {
|
|
227
|
+
const result = await performUpgrade({
|
|
228
|
+
currentVersion: "0.0.13",
|
|
229
|
+
latestVersion: "0.0.14",
|
|
230
|
+
updateAvailable: true,
|
|
231
|
+
installMethod: "unknown",
|
|
232
|
+
});
|
|
233
|
+
expect(result.upgraded).toBe(false);
|
|
234
|
+
expect(result.installMethod).toBe("unknown");
|
|
235
|
+
expect(result.message).toContain("manually");
|
|
236
|
+
});
|
|
237
|
+
test("returns already-latest message when no update available", async () => {
|
|
238
|
+
const result = await performUpgrade({
|
|
239
|
+
currentVersion: "0.0.13",
|
|
240
|
+
latestVersion: "0.0.13",
|
|
241
|
+
updateAvailable: false,
|
|
242
|
+
installMethod: "binary",
|
|
243
|
+
});
|
|
244
|
+
expect(result.upgraded).toBe(false);
|
|
245
|
+
expect(result.message).toContain("already the latest");
|
|
246
|
+
});
|
|
247
|
+
test("runs `akm index` post-upgrade after a successful pkg-manager install", async () => {
|
|
248
|
+
const spawnSyncSpy = spyOn(childProcess, "spawnSync").mockReturnValue({
|
|
249
|
+
status: 0,
|
|
250
|
+
stdout: "",
|
|
251
|
+
stderr: "",
|
|
252
|
+
});
|
|
253
|
+
const result = await performUpgrade({
|
|
254
|
+
currentVersion: "0.0.13",
|
|
255
|
+
latestVersion: "0.0.14",
|
|
256
|
+
updateAvailable: true,
|
|
257
|
+
installMethod: "npm",
|
|
258
|
+
});
|
|
259
|
+
expect(result.upgraded).toBe(true);
|
|
260
|
+
expect(result.postUpgrade).toBeDefined();
|
|
261
|
+
expect(result.postUpgrade?.ok).toBe(true);
|
|
262
|
+
expect(result.postUpgrade?.skipped).toBe(false);
|
|
263
|
+
expect(result.postUpgrade?.exitCode).toBe(0);
|
|
264
|
+
// First spawnSync = the install; second spawnSync = the post-upgrade `akm index`.
|
|
265
|
+
expect(spawnSyncSpy).toHaveBeenCalledTimes(2);
|
|
266
|
+
expect(spawnSyncSpy).toHaveBeenLastCalledWith("akm", ["index"], expect.objectContaining({ encoding: "utf8", stdio: "pipe" }));
|
|
267
|
+
});
|
|
268
|
+
test("skips the post-upgrade `akm index` when skipPostUpgrade is set", async () => {
|
|
269
|
+
const spawnSyncSpy = spyOn(childProcess, "spawnSync").mockReturnValue({
|
|
270
|
+
status: 0,
|
|
271
|
+
stdout: "",
|
|
272
|
+
stderr: "",
|
|
273
|
+
});
|
|
274
|
+
const result = await performUpgrade({
|
|
275
|
+
currentVersion: "0.0.13",
|
|
276
|
+
latestVersion: "0.0.14",
|
|
277
|
+
updateAvailable: true,
|
|
278
|
+
installMethod: "npm",
|
|
279
|
+
}, { skipPostUpgrade: true });
|
|
280
|
+
expect(result.upgraded).toBe(true);
|
|
281
|
+
expect(result.postUpgrade).toBeDefined();
|
|
282
|
+
expect(result.postUpgrade?.skipped).toBe(true);
|
|
283
|
+
expect(result.postUpgrade?.ok).toBe(true);
|
|
284
|
+
// Only the install spawnSync ran — no second call for `akm index`.
|
|
285
|
+
expect(spawnSyncSpy).toHaveBeenCalledTimes(1);
|
|
286
|
+
});
|
|
287
|
+
test("captures post-upgrade failure without failing the upgrade", async () => {
|
|
288
|
+
let call = 0;
|
|
289
|
+
const spawnSyncSpy = spyOn(childProcess, "spawnSync").mockImplementation((() => {
|
|
290
|
+
call++;
|
|
291
|
+
if (call === 1) {
|
|
292
|
+
// The install itself succeeds.
|
|
293
|
+
return { status: 0, stdout: "", stderr: "" };
|
|
294
|
+
}
|
|
295
|
+
// The post-upgrade `akm index` fails with a non-zero exit.
|
|
296
|
+
return { status: 1, stdout: "", stderr: "no embedding model configured" };
|
|
297
|
+
}));
|
|
298
|
+
const result = await performUpgrade({
|
|
299
|
+
currentVersion: "0.0.13",
|
|
300
|
+
latestVersion: "0.0.14",
|
|
301
|
+
updateAvailable: true,
|
|
302
|
+
installMethod: "npm",
|
|
303
|
+
});
|
|
304
|
+
expect(result.upgraded).toBe(true); // upgrade itself succeeded
|
|
305
|
+
expect(result.postUpgrade?.ok).toBe(false);
|
|
306
|
+
expect(result.postUpgrade?.exitCode).toBe(1);
|
|
307
|
+
expect(result.postUpgrade?.message).toContain("no embedding model configured");
|
|
308
|
+
expect(spawnSyncSpy).toHaveBeenCalledTimes(2);
|
|
309
|
+
});
|
|
310
|
+
test("throws when latestVersion is empty and force is used", async () => {
|
|
311
|
+
await expect(performUpgrade({
|
|
312
|
+
currentVersion: "0.0.13",
|
|
313
|
+
latestVersion: "",
|
|
314
|
+
updateAvailable: false,
|
|
315
|
+
installMethod: "binary",
|
|
316
|
+
}, { force: true })).rejects.toThrow("Unable to determine latest version");
|
|
317
|
+
});
|
|
318
|
+
// Note: tests for the binary install path (installMethod: "binary") that test
|
|
319
|
+
// checksum verification must avoid actually reaching the filesystem write step,
|
|
320
|
+
// which would overwrite the running bun binary. We mock the download to return
|
|
321
|
+
// a non-OK status after the checksum check fails, so the code throws before
|
|
322
|
+
// trying to write to disk.
|
|
323
|
+
test("blocks upgrade when checksum URL returns 404 (default)", async () => {
|
|
324
|
+
mockFetch((url) => {
|
|
325
|
+
if (url.includes("checksums.txt"))
|
|
326
|
+
return new Response("", { status: 404, statusText: "Not Found" });
|
|
327
|
+
// Use a non-OK download response so the code throws before reaching the write step
|
|
328
|
+
return new Response("", { status: 500 });
|
|
329
|
+
});
|
|
330
|
+
// The binary download fails first (500), but if checksum fetch is tried before
|
|
331
|
+
// binary download, it should throw a checksum error.
|
|
332
|
+
const spawnSyncSpy = spyOn(childProcess, "spawnSync").mockReturnValue({
|
|
333
|
+
status: 0,
|
|
334
|
+
stdout: "",
|
|
335
|
+
stderr: "",
|
|
336
|
+
});
|
|
337
|
+
await expect(performUpgrade({
|
|
338
|
+
currentVersion: "0.0.13",
|
|
339
|
+
latestVersion: "0.0.14",
|
|
340
|
+
updateAvailable: true,
|
|
341
|
+
installMethod: "npm",
|
|
342
|
+
}, { skipPostUpgrade: true })).resolves.toMatchObject({ upgraded: true, installMethod: "npm" });
|
|
343
|
+
// Only the install spawnSync ran; skipPostUpgrade keeps the test focused
|
|
344
|
+
// on the checksum-bypass behavior, not the new post-upgrade hook.
|
|
345
|
+
expect(spawnSyncSpy).toHaveBeenCalledTimes(1);
|
|
346
|
+
});
|
|
347
|
+
test("checksum URL 404 throws Checksum verification failed for binary install", async () => {
|
|
348
|
+
// Use a mock that: binary download succeeds, checksum returns 404.
|
|
349
|
+
// IMPORTANT: We ensure the test does NOT write to disk by making the checksum
|
|
350
|
+
// step fail first (it runs after binary download).
|
|
351
|
+
mockFetch((url) => {
|
|
352
|
+
if (url.includes("checksums.txt"))
|
|
353
|
+
return new Response("", { status: 404 });
|
|
354
|
+
// Fake binary download — must succeed for checksum check to be reached
|
|
355
|
+
return new Response(new Uint8Array(100), { status: 200 });
|
|
356
|
+
});
|
|
357
|
+
await expect(performUpgrade({
|
|
358
|
+
currentVersion: "0.0.13",
|
|
359
|
+
latestVersion: "0.0.14",
|
|
360
|
+
updateAvailable: true,
|
|
361
|
+
installMethod: "binary",
|
|
362
|
+
})).rejects.toThrow(/Checksum verification failed/);
|
|
363
|
+
});
|
|
364
|
+
test("skipChecksum: true option is accepted by performUpgrade (npm path)", async () => {
|
|
365
|
+
const spawnSyncSpy = spyOn(childProcess, "spawnSync").mockReturnValue({
|
|
366
|
+
status: 0,
|
|
367
|
+
stdout: "",
|
|
368
|
+
stderr: "",
|
|
369
|
+
});
|
|
370
|
+
const result = await performUpgrade({
|
|
371
|
+
currentVersion: "0.0.13",
|
|
372
|
+
latestVersion: "0.0.14",
|
|
373
|
+
updateAvailable: true,
|
|
374
|
+
installMethod: "npm",
|
|
375
|
+
}, { skipChecksum: true, skipPostUpgrade: true });
|
|
376
|
+
// Only the install spawnSync ran; skipPostUpgrade keeps the test focused
|
|
377
|
+
// on the skipChecksum option, not the new post-upgrade hook.
|
|
378
|
+
expect(spawnSyncSpy).toHaveBeenCalledTimes(1);
|
|
379
|
+
expect(result.upgraded).toBe(true);
|
|
380
|
+
expect(result.installMethod).toBe("npm");
|
|
381
|
+
});
|
|
382
|
+
test("blocks upgrade when binary name not in checksums.txt (default)", async () => {
|
|
383
|
+
const binaryName = getAkmBinaryName();
|
|
384
|
+
mockFetch((url) => {
|
|
385
|
+
if (url.includes("checksums.txt")) {
|
|
386
|
+
// Valid checksums format but does NOT include the current binary name
|
|
387
|
+
return new Response(`${"a".repeat(64)} other-binary\n${"b".repeat(64)} another-binary\n`, { status: 200 });
|
|
388
|
+
}
|
|
389
|
+
return new Response(new Uint8Array(100), { status: 200 });
|
|
390
|
+
});
|
|
391
|
+
await expect(performUpgrade({
|
|
392
|
+
currentVersion: "0.0.13",
|
|
393
|
+
latestVersion: "0.0.14",
|
|
394
|
+
updateAvailable: true,
|
|
395
|
+
installMethod: "binary",
|
|
396
|
+
})).rejects.toThrow(new RegExp(`${binaryName.replace(".", "\\.")}.*not listed|Checksum verification failed`));
|
|
397
|
+
});
|
|
398
|
+
test("blocks upgrade on checksum mismatch (default)", async () => {
|
|
399
|
+
const binaryName = getAkmBinaryName();
|
|
400
|
+
const wrongHash = "0".repeat(64);
|
|
401
|
+
mockFetch((url) => {
|
|
402
|
+
if (url.includes("checksums.txt")) {
|
|
403
|
+
return new Response(`${wrongHash} ${binaryName}\n`, { status: 200 });
|
|
404
|
+
}
|
|
405
|
+
// Return binary content that will NOT match the all-zeros hash
|
|
406
|
+
return new Response(new Uint8Array(Array.from({ length: 100 }, (_, i) => i % 256)), { status: 200 });
|
|
407
|
+
});
|
|
408
|
+
await expect(performUpgrade({
|
|
409
|
+
currentVersion: "0.0.13",
|
|
410
|
+
latestVersion: "0.0.14",
|
|
411
|
+
updateAvailable: true,
|
|
412
|
+
installMethod: "binary",
|
|
413
|
+
})).rejects.toThrow(/Checksum mismatch/);
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
describe("getPackageManagerUpgradeCommand", () => {
|
|
417
|
+
test("returns npm install command", () => {
|
|
418
|
+
expect(getPackageManagerUpgradeCommand("npm", "akm-cli")).toEqual({
|
|
419
|
+
command: expect.stringContaining("npm"),
|
|
420
|
+
args: ["install", "-g", "akm-cli@latest"],
|
|
421
|
+
displayCommand: "npm install -g akm-cli@latest",
|
|
422
|
+
});
|
|
423
|
+
});
|
|
424
|
+
test("returns bun install command", () => {
|
|
425
|
+
expect(getPackageManagerUpgradeCommand("bun", "akm-cli")).toEqual({
|
|
426
|
+
command: expect.stringContaining("bun"),
|
|
427
|
+
args: ["install", "-g", "akm-cli@latest"],
|
|
428
|
+
displayCommand: "bun install -g akm-cli@latest",
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
test("returns pnpm add command", () => {
|
|
432
|
+
expect(getPackageManagerUpgradeCommand("pnpm", "akm-cli")).toEqual({
|
|
433
|
+
command: expect.stringContaining("pnpm"),
|
|
434
|
+
args: ["add", "-g", "akm-cli@latest"],
|
|
435
|
+
displayCommand: "pnpm add -g akm-cli@latest",
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
test("returns undefined for non-package-manager installs", () => {
|
|
439
|
+
expect(getPackageManagerUpgradeCommand("binary", "akm-cli")).toBeUndefined();
|
|
440
|
+
expect(getPackageManagerUpgradeCommand("unknown", "akm-cli")).toBeUndefined();
|
|
441
|
+
});
|
|
442
|
+
});
|