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,648 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for search scoring pipeline fixes (Issues #1, #3, #4, #7, #8, #12, #14, #15).
|
|
3
|
-
*
|
|
4
|
-
* Each describe block targets a specific issue and follows TDD:
|
|
5
|
-
* write the failing test first, then verify it passes after the fix.
|
|
6
|
-
*/
|
|
7
|
-
import { afterAll, afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
8
|
-
import fs from "node:fs";
|
|
9
|
-
import os from "node:os";
|
|
10
|
-
import path from "node:path";
|
|
11
|
-
import { akmSearch } from "../src/commands/search";
|
|
12
|
-
import { saveConfig } from "../src/core/config";
|
|
13
|
-
import { buildDbHit, buildWhyMatched } from "../src/indexer/db-search";
|
|
14
|
-
import { akmIndex } from "../src/indexer/indexer";
|
|
15
|
-
// ── Temp directory tracking ─────────────────────────────────────────────────
|
|
16
|
-
const createdTmpDirs = [];
|
|
17
|
-
function createTmpDir(prefix = "akm-scoring-") {
|
|
18
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
19
|
-
createdTmpDirs.push(dir);
|
|
20
|
-
return dir;
|
|
21
|
-
}
|
|
22
|
-
afterAll(() => {
|
|
23
|
-
for (const dir of createdTmpDirs) {
|
|
24
|
-
fs.rmSync(dir, { recursive: true, force: true });
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
// ── Helpers ─────────────────────────────────────────────────────────────────
|
|
28
|
-
function writeFile(filePath, content = "") {
|
|
29
|
-
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
30
|
-
fs.writeFileSync(filePath, content);
|
|
31
|
-
}
|
|
32
|
-
function tmpStash() {
|
|
33
|
-
const dir = createTmpDir("akm-scoring-stash-");
|
|
34
|
-
for (const sub of ["skills", "commands", "agents", "knowledge", "scripts"]) {
|
|
35
|
-
fs.mkdirSync(path.join(dir, sub), { recursive: true });
|
|
36
|
-
}
|
|
37
|
-
return dir;
|
|
38
|
-
}
|
|
39
|
-
async function buildTestIndex(stashDir, files = {}) {
|
|
40
|
-
for (const [relPath, content] of Object.entries(files)) {
|
|
41
|
-
const fullPath = path.join(stashDir, relPath);
|
|
42
|
-
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
|
|
43
|
-
fs.writeFileSync(fullPath, content);
|
|
44
|
-
}
|
|
45
|
-
process.env.AKM_STASH_DIR = stashDir;
|
|
46
|
-
saveConfig({ semanticSearchMode: "off" });
|
|
47
|
-
await akmIndex({ stashDir, full: true });
|
|
48
|
-
}
|
|
49
|
-
function expectDefined(value) {
|
|
50
|
-
expect(value).toBeDefined();
|
|
51
|
-
if (value === undefined || value === null) {
|
|
52
|
-
throw new Error("Expected value to be defined");
|
|
53
|
-
}
|
|
54
|
-
return value;
|
|
55
|
-
}
|
|
56
|
-
// ── Environment isolation ───────────────────────────────────────────────────
|
|
57
|
-
const originalXdgCacheHome = process.env.XDG_CACHE_HOME;
|
|
58
|
-
const originalXdgConfigHome = process.env.XDG_CONFIG_HOME;
|
|
59
|
-
const originalAkmStashDir = process.env.AKM_STASH_DIR;
|
|
60
|
-
let testCacheDir = "";
|
|
61
|
-
let testConfigDir = "";
|
|
62
|
-
beforeEach(() => {
|
|
63
|
-
testCacheDir = createTmpDir("akm-scoring-cache-");
|
|
64
|
-
testConfigDir = createTmpDir("akm-scoring-config-");
|
|
65
|
-
process.env.XDG_CACHE_HOME = testCacheDir;
|
|
66
|
-
process.env.XDG_CONFIG_HOME = testConfigDir;
|
|
67
|
-
});
|
|
68
|
-
afterEach(() => {
|
|
69
|
-
if (originalXdgCacheHome === undefined) {
|
|
70
|
-
delete process.env.XDG_CACHE_HOME;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
process.env.XDG_CACHE_HOME = originalXdgCacheHome;
|
|
74
|
-
}
|
|
75
|
-
if (originalXdgConfigHome === undefined) {
|
|
76
|
-
delete process.env.XDG_CONFIG_HOME;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
process.env.XDG_CONFIG_HOME = originalXdgConfigHome;
|
|
80
|
-
}
|
|
81
|
-
if (originalAkmStashDir === undefined) {
|
|
82
|
-
delete process.env.AKM_STASH_DIR;
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
process.env.AKM_STASH_DIR = originalAkmStashDir;
|
|
86
|
-
}
|
|
87
|
-
if (testCacheDir) {
|
|
88
|
-
fs.rmSync(testCacheDir, { recursive: true, force: true });
|
|
89
|
-
testCacheDir = "";
|
|
90
|
-
}
|
|
91
|
-
if (testConfigDir) {
|
|
92
|
-
fs.rmSync(testConfigDir, { recursive: true, force: true });
|
|
93
|
-
testConfigDir = "";
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
// ── Issue #1: Two-phase boost causes score/rank inconsistency ───────────────
|
|
97
|
-
describe("Issue #1: Two-phase boost — score/rank consistency", () => {
|
|
98
|
-
test("curated item ranked higher than generated item also shows higher final score", async () => {
|
|
99
|
-
const stashDir = tmpStash();
|
|
100
|
-
// Create two entries with identical FTS content, but different quality fields.
|
|
101
|
-
// The curated entry should rank higher AND show a higher score.
|
|
102
|
-
writeFile(path.join(stashDir, "scripts", "alpha-tool", "alpha-tool.sh"), "#!/bin/bash\necho alpha\n");
|
|
103
|
-
writeFile(path.join(stashDir, "scripts", "alpha-tool", ".stash.json"), JSON.stringify({
|
|
104
|
-
entries: [
|
|
105
|
-
{
|
|
106
|
-
name: "alpha-tool",
|
|
107
|
-
type: "script",
|
|
108
|
-
description: "A special deployment utility for servers",
|
|
109
|
-
quality: "curated",
|
|
110
|
-
confidence: 0.9,
|
|
111
|
-
filename: "alpha-tool.sh",
|
|
112
|
-
},
|
|
113
|
-
],
|
|
114
|
-
}));
|
|
115
|
-
writeFile(path.join(stashDir, "scripts", "beta-tool", "beta-tool.sh"), "#!/bin/bash\necho beta\n");
|
|
116
|
-
writeFile(path.join(stashDir, "scripts", "beta-tool", ".stash.json"), JSON.stringify({
|
|
117
|
-
entries: [
|
|
118
|
-
{
|
|
119
|
-
name: "beta-tool",
|
|
120
|
-
type: "script",
|
|
121
|
-
description: "A special deployment utility for servers",
|
|
122
|
-
quality: "generated",
|
|
123
|
-
confidence: 0.0,
|
|
124
|
-
filename: "beta-tool.sh",
|
|
125
|
-
},
|
|
126
|
-
],
|
|
127
|
-
}));
|
|
128
|
-
await buildTestIndex(stashDir, {});
|
|
129
|
-
const result = await akmSearch({ query: "deployment utility", source: "local" });
|
|
130
|
-
const localHits = result.hits.filter((h) => h.type !== "registry");
|
|
131
|
-
const alphaHit = localHits.find((h) => h.name === "alpha-tool");
|
|
132
|
-
const betaHit = localHits.find((h) => h.name === "beta-tool");
|
|
133
|
-
const resolvedAlpha = expectDefined(alphaHit);
|
|
134
|
-
const resolvedBeta = expectDefined(betaHit);
|
|
135
|
-
// After fix: rank order and displayed scores must agree.
|
|
136
|
-
// The curated item (alpha) should rank higher than the generated item.
|
|
137
|
-
// Per CLAUDE.md / spec §9 displayed scores are clamped to [0,1]; on a
|
|
138
|
-
// strong-match query both items may clamp to the ceiling, so the
|
|
139
|
-
// observable score relation is "alpha >= beta" while rank ordering
|
|
140
|
-
// strictly separates them.
|
|
141
|
-
const alphaIdx = localHits.indexOf(resolvedAlpha);
|
|
142
|
-
const betaIdx = localHits.indexOf(resolvedBeta);
|
|
143
|
-
expect(alphaIdx).toBeLessThan(betaIdx);
|
|
144
|
-
expect(resolvedAlpha.score ?? 0).toBeGreaterThanOrEqual(expectDefined(resolvedBeta.score));
|
|
145
|
-
});
|
|
146
|
-
test("buildDbHit does not apply quality/confidence boost a second time", async () => {
|
|
147
|
-
// Directly call buildDbHit with a known score — the score should pass through
|
|
148
|
-
// without further quality/confidence multiplication.
|
|
149
|
-
const stashDir = tmpStash();
|
|
150
|
-
writeFile(path.join(stashDir, "scripts", "passthrough", "passthrough.sh"), "#!/bin/bash\n");
|
|
151
|
-
writeFile(path.join(stashDir, "scripts", "passthrough", ".stash.json"), JSON.stringify({
|
|
152
|
-
entries: [
|
|
153
|
-
{
|
|
154
|
-
name: "passthrough",
|
|
155
|
-
type: "script",
|
|
156
|
-
description: "Test passthrough",
|
|
157
|
-
quality: "curated",
|
|
158
|
-
confidence: 1.0,
|
|
159
|
-
filename: "passthrough.sh",
|
|
160
|
-
},
|
|
161
|
-
],
|
|
162
|
-
}));
|
|
163
|
-
const hit = await buildDbHit({
|
|
164
|
-
entry: {
|
|
165
|
-
name: "passthrough",
|
|
166
|
-
type: "script",
|
|
167
|
-
description: "Test passthrough",
|
|
168
|
-
quality: "curated",
|
|
169
|
-
confidence: 1.0,
|
|
170
|
-
},
|
|
171
|
-
path: path.join(stashDir, "scripts", "passthrough", "passthrough.sh"),
|
|
172
|
-
score: 0.0234,
|
|
173
|
-
query: "test",
|
|
174
|
-
rankingMode: "fts",
|
|
175
|
-
defaultStashDir: stashDir,
|
|
176
|
-
allSourceDirs: [stashDir],
|
|
177
|
-
sources: [{ path: stashDir }],
|
|
178
|
-
config: { semanticSearchMode: "off" },
|
|
179
|
-
});
|
|
180
|
-
// After fix: buildDbHit should NOT multiply by quality/confidence.
|
|
181
|
-
// The score should be rounded to 4 decimals from the input score directly.
|
|
182
|
-
expect(hit.score).toBe(0.0234);
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
// ── Issue #3: NaN from vec distance corrupts sort ───────────────────────────
|
|
186
|
-
describe("Issue #3: NaN guard on vector distance", () => {
|
|
187
|
-
test("search with indexed entries does not produce NaN scores", async () => {
|
|
188
|
-
// This integration test verifies the general pipeline does not produce NaN.
|
|
189
|
-
// The actual NaN guard is in tryVecScores which is called only when
|
|
190
|
-
// semanticSearchMode is enabled. We test the code path indirectly.
|
|
191
|
-
const stashDir = tmpStash();
|
|
192
|
-
writeFile(path.join(stashDir, "scripts", "vec-safe", "vec-safe.sh"), "#!/bin/bash\necho safe\n");
|
|
193
|
-
writeFile(path.join(stashDir, "scripts", "vec-safe", ".stash.json"), JSON.stringify({
|
|
194
|
-
entries: [
|
|
195
|
-
{
|
|
196
|
-
name: "vec-safe",
|
|
197
|
-
type: "script",
|
|
198
|
-
description: "A tool for testing NaN safety",
|
|
199
|
-
filename: "vec-safe.sh",
|
|
200
|
-
},
|
|
201
|
-
],
|
|
202
|
-
}));
|
|
203
|
-
await buildTestIndex(stashDir, {});
|
|
204
|
-
const result = await akmSearch({ query: "testing NaN safety", source: "local" });
|
|
205
|
-
const localHits = result.hits.filter((h) => h.type !== "registry");
|
|
206
|
-
for (const hit of localHits) {
|
|
207
|
-
if (hit.score !== undefined) {
|
|
208
|
-
expect(Number.isFinite(hit.score)).toBe(true);
|
|
209
|
-
expect(Number.isNaN(hit.score)).toBe(false);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
// ── Issue #4: deduplicateByPath precondition ────────────────────────────────
|
|
215
|
-
describe("Issue #4: deduplicateByPath enforces sort precondition", () => {
|
|
216
|
-
test("deduplication keeps highest-scored entry when entries share same path", async () => {
|
|
217
|
-
const stashDir = tmpStash();
|
|
218
|
-
// Create two entries that map to the same file path.
|
|
219
|
-
// The one with more boost signals should win.
|
|
220
|
-
const scriptPath = path.join(stashDir, "scripts", "shared-path", "shared.sh");
|
|
221
|
-
writeFile(scriptPath, "#!/bin/bash\necho shared\n");
|
|
222
|
-
writeFile(path.join(stashDir, "scripts", "shared-path", ".stash.json"), JSON.stringify({
|
|
223
|
-
entries: [
|
|
224
|
-
{
|
|
225
|
-
name: "shared-deploy",
|
|
226
|
-
type: "script",
|
|
227
|
-
description: "Deploy shared infrastructure components",
|
|
228
|
-
tags: ["deploy", "infra"],
|
|
229
|
-
searchHints: ["deploy infrastructure"],
|
|
230
|
-
filename: "shared.sh",
|
|
231
|
-
},
|
|
232
|
-
{
|
|
233
|
-
name: "shared-minimal",
|
|
234
|
-
type: "script",
|
|
235
|
-
description: "Shared infrastructure setup",
|
|
236
|
-
filename: "shared.sh",
|
|
237
|
-
},
|
|
238
|
-
],
|
|
239
|
-
}));
|
|
240
|
-
await buildTestIndex(stashDir, {});
|
|
241
|
-
const result = await akmSearch({ query: "deploy infra", source: "local" });
|
|
242
|
-
const localHits = result.hits.filter((h) => h.type !== "registry");
|
|
243
|
-
// Only one hit per file path should appear
|
|
244
|
-
const pathCounts = new Map();
|
|
245
|
-
for (const hit of localHits) {
|
|
246
|
-
pathCounts.set(hit.path, (pathCounts.get(hit.path) ?? 0) + 1);
|
|
247
|
-
}
|
|
248
|
-
for (const [, count] of pathCounts) {
|
|
249
|
-
expect(count).toBe(1);
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
// ── Issue #7: Unbounded boost accumulation ──────────────────────────────────
|
|
254
|
-
describe("Issue #7: Boost accumulation caps", () => {
|
|
255
|
-
test("entry with many matching tags does not get unbounded boost", async () => {
|
|
256
|
-
const stashDir = tmpStash();
|
|
257
|
-
// Both entries share the same description so FTS scores are identical.
|
|
258
|
-
// Only the tag boost differs: 10 matching tags vs 2 matching tags.
|
|
259
|
-
const sharedDesc = "Infrastructure automation toolkit for cloud deployments";
|
|
260
|
-
// Entry with 10 matching tags (would get +1.5 boost uncapped, 2.5x multiplier)
|
|
261
|
-
writeFile(path.join(stashDir, "scripts", "many-tags", "many-tags.sh"), "#!/bin/bash\necho many\n");
|
|
262
|
-
writeFile(path.join(stashDir, "scripts", "many-tags", ".stash.json"), JSON.stringify({
|
|
263
|
-
entries: [
|
|
264
|
-
{
|
|
265
|
-
name: "many-tags",
|
|
266
|
-
type: "script",
|
|
267
|
-
description: sharedDesc,
|
|
268
|
-
tags: ["deploy", "server", "cloud", "infra", "ci", "cd", "build", "release", "ship", "prod"],
|
|
269
|
-
filename: "many-tags.sh",
|
|
270
|
-
},
|
|
271
|
-
],
|
|
272
|
-
}));
|
|
273
|
-
// Entry with exactly 2 matching tags (capped level)
|
|
274
|
-
writeFile(path.join(stashDir, "scripts", "few-tags", "few-tags.sh"), "#!/bin/bash\necho few\n");
|
|
275
|
-
writeFile(path.join(stashDir, "scripts", "few-tags", ".stash.json"), JSON.stringify({
|
|
276
|
-
entries: [
|
|
277
|
-
{
|
|
278
|
-
name: "few-tags",
|
|
279
|
-
type: "script",
|
|
280
|
-
description: sharedDesc,
|
|
281
|
-
tags: ["deploy", "server"],
|
|
282
|
-
filename: "few-tags.sh",
|
|
283
|
-
},
|
|
284
|
-
],
|
|
285
|
-
}));
|
|
286
|
-
await buildTestIndex(stashDir, {});
|
|
287
|
-
// Use a simple query that both entries match on via FTS (description),
|
|
288
|
-
// with tokens that also match tags in both entries
|
|
289
|
-
const result = await akmSearch({ query: "deploy server", source: "local" });
|
|
290
|
-
const localHits = result.hits.filter((h) => h.type !== "registry");
|
|
291
|
-
const manyTagsHit = localHits.find((h) => h.name === "many-tags");
|
|
292
|
-
const fewTagsHit = localHits.find((h) => h.name === "few-tags");
|
|
293
|
-
const resolvedMany = expectDefined(manyTagsHit);
|
|
294
|
-
const resolvedFew = expectDefined(fewTagsHit);
|
|
295
|
-
// With tag cap at 0.30, both entries cap at the same tag boost (2 tags
|
|
296
|
-
// match "deploy" and "server" in both). The many-tags entry should NOT
|
|
297
|
-
// have a dramatically higher score. The ratio should be bounded.
|
|
298
|
-
const ratio = expectDefined(resolvedMany.score) / expectDefined(resolvedFew.score);
|
|
299
|
-
expect(ratio).toBeLessThan(2.0);
|
|
300
|
-
});
|
|
301
|
-
test("entry with many matching searchHints has capped boost", async () => {
|
|
302
|
-
const stashDir = tmpStash();
|
|
303
|
-
// Entry with 5 matching hints (would get +0.60 boost uncapped)
|
|
304
|
-
writeFile(path.join(stashDir, "scripts", "many-hints", "many-hints.sh"), "#!/bin/bash\n");
|
|
305
|
-
writeFile(path.join(stashDir, "scripts", "many-hints", ".stash.json"), JSON.stringify({
|
|
306
|
-
entries: [
|
|
307
|
-
{
|
|
308
|
-
name: "many-hints",
|
|
309
|
-
type: "script",
|
|
310
|
-
description: "Testing hint caps for search relevance",
|
|
311
|
-
searchHints: [
|
|
312
|
-
"deploy web apps",
|
|
313
|
-
"deploy mobile apps",
|
|
314
|
-
"deploy backend",
|
|
315
|
-
"deploy microservices",
|
|
316
|
-
"deploy containers",
|
|
317
|
-
],
|
|
318
|
-
filename: "many-hints.sh",
|
|
319
|
-
},
|
|
320
|
-
],
|
|
321
|
-
}));
|
|
322
|
-
// Entry with 2 matching hints (at the cap level)
|
|
323
|
-
writeFile(path.join(stashDir, "scripts", "few-hints", "few-hints.sh"), "#!/bin/bash\n");
|
|
324
|
-
writeFile(path.join(stashDir, "scripts", "few-hints", ".stash.json"), JSON.stringify({
|
|
325
|
-
entries: [
|
|
326
|
-
{
|
|
327
|
-
name: "few-hints",
|
|
328
|
-
type: "script",
|
|
329
|
-
description: "Testing hint caps for search relevance",
|
|
330
|
-
searchHints: ["deploy web apps", "deploy mobile apps"],
|
|
331
|
-
filename: "few-hints.sh",
|
|
332
|
-
},
|
|
333
|
-
],
|
|
334
|
-
}));
|
|
335
|
-
await buildTestIndex(stashDir, {});
|
|
336
|
-
const result = await akmSearch({ query: "deploy", source: "local" });
|
|
337
|
-
const localHits = result.hits.filter((h) => h.type !== "registry");
|
|
338
|
-
const manyHintsHit = localHits.find((h) => h.name === "many-hints");
|
|
339
|
-
const fewHintsHit = localHits.find((h) => h.name === "few-hints");
|
|
340
|
-
const resolvedMany = expectDefined(manyHintsHit);
|
|
341
|
-
const resolvedFew = expectDefined(fewHintsHit);
|
|
342
|
-
// The hint cap (0.24) limits hint boost accumulation, but base FTS scores
|
|
343
|
-
// may differ because entries with more hint content have more searchable text.
|
|
344
|
-
// The key invariant: both hits should be found and the ratio should be bounded.
|
|
345
|
-
const ratio = expectDefined(resolvedMany.score) / expectDefined(resolvedFew.score);
|
|
346
|
-
expect(ratio).toBeLessThan(3.5); // Reasonable bound; exact ratio depends on FTS normalization
|
|
347
|
-
});
|
|
348
|
-
});
|
|
349
|
-
// ── Issue #8: Score rounding destroys differentiation ───────────────────────
|
|
350
|
-
describe("Issue #8: Score rounding precision", () => {
|
|
351
|
-
test("scores differentiate entries that would collapse at 2 decimal places", async () => {
|
|
352
|
-
const stashDir = tmpStash();
|
|
353
|
-
// Create two entries with slightly different relevance signals.
|
|
354
|
-
// At 2-decimal rounding, both would be 0.02; at 4-decimal, they should differ.
|
|
355
|
-
writeFile(path.join(stashDir, "scripts", "precise-a", "precise-a.sh"), "#!/bin/bash\n");
|
|
356
|
-
writeFile(path.join(stashDir, "scripts", "precise-a", ".stash.json"), JSON.stringify({
|
|
357
|
-
entries: [
|
|
358
|
-
{
|
|
359
|
-
name: "precise-a",
|
|
360
|
-
type: "script",
|
|
361
|
-
description: "Widget factory for production deployment of services",
|
|
362
|
-
tags: ["widget"],
|
|
363
|
-
filename: "precise-a.sh",
|
|
364
|
-
},
|
|
365
|
-
],
|
|
366
|
-
}));
|
|
367
|
-
writeFile(path.join(stashDir, "scripts", "precise-b", "precise-b.sh"), "#!/bin/bash\n");
|
|
368
|
-
writeFile(path.join(stashDir, "scripts", "precise-b", ".stash.json"), JSON.stringify({
|
|
369
|
-
entries: [
|
|
370
|
-
{
|
|
371
|
-
name: "precise-b",
|
|
372
|
-
type: "script",
|
|
373
|
-
description: "Widget factory for production deployment of services",
|
|
374
|
-
filename: "precise-b.sh",
|
|
375
|
-
},
|
|
376
|
-
],
|
|
377
|
-
}));
|
|
378
|
-
await buildTestIndex(stashDir, {});
|
|
379
|
-
const result = await akmSearch({ query: "widget", source: "local" });
|
|
380
|
-
const localHits = result.hits.filter((h) => h.type !== "registry");
|
|
381
|
-
const hitA = localHits.find((h) => h.name === "precise-a");
|
|
382
|
-
const hitB = localHits.find((h) => h.name === "precise-b");
|
|
383
|
-
const resolvedA = expectDefined(hitA);
|
|
384
|
-
const resolvedB = expectDefined(hitB);
|
|
385
|
-
// With 4-decimal rounding, these should have different scores
|
|
386
|
-
// because precise-a has a tag match boost and precise-b does not.
|
|
387
|
-
expect(resolvedA.score).toBeGreaterThan(expectDefined(resolvedB.score));
|
|
388
|
-
expect(resolvedA.score).not.toBe(resolvedB.score);
|
|
389
|
-
});
|
|
390
|
-
test("scores are rounded to at most 4 decimal places", async () => {
|
|
391
|
-
const stashDir = tmpStash();
|
|
392
|
-
writeFile(path.join(stashDir, "scripts", "round-check", "round-check.sh"), "#!/bin/bash\n");
|
|
393
|
-
writeFile(path.join(stashDir, "scripts", "round-check", ".stash.json"), JSON.stringify({
|
|
394
|
-
entries: [
|
|
395
|
-
{
|
|
396
|
-
name: "round-check",
|
|
397
|
-
type: "script",
|
|
398
|
-
description: "A utility for checking rounding behavior",
|
|
399
|
-
filename: "round-check.sh",
|
|
400
|
-
},
|
|
401
|
-
],
|
|
402
|
-
}));
|
|
403
|
-
await buildTestIndex(stashDir, {});
|
|
404
|
-
const result = await akmSearch({ query: "rounding behavior", source: "local" });
|
|
405
|
-
const localHits = result.hits.filter((h) => h.type !== "registry");
|
|
406
|
-
const hit = localHits.find((h) => h.name === "round-check");
|
|
407
|
-
const resolved = expectDefined(hit);
|
|
408
|
-
// Verify score has at most 4 decimal places
|
|
409
|
-
const scoreStr = String(resolved.score);
|
|
410
|
-
const decimalPart = scoreStr.split(".")[1] ?? "";
|
|
411
|
-
expect(decimalPart.length).toBeLessThanOrEqual(4);
|
|
412
|
-
});
|
|
413
|
-
});
|
|
414
|
-
// ── Issue #12: buildWhyMatched omits description matches ────────────────────
|
|
415
|
-
describe("Issue #12: buildWhyMatched includes description matches", () => {
|
|
416
|
-
test("whyMatched includes 'matched description' when query matches description", async () => {
|
|
417
|
-
const stashDir = tmpStash();
|
|
418
|
-
writeFile(path.join(stashDir, "scripts", "desc-match", "desc-match.sh"), "#!/bin/bash\n");
|
|
419
|
-
writeFile(path.join(stashDir, "scripts", "desc-match", ".stash.json"), JSON.stringify({
|
|
420
|
-
entries: [
|
|
421
|
-
{
|
|
422
|
-
name: "desc-match",
|
|
423
|
-
type: "script",
|
|
424
|
-
description: "Orchestrates Kubernetes pod lifecycle management",
|
|
425
|
-
filename: "desc-match.sh",
|
|
426
|
-
},
|
|
427
|
-
],
|
|
428
|
-
}));
|
|
429
|
-
await buildTestIndex(stashDir, {});
|
|
430
|
-
const result = await akmSearch({ query: "kubernetes", source: "local" });
|
|
431
|
-
const localHits = result.hits.filter((h) => h.type !== "registry");
|
|
432
|
-
const hit = localHits.find((h) => h.name === "desc-match");
|
|
433
|
-
const resolved = expectDefined(hit);
|
|
434
|
-
expect(resolved.whyMatched).toBeDefined();
|
|
435
|
-
expect(resolved.whyMatched).toContain("matched description");
|
|
436
|
-
});
|
|
437
|
-
test("buildWhyMatched unit test: description match is reported", () => {
|
|
438
|
-
const reasons = buildWhyMatched({
|
|
439
|
-
name: "some-tool",
|
|
440
|
-
type: "script",
|
|
441
|
-
description: "Manages infrastructure provisioning",
|
|
442
|
-
tags: [],
|
|
443
|
-
}, "infrastructure", "fts", 0, 0);
|
|
444
|
-
expect(reasons).toContain("matched description");
|
|
445
|
-
});
|
|
446
|
-
test("buildWhyMatched unit test: no false positive when description does not match", () => {
|
|
447
|
-
const reasons = buildWhyMatched({
|
|
448
|
-
name: "other-tool",
|
|
449
|
-
type: "script",
|
|
450
|
-
description: "Formats source code",
|
|
451
|
-
tags: [],
|
|
452
|
-
}, "kubernetes", "fts", 0, 0);
|
|
453
|
-
expect(reasons).not.toContain("matched description");
|
|
454
|
-
});
|
|
455
|
-
});
|
|
456
|
-
// ── Issue #14: Unstable sort on tied DB scores ──────────────────────────────
|
|
457
|
-
describe("Issue #14: Deterministic sort on tied scores", () => {
|
|
458
|
-
test("entries with equal FTS scores are sorted deterministically by name", async () => {
|
|
459
|
-
const stashDir = tmpStash();
|
|
460
|
-
// Create entries with identical content so they get the same FTS score.
|
|
461
|
-
// Names chosen so alphabetical order is clear: aaa < bbb < ccc
|
|
462
|
-
const names = ["ccc-tool", "aaa-tool", "bbb-tool"];
|
|
463
|
-
for (const name of names) {
|
|
464
|
-
writeFile(path.join(stashDir, "scripts", name, `${name}.sh`), "#!/bin/bash\necho same content\n");
|
|
465
|
-
writeFile(path.join(stashDir, "scripts", name, ".stash.json"), JSON.stringify({
|
|
466
|
-
entries: [
|
|
467
|
-
{
|
|
468
|
-
name,
|
|
469
|
-
type: "script",
|
|
470
|
-
description: "Identical widget factory for production",
|
|
471
|
-
filename: `${name}.sh`,
|
|
472
|
-
},
|
|
473
|
-
],
|
|
474
|
-
}));
|
|
475
|
-
}
|
|
476
|
-
await buildTestIndex(stashDir, {});
|
|
477
|
-
// Run the search multiple times to verify determinism
|
|
478
|
-
const results = [];
|
|
479
|
-
for (let i = 0; i < 5; i++) {
|
|
480
|
-
const result = await akmSearch({ query: "widget factory", source: "local" });
|
|
481
|
-
const localHits = result.hits.filter((h) => h.type !== "registry");
|
|
482
|
-
const order = localHits.filter((h) => names.includes(h.name)).map((h) => h.name);
|
|
483
|
-
results.push(order);
|
|
484
|
-
}
|
|
485
|
-
// All runs should produce the exact same order — this is the key
|
|
486
|
-
// requirement. Without the tiebreaker, the sort is non-deterministic.
|
|
487
|
-
for (let i = 1; i < results.length; i++) {
|
|
488
|
-
expect(results[i]).toEqual(results[0]);
|
|
489
|
-
}
|
|
490
|
-
// Also verify all 3 entries are present
|
|
491
|
-
expect(results[0].length).toBe(3);
|
|
492
|
-
});
|
|
493
|
-
});
|
|
494
|
-
// ── Issue #15: "semantic" label for hybrid results ──────────────────────────
|
|
495
|
-
describe("Issue #15: Hybrid ranking mode label", () => {
|
|
496
|
-
test("buildWhyMatched handles 'hybrid' ranking mode", () => {
|
|
497
|
-
const reasons = buildWhyMatched({
|
|
498
|
-
name: "hybrid-test",
|
|
499
|
-
type: "script",
|
|
500
|
-
description: "A hybrid test entry",
|
|
501
|
-
tags: [],
|
|
502
|
-
}, "hybrid", "hybrid", 0, 0);
|
|
503
|
-
expect(reasons[0]).toContain("hybrid");
|
|
504
|
-
expect(reasons[0]).toContain("fts");
|
|
505
|
-
expect(reasons[0]).toContain("semantic");
|
|
506
|
-
});
|
|
507
|
-
test("buildWhyMatched still handles 'fts' ranking mode", () => {
|
|
508
|
-
const reasons = buildWhyMatched({
|
|
509
|
-
name: "fts-test",
|
|
510
|
-
type: "script",
|
|
511
|
-
description: "An fts test entry",
|
|
512
|
-
tags: [],
|
|
513
|
-
}, "fts", "fts", 0, 0);
|
|
514
|
-
expect(reasons[0]).toContain("fts");
|
|
515
|
-
expect(reasons[0]).toContain("bm25");
|
|
516
|
-
});
|
|
517
|
-
test("buildWhyMatched still handles 'semantic' ranking mode for vec-only results", () => {
|
|
518
|
-
const reasons = buildWhyMatched({
|
|
519
|
-
name: "semantic-test",
|
|
520
|
-
type: "script",
|
|
521
|
-
description: "A semantic test entry",
|
|
522
|
-
tags: [],
|
|
523
|
-
}, "semantic", "semantic", 0, 0);
|
|
524
|
-
expect(reasons[0]).toContain("semantic");
|
|
525
|
-
});
|
|
526
|
-
test("buildDbHit accepts 'hybrid' ranking mode", async () => {
|
|
527
|
-
const stashDir = tmpStash();
|
|
528
|
-
writeFile(path.join(stashDir, "scripts", "hybrid-entry", "hybrid-entry.sh"), "#!/bin/bash\n");
|
|
529
|
-
const hit = await buildDbHit({
|
|
530
|
-
entry: {
|
|
531
|
-
name: "hybrid-entry",
|
|
532
|
-
type: "script",
|
|
533
|
-
description: "A hybrid test",
|
|
534
|
-
},
|
|
535
|
-
path: path.join(stashDir, "scripts", "hybrid-entry", "hybrid-entry.sh"),
|
|
536
|
-
score: 0.025,
|
|
537
|
-
query: "hybrid",
|
|
538
|
-
rankingMode: "hybrid",
|
|
539
|
-
defaultStashDir: stashDir,
|
|
540
|
-
allSourceDirs: [stashDir],
|
|
541
|
-
sources: [{ path: stashDir }],
|
|
542
|
-
config: { semanticSearchMode: "off" },
|
|
543
|
-
});
|
|
544
|
-
expect(hit.whyMatched).toBeDefined();
|
|
545
|
-
expect(hit.whyMatched?.[0]).toContain("hybrid");
|
|
546
|
-
});
|
|
547
|
-
});
|
|
548
|
-
// ── Cross-stash deduplication (indexer level) ────────────────────────────────
|
|
549
|
-
describe("Cross-stash deduplication at index time", () => {
|
|
550
|
-
test("same asset in two stash sources produces only one index entry", async () => {
|
|
551
|
-
const primaryStash = tmpStash();
|
|
552
|
-
const secondStash = tmpStash();
|
|
553
|
-
// Same file with same content/metadata in both stashes, but under
|
|
554
|
-
// different directory prefixes (mimics primary stash + installed stash)
|
|
555
|
-
const script = "#!/bin/bash\necho github platform adapter\n";
|
|
556
|
-
const metadata = JSON.stringify({
|
|
557
|
-
entries: [
|
|
558
|
-
{
|
|
559
|
-
name: "github",
|
|
560
|
-
type: "script",
|
|
561
|
-
description: "GitHub Platform Adapter for issue tracking",
|
|
562
|
-
filename: "github.sh",
|
|
563
|
-
},
|
|
564
|
-
],
|
|
565
|
-
});
|
|
566
|
-
writeFile(path.join(primaryStash, "scripts", "platforms", "github.sh"), script);
|
|
567
|
-
writeFile(path.join(primaryStash, "scripts", "platforms", ".stash.json"), metadata);
|
|
568
|
-
writeFile(path.join(secondStash, "scripts", "platforms", "github.sh"), script);
|
|
569
|
-
writeFile(path.join(secondStash, "scripts", "platforms", ".stash.json"), metadata);
|
|
570
|
-
process.env.AKM_STASH_DIR = primaryStash;
|
|
571
|
-
saveConfig({
|
|
572
|
-
semanticSearchMode: "off",
|
|
573
|
-
sources: [{ type: "filesystem", path: secondStash, name: "second", enabled: true }],
|
|
574
|
-
});
|
|
575
|
-
await akmIndex({ stashDir: primaryStash, full: true });
|
|
576
|
-
const result = await akmSearch({ query: "github", source: "stash" });
|
|
577
|
-
const localHits = result.hits.filter((h) => h.type !== "registry");
|
|
578
|
-
// Filter to just the "github" platform adapter hits
|
|
579
|
-
const githubHits = localHits.filter((h) => h.name.includes("github") && h.description?.includes("GitHub Platform Adapter"));
|
|
580
|
-
// Indexer should skip the duplicate — only one entry in the DB
|
|
581
|
-
expect(githubHits.length).toBe(1);
|
|
582
|
-
// The surviving hit should be from the primary stash (higher priority)
|
|
583
|
-
expect(githubHits[0].path).toContain(primaryStash);
|
|
584
|
-
});
|
|
585
|
-
test("different stash directory structures deduped by type+basename+description", async () => {
|
|
586
|
-
const primaryStash = tmpStash();
|
|
587
|
-
const secondStash = tmpStash();
|
|
588
|
-
// Create identical assets with identical descriptions in both stashes
|
|
589
|
-
// but with DIFFERENT directory structures (so paths differ)
|
|
590
|
-
writeFile(path.join(primaryStash, "skills", "tracker", "platforms", "github.sh"), "#!/bin/bash\necho adapter\n");
|
|
591
|
-
writeFile(path.join(primaryStash, "skills", "tracker", "platforms", ".stash.json"), JSON.stringify({
|
|
592
|
-
entries: [
|
|
593
|
-
{
|
|
594
|
-
name: "tracker/platforms/github",
|
|
595
|
-
type: "script",
|
|
596
|
-
description: "GitHub Platform Adapter wrapping the gh CLI",
|
|
597
|
-
filename: "github.sh",
|
|
598
|
-
},
|
|
599
|
-
],
|
|
600
|
-
}));
|
|
601
|
-
writeFile(path.join(secondStash, "scripts", "platforms", "github.sh"), "#!/bin/bash\necho adapter\n");
|
|
602
|
-
writeFile(path.join(secondStash, "scripts", "platforms", ".stash.json"), JSON.stringify({
|
|
603
|
-
entries: [
|
|
604
|
-
{
|
|
605
|
-
name: "platforms/github",
|
|
606
|
-
type: "script",
|
|
607
|
-
description: "GitHub Platform Adapter wrapping the gh CLI",
|
|
608
|
-
filename: "github.sh",
|
|
609
|
-
},
|
|
610
|
-
],
|
|
611
|
-
}));
|
|
612
|
-
process.env.AKM_STASH_DIR = primaryStash;
|
|
613
|
-
saveConfig({
|
|
614
|
-
semanticSearchMode: "off",
|
|
615
|
-
sources: [{ type: "filesystem", path: secondStash, name: "second", enabled: true }],
|
|
616
|
-
});
|
|
617
|
-
await akmIndex({ stashDir: primaryStash, full: true });
|
|
618
|
-
const result = await akmSearch({ query: "github adapter", source: "stash" });
|
|
619
|
-
const localHits = result.hits.filter((h) => h.type !== "registry");
|
|
620
|
-
// Filter to just the adapter hits (same description from different roots)
|
|
621
|
-
const adapterHits = localHits.filter((h) => h.description?.includes("GitHub Platform Adapter"));
|
|
622
|
-
// Indexer dedup: only one entry despite different paths
|
|
623
|
-
expect(adapterHits.length).toBe(1);
|
|
624
|
-
});
|
|
625
|
-
test("different assets with same filename but different descriptions are NOT deduped", async () => {
|
|
626
|
-
const primaryStash = tmpStash();
|
|
627
|
-
const secondStash = tmpStash();
|
|
628
|
-
writeFile(path.join(primaryStash, "scripts", "utils", "helper.sh"), "#!/bin/bash\necho primary\n");
|
|
629
|
-
writeFile(path.join(primaryStash, "scripts", "utils", ".stash.json"), JSON.stringify({
|
|
630
|
-
entries: [{ name: "helper", type: "script", description: "Build helper for CI", filename: "helper.sh" }],
|
|
631
|
-
}));
|
|
632
|
-
writeFile(path.join(secondStash, "scripts", "tools", "helper.sh"), "#!/bin/bash\necho second\n");
|
|
633
|
-
writeFile(path.join(secondStash, "scripts", "tools", ".stash.json"), JSON.stringify({
|
|
634
|
-
entries: [{ name: "helper", type: "script", description: "Test helper for local dev", filename: "helper.sh" }],
|
|
635
|
-
}));
|
|
636
|
-
process.env.AKM_STASH_DIR = primaryStash;
|
|
637
|
-
saveConfig({
|
|
638
|
-
semanticSearchMode: "off",
|
|
639
|
-
sources: [{ type: "filesystem", path: secondStash, name: "second", enabled: true }],
|
|
640
|
-
});
|
|
641
|
-
await akmIndex({ stashDir: primaryStash, full: true });
|
|
642
|
-
const result = await akmSearch({ query: "helper", source: "stash" });
|
|
643
|
-
const localHits = result.hits.filter((h) => h.type !== "registry");
|
|
644
|
-
const helperHits = localHits.filter((h) => h.name.includes("helper"));
|
|
645
|
-
// Different descriptions = different assets — both should be indexed
|
|
646
|
-
expect(helperHits.length).toBe(2);
|
|
647
|
-
});
|
|
648
|
-
});
|