akm-cli 0.6.1 → 0.7.0-rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -0
- package/dist/{cli.js → src/cli.js} +620 -26
- package/dist/{commands → src/commands}/config-cli.js +5 -4
- package/dist/src/commands/distill.js +283 -0
- package/dist/src/commands/events.js +108 -0
- package/dist/src/commands/history.js +120 -0
- package/dist/{commands → src/commands}/installed-stashes.js +1 -1
- package/dist/src/commands/proposal.js +119 -0
- package/dist/src/commands/propose.js +171 -0
- package/dist/src/commands/reflect.js +193 -0
- package/dist/{commands → src/commands}/registry-search.js +2 -1
- package/dist/{commands → src/commands}/remember.js +12 -0
- package/dist/{commands → src/commands}/search.js +74 -1
- package/dist/{commands → src/commands}/self-update.js +4 -3
- package/dist/{commands → src/commands}/show.js +44 -0
- package/dist/{core → src/core}/asset-ref.js +5 -5
- package/dist/{core → src/core}/asset-spec.js +12 -0
- package/dist/{core → src/core}/common.js +1 -1
- package/dist/{core → src/core}/config.js +175 -121
- package/dist/{core → src/core}/errors.js +4 -0
- package/dist/src/core/events.js +239 -0
- package/dist/src/core/lesson-lint.js +86 -0
- package/dist/src/core/proposals.js +406 -0
- package/dist/src/core/warn.js +72 -0
- package/dist/{core → src/core}/write-source.js +80 -5
- package/dist/{indexer → src/indexer}/db-search.js +113 -24
- package/dist/{indexer → src/indexer}/db.js +76 -23
- package/dist/{indexer → src/indexer}/file-context.js +0 -3
- package/dist/src/indexer/graph-boost.js +179 -0
- package/dist/src/indexer/graph-extraction.js +212 -0
- package/dist/{indexer → src/indexer}/indexer.js +73 -6
- package/dist/src/indexer/memory-inference.js +263 -0
- package/dist/{indexer → src/indexer}/metadata.js +111 -3
- package/dist/src/integrations/agent/config.js +292 -0
- package/dist/src/integrations/agent/detect.js +94 -0
- package/dist/src/integrations/agent/index.js +17 -0
- package/dist/src/integrations/agent/profiles.js +65 -0
- package/dist/src/integrations/agent/prompts.js +167 -0
- package/dist/src/integrations/agent/spawn.js +221 -0
- package/dist/{integrations → src/integrations}/lockfile.js +0 -26
- package/dist/{llm → src/llm}/client.js +33 -2
- package/dist/src/llm/feature-gate.js +108 -0
- package/dist/src/llm/graph-extract.js +107 -0
- package/dist/src/llm/index-passes.js +35 -0
- package/dist/src/llm/memory-infer.js +86 -0
- package/dist/{output → src/output}/renderers.js +60 -1
- package/dist/src/output/shapes.js +516 -0
- package/dist/{output → src/output}/text.js +447 -4
- package/dist/{registry → src/registry}/build-index.js +14 -4
- package/dist/{registry → src/registry}/factory.js +0 -8
- package/dist/{registry → src/registry}/providers/static-index.js +3 -2
- package/dist/{registry → src/registry}/resolve.js +68 -2
- package/dist/{setup → src/setup}/setup.js +43 -5
- package/dist/{sources → src/sources}/providers/git.js +7 -15
- package/dist/tests/add-website-source.test.js +119 -0
- package/dist/tests/agent/agent-config-loader.test.js +70 -0
- package/dist/tests/agent/agent-config.test.js +221 -0
- package/dist/tests/agent/agent-detect.test.js +100 -0
- package/dist/tests/agent/agent-spawn.test.js +234 -0
- package/dist/tests/agent-output.test.js +186 -0
- package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +103 -0
- package/dist/tests/architecture/agent-spawn-seam.test.js +193 -0
- package/dist/tests/architecture/llm-stateless-seam.test.js +112 -0
- package/dist/tests/asset-ref.test.js +192 -0
- package/dist/tests/asset-registry.test.js +103 -0
- package/dist/tests/asset-spec.test.js +241 -0
- package/dist/tests/bench/attribution.test.js +995 -0
- package/dist/tests/bench/cleanup-sigint.test.js +83 -0
- package/dist/tests/bench/cleanup.js +203 -0
- package/dist/tests/bench/cleanup.test.js +166 -0
- package/dist/tests/bench/cli.js +683 -0
- package/dist/tests/bench/cli.test.js +177 -0
- package/dist/tests/bench/compare.test.js +556 -0
- package/dist/tests/bench/corpus.js +314 -0
- package/dist/tests/bench/corpus.test.js +258 -0
- package/dist/tests/bench/driver.js +346 -0
- package/dist/tests/bench/driver.test.js +443 -0
- package/dist/tests/bench/evolve-metrics.js +179 -0
- package/dist/tests/bench/evolve-metrics.test.js +187 -0
- package/dist/tests/bench/evolve.js +580 -0
- package/dist/tests/bench/evolve.test.js +616 -0
- package/dist/tests/bench/failure-modes.test.js +300 -0
- package/dist/tests/bench/feedback-integrity.test.js +456 -0
- package/dist/tests/bench/leakage.test.js +125 -0
- package/dist/tests/bench/learning-curve.test.js +133 -0
- package/dist/tests/bench/metrics.js +2319 -0
- package/dist/tests/bench/metrics.test.js +1144 -0
- package/dist/tests/bench/no-os-tmpdir-invariant.test.js +43 -0
- package/dist/tests/bench/report.js +1821 -0
- package/dist/tests/bench/report.test.js +989 -0
- package/dist/tests/bench/runner.js +536 -0
- package/dist/tests/bench/runner.test.js +958 -0
- package/dist/tests/bench/search-bridge.test.js +331 -0
- package/dist/tests/bench/tmp.js +41 -0
- package/dist/tests/bench/trajectory.js +116 -0
- package/dist/tests/bench/trajectory.test.js +127 -0
- package/dist/tests/bench/verifier.js +109 -0
- package/dist/tests/bench/verifier.test.js +118 -0
- package/dist/tests/bench/workflow-evaluator.js +557 -0
- package/dist/tests/bench/workflow-evaluator.test.js +421 -0
- package/dist/tests/bench/workflow-spec.js +358 -0
- package/dist/tests/bench/workflow-spec.test.js +363 -0
- package/dist/tests/bench/workflow-trace.js +438 -0
- package/dist/tests/bench/workflow-trace.test.js +254 -0
- package/dist/tests/benchmark-search-quality.js +536 -0
- package/dist/tests/benchmark-suite.js +1441 -0
- package/dist/tests/capture-cli.test.js +112 -0
- package/dist/tests/cli-errors.test.js +203 -0
- package/dist/tests/commands/events.test.js +370 -0
- package/dist/tests/commands/history.test.js +223 -0
- package/dist/tests/commands/import.test.js +103 -0
- package/dist/tests/commands/proposal-cli.test.js +209 -0
- package/dist/tests/commands/reflect-propose-cli.test.js +333 -0
- package/dist/tests/commands/remember.test.js +97 -0
- package/dist/tests/commands/scope-flags.test.js +300 -0
- package/dist/tests/commands/search.test.js +537 -0
- package/dist/tests/commands/show-indexer-parity.test.js +117 -0
- package/dist/tests/commands/show.test.js +294 -0
- package/dist/tests/common.test.js +266 -0
- package/dist/tests/completions.test.js +142 -0
- package/dist/tests/config-cli.test.js +193 -0
- package/dist/tests/config-llm-features.test.js +139 -0
- package/dist/tests/config.test.js +544 -0
- package/dist/tests/contracts/migration-baseline.test.js +43 -0
- package/dist/tests/contracts/reflect-propose-envelope.test.js +139 -0
- package/dist/tests/contracts/spec-helpers.js +46 -0
- package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +228 -0
- package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +56 -0
- package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +34 -0
- package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +94 -0
- package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +39 -0
- package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +44 -0
- package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +47 -0
- package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +40 -0
- package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +58 -0
- package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +34 -0
- package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +75 -0
- package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +36 -0
- package/dist/tests/core/write-source.test.js +366 -0
- package/dist/tests/curate-command.test.js +87 -0
- package/dist/tests/db-scoring.test.js +201 -0
- package/dist/tests/db.test.js +654 -0
- package/dist/tests/distill-cli-flag.test.js +208 -0
- package/dist/tests/distill.test.js +515 -0
- package/dist/tests/docker-install.test.js +120 -0
- package/dist/tests/e2e.test.js +1398 -0
- package/dist/tests/embedder.test.js +340 -0
- package/dist/tests/embedding-model-config.test.js +379 -0
- package/dist/tests/feedback-command.test.js +172 -0
- package/dist/tests/file-context.test.js +552 -0
- package/dist/tests/fixtures/scripts/git/summarize-diff.js +9 -0
- package/dist/tests/fixtures/scripts/lint/eslint-check.js +7 -0
- package/dist/tests/fixtures/stashes/load.js +166 -0
- package/dist/tests/fixtures/stashes/load.test.js +88 -0
- package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +12 -0
- package/dist/tests/frontmatter.test.js +190 -0
- package/dist/tests/fts-field-weighting.test.js +254 -0
- package/dist/tests/fuzzy-search.test.js +230 -0
- package/dist/tests/git-provider-clone.test.js +45 -0
- package/dist/tests/github.test.js +161 -0
- package/dist/tests/graph-boost-ranking.test.js +305 -0
- package/dist/tests/graph-extraction.test.js +282 -0
- package/dist/tests/helpers/usage-events.js +8 -0
- package/dist/tests/index-pass-llm.test.js +161 -0
- package/dist/tests/indexer.test.js +559 -0
- package/dist/tests/info-command.test.js +166 -0
- package/dist/tests/init.test.js +69 -0
- package/dist/tests/install-script.test.js +246 -0
- package/dist/tests/integration/agent-real-profile.test.js +94 -0
- package/dist/tests/issue-36-repro.test.js +304 -0
- package/dist/tests/issues-191-194.test.js +160 -0
- package/dist/tests/lesson-lint.test.js +111 -0
- package/dist/tests/llm-client.test.js +115 -0
- package/dist/tests/llm-feature-gate.test.js +151 -0
- package/dist/tests/llm.test.js +139 -0
- package/dist/tests/lockfile.test.js +216 -0
- package/dist/tests/manifest.test.js +205 -0
- package/dist/tests/markdown.test.js +126 -0
- package/dist/tests/matchers-unit.test.js +189 -0
- package/dist/tests/memory-inference.test.js +299 -0
- package/dist/tests/merge-scoring.test.js +136 -0
- package/dist/tests/metadata.test.js +313 -0
- package/dist/tests/migration-help.test.js +89 -0
- package/dist/tests/origin-resolve.test.js +124 -0
- package/dist/tests/output-baseline.test.js +217 -0
- package/dist/tests/output-shapes-unit.test.js +476 -0
- package/dist/tests/parallel-search.test.js +272 -0
- package/dist/tests/parameter-metadata.test.js +365 -0
- package/dist/tests/paths.test.js +177 -0
- package/dist/tests/progressive-disclosure.test.js +280 -0
- package/dist/tests/proposals.test.js +279 -0
- package/dist/tests/proposed-quality.test.js +271 -0
- package/dist/tests/provider-registry.test.js +32 -0
- package/dist/tests/ranking-regression.test.js +548 -0
- package/dist/tests/reflect-propose.test.js +455 -0
- package/dist/tests/registry-build-index.test.js +378 -0
- package/dist/tests/registry-cli.test.js +290 -0
- package/dist/tests/registry-index-v2.test.js +430 -0
- package/dist/tests/registry-install.test.js +728 -0
- package/dist/tests/registry-providers/parity.test.js +189 -0
- package/dist/tests/registry-providers/skills-sh.test.js +309 -0
- package/dist/tests/registry-providers/static-index.test.js +204 -0
- package/dist/tests/registry-resolve.test.js +126 -0
- package/dist/tests/registry-search.test.js +723 -0
- package/dist/tests/remember-frontmatter.test.js +380 -0
- package/dist/tests/remember-unit.test.js +123 -0
- package/dist/tests/ripgrep-install.test.js +251 -0
- package/dist/tests/ripgrep-resolve.test.js +108 -0
- package/dist/tests/ripgrep.test.js +163 -0
- package/dist/tests/save-command.test.js +94 -0
- package/dist/tests/save-trust-qa-fixes.test.js +270 -0
- package/dist/tests/scoring-pipeline.test.js +648 -0
- package/dist/tests/search-include-proposed-cli.test.js +118 -0
- package/dist/tests/self-update.test.js +442 -0
- package/dist/tests/semantic-search-e2e.test.js +512 -0
- package/dist/tests/semantic-status.test.js +471 -0
- package/dist/tests/setup-run.integration.js +877 -0
- package/dist/tests/setup-wizard.test.js +198 -0
- package/dist/tests/setup.test.js +131 -0
- package/dist/tests/source-add.test.js +11 -0
- package/dist/tests/source-clone.test.js +254 -0
- package/dist/tests/source-manage.test.js +366 -0
- package/dist/tests/source-providers/filesystem.test.js +82 -0
- package/dist/tests/source-providers/git.test.js +252 -0
- package/dist/tests/source-providers/website.test.js +128 -0
- package/dist/tests/source-qa-fixes.test.js +268 -0
- package/dist/tests/source-registry.test.js +350 -0
- package/dist/tests/source-resolve.test.js +100 -0
- package/dist/tests/source-source.test.js +221 -0
- package/dist/tests/source.test.js +533 -0
- package/dist/tests/tar-utils-scan.test.js +73 -0
- package/dist/tests/toggle-components.test.js +73 -0
- package/dist/tests/usage-telemetry.test.js +265 -0
- package/dist/tests/utility-scoring.test.js +558 -0
- package/dist/tests/vault-load-error.test.js +78 -0
- package/dist/tests/vault-qa-fixes.test.js +194 -0
- package/dist/tests/vault.test.js +429 -0
- package/dist/tests/vector-search.test.js +608 -0
- package/dist/tests/walker.test.js +252 -0
- package/dist/tests/wave2-cluster-bc.test.js +228 -0
- package/dist/tests/wave2-cluster-d.test.js +180 -0
- package/dist/tests/wave2-cluster-e.test.js +179 -0
- package/dist/tests/wiki-qa-fixes.test.js +270 -0
- package/dist/tests/wiki.test.js +529 -0
- package/dist/tests/workflow-cli.test.js +271 -0
- package/dist/tests/workflow-markdown.test.js +171 -0
- package/dist/tests/workflow-path-escape.test.js +132 -0
- package/dist/tests/workflow-qa-fixes.test.js +377 -0
- package/dist/tests/workflows/indexer-rejection.test.js +213 -0
- package/docs/README.md +8 -0
- package/docs/migration/release-notes/0.7.0.md +244 -0
- package/package.json +2 -2
- package/dist/core/warn.js +0 -27
- package/dist/output/shapes.js +0 -212
- /package/dist/{commands → src/commands}/completions.js +0 -0
- /package/dist/{commands → src/commands}/curate.js +0 -0
- /package/dist/{commands → src/commands}/info.js +0 -0
- /package/dist/{commands → src/commands}/init.js +0 -0
- /package/dist/{commands → src/commands}/install-audit.js +0 -0
- /package/dist/{commands → src/commands}/migration-help.js +0 -0
- /package/dist/{commands → src/commands}/source-add.js +0 -0
- /package/dist/{commands → src/commands}/source-clone.js +0 -0
- /package/dist/{commands → src/commands}/source-manage.js +0 -0
- /package/dist/{commands → src/commands}/vault.js +0 -0
- /package/dist/{core → src/core}/asset-registry.js +0 -0
- /package/dist/{core → src/core}/frontmatter.js +0 -0
- /package/dist/{core → src/core}/markdown.js +0 -0
- /package/dist/{core → src/core}/paths.js +0 -0
- /package/dist/{indexer → src/indexer}/manifest.js +0 -0
- /package/dist/{indexer → src/indexer}/matchers.js +0 -0
- /package/dist/{indexer → src/indexer}/search-fields.js +0 -0
- /package/dist/{indexer → src/indexer}/search-source.js +0 -0
- /package/dist/{indexer → src/indexer}/semantic-status.js +0 -0
- /package/dist/{indexer → src/indexer}/usage-events.js +0 -0
- /package/dist/{indexer → src/indexer}/walker.js +0 -0
- /package/dist/{integrations → src/integrations}/github.js +0 -0
- /package/dist/{llm → src/llm}/embedder.js +0 -0
- /package/dist/{llm → src/llm}/embedders/cache.js +0 -0
- /package/dist/{llm → src/llm}/embedders/local.js +0 -0
- /package/dist/{llm → src/llm}/embedders/remote.js +0 -0
- /package/dist/{llm → src/llm}/embedders/types.js +0 -0
- /package/dist/{llm → src/llm}/metadata-enhance.js +0 -0
- /package/dist/{output → src/output}/cli-hints.js +0 -0
- /package/dist/{output → src/output}/context.js +0 -0
- /package/dist/{registry → src/registry}/create-provider-registry.js +0 -0
- /package/dist/{registry → src/registry}/origin-resolve.js +0 -0
- /package/dist/{registry → src/registry}/providers/index.js +0 -0
- /package/dist/{registry → src/registry}/providers/skills-sh.js +0 -0
- /package/dist/{registry → src/registry}/providers/types.js +0 -0
- /package/dist/{registry → src/registry}/types.js +0 -0
- /package/dist/{setup → src/setup}/detect.js +0 -0
- /package/dist/{setup → src/setup}/ripgrep-install.js +0 -0
- /package/dist/{setup → src/setup}/ripgrep-resolve.js +0 -0
- /package/dist/{setup → src/setup}/steps.js +0 -0
- /package/dist/{sources → src/sources}/include.js +0 -0
- /package/dist/{sources → src/sources}/provider-factory.js +0 -0
- /package/dist/{sources → src/sources}/provider.js +0 -0
- /package/dist/{sources → src/sources}/providers/filesystem.js +0 -0
- /package/dist/{sources → src/sources}/providers/index.js +0 -0
- /package/dist/{sources → src/sources}/providers/install-types.js +0 -0
- /package/dist/{sources → src/sources}/providers/npm.js +0 -0
- /package/dist/{sources → src/sources}/providers/provider-utils.js +0 -0
- /package/dist/{sources → src/sources}/providers/sync-from-ref.js +0 -0
- /package/dist/{sources → src/sources}/providers/tar-utils.js +0 -0
- /package/dist/{sources → src/sources}/providers/website.js +0 -0
- /package/dist/{sources → src/sources}/resolve.js +0 -0
- /package/dist/{sources → src/sources}/types.js +0 -0
- /package/dist/{templates → src/templates}/wiki-templates.js +0 -0
- /package/dist/{version.js → src/version.js} +0 -0
- /package/dist/{wiki → src/wiki}/wiki.js +0 -0
- /package/dist/{workflows → src/workflows}/authoring.js +0 -0
- /package/dist/{workflows → src/workflows}/cli.js +0 -0
- /package/dist/{workflows → src/workflows}/db.js +0 -0
- /package/dist/{workflows → src/workflows}/document-cache.js +0 -0
- /package/dist/{workflows → src/workflows}/parser.js +0 -0
- /package/dist/{workflows → src/workflows}/renderer.js +0 -0
- /package/dist/{workflows → src/workflows}/runs.js +0 -0
- /package/dist/{workflows → src/workflows}/schema.js +0 -0
- /package/dist/{workflows → src/workflows}/validator.js +0 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* import --target tests
|
|
3
|
+
*
|
|
4
|
+
* Verifies the `--target` flag added to `akm import` per v1 implementation
|
|
5
|
+
* plan §6 decision 3. Resolution order is:
|
|
6
|
+
* --target → defaultWriteTarget → working stash → ConfigError
|
|
7
|
+
*
|
|
8
|
+
* These tests exercise the explicit-target path:
|
|
9
|
+
* - resolves to a configured filesystem source by name
|
|
10
|
+
* - errors on unknown target names (UsageError)
|
|
11
|
+
* - errors on non-writable targets (ConfigError)
|
|
12
|
+
*/
|
|
13
|
+
import { afterEach, describe, expect, test } from "bun:test";
|
|
14
|
+
import { spawnSync } from "node:child_process";
|
|
15
|
+
import fs from "node:fs";
|
|
16
|
+
import os from "node:os";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
const CLI = path.join(__dirname, "..", "..", "src", "cli.ts");
|
|
19
|
+
const tempDirs = [];
|
|
20
|
+
function makeTempDir(prefix) {
|
|
21
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
22
|
+
tempDirs.push(dir);
|
|
23
|
+
return dir;
|
|
24
|
+
}
|
|
25
|
+
function writeConfig(configDir, body) {
|
|
26
|
+
const akmDir = path.join(configDir, "akm");
|
|
27
|
+
fs.mkdirSync(akmDir, { recursive: true });
|
|
28
|
+
fs.writeFileSync(path.join(akmDir, "config.json"), JSON.stringify(body, null, 2), "utf8");
|
|
29
|
+
}
|
|
30
|
+
function runCli(args, options) {
|
|
31
|
+
const stashDir = options.stashDir ?? makeTempDir("akm-import-stash-");
|
|
32
|
+
const xdgCache = makeTempDir("akm-import-cache-");
|
|
33
|
+
const result = spawnSync("bun", [CLI, ...args], {
|
|
34
|
+
encoding: "utf8",
|
|
35
|
+
timeout: 30_000,
|
|
36
|
+
input: options.input,
|
|
37
|
+
env: {
|
|
38
|
+
...process.env,
|
|
39
|
+
AKM_STASH_DIR: stashDir,
|
|
40
|
+
AKM_CONFIG_DIR: path.join(options.configDir, "akm"),
|
|
41
|
+
XDG_CACHE_HOME: xdgCache,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
return { stashDir, result };
|
|
45
|
+
}
|
|
46
|
+
function makeKnowledgeFile(name, body) {
|
|
47
|
+
const dir = makeTempDir("akm-import-source-");
|
|
48
|
+
const filePath = path.join(dir, name);
|
|
49
|
+
fs.writeFileSync(filePath, body, "utf8");
|
|
50
|
+
return filePath;
|
|
51
|
+
}
|
|
52
|
+
afterEach(() => {
|
|
53
|
+
for (const dir of tempDirs.splice(0)) {
|
|
54
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
describe("import --target", () => {
|
|
58
|
+
test("--target resolves to a configured filesystem source", () => {
|
|
59
|
+
const configDir = makeTempDir("akm-import-config-");
|
|
60
|
+
const targetDir = makeTempDir("akm-import-target-");
|
|
61
|
+
writeConfig(configDir, {
|
|
62
|
+
semanticSearchMode: "off",
|
|
63
|
+
sources: [{ type: "filesystem", name: "writable-target", path: targetDir, writable: true }],
|
|
64
|
+
});
|
|
65
|
+
const sourcePath = makeKnowledgeFile("auth-flow.md", "# Auth flow\n\nOAuth2 walk-through.\n");
|
|
66
|
+
const { stashDir, result } = runCli(["import", sourcePath, "--target", "writable-target"], { configDir });
|
|
67
|
+
expect(result.status).toBe(0);
|
|
68
|
+
const json = JSON.parse(result.stdout);
|
|
69
|
+
expect(json.ok).toBe(true);
|
|
70
|
+
expect(json.ref).toBe("knowledge:auth-flow");
|
|
71
|
+
const expectedPath = path.join(targetDir, "knowledge", "auth-flow.md");
|
|
72
|
+
expect(json.path).toBe(expectedPath);
|
|
73
|
+
expect(fs.existsSync(expectedPath)).toBe(true);
|
|
74
|
+
expect(fs.existsSync(path.join(stashDir, "knowledge", "auth-flow.md"))).toBe(false);
|
|
75
|
+
});
|
|
76
|
+
test("--target with an unknown source name throws a usage error", () => {
|
|
77
|
+
const configDir = makeTempDir("akm-import-config-");
|
|
78
|
+
const targetDir = makeTempDir("akm-import-target-");
|
|
79
|
+
writeConfig(configDir, {
|
|
80
|
+
semanticSearchMode: "off",
|
|
81
|
+
sources: [{ type: "filesystem", name: "real-target", path: targetDir, writable: true }],
|
|
82
|
+
});
|
|
83
|
+
const sourcePath = makeKnowledgeFile("notes.md", "# Notes\n\nSomething.\n");
|
|
84
|
+
const { result } = runCli(["import", sourcePath, "--target", "ghost"], { configDir });
|
|
85
|
+
expect(result.status).toBe(2);
|
|
86
|
+
const json = JSON.parse(result.stderr);
|
|
87
|
+
expect(json.error).toContain('No source named "ghost" is configured');
|
|
88
|
+
expect(json.error).toContain("--target must reference a source name");
|
|
89
|
+
});
|
|
90
|
+
test("--target on a non-writable source throws a config error", () => {
|
|
91
|
+
const configDir = makeTempDir("akm-import-config-");
|
|
92
|
+
const targetDir = makeTempDir("akm-import-target-");
|
|
93
|
+
writeConfig(configDir, {
|
|
94
|
+
semanticSearchMode: "off",
|
|
95
|
+
sources: [{ type: "filesystem", name: "read-only", path: targetDir, writable: false }],
|
|
96
|
+
});
|
|
97
|
+
const sourcePath = makeKnowledgeFile("notes.md", "# Notes\n\nSomething.\n");
|
|
98
|
+
const { result } = runCli(["import", sourcePath, "--target", "read-only"], { configDir });
|
|
99
|
+
expect(result.status).not.toBe(0);
|
|
100
|
+
const json = JSON.parse(result.stderr);
|
|
101
|
+
expect(json.error).toContain("source read-only is not writable");
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* End-to-end CLI integration tests for `akm proposal {list,show,accept,reject,diff}`.
|
|
3
|
+
*
|
|
4
|
+
* Exercises the citty dispatcher as a real subprocess so:
|
|
5
|
+
* - flag parsing,
|
|
6
|
+
* - exit-code mapping (UsageError → 2, NotFoundError → 1, success → 0),
|
|
7
|
+
* - JSON envelope shape,
|
|
8
|
+
* are all covered end-to-end. A pre-built stash directory (created via the
|
|
9
|
+
* direct `createProposal` helper) seeds the proposal queue so each subcommand
|
|
10
|
+
* has a deterministic id to act on.
|
|
11
|
+
*
|
|
12
|
+
* Backfill for issue #284 GAP-CRIT 1.
|
|
13
|
+
*/
|
|
14
|
+
import { afterAll, beforeEach, describe, expect, test } from "bun:test";
|
|
15
|
+
import { spawnSync } from "node:child_process";
|
|
16
|
+
import fs from "node:fs";
|
|
17
|
+
import os from "node:os";
|
|
18
|
+
import path from "node:path";
|
|
19
|
+
import { createProposal } from "../../src/core/proposals";
|
|
20
|
+
const tempDirs = [];
|
|
21
|
+
function makeTempDir(prefix = "akm-proposal-cli-") {
|
|
22
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
23
|
+
tempDirs.push(dir);
|
|
24
|
+
return dir;
|
|
25
|
+
}
|
|
26
|
+
function makeStashDir() {
|
|
27
|
+
const stash = makeTempDir("akm-proposal-cli-stash-");
|
|
28
|
+
for (const sub of ["lessons", "skills", "memories", "knowledge"]) {
|
|
29
|
+
fs.mkdirSync(path.join(stash, sub), { recursive: true });
|
|
30
|
+
}
|
|
31
|
+
return stash;
|
|
32
|
+
}
|
|
33
|
+
afterAll(() => {
|
|
34
|
+
for (const dir of tempDirs.splice(0)) {
|
|
35
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const repoRoot = path.resolve(import.meta.dir, "..", "..");
|
|
39
|
+
const cliPath = path.join(repoRoot, "src", "cli.ts");
|
|
40
|
+
function runCli(args, options = { stashDir: "" }) {
|
|
41
|
+
const xdgCache = makeTempDir("akm-proposal-cli-cache-");
|
|
42
|
+
const xdgConfig = makeTempDir("akm-proposal-cli-config-");
|
|
43
|
+
const home = makeTempDir("akm-proposal-cli-home-");
|
|
44
|
+
const result = spawnSync("bun", [cliPath, ...args], {
|
|
45
|
+
encoding: "utf8",
|
|
46
|
+
timeout: 20_000,
|
|
47
|
+
cwd: repoRoot,
|
|
48
|
+
env: {
|
|
49
|
+
...process.env,
|
|
50
|
+
AKM_STASH_DIR: options.stashDir || undefined,
|
|
51
|
+
HOME: home,
|
|
52
|
+
XDG_CACHE_HOME: xdgCache,
|
|
53
|
+
XDG_CONFIG_HOME: xdgConfig,
|
|
54
|
+
...options.env,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
stdout: result.stdout ?? "",
|
|
59
|
+
stderr: result.stderr ?? "",
|
|
60
|
+
status: result.status ?? -1,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const VALID_LESSON = `---\ndescription: Use ripgrep before grep\nwhen_to_use: Searching large repos\n---\n\nPrefer rg.\n`;
|
|
64
|
+
function seedProposal(stash, ref = "lesson:rg-over-grep") {
|
|
65
|
+
return createProposal(stash, {
|
|
66
|
+
ref,
|
|
67
|
+
source: "reflect",
|
|
68
|
+
payload: { content: VALID_LESSON },
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
beforeEach(() => {
|
|
72
|
+
// (Each test creates its own stash dir so we get fresh state.)
|
|
73
|
+
});
|
|
74
|
+
describe("akm proposal list (CLI)", () => {
|
|
75
|
+
test("happy path: lists pending proposal as JSON with totalCount", () => {
|
|
76
|
+
const stash = makeStashDir();
|
|
77
|
+
const created = seedProposal(stash);
|
|
78
|
+
const result = runCli(["proposal", "list", "--format=json"], { stashDir: stash });
|
|
79
|
+
expect(result.status).toBe(0);
|
|
80
|
+
const parsed = JSON.parse(result.stdout);
|
|
81
|
+
expect(parsed.totalCount).toBe(1);
|
|
82
|
+
expect(Array.isArray(parsed.proposals)).toBe(true);
|
|
83
|
+
expect(parsed.proposals[0].id).toBe(created.id);
|
|
84
|
+
expect(parsed.proposals[0].ref).toBe("lesson:rg-over-grep");
|
|
85
|
+
expect(parsed.proposals[0].status).toBe("pending");
|
|
86
|
+
});
|
|
87
|
+
test("error path: invalid --status value → UsageError exit 2 with code", () => {
|
|
88
|
+
const stash = makeStashDir();
|
|
89
|
+
seedProposal(stash);
|
|
90
|
+
const result = runCli(["proposal", "list", "--status=bogus", "--format=json"], { stashDir: stash });
|
|
91
|
+
expect(result.status).toBe(2);
|
|
92
|
+
const envelope = JSON.parse(result.stderr);
|
|
93
|
+
expect(envelope.ok).toBe(false);
|
|
94
|
+
expect(envelope.code).toBe("INVALID_FLAG_VALUE");
|
|
95
|
+
expect(envelope.error).toContain("Invalid --status value");
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
describe("akm proposal show (CLI)", () => {
|
|
99
|
+
test("happy path: returns proposal + validation report", () => {
|
|
100
|
+
const stash = makeStashDir();
|
|
101
|
+
const created = seedProposal(stash);
|
|
102
|
+
const result = runCli(["proposal", "show", created.id, "--format=json"], { stashDir: stash });
|
|
103
|
+
expect(result.status).toBe(0);
|
|
104
|
+
const parsed = JSON.parse(result.stdout);
|
|
105
|
+
expect(parsed.proposal).toBeDefined();
|
|
106
|
+
expect(parsed.proposal.id).toBe(created.id);
|
|
107
|
+
expect(parsed.proposal.ref).toBe("lesson:rg-over-grep");
|
|
108
|
+
expect(parsed.validation).toBeDefined();
|
|
109
|
+
expect(parsed.validation.ok).toBe(true);
|
|
110
|
+
});
|
|
111
|
+
test("error path: missing id → NotFoundError, exit 1", () => {
|
|
112
|
+
const stash = makeStashDir();
|
|
113
|
+
const result = runCli(["proposal", "show", "00000000-dead-beef-0000-000000000000", "--format=json"], {
|
|
114
|
+
stashDir: stash,
|
|
115
|
+
});
|
|
116
|
+
expect(result.status).toBe(1);
|
|
117
|
+
const envelope = JSON.parse(result.stderr);
|
|
118
|
+
expect(envelope.ok).toBe(false);
|
|
119
|
+
expect(envelope.code).toBe("FILE_NOT_FOUND");
|
|
120
|
+
expect(envelope.error).toContain("00000000-dead-beef-0000-000000000000");
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
describe("akm proposal accept (CLI)", () => {
|
|
124
|
+
test("happy path: materialises asset on disk and exits 0", () => {
|
|
125
|
+
const stash = makeStashDir();
|
|
126
|
+
const created = seedProposal(stash);
|
|
127
|
+
const result = runCli(["proposal", "accept", created.id, "--format=json"], { stashDir: stash });
|
|
128
|
+
expect(result.status).toBe(0);
|
|
129
|
+
const parsed = JSON.parse(result.stdout);
|
|
130
|
+
expect(parsed.ok).toBe(true);
|
|
131
|
+
expect(parsed.id).toBe(created.id);
|
|
132
|
+
expect(parsed.ref).toBe("lesson:rg-over-grep");
|
|
133
|
+
expect(parsed.assetPath).toBeDefined();
|
|
134
|
+
expect(fs.existsSync(parsed.assetPath)).toBe(true);
|
|
135
|
+
});
|
|
136
|
+
test("error path: missing id → NotFoundError exit 1", () => {
|
|
137
|
+
const stash = makeStashDir();
|
|
138
|
+
const result = runCli(["proposal", "accept", "11111111-dead-beef-0000-000000000000", "--format=json"], {
|
|
139
|
+
stashDir: stash,
|
|
140
|
+
});
|
|
141
|
+
expect(result.status).toBe(1);
|
|
142
|
+
const envelope = JSON.parse(result.stderr);
|
|
143
|
+
expect(envelope.ok).toBe(false);
|
|
144
|
+
expect(envelope.code).toBe("FILE_NOT_FOUND");
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
describe("akm proposal reject (CLI)", () => {
|
|
148
|
+
test("happy path: archives proposal with reason, exit 0", () => {
|
|
149
|
+
const stash = makeStashDir();
|
|
150
|
+
const created = seedProposal(stash);
|
|
151
|
+
const result = runCli(["proposal", "reject", created.id, "--reason", "duplicate", "--format=json"], {
|
|
152
|
+
stashDir: stash,
|
|
153
|
+
});
|
|
154
|
+
expect(result.status).toBe(0);
|
|
155
|
+
const parsed = JSON.parse(result.stdout);
|
|
156
|
+
expect(parsed.ok).toBe(true);
|
|
157
|
+
expect(parsed.reason).toBe("duplicate");
|
|
158
|
+
// Live queue should now be empty.
|
|
159
|
+
const list = runCli(["proposal", "list", "--format=json"], { stashDir: stash });
|
|
160
|
+
expect(JSON.parse(list.stdout).totalCount).toBe(0);
|
|
161
|
+
});
|
|
162
|
+
test("error path: rejecting a non-pending proposal → UsageError INVALID_FLAG_VALUE, exit 2", () => {
|
|
163
|
+
const stash = makeStashDir();
|
|
164
|
+
const created = seedProposal(stash);
|
|
165
|
+
// Reject once → archive.
|
|
166
|
+
const first = runCli(["proposal", "reject", created.id, "--format=json"], { stashDir: stash });
|
|
167
|
+
expect(first.status).toBe(0);
|
|
168
|
+
// Reject again → must surface UsageError because it's no longer pending.
|
|
169
|
+
const second = runCli(["proposal", "reject", created.id, "--format=json"], { stashDir: stash });
|
|
170
|
+
expect(second.status).toBe(2);
|
|
171
|
+
const envelope = JSON.parse(second.stderr);
|
|
172
|
+
expect(envelope.ok).toBe(false);
|
|
173
|
+
expect(envelope.code).toBe("INVALID_FLAG_VALUE");
|
|
174
|
+
expect(envelope.error).toMatch(/not pending|already/i);
|
|
175
|
+
});
|
|
176
|
+
test("error path: missing id → NotFoundError exit 1", () => {
|
|
177
|
+
const stash = makeStashDir();
|
|
178
|
+
const result = runCli(["proposal", "reject", "22222222-dead-beef-0000-000000000000", "--format=json"], {
|
|
179
|
+
stashDir: stash,
|
|
180
|
+
});
|
|
181
|
+
expect(result.status).toBe(1);
|
|
182
|
+
const envelope = JSON.parse(result.stderr);
|
|
183
|
+
expect(envelope.code).toBe("FILE_NOT_FOUND");
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
describe("akm proposal diff (CLI)", () => {
|
|
187
|
+
test("happy path: new asset diff contains /dev/null marker", () => {
|
|
188
|
+
const stash = makeStashDir();
|
|
189
|
+
const created = seedProposal(stash);
|
|
190
|
+
const result = runCli(["proposal", "diff", created.id, "--format=json"], { stashDir: stash });
|
|
191
|
+
expect(result.status).toBe(0);
|
|
192
|
+
const parsed = JSON.parse(result.stdout);
|
|
193
|
+
expect(parsed.id).toBe(created.id);
|
|
194
|
+
expect(parsed.ref).toBe("lesson:rg-over-grep");
|
|
195
|
+
expect(parsed.isNew).toBe(true);
|
|
196
|
+
expect(parsed.unified).toContain("/dev/null");
|
|
197
|
+
expect(parsed.unified).toContain("Prefer rg");
|
|
198
|
+
});
|
|
199
|
+
test("error path: missing id → NotFoundError exit 1", () => {
|
|
200
|
+
const stash = makeStashDir();
|
|
201
|
+
const result = runCli(["proposal", "diff", "33333333-dead-beef-0000-000000000000", "--format=json"], {
|
|
202
|
+
stashDir: stash,
|
|
203
|
+
});
|
|
204
|
+
expect(result.status).toBe(1);
|
|
205
|
+
const envelope = JSON.parse(result.stderr);
|
|
206
|
+
expect(envelope.ok).toBe(false);
|
|
207
|
+
expect(envelope.code).toBe("FILE_NOT_FOUND");
|
|
208
|
+
});
|
|
209
|
+
});
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-tree CLI argv-coercion tests for `akm reflect` and `akm propose` (#226).
|
|
3
|
+
*
|
|
4
|
+
* The real CLI dispatcher in `src/cli.ts` coerces citty's argv shape
|
|
5
|
+
* (`{ ref?, task?, profile?, "timeout-ms"?, type, name }`) into the
|
|
6
|
+
* `AkmReflectOptions` / `AkmProposeOptions` shape consumed by
|
|
7
|
+
* `akmReflect` / `akmPropose`. Exercising the live `runMain` here would
|
|
8
|
+
* require spawning the CLI and stubbing PATH-resolved binaries, which is
|
|
9
|
+
* brittle. Instead we replicate the exact argv coercion logic and assert it
|
|
10
|
+
* matches the production code, then drive `akmReflect` / `akmPropose` with
|
|
11
|
+
* a captured-spawn fake (mirroring `tests/agent/agent-spawn.test.ts`) for
|
|
12
|
+
* deterministic happy + failure paths.
|
|
13
|
+
*
|
|
14
|
+
* Backfill for issue #284 GAP-CRIT 2.
|
|
15
|
+
*/
|
|
16
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
17
|
+
import fs from "node:fs";
|
|
18
|
+
import os from "node:os";
|
|
19
|
+
import path from "node:path";
|
|
20
|
+
import { akmPropose } from "../../src/commands/propose";
|
|
21
|
+
import { akmReflect } from "../../src/commands/reflect";
|
|
22
|
+
const tempDirs = [];
|
|
23
|
+
const savedEnv = {
|
|
24
|
+
AKM_STASH_DIR: process.env.AKM_STASH_DIR,
|
|
25
|
+
XDG_CACHE_HOME: process.env.XDG_CACHE_HOME,
|
|
26
|
+
XDG_CONFIG_HOME: process.env.XDG_CONFIG_HOME,
|
|
27
|
+
};
|
|
28
|
+
function makeTempDir(prefix) {
|
|
29
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
|
|
30
|
+
tempDirs.push(dir);
|
|
31
|
+
return dir;
|
|
32
|
+
}
|
|
33
|
+
function makeStashDir() {
|
|
34
|
+
const stash = makeTempDir("akm-rp-cli-stash-");
|
|
35
|
+
for (const sub of ["lessons", "skills", "memories", "knowledge"]) {
|
|
36
|
+
fs.mkdirSync(path.join(stash, sub), { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
return stash;
|
|
39
|
+
}
|
|
40
|
+
function makeProfile(overrides = {}) {
|
|
41
|
+
return {
|
|
42
|
+
name: "fake-agent",
|
|
43
|
+
bin: "fake-agent",
|
|
44
|
+
args: [],
|
|
45
|
+
stdio: "captured",
|
|
46
|
+
envPassthrough: ["PATH"],
|
|
47
|
+
parseOutput: "text",
|
|
48
|
+
...overrides,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function asReadableStream(text) {
|
|
52
|
+
const bytes = new TextEncoder().encode(text);
|
|
53
|
+
return new ReadableStream({
|
|
54
|
+
start(controller) {
|
|
55
|
+
controller.enqueue(bytes);
|
|
56
|
+
controller.close();
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function fakeSpawn(stdout, stderr, exitCode, capture) {
|
|
61
|
+
return (cmd) => {
|
|
62
|
+
capture?.(cmd);
|
|
63
|
+
const proc = {
|
|
64
|
+
exitCode,
|
|
65
|
+
exited: Promise.resolve(exitCode),
|
|
66
|
+
stdout: asReadableStream(stdout),
|
|
67
|
+
stderr: asReadableStream(stderr),
|
|
68
|
+
stdin: null,
|
|
69
|
+
kill: () => undefined,
|
|
70
|
+
};
|
|
71
|
+
return proc;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function hangingSpawn() {
|
|
75
|
+
return () => {
|
|
76
|
+
let resolveExit;
|
|
77
|
+
const exited = new Promise((r) => {
|
|
78
|
+
resolveExit = r;
|
|
79
|
+
});
|
|
80
|
+
const proc = {
|
|
81
|
+
exitCode: null,
|
|
82
|
+
exited,
|
|
83
|
+
stdout: asReadableStream(""),
|
|
84
|
+
stderr: asReadableStream(""),
|
|
85
|
+
stdin: null,
|
|
86
|
+
kill: () => resolveExit?.(143),
|
|
87
|
+
};
|
|
88
|
+
return proc;
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const VALID_LESSON_PAYLOAD = JSON.stringify({
|
|
92
|
+
ref: "lesson:rg-over-grep",
|
|
93
|
+
content: "---\ndescription: Use ripgrep before grep\nwhen_to_use: Searching large repos for patterns\n---\n\nPrefer rg.\n",
|
|
94
|
+
});
|
|
95
|
+
const VALID_SKILL_PAYLOAD = JSON.stringify({
|
|
96
|
+
ref: "skill:hello",
|
|
97
|
+
content: "---\ndescription: Say hi\nwhen_to_use: When greeting\n---\n\nSay hi politely.\n",
|
|
98
|
+
});
|
|
99
|
+
beforeEach(() => {
|
|
100
|
+
process.env.XDG_CACHE_HOME = makeTempDir("akm-rp-cli-cache-");
|
|
101
|
+
process.env.XDG_CONFIG_HOME = makeTempDir("akm-rp-cli-config-");
|
|
102
|
+
});
|
|
103
|
+
afterEach(() => {
|
|
104
|
+
if (savedEnv.AKM_STASH_DIR === undefined)
|
|
105
|
+
delete process.env.AKM_STASH_DIR;
|
|
106
|
+
else
|
|
107
|
+
process.env.AKM_STASH_DIR = savedEnv.AKM_STASH_DIR;
|
|
108
|
+
if (savedEnv.XDG_CACHE_HOME === undefined)
|
|
109
|
+
delete process.env.XDG_CACHE_HOME;
|
|
110
|
+
else
|
|
111
|
+
process.env.XDG_CACHE_HOME = savedEnv.XDG_CACHE_HOME;
|
|
112
|
+
if (savedEnv.XDG_CONFIG_HOME === undefined)
|
|
113
|
+
delete process.env.XDG_CONFIG_HOME;
|
|
114
|
+
else
|
|
115
|
+
process.env.XDG_CONFIG_HOME = savedEnv.XDG_CONFIG_HOME;
|
|
116
|
+
for (const dir of tempDirs.splice(0)) {
|
|
117
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
// ── argv coercion helpers (mirror src/cli.ts) ───────────────────────────────
|
|
121
|
+
/**
|
|
122
|
+
* Mirror of `cli.ts` reflect-command coercion. Exercises the same string
|
|
123
|
+
* trimming + Number.parseInt path the CLI dispatcher uses so a regression in
|
|
124
|
+
* either place fails this test.
|
|
125
|
+
*/
|
|
126
|
+
function coerceReflectArgs(args) {
|
|
127
|
+
const timeoutRaw = args["timeout-ms"];
|
|
128
|
+
const timeoutMs = typeof timeoutRaw === "string" && timeoutRaw.trim() ? Number.parseInt(timeoutRaw, 10) : undefined;
|
|
129
|
+
return {
|
|
130
|
+
ref: typeof args.ref === "string" && args.ref.trim() ? args.ref : undefined,
|
|
131
|
+
task: typeof args.task === "string" && args.task.trim() ? args.task : undefined,
|
|
132
|
+
profile: typeof args.profile === "string" && args.profile.trim() ? args.profile : undefined,
|
|
133
|
+
...(timeoutMs !== undefined && Number.isFinite(timeoutMs) ? { timeoutMs } : {}),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function coerceProposeArgs(args) {
|
|
137
|
+
const timeoutRaw = args["timeout-ms"];
|
|
138
|
+
const timeoutMs = typeof timeoutRaw === "string" && timeoutRaw.trim() ? Number.parseInt(timeoutRaw, 10) : undefined;
|
|
139
|
+
return {
|
|
140
|
+
type: String(args.type),
|
|
141
|
+
name: String(args.name),
|
|
142
|
+
task: String(args.task ?? ""),
|
|
143
|
+
profile: typeof args.profile === "string" && args.profile.trim() ? args.profile : undefined,
|
|
144
|
+
...(timeoutMs !== undefined && Number.isFinite(timeoutMs) ? { timeoutMs } : {}),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
// ── Coercion unit tests ────────────────────────────────────────────────────
|
|
148
|
+
describe("citty argv → akmReflect coercion", () => {
|
|
149
|
+
test("string fields trimmed; empty strings → undefined", () => {
|
|
150
|
+
expect(coerceReflectArgs({ ref: "lesson:foo", task: " ", profile: "" })).toEqual({
|
|
151
|
+
ref: "lesson:foo",
|
|
152
|
+
task: undefined,
|
|
153
|
+
profile: undefined,
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
test("--timeout-ms parsed as integer", () => {
|
|
157
|
+
expect(coerceReflectArgs({ "timeout-ms": "1500" })).toMatchObject({ timeoutMs: 1500 });
|
|
158
|
+
});
|
|
159
|
+
test("non-numeric --timeout-ms → omitted (Number.isFinite filter)", () => {
|
|
160
|
+
expect(coerceReflectArgs({ "timeout-ms": "abc" })).not.toHaveProperty("timeoutMs");
|
|
161
|
+
});
|
|
162
|
+
test("blank --timeout-ms is omitted", () => {
|
|
163
|
+
expect(coerceReflectArgs({ "timeout-ms": " " })).not.toHaveProperty("timeoutMs");
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
describe("citty argv → akmPropose coercion", () => {
|
|
167
|
+
test("type/name/task always strings; profile trimmed", () => {
|
|
168
|
+
expect(coerceProposeArgs({ type: "skill", name: "hello", task: "Say hi", profile: " " })).toEqual({
|
|
169
|
+
type: "skill",
|
|
170
|
+
name: "hello",
|
|
171
|
+
task: "Say hi",
|
|
172
|
+
profile: undefined,
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
test("missing task coerced to empty string (downstream UsageError)", () => {
|
|
176
|
+
expect(coerceProposeArgs({ type: "skill", name: "x" })).toMatchObject({ task: "" });
|
|
177
|
+
});
|
|
178
|
+
test("--timeout-ms parsed; profile passed through when set", () => {
|
|
179
|
+
expect(coerceProposeArgs({ type: "skill", name: "x", task: "go", "timeout-ms": "9000", profile: "claude" })).toMatchObject({ timeoutMs: 9000, profile: "claude" });
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
// ── Reflect command behaviour with coerced args ────────────────────────────
|
|
183
|
+
describe("akmReflect — argv-coerced calls (happy + failure)", () => {
|
|
184
|
+
test("happy: argv-shape passed through coercion → queues a proposal", async () => {
|
|
185
|
+
const stash = makeStashDir();
|
|
186
|
+
const coerced = coerceReflectArgs({ ref: "lesson:rg-over-grep", task: "focus on speed", "timeout-ms": "5000" });
|
|
187
|
+
let capturedCmd = [];
|
|
188
|
+
const result = await akmReflect({
|
|
189
|
+
...coerced,
|
|
190
|
+
stashDir: stash,
|
|
191
|
+
agentProfile: makeProfile(),
|
|
192
|
+
runAgentOptions: {
|
|
193
|
+
spawn: fakeSpawn(VALID_LESSON_PAYLOAD, "", 0, (cmd) => {
|
|
194
|
+
capturedCmd = cmd;
|
|
195
|
+
}),
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
expect(result.ok).toBe(true);
|
|
199
|
+
if (!result.ok)
|
|
200
|
+
throw new Error("expected ok");
|
|
201
|
+
expect(result.proposal.ref).toBe("lesson:rg-over-grep");
|
|
202
|
+
expect(capturedCmd[0]).toBe("fake-agent");
|
|
203
|
+
});
|
|
204
|
+
test("parse_error: agent stdout is malformed → ok:false envelope", async () => {
|
|
205
|
+
const stash = makeStashDir();
|
|
206
|
+
const coerced = coerceReflectArgs({ ref: "lesson:rg-over-grep" });
|
|
207
|
+
const result = await akmReflect({
|
|
208
|
+
...coerced,
|
|
209
|
+
stashDir: stash,
|
|
210
|
+
agentProfile: makeProfile(),
|
|
211
|
+
runAgentOptions: { spawn: fakeSpawn("not json", "", 0) },
|
|
212
|
+
});
|
|
213
|
+
expect(result.ok).toBe(false);
|
|
214
|
+
if (result.ok)
|
|
215
|
+
throw new Error("expected failure");
|
|
216
|
+
expect(result.reason).toBe("parse_error");
|
|
217
|
+
});
|
|
218
|
+
test("timeout: short --timeout-ms is honoured by the wrapper", async () => {
|
|
219
|
+
const stash = makeStashDir();
|
|
220
|
+
const coerced = coerceReflectArgs({ ref: "lesson:rg-over-grep", "timeout-ms": "1" });
|
|
221
|
+
let timerCb;
|
|
222
|
+
const result = await akmReflect({
|
|
223
|
+
...coerced,
|
|
224
|
+
stashDir: stash,
|
|
225
|
+
agentProfile: makeProfile(),
|
|
226
|
+
runAgentOptions: {
|
|
227
|
+
spawn: hangingSpawn(),
|
|
228
|
+
setTimeoutFn: ((cb) => {
|
|
229
|
+
timerCb = cb;
|
|
230
|
+
// Fire on next tick — keeps the test deterministic.
|
|
231
|
+
queueMicrotask(() => timerCb?.());
|
|
232
|
+
return 1;
|
|
233
|
+
}),
|
|
234
|
+
clearTimeoutFn: (() => undefined),
|
|
235
|
+
},
|
|
236
|
+
});
|
|
237
|
+
expect(result.ok).toBe(false);
|
|
238
|
+
if (result.ok)
|
|
239
|
+
throw new Error("expected failure");
|
|
240
|
+
expect(result.reason).toBe("timeout");
|
|
241
|
+
});
|
|
242
|
+
test("missing agent config (no `agent` block) → ConfigError surfaces with .code", async () => {
|
|
243
|
+
const stash = makeStashDir();
|
|
244
|
+
let thrown;
|
|
245
|
+
try {
|
|
246
|
+
await akmReflect({
|
|
247
|
+
ref: "lesson:rg-over-grep",
|
|
248
|
+
stashDir: stash,
|
|
249
|
+
agentConfig: undefined, // explicit: no agent block resolved
|
|
250
|
+
// Note: we deliberately do NOT pass agentProfile so resolveProfile is exercised.
|
|
251
|
+
// loadAgentConfigFromDisk will load empty config (no XDG_CONFIG_HOME entry exists)
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
catch (err) {
|
|
255
|
+
thrown = err;
|
|
256
|
+
}
|
|
257
|
+
expect(thrown).toBeInstanceOf(Error);
|
|
258
|
+
const e = thrown;
|
|
259
|
+
expect(e.name).toBe("ConfigError");
|
|
260
|
+
expect(e.code).toBe("INVALID_CONFIG_FILE");
|
|
261
|
+
expect(e.message).toContain("agent");
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
// ── Propose command behaviour with coerced args ────────────────────────────
|
|
265
|
+
describe("akmPropose — argv-coerced calls (happy + failure)", () => {
|
|
266
|
+
test("happy: argv-shape passed through coercion → queues skill proposal", async () => {
|
|
267
|
+
const stash = makeStashDir();
|
|
268
|
+
const coerced = coerceProposeArgs({ type: "skill", name: "hello", task: "Say hi", "timeout-ms": "5000" });
|
|
269
|
+
const result = await akmPropose({
|
|
270
|
+
...coerced,
|
|
271
|
+
stashDir: stash,
|
|
272
|
+
agentProfile: makeProfile(),
|
|
273
|
+
runAgentOptions: { spawn: fakeSpawn(VALID_SKILL_PAYLOAD, "", 0) },
|
|
274
|
+
});
|
|
275
|
+
expect(result.ok).toBe(true);
|
|
276
|
+
if (!result.ok)
|
|
277
|
+
throw new Error("expected ok");
|
|
278
|
+
expect(result.proposal.ref).toBe("skill:hello");
|
|
279
|
+
});
|
|
280
|
+
test("parse_error: agent returns malformed JSON", async () => {
|
|
281
|
+
const stash = makeStashDir();
|
|
282
|
+
const coerced = coerceProposeArgs({ type: "skill", name: "hello", task: "Say hi" });
|
|
283
|
+
const result = await akmPropose({
|
|
284
|
+
...coerced,
|
|
285
|
+
stashDir: stash,
|
|
286
|
+
agentProfile: makeProfile(),
|
|
287
|
+
runAgentOptions: { spawn: fakeSpawn("garbage {", "", 0) },
|
|
288
|
+
});
|
|
289
|
+
expect(result.ok).toBe(false);
|
|
290
|
+
if (result.ok)
|
|
291
|
+
throw new Error("expected failure");
|
|
292
|
+
expect(result.reason).toBe("parse_error");
|
|
293
|
+
});
|
|
294
|
+
test("missing config: no agent block → ConfigError when resolveProfile runs", async () => {
|
|
295
|
+
const stash = makeStashDir();
|
|
296
|
+
let thrown;
|
|
297
|
+
try {
|
|
298
|
+
await akmPropose({
|
|
299
|
+
type: "skill",
|
|
300
|
+
name: "hello",
|
|
301
|
+
task: "Say hi",
|
|
302
|
+
stashDir: stash,
|
|
303
|
+
// Do NOT pass agentProfile or agentConfig — exercises the disk path
|
|
304
|
+
// which resolves to undefined under the empty XDG_CONFIG_HOME above.
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
catch (err) {
|
|
308
|
+
thrown = err;
|
|
309
|
+
}
|
|
310
|
+
expect(thrown).toBeInstanceOf(Error);
|
|
311
|
+
const e = thrown;
|
|
312
|
+
expect(e.name).toBe("ConfigError");
|
|
313
|
+
expect(e.code).toBe("INVALID_CONFIG_FILE");
|
|
314
|
+
});
|
|
315
|
+
test("missing --task surfaces UsageError (matches CLI contract for empty positional)", async () => {
|
|
316
|
+
const stash = makeStashDir();
|
|
317
|
+
const coerced = coerceProposeArgs({ type: "skill", name: "x" }); // task absent
|
|
318
|
+
let thrown;
|
|
319
|
+
try {
|
|
320
|
+
await akmPropose({
|
|
321
|
+
...coerced,
|
|
322
|
+
stashDir: stash,
|
|
323
|
+
agentProfile: makeProfile(),
|
|
324
|
+
runAgentOptions: { spawn: fakeSpawn(VALID_SKILL_PAYLOAD, "", 0) },
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
catch (err) {
|
|
328
|
+
thrown = err;
|
|
329
|
+
}
|
|
330
|
+
expect(thrown).toBeInstanceOf(Error);
|
|
331
|
+
expect(thrown.message).toContain("--task");
|
|
332
|
+
});
|
|
333
|
+
});
|