@soleri/core 2.1.0 → 2.5.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/dist/brain/brain.d.ts +10 -1
- package/dist/brain/brain.d.ts.map +1 -1
- package/dist/brain/brain.js +116 -13
- package/dist/brain/brain.js.map +1 -1
- package/dist/brain/intelligence.d.ts +36 -1
- package/dist/brain/intelligence.d.ts.map +1 -1
- package/dist/brain/intelligence.js +119 -14
- package/dist/brain/intelligence.js.map +1 -1
- package/dist/brain/types.d.ts +34 -2
- package/dist/brain/types.d.ts.map +1 -1
- package/dist/cognee/client.d.ts +3 -0
- package/dist/cognee/client.d.ts.map +1 -1
- package/dist/cognee/client.js +17 -0
- package/dist/cognee/client.js.map +1 -1
- package/dist/cognee/sync-manager.d.ts +94 -0
- package/dist/cognee/sync-manager.d.ts.map +1 -0
- package/dist/cognee/sync-manager.js +293 -0
- package/dist/cognee/sync-manager.js.map +1 -0
- package/dist/control/identity-manager.d.ts +22 -0
- package/dist/control/identity-manager.d.ts.map +1 -0
- package/dist/control/identity-manager.js +233 -0
- package/dist/control/identity-manager.js.map +1 -0
- package/dist/control/intent-router.d.ts +32 -0
- package/dist/control/intent-router.d.ts.map +1 -0
- package/dist/control/intent-router.js +242 -0
- package/dist/control/intent-router.js.map +1 -0
- package/dist/control/types.d.ts +68 -0
- package/dist/control/types.d.ts.map +1 -0
- package/dist/control/types.js +9 -0
- package/dist/control/types.js.map +1 -0
- package/dist/curator/curator.d.ts +37 -1
- package/dist/curator/curator.d.ts.map +1 -1
- package/dist/curator/curator.js +199 -1
- package/dist/curator/curator.js.map +1 -1
- package/dist/errors/classify.d.ts +13 -0
- package/dist/errors/classify.d.ts.map +1 -0
- package/dist/errors/classify.js +97 -0
- package/dist/errors/classify.js.map +1 -0
- package/dist/errors/index.d.ts +6 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +4 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/errors/retry.d.ts +40 -0
- package/dist/errors/retry.d.ts.map +1 -0
- package/dist/errors/retry.js +97 -0
- package/dist/errors/retry.js.map +1 -0
- package/dist/errors/types.d.ts +48 -0
- package/dist/errors/types.d.ts.map +1 -0
- package/dist/errors/types.js +59 -0
- package/dist/errors/types.js.map +1 -0
- package/dist/facades/types.d.ts +1 -1
- package/dist/governance/governance.d.ts +42 -0
- package/dist/governance/governance.d.ts.map +1 -0
- package/dist/governance/governance.js +488 -0
- package/dist/governance/governance.js.map +1 -0
- package/dist/governance/index.d.ts +3 -0
- package/dist/governance/index.d.ts.map +1 -0
- package/dist/governance/index.js +2 -0
- package/dist/governance/index.js.map +1 -0
- package/dist/governance/types.d.ts +102 -0
- package/dist/governance/types.d.ts.map +1 -0
- package/dist/governance/types.js +3 -0
- package/dist/governance/types.js.map +1 -0
- package/dist/index.d.ts +52 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -1
- package/dist/index.js.map +1 -1
- package/dist/intake/content-classifier.d.ts +14 -0
- package/dist/intake/content-classifier.d.ts.map +1 -0
- package/dist/intake/content-classifier.js +125 -0
- package/dist/intake/content-classifier.js.map +1 -0
- package/dist/intake/dedup-gate.d.ts +17 -0
- package/dist/intake/dedup-gate.d.ts.map +1 -0
- package/dist/intake/dedup-gate.js +66 -0
- package/dist/intake/dedup-gate.js.map +1 -0
- package/dist/intake/intake-pipeline.d.ts +63 -0
- package/dist/intake/intake-pipeline.d.ts.map +1 -0
- package/dist/intake/intake-pipeline.js +373 -0
- package/dist/intake/intake-pipeline.js.map +1 -0
- package/dist/intake/types.d.ts +65 -0
- package/dist/intake/types.d.ts.map +1 -0
- package/dist/intake/types.js +3 -0
- package/dist/intake/types.js.map +1 -0
- package/dist/intelligence/loader.js +1 -1
- package/dist/intelligence/loader.js.map +1 -1
- package/dist/intelligence/types.d.ts +3 -1
- package/dist/intelligence/types.d.ts.map +1 -1
- package/dist/logging/logger.d.ts +37 -0
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +145 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/logging/types.d.ts +19 -0
- package/dist/logging/types.d.ts.map +1 -0
- package/dist/logging/types.js +2 -0
- package/dist/logging/types.js.map +1 -0
- package/dist/loop/loop-manager.d.ts +100 -0
- package/dist/loop/loop-manager.d.ts.map +1 -0
- package/dist/loop/loop-manager.js +379 -0
- package/dist/loop/loop-manager.js.map +1 -0
- package/dist/loop/types.d.ts +103 -0
- package/dist/loop/types.d.ts.map +1 -0
- package/dist/loop/types.js +11 -0
- package/dist/loop/types.js.map +1 -0
- package/dist/persistence/index.d.ts +3 -0
- package/dist/persistence/index.d.ts.map +1 -0
- package/dist/persistence/index.js +2 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/persistence/sqlite-provider.d.ts +25 -0
- package/dist/persistence/sqlite-provider.d.ts.map +1 -0
- package/dist/persistence/sqlite-provider.js +59 -0
- package/dist/persistence/sqlite-provider.js.map +1 -0
- package/dist/persistence/types.d.ts +36 -0
- package/dist/persistence/types.d.ts.map +1 -0
- package/dist/persistence/types.js +8 -0
- package/dist/persistence/types.js.map +1 -0
- package/dist/planning/gap-analysis.d.ts +72 -0
- package/dist/planning/gap-analysis.d.ts.map +1 -0
- package/dist/planning/gap-analysis.js +442 -0
- package/dist/planning/gap-analysis.js.map +1 -0
- package/dist/planning/gap-types.d.ts +29 -0
- package/dist/planning/gap-types.d.ts.map +1 -0
- package/dist/planning/gap-types.js +28 -0
- package/dist/planning/gap-types.js.map +1 -0
- package/dist/planning/planner.d.ts +421 -4
- package/dist/planning/planner.d.ts.map +1 -1
- package/dist/planning/planner.js +949 -21
- package/dist/planning/planner.js.map +1 -1
- package/dist/playbooks/generic/brainstorming.d.ts +9 -0
- package/dist/playbooks/generic/brainstorming.d.ts.map +1 -0
- package/dist/playbooks/generic/brainstorming.js +105 -0
- package/dist/playbooks/generic/brainstorming.js.map +1 -0
- package/dist/playbooks/generic/code-review.d.ts +11 -0
- package/dist/playbooks/generic/code-review.d.ts.map +1 -0
- package/dist/playbooks/generic/code-review.js +176 -0
- package/dist/playbooks/generic/code-review.js.map +1 -0
- package/dist/playbooks/generic/subagent-execution.d.ts +9 -0
- package/dist/playbooks/generic/subagent-execution.d.ts.map +1 -0
- package/dist/playbooks/generic/subagent-execution.js +68 -0
- package/dist/playbooks/generic/subagent-execution.js.map +1 -0
- package/dist/playbooks/generic/systematic-debugging.d.ts +9 -0
- package/dist/playbooks/generic/systematic-debugging.d.ts.map +1 -0
- package/dist/playbooks/generic/systematic-debugging.js +87 -0
- package/dist/playbooks/generic/systematic-debugging.js.map +1 -0
- package/dist/playbooks/generic/tdd.d.ts +9 -0
- package/dist/playbooks/generic/tdd.d.ts.map +1 -0
- package/dist/playbooks/generic/tdd.js +70 -0
- package/dist/playbooks/generic/tdd.js.map +1 -0
- package/dist/playbooks/generic/verification.d.ts +9 -0
- package/dist/playbooks/generic/verification.d.ts.map +1 -0
- package/dist/playbooks/generic/verification.js +74 -0
- package/dist/playbooks/generic/verification.js.map +1 -0
- package/dist/playbooks/index.d.ts +4 -0
- package/dist/playbooks/index.d.ts.map +1 -0
- package/dist/playbooks/index.js +5 -0
- package/dist/playbooks/index.js.map +1 -0
- package/dist/playbooks/playbook-registry.d.ts +42 -0
- package/dist/playbooks/playbook-registry.d.ts.map +1 -0
- package/dist/playbooks/playbook-registry.js +227 -0
- package/dist/playbooks/playbook-registry.js.map +1 -0
- package/dist/playbooks/playbook-seeder.d.ts +47 -0
- package/dist/playbooks/playbook-seeder.d.ts.map +1 -0
- package/dist/playbooks/playbook-seeder.js +104 -0
- package/dist/playbooks/playbook-seeder.js.map +1 -0
- package/dist/playbooks/playbook-types.d.ts +132 -0
- package/dist/playbooks/playbook-types.d.ts.map +1 -0
- package/dist/playbooks/playbook-types.js +12 -0
- package/dist/playbooks/playbook-types.js.map +1 -0
- package/dist/project/project-registry.d.ts +79 -0
- package/dist/project/project-registry.d.ts.map +1 -0
- package/dist/project/project-registry.js +274 -0
- package/dist/project/project-registry.js.map +1 -0
- package/dist/project/types.d.ts +28 -0
- package/dist/project/types.d.ts.map +1 -0
- package/dist/project/types.js +5 -0
- package/dist/project/types.js.map +1 -0
- package/dist/prompts/index.d.ts +4 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +3 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/prompts/parser.d.ts +17 -0
- package/dist/prompts/parser.d.ts.map +1 -0
- package/dist/prompts/parser.js +47 -0
- package/dist/prompts/parser.js.map +1 -0
- package/dist/prompts/template-manager.d.ts +25 -0
- package/dist/prompts/template-manager.d.ts.map +1 -0
- package/dist/prompts/template-manager.js +71 -0
- package/dist/prompts/template-manager.js.map +1 -0
- package/dist/prompts/types.d.ts +26 -0
- package/dist/prompts/types.d.ts.map +1 -0
- package/dist/prompts/types.js +5 -0
- package/dist/prompts/types.js.map +1 -0
- package/dist/runtime/admin-extra-ops.d.ts +15 -0
- package/dist/runtime/admin-extra-ops.d.ts.map +1 -0
- package/dist/runtime/admin-extra-ops.js +595 -0
- package/dist/runtime/admin-extra-ops.js.map +1 -0
- package/dist/runtime/admin-ops.d.ts +15 -0
- package/dist/runtime/admin-ops.d.ts.map +1 -0
- package/dist/runtime/admin-ops.js +329 -0
- package/dist/runtime/admin-ops.js.map +1 -0
- package/dist/runtime/capture-ops.d.ts +15 -0
- package/dist/runtime/capture-ops.d.ts.map +1 -0
- package/dist/runtime/capture-ops.js +363 -0
- package/dist/runtime/capture-ops.js.map +1 -0
- package/dist/runtime/cognee-sync-ops.d.ts +12 -0
- package/dist/runtime/cognee-sync-ops.d.ts.map +1 -0
- package/dist/runtime/cognee-sync-ops.js +55 -0
- package/dist/runtime/cognee-sync-ops.js.map +1 -0
- package/dist/runtime/core-ops.d.ts +9 -3
- package/dist/runtime/core-ops.d.ts.map +1 -1
- package/dist/runtime/core-ops.js +693 -10
- package/dist/runtime/core-ops.js.map +1 -1
- package/dist/runtime/curator-extra-ops.d.ts +9 -0
- package/dist/runtime/curator-extra-ops.d.ts.map +1 -0
- package/dist/runtime/curator-extra-ops.js +71 -0
- package/dist/runtime/curator-extra-ops.js.map +1 -0
- package/dist/runtime/domain-ops.d.ts.map +1 -1
- package/dist/runtime/domain-ops.js +61 -15
- package/dist/runtime/domain-ops.js.map +1 -1
- package/dist/runtime/grading-ops.d.ts +14 -0
- package/dist/runtime/grading-ops.d.ts.map +1 -0
- package/dist/runtime/grading-ops.js +105 -0
- package/dist/runtime/grading-ops.js.map +1 -0
- package/dist/runtime/intake-ops.d.ts +14 -0
- package/dist/runtime/intake-ops.d.ts.map +1 -0
- package/dist/runtime/intake-ops.js +110 -0
- package/dist/runtime/intake-ops.js.map +1 -0
- package/dist/runtime/loop-ops.d.ts +14 -0
- package/dist/runtime/loop-ops.d.ts.map +1 -0
- package/dist/runtime/loop-ops.js +251 -0
- package/dist/runtime/loop-ops.js.map +1 -0
- package/dist/runtime/memory-cross-project-ops.d.ts +12 -0
- package/dist/runtime/memory-cross-project-ops.d.ts.map +1 -0
- package/dist/runtime/memory-cross-project-ops.js +165 -0
- package/dist/runtime/memory-cross-project-ops.js.map +1 -0
- package/dist/runtime/memory-extra-ops.d.ts +13 -0
- package/dist/runtime/memory-extra-ops.d.ts.map +1 -0
- package/dist/runtime/memory-extra-ops.js +173 -0
- package/dist/runtime/memory-extra-ops.js.map +1 -0
- package/dist/runtime/orchestrate-ops.d.ts +17 -0
- package/dist/runtime/orchestrate-ops.d.ts.map +1 -0
- package/dist/runtime/orchestrate-ops.js +246 -0
- package/dist/runtime/orchestrate-ops.js.map +1 -0
- package/dist/runtime/planning-extra-ops.d.ts +25 -0
- package/dist/runtime/planning-extra-ops.d.ts.map +1 -0
- package/dist/runtime/planning-extra-ops.js +663 -0
- package/dist/runtime/planning-extra-ops.js.map +1 -0
- package/dist/runtime/playbook-ops.d.ts +14 -0
- package/dist/runtime/playbook-ops.d.ts.map +1 -0
- package/dist/runtime/playbook-ops.js +141 -0
- package/dist/runtime/playbook-ops.js.map +1 -0
- package/dist/runtime/project-ops.d.ts +15 -0
- package/dist/runtime/project-ops.d.ts.map +1 -0
- package/dist/runtime/project-ops.js +186 -0
- package/dist/runtime/project-ops.js.map +1 -0
- package/dist/runtime/runtime.d.ts.map +1 -1
- package/dist/runtime/runtime.js +65 -3
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/runtime/types.d.ts +29 -0
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/vault-extra-ops.d.ts +10 -0
- package/dist/runtime/vault-extra-ops.d.ts.map +1 -0
- package/dist/runtime/vault-extra-ops.js +536 -0
- package/dist/runtime/vault-extra-ops.js.map +1 -0
- package/dist/telemetry/telemetry.d.ts +48 -0
- package/dist/telemetry/telemetry.d.ts.map +1 -0
- package/dist/telemetry/telemetry.js +87 -0
- package/dist/telemetry/telemetry.js.map +1 -0
- package/dist/vault/playbook.d.ts +34 -0
- package/dist/vault/playbook.d.ts.map +1 -0
- package/dist/vault/playbook.js +60 -0
- package/dist/vault/playbook.js.map +1 -0
- package/dist/vault/vault.d.ts +97 -4
- package/dist/vault/vault.d.ts.map +1 -1
- package/dist/vault/vault.js +424 -65
- package/dist/vault/vault.js.map +1 -1
- package/package.json +7 -3
- package/src/__tests__/admin-extra-ops.test.ts +467 -0
- package/src/__tests__/admin-ops.test.ts +271 -0
- package/src/__tests__/brain-intelligence.test.ts +205 -0
- package/src/__tests__/brain.test.ts +134 -3
- package/src/__tests__/capture-ops.test.ts +509 -0
- package/src/__tests__/cognee-integration.test.ts +80 -0
- package/src/__tests__/cognee-sync-manager.test.ts +103 -0
- package/src/__tests__/core-ops.test.ts +292 -2
- package/src/__tests__/curator-extra-ops.test.ts +381 -0
- package/src/__tests__/domain-ops.test.ts +66 -0
- package/src/__tests__/errors.test.ts +388 -0
- package/src/__tests__/governance.test.ts +522 -0
- package/src/__tests__/grading-ops.test.ts +361 -0
- package/src/__tests__/identity-manager.test.ts +243 -0
- package/src/__tests__/intake-pipeline.test.ts +162 -0
- package/src/__tests__/intent-router.test.ts +222 -0
- package/src/__tests__/logger.test.ts +200 -0
- package/src/__tests__/loop-ops.test.ts +469 -0
- package/src/__tests__/memory-cross-project-ops.test.ts +248 -0
- package/src/__tests__/memory-extra-ops.test.ts +352 -0
- package/src/__tests__/orchestrate-ops.test.ts +289 -0
- package/src/__tests__/persistence.test.ts +225 -0
- package/src/__tests__/planner.test.ts +416 -7
- package/src/__tests__/planning-extra-ops.test.ts +706 -0
- package/src/__tests__/playbook-registry.test.ts +326 -0
- package/src/__tests__/playbook-seeder.test.ts +163 -0
- package/src/__tests__/playbook.test.ts +389 -0
- package/src/__tests__/project-ops.test.ts +381 -0
- package/src/__tests__/template-manager.test.ts +222 -0
- package/src/__tests__/vault-extra-ops.test.ts +482 -0
- package/src/brain/brain.ts +185 -16
- package/src/brain/intelligence.ts +179 -10
- package/src/brain/types.ts +40 -2
- package/src/cognee/client.ts +18 -0
- package/src/cognee/sync-manager.ts +389 -0
- package/src/control/identity-manager.ts +354 -0
- package/src/control/intent-router.ts +326 -0
- package/src/control/types.ts +102 -0
- package/src/curator/curator.ts +295 -1
- package/src/errors/classify.ts +102 -0
- package/src/errors/index.ts +5 -0
- package/src/errors/retry.ts +132 -0
- package/src/errors/types.ts +81 -0
- package/src/governance/governance.ts +698 -0
- package/src/governance/index.ts +18 -0
- package/src/governance/types.ts +111 -0
- package/src/index.ts +213 -2
- package/src/intake/content-classifier.ts +146 -0
- package/src/intake/dedup-gate.ts +92 -0
- package/src/intake/intake-pipeline.ts +503 -0
- package/src/intake/types.ts +69 -0
- package/src/intelligence/loader.ts +1 -1
- package/src/intelligence/types.ts +3 -1
- package/src/logging/logger.ts +154 -0
- package/src/logging/types.ts +21 -0
- package/src/loop/loop-manager.ts +448 -0
- package/src/loop/types.ts +115 -0
- package/src/persistence/index.ts +7 -0
- package/src/persistence/sqlite-provider.ts +62 -0
- package/src/persistence/types.ts +44 -0
- package/src/planning/gap-analysis.ts +775 -0
- package/src/planning/gap-types.ts +61 -0
- package/src/planning/planner.ts +1273 -24
- package/src/playbooks/generic/brainstorming.ts +110 -0
- package/src/playbooks/generic/code-review.ts +181 -0
- package/src/playbooks/generic/subagent-execution.ts +74 -0
- package/src/playbooks/generic/systematic-debugging.ts +92 -0
- package/src/playbooks/generic/tdd.ts +75 -0
- package/src/playbooks/generic/verification.ts +79 -0
- package/src/playbooks/index.ts +27 -0
- package/src/playbooks/playbook-registry.ts +284 -0
- package/src/playbooks/playbook-seeder.ts +119 -0
- package/src/playbooks/playbook-types.ts +162 -0
- package/src/project/project-registry.ts +370 -0
- package/src/project/types.ts +31 -0
- package/src/prompts/index.ts +3 -0
- package/src/prompts/parser.ts +59 -0
- package/src/prompts/template-manager.ts +77 -0
- package/src/prompts/types.ts +28 -0
- package/src/runtime/admin-extra-ops.ts +652 -0
- package/src/runtime/admin-ops.ts +340 -0
- package/src/runtime/capture-ops.ts +404 -0
- package/src/runtime/cognee-sync-ops.ts +63 -0
- package/src/runtime/core-ops.ts +787 -9
- package/src/runtime/curator-extra-ops.ts +85 -0
- package/src/runtime/domain-ops.ts +67 -15
- package/src/runtime/grading-ops.ts +130 -0
- package/src/runtime/intake-ops.ts +126 -0
- package/src/runtime/loop-ops.ts +277 -0
- package/src/runtime/memory-cross-project-ops.ts +191 -0
- package/src/runtime/memory-extra-ops.ts +186 -0
- package/src/runtime/orchestrate-ops.ts +278 -0
- package/src/runtime/planning-extra-ops.ts +718 -0
- package/src/runtime/playbook-ops.ts +169 -0
- package/src/runtime/project-ops.ts +202 -0
- package/src/runtime/runtime.ts +77 -3
- package/src/runtime/types.ts +29 -0
- package/src/runtime/vault-extra-ops.ts +606 -0
- package/src/telemetry/telemetry.ts +118 -0
- package/src/vault/playbook.ts +87 -0
- package/src/vault/vault.ts +575 -98
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest';
|
|
2
|
+
import { createAgentRuntime } from '../runtime/runtime.js';
|
|
3
|
+
import { createProjectOps } from '../runtime/project-ops.js';
|
|
4
|
+
import type { AgentRuntime } from '../runtime/types.js';
|
|
5
|
+
import type { OpDefinition } from '../facades/types.js';
|
|
6
|
+
|
|
7
|
+
describe('createProjectOps', () => {
|
|
8
|
+
let runtime: AgentRuntime;
|
|
9
|
+
let ops: OpDefinition[];
|
|
10
|
+
|
|
11
|
+
function findOp(name: string): OpDefinition {
|
|
12
|
+
const op = ops.find((o) => o.name === name);
|
|
13
|
+
if (!op) throw new Error(`Op "${name}" not found`);
|
|
14
|
+
return op;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
runtime?.close();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
function setup() {
|
|
22
|
+
runtime = createAgentRuntime({
|
|
23
|
+
agentId: 'test-project',
|
|
24
|
+
vaultPath: ':memory:',
|
|
25
|
+
});
|
|
26
|
+
ops = createProjectOps(runtime);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
it('should return 12 ops', () => {
|
|
30
|
+
setup();
|
|
31
|
+
expect(ops).toHaveLength(12);
|
|
32
|
+
const names = ops.map((o) => o.name);
|
|
33
|
+
expect(names).toEqual([
|
|
34
|
+
'project_get',
|
|
35
|
+
'project_list',
|
|
36
|
+
'project_unregister',
|
|
37
|
+
'project_get_rules',
|
|
38
|
+
'project_list_rules',
|
|
39
|
+
'project_add_rule',
|
|
40
|
+
'project_remove_rule',
|
|
41
|
+
'project_link',
|
|
42
|
+
'project_unlink',
|
|
43
|
+
'project_get_links',
|
|
44
|
+
'project_linked_projects',
|
|
45
|
+
'project_touch',
|
|
46
|
+
]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// ─── Register + Get round-trip ─────────────────────────────────
|
|
50
|
+
|
|
51
|
+
describe('register + project_get round-trip', () => {
|
|
52
|
+
it('should register a project and retrieve it by ID', async () => {
|
|
53
|
+
setup();
|
|
54
|
+
const registered = runtime.projectRegistry.register('/tmp/my-project', 'My Project');
|
|
55
|
+
const result = (await findOp('project_get').handler({
|
|
56
|
+
projectId: registered.id,
|
|
57
|
+
})) as { found: boolean; project: { id: string; path: string; name: string } };
|
|
58
|
+
|
|
59
|
+
expect(result.found).toBe(true);
|
|
60
|
+
expect(result.project.path).toBe('/tmp/my-project');
|
|
61
|
+
expect(result.project.name).toBe('My Project');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should return found=false for unknown ID', async () => {
|
|
65
|
+
setup();
|
|
66
|
+
const result = (await findOp('project_get').handler({
|
|
67
|
+
projectId: 'nonexistent',
|
|
68
|
+
})) as { found: boolean; project: null };
|
|
69
|
+
|
|
70
|
+
expect(result.found).toBe(false);
|
|
71
|
+
expect(result.project).toBeNull();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// ─── project_list ──────────────────────────────────────────────
|
|
76
|
+
|
|
77
|
+
describe('project_list', () => {
|
|
78
|
+
it('should list all registered projects', async () => {
|
|
79
|
+
setup();
|
|
80
|
+
runtime.projectRegistry.register('/tmp/alpha', 'Alpha');
|
|
81
|
+
runtime.projectRegistry.register('/tmp/beta', 'Beta');
|
|
82
|
+
|
|
83
|
+
const result = (await findOp('project_list').handler({})) as {
|
|
84
|
+
count: number;
|
|
85
|
+
projects: Array<{ path: string; name: string }>;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
expect(result.count).toBe(2);
|
|
89
|
+
const paths = result.projects.map((p) => p.path);
|
|
90
|
+
expect(paths).toContain('/tmp/alpha');
|
|
91
|
+
expect(paths).toContain('/tmp/beta');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('should return empty list when no projects registered', async () => {
|
|
95
|
+
setup();
|
|
96
|
+
const result = (await findOp('project_list').handler({})) as {
|
|
97
|
+
count: number;
|
|
98
|
+
projects: unknown[];
|
|
99
|
+
};
|
|
100
|
+
expect(result.count).toBe(0);
|
|
101
|
+
expect(result.projects).toEqual([]);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// ─── project_unregister ────────────────────────────────────────
|
|
106
|
+
|
|
107
|
+
describe('project_unregister', () => {
|
|
108
|
+
it('should unregister a project', async () => {
|
|
109
|
+
setup();
|
|
110
|
+
const registered = runtime.projectRegistry.register('/tmp/to-remove');
|
|
111
|
+
|
|
112
|
+
const result = (await findOp('project_unregister').handler({
|
|
113
|
+
projectId: registered.id,
|
|
114
|
+
})) as { removed: boolean };
|
|
115
|
+
|
|
116
|
+
expect(result.removed).toBe(true);
|
|
117
|
+
|
|
118
|
+
// Verify it is gone
|
|
119
|
+
const getResult = (await findOp('project_get').handler({
|
|
120
|
+
projectId: registered.id,
|
|
121
|
+
})) as { found: boolean };
|
|
122
|
+
expect(getResult.found).toBe(false);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('should return removed=false for unknown project', async () => {
|
|
126
|
+
setup();
|
|
127
|
+
const result = (await findOp('project_unregister').handler({
|
|
128
|
+
projectId: 'nonexistent',
|
|
129
|
+
})) as { removed: boolean };
|
|
130
|
+
expect(result.removed).toBe(false);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
// ─── Rules CRUD ────────────────────────────────────────────────
|
|
135
|
+
|
|
136
|
+
describe('project_add_rule + project_get_rules', () => {
|
|
137
|
+
it('should add and retrieve rules for a project', async () => {
|
|
138
|
+
setup();
|
|
139
|
+
const project = runtime.projectRegistry.register('/tmp/rules-project');
|
|
140
|
+
|
|
141
|
+
const addResult = (await findOp('project_add_rule').handler({
|
|
142
|
+
projectId: project.id,
|
|
143
|
+
category: 'behavior',
|
|
144
|
+
text: 'Always use semantic tokens',
|
|
145
|
+
priority: 10,
|
|
146
|
+
})) as {
|
|
147
|
+
added: boolean;
|
|
148
|
+
rule: { id: string; category: string; text: string; priority: number };
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
expect(addResult.added).toBe(true);
|
|
152
|
+
expect(addResult.rule.category).toBe('behavior');
|
|
153
|
+
expect(addResult.rule.text).toBe('Always use semantic tokens');
|
|
154
|
+
expect(addResult.rule.priority).toBe(10);
|
|
155
|
+
|
|
156
|
+
const rulesResult = (await findOp('project_get_rules').handler({
|
|
157
|
+
projectId: project.id,
|
|
158
|
+
})) as { count: number; rules: Array<{ text: string }> };
|
|
159
|
+
|
|
160
|
+
expect(rulesResult.count).toBe(1);
|
|
161
|
+
expect(rulesResult.rules[0].text).toBe('Always use semantic tokens');
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
describe('project_remove_rule', () => {
|
|
166
|
+
it('should remove a rule', async () => {
|
|
167
|
+
setup();
|
|
168
|
+
const project = runtime.projectRegistry.register('/tmp/rm-rule');
|
|
169
|
+
const rule = runtime.projectRegistry.addRule(project.id, {
|
|
170
|
+
category: 'restriction',
|
|
171
|
+
text: 'No inline styles',
|
|
172
|
+
priority: 5,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
const result = (await findOp('project_remove_rule').handler({
|
|
176
|
+
ruleId: rule.id,
|
|
177
|
+
})) as { removed: boolean };
|
|
178
|
+
|
|
179
|
+
expect(result.removed).toBe(true);
|
|
180
|
+
|
|
181
|
+
// Verify rule is gone
|
|
182
|
+
const rulesResult = (await findOp('project_get_rules').handler({
|
|
183
|
+
projectId: project.id,
|
|
184
|
+
})) as { count: number };
|
|
185
|
+
expect(rulesResult.count).toBe(0);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('should return removed=false for unknown rule', async () => {
|
|
189
|
+
setup();
|
|
190
|
+
const result = (await findOp('project_remove_rule').handler({
|
|
191
|
+
ruleId: 'nonexistent-rule',
|
|
192
|
+
})) as { removed: boolean };
|
|
193
|
+
expect(result.removed).toBe(false);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe('project_list_rules', () => {
|
|
198
|
+
it('should list all projects with their rules', async () => {
|
|
199
|
+
setup();
|
|
200
|
+
const p1 = runtime.projectRegistry.register('/tmp/p1', 'P1');
|
|
201
|
+
const p2 = runtime.projectRegistry.register('/tmp/p2', 'P2');
|
|
202
|
+
runtime.projectRegistry.addRule(p1.id, { category: 'behavior', text: 'Rule A', priority: 0 });
|
|
203
|
+
runtime.projectRegistry.addRule(p1.id, {
|
|
204
|
+
category: 'convention',
|
|
205
|
+
text: 'Rule B',
|
|
206
|
+
priority: 1,
|
|
207
|
+
});
|
|
208
|
+
runtime.projectRegistry.addRule(p2.id, {
|
|
209
|
+
category: 'preference',
|
|
210
|
+
text: 'Rule C',
|
|
211
|
+
priority: 0,
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
const result = (await findOp('project_list_rules').handler({})) as {
|
|
215
|
+
count: number;
|
|
216
|
+
projects: Array<{ project: { id: string }; ruleCount: number; rules: unknown[] }>;
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
expect(result.count).toBe(2);
|
|
220
|
+
const p1Entry = result.projects.find((p) => p.project.id === p1.id);
|
|
221
|
+
expect(p1Entry?.ruleCount).toBe(2);
|
|
222
|
+
const p2Entry = result.projects.find((p) => p.project.id === p2.id);
|
|
223
|
+
expect(p2Entry?.ruleCount).toBe(1);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// ─── Links ─────────────────────────────────────────────────────
|
|
228
|
+
|
|
229
|
+
describe('project_link + project_unlink', () => {
|
|
230
|
+
it('should link and unlink two projects', async () => {
|
|
231
|
+
setup();
|
|
232
|
+
const p1 = runtime.projectRegistry.register('/tmp/link-a', 'Link A');
|
|
233
|
+
const p2 = runtime.projectRegistry.register('/tmp/link-b', 'Link B');
|
|
234
|
+
|
|
235
|
+
const linkResult = (await findOp('project_link').handler({
|
|
236
|
+
sourceId: p1.id,
|
|
237
|
+
targetId: p2.id,
|
|
238
|
+
linkType: 'related',
|
|
239
|
+
})) as {
|
|
240
|
+
linked: boolean;
|
|
241
|
+
link: { sourceProjectId: string; targetProjectId: string; linkType: string };
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
expect(linkResult.linked).toBe(true);
|
|
245
|
+
expect(linkResult.link.sourceProjectId).toBe(p1.id);
|
|
246
|
+
expect(linkResult.link.targetProjectId).toBe(p2.id);
|
|
247
|
+
expect(linkResult.link.linkType).toBe('related');
|
|
248
|
+
|
|
249
|
+
const unlinkResult = (await findOp('project_unlink').handler({
|
|
250
|
+
sourceId: p1.id,
|
|
251
|
+
targetId: p2.id,
|
|
252
|
+
linkType: 'related',
|
|
253
|
+
})) as { removed: number };
|
|
254
|
+
|
|
255
|
+
expect(unlinkResult.removed).toBe(1);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('should unlink all types when linkType is omitted', async () => {
|
|
259
|
+
setup();
|
|
260
|
+
const p1 = runtime.projectRegistry.register('/tmp/unlink-a');
|
|
261
|
+
const p2 = runtime.projectRegistry.register('/tmp/unlink-b');
|
|
262
|
+
|
|
263
|
+
runtime.projectRegistry.link(p1.id, p2.id, 'related');
|
|
264
|
+
runtime.projectRegistry.link(p1.id, p2.id, 'parent');
|
|
265
|
+
|
|
266
|
+
const result = (await findOp('project_unlink').handler({
|
|
267
|
+
sourceId: p1.id,
|
|
268
|
+
targetId: p2.id,
|
|
269
|
+
})) as { removed: number };
|
|
270
|
+
|
|
271
|
+
expect(result.removed).toBe(2);
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
describe('project_get_links', () => {
|
|
276
|
+
it('should get all links for a project', async () => {
|
|
277
|
+
setup();
|
|
278
|
+
const p1 = runtime.projectRegistry.register('/tmp/gl-a');
|
|
279
|
+
const p2 = runtime.projectRegistry.register('/tmp/gl-b');
|
|
280
|
+
const p3 = runtime.projectRegistry.register('/tmp/gl-c');
|
|
281
|
+
|
|
282
|
+
runtime.projectRegistry.link(p1.id, p2.id, 'related');
|
|
283
|
+
runtime.projectRegistry.link(p3.id, p1.id, 'parent');
|
|
284
|
+
|
|
285
|
+
const result = (await findOp('project_get_links').handler({
|
|
286
|
+
projectId: p1.id,
|
|
287
|
+
})) as { count: number; links: Array<{ sourceProjectId: string; targetProjectId: string }> };
|
|
288
|
+
|
|
289
|
+
expect(result.count).toBe(2);
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
describe('project_linked_projects', () => {
|
|
294
|
+
it('should return linked projects with direction info', async () => {
|
|
295
|
+
setup();
|
|
296
|
+
const p1 = runtime.projectRegistry.register('/tmp/lp-a', 'LP-A');
|
|
297
|
+
const p2 = runtime.projectRegistry.register('/tmp/lp-b', 'LP-B');
|
|
298
|
+
const p3 = runtime.projectRegistry.register('/tmp/lp-c', 'LP-C');
|
|
299
|
+
|
|
300
|
+
runtime.projectRegistry.link(p1.id, p2.id, 'related');
|
|
301
|
+
runtime.projectRegistry.link(p3.id, p1.id, 'fork');
|
|
302
|
+
|
|
303
|
+
const result = (await findOp('project_linked_projects').handler({
|
|
304
|
+
projectId: p1.id,
|
|
305
|
+
})) as {
|
|
306
|
+
count: number;
|
|
307
|
+
linked: Array<{
|
|
308
|
+
project: { id: string; name: string };
|
|
309
|
+
linkType: string;
|
|
310
|
+
direction: 'outgoing' | 'incoming';
|
|
311
|
+
}>;
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
expect(result.count).toBe(2);
|
|
315
|
+
|
|
316
|
+
const outgoing = result.linked.find((l) => l.direction === 'outgoing');
|
|
317
|
+
expect(outgoing?.project.name).toBe('LP-B');
|
|
318
|
+
expect(outgoing?.linkType).toBe('related');
|
|
319
|
+
|
|
320
|
+
const incoming = result.linked.find((l) => l.direction === 'incoming');
|
|
321
|
+
expect(incoming?.project.name).toBe('LP-C');
|
|
322
|
+
expect(incoming?.linkType).toBe('fork');
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// ─── project_touch ─────────────────────────────────────────────
|
|
327
|
+
|
|
328
|
+
describe('project_touch', () => {
|
|
329
|
+
it('should update last accessed timestamp', async () => {
|
|
330
|
+
setup();
|
|
331
|
+
const project = runtime.projectRegistry.register('/tmp/touch-project');
|
|
332
|
+
const originalTs = project.lastAccessedAt;
|
|
333
|
+
|
|
334
|
+
// Small delay to ensure timestamp changes
|
|
335
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
336
|
+
|
|
337
|
+
const result = (await findOp('project_touch').handler({
|
|
338
|
+
projectId: project.id,
|
|
339
|
+
})) as { touched: boolean };
|
|
340
|
+
|
|
341
|
+
expect(result.touched).toBe(true);
|
|
342
|
+
|
|
343
|
+
const updated = runtime.projectRegistry.get(project.id);
|
|
344
|
+
expect(updated!.lastAccessedAt).toBeGreaterThan(originalTs);
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
// ─── Auth levels ───────────────────────────────────────────────
|
|
349
|
+
|
|
350
|
+
describe('auth levels', () => {
|
|
351
|
+
it('should use read auth for read ops', () => {
|
|
352
|
+
setup();
|
|
353
|
+
const readOps = [
|
|
354
|
+
'project_get',
|
|
355
|
+
'project_list',
|
|
356
|
+
'project_get_rules',
|
|
357
|
+
'project_list_rules',
|
|
358
|
+
'project_get_links',
|
|
359
|
+
'project_linked_projects',
|
|
360
|
+
];
|
|
361
|
+
for (const name of readOps) {
|
|
362
|
+
expect(findOp(name).auth).toBe('read');
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it('should use write auth for mutation ops', () => {
|
|
367
|
+
setup();
|
|
368
|
+
const writeOps = [
|
|
369
|
+
'project_unregister',
|
|
370
|
+
'project_add_rule',
|
|
371
|
+
'project_remove_rule',
|
|
372
|
+
'project_link',
|
|
373
|
+
'project_unlink',
|
|
374
|
+
'project_touch',
|
|
375
|
+
];
|
|
376
|
+
for (const name of writeOps) {
|
|
377
|
+
expect(findOp(name).auth).toBe('write');
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
});
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { mkdirSync, writeFileSync, rmSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { parseVariables, resolveIncludes } from '../prompts/parser.js';
|
|
6
|
+
import { TemplateManager } from '../prompts/template-manager.js';
|
|
7
|
+
|
|
8
|
+
// ─── parseVariables ───────────────────────────────────────────────────
|
|
9
|
+
|
|
10
|
+
describe('parseVariables', () => {
|
|
11
|
+
it('extracts required variable', () => {
|
|
12
|
+
const vars = parseVariables('Hello {{name}}');
|
|
13
|
+
expect(vars).toHaveLength(1);
|
|
14
|
+
expect(vars[0]).toEqual({ name: 'name', required: true, defaultValue: undefined });
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('extracts variable with default', () => {
|
|
18
|
+
const vars = parseVariables('Hello {{name:World}}');
|
|
19
|
+
expect(vars).toHaveLength(1);
|
|
20
|
+
expect(vars[0]).toEqual({ name: 'name', required: false, defaultValue: 'World' });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('extracts multiple unique variables', () => {
|
|
24
|
+
const vars = parseVariables('{{greeting}} {{name}}, welcome to {{place}}');
|
|
25
|
+
expect(vars).toHaveLength(3);
|
|
26
|
+
expect(vars.map((v) => v.name)).toEqual(['greeting', 'name', 'place']);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('deduplicates same variable', () => {
|
|
30
|
+
const vars = parseVariables('{{name}} and {{name}} again');
|
|
31
|
+
expect(vars).toHaveLength(1);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('handles empty default', () => {
|
|
35
|
+
const vars = parseVariables('{{opt:}}');
|
|
36
|
+
expect(vars[0]).toEqual({ name: 'opt', required: false, defaultValue: '' });
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('returns empty for no variables', () => {
|
|
40
|
+
expect(parseVariables('plain text')).toEqual([]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('handles mixed required and optional', () => {
|
|
44
|
+
const vars = parseVariables('{{required}} and {{optional:fallback}}');
|
|
45
|
+
expect(vars).toHaveLength(2);
|
|
46
|
+
expect(vars[0].required).toBe(true);
|
|
47
|
+
expect(vars[1].required).toBe(false);
|
|
48
|
+
expect(vars[1].defaultValue).toBe('fallback');
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// ─── resolveIncludes ──────────────────────────────────────────────────
|
|
53
|
+
|
|
54
|
+
describe('resolveIncludes', () => {
|
|
55
|
+
it('resolves single include', () => {
|
|
56
|
+
const result = resolveIncludes('before @include(header) after', (name) => {
|
|
57
|
+
if (name === 'header') return 'HEADER';
|
|
58
|
+
return '';
|
|
59
|
+
});
|
|
60
|
+
expect(result).toBe('before HEADER after');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('resolves nested includes', () => {
|
|
64
|
+
const result = resolveIncludes('start @include(a)', (name) => {
|
|
65
|
+
if (name === 'a') return 'A @include(b)';
|
|
66
|
+
if (name === 'b') return 'B';
|
|
67
|
+
return '';
|
|
68
|
+
});
|
|
69
|
+
expect(result).toBe('start A B');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('detects circular includes', () => {
|
|
73
|
+
expect(() =>
|
|
74
|
+
resolveIncludes('@include(a)', (name) => {
|
|
75
|
+
if (name === 'a') return '@include(b)';
|
|
76
|
+
if (name === 'b') return '@include(a)';
|
|
77
|
+
return '';
|
|
78
|
+
}),
|
|
79
|
+
).toThrow(/Circular include detected/);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('throws on depth exceeding 10', () => {
|
|
83
|
+
// Each level includes a unique name so cycle detection doesn't fire
|
|
84
|
+
let counter = 0;
|
|
85
|
+
expect(() =>
|
|
86
|
+
resolveIncludes('@include(level0)', (name) => {
|
|
87
|
+
counter++;
|
|
88
|
+
return `@include(level${counter})`;
|
|
89
|
+
}),
|
|
90
|
+
).toThrow(/Include depth exceeded/);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('handles no includes', () => {
|
|
94
|
+
const result = resolveIncludes('no includes here', () => '');
|
|
95
|
+
expect(result).toBe('no includes here');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('handles multiple includes', () => {
|
|
99
|
+
const result = resolveIncludes('@include(a) + @include(b)', (name) => name.toUpperCase());
|
|
100
|
+
expect(result).toBe('A + B');
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// ─── TemplateManager ──────────────────────────────────────────────────
|
|
105
|
+
|
|
106
|
+
describe('TemplateManager', () => {
|
|
107
|
+
let tempDir: string;
|
|
108
|
+
|
|
109
|
+
beforeEach(() => {
|
|
110
|
+
tempDir = join(tmpdir(), `templates-test-${Date.now()}`);
|
|
111
|
+
mkdirSync(tempDir, { recursive: true });
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
afterEach(() => {
|
|
115
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('loads .prompt files from directory', () => {
|
|
119
|
+
writeFileSync(join(tempDir, 'greeting.prompt'), 'Hello {{name}}!');
|
|
120
|
+
writeFileSync(join(tempDir, 'farewell.prompt'), 'Goodbye {{name}}.');
|
|
121
|
+
writeFileSync(join(tempDir, 'not-a-template.txt'), 'ignored');
|
|
122
|
+
|
|
123
|
+
const mgr = new TemplateManager(tempDir);
|
|
124
|
+
mgr.load();
|
|
125
|
+
|
|
126
|
+
expect(mgr.listTemplates().sort()).toEqual(['farewell', 'greeting']);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('handles nonexistent directory gracefully', () => {
|
|
130
|
+
const mgr = new TemplateManager('/nonexistent/path');
|
|
131
|
+
mgr.load(); // should not throw
|
|
132
|
+
expect(mgr.listTemplates()).toEqual([]);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('renders template with variables', () => {
|
|
136
|
+
writeFileSync(join(tempDir, 'hello.prompt'), 'Hello {{name}}, you are {{role}}!');
|
|
137
|
+
const mgr = new TemplateManager(tempDir);
|
|
138
|
+
mgr.load();
|
|
139
|
+
|
|
140
|
+
const result = mgr.render('hello', { name: 'Atlas', role: 'advisor' });
|
|
141
|
+
expect(result).toBe('Hello Atlas, you are advisor!');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('uses default values', () => {
|
|
145
|
+
writeFileSync(join(tempDir, 'hello.prompt'), 'Hello {{name:World}}!');
|
|
146
|
+
const mgr = new TemplateManager(tempDir);
|
|
147
|
+
mgr.load();
|
|
148
|
+
|
|
149
|
+
expect(mgr.render('hello', {})).toBe('Hello World!');
|
|
150
|
+
expect(mgr.render('hello', { name: 'Custom' })).toBe('Hello Custom!');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('throws on missing required variable in strict mode', () => {
|
|
154
|
+
writeFileSync(join(tempDir, 'strict.prompt'), '{{required}}');
|
|
155
|
+
const mgr = new TemplateManager(tempDir);
|
|
156
|
+
mgr.load();
|
|
157
|
+
|
|
158
|
+
expect(() => mgr.render('strict', {})).toThrow(/Missing required variable: required/);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('leaves placeholder in non-strict mode', () => {
|
|
162
|
+
writeFileSync(join(tempDir, 'lax.prompt'), 'Hello {{name}}!');
|
|
163
|
+
const mgr = new TemplateManager(tempDir);
|
|
164
|
+
mgr.load();
|
|
165
|
+
|
|
166
|
+
const result = mgr.render('lax', {}, { strict: false });
|
|
167
|
+
expect(result).toBe('Hello {{name}}!');
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('resolves @include directives', () => {
|
|
171
|
+
writeFileSync(join(tempDir, 'header.prompt'), '--- HEADER ---');
|
|
172
|
+
writeFileSync(join(tempDir, 'page.prompt'), '@include(header)\nContent here.');
|
|
173
|
+
const mgr = new TemplateManager(tempDir);
|
|
174
|
+
mgr.load();
|
|
175
|
+
|
|
176
|
+
const result = mgr.render('page', {});
|
|
177
|
+
expect(result).toBe('--- HEADER ---\nContent here.');
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('throws on missing include', () => {
|
|
181
|
+
writeFileSync(join(tempDir, 'broken.prompt'), '@include(nonexistent)');
|
|
182
|
+
const mgr = new TemplateManager(tempDir);
|
|
183
|
+
mgr.load();
|
|
184
|
+
|
|
185
|
+
expect(() => mgr.render('broken', {})).toThrow(/Include not found: nonexistent/);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('throws on nonexistent template name', () => {
|
|
189
|
+
const mgr = new TemplateManager(tempDir);
|
|
190
|
+
mgr.load();
|
|
191
|
+
|
|
192
|
+
expect(() => mgr.render('missing', {})).toThrow(/Template not found: missing/);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('getTemplate returns raw template', () => {
|
|
196
|
+
writeFileSync(join(tempDir, 'raw.prompt'), 'Raw {{content}}');
|
|
197
|
+
const mgr = new TemplateManager(tempDir);
|
|
198
|
+
mgr.load();
|
|
199
|
+
|
|
200
|
+
const tmpl = mgr.getTemplate('raw');
|
|
201
|
+
expect(tmpl).not.toBeNull();
|
|
202
|
+
expect(tmpl!.name).toBe('raw');
|
|
203
|
+
expect(tmpl!.content).toBe('Raw {{content}}');
|
|
204
|
+
expect(tmpl!.variables).toHaveLength(1);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('getTemplate returns null for nonexistent', () => {
|
|
208
|
+
const mgr = new TemplateManager(tempDir);
|
|
209
|
+
mgr.load();
|
|
210
|
+
expect(mgr.getTemplate('nope')).toBeNull();
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('variables in included templates get substituted', () => {
|
|
214
|
+
writeFileSync(join(tempDir, 'partial.prompt'), 'I am {{name}}');
|
|
215
|
+
writeFileSync(join(tempDir, 'main.prompt'), 'Hello: @include(partial)!');
|
|
216
|
+
const mgr = new TemplateManager(tempDir);
|
|
217
|
+
mgr.load();
|
|
218
|
+
|
|
219
|
+
const result = mgr.render('main', { name: 'Atlas' });
|
|
220
|
+
expect(result).toBe('Hello: I am Atlas!');
|
|
221
|
+
});
|
|
222
|
+
});
|