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,394 @@
|
|
|
1
|
+
import { afterAll, afterEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { buildRegistryIndex, writeRegistryIndex } from "../src/registry/build-index";
|
|
7
|
+
const CLI = path.join(import.meta.dir, "..", "src", "cli.ts");
|
|
8
|
+
const tempDirs = [];
|
|
9
|
+
const servers = [];
|
|
10
|
+
function makeTempDir(prefix) {
|
|
11
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
12
|
+
tempDirs.push(dir);
|
|
13
|
+
return dir;
|
|
14
|
+
}
|
|
15
|
+
function writeFile(filePath, content) {
|
|
16
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
17
|
+
fs.writeFileSync(filePath, content, "utf8");
|
|
18
|
+
}
|
|
19
|
+
function createTarball(sourceDir, archivePath) {
|
|
20
|
+
const result = spawnSync("tar", ["czf", archivePath, "-C", path.dirname(sourceDir), path.basename(sourceDir)], {
|
|
21
|
+
encoding: "utf8",
|
|
22
|
+
timeout: 30_000,
|
|
23
|
+
});
|
|
24
|
+
expect(result.status).toBe(0);
|
|
25
|
+
}
|
|
26
|
+
function createRegistryServer(npmArchivePath, githubArchivePath) {
|
|
27
|
+
const server = Bun.serve({
|
|
28
|
+
port: 0,
|
|
29
|
+
async fetch(request) {
|
|
30
|
+
const url = new URL(request.url);
|
|
31
|
+
const pathname = url.pathname;
|
|
32
|
+
if (pathname === "/-/v1/search") {
|
|
33
|
+
return Response.json({
|
|
34
|
+
objects: [
|
|
35
|
+
{
|
|
36
|
+
package: {
|
|
37
|
+
name: "agent-stash",
|
|
38
|
+
version: "1.2.3",
|
|
39
|
+
description: "npm description",
|
|
40
|
+
keywords: ["akm-stash", "deploy"],
|
|
41
|
+
links: {
|
|
42
|
+
homepage: "https://example.test/agent-stash",
|
|
43
|
+
repository: "https://github.com/acme/agent-stash",
|
|
44
|
+
},
|
|
45
|
+
author: { name: "acme" },
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (pathname === "/agent-stash/latest") {
|
|
52
|
+
return Response.json({
|
|
53
|
+
version: "1.2.3",
|
|
54
|
+
description: "npm latest description",
|
|
55
|
+
keywords: ["akm-stash", "deploy", "review"],
|
|
56
|
+
license: "MIT",
|
|
57
|
+
dist: {
|
|
58
|
+
tarball: `${url.origin}/archives/npm-agent-stash.tgz`,
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (pathname === "/search/repositories") {
|
|
63
|
+
return Response.json({
|
|
64
|
+
items: [
|
|
65
|
+
{
|
|
66
|
+
full_name: "acme/release-stash",
|
|
67
|
+
name: "release-stash",
|
|
68
|
+
description: "github description",
|
|
69
|
+
html_url: "https://github.com/acme/release-stash",
|
|
70
|
+
owner: { login: "acme" },
|
|
71
|
+
license: { spdx_id: "Apache-2.0" },
|
|
72
|
+
topics: ["akm-stash", "release"],
|
|
73
|
+
default_branch: "main",
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (pathname === "/repos/acme/release-stash/tarball/main") {
|
|
79
|
+
return new Response(Bun.file(githubArchivePath), {
|
|
80
|
+
headers: { "Content-Type": "application/gzip" },
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (pathname === "/archives/npm-agent-stash.tgz") {
|
|
84
|
+
return new Response(Bun.file(npmArchivePath), {
|
|
85
|
+
headers: { "Content-Type": "application/gzip" },
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return new Response("not found", { status: 404 });
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
servers.push(server);
|
|
92
|
+
return `http://127.0.0.1:${server.port}`;
|
|
93
|
+
}
|
|
94
|
+
afterEach(() => {
|
|
95
|
+
while (servers.length > 0) {
|
|
96
|
+
servers.pop()?.stop(true);
|
|
97
|
+
}
|
|
98
|
+
while (tempDirs.length > 0) {
|
|
99
|
+
fs.rmSync(tempDirs.pop() ?? "", { recursive: true, force: true });
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
afterAll(() => {
|
|
103
|
+
while (servers.length > 0) {
|
|
104
|
+
servers.pop()?.stop(true);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
describe("buildRegistryIndex", () => {
|
|
108
|
+
test("writeRegistryIndex defaults under the cache registry-build directory", () => {
|
|
109
|
+
const cacheHome = makeTempDir("akm-registry-cache-");
|
|
110
|
+
const originalCacheHome = process.env.XDG_CACHE_HOME;
|
|
111
|
+
process.env.XDG_CACHE_HOME = cacheHome;
|
|
112
|
+
try {
|
|
113
|
+
const outPath = writeRegistryIndex({ version: 3, updatedAt: "2026-05-01T00:00:00.000Z", stashes: [] });
|
|
114
|
+
expect(outPath).toBe(path.join(cacheHome, "akm", "registry-build", "index.json"));
|
|
115
|
+
expect(fs.existsSync(outPath)).toBe(true);
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
if (originalCacheHome === undefined)
|
|
119
|
+
delete process.env.XDG_CACHE_HOME;
|
|
120
|
+
else
|
|
121
|
+
process.env.XDG_CACHE_HOME = originalCacheHome;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
test("builds a v2 index from discovery and manual entries", async () => {
|
|
125
|
+
const fixtureRoot = makeTempDir("akm-registry-build-fixture-");
|
|
126
|
+
const npmPackageDir = path.join(fixtureRoot, "package");
|
|
127
|
+
writeFile(path.join(npmPackageDir, "package.json"), JSON.stringify({
|
|
128
|
+
name: "agent-stash",
|
|
129
|
+
version: "1.2.3",
|
|
130
|
+
description: "package archive description",
|
|
131
|
+
keywords: ["akm-stash", "deploy", "review"],
|
|
132
|
+
license: "MIT",
|
|
133
|
+
}));
|
|
134
|
+
writeFile(path.join(npmPackageDir, "scripts", "deploy.sh"), "#!/usr/bin/env bash\n");
|
|
135
|
+
writeFile(path.join(npmPackageDir, "skills", "review", "SKILL.md"), "---\ndescription: Review code\n---\n");
|
|
136
|
+
const npmArchivePath = path.join(fixtureRoot, "npm-agent-stash.tgz");
|
|
137
|
+
createTarball(npmPackageDir, npmArchivePath);
|
|
138
|
+
const githubRepoDir = path.join(fixtureRoot, "release-stash-main");
|
|
139
|
+
writeFile(path.join(githubRepoDir, "package.json"), JSON.stringify({
|
|
140
|
+
name: "release-stash",
|
|
141
|
+
version: "0.4.0",
|
|
142
|
+
description: "repo archive description",
|
|
143
|
+
keywords: ["akm-stash", "release", "automation"],
|
|
144
|
+
}));
|
|
145
|
+
writeFile(path.join(githubRepoDir, "agents", "planner.md"), "---\ndescription: Plan releases\n---\n");
|
|
146
|
+
writeFile(path.join(githubRepoDir, "commands", "release.md"), "Use $ARGUMENTS\n");
|
|
147
|
+
const githubArchivePath = path.join(fixtureRoot, "github-release-stash.tgz");
|
|
148
|
+
createTarball(githubRepoDir, githubArchivePath);
|
|
149
|
+
const serverBase = createRegistryServer(npmArchivePath, githubArchivePath);
|
|
150
|
+
const manualEntriesPath = path.join(fixtureRoot, "manual-entries.json");
|
|
151
|
+
fs.writeFileSync(manualEntriesPath, `${JSON.stringify([
|
|
152
|
+
{
|
|
153
|
+
id: "npm:agent-stash",
|
|
154
|
+
name: "Agent Stash",
|
|
155
|
+
description: "manual description",
|
|
156
|
+
ref: "agent-stash",
|
|
157
|
+
source: "npm",
|
|
158
|
+
tags: ["curated"],
|
|
159
|
+
assets: [{ type: "knowledge", name: "guide", description: "Manual guide" }],
|
|
160
|
+
curated: true,
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
id: "github:manual/only",
|
|
164
|
+
name: "Manual Only",
|
|
165
|
+
description: "manual only entry",
|
|
166
|
+
ref: "manual/only",
|
|
167
|
+
source: "github",
|
|
168
|
+
assetTypes: ["skill"],
|
|
169
|
+
curated: true,
|
|
170
|
+
},
|
|
171
|
+
], null, 2)}\n`, "utf8");
|
|
172
|
+
const result = await buildRegistryIndex({
|
|
173
|
+
manualEntriesPath,
|
|
174
|
+
npmRegistryBase: serverBase,
|
|
175
|
+
githubApiBase: serverBase,
|
|
176
|
+
});
|
|
177
|
+
expect(result.index.version).toBe(3);
|
|
178
|
+
expect(result.counts).toEqual({ manual: 2, npm: 1, github: 1, total: 3 });
|
|
179
|
+
const npmStash = result.index.stashes.find((stash) => stash.id === "npm:agent-stash");
|
|
180
|
+
expect(npmStash).toBeDefined();
|
|
181
|
+
expect(npmStash?.description).toBe("manual description");
|
|
182
|
+
// v1 spec §4.2: the legacy `curated` boolean is removed. The builder must
|
|
183
|
+
// not surface it on emitted stash entries even when input contained it.
|
|
184
|
+
expect(npmStash).not.toHaveProperty("curated");
|
|
185
|
+
expect(npmStash?.assetTypes).toEqual(["knowledge", "script", "skill"]);
|
|
186
|
+
expect(npmStash?.tags).toEqual(["curated", "deploy", "review"]);
|
|
187
|
+
expect(npmStash?.assets?.map((asset) => `${asset.type}:${asset.name}`)).toEqual([
|
|
188
|
+
"knowledge:guide",
|
|
189
|
+
"script:deploy.sh",
|
|
190
|
+
"skill:review",
|
|
191
|
+
]);
|
|
192
|
+
const githubStash = result.index.stashes.find((stash) => stash.id === "github:acme/release-stash");
|
|
193
|
+
expect(githubStash).toBeDefined();
|
|
194
|
+
expect(githubStash?.assetTypes).toEqual(["agent", "command"]);
|
|
195
|
+
expect(githubStash?.assets?.map((asset) => `${asset.type}:${asset.name}`)).toEqual([
|
|
196
|
+
"agent:planner",
|
|
197
|
+
"command:release",
|
|
198
|
+
]);
|
|
199
|
+
expect(githubStash?.assets?.every((asset) => typeof asset.estimatedTokens === "number")).toBe(true);
|
|
200
|
+
expect(githubStash?.latestVersion).toBe("0.4.0");
|
|
201
|
+
expect(githubStash?.tags).toEqual(["automation", "release"]);
|
|
202
|
+
const manualOnlyStash = result.index.stashes.find((stash) => stash.id === "github:manual/only");
|
|
203
|
+
expect(manualOnlyStash).toBeDefined();
|
|
204
|
+
// v1 spec §4.2: legacy `curated` from manual entries is silently ignored.
|
|
205
|
+
expect(manualOnlyStash).not.toHaveProperty("curated");
|
|
206
|
+
expect(manualOnlyStash?.assetTypes).toEqual(["skill"]);
|
|
207
|
+
});
|
|
208
|
+
test("legacy curated key parses without error", async () => {
|
|
209
|
+
// v1 spec §4.2: `curated: true` is a removed legacy field on registry
|
|
210
|
+
// entries. Manual-entry JSON in the wild may still contain it. The
|
|
211
|
+
// builder MUST silently ignore it (not throw, not fail validation),
|
|
212
|
+
// and the entry MUST still be processed end-to-end.
|
|
213
|
+
const fixtureRoot = makeTempDir("akm-registry-build-legacy-curated-");
|
|
214
|
+
const githubRepoDir = path.join(fixtureRoot, "release-stash-main");
|
|
215
|
+
writeFile(path.join(githubRepoDir, "commands", "release.md"), "Use $ARGUMENTS\n");
|
|
216
|
+
const githubArchivePath = path.join(fixtureRoot, "github-release-stash.tgz");
|
|
217
|
+
createTarball(githubRepoDir, githubArchivePath);
|
|
218
|
+
const npmPackageDir = path.join(fixtureRoot, "package");
|
|
219
|
+
writeFile(path.join(npmPackageDir, "package.json"), JSON.stringify({ name: "agent-stash", version: "1.2.3" }));
|
|
220
|
+
const npmArchivePath = path.join(fixtureRoot, "npm-agent-stash.tgz");
|
|
221
|
+
createTarball(npmPackageDir, npmArchivePath);
|
|
222
|
+
const serverBase = createRegistryServer(npmArchivePath, githubArchivePath);
|
|
223
|
+
const manualEntriesPath = path.join(fixtureRoot, "manual-entries.json");
|
|
224
|
+
fs.writeFileSync(manualEntriesPath, `${JSON.stringify([
|
|
225
|
+
{
|
|
226
|
+
id: "github:legacy/curated",
|
|
227
|
+
name: "Legacy Curated",
|
|
228
|
+
description: "entry retaining the removed `curated: true` field",
|
|
229
|
+
ref: "legacy/curated",
|
|
230
|
+
source: "github",
|
|
231
|
+
assetTypes: ["skill"],
|
|
232
|
+
curated: true,
|
|
233
|
+
},
|
|
234
|
+
], null, 2)}\n`, "utf8");
|
|
235
|
+
await expect(buildRegistryIndex({
|
|
236
|
+
manualEntriesPath,
|
|
237
|
+
npmRegistryBase: serverBase,
|
|
238
|
+
githubApiBase: serverBase,
|
|
239
|
+
})).resolves.toBeDefined();
|
|
240
|
+
// Re-run to inspect the actual result; resolves above proves no throw.
|
|
241
|
+
const result = await buildRegistryIndex({
|
|
242
|
+
manualEntriesPath,
|
|
243
|
+
npmRegistryBase: serverBase,
|
|
244
|
+
githubApiBase: serverBase,
|
|
245
|
+
});
|
|
246
|
+
// Non-empty kit list proves the legacy entry was processed, not silently
|
|
247
|
+
// dropped on parse error.
|
|
248
|
+
expect(result.index.stashes.length).toBeGreaterThan(0);
|
|
249
|
+
const legacyStash = result.index.stashes.find((stash) => stash.id === "github:legacy/curated");
|
|
250
|
+
expect(legacyStash).toBeDefined();
|
|
251
|
+
expect(legacyStash).not.toHaveProperty("curated");
|
|
252
|
+
});
|
|
253
|
+
test("respects .stash.json metadata and akm.include when enriching assets", async () => {
|
|
254
|
+
const fixtureRoot = makeTempDir("akm-registry-build-include-");
|
|
255
|
+
const npmPackageDir = path.join(fixtureRoot, "package");
|
|
256
|
+
writeFile(path.join(npmPackageDir, "package.json"), JSON.stringify({
|
|
257
|
+
name: "agent-stash",
|
|
258
|
+
version: "1.2.3",
|
|
259
|
+
akm: { include: ["skills", "docs"] },
|
|
260
|
+
}));
|
|
261
|
+
writeFile(path.join(npmPackageDir, "scripts", "ignored.sh"), "#!/usr/bin/env bash\n");
|
|
262
|
+
writeFile(path.join(npmPackageDir, "skills", "review", "SKILL.md"), "# Review\n");
|
|
263
|
+
writeFile(path.join(npmPackageDir, "skills", "review", ".stash.json"), JSON.stringify({
|
|
264
|
+
entries: [
|
|
265
|
+
{
|
|
266
|
+
name: "review",
|
|
267
|
+
type: "skill",
|
|
268
|
+
filename: "SKILL.md",
|
|
269
|
+
description: "Curated review workflow",
|
|
270
|
+
tags: ["quality", "code-review"],
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
}));
|
|
274
|
+
writeFile(path.join(npmPackageDir, "docs", "guide.md"), "# Guide\n");
|
|
275
|
+
const npmArchivePath = path.join(fixtureRoot, "npm-agent-stash.tgz");
|
|
276
|
+
createTarball(npmPackageDir, npmArchivePath);
|
|
277
|
+
const githubRepoDir = path.join(fixtureRoot, "release-stash-main");
|
|
278
|
+
writeFile(path.join(githubRepoDir, "commands", "release.md"), "Use $ARGUMENTS\n");
|
|
279
|
+
const githubArchivePath = path.join(fixtureRoot, "github-release-stash.tgz");
|
|
280
|
+
createTarball(githubRepoDir, githubArchivePath);
|
|
281
|
+
const serverBase = createRegistryServer(npmArchivePath, githubArchivePath);
|
|
282
|
+
const manualEntriesPath = path.join(fixtureRoot, "manual-entries.json");
|
|
283
|
+
fs.writeFileSync(manualEntriesPath, "[]\n", "utf8");
|
|
284
|
+
const result = await buildRegistryIndex({
|
|
285
|
+
manualEntriesPath,
|
|
286
|
+
npmRegistryBase: serverBase,
|
|
287
|
+
githubApiBase: serverBase,
|
|
288
|
+
});
|
|
289
|
+
const npmStash = result.index.stashes.find((stash) => stash.id === "npm:agent-stash");
|
|
290
|
+
expect(npmStash?.assetTypes).toEqual(["knowledge", "skill"]);
|
|
291
|
+
expect(npmStash?.assets?.map((asset) => `${asset.type}:${asset.name}`)).toEqual([
|
|
292
|
+
"knowledge:docs/guide",
|
|
293
|
+
"skill:review",
|
|
294
|
+
]);
|
|
295
|
+
const reviewAsset = npmStash?.assets?.find((asset) => asset.type === "skill" && asset.name === "review");
|
|
296
|
+
expect(reviewAsset?.description).toBe("Curated review workflow");
|
|
297
|
+
expect(reviewAsset?.tags).toEqual(["quality", "code-review"]);
|
|
298
|
+
expect(reviewAsset?.estimatedTokens).toBeGreaterThan(0);
|
|
299
|
+
expect(npmStash?.assets?.some((asset) => asset.name === "ignored.sh")).toBe(false);
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
function waitForChild(child, timeoutMs) {
|
|
303
|
+
return new Promise((resolve, reject) => {
|
|
304
|
+
let stdout = "";
|
|
305
|
+
let stderr = "";
|
|
306
|
+
let settled = false;
|
|
307
|
+
child.stdout?.on("data", (chunk) => {
|
|
308
|
+
stdout += String(chunk);
|
|
309
|
+
});
|
|
310
|
+
child.stderr?.on("data", (chunk) => {
|
|
311
|
+
stderr += String(chunk);
|
|
312
|
+
});
|
|
313
|
+
const timer = setTimeout(() => {
|
|
314
|
+
if (!settled) {
|
|
315
|
+
settled = true;
|
|
316
|
+
child.kill("SIGKILL");
|
|
317
|
+
reject(new Error(`Child process timed out after ${timeoutMs}ms\nstdout: ${stdout}\nstderr: ${stderr}`));
|
|
318
|
+
}
|
|
319
|
+
}, timeoutMs);
|
|
320
|
+
child.on("error", (err) => {
|
|
321
|
+
if (!settled) {
|
|
322
|
+
settled = true;
|
|
323
|
+
clearTimeout(timer);
|
|
324
|
+
reject(err);
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
child.on("close", (code) => {
|
|
328
|
+
if (!settled) {
|
|
329
|
+
settled = true;
|
|
330
|
+
clearTimeout(timer);
|
|
331
|
+
resolve({ code: code ?? 1, stdout, stderr });
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
describe("akm registry build-index", () => {
|
|
337
|
+
test("writes the generated index to disk", async () => {
|
|
338
|
+
const fixtureRoot = makeTempDir("akm-registry-build-cli-");
|
|
339
|
+
const npmPackageDir = path.join(fixtureRoot, "package");
|
|
340
|
+
writeFile(path.join(npmPackageDir, "package.json"), JSON.stringify({ name: "agent-stash", version: "1.2.3" }));
|
|
341
|
+
writeFile(path.join(npmPackageDir, "scripts", "deploy.sh"), "#!/usr/bin/env bash\n");
|
|
342
|
+
const npmArchivePath = path.join(fixtureRoot, "npm-agent-stash.tgz");
|
|
343
|
+
createTarball(npmPackageDir, npmArchivePath);
|
|
344
|
+
const githubRepoDir = path.join(fixtureRoot, "release-stash-main");
|
|
345
|
+
writeFile(path.join(githubRepoDir, "commands", "release.md"), "Use $ARGUMENTS\n");
|
|
346
|
+
const githubArchivePath = path.join(fixtureRoot, "github-release-stash.tgz");
|
|
347
|
+
createTarball(githubRepoDir, githubArchivePath);
|
|
348
|
+
const serverBase = createRegistryServer(npmArchivePath, githubArchivePath);
|
|
349
|
+
const manualEntriesPath = path.join(fixtureRoot, "manual-entries.json");
|
|
350
|
+
fs.writeFileSync(manualEntriesPath, "[]\n", "utf8");
|
|
351
|
+
const outPath = path.join(fixtureRoot, "out", "index.json");
|
|
352
|
+
const xdgCache = makeTempDir("akm-registry-build-cache-");
|
|
353
|
+
const xdgConfig = makeTempDir("akm-registry-build-config-");
|
|
354
|
+
const homeDir = makeTempDir("akm-registry-build-home-");
|
|
355
|
+
const child = spawn("bun", [
|
|
356
|
+
CLI,
|
|
357
|
+
"registry",
|
|
358
|
+
"build-index",
|
|
359
|
+
"--format=json",
|
|
360
|
+
"--out",
|
|
361
|
+
outPath,
|
|
362
|
+
"--manual",
|
|
363
|
+
manualEntriesPath,
|
|
364
|
+
"--npmRegistry",
|
|
365
|
+
serverBase,
|
|
366
|
+
"--githubApi",
|
|
367
|
+
serverBase,
|
|
368
|
+
], {
|
|
369
|
+
cwd: path.join(import.meta.dir, ".."),
|
|
370
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
371
|
+
env: {
|
|
372
|
+
...process.env,
|
|
373
|
+
HOME: homeDir,
|
|
374
|
+
NO_PROXY: "127.0.0.1,localhost",
|
|
375
|
+
GITHUB_TOKEN: "",
|
|
376
|
+
XDG_CACHE_HOME: xdgCache,
|
|
377
|
+
XDG_CONFIG_HOME: xdgConfig,
|
|
378
|
+
},
|
|
379
|
+
});
|
|
380
|
+
const result = await waitForChild(child, 30_000);
|
|
381
|
+
if (result.code !== 0) {
|
|
382
|
+
console.error("stderr:", result.stderr);
|
|
383
|
+
console.error("stdout:", result.stdout);
|
|
384
|
+
}
|
|
385
|
+
expect(result.code).toBe(0);
|
|
386
|
+
expect(result.stderr.trim()).toBe("");
|
|
387
|
+
const stdout = JSON.parse(result.stdout.trim());
|
|
388
|
+
expect(stdout.outPath).toBe(outPath);
|
|
389
|
+
expect(stdout.totalKits).toBe(2);
|
|
390
|
+
const written = JSON.parse(fs.readFileSync(outPath, "utf8"));
|
|
391
|
+
expect(written.version).toBe(3);
|
|
392
|
+
expect(written.stashes.map((stash) => stash.id)).toEqual(["npm:agent-stash", "github:acme/release-stash"]);
|
|
393
|
+
}, { timeout: 60_000 });
|
|
394
|
+
});
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { afterAll, 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 { resolveRegistries, searchRegistry } from "../src/commands/registry-search";
|
|
6
|
+
import { getConfigPath, loadConfig, saveConfig } from "../src/core/config";
|
|
7
|
+
// ── Helpers ─────────────────────────────────────────────────────────────────
|
|
8
|
+
const createdTmpDirs = [];
|
|
9
|
+
function createTmpDir(prefix = "akm-reg-cli-") {
|
|
10
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
11
|
+
createdTmpDirs.push(dir);
|
|
12
|
+
return dir;
|
|
13
|
+
}
|
|
14
|
+
function writeConfig(configPath, config) {
|
|
15
|
+
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
16
|
+
fs.writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`);
|
|
17
|
+
}
|
|
18
|
+
function serveIndex(index) {
|
|
19
|
+
const body = JSON.stringify(index);
|
|
20
|
+
const server = Bun.serve({
|
|
21
|
+
port: 0,
|
|
22
|
+
fetch() {
|
|
23
|
+
return new Response(body, {
|
|
24
|
+
headers: { "Content-Type": "application/json" },
|
|
25
|
+
});
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
url: `http://localhost:${server.port}/index.json`,
|
|
30
|
+
close: () => server.stop(true),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
afterAll(() => {
|
|
34
|
+
for (const dir of createdTmpDirs) {
|
|
35
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const originalXdgConfigHome = process.env.XDG_CONFIG_HOME;
|
|
39
|
+
const originalXdgCacheHome = process.env.XDG_CACHE_HOME;
|
|
40
|
+
const originalRegistryUrl = process.env.AKM_REGISTRY_URL;
|
|
41
|
+
beforeEach(() => {
|
|
42
|
+
process.env.XDG_CONFIG_HOME = createTmpDir("akm-reg-config-");
|
|
43
|
+
process.env.XDG_CACHE_HOME = createTmpDir("akm-reg-cache-");
|
|
44
|
+
delete process.env.AKM_REGISTRY_URL;
|
|
45
|
+
});
|
|
46
|
+
afterEach(() => {
|
|
47
|
+
if (originalXdgConfigHome === undefined) {
|
|
48
|
+
delete process.env.XDG_CONFIG_HOME;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
process.env.XDG_CONFIG_HOME = originalXdgConfigHome;
|
|
52
|
+
}
|
|
53
|
+
if (originalXdgCacheHome === undefined) {
|
|
54
|
+
delete process.env.XDG_CACHE_HOME;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
process.env.XDG_CACHE_HOME = originalXdgCacheHome;
|
|
58
|
+
}
|
|
59
|
+
if (originalRegistryUrl === undefined) {
|
|
60
|
+
delete process.env.AKM_REGISTRY_URL;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
process.env.AKM_REGISTRY_URL = originalRegistryUrl;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
// ── Registry add/remove/list ─────────────────────────────────────────────────
|
|
67
|
+
describe("registry add/remove/list via config", () => {
|
|
68
|
+
test("list returns default registries when none configured", () => {
|
|
69
|
+
const config = loadConfig();
|
|
70
|
+
const registries = config.registries ?? [];
|
|
71
|
+
expect(registries.length).toBe(2);
|
|
72
|
+
expect(registries[0].name).toBe("official");
|
|
73
|
+
expect(registries[0].url).toContain("akm-registry");
|
|
74
|
+
expect(registries[1].name).toBe("skills.sh");
|
|
75
|
+
expect(registries[1].provider).toBe("skills-sh");
|
|
76
|
+
});
|
|
77
|
+
test("add appends a registry entry", () => {
|
|
78
|
+
const config = loadConfig();
|
|
79
|
+
const registries = [...(config.registries ?? [])];
|
|
80
|
+
const newEntry = { url: "https://example.com/index.json", name: "custom" };
|
|
81
|
+
registries.push(newEntry);
|
|
82
|
+
saveConfig({ ...config, registries });
|
|
83
|
+
const updated = loadConfig();
|
|
84
|
+
expect(updated.registries?.length).toBe(3);
|
|
85
|
+
expect(updated.registries?.[2].url).toBe("https://example.com/index.json");
|
|
86
|
+
expect(updated.registries?.[2].name).toBe("custom");
|
|
87
|
+
});
|
|
88
|
+
test("add deduplicates by URL", () => {
|
|
89
|
+
// Start with a known registry entry
|
|
90
|
+
const url = "https://example.com/dedup-test.json";
|
|
91
|
+
const config = loadConfig();
|
|
92
|
+
const registries = [...(config.registries ?? [])];
|
|
93
|
+
registries.push({ url, name: "dedup-target" });
|
|
94
|
+
saveConfig({ ...config, registries });
|
|
95
|
+
// Verify it was added
|
|
96
|
+
const afterFirst = loadConfig();
|
|
97
|
+
const countAfterFirst = afterFirst.registries?.length ?? 0;
|
|
98
|
+
// Try to add the same URL again using the CLI's dedup logic
|
|
99
|
+
const current = loadConfig();
|
|
100
|
+
const currentRegistries = [...(current.registries ?? [])];
|
|
101
|
+
if (!currentRegistries.some((r) => r.url === url)) {
|
|
102
|
+
currentRegistries.push({ url, name: "dedup-target" });
|
|
103
|
+
}
|
|
104
|
+
saveConfig({ ...current, registries: currentRegistries });
|
|
105
|
+
// Verify length is unchanged — the duplicate was rejected
|
|
106
|
+
const afterSecond = loadConfig();
|
|
107
|
+
expect(afterSecond.registries?.length).toBe(countAfterFirst);
|
|
108
|
+
});
|
|
109
|
+
test("remove by URL", () => {
|
|
110
|
+
const config = loadConfig();
|
|
111
|
+
const registries = [
|
|
112
|
+
{ url: "https://example.com/a.json", name: "a" },
|
|
113
|
+
{ url: "https://example.com/b.json", name: "b" },
|
|
114
|
+
];
|
|
115
|
+
saveConfig({ ...config, registries });
|
|
116
|
+
const current = loadConfig();
|
|
117
|
+
const remaining = (current.registries ?? []).filter((r) => r.url !== "https://example.com/a.json");
|
|
118
|
+
saveConfig({ ...current, registries: remaining });
|
|
119
|
+
const final = loadConfig();
|
|
120
|
+
expect(final.registries?.length).toBe(1);
|
|
121
|
+
expect(final.registries?.[0].name).toBe("b");
|
|
122
|
+
});
|
|
123
|
+
test("remove by name", () => {
|
|
124
|
+
const config = loadConfig();
|
|
125
|
+
const registries = [
|
|
126
|
+
{ url: "https://example.com/a.json", name: "alpha" },
|
|
127
|
+
{ url: "https://example.com/b.json", name: "beta" },
|
|
128
|
+
];
|
|
129
|
+
saveConfig({ ...config, registries });
|
|
130
|
+
const current = loadConfig();
|
|
131
|
+
const remaining = (current.registries ?? []).filter((r) => r.name !== "alpha");
|
|
132
|
+
saveConfig({ ...current, registries: remaining });
|
|
133
|
+
const final = loadConfig();
|
|
134
|
+
expect(final.registries?.length).toBe(1);
|
|
135
|
+
expect(final.registries?.[0].name).toBe("beta");
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
// ── resolveRegistries ───────────────────────────────────────────────────────
|
|
139
|
+
describe("resolveRegistries", () => {
|
|
140
|
+
test("filters out disabled registries", () => {
|
|
141
|
+
const entries = [
|
|
142
|
+
{ url: "https://a.com/index.json", name: "a", enabled: true },
|
|
143
|
+
{ url: "https://b.com/index.json", name: "b", enabled: false },
|
|
144
|
+
{ url: "https://c.com/index.json", name: "c" },
|
|
145
|
+
];
|
|
146
|
+
const resolved = resolveRegistries(entries);
|
|
147
|
+
expect(resolved.length).toBe(2);
|
|
148
|
+
expect(resolved.map((r) => r.name)).toEqual(["a", "c"]);
|
|
149
|
+
});
|
|
150
|
+
test("AKM_REGISTRY_URL env var overrides config", () => {
|
|
151
|
+
process.env.AKM_REGISTRY_URL = "https://override.com/index.json";
|
|
152
|
+
const resolved = resolveRegistries([{ url: "https://config.com/index.json" }]);
|
|
153
|
+
expect(resolved.length).toBe(1);
|
|
154
|
+
expect(resolved[0].url).toBe("https://override.com/index.json");
|
|
155
|
+
});
|
|
156
|
+
test("returns empty array when passed empty array", () => {
|
|
157
|
+
const resolved = resolveRegistries([]);
|
|
158
|
+
// Empty array passed explicitly — returns empty, no fallback
|
|
159
|
+
expect(resolved).toEqual([]);
|
|
160
|
+
});
|
|
161
|
+
test("returns default from config when no override", () => {
|
|
162
|
+
const resolved = resolveRegistries(undefined);
|
|
163
|
+
// Will read from loadConfig which returns DEFAULT_CONFIG registries
|
|
164
|
+
expect(resolved.length).toBeGreaterThan(0);
|
|
165
|
+
expect(resolved[0].name).toBe("official");
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
// ── Registry search with RegistryConfigEntry ────────────────────────────────
|
|
169
|
+
describe("registry search with config entries", () => {
|
|
170
|
+
test("basic query against mock index", async () => {
|
|
171
|
+
const index = {
|
|
172
|
+
version: 3,
|
|
173
|
+
updatedAt: "2026-01-01T00:00:00Z",
|
|
174
|
+
stashes: [
|
|
175
|
+
{
|
|
176
|
+
id: "npm:test-stash",
|
|
177
|
+
name: "Test Stash",
|
|
178
|
+
description: "A test stash for deploy",
|
|
179
|
+
ref: "test-stash",
|
|
180
|
+
source: "npm",
|
|
181
|
+
tags: ["deploy"],
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
};
|
|
185
|
+
const srv = serveIndex(index);
|
|
186
|
+
try {
|
|
187
|
+
const result = await searchRegistry("deploy", {
|
|
188
|
+
registries: [{ url: srv.url, name: "test-reg" }],
|
|
189
|
+
});
|
|
190
|
+
expect(result.hits.length).toBe(1);
|
|
191
|
+
expect(result.hits[0].id).toBe("npm:test-stash");
|
|
192
|
+
expect(result.hits[0].registryName).toBe("test-reg");
|
|
193
|
+
}
|
|
194
|
+
finally {
|
|
195
|
+
srv.close();
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
test("multi-registry search merges results from multiple URLs", async () => {
|
|
199
|
+
const index1 = {
|
|
200
|
+
version: 3,
|
|
201
|
+
updatedAt: "2026-01-01T00:00:00Z",
|
|
202
|
+
stashes: [
|
|
203
|
+
{
|
|
204
|
+
id: "npm:stash-one",
|
|
205
|
+
name: "Stash One",
|
|
206
|
+
description: "First stash for build",
|
|
207
|
+
ref: "stash-one",
|
|
208
|
+
source: "npm",
|
|
209
|
+
tags: ["build"],
|
|
210
|
+
},
|
|
211
|
+
],
|
|
212
|
+
};
|
|
213
|
+
const index2 = {
|
|
214
|
+
version: 3,
|
|
215
|
+
updatedAt: "2026-01-01T00:00:00Z",
|
|
216
|
+
stashes: [
|
|
217
|
+
{
|
|
218
|
+
id: "github:org/stash-two",
|
|
219
|
+
name: "Stash Two",
|
|
220
|
+
description: "Second stash for build automation",
|
|
221
|
+
ref: "org/stash-two",
|
|
222
|
+
source: "github",
|
|
223
|
+
tags: ["build"],
|
|
224
|
+
},
|
|
225
|
+
],
|
|
226
|
+
};
|
|
227
|
+
const srv1 = serveIndex(index1);
|
|
228
|
+
const srv2 = serveIndex(index2);
|
|
229
|
+
try {
|
|
230
|
+
const result = await searchRegistry("build", {
|
|
231
|
+
registries: [
|
|
232
|
+
{ url: srv1.url, name: "primary" },
|
|
233
|
+
{ url: srv2.url, name: "secondary" },
|
|
234
|
+
],
|
|
235
|
+
});
|
|
236
|
+
expect(result.hits.length).toBe(2);
|
|
237
|
+
const ids = result.hits.map((h) => h.id);
|
|
238
|
+
expect(ids).toContain("npm:stash-one");
|
|
239
|
+
expect(ids).toContain("github:org/stash-two");
|
|
240
|
+
// Verify provenance
|
|
241
|
+
const stash1Hit = result.hits.find((h) => h.id === "npm:stash-one");
|
|
242
|
+
const stash2Hit = result.hits.find((h) => h.id === "github:org/stash-two");
|
|
243
|
+
expect(stash1Hit?.registryName).toBe("primary");
|
|
244
|
+
expect(stash2Hit?.registryName).toBe("secondary");
|
|
245
|
+
}
|
|
246
|
+
finally {
|
|
247
|
+
srv1.close();
|
|
248
|
+
srv2.close();
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
test("disabled registries are skipped via resolveRegistries before search", () => {
|
|
252
|
+
const entries = [
|
|
253
|
+
{ url: "https://enabled.com/index.json", name: "enabled", enabled: true },
|
|
254
|
+
{ url: "https://disabled.com/index.json", name: "disabled", enabled: false },
|
|
255
|
+
];
|
|
256
|
+
const resolved = resolveRegistries(entries);
|
|
257
|
+
expect(resolved.length).toBe(1);
|
|
258
|
+
expect(resolved[0].name).toBe("enabled");
|
|
259
|
+
});
|
|
260
|
+
});
|
|
261
|
+
// ── Config roundtrip for registries ─────────────────────────────────────────
|
|
262
|
+
describe("config roundtrip", () => {
|
|
263
|
+
test("registries persist through save/load cycle", () => {
|
|
264
|
+
const registries = [
|
|
265
|
+
{ url: "https://a.com/index.json", name: "alpha" },
|
|
266
|
+
{ url: "https://b.com/index.json", name: "beta", enabled: false },
|
|
267
|
+
];
|
|
268
|
+
saveConfig({ semanticSearchMode: "auto", registries });
|
|
269
|
+
const loaded = loadConfig();
|
|
270
|
+
expect(loaded.registries?.length).toBe(2);
|
|
271
|
+
expect(loaded.registries?.[0]).toEqual({ url: "https://a.com/index.json", name: "alpha" });
|
|
272
|
+
expect(loaded.registries?.[1]).toEqual({ url: "https://b.com/index.json", name: "beta", enabled: false });
|
|
273
|
+
});
|
|
274
|
+
test("invalid registry entries are filtered during load", () => {
|
|
275
|
+
const configPath = getConfigPath();
|
|
276
|
+
writeConfig(configPath, {
|
|
277
|
+
semanticSearchMode: "auto",
|
|
278
|
+
registries: [
|
|
279
|
+
{ url: "https://valid.com/index.json", name: "valid" },
|
|
280
|
+
{ url: "", name: "empty-url" },
|
|
281
|
+
{ name: "no-url" },
|
|
282
|
+
42,
|
|
283
|
+
null,
|
|
284
|
+
],
|
|
285
|
+
});
|
|
286
|
+
const loaded = loadConfig();
|
|
287
|
+
expect(loaded.registries?.length).toBe(1);
|
|
288
|
+
expect(loaded.registries?.[0].url).toBe("https://valid.com/index.json");
|
|
289
|
+
});
|
|
290
|
+
});
|