akm-cli 0.7.0 → 0.7.1
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/package.json +8 -8
- package/dist/tests/add-website-source.test.js +0 -119
- package/dist/tests/agent/agent-config-loader.test.js +0 -70
- package/dist/tests/agent/agent-config.test.js +0 -221
- package/dist/tests/agent/agent-detect.test.js +0 -100
- package/dist/tests/agent/agent-spawn.test.js +0 -234
- package/dist/tests/agent-output.test.js +0 -186
- package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +0 -103
- package/dist/tests/architecture/agent-spawn-seam.test.js +0 -193
- package/dist/tests/architecture/llm-stateless-seam.test.js +0 -112
- package/dist/tests/asset-ref.test.js +0 -192
- package/dist/tests/asset-registry.test.js +0 -103
- package/dist/tests/asset-spec.test.js +0 -241
- package/dist/tests/bench/attribution.test.js +0 -996
- package/dist/tests/bench/cleanup-sigint.test.js +0 -83
- package/dist/tests/bench/cleanup.js +0 -234
- package/dist/tests/bench/cleanup.test.js +0 -166
- package/dist/tests/bench/cli.js +0 -1018
- package/dist/tests/bench/cli.test.js +0 -445
- package/dist/tests/bench/compare.test.js +0 -556
- package/dist/tests/bench/corpus.js +0 -317
- package/dist/tests/bench/corpus.test.js +0 -258
- package/dist/tests/bench/doctor.js +0 -525
- package/dist/tests/bench/driver.js +0 -401
- package/dist/tests/bench/driver.test.js +0 -584
- package/dist/tests/bench/environment.js +0 -233
- package/dist/tests/bench/environment.test.js +0 -199
- package/dist/tests/bench/evolve-metrics.js +0 -179
- package/dist/tests/bench/evolve-metrics.test.js +0 -187
- package/dist/tests/bench/evolve.js +0 -647
- package/dist/tests/bench/evolve.test.js +0 -624
- package/dist/tests/bench/failure-modes.test.js +0 -349
- package/dist/tests/bench/feedback-integrity.test.js +0 -457
- package/dist/tests/bench/leakage.test.js +0 -228
- package/dist/tests/bench/learning-curve.test.js +0 -134
- package/dist/tests/bench/metrics.js +0 -2395
- package/dist/tests/bench/metrics.test.js +0 -1150
- package/dist/tests/bench/no-os-tmpdir-invariant.test.js +0 -43
- package/dist/tests/bench/opencode-config.js +0 -194
- package/dist/tests/bench/opencode-config.test.js +0 -370
- package/dist/tests/bench/report.js +0 -1885
- package/dist/tests/bench/report.test.js +0 -1038
- package/dist/tests/bench/run-config.js +0 -355
- package/dist/tests/bench/run-config.test.js +0 -298
- package/dist/tests/bench/run-curate-test.js +0 -32
- package/dist/tests/bench/run-failing-tasks.js +0 -56
- package/dist/tests/bench/run-full-bench.js +0 -51
- package/dist/tests/bench/run-items36-targeted.js +0 -69
- package/dist/tests/bench/run-nano-quick.js +0 -42
- package/dist/tests/bench/run-waveg-targeted.js +0 -62
- package/dist/tests/bench/runner.js +0 -699
- package/dist/tests/bench/runner.test.js +0 -958
- package/dist/tests/bench/search-bridge.test.js +0 -331
- package/dist/tests/bench/tmp.js +0 -131
- package/dist/tests/bench/trajectory.js +0 -116
- package/dist/tests/bench/trajectory.test.js +0 -127
- package/dist/tests/bench/verifier.js +0 -114
- package/dist/tests/bench/verifier.test.js +0 -118
- package/dist/tests/bench/workflow-evaluator.js +0 -557
- package/dist/tests/bench/workflow-evaluator.test.js +0 -421
- package/dist/tests/bench/workflow-spec.js +0 -345
- package/dist/tests/bench/workflow-spec.test.js +0 -363
- package/dist/tests/bench/workflow-trace.js +0 -472
- package/dist/tests/bench/workflow-trace.test.js +0 -254
- package/dist/tests/benchmark-search-quality.js +0 -536
- package/dist/tests/benchmark-suite.js +0 -1441
- package/dist/tests/capture-cli.test.js +0 -112
- package/dist/tests/cli-errors.test.js +0 -204
- package/dist/tests/commands/events.test.js +0 -370
- package/dist/tests/commands/history.test.js +0 -418
- package/dist/tests/commands/import.test.js +0 -103
- package/dist/tests/commands/proposal-cli.test.js +0 -209
- package/dist/tests/commands/reflect-propose-cli.test.js +0 -333
- package/dist/tests/commands/remember.test.js +0 -97
- package/dist/tests/commands/scope-flags.test.js +0 -300
- package/dist/tests/commands/search.test.js +0 -537
- package/dist/tests/commands/show-indexer-parity.test.js +0 -117
- package/dist/tests/commands/show.test.js +0 -294
- package/dist/tests/common.test.js +0 -266
- package/dist/tests/completions.test.js +0 -142
- package/dist/tests/config-cli.test.js +0 -193
- package/dist/tests/config-llm-features.test.js +0 -139
- package/dist/tests/config.test.js +0 -569
- package/dist/tests/contracts/migration-baseline.test.js +0 -43
- package/dist/tests/contracts/reflect-propose-envelope.test.js +0 -139
- package/dist/tests/contracts/spec-helpers.js +0 -46
- package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +0 -228
- package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +0 -56
- package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +0 -34
- package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +0 -94
- package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +0 -39
- package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +0 -44
- package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +0 -47
- package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +0 -40
- package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +0 -58
- package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +0 -34
- package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +0 -75
- package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +0 -36
- package/dist/tests/core/write-source.test.js +0 -366
- package/dist/tests/curate-command.test.js +0 -87
- package/dist/tests/db-scoring.test.js +0 -201
- package/dist/tests/db.test.js +0 -654
- package/dist/tests/distill-cli-flag.test.js +0 -208
- package/dist/tests/distill.test.js +0 -515
- package/dist/tests/docker-install.test.js +0 -120
- package/dist/tests/e2e.test.js +0 -1419
- package/dist/tests/embedder.test.js +0 -340
- package/dist/tests/embedding-model-config.test.js +0 -379
- package/dist/tests/feedback-command.test.js +0 -172
- package/dist/tests/file-context.test.js +0 -552
- package/dist/tests/fixtures/scripts/git/summarize-diff.js +0 -9
- package/dist/tests/fixtures/scripts/lint/eslint-check.js +0 -7
- package/dist/tests/fixtures/stashes/load.js +0 -166
- package/dist/tests/fixtures/stashes/load.test.js +0 -97
- package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +0 -12
- package/dist/tests/frontmatter.test.js +0 -190
- package/dist/tests/fts-field-weighting.test.js +0 -254
- package/dist/tests/fuzzy-search.test.js +0 -230
- package/dist/tests/git-provider-clone.test.js +0 -45
- package/dist/tests/github.test.js +0 -161
- package/dist/tests/graph-boost-ranking.test.js +0 -305
- package/dist/tests/graph-extraction.test.js +0 -282
- package/dist/tests/helpers/usage-events.js +0 -8
- package/dist/tests/index-pass-llm.test.js +0 -161
- package/dist/tests/indexer.test.js +0 -570
- package/dist/tests/info-command.test.js +0 -166
- package/dist/tests/init.test.js +0 -69
- package/dist/tests/install-script.test.js +0 -246
- package/dist/tests/integration/agent-real-profile.test.js +0 -94
- package/dist/tests/issue-36-repro.test.js +0 -304
- package/dist/tests/issues-191-194.test.js +0 -160
- package/dist/tests/lesson-lint.test.js +0 -111
- package/dist/tests/llm-client.test.js +0 -115
- package/dist/tests/llm-feature-gate.test.js +0 -151
- package/dist/tests/llm.test.js +0 -139
- package/dist/tests/lockfile.test.js +0 -216
- package/dist/tests/manifest.test.js +0 -205
- package/dist/tests/markdown.test.js +0 -126
- package/dist/tests/matchers-unit.test.js +0 -189
- package/dist/tests/memory-inference.test.js +0 -299
- package/dist/tests/merge-scoring.test.js +0 -136
- package/dist/tests/metadata.test.js +0 -313
- package/dist/tests/migration-help.test.js +0 -89
- package/dist/tests/origin-resolve.test.js +0 -124
- package/dist/tests/output-baseline.test.js +0 -218
- package/dist/tests/output-shapes-unit.test.js +0 -478
- package/dist/tests/parallel-search.test.js +0 -272
- package/dist/tests/parameter-metadata.test.js +0 -365
- package/dist/tests/paths.test.js +0 -177
- package/dist/tests/progressive-disclosure.test.js +0 -280
- package/dist/tests/proposals.test.js +0 -279
- package/dist/tests/proposed-quality.test.js +0 -271
- package/dist/tests/provider-registry.test.js +0 -32
- package/dist/tests/ranking-regression.test.js +0 -548
- package/dist/tests/reflect-propose.test.js +0 -455
- package/dist/tests/registry-build-index.test.js +0 -394
- package/dist/tests/registry-cli.test.js +0 -290
- package/dist/tests/registry-index-v2.test.js +0 -430
- package/dist/tests/registry-install.test.js +0 -728
- package/dist/tests/registry-providers/parity.test.js +0 -189
- package/dist/tests/registry-providers/skills-sh.test.js +0 -309
- package/dist/tests/registry-providers/static-index.test.js +0 -238
- package/dist/tests/registry-resolve.test.js +0 -126
- package/dist/tests/registry-search.test.js +0 -923
- package/dist/tests/remember-frontmatter.test.js +0 -378
- package/dist/tests/remember-unit.test.js +0 -123
- package/dist/tests/ripgrep-install.test.js +0 -251
- package/dist/tests/ripgrep-resolve.test.js +0 -108
- package/dist/tests/ripgrep.test.js +0 -163
- package/dist/tests/save-command.test.js +0 -94
- package/dist/tests/save-trust-qa-fixes.test.js +0 -270
- package/dist/tests/scoring-pipeline.test.js +0 -648
- package/dist/tests/search-include-proposed-cli.test.js +0 -118
- package/dist/tests/self-update.test.js +0 -442
- package/dist/tests/semantic-search-e2e.test.js +0 -512
- package/dist/tests/semantic-status.test.js +0 -471
- package/dist/tests/setup-run.integration.js +0 -877
- package/dist/tests/setup-wizard.test.js +0 -198
- package/dist/tests/setup.test.js +0 -131
- package/dist/tests/source-add.test.js +0 -11
- package/dist/tests/source-clone.test.js +0 -254
- package/dist/tests/source-manage.test.js +0 -366
- package/dist/tests/source-providers/filesystem.test.js +0 -82
- package/dist/tests/source-providers/git.test.js +0 -252
- package/dist/tests/source-providers/website.test.js +0 -128
- package/dist/tests/source-qa-fixes.test.js +0 -286
- package/dist/tests/source-registry.test.js +0 -350
- package/dist/tests/source-resolve.test.js +0 -100
- package/dist/tests/source-source.test.js +0 -281
- package/dist/tests/source.test.js +0 -533
- package/dist/tests/tar-utils-scan.test.js +0 -73
- package/dist/tests/toggle-components.test.js +0 -73
- package/dist/tests/usage-telemetry.test.js +0 -265
- package/dist/tests/utility-scoring.test.js +0 -558
- package/dist/tests/vault-load-error.test.js +0 -78
- package/dist/tests/vault-qa-fixes.test.js +0 -194
- package/dist/tests/vault.test.js +0 -429
- package/dist/tests/vector-search.test.js +0 -608
- package/dist/tests/walker.test.js +0 -252
- package/dist/tests/wave2-cluster-bc.test.js +0 -228
- package/dist/tests/wave2-cluster-d.test.js +0 -180
- package/dist/tests/wave2-cluster-e.test.js +0 -179
- package/dist/tests/wiki-qa-fixes.test.js +0 -270
- package/dist/tests/wiki.test.js +0 -529
- package/dist/tests/workflow-cli.test.js +0 -271
- package/dist/tests/workflow-markdown.test.js +0 -171
- package/dist/tests/workflow-path-escape.test.js +0 -132
- package/dist/tests/workflow-qa-fixes.test.js +0 -395
- package/dist/tests/workflows/indexer-rejection.test.js +0 -213
- /package/dist/{src/cli.js → cli.js} +0 -0
- /package/dist/{src/commands → commands}/completions.js +0 -0
- /package/dist/{src/commands → commands}/config-cli.js +0 -0
- /package/dist/{src/commands → commands}/curate.js +0 -0
- /package/dist/{src/commands → commands}/distill.js +0 -0
- /package/dist/{src/commands → commands}/events.js +0 -0
- /package/dist/{src/commands → commands}/history.js +0 -0
- /package/dist/{src/commands → commands}/info.js +0 -0
- /package/dist/{src/commands → commands}/init.js +0 -0
- /package/dist/{src/commands → commands}/install-audit.js +0 -0
- /package/dist/{src/commands → commands}/installed-stashes.js +0 -0
- /package/dist/{src/commands → commands}/migration-help.js +0 -0
- /package/dist/{src/commands → commands}/proposal.js +0 -0
- /package/dist/{src/commands → commands}/propose.js +0 -0
- /package/dist/{src/commands → commands}/reflect.js +0 -0
- /package/dist/{src/commands → commands}/registry-search.js +0 -0
- /package/dist/{src/commands → commands}/remember.js +0 -0
- /package/dist/{src/commands → commands}/search.js +0 -0
- /package/dist/{src/commands → commands}/self-update.js +0 -0
- /package/dist/{src/commands → commands}/show.js +0 -0
- /package/dist/{src/commands → commands}/source-add.js +0 -0
- /package/dist/{src/commands → commands}/source-clone.js +0 -0
- /package/dist/{src/commands → commands}/source-manage.js +0 -0
- /package/dist/{src/commands → commands}/vault.js +0 -0
- /package/dist/{src/core → core}/asset-ref.js +0 -0
- /package/dist/{src/core → core}/asset-registry.js +0 -0
- /package/dist/{src/core → core}/asset-spec.js +0 -0
- /package/dist/{src/core → core}/common.js +0 -0
- /package/dist/{src/core → core}/config.js +0 -0
- /package/dist/{src/core → core}/errors.js +0 -0
- /package/dist/{src/core → core}/events.js +0 -0
- /package/dist/{src/core → core}/frontmatter.js +0 -0
- /package/dist/{src/core → core}/lesson-lint.js +0 -0
- /package/dist/{src/core → core}/markdown.js +0 -0
- /package/dist/{src/core → core}/paths.js +0 -0
- /package/dist/{src/core → core}/proposals.js +0 -0
- /package/dist/{src/core → core}/warn.js +0 -0
- /package/dist/{src/core → core}/write-source.js +0 -0
- /package/dist/{src/indexer → indexer}/db-search.js +0 -0
- /package/dist/{src/indexer → indexer}/db.js +0 -0
- /package/dist/{src/indexer → indexer}/file-context.js +0 -0
- /package/dist/{src/indexer → indexer}/graph-boost.js +0 -0
- /package/dist/{src/indexer → indexer}/graph-extraction.js +0 -0
- /package/dist/{src/indexer → indexer}/indexer.js +0 -0
- /package/dist/{src/indexer → indexer}/manifest.js +0 -0
- /package/dist/{src/indexer → indexer}/matchers.js +0 -0
- /package/dist/{src/indexer → indexer}/memory-inference.js +0 -0
- /package/dist/{src/indexer → indexer}/metadata.js +0 -0
- /package/dist/{src/indexer → indexer}/search-fields.js +0 -0
- /package/dist/{src/indexer → indexer}/search-source.js +0 -0
- /package/dist/{src/indexer → indexer}/semantic-status.js +0 -0
- /package/dist/{src/indexer → indexer}/usage-events.js +0 -0
- /package/dist/{src/indexer → indexer}/walker.js +0 -0
- /package/dist/{src/integrations → integrations}/agent/config.js +0 -0
- /package/dist/{src/integrations → integrations}/agent/detect.js +0 -0
- /package/dist/{src/integrations → integrations}/agent/index.js +0 -0
- /package/dist/{src/integrations → integrations}/agent/profiles.js +0 -0
- /package/dist/{src/integrations → integrations}/agent/prompts.js +0 -0
- /package/dist/{src/integrations → integrations}/agent/spawn.js +0 -0
- /package/dist/{src/integrations → integrations}/github.js +0 -0
- /package/dist/{src/integrations → integrations}/lockfile.js +0 -0
- /package/dist/{src/llm → llm}/client.js +0 -0
- /package/dist/{src/llm → llm}/embedder.js +0 -0
- /package/dist/{src/llm → llm}/embedders/cache.js +0 -0
- /package/dist/{src/llm → llm}/embedders/local.js +0 -0
- /package/dist/{src/llm → llm}/embedders/remote.js +0 -0
- /package/dist/{src/llm → llm}/embedders/types.js +0 -0
- /package/dist/{src/llm → llm}/feature-gate.js +0 -0
- /package/dist/{src/llm → llm}/graph-extract.js +0 -0
- /package/dist/{src/llm → llm}/index-passes.js +0 -0
- /package/dist/{src/llm → llm}/memory-infer.js +0 -0
- /package/dist/{src/llm → llm}/metadata-enhance.js +0 -0
- /package/dist/{src/output → output}/cli-hints.js +0 -0
- /package/dist/{src/output → output}/context.js +0 -0
- /package/dist/{src/output → output}/renderers.js +0 -0
- /package/dist/{src/output → output}/shapes.js +0 -0
- /package/dist/{src/output → output}/text.js +0 -0
- /package/dist/{src/registry → registry}/build-index.js +0 -0
- /package/dist/{src/registry → registry}/create-provider-registry.js +0 -0
- /package/dist/{src/registry → registry}/factory.js +0 -0
- /package/dist/{src/registry → registry}/origin-resolve.js +0 -0
- /package/dist/{src/registry → registry}/providers/index.js +0 -0
- /package/dist/{src/registry → registry}/providers/skills-sh.js +0 -0
- /package/dist/{src/registry → registry}/providers/static-index.js +0 -0
- /package/dist/{src/registry → registry}/providers/types.js +0 -0
- /package/dist/{src/registry → registry}/resolve.js +0 -0
- /package/dist/{src/registry → registry}/types.js +0 -0
- /package/dist/{src/setup → setup}/detect.js +0 -0
- /package/dist/{src/setup → setup}/ripgrep-install.js +0 -0
- /package/dist/{src/setup → setup}/ripgrep-resolve.js +0 -0
- /package/dist/{src/setup → setup}/setup.js +0 -0
- /package/dist/{src/setup → setup}/steps.js +0 -0
- /package/dist/{src/sources → sources}/include.js +0 -0
- /package/dist/{src/sources → sources}/provider-factory.js +0 -0
- /package/dist/{src/sources → sources}/provider.js +0 -0
- /package/dist/{src/sources → sources}/providers/filesystem.js +0 -0
- /package/dist/{src/sources → sources}/providers/git.js +0 -0
- /package/dist/{src/sources → sources}/providers/index.js +0 -0
- /package/dist/{src/sources → sources}/providers/install-types.js +0 -0
- /package/dist/{src/sources → sources}/providers/npm.js +0 -0
- /package/dist/{src/sources → sources}/providers/provider-utils.js +0 -0
- /package/dist/{src/sources → sources}/providers/sync-from-ref.js +0 -0
- /package/dist/{src/sources → sources}/providers/tar-utils.js +0 -0
- /package/dist/{src/sources → sources}/providers/website.js +0 -0
- /package/dist/{src/sources → sources}/resolve.js +0 -0
- /package/dist/{src/sources → sources}/types.js +0 -0
- /package/dist/{src/templates → templates}/wiki-templates.js +0 -0
- /package/dist/{src/version.js → version.js} +0 -0
- /package/dist/{src/wiki → wiki}/wiki.js +0 -0
- /package/dist/{src/workflows → workflows}/authoring.js +0 -0
- /package/dist/{src/workflows → workflows}/cli.js +0 -0
- /package/dist/{src/workflows → workflows}/db.js +0 -0
- /package/dist/{src/workflows → workflows}/document-cache.js +0 -0
- /package/dist/{src/workflows → workflows}/parser.js +0 -0
- /package/dist/{src/workflows → workflows}/renderer.js +0 -0
- /package/dist/{src/workflows → workflows}/runs.js +0 -0
- /package/dist/{src/workflows → workflows}/schema.js +0 -0
- /package/dist/{src/workflows → workflows}/validator.js +0 -0
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
import { afterAll, 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 { extractDescriptionFromComments, extractPackageMetadata, extractTagsFromPath, fileNameToDescription, generateMetadata, loadStashFile, validateStashEntry, writeStashFile, } from "../src/indexer/metadata";
|
|
6
|
-
// Renderers auto-register via ensureBuiltinsRegistered in file-context.ts
|
|
7
|
-
const createdTmpDirs = [];
|
|
8
|
-
function tmpDir() {
|
|
9
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-meta-"));
|
|
10
|
-
createdTmpDirs.push(dir);
|
|
11
|
-
return dir;
|
|
12
|
-
}
|
|
13
|
-
afterAll(() => {
|
|
14
|
-
for (const dir of createdTmpDirs) {
|
|
15
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
function writeFile(filePath, content = "") {
|
|
19
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
20
|
-
fs.writeFileSync(filePath, content);
|
|
21
|
-
}
|
|
22
|
-
// ── loadStashFile ───────────────────────────────────────────────────────────
|
|
23
|
-
test("loadStashFile reads valid .stash.json", () => {
|
|
24
|
-
const dir = tmpDir();
|
|
25
|
-
const stash = {
|
|
26
|
-
entries: [
|
|
27
|
-
{
|
|
28
|
-
name: "docker-build",
|
|
29
|
-
type: "script",
|
|
30
|
-
description: "build docker images",
|
|
31
|
-
tags: ["docker", "build"],
|
|
32
|
-
filename: "docker-build.ts",
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
};
|
|
36
|
-
writeFile(path.join(dir, ".stash.json"), JSON.stringify(stash));
|
|
37
|
-
const result = loadStashFile(dir);
|
|
38
|
-
expect(result).not.toBeNull();
|
|
39
|
-
expect(result?.entries).toHaveLength(1);
|
|
40
|
-
expect(result?.entries[0].name).toBe("docker-build");
|
|
41
|
-
expect(result?.entries[0].description).toBe("build docker images");
|
|
42
|
-
expect(result?.entries[0].tags).toEqual(["docker", "build"]);
|
|
43
|
-
});
|
|
44
|
-
test("loadStashFile returns null for missing file", () => {
|
|
45
|
-
const dir = tmpDir();
|
|
46
|
-
expect(loadStashFile(dir)).toBeNull();
|
|
47
|
-
});
|
|
48
|
-
test("loadStashFile returns null for invalid JSON", () => {
|
|
49
|
-
const dir = tmpDir();
|
|
50
|
-
writeFile(path.join(dir, ".stash.json"), "not json");
|
|
51
|
-
expect(loadStashFile(dir)).toBeNull();
|
|
52
|
-
});
|
|
53
|
-
test("loadStashFile returns null for missing entries array", () => {
|
|
54
|
-
const dir = tmpDir();
|
|
55
|
-
writeFile(path.join(dir, ".stash.json"), '{"foo": "bar"}');
|
|
56
|
-
expect(loadStashFile(dir)).toBeNull();
|
|
57
|
-
});
|
|
58
|
-
test("loadStashFile parses intent field", () => {
|
|
59
|
-
const dir = tmpDir();
|
|
60
|
-
const stash = {
|
|
61
|
-
entries: [
|
|
62
|
-
{
|
|
63
|
-
name: "deploy",
|
|
64
|
-
type: "script",
|
|
65
|
-
intent: { when: "user needs to deploy", input: "service name", output: "deployment status" },
|
|
66
|
-
filename: "deploy.sh",
|
|
67
|
-
},
|
|
68
|
-
],
|
|
69
|
-
};
|
|
70
|
-
writeFile(path.join(dir, ".stash.json"), JSON.stringify(stash));
|
|
71
|
-
const result = loadStashFile(dir);
|
|
72
|
-
expect(result?.entries[0].intent).toEqual({
|
|
73
|
-
when: "user needs to deploy",
|
|
74
|
-
input: "service name",
|
|
75
|
-
output: "deployment status",
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
// ── writeStashFile ──────────────────────────────────────────────────────────
|
|
79
|
-
test("writeStashFile persists .stash.json to disk", () => {
|
|
80
|
-
const dir = tmpDir();
|
|
81
|
-
const stash = {
|
|
82
|
-
entries: [{ name: "test", type: "script", quality: "generated" }],
|
|
83
|
-
};
|
|
84
|
-
writeStashFile(dir, stash);
|
|
85
|
-
const raw = fs.readFileSync(path.join(dir, ".stash.json"), "utf8");
|
|
86
|
-
const parsed = JSON.parse(raw);
|
|
87
|
-
expect(parsed.entries[0].name).toBe("test");
|
|
88
|
-
expect(parsed.entries[0].quality).toBe("generated");
|
|
89
|
-
});
|
|
90
|
-
// ── validateStashEntry ──────────────────────────────────────────────────────
|
|
91
|
-
test("validateStashEntry rejects entries without name", () => {
|
|
92
|
-
expect(validateStashEntry({ type: "script" })).toBeNull();
|
|
93
|
-
});
|
|
94
|
-
test("validateStashEntry rejects entries without valid type", () => {
|
|
95
|
-
expect(validateStashEntry({ name: "x", type: "invalid" })).toBeNull();
|
|
96
|
-
});
|
|
97
|
-
test("validateStashEntry accepts minimal valid entry", () => {
|
|
98
|
-
const result = validateStashEntry({ name: "x", type: "script" });
|
|
99
|
-
expect(result).not.toBeNull();
|
|
100
|
-
expect(result?.name).toBe("x");
|
|
101
|
-
expect(result?.type).toBe("script");
|
|
102
|
-
});
|
|
103
|
-
test("validateStashEntry parses quality, confidence, source, and aliases", () => {
|
|
104
|
-
const result = validateStashEntry({
|
|
105
|
-
name: "lint",
|
|
106
|
-
type: "script",
|
|
107
|
-
quality: "curated",
|
|
108
|
-
confidence: 2,
|
|
109
|
-
source: "manual",
|
|
110
|
-
aliases: ["Lint", "linters"],
|
|
111
|
-
});
|
|
112
|
-
expect(result).not.toBeNull();
|
|
113
|
-
expect(result?.quality).toBe("curated");
|
|
114
|
-
expect(result?.confidence).toBe(1);
|
|
115
|
-
expect(result?.source).toBe("manual");
|
|
116
|
-
// R4.6: de-pluralization heuristic removed; FTS5 porter stemmer handles stemming.
|
|
117
|
-
// "linters" is preserved as-is; "linter" is no longer generated.
|
|
118
|
-
expect(result?.aliases).toEqual(["lint", "linters"]);
|
|
119
|
-
});
|
|
120
|
-
// ── extractDescriptionFromComments ──────────────────────────────────────────
|
|
121
|
-
test("extractDescriptionFromComments parses JSDoc block comment", () => {
|
|
122
|
-
const dir = tmpDir();
|
|
123
|
-
const file = path.join(dir, "tool.ts");
|
|
124
|
-
writeFile(file, `/**\n * Generate docker compose stacks\n */\nconsole.log("hi")\n`);
|
|
125
|
-
const desc = extractDescriptionFromComments(file);
|
|
126
|
-
expect(desc).toBe("Generate docker compose stacks");
|
|
127
|
-
});
|
|
128
|
-
test("extractDescriptionFromComments parses hash comments after shebang", () => {
|
|
129
|
-
const dir = tmpDir();
|
|
130
|
-
const file = path.join(dir, "tool.sh");
|
|
131
|
-
writeFile(file, `#!/usr/bin/env bash\n# Deploy to production\n# Handles rollback\necho deploy\n`);
|
|
132
|
-
const desc = extractDescriptionFromComments(file);
|
|
133
|
-
expect(desc).toBe("Deploy to production Handles rollback");
|
|
134
|
-
});
|
|
135
|
-
test("extractDescriptionFromComments returns null for no comments", () => {
|
|
136
|
-
const dir = tmpDir();
|
|
137
|
-
const file = path.join(dir, "tool.ts");
|
|
138
|
-
writeFile(file, `console.log("no comments")\n`);
|
|
139
|
-
expect(extractDescriptionFromComments(file)).toBeNull();
|
|
140
|
-
});
|
|
141
|
-
// ── extractPackageMetadata ──────────────────────────────────────────────────
|
|
142
|
-
test("extractPackageMetadata reads package.json fields", () => {
|
|
143
|
-
const dir = tmpDir();
|
|
144
|
-
writeFile(path.join(dir, "package.json"), JSON.stringify({ name: "my-tool", description: "A useful tool", keywords: ["deploy", "ci"] }));
|
|
145
|
-
const meta = extractPackageMetadata(dir);
|
|
146
|
-
expect(meta).not.toBeNull();
|
|
147
|
-
expect(meta?.name).toBe("my-tool");
|
|
148
|
-
expect(meta?.description).toBe("A useful tool");
|
|
149
|
-
expect(meta?.keywords).toEqual(["deploy", "ci"]);
|
|
150
|
-
});
|
|
151
|
-
test("extractPackageMetadata returns null when no package.json", () => {
|
|
152
|
-
const dir = tmpDir();
|
|
153
|
-
expect(extractPackageMetadata(dir)).toBeNull();
|
|
154
|
-
});
|
|
155
|
-
// ── fileNameToDescription ───────────────────────────────────────────────────
|
|
156
|
-
test("fileNameToDescription converts dashes and underscores to spaces", () => {
|
|
157
|
-
expect(fileNameToDescription("docker-compose-generator")).toBe("docker compose generator");
|
|
158
|
-
expect(fileNameToDescription("my_script_tool")).toBe("my script tool");
|
|
159
|
-
});
|
|
160
|
-
test("fileNameToDescription handles camelCase", () => {
|
|
161
|
-
expect(fileNameToDescription("dockerBuild")).toBe("docker build");
|
|
162
|
-
});
|
|
163
|
-
// ── extractTagsFromPath ─────────────────────────────────────────────────────
|
|
164
|
-
test("extractTagsFromPath extracts tokens from path segments", () => {
|
|
165
|
-
const root = "/stash/scripts";
|
|
166
|
-
const file = path.join(root, "docker", "compose-generator.ts");
|
|
167
|
-
const tags = extractTagsFromPath(file, root);
|
|
168
|
-
expect(tags).toContain("docker");
|
|
169
|
-
expect(tags).toContain("compose");
|
|
170
|
-
expect(tags).toContain("generator");
|
|
171
|
-
});
|
|
172
|
-
// ── generateMetadata ────────────────────────────────────────────────────────
|
|
173
|
-
test("generateMetadata creates entries from script files with filename heuristics", async () => {
|
|
174
|
-
const dir = tmpDir();
|
|
175
|
-
const tool1 = path.join(dir, "summarize-diff.ts");
|
|
176
|
-
writeFile(tool1, `console.log("summarize")\n`);
|
|
177
|
-
const stash = await generateMetadata(dir, "script", [tool1]);
|
|
178
|
-
expect(stash.entries).toHaveLength(1);
|
|
179
|
-
expect(stash.entries[0].name).toBe("summarize-diff.ts");
|
|
180
|
-
expect(stash.entries[0].type).toBe("script");
|
|
181
|
-
expect(stash.entries[0].description).toBe("summarize diff");
|
|
182
|
-
expect(stash.entries[0].quality).toBe("generated");
|
|
183
|
-
expect(stash.entries[0].source).toBe("filename");
|
|
184
|
-
expect(stash.entries[0].confidence).toBe(0.55);
|
|
185
|
-
expect(stash.entries[0].aliases).toContain("summarize diff");
|
|
186
|
-
expect(stash.entries[0].filename).toBe("summarize-diff.ts");
|
|
187
|
-
});
|
|
188
|
-
test("generateMetadata extracts description from code comments", async () => {
|
|
189
|
-
const dir = tmpDir();
|
|
190
|
-
const tool1 = path.join(dir, "deploy.sh");
|
|
191
|
-
writeFile(tool1, `#!/usr/bin/env bash\n# Deploy services to production\necho deploy\n`);
|
|
192
|
-
const stash = await generateMetadata(dir, "script", [tool1]);
|
|
193
|
-
expect(stash.entries[0].description).toBe("Deploy services to production");
|
|
194
|
-
expect(stash.entries[0].source).toBe("comments");
|
|
195
|
-
});
|
|
196
|
-
test("generateMetadata extracts metadata from package.json", async () => {
|
|
197
|
-
const dir = tmpDir();
|
|
198
|
-
const tool1 = path.join(dir, "run.ts");
|
|
199
|
-
writeFile(tool1, `console.log("run")\n`);
|
|
200
|
-
writeFile(path.join(dir, "package.json"), JSON.stringify({ description: "Git diff summarizer", keywords: ["git", "diff"] }));
|
|
201
|
-
const stash = await generateMetadata(dir, "script", [tool1]);
|
|
202
|
-
expect(stash.entries[0].description).toBe("Git diff summarizer");
|
|
203
|
-
expect(stash.entries[0].source).toBe("package");
|
|
204
|
-
expect(stash.entries[0].confidence).toBe(0.8);
|
|
205
|
-
expect(stash.entries[0].tags).toEqual(["git", "diff"]);
|
|
206
|
-
});
|
|
207
|
-
test("generateMetadata skips non-script extensions for script type", async () => {
|
|
208
|
-
const dir = tmpDir();
|
|
209
|
-
const mdFile = path.join(dir, "README.md");
|
|
210
|
-
writeFile(mdFile, "# Readme\n");
|
|
211
|
-
const stash = await generateMetadata(dir, "script", [mdFile]);
|
|
212
|
-
expect(stash.entries).toHaveLength(0);
|
|
213
|
-
});
|
|
214
|
-
test("generateMetadata handles multi-script directories", async () => {
|
|
215
|
-
const dir = tmpDir();
|
|
216
|
-
const tool1 = path.join(dir, "docker-build.ts");
|
|
217
|
-
const tool2 = path.join(dir, "docker-compose.ts");
|
|
218
|
-
writeFile(tool1, `/**\n * Build docker images\n */\n`);
|
|
219
|
-
writeFile(tool2, `/**\n * Generate docker compose stacks\n */\n`);
|
|
220
|
-
const stash = await generateMetadata(dir, "script", [tool1, tool2]);
|
|
221
|
-
expect(stash.entries).toHaveLength(2);
|
|
222
|
-
expect(stash.entries[0].name).toBe("docker-build.ts");
|
|
223
|
-
expect(stash.entries[0].description).toBe("Build docker images");
|
|
224
|
-
expect(stash.entries[1].name).toBe("docker-compose.ts");
|
|
225
|
-
expect(stash.entries[1].description).toBe("Generate docker compose stacks");
|
|
226
|
-
});
|
|
227
|
-
// ── validateStashEntry with searchHints ─────────────────────────────────────────
|
|
228
|
-
test("validateStashEntry accepts entries with searchHints array", () => {
|
|
229
|
-
const result = validateStashEntry({
|
|
230
|
-
name: "test",
|
|
231
|
-
type: "script",
|
|
232
|
-
searchHints: ["summarize commits", "explain changes"],
|
|
233
|
-
});
|
|
234
|
-
expect(result).not.toBeNull();
|
|
235
|
-
expect(result?.searchHints).toEqual(["summarize commits", "explain changes"]);
|
|
236
|
-
});
|
|
237
|
-
test("validateStashEntry filters non-string elements from searchHints", () => {
|
|
238
|
-
const result = validateStashEntry({
|
|
239
|
-
name: "test",
|
|
240
|
-
type: "script",
|
|
241
|
-
searchHints: ["valid", 42, "", "also valid", null],
|
|
242
|
-
});
|
|
243
|
-
expect(result).not.toBeNull();
|
|
244
|
-
expect(result?.searchHints).toEqual(["valid", "also valid"]);
|
|
245
|
-
});
|
|
246
|
-
test("validateStashEntry omits searchHints if all filtered out", () => {
|
|
247
|
-
const result = validateStashEntry({
|
|
248
|
-
name: "test",
|
|
249
|
-
type: "script",
|
|
250
|
-
searchHints: ["", " "],
|
|
251
|
-
});
|
|
252
|
-
expect(result).not.toBeNull();
|
|
253
|
-
expect(result?.searchHints).toBeUndefined();
|
|
254
|
-
});
|
|
255
|
-
test("validateStashEntry accepts usage as string", () => {
|
|
256
|
-
const result = validateStashEntry({
|
|
257
|
-
name: "test",
|
|
258
|
-
type: "script",
|
|
259
|
-
usage: "Run after checking branch state",
|
|
260
|
-
});
|
|
261
|
-
expect(result).not.toBeNull();
|
|
262
|
-
expect(result?.usage).toEqual(["Run after checking branch state"]);
|
|
263
|
-
});
|
|
264
|
-
test("validateStashEntry normalizes usage array", () => {
|
|
265
|
-
const result = validateStashEntry({
|
|
266
|
-
name: "test",
|
|
267
|
-
type: "script",
|
|
268
|
-
usage: [" First step ", "", "Second step", 2, null],
|
|
269
|
-
});
|
|
270
|
-
expect(result).not.toBeNull();
|
|
271
|
-
expect(result?.usage).toEqual(["First step", "Second step"]);
|
|
272
|
-
});
|
|
273
|
-
test("loadStashFile parses usage field", () => {
|
|
274
|
-
const dir = tmpDir();
|
|
275
|
-
const stash = {
|
|
276
|
-
entries: [
|
|
277
|
-
{
|
|
278
|
-
name: "git-diff",
|
|
279
|
-
type: "script",
|
|
280
|
-
usage: ["Run after fetching main", "Use --stat for quick output"],
|
|
281
|
-
filename: "run.ts",
|
|
282
|
-
},
|
|
283
|
-
],
|
|
284
|
-
};
|
|
285
|
-
writeFile(path.join(dir, ".stash.json"), JSON.stringify(stash));
|
|
286
|
-
const result = loadStashFile(dir);
|
|
287
|
-
expect(result?.entries[0].usage).toEqual(["Run after fetching main", "Use --stat for quick output"]);
|
|
288
|
-
});
|
|
289
|
-
test("loadStashFile parses searchHints field", () => {
|
|
290
|
-
const dir = tmpDir();
|
|
291
|
-
const stash = {
|
|
292
|
-
entries: [
|
|
293
|
-
{
|
|
294
|
-
name: "git-diff",
|
|
295
|
-
type: "script",
|
|
296
|
-
searchHints: ["summarize git commits", "explain what changed"],
|
|
297
|
-
filename: "run.ts",
|
|
298
|
-
},
|
|
299
|
-
],
|
|
300
|
-
};
|
|
301
|
-
writeFile(path.join(dir, ".stash.json"), JSON.stringify(stash));
|
|
302
|
-
const result = loadStashFile(dir);
|
|
303
|
-
expect(result?.entries[0].searchHints).toEqual(["summarize git commits", "explain what changed"]);
|
|
304
|
-
});
|
|
305
|
-
// ── generateMetadata populates searchHints ──────────────────────────────────────
|
|
306
|
-
test("generateMetadata does not generate heuristic searchHints (LLM-only)", async () => {
|
|
307
|
-
const dir = tmpDir();
|
|
308
|
-
const tool = path.join(dir, "summarize-diff.ts");
|
|
309
|
-
writeFile(tool, `/**\n * Summarize git diff changes\n */\n`);
|
|
310
|
-
const stash = await generateMetadata(dir, "script", [tool]);
|
|
311
|
-
// Search hints are only generated when LLM is configured, not heuristically
|
|
312
|
-
expect(stash.entries[0].searchHints).toBeUndefined();
|
|
313
|
-
});
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { 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 { listBundledReleaseVersions, renderMigrationHelp } from "../src/commands/migration-help";
|
|
6
|
-
const PROJECT_ROOT = path.resolve(import.meta.dirname, "..");
|
|
7
|
-
const RELEASE_NOTES_DIR = path.join(PROJECT_ROOT, "docs", "migration", "release-notes");
|
|
8
|
-
describe("migration help", () => {
|
|
9
|
-
test("renders bundled migration guidance when changelog is unavailable", () => {
|
|
10
|
-
const result = renderMigrationHelp("0.5.0", undefined);
|
|
11
|
-
expect(result).toContain("Migration notes for akm v0.5.0");
|
|
12
|
-
expect(result).toContain("akm wiki");
|
|
13
|
-
});
|
|
14
|
-
test("normalizes v-prefixed prerelease versions to the stable release notes", () => {
|
|
15
|
-
const result = renderMigrationHelp("v0.5.0-rc1");
|
|
16
|
-
expect(result).toContain("Migration notes for akm v0.5.0");
|
|
17
|
-
expect(result).toContain("## [0.5.0]");
|
|
18
|
-
});
|
|
19
|
-
test("supports latest alias when changelog text is available", () => {
|
|
20
|
-
const result = renderMigrationHelp("latest");
|
|
21
|
-
expect(result).toContain("## [0.7.0]");
|
|
22
|
-
});
|
|
23
|
-
test("ensures published static files exist in the repo", () => {
|
|
24
|
-
const packageJson = JSON.parse(fs.readFileSync(path.join(PROJECT_ROOT, "package.json"), "utf8"));
|
|
25
|
-
const staticFiles = (packageJson.files ?? []).filter((entry) => entry !== "dist");
|
|
26
|
-
expect(staticFiles).toContain("CHANGELOG.md");
|
|
27
|
-
expect(staticFiles).toContain("docs/migration/release-notes");
|
|
28
|
-
for (const entry of staticFiles) {
|
|
29
|
-
expect(fs.existsSync(path.join(PROJECT_ROOT, entry))).toBe(true);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
test("every bundled release-notes file is surfaced by the loader", () => {
|
|
33
|
-
const bundled = listBundledReleaseVersions();
|
|
34
|
-
expect(bundled.length).toBeGreaterThan(0);
|
|
35
|
-
// Sanity: every known prior release has a note. Adding a new file to
|
|
36
|
-
// docs/migration/release-notes/ should be all it takes to extend this.
|
|
37
|
-
for (const version of ["0.0.13", "0.1.0", "0.2.0", "0.3.0", "0.5.0", "0.6.0"]) {
|
|
38
|
-
expect(bundled).toContain(version);
|
|
39
|
-
const result = renderMigrationHelp(version, undefined);
|
|
40
|
-
expect(result).toContain(`Migration notes for akm v${version}`);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
test("renders dedicated message when no bundled note or changelog entry exists", () => {
|
|
44
|
-
const result = renderMigrationHelp("9.9.9", undefined);
|
|
45
|
-
expect(result).toContain("No dedicated migration note");
|
|
46
|
-
expect(result).toContain("9.9.9");
|
|
47
|
-
// Fallback lists the bundled versions so users can pick one that exists.
|
|
48
|
-
expect(result).toContain("Available bundled notes:");
|
|
49
|
-
expect(result).toContain("0.6.0");
|
|
50
|
-
});
|
|
51
|
-
test("rejects unsafe version components (path traversal guard)", () => {
|
|
52
|
-
// Any of these would escape the release-notes directory if passed
|
|
53
|
-
// directly to fs.readFileSync; the loader must refuse them and fall
|
|
54
|
-
// through to the no-note fallback.
|
|
55
|
-
for (const bad of ["../../etc/passwd", "..", "0.6.0/../secret", "0.6.0\0"]) {
|
|
56
|
-
const result = renderMigrationHelp(bad, undefined);
|
|
57
|
-
expect(result).toContain("No dedicated migration note");
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
test("dist build resolves release-notes relative to the compiled module", () => {
|
|
61
|
-
// Simulate the published layout: a `<pkg>/dist` directory alongside
|
|
62
|
-
// `<pkg>/docs/migration/release-notes`. The loader derives its path
|
|
63
|
-
// from `import.meta.dir`, so we rebuild that relationship in a temp
|
|
64
|
-
// directory and assert the expected file resolves.
|
|
65
|
-
const tempPkg = fs.mkdtempSync(path.join(os.tmpdir(), "akm-pkg-layout-"));
|
|
66
|
-
try {
|
|
67
|
-
fs.mkdirSync(path.join(tempPkg, "dist"));
|
|
68
|
-
fs.mkdirSync(path.join(tempPkg, "docs", "migration", "release-notes"), { recursive: true });
|
|
69
|
-
const notePath = path.join(tempPkg, "docs", "migration", "release-notes", "0.6.0.md");
|
|
70
|
-
fs.writeFileSync(notePath, "Migration notes for akm v0.6.0\n- stub body for test\n", "utf8");
|
|
71
|
-
// Resolve exactly the way migration-help does (path.resolve(<mod>, "../docs/migration/release-notes")).
|
|
72
|
-
const moduleDir = path.join(tempPkg, "dist");
|
|
73
|
-
const resolved = path.resolve(moduleDir, "../docs/migration/release-notes", "0.6.0.md");
|
|
74
|
-
expect(fs.existsSync(resolved)).toBe(true);
|
|
75
|
-
expect(fs.readFileSync(resolved, "utf8")).toContain("Migration notes for akm v0.6.0");
|
|
76
|
-
}
|
|
77
|
-
finally {
|
|
78
|
-
fs.rmSync(tempPkg, { recursive: true, force: true });
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
test("every release-notes filename matches a published version shape", () => {
|
|
82
|
-
const files = fs.readdirSync(RELEASE_NOTES_DIR).filter((name) => name.endsWith(".md") && name !== "README.md");
|
|
83
|
-
for (const file of files) {
|
|
84
|
-
const version = file.slice(0, -".md".length);
|
|
85
|
-
// Accept semver-ish strings the loader is willing to serve.
|
|
86
|
-
expect(version).toMatch(/^[A-Za-z0-9._+-]+$/);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
});
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { afterEach, 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 { isRemoteOrigin, resolveSourcesForOrigin } from "../src/registry/origin-resolve";
|
|
6
|
-
// ── Helpers ─────────────────────────────────────────────────────────────────
|
|
7
|
-
let tmpDirs = [];
|
|
8
|
-
function makeTmpDir() {
|
|
9
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "akm-origin-test-"));
|
|
10
|
-
tmpDirs.push(dir);
|
|
11
|
-
return dir;
|
|
12
|
-
}
|
|
13
|
-
function makeSource(overrides) {
|
|
14
|
-
return {
|
|
15
|
-
path: overrides?.path ?? makeTmpDir(),
|
|
16
|
-
registryId: overrides?.registryId,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
afterEach(() => {
|
|
20
|
-
for (const dir of tmpDirs) {
|
|
21
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
22
|
-
}
|
|
23
|
-
tmpDirs = [];
|
|
24
|
-
});
|
|
25
|
-
// ── resolveSourcesForOrigin ─────────────────────────────────────────────────
|
|
26
|
-
describe("resolveSourcesForOrigin", () => {
|
|
27
|
-
test("returns all sources when origin is undefined", () => {
|
|
28
|
-
const sources = [makeSource(), makeSource()];
|
|
29
|
-
const result = resolveSourcesForOrigin(undefined, sources);
|
|
30
|
-
expect(result).toEqual(sources);
|
|
31
|
-
});
|
|
32
|
-
test("returns first source for 'local' origin", () => {
|
|
33
|
-
const sources = [makeSource(), makeSource(), makeSource()];
|
|
34
|
-
const result = resolveSourcesForOrigin("local", sources);
|
|
35
|
-
expect(result).toHaveLength(1);
|
|
36
|
-
expect(result[0]).toBe(sources[0]);
|
|
37
|
-
});
|
|
38
|
-
test("returns empty array for 'local' origin with no sources", () => {
|
|
39
|
-
const result = resolveSourcesForOrigin("local", []);
|
|
40
|
-
expect(result).toEqual([]);
|
|
41
|
-
});
|
|
42
|
-
test("matches by exact registryId", () => {
|
|
43
|
-
const target = makeSource({ registryId: "npm:@scope/pkg" });
|
|
44
|
-
const other = makeSource({ registryId: "github:owner/repo" });
|
|
45
|
-
const sources = [makeSource(), target, other];
|
|
46
|
-
const result = resolveSourcesForOrigin("npm:@scope/pkg", sources);
|
|
47
|
-
expect(result).toHaveLength(1);
|
|
48
|
-
expect(result[0]).toBe(target);
|
|
49
|
-
});
|
|
50
|
-
test("falls through to empty when parseRegistryRef throws for invalid shorthand", () => {
|
|
51
|
-
// "owner/repo" looks path-like and fails statSync, so parseRegistryRef throws.
|
|
52
|
-
// The catch block in resolveSourcesForOrigin swallows the error, and path matching
|
|
53
|
-
// also fails since the path doesn't exist. Result: empty array.
|
|
54
|
-
const target = makeSource({ registryId: "github:owner/repo" });
|
|
55
|
-
const sources = [makeSource(), target];
|
|
56
|
-
const result = resolveSourcesForOrigin("owner/repo", sources);
|
|
57
|
-
expect(result).toEqual([]);
|
|
58
|
-
});
|
|
59
|
-
test("matches by exact registryId with full prefix form", () => {
|
|
60
|
-
const target = makeSource({ registryId: "github:owner/repo" });
|
|
61
|
-
const sources = [makeSource(), target];
|
|
62
|
-
// Full prefix "github:owner/repo" matches exact registryId
|
|
63
|
-
const result = resolveSourcesForOrigin("github:owner/repo", sources);
|
|
64
|
-
expect(result).toHaveLength(1);
|
|
65
|
-
expect(result[0]).toBe(target);
|
|
66
|
-
});
|
|
67
|
-
test("matches by resolved path", () => {
|
|
68
|
-
const dir = makeTmpDir();
|
|
69
|
-
const source = makeSource({ path: dir });
|
|
70
|
-
const sources = [makeSource(), source];
|
|
71
|
-
const result = resolveSourcesForOrigin(dir, sources);
|
|
72
|
-
expect(result).toHaveLength(1);
|
|
73
|
-
expect(result[0]).toBe(source);
|
|
74
|
-
});
|
|
75
|
-
test("returns empty array when no match found", () => {
|
|
76
|
-
const sources = [makeSource(), makeSource()];
|
|
77
|
-
const result = resolveSourcesForOrigin("nonexistent:thing", sources);
|
|
78
|
-
expect(result).toEqual([]);
|
|
79
|
-
});
|
|
80
|
-
test("returns empty array for empty sources list with a non-local origin", () => {
|
|
81
|
-
const result = resolveSourcesForOrigin("npm:@scope/pkg", []);
|
|
82
|
-
expect(result).toEqual([]);
|
|
83
|
-
});
|
|
84
|
-
test("exact registryId match takes priority over path match", () => {
|
|
85
|
-
const dir = makeTmpDir();
|
|
86
|
-
const byId = makeSource({ registryId: dir });
|
|
87
|
-
const byPath = makeSource({ path: dir });
|
|
88
|
-
const sources = [byId, byPath];
|
|
89
|
-
// The origin matches byId's registryId exactly
|
|
90
|
-
const result = resolveSourcesForOrigin(dir, sources);
|
|
91
|
-
expect(result).toHaveLength(1);
|
|
92
|
-
expect(result[0]).toBe(byId);
|
|
93
|
-
});
|
|
94
|
-
test("returns multiple sources if multiple registryIds match", () => {
|
|
95
|
-
const a = makeSource({ registryId: "npm:@scope/pkg" });
|
|
96
|
-
const b = makeSource({ registryId: "npm:@scope/pkg" });
|
|
97
|
-
const sources = [makeSource(), a, b];
|
|
98
|
-
const result = resolveSourcesForOrigin("npm:@scope/pkg", sources);
|
|
99
|
-
expect(result).toHaveLength(2);
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
// ── isRemoteOrigin ──────────────────────────────────────────────────────────
|
|
103
|
-
describe("isRemoteOrigin", () => {
|
|
104
|
-
test("returns false for 'local' origin", () => {
|
|
105
|
-
expect(isRemoteOrigin("local", [])).toBe(false);
|
|
106
|
-
});
|
|
107
|
-
test("returns true when origin matches no sources", () => {
|
|
108
|
-
const sources = [makeSource()];
|
|
109
|
-
expect(isRemoteOrigin("npm:@nonexistent/pkg", sources)).toBe(true);
|
|
110
|
-
});
|
|
111
|
-
test("returns false when origin matches a source by registryId", () => {
|
|
112
|
-
const source = makeSource({ registryId: "npm:@scope/pkg" });
|
|
113
|
-
expect(isRemoteOrigin("npm:@scope/pkg", [source])).toBe(false);
|
|
114
|
-
});
|
|
115
|
-
test("returns false when origin matches a source by path", () => {
|
|
116
|
-
const dir = makeTmpDir();
|
|
117
|
-
const source = makeSource({ path: dir });
|
|
118
|
-
expect(isRemoteOrigin(dir, [source])).toBe(false);
|
|
119
|
-
});
|
|
120
|
-
test("returns true for an uninstalled GitHub ref", () => {
|
|
121
|
-
const sources = [makeSource()];
|
|
122
|
-
expect(isRemoteOrigin("github:unknown/repo", sources)).toBe(true);
|
|
123
|
-
});
|
|
124
|
-
});
|