akm-cli 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +66 -0
- package/dist/{cli.js → src/cli.js} +712 -34
- package/dist/{commands → src/commands}/config-cli.js +47 -4
- package/dist/src/commands/distill.js +283 -0
- package/dist/src/commands/events.js +108 -0
- package/dist/src/commands/history.js +191 -0
- package/dist/{commands → src/commands}/installed-stashes.js +1 -1
- package/dist/src/commands/proposal.js +119 -0
- package/dist/src/commands/propose.js +171 -0
- package/dist/src/commands/reflect.js +193 -0
- package/dist/{commands → src/commands}/registry-search.js +71 -7
- package/dist/{commands → src/commands}/remember.js +12 -0
- package/dist/{commands → src/commands}/search.js +104 -4
- package/dist/{commands → src/commands}/self-update.js +4 -3
- package/dist/{commands → src/commands}/show.js +73 -0
- package/dist/{commands → src/commands}/source-add.js +5 -1
- package/dist/{commands → src/commands}/source-manage.js +7 -1
- package/dist/{core → src/core}/asset-ref.js +5 -5
- package/dist/{core → src/core}/asset-spec.js +12 -0
- package/dist/{core → src/core}/common.js +1 -1
- package/dist/{core → src/core}/config.js +203 -121
- package/dist/{core → src/core}/errors.js +4 -0
- package/dist/src/core/events.js +239 -0
- package/dist/src/core/lesson-lint.js +86 -0
- package/dist/src/core/proposals.js +406 -0
- package/dist/src/core/warn.js +72 -0
- package/dist/{core → src/core}/write-source.js +80 -5
- package/dist/{indexer → src/indexer}/db-search.js +114 -24
- package/dist/{indexer → src/indexer}/db.js +76 -23
- package/dist/{indexer → src/indexer}/file-context.js +0 -3
- package/dist/src/indexer/graph-boost.js +179 -0
- package/dist/src/indexer/graph-extraction.js +212 -0
- package/dist/{indexer → src/indexer}/indexer.js +88 -7
- package/dist/{indexer → src/indexer}/matchers.js +1 -1
- package/dist/src/indexer/memory-inference.js +263 -0
- package/dist/{indexer → src/indexer}/metadata.js +111 -3
- package/dist/{indexer → src/indexer}/search-source.js +4 -2
- package/dist/src/integrations/agent/config.js +292 -0
- package/dist/src/integrations/agent/detect.js +94 -0
- package/dist/src/integrations/agent/index.js +17 -0
- package/dist/src/integrations/agent/profiles.js +65 -0
- package/dist/src/integrations/agent/prompts.js +167 -0
- package/dist/src/integrations/agent/spawn.js +272 -0
- package/dist/{integrations → src/integrations}/github.js +9 -3
- package/dist/{integrations → src/integrations}/lockfile.js +0 -26
- package/dist/{llm → src/llm}/client.js +33 -2
- package/dist/{llm → src/llm}/embedders/remote.js +37 -3
- package/dist/src/llm/feature-gate.js +108 -0
- package/dist/src/llm/graph-extract.js +107 -0
- package/dist/src/llm/index-passes.js +35 -0
- package/dist/src/llm/memory-infer.js +86 -0
- package/dist/{output → src/output}/cli-hints.js +15 -2
- package/dist/{output → src/output}/renderers.js +63 -2
- package/dist/src/output/shapes.js +523 -0
- package/dist/src/output/text.js +1116 -0
- package/dist/{registry → src/registry}/build-index.js +19 -8
- package/dist/{registry → src/registry}/factory.js +0 -8
- package/dist/{registry → src/registry}/providers/static-index.js +6 -3
- package/dist/{registry → src/registry}/resolve.js +68 -2
- package/dist/{setup → src/setup}/setup.js +52 -5
- package/dist/{sources → src/sources}/providers/git.js +7 -15
- package/dist/{wiki → src/wiki}/wiki.js +54 -6
- package/dist/{workflows → src/workflows}/runs.js +37 -3
- package/dist/tests/add-website-source.test.js +119 -0
- package/dist/tests/agent/agent-config-loader.test.js +70 -0
- package/dist/tests/agent/agent-config.test.js +221 -0
- package/dist/tests/agent/agent-detect.test.js +100 -0
- package/dist/tests/agent/agent-spawn.test.js +234 -0
- package/dist/tests/agent-output.test.js +186 -0
- package/dist/tests/architecture/agent-no-llm-sdk-guard.test.js +103 -0
- package/dist/tests/architecture/agent-spawn-seam.test.js +193 -0
- package/dist/tests/architecture/llm-stateless-seam.test.js +112 -0
- package/dist/tests/asset-ref.test.js +192 -0
- package/dist/tests/asset-registry.test.js +103 -0
- package/dist/tests/asset-spec.test.js +241 -0
- package/dist/tests/bench/attribution.test.js +996 -0
- package/dist/tests/bench/cleanup-sigint.test.js +83 -0
- package/dist/tests/bench/cleanup.js +234 -0
- package/dist/tests/bench/cleanup.test.js +166 -0
- package/dist/tests/bench/cli.js +1018 -0
- package/dist/tests/bench/cli.test.js +445 -0
- package/dist/tests/bench/compare.test.js +556 -0
- package/dist/tests/bench/corpus.js +317 -0
- package/dist/tests/bench/corpus.test.js +258 -0
- package/dist/tests/bench/doctor.js +525 -0
- package/dist/tests/bench/driver.js +401 -0
- package/dist/tests/bench/driver.test.js +584 -0
- package/dist/tests/bench/environment.js +233 -0
- package/dist/tests/bench/environment.test.js +199 -0
- package/dist/tests/bench/evolve-metrics.js +179 -0
- package/dist/tests/bench/evolve-metrics.test.js +187 -0
- package/dist/tests/bench/evolve.js +647 -0
- package/dist/tests/bench/evolve.test.js +624 -0
- package/dist/tests/bench/failure-modes.test.js +349 -0
- package/dist/tests/bench/feedback-integrity.test.js +457 -0
- package/dist/tests/bench/leakage.test.js +228 -0
- package/dist/tests/bench/learning-curve.test.js +134 -0
- package/dist/tests/bench/metrics.js +2395 -0
- package/dist/tests/bench/metrics.test.js +1150 -0
- package/dist/tests/bench/no-os-tmpdir-invariant.test.js +43 -0
- package/dist/tests/bench/opencode-config.js +194 -0
- package/dist/tests/bench/opencode-config.test.js +370 -0
- package/dist/tests/bench/report.js +1885 -0
- package/dist/tests/bench/report.test.js +1038 -0
- package/dist/tests/bench/run-config.js +355 -0
- package/dist/tests/bench/run-config.test.js +298 -0
- package/dist/tests/bench/run-curate-test.js +32 -0
- package/dist/tests/bench/run-failing-tasks.js +56 -0
- package/dist/tests/bench/run-full-bench.js +51 -0
- package/dist/tests/bench/run-items36-targeted.js +69 -0
- package/dist/tests/bench/run-nano-quick.js +42 -0
- package/dist/tests/bench/run-waveg-targeted.js +62 -0
- package/dist/tests/bench/runner.js +699 -0
- package/dist/tests/bench/runner.test.js +958 -0
- package/dist/tests/bench/search-bridge.test.js +331 -0
- package/dist/tests/bench/tmp.js +131 -0
- package/dist/tests/bench/trajectory.js +116 -0
- package/dist/tests/bench/trajectory.test.js +127 -0
- package/dist/tests/bench/verifier.js +114 -0
- package/dist/tests/bench/verifier.test.js +118 -0
- package/dist/tests/bench/workflow-evaluator.js +557 -0
- package/dist/tests/bench/workflow-evaluator.test.js +421 -0
- package/dist/tests/bench/workflow-spec.js +345 -0
- package/dist/tests/bench/workflow-spec.test.js +363 -0
- package/dist/tests/bench/workflow-trace.js +472 -0
- package/dist/tests/bench/workflow-trace.test.js +254 -0
- package/dist/tests/benchmark-search-quality.js +536 -0
- package/dist/tests/benchmark-suite.js +1441 -0
- package/dist/tests/capture-cli.test.js +112 -0
- package/dist/tests/cli-errors.test.js +204 -0
- package/dist/tests/commands/events.test.js +370 -0
- package/dist/tests/commands/history.test.js +418 -0
- package/dist/tests/commands/import.test.js +103 -0
- package/dist/tests/commands/proposal-cli.test.js +209 -0
- package/dist/tests/commands/reflect-propose-cli.test.js +333 -0
- package/dist/tests/commands/remember.test.js +97 -0
- package/dist/tests/commands/scope-flags.test.js +300 -0
- package/dist/tests/commands/search.test.js +537 -0
- package/dist/tests/commands/show-indexer-parity.test.js +117 -0
- package/dist/tests/commands/show.test.js +294 -0
- package/dist/tests/common.test.js +266 -0
- package/dist/tests/completions.test.js +142 -0
- package/dist/tests/config-cli.test.js +193 -0
- package/dist/tests/config-llm-features.test.js +139 -0
- package/dist/tests/config.test.js +569 -0
- package/dist/tests/contracts/migration-baseline.test.js +43 -0
- package/dist/tests/contracts/reflect-propose-envelope.test.js +139 -0
- package/dist/tests/contracts/spec-helpers.js +46 -0
- package/dist/tests/contracts/v1-spec-section-11-proposal-queue.test.js +228 -0
- package/dist/tests/contracts/v1-spec-section-12-agent-config.test.js +56 -0
- package/dist/tests/contracts/v1-spec-section-13-lesson-type.test.js +34 -0
- package/dist/tests/contracts/v1-spec-section-14-llm-features.test.js +94 -0
- package/dist/tests/contracts/v1-spec-section-4-1-asset-types.test.js +39 -0
- package/dist/tests/contracts/v1-spec-section-4-2-quality-rules.test.js +44 -0
- package/dist/tests/contracts/v1-spec-section-5-configuration.test.js +47 -0
- package/dist/tests/contracts/v1-spec-section-6-orchestration.test.js +40 -0
- package/dist/tests/contracts/v1-spec-section-7-module-layout.test.js +58 -0
- package/dist/tests/contracts/v1-spec-section-8-extension-points.test.js +34 -0
- package/dist/tests/contracts/v1-spec-section-9-4-cli-surface.test.js +75 -0
- package/dist/tests/contracts/v1-spec-section-9-7-llm-agent-boundary.test.js +36 -0
- package/dist/tests/core/write-source.test.js +366 -0
- package/dist/tests/curate-command.test.js +87 -0
- package/dist/tests/db-scoring.test.js +201 -0
- package/dist/tests/db.test.js +654 -0
- package/dist/tests/distill-cli-flag.test.js +208 -0
- package/dist/tests/distill.test.js +515 -0
- package/dist/tests/docker-install.test.js +120 -0
- package/dist/tests/e2e.test.js +1419 -0
- package/dist/tests/embedder.test.js +340 -0
- package/dist/tests/embedding-model-config.test.js +379 -0
- package/dist/tests/feedback-command.test.js +172 -0
- package/dist/tests/file-context.test.js +552 -0
- package/dist/tests/fixtures/scripts/git/summarize-diff.js +9 -0
- package/dist/tests/fixtures/scripts/lint/eslint-check.js +7 -0
- package/dist/tests/fixtures/stashes/load.js +166 -0
- package/dist/tests/fixtures/stashes/load.test.js +97 -0
- package/dist/tests/fixtures/stashes/ranking-baseline/scripts/mem0-search.js +12 -0
- package/dist/tests/frontmatter.test.js +190 -0
- package/dist/tests/fts-field-weighting.test.js +254 -0
- package/dist/tests/fuzzy-search.test.js +230 -0
- package/dist/tests/git-provider-clone.test.js +45 -0
- package/dist/tests/github.test.js +161 -0
- package/dist/tests/graph-boost-ranking.test.js +305 -0
- package/dist/tests/graph-extraction.test.js +282 -0
- package/dist/tests/helpers/usage-events.js +8 -0
- package/dist/tests/index-pass-llm.test.js +161 -0
- package/dist/tests/indexer.test.js +570 -0
- package/dist/tests/info-command.test.js +166 -0
- package/dist/tests/init.test.js +69 -0
- package/dist/tests/install-script.test.js +246 -0
- package/dist/tests/integration/agent-real-profile.test.js +94 -0
- package/dist/tests/issue-36-repro.test.js +304 -0
- package/dist/tests/issues-191-194.test.js +160 -0
- package/dist/tests/lesson-lint.test.js +111 -0
- package/dist/tests/llm-client.test.js +115 -0
- package/dist/tests/llm-feature-gate.test.js +151 -0
- package/dist/tests/llm.test.js +139 -0
- package/dist/tests/lockfile.test.js +216 -0
- package/dist/tests/manifest.test.js +205 -0
- package/dist/tests/markdown.test.js +126 -0
- package/dist/tests/matchers-unit.test.js +189 -0
- package/dist/tests/memory-inference.test.js +299 -0
- package/dist/tests/merge-scoring.test.js +136 -0
- package/dist/tests/metadata.test.js +313 -0
- package/dist/tests/migration-help.test.js +89 -0
- package/dist/tests/origin-resolve.test.js +124 -0
- package/dist/tests/output-baseline.test.js +218 -0
- package/dist/tests/output-shapes-unit.test.js +478 -0
- package/dist/tests/parallel-search.test.js +272 -0
- package/dist/tests/parameter-metadata.test.js +365 -0
- package/dist/tests/paths.test.js +177 -0
- package/dist/tests/progressive-disclosure.test.js +280 -0
- package/dist/tests/proposals.test.js +279 -0
- package/dist/tests/proposed-quality.test.js +271 -0
- package/dist/tests/provider-registry.test.js +32 -0
- package/dist/tests/ranking-regression.test.js +548 -0
- package/dist/tests/reflect-propose.test.js +455 -0
- package/dist/tests/registry-build-index.test.js +394 -0
- package/dist/tests/registry-cli.test.js +290 -0
- package/dist/tests/registry-index-v2.test.js +430 -0
- package/dist/tests/registry-install.test.js +728 -0
- package/dist/tests/registry-providers/parity.test.js +189 -0
- package/dist/tests/registry-providers/skills-sh.test.js +309 -0
- package/dist/tests/registry-providers/static-index.test.js +238 -0
- package/dist/tests/registry-resolve.test.js +126 -0
- package/dist/tests/registry-search.test.js +923 -0
- package/dist/tests/remember-frontmatter.test.js +378 -0
- package/dist/tests/remember-unit.test.js +123 -0
- package/dist/tests/ripgrep-install.test.js +251 -0
- package/dist/tests/ripgrep-resolve.test.js +108 -0
- package/dist/tests/ripgrep.test.js +163 -0
- package/dist/tests/save-command.test.js +94 -0
- package/dist/tests/save-trust-qa-fixes.test.js +270 -0
- package/dist/tests/scoring-pipeline.test.js +648 -0
- package/dist/tests/search-include-proposed-cli.test.js +118 -0
- package/dist/tests/self-update.test.js +442 -0
- package/dist/tests/semantic-search-e2e.test.js +512 -0
- package/dist/tests/semantic-status.test.js +471 -0
- package/dist/tests/setup-run.integration.js +877 -0
- package/dist/tests/setup-wizard.test.js +198 -0
- package/dist/tests/setup.test.js +131 -0
- package/dist/tests/source-add.test.js +11 -0
- package/dist/tests/source-clone.test.js +254 -0
- package/dist/tests/source-manage.test.js +366 -0
- package/dist/tests/source-providers/filesystem.test.js +82 -0
- package/dist/tests/source-providers/git.test.js +252 -0
- package/dist/tests/source-providers/website.test.js +128 -0
- package/dist/tests/source-qa-fixes.test.js +286 -0
- package/dist/tests/source-registry.test.js +350 -0
- package/dist/tests/source-resolve.test.js +100 -0
- package/dist/tests/source-source.test.js +281 -0
- package/dist/tests/source.test.js +533 -0
- package/dist/tests/tar-utils-scan.test.js +73 -0
- package/dist/tests/toggle-components.test.js +73 -0
- package/dist/tests/usage-telemetry.test.js +265 -0
- package/dist/tests/utility-scoring.test.js +558 -0
- package/dist/tests/vault-load-error.test.js +78 -0
- package/dist/tests/vault-qa-fixes.test.js +194 -0
- package/dist/tests/vault.test.js +429 -0
- package/dist/tests/vector-search.test.js +608 -0
- package/dist/tests/walker.test.js +252 -0
- package/dist/tests/wave2-cluster-bc.test.js +228 -0
- package/dist/tests/wave2-cluster-d.test.js +180 -0
- package/dist/tests/wave2-cluster-e.test.js +179 -0
- package/dist/tests/wiki-qa-fixes.test.js +270 -0
- package/dist/tests/wiki.test.js +529 -0
- package/dist/tests/workflow-cli.test.js +271 -0
- package/dist/tests/workflow-markdown.test.js +171 -0
- package/dist/tests/workflow-path-escape.test.js +132 -0
- package/dist/tests/workflow-qa-fixes.test.js +395 -0
- package/dist/tests/workflows/indexer-rejection.test.js +213 -0
- package/docs/README.md +8 -0
- package/docs/migration/release-notes/0.7.0.md +244 -0
- package/package.json +2 -2
- package/dist/core/warn.js +0 -27
- package/dist/output/shapes.js +0 -212
- package/dist/output/text.js +0 -520
- /package/dist/{commands → src/commands}/completions.js +0 -0
- /package/dist/{commands → src/commands}/curate.js +0 -0
- /package/dist/{commands → src/commands}/info.js +0 -0
- /package/dist/{commands → src/commands}/init.js +0 -0
- /package/dist/{commands → src/commands}/install-audit.js +0 -0
- /package/dist/{commands → src/commands}/migration-help.js +0 -0
- /package/dist/{commands → src/commands}/source-clone.js +0 -0
- /package/dist/{commands → src/commands}/vault.js +0 -0
- /package/dist/{core → src/core}/asset-registry.js +0 -0
- /package/dist/{core → src/core}/frontmatter.js +0 -0
- /package/dist/{core → src/core}/markdown.js +0 -0
- /package/dist/{core → src/core}/paths.js +0 -0
- /package/dist/{indexer → src/indexer}/manifest.js +0 -0
- /package/dist/{indexer → src/indexer}/search-fields.js +0 -0
- /package/dist/{indexer → src/indexer}/semantic-status.js +0 -0
- /package/dist/{indexer → src/indexer}/usage-events.js +0 -0
- /package/dist/{indexer → src/indexer}/walker.js +0 -0
- /package/dist/{llm → src/llm}/embedder.js +0 -0
- /package/dist/{llm → src/llm}/embedders/cache.js +0 -0
- /package/dist/{llm → src/llm}/embedders/local.js +0 -0
- /package/dist/{llm → src/llm}/embedders/types.js +0 -0
- /package/dist/{llm → src/llm}/metadata-enhance.js +0 -0
- /package/dist/{output → src/output}/context.js +0 -0
- /package/dist/{registry → src/registry}/create-provider-registry.js +0 -0
- /package/dist/{registry → src/registry}/origin-resolve.js +0 -0
- /package/dist/{registry → src/registry}/providers/index.js +0 -0
- /package/dist/{registry → src/registry}/providers/skills-sh.js +0 -0
- /package/dist/{registry → src/registry}/providers/types.js +0 -0
- /package/dist/{registry → src/registry}/types.js +0 -0
- /package/dist/{setup → src/setup}/detect.js +0 -0
- /package/dist/{setup → src/setup}/ripgrep-install.js +0 -0
- /package/dist/{setup → src/setup}/ripgrep-resolve.js +0 -0
- /package/dist/{setup → src/setup}/steps.js +0 -0
- /package/dist/{sources → src/sources}/include.js +0 -0
- /package/dist/{sources → src/sources}/provider-factory.js +0 -0
- /package/dist/{sources → src/sources}/provider.js +0 -0
- /package/dist/{sources → src/sources}/providers/filesystem.js +0 -0
- /package/dist/{sources → src/sources}/providers/index.js +0 -0
- /package/dist/{sources → src/sources}/providers/install-types.js +0 -0
- /package/dist/{sources → src/sources}/providers/npm.js +0 -0
- /package/dist/{sources → src/sources}/providers/provider-utils.js +0 -0
- /package/dist/{sources → src/sources}/providers/sync-from-ref.js +0 -0
- /package/dist/{sources → src/sources}/providers/tar-utils.js +0 -0
- /package/dist/{sources → src/sources}/providers/website.js +0 -0
- /package/dist/{sources → src/sources}/resolve.js +0 -0
- /package/dist/{sources → src/sources}/types.js +0 -0
- /package/dist/{templates → src/templates}/wiki-templates.js +0 -0
- /package/dist/{version.js → src/version.js} +0 -0
- /package/dist/{workflows → src/workflows}/authoring.js +0 -0
- /package/dist/{workflows → src/workflows}/cli.js +0 -0
- /package/dist/{workflows → src/workflows}/db.js +0 -0
- /package/dist/{workflows → src/workflows}/document-cache.js +0 -0
- /package/dist/{workflows → src/workflows}/parser.js +0 -0
- /package/dist/{workflows → src/workflows}/renderer.js +0 -0
- /package/dist/{workflows → src/workflows}/schema.js +0 -0
- /package/dist/{workflows → src/workflows}/validator.js +0 -0
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the workflow-spec YAML loader.
|
|
3
|
+
*
|
|
4
|
+
* Covers: valid fixtures, malformed specs, unknown event names,
|
|
5
|
+
* applicability filters, gold_ref validation, path-traversal rejection,
|
|
6
|
+
* scoring validation, duplicate ids.
|
|
7
|
+
*/
|
|
8
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
9
|
+
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
import { benchMkdtemp } from "./tmp";
|
|
12
|
+
import { KNOWN_EVENT_NAMES, loadAllWorkflowSpecs, loadWorkflowSpec, specApplies, WorkflowSpecError, } from "./workflow-spec";
|
|
13
|
+
const FIXTURE_DIR = path.resolve(__dirname, "..", "fixtures", "bench", "workflows");
|
|
14
|
+
const REQUIRED_SPECS = [
|
|
15
|
+
"akm-lookup-before-edit",
|
|
16
|
+
"akm-correct-asset-use",
|
|
17
|
+
"akm-feedback-after-use",
|
|
18
|
+
"akm-negative-feedback-on-failure",
|
|
19
|
+
"akm-reflect-after-repeated-failure",
|
|
20
|
+
"akm-workflow-followed",
|
|
21
|
+
];
|
|
22
|
+
// ── Scratch directory helpers ──────────────────────────────────────────────
|
|
23
|
+
let scratch;
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
scratch = benchMkdtemp("akm-workflow-spec-");
|
|
26
|
+
});
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
29
|
+
});
|
|
30
|
+
function writeSpec(name, body) {
|
|
31
|
+
const p = path.join(scratch, name);
|
|
32
|
+
writeFileSync(p, body, "utf8");
|
|
33
|
+
return p;
|
|
34
|
+
}
|
|
35
|
+
// ── Fixture sanity ─────────────────────────────────────────────────────────
|
|
36
|
+
describe("loadAllWorkflowSpecs (real fixtures)", () => {
|
|
37
|
+
test("loads every checked-in workflow spec", () => {
|
|
38
|
+
const specs = loadAllWorkflowSpecs(FIXTURE_DIR);
|
|
39
|
+
const ids = specs.map((s) => s.id).sort();
|
|
40
|
+
for (const required of REQUIRED_SPECS) {
|
|
41
|
+
expect(ids).toContain(required);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
test("every fixture has a valid scoring block", () => {
|
|
45
|
+
const specs = loadAllWorkflowSpecs(FIXTURE_DIR);
|
|
46
|
+
for (const s of specs) {
|
|
47
|
+
const sum = s.scoring.required_steps_weight + s.scoring.forbidden_steps_weight + s.scoring.evidence_quality_weight;
|
|
48
|
+
expect(Math.abs(sum - 1)).toBeLessThan(1e-6);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
test("every fixture event-name is in the known set", () => {
|
|
52
|
+
const known = new Set(KNOWN_EVENT_NAMES);
|
|
53
|
+
const specs = loadAllWorkflowSpecs(FIXTURE_DIR);
|
|
54
|
+
for (const s of specs) {
|
|
55
|
+
for (const step of s.required_sequence) {
|
|
56
|
+
expect(known.has(step.event)).toBe(true);
|
|
57
|
+
if (step.before)
|
|
58
|
+
expect(known.has(step.before)).toBe(true);
|
|
59
|
+
}
|
|
60
|
+
for (const step of s.forbidden ?? []) {
|
|
61
|
+
expect(known.has(step.event)).toBe(true);
|
|
62
|
+
if (step.before)
|
|
63
|
+
expect(known.has(step.before)).toBe(true);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
// ── Valid spec parsing ─────────────────────────────────────────────────────
|
|
69
|
+
describe("loadWorkflowSpec — valid", () => {
|
|
70
|
+
test("parses a minimal valid spec", () => {
|
|
71
|
+
const p = writeSpec("min.yaml", `id: min
|
|
72
|
+
title: Minimal
|
|
73
|
+
required_sequence:
|
|
74
|
+
- event: agent_started
|
|
75
|
+
- event: agent_finished
|
|
76
|
+
scoring:
|
|
77
|
+
required_steps_weight: 0.6
|
|
78
|
+
forbidden_steps_weight: 0.2
|
|
79
|
+
evidence_quality_weight: 0.2
|
|
80
|
+
`);
|
|
81
|
+
const spec = loadWorkflowSpec(p);
|
|
82
|
+
expect(spec.id).toBe("min");
|
|
83
|
+
expect(spec.required_sequence.length).toBe(2);
|
|
84
|
+
expect(spec.forbidden).toBeUndefined();
|
|
85
|
+
expect(spec.applies_to).toBeUndefined();
|
|
86
|
+
expect(spec.sourcePath).toBe(path.resolve(p));
|
|
87
|
+
});
|
|
88
|
+
test("preserves all richer fields (applies_to, forbidden, gold_ref)", () => {
|
|
89
|
+
const p = writeSpec("rich.yaml", `id: rich
|
|
90
|
+
title: Rich
|
|
91
|
+
applies_to:
|
|
92
|
+
arms: ["akm"]
|
|
93
|
+
task_domains: ["docker-homelab"]
|
|
94
|
+
outcomes: ["pass"]
|
|
95
|
+
requires_gold_ref: true
|
|
96
|
+
min_repeated_failures: 2
|
|
97
|
+
gold_ref: "skill:deploy"
|
|
98
|
+
required_sequence:
|
|
99
|
+
- event: agent_started
|
|
100
|
+
- event: akm_show
|
|
101
|
+
ref_must_equal: gold_ref
|
|
102
|
+
before: first_workspace_write
|
|
103
|
+
- event: first_workspace_write
|
|
104
|
+
forbidden:
|
|
105
|
+
- event: first_workspace_write
|
|
106
|
+
before: akm_show
|
|
107
|
+
scoring:
|
|
108
|
+
required_steps_weight: 0.5
|
|
109
|
+
forbidden_steps_weight: 0.3
|
|
110
|
+
evidence_quality_weight: 0.2
|
|
111
|
+
`);
|
|
112
|
+
const spec = loadWorkflowSpec(p);
|
|
113
|
+
expect(spec.applies_to?.arms).toEqual(["akm"]);
|
|
114
|
+
expect(spec.applies_to?.task_domains).toEqual(["docker-homelab"]);
|
|
115
|
+
expect(spec.applies_to?.requires_gold_ref).toBe(true);
|
|
116
|
+
expect(spec.applies_to?.min_repeated_failures).toBe(2);
|
|
117
|
+
expect(spec.gold_ref).toBe("skill:deploy");
|
|
118
|
+
expect(spec.forbidden?.length).toBe(1);
|
|
119
|
+
expect(spec.required_sequence[1].ref_must_equal).toBe("gold_ref");
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
// ── Malformed specs ────────────────────────────────────────────────────────
|
|
123
|
+
describe("loadWorkflowSpec — malformed", () => {
|
|
124
|
+
test("rejects non-YAML garbage", () => {
|
|
125
|
+
const p = writeSpec("bad.yaml", "::: not yaml\n - oops:\n: : :");
|
|
126
|
+
expect(() => loadWorkflowSpec(p)).toThrow(WorkflowSpecError);
|
|
127
|
+
});
|
|
128
|
+
test("rejects YAML whose top level is not a mapping", () => {
|
|
129
|
+
const p = writeSpec("array.yaml", "- 1\n- 2\n");
|
|
130
|
+
expect(() => loadWorkflowSpec(p)).toThrow(/must be a mapping/);
|
|
131
|
+
});
|
|
132
|
+
test("rejects missing required fields", () => {
|
|
133
|
+
const p = writeSpec("no-title.yaml", `id: x
|
|
134
|
+
required_sequence:
|
|
135
|
+
- event: agent_started
|
|
136
|
+
scoring:
|
|
137
|
+
required_steps_weight: 0.5
|
|
138
|
+
forbidden_steps_weight: 0.3
|
|
139
|
+
evidence_quality_weight: 0.2
|
|
140
|
+
`);
|
|
141
|
+
expect(() => loadWorkflowSpec(p)).toThrow(/title/);
|
|
142
|
+
});
|
|
143
|
+
test("rejects empty required_sequence", () => {
|
|
144
|
+
const p = writeSpec("empty-seq.yaml", `id: x
|
|
145
|
+
title: x
|
|
146
|
+
required_sequence: []
|
|
147
|
+
scoring:
|
|
148
|
+
required_steps_weight: 0.5
|
|
149
|
+
forbidden_steps_weight: 0.3
|
|
150
|
+
evidence_quality_weight: 0.2
|
|
151
|
+
`);
|
|
152
|
+
expect(() => loadWorkflowSpec(p)).toThrow(/required_sequence/);
|
|
153
|
+
});
|
|
154
|
+
test("rejects scoring weights that don't sum to 1", () => {
|
|
155
|
+
const p = writeSpec("bad-scoring.yaml", `id: x
|
|
156
|
+
title: x
|
|
157
|
+
required_sequence:
|
|
158
|
+
- event: agent_started
|
|
159
|
+
scoring:
|
|
160
|
+
required_steps_weight: 0.5
|
|
161
|
+
forbidden_steps_weight: 0.3
|
|
162
|
+
evidence_quality_weight: 0.5
|
|
163
|
+
`);
|
|
164
|
+
expect(() => loadWorkflowSpec(p)).toThrow(/sum to 1/);
|
|
165
|
+
});
|
|
166
|
+
test("rejects scoring weight outside [0, 1]", () => {
|
|
167
|
+
const p = writeSpec("neg-scoring.yaml", `id: x
|
|
168
|
+
title: x
|
|
169
|
+
required_sequence:
|
|
170
|
+
- event: agent_started
|
|
171
|
+
scoring:
|
|
172
|
+
required_steps_weight: -0.2
|
|
173
|
+
forbidden_steps_weight: 0.6
|
|
174
|
+
evidence_quality_weight: 0.6
|
|
175
|
+
`);
|
|
176
|
+
expect(() => loadWorkflowSpec(p)).toThrow(/in \[0, 1\]/);
|
|
177
|
+
});
|
|
178
|
+
test("rejects invalid gold_ref via parseAssetRef", () => {
|
|
179
|
+
const p = writeSpec("bad-ref.yaml", `id: x
|
|
180
|
+
title: x
|
|
181
|
+
gold_ref: "not-a-ref"
|
|
182
|
+
required_sequence:
|
|
183
|
+
- event: agent_started
|
|
184
|
+
scoring:
|
|
185
|
+
required_steps_weight: 0.5
|
|
186
|
+
forbidden_steps_weight: 0.3
|
|
187
|
+
evidence_quality_weight: 0.2
|
|
188
|
+
`);
|
|
189
|
+
expect(() => loadWorkflowSpec(p)).toThrow(/gold_ref/);
|
|
190
|
+
});
|
|
191
|
+
test("rejects invalid polarity", () => {
|
|
192
|
+
const p = writeSpec("bad-polarity.yaml", `id: x
|
|
193
|
+
title: x
|
|
194
|
+
required_sequence:
|
|
195
|
+
- event: akm_feedback
|
|
196
|
+
polarity: lukewarm
|
|
197
|
+
scoring:
|
|
198
|
+
required_steps_weight: 0.5
|
|
199
|
+
forbidden_steps_weight: 0.3
|
|
200
|
+
evidence_quality_weight: 0.2
|
|
201
|
+
`);
|
|
202
|
+
expect(() => loadWorkflowSpec(p)).toThrow(/polarity/);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
// ── Unknown event names ────────────────────────────────────────────────────
|
|
206
|
+
describe("loadWorkflowSpec — unknown event names", () => {
|
|
207
|
+
test("rejects unknown event in required_sequence", () => {
|
|
208
|
+
const p = writeSpec("unknown.yaml", `id: x
|
|
209
|
+
title: x
|
|
210
|
+
required_sequence:
|
|
211
|
+
- event: agent_started
|
|
212
|
+
- event: cosmic_rays
|
|
213
|
+
scoring:
|
|
214
|
+
required_steps_weight: 0.5
|
|
215
|
+
forbidden_steps_weight: 0.3
|
|
216
|
+
evidence_quality_weight: 0.2
|
|
217
|
+
`);
|
|
218
|
+
expect(() => loadWorkflowSpec(p)).toThrow(/Unknown event name "cosmic_rays"/);
|
|
219
|
+
});
|
|
220
|
+
test("rejects unknown event in `before` clause", () => {
|
|
221
|
+
const p = writeSpec("unknown-before.yaml", `id: x
|
|
222
|
+
title: x
|
|
223
|
+
required_sequence:
|
|
224
|
+
- event: akm_search
|
|
225
|
+
before: nope
|
|
226
|
+
scoring:
|
|
227
|
+
required_steps_weight: 0.5
|
|
228
|
+
forbidden_steps_weight: 0.3
|
|
229
|
+
evidence_quality_weight: 0.2
|
|
230
|
+
`);
|
|
231
|
+
expect(() => loadWorkflowSpec(p)).toThrow(/Unknown event name "nope"/);
|
|
232
|
+
});
|
|
233
|
+
test("rejects unknown event in forbidden block", () => {
|
|
234
|
+
const p = writeSpec("unknown-forbidden.yaml", `id: x
|
|
235
|
+
title: x
|
|
236
|
+
required_sequence:
|
|
237
|
+
- event: agent_started
|
|
238
|
+
forbidden:
|
|
239
|
+
- event: ouija_board
|
|
240
|
+
scoring:
|
|
241
|
+
required_steps_weight: 0.5
|
|
242
|
+
forbidden_steps_weight: 0.3
|
|
243
|
+
evidence_quality_weight: 0.2
|
|
244
|
+
`);
|
|
245
|
+
expect(() => loadWorkflowSpec(p)).toThrow(/Unknown event name "ouija_board"/);
|
|
246
|
+
});
|
|
247
|
+
});
|
|
248
|
+
// ── Applicability filters ──────────────────────────────────────────────────
|
|
249
|
+
describe("specApplies", () => {
|
|
250
|
+
function specWith(applies_to) {
|
|
251
|
+
const yaml = applies_to
|
|
252
|
+
? `id: x\ntitle: x\napplies_to:\n${Object.entries(applies_to)
|
|
253
|
+
.map(([k, v]) => ` ${k}: ${JSON.stringify(v)}`)
|
|
254
|
+
.join("\n")}\nrequired_sequence:\n - event: agent_started\nscoring:\n required_steps_weight: 0.5\n forbidden_steps_weight: 0.3\n evidence_quality_weight: 0.2\n`
|
|
255
|
+
: `id: x\ntitle: x\nrequired_sequence:\n - event: agent_started\nscoring:\n required_steps_weight: 0.5\n forbidden_steps_weight: 0.3\n evidence_quality_weight: 0.2\n`;
|
|
256
|
+
const p = writeSpec(`${Math.random().toString(36).slice(2)}.yaml`, yaml);
|
|
257
|
+
return loadWorkflowSpec(p);
|
|
258
|
+
}
|
|
259
|
+
test("no filter ⇒ matches anything", () => {
|
|
260
|
+
const s = specWith();
|
|
261
|
+
expect(specApplies(s, { arm: "noakm", taskId: "any/thing" })).toBe(true);
|
|
262
|
+
});
|
|
263
|
+
test("arm filter rejects mismatched arm", () => {
|
|
264
|
+
const s = specWith({ arms: ["akm"] });
|
|
265
|
+
expect(specApplies(s, { arm: "noakm", taskId: "x/y" })).toBe(false);
|
|
266
|
+
expect(specApplies(s, { arm: "akm", taskId: "x/y" })).toBe(true);
|
|
267
|
+
});
|
|
268
|
+
test("task_domains filter uses first segment of taskId", () => {
|
|
269
|
+
const s = specWith({ task_domains: ["docker-homelab"] });
|
|
270
|
+
expect(specApplies(s, { arm: "akm", taskId: "docker-homelab/redis" })).toBe(true);
|
|
271
|
+
expect(specApplies(s, { arm: "akm", taskId: "az-cli/storage" })).toBe(false);
|
|
272
|
+
});
|
|
273
|
+
test("outcomes filter requires the outcome to be present", () => {
|
|
274
|
+
const s = specWith({ outcomes: ["pass"] });
|
|
275
|
+
expect(specApplies(s, { arm: "akm", taskId: "x/y", outcome: "pass" })).toBe(true);
|
|
276
|
+
expect(specApplies(s, { arm: "akm", taskId: "x/y", outcome: "fail" })).toBe(false);
|
|
277
|
+
expect(specApplies(s, { arm: "akm", taskId: "x/y" })).toBe(false);
|
|
278
|
+
});
|
|
279
|
+
test("requires_gold_ref demands hasGoldRef", () => {
|
|
280
|
+
const s = specWith({ requires_gold_ref: true });
|
|
281
|
+
expect(specApplies(s, { arm: "akm", taskId: "x/y", hasGoldRef: false })).toBe(false);
|
|
282
|
+
expect(specApplies(s, { arm: "akm", taskId: "x/y", hasGoldRef: true })).toBe(true);
|
|
283
|
+
});
|
|
284
|
+
test("min_repeated_failures gates on repeatedFailures count", () => {
|
|
285
|
+
const s = specWith({ min_repeated_failures: 2 });
|
|
286
|
+
expect(specApplies(s, { arm: "akm", taskId: "x/y", repeatedFailures: 1 })).toBe(false);
|
|
287
|
+
expect(specApplies(s, { arm: "akm", taskId: "x/y", repeatedFailures: 2 })).toBe(true);
|
|
288
|
+
expect(specApplies(s, { arm: "akm", taskId: "x/y" })).toBe(false);
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
// ── Path traversal ─────────────────────────────────────────────────────────
|
|
292
|
+
describe("loadWorkflowSpec — path traversal", () => {
|
|
293
|
+
test("rejects spec resolved outside the provided root", () => {
|
|
294
|
+
// Set up a workflows root with a sibling file outside it.
|
|
295
|
+
const root = path.join(scratch, "workflows");
|
|
296
|
+
mkdirSync(root, { recursive: true });
|
|
297
|
+
const inside = path.join(root, "ok.yaml");
|
|
298
|
+
writeFileSync(inside, `id: ok
|
|
299
|
+
title: ok
|
|
300
|
+
required_sequence:
|
|
301
|
+
- event: agent_started
|
|
302
|
+
scoring:
|
|
303
|
+
required_steps_weight: 0.5
|
|
304
|
+
forbidden_steps_weight: 0.3
|
|
305
|
+
evidence_quality_weight: 0.2
|
|
306
|
+
`, "utf8");
|
|
307
|
+
const outside = path.join(scratch, "outside.yaml");
|
|
308
|
+
writeFileSync(outside, "id: nope\ntitle: nope\n", "utf8");
|
|
309
|
+
expect(() => loadWorkflowSpec(inside, root)).not.toThrow();
|
|
310
|
+
expect(() => loadWorkflowSpec(outside, root)).toThrow(/outside/);
|
|
311
|
+
// Traversal pattern must also be rejected.
|
|
312
|
+
const traversal = path.join(root, "..", "outside.yaml");
|
|
313
|
+
expect(() => loadWorkflowSpec(traversal, root)).toThrow(/outside/);
|
|
314
|
+
});
|
|
315
|
+
test("allows in-root spec paths whose filename starts with '..'", () => {
|
|
316
|
+
const root = path.join(scratch, "workflows");
|
|
317
|
+
mkdirSync(root, { recursive: true });
|
|
318
|
+
const inside = path.join(root, "..still-inside.yaml");
|
|
319
|
+
writeFileSync(inside, `id: ok
|
|
320
|
+
title: ok
|
|
321
|
+
required_sequence:
|
|
322
|
+
- event: agent_started
|
|
323
|
+
scoring:
|
|
324
|
+
required_steps_weight: 0.5
|
|
325
|
+
forbidden_steps_weight: 0.3
|
|
326
|
+
evidence_quality_weight: 0.2
|
|
327
|
+
`, "utf8");
|
|
328
|
+
expect(() => loadWorkflowSpec(inside, root)).not.toThrow();
|
|
329
|
+
});
|
|
330
|
+
test("loadAllWorkflowSpecs ignores non-yaml files in dir", () => {
|
|
331
|
+
const root = path.join(scratch, "workflows");
|
|
332
|
+
mkdirSync(root, { recursive: true });
|
|
333
|
+
writeFileSync(path.join(root, "README.md"), "not a spec\n", "utf8");
|
|
334
|
+
writeFileSync(path.join(root, "a.yaml"), `id: a
|
|
335
|
+
title: a
|
|
336
|
+
required_sequence:
|
|
337
|
+
- event: agent_started
|
|
338
|
+
scoring:
|
|
339
|
+
required_steps_weight: 0.5
|
|
340
|
+
forbidden_steps_weight: 0.3
|
|
341
|
+
evidence_quality_weight: 0.2
|
|
342
|
+
`, "utf8");
|
|
343
|
+
const specs = loadAllWorkflowSpecs(root);
|
|
344
|
+
expect(specs.length).toBe(1);
|
|
345
|
+
expect(specs[0].id).toBe("a");
|
|
346
|
+
});
|
|
347
|
+
test("loadAllWorkflowSpecs rejects duplicate ids across files", () => {
|
|
348
|
+
const root = path.join(scratch, "workflows");
|
|
349
|
+
mkdirSync(root, { recursive: true });
|
|
350
|
+
const body = `id: dup
|
|
351
|
+
title: dup
|
|
352
|
+
required_sequence:
|
|
353
|
+
- event: agent_started
|
|
354
|
+
scoring:
|
|
355
|
+
required_steps_weight: 0.5
|
|
356
|
+
forbidden_steps_weight: 0.3
|
|
357
|
+
evidence_quality_weight: 0.2
|
|
358
|
+
`;
|
|
359
|
+
writeFileSync(path.join(root, "a.yaml"), body, "utf8");
|
|
360
|
+
writeFileSync(path.join(root, "b.yaml"), body, "utf8");
|
|
361
|
+
expect(() => loadAllWorkflowSpecs(root)).toThrow(/Duplicate workflow spec id "dup"/);
|
|
362
|
+
});
|
|
363
|
+
});
|