apcore-js 0.4.0 → 0.6.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/acl.d.ts +27 -0
- package/dist/acl.d.ts.map +1 -0
- package/dist/acl.js +175 -0
- package/dist/acl.js.map +1 -0
- package/dist/async-task.d.ts +90 -0
- package/dist/async-task.d.ts.map +1 -0
- package/dist/async-task.js +215 -0
- package/dist/async-task.js.map +1 -0
- package/dist/bindings.d.ts +12 -0
- package/dist/bindings.d.ts.map +1 -0
- package/dist/bindings.js +185 -0
- package/dist/bindings.js.map +1 -0
- package/dist/cancel.d.ts +14 -0
- package/dist/cancel.d.ts.map +1 -0
- package/dist/cancel.js +27 -0
- package/dist/cancel.js.map +1 -0
- package/dist/config.d.ts +9 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +23 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +50 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +87 -0
- package/dist/context.js.map +1 -0
- package/dist/decorator.d.ts +57 -0
- package/dist/decorator.d.ts.map +1 -0
- package/dist/decorator.js +74 -0
- package/dist/decorator.js.map +1 -0
- package/dist/errors.d.ts +215 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +246 -0
- package/dist/errors.js.map +1 -0
- package/dist/executor.d.ts +67 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/executor.js +372 -0
- package/dist/executor.js.map +1 -0
- package/dist/extensions.d.ts +58 -0
- package/dist/extensions.d.ts.map +1 -0
- package/dist/extensions.js +220 -0
- package/dist/extensions.js.map +1 -0
- package/{src/index.ts → dist/index.d.ts} +14 -59
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +43 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware/adapters.d.ts +18 -0
- package/dist/middleware/adapters.d.ts.map +1 -0
- package/dist/middleware/adapters.js +25 -0
- package/dist/middleware/adapters.js.map +1 -0
- package/dist/middleware/base.d.ts +10 -0
- package/dist/middleware/base.d.ts.map +1 -0
- package/dist/middleware/base.js +15 -0
- package/dist/middleware/base.js.map +1 -0
- package/{src/middleware/index.ts → dist/middleware/index.d.ts} +1 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +5 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/logging.d.ts +25 -0
- package/dist/middleware/logging.d.ts.map +1 -0
- package/dist/middleware/logging.js +64 -0
- package/dist/middleware/logging.js.map +1 -0
- package/dist/middleware/manager.d.ts +21 -0
- package/dist/middleware/manager.d.ts.map +1 -0
- package/dist/middleware/manager.js +77 -0
- package/dist/middleware/manager.js.map +1 -0
- package/dist/module.d.ts +31 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +12 -0
- package/dist/module.js.map +1 -0
- package/dist/observability/context-logger.d.ts +54 -0
- package/dist/observability/context-logger.d.ts.map +1 -0
- package/dist/observability/context-logger.js +151 -0
- package/dist/observability/context-logger.js.map +1 -0
- package/{src/observability/index.ts → dist/observability/index.d.ts} +1 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +4 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/metrics.d.ts +30 -0
- package/dist/observability/metrics.d.ts.map +1 -0
- package/dist/observability/metrics.js +177 -0
- package/dist/observability/metrics.js.map +1 -0
- package/dist/observability/tracing.d.ts +62 -0
- package/dist/observability/tracing.d.ts.map +1 -0
- package/dist/observability/tracing.js +184 -0
- package/dist/observability/tracing.js.map +1 -0
- package/dist/registry/dependencies.d.ts +6 -0
- package/dist/registry/dependencies.d.ts.map +1 -0
- package/dist/registry/dependencies.js +83 -0
- package/dist/registry/dependencies.js.map +1 -0
- package/dist/registry/entry-point.d.ts +6 -0
- package/dist/registry/entry-point.d.ts.map +1 -0
- package/dist/registry/entry-point.js +55 -0
- package/dist/registry/entry-point.js.map +1 -0
- package/{src/registry/index.ts → dist/registry/index.d.ts} +2 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +8 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry/metadata.d.ts +9 -0
- package/dist/registry/metadata.d.ts.map +1 -0
- package/dist/registry/metadata.js +105 -0
- package/dist/registry/metadata.js.map +1 -0
- package/dist/registry/registry.d.ts +102 -0
- package/dist/registry/registry.d.ts.map +1 -0
- package/dist/registry/registry.js +534 -0
- package/dist/registry/registry.js.map +1 -0
- package/dist/registry/scanner.d.ts +7 -0
- package/dist/registry/scanner.d.ts.map +1 -0
- package/dist/registry/scanner.js +164 -0
- package/dist/registry/scanner.js.map +1 -0
- package/dist/registry/schema-export.d.ts +9 -0
- package/dist/registry/schema-export.d.ts.map +1 -0
- package/dist/registry/schema-export.js +132 -0
- package/dist/registry/schema-export.js.map +1 -0
- package/dist/registry/types.d.ts +29 -0
- package/dist/registry/types.d.ts.map +1 -0
- package/dist/registry/types.js +5 -0
- package/dist/registry/types.js.map +1 -0
- package/dist/registry/validation.d.ts +9 -0
- package/dist/registry/validation.d.ts.map +1 -0
- package/dist/registry/validation.js +33 -0
- package/dist/registry/validation.js.map +1 -0
- package/dist/schema/annotations.d.ts +8 -0
- package/dist/schema/annotations.d.ts.map +1 -0
- package/dist/schema/annotations.js +52 -0
- package/dist/schema/annotations.js.map +1 -0
- package/dist/schema/exporter.d.ts +13 -0
- package/dist/schema/exporter.d.ts.map +1 -0
- package/dist/schema/exporter.js +71 -0
- package/dist/schema/exporter.js.map +1 -0
- package/dist/schema/index.d.ts +9 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/{src/schema/index.ts → dist/schema/index.js} +1 -7
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/loader.d.ts +30 -0
- package/dist/schema/loader.d.ts.map +1 -0
- package/dist/schema/loader.js +260 -0
- package/dist/schema/loader.js.map +1 -0
- package/dist/schema/ref-resolver.d.ts +19 -0
- package/dist/schema/ref-resolver.d.ts.map +1 -0
- package/dist/schema/ref-resolver.js +212 -0
- package/dist/schema/ref-resolver.js.map +1 -0
- package/dist/schema/strict.d.ts +7 -0
- package/dist/schema/strict.d.ts.map +1 -0
- package/dist/schema/strict.js +127 -0
- package/dist/schema/strict.js.map +1 -0
- package/dist/schema/types.d.ts +53 -0
- package/dist/schema/types.d.ts.map +1 -0
- package/dist/schema/types.js +31 -0
- package/dist/schema/types.js.map +1 -0
- package/dist/schema/validator.d.ts +16 -0
- package/dist/schema/validator.d.ts.map +1 -0
- package/dist/schema/validator.js +71 -0
- package/dist/schema/validator.js.map +1 -0
- package/dist/trace-context.d.ts +35 -0
- package/dist/trace-context.d.ts.map +1 -0
- package/dist/trace-context.js +86 -0
- package/dist/trace-context.js.map +1 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +32 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/pattern.d.ts +5 -0
- package/dist/utils/pattern.d.ts.map +1 -0
- package/dist/utils/pattern.js +31 -0
- package/dist/utils/pattern.js.map +1 -0
- package/package.json +8 -2
- package/.claude/settings.local.json +0 -12
- package/.github/workflows/ci.yml +0 -39
- package/.gitmessage +0 -60
- package/.pre-commit-config.yaml +0 -28
- package/CHANGELOG.md +0 -183
- package/CLAUDE.md +0 -68
- package/apcore-logo.svg +0 -79
- package/planning/acl-system/overview.md +0 -54
- package/planning/acl-system/plan.md +0 -92
- package/planning/acl-system/state.json +0 -76
- package/planning/acl-system/tasks/acl-core.md +0 -226
- package/planning/acl-system/tasks/acl-rule.md +0 -92
- package/planning/acl-system/tasks/conditional-rules.md +0 -259
- package/planning/acl-system/tasks/pattern-matching.md +0 -152
- package/planning/acl-system/tasks/yaml-loading.md +0 -271
- package/planning/core-executor/overview.md +0 -53
- package/planning/core-executor/plan.md +0 -88
- package/planning/core-executor/state.json +0 -76
- package/planning/core-executor/tasks/async-support.md +0 -106
- package/planning/core-executor/tasks/execution-pipeline.md +0 -113
- package/planning/core-executor/tasks/redaction.md +0 -85
- package/planning/core-executor/tasks/safety-checks.md +0 -65
- package/planning/core-executor/tasks/setup.md +0 -75
- package/planning/decorator-bindings/overview.md +0 -62
- package/planning/decorator-bindings/plan.md +0 -104
- package/planning/decorator-bindings/state.json +0 -87
- package/planning/decorator-bindings/tasks/binding-directory.md +0 -79
- package/planning/decorator-bindings/tasks/binding-loader.md +0 -148
- package/planning/decorator-bindings/tasks/explicit-schemas.md +0 -85
- package/planning/decorator-bindings/tasks/function-module.md +0 -127
- package/planning/decorator-bindings/tasks/module-factory.md +0 -89
- package/planning/decorator-bindings/tasks/schema-modes.md +0 -142
- package/planning/middleware-system/overview.md +0 -48
- package/planning/middleware-system/plan.md +0 -102
- package/planning/middleware-system/state.json +0 -65
- package/planning/middleware-system/tasks/adapters.md +0 -170
- package/planning/middleware-system/tasks/base.md +0 -115
- package/planning/middleware-system/tasks/logging-middleware.md +0 -304
- package/planning/middleware-system/tasks/manager.md +0 -313
- package/planning/observability/overview.md +0 -53
- package/planning/observability/plan.md +0 -119
- package/planning/observability/state.json +0 -98
- package/planning/observability/tasks/context-logger.md +0 -201
- package/planning/observability/tasks/exporters.md +0 -121
- package/planning/observability/tasks/metrics-collector.md +0 -162
- package/planning/observability/tasks/metrics-middleware.md +0 -141
- package/planning/observability/tasks/obs-logging-middleware.md +0 -179
- package/planning/observability/tasks/span-model.md +0 -120
- package/planning/observability/tasks/tracing-middleware.md +0 -179
- package/planning/overview.md +0 -81
- package/planning/registry-system/overview.md +0 -57
- package/planning/registry-system/plan.md +0 -114
- package/planning/registry-system/state.json +0 -109
- package/planning/registry-system/tasks/dependencies.md +0 -157
- package/planning/registry-system/tasks/entry-point.md +0 -148
- package/planning/registry-system/tasks/metadata.md +0 -198
- package/planning/registry-system/tasks/registry-core.md +0 -323
- package/planning/registry-system/tasks/scanner.md +0 -172
- package/planning/registry-system/tasks/schema-export.md +0 -261
- package/planning/registry-system/tasks/types.md +0 -124
- package/planning/registry-system/tasks/validation.md +0 -177
- package/planning/schema-system/overview.md +0 -56
- package/planning/schema-system/plan.md +0 -121
- package/planning/schema-system/state.json +0 -98
- package/planning/schema-system/tasks/exporter.md +0 -153
- package/planning/schema-system/tasks/loader.md +0 -106
- package/planning/schema-system/tasks/ref-resolver.md +0 -133
- package/planning/schema-system/tasks/strict-mode.md +0 -140
- package/planning/schema-system/tasks/typebox-generation.md +0 -133
- package/planning/schema-system/tasks/types-and-annotations.md +0 -160
- package/planning/schema-system/tasks/validator.md +0 -149
- package/src/acl.ts +0 -200
- package/src/bindings.ts +0 -207
- package/src/config.ts +0 -24
- package/src/context.ts +0 -78
- package/src/decorator.ts +0 -110
- package/src/errors.ts +0 -425
- package/src/executor.ts +0 -475
- package/src/middleware/adapters.ts +0 -54
- package/src/middleware/base.ts +0 -33
- package/src/middleware/logging.ts +0 -103
- package/src/middleware/manager.ts +0 -105
- package/src/module.ts +0 -43
- package/src/observability/context-logger.ts +0 -203
- package/src/observability/metrics.ts +0 -214
- package/src/observability/tracing.ts +0 -188
- package/src/registry/dependencies.ts +0 -99
- package/src/registry/entry-point.ts +0 -64
- package/src/registry/metadata.ts +0 -111
- package/src/registry/registry.ts +0 -360
- package/src/registry/scanner.ts +0 -168
- package/src/registry/schema-export.ts +0 -181
- package/src/registry/types.ts +0 -32
- package/src/registry/validation.ts +0 -38
- package/src/schema/annotations.ts +0 -68
- package/src/schema/exporter.ts +0 -90
- package/src/schema/loader.ts +0 -273
- package/src/schema/ref-resolver.ts +0 -244
- package/src/schema/strict.ts +0 -136
- package/src/schema/types.ts +0 -73
- package/src/schema/validator.ts +0 -82
- package/src/utils/index.ts +0 -5
- package/src/utils/pattern.ts +0 -30
- package/tests/helpers.ts +0 -30
- package/tests/integration/test-acl-safety.test.ts +0 -269
- package/tests/integration/test-binding-executor.test.ts +0 -194
- package/tests/integration/test-e2e-flow.test.ts +0 -117
- package/tests/integration/test-error-propagation.test.ts +0 -259
- package/tests/integration/test-middleware-chain.test.ts +0 -120
- package/tests/integration/test-observability-integration.test.ts +0 -438
- package/tests/observability/test-context-logger.test.ts +0 -123
- package/tests/observability/test-metrics.test.ts +0 -186
- package/tests/observability/test-tracing.test.ts +0 -131
- package/tests/registry/test-dependencies.test.ts +0 -70
- package/tests/registry/test-entry-point.test.ts +0 -133
- package/tests/registry/test-metadata.test.ts +0 -265
- package/tests/registry/test-registry.test.ts +0 -1008
- package/tests/registry/test-scanner.test.ts +0 -257
- package/tests/registry/test-schema-export.test.ts +0 -355
- package/tests/registry/test-validation.test.ts +0 -75
- package/tests/schema/test-annotations.test.ts +0 -137
- package/tests/schema/test-exporter.test.ts +0 -172
- package/tests/schema/test-loader.test.ts +0 -461
- package/tests/schema/test-ref-resolver.test.ts +0 -530
- package/tests/schema/test-strict.test.ts +0 -348
- package/tests/schema/test-validator.test.ts +0 -64
- package/tests/test-acl.test.ts +0 -423
- package/tests/test-bindings.test.ts +0 -227
- package/tests/test-config.test.ts +0 -76
- package/tests/test-context.test.ts +0 -151
- package/tests/test-decorator.test.ts +0 -173
- package/tests/test-errors.test.ts +0 -647
- package/tests/test-executor-stream.test.ts +0 -208
- package/tests/test-executor.test.ts +0 -252
- package/tests/test-logging-middleware.test.ts +0 -150
- package/tests/test-middleware-manager.test.ts +0 -185
- package/tests/test-middleware.test.ts +0 -86
- package/tests/utils/test-pattern.test.ts +0 -109
- package/tsconfig.build.json +0 -8
- package/tsconfig.json +0 -20
- package/vitest.config.ts +0 -18
|
@@ -1,257 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
mkdtempSync,
|
|
4
|
-
mkdirSync,
|
|
5
|
-
writeFileSync,
|
|
6
|
-
rmSync,
|
|
7
|
-
chmodSync,
|
|
8
|
-
} from 'node:fs';
|
|
9
|
-
import { tmpdir } from 'node:os';
|
|
10
|
-
import { join, sep } from 'node:path';
|
|
11
|
-
import { scanExtensions, scanMultiRoot } from '../../src/registry/scanner.js';
|
|
12
|
-
import { ConfigNotFoundError, ConfigError } from '../../src/errors.js';
|
|
13
|
-
|
|
14
|
-
let tempDir: string;
|
|
15
|
-
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
tempDir = mkdtempSync(join(tmpdir(), 'scanner-test-'));
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
afterEach(() => {
|
|
21
|
-
rmSync(tempDir, { recursive: true, force: true });
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
function touch(relativePath: string, content = ''): string {
|
|
25
|
-
const full = join(tempDir, relativePath);
|
|
26
|
-
const dir = full.substring(0, full.lastIndexOf(sep));
|
|
27
|
-
mkdirSync(dir, { recursive: true });
|
|
28
|
-
writeFileSync(full, content);
|
|
29
|
-
return full;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
describe('scanExtensions', () => {
|
|
33
|
-
it('discovers .ts and .js files and returns correct DiscoveredModule shape', () => {
|
|
34
|
-
touch('alpha.ts');
|
|
35
|
-
touch('beta.js');
|
|
36
|
-
|
|
37
|
-
const results = scanExtensions(tempDir);
|
|
38
|
-
expect(results).toHaveLength(2);
|
|
39
|
-
const ids = results.map((r) => r.canonicalId).sort();
|
|
40
|
-
expect(ids).toEqual(['alpha', 'beta']);
|
|
41
|
-
|
|
42
|
-
for (const mod of results) {
|
|
43
|
-
expect(mod.filePath).toBeTruthy();
|
|
44
|
-
expect(mod.canonicalId).toBeTruthy();
|
|
45
|
-
expect(mod.metaPath).toBeNull();
|
|
46
|
-
expect(mod.namespace).toBeNull();
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('builds dot-notation canonicalId from nested paths', () => {
|
|
51
|
-
touch('sub/module.ts');
|
|
52
|
-
touch('deep/nested/handler.js');
|
|
53
|
-
|
|
54
|
-
const results = scanExtensions(tempDir);
|
|
55
|
-
const ids = results.map((r) => r.canonicalId).sort();
|
|
56
|
-
expect(ids).toEqual(['deep.nested.handler', 'sub.module']);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('skips .d.ts declaration files', () => {
|
|
60
|
-
touch('real.ts');
|
|
61
|
-
touch('types.d.ts');
|
|
62
|
-
|
|
63
|
-
const results = scanExtensions(tempDir);
|
|
64
|
-
expect(results).toHaveLength(1);
|
|
65
|
-
expect(results[0].canonicalId).toBe('real');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('skips .test.ts, .test.js, .spec.ts, and .spec.js files', () => {
|
|
69
|
-
touch('handler.ts');
|
|
70
|
-
touch('handler.test.ts');
|
|
71
|
-
touch('handler.test.js');
|
|
72
|
-
touch('handler.spec.ts');
|
|
73
|
-
touch('handler.spec.js');
|
|
74
|
-
|
|
75
|
-
const results = scanExtensions(tempDir);
|
|
76
|
-
expect(results).toHaveLength(1);
|
|
77
|
-
expect(results[0].canonicalId).toBe('handler');
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('skips dot-prefixed and underscore-prefixed entries', () => {
|
|
81
|
-
touch('.hidden/secret.ts');
|
|
82
|
-
touch('_private/internal.ts');
|
|
83
|
-
touch('.env.ts');
|
|
84
|
-
touch('_helper.ts');
|
|
85
|
-
touch('visible.ts');
|
|
86
|
-
|
|
87
|
-
const results = scanExtensions(tempDir);
|
|
88
|
-
expect(results).toHaveLength(1);
|
|
89
|
-
expect(results[0].canonicalId).toBe('visible');
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('skips node_modules and __pycache__ directories', () => {
|
|
93
|
-
touch('node_modules/pkg/index.ts');
|
|
94
|
-
touch('__pycache__/cached.ts');
|
|
95
|
-
touch('real.ts');
|
|
96
|
-
|
|
97
|
-
const results = scanExtensions(tempDir);
|
|
98
|
-
expect(results).toHaveLength(1);
|
|
99
|
-
expect(results[0].canonicalId).toBe('real');
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('ignores non-.ts/.js files', () => {
|
|
103
|
-
touch('readme.md');
|
|
104
|
-
touch('config.yaml');
|
|
105
|
-
touch('data.json');
|
|
106
|
-
touch('valid.ts');
|
|
107
|
-
|
|
108
|
-
const results = scanExtensions(tempDir);
|
|
109
|
-
expect(results).toHaveLength(1);
|
|
110
|
-
expect(results[0].canonicalId).toBe('valid');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('detects companion _meta.yaml files', () => {
|
|
114
|
-
touch('handler.ts');
|
|
115
|
-
touch('handler_meta.yaml', 'description: a handler');
|
|
116
|
-
|
|
117
|
-
const results = scanExtensions(tempDir);
|
|
118
|
-
expect(results).toHaveLength(1);
|
|
119
|
-
expect(results[0].metaPath).toBe(join(tempDir, 'handler_meta.yaml'));
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('sets metaPath to null when no companion _meta.yaml exists', () => {
|
|
123
|
-
touch('handler.ts');
|
|
124
|
-
touch('handler_meta.json', '{}');
|
|
125
|
-
|
|
126
|
-
const results = scanExtensions(tempDir);
|
|
127
|
-
expect(results).toHaveLength(1);
|
|
128
|
-
expect(results[0].metaPath).toBeNull();
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('respects maxDepth parameter', () => {
|
|
132
|
-
touch('level1.ts');
|
|
133
|
-
touch('a/level2.ts');
|
|
134
|
-
touch('a/b/level3.ts');
|
|
135
|
-
|
|
136
|
-
const resultsDepth1 = scanExtensions(tempDir, 1);
|
|
137
|
-
expect(resultsDepth1.map((r) => r.canonicalId).sort()).toEqual(['level1']);
|
|
138
|
-
|
|
139
|
-
const resultsDepth2 = scanExtensions(tempDir, 2);
|
|
140
|
-
expect(resultsDepth2.map((r) => r.canonicalId).sort()).toEqual(['a.level2', 'level1']);
|
|
141
|
-
|
|
142
|
-
const resultsAll = scanExtensions(tempDir, 8);
|
|
143
|
-
expect(resultsAll.map((r) => r.canonicalId).sort()).toEqual(['a.b.level3', 'a.level2', 'level1']);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('throws ConfigNotFoundError for non-existent root directory', () => {
|
|
147
|
-
const bogus = join(tempDir, 'does-not-exist');
|
|
148
|
-
expect(() => scanExtensions(bogus)).toThrow(ConfigNotFoundError);
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('deduplicates by canonicalId (first file wins)', () => {
|
|
152
|
-
touch('handler.ts');
|
|
153
|
-
touch('handler.js');
|
|
154
|
-
|
|
155
|
-
const results = scanExtensions(tempDir);
|
|
156
|
-
expect(results).toHaveLength(1);
|
|
157
|
-
expect(results[0].canonicalId).toBe('handler');
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('handles deeply nested structures correctly', () => {
|
|
161
|
-
touch('a/b/c/d/e/module.ts');
|
|
162
|
-
|
|
163
|
-
const results = scanExtensions(tempDir);
|
|
164
|
-
expect(results).toHaveLength(1);
|
|
165
|
-
expect(results[0].canonicalId).toBe('a.b.c.d.e.module');
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('returns empty array for an empty directory', () => {
|
|
169
|
-
const results = scanExtensions(tempDir);
|
|
170
|
-
expect(results).toEqual([]);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it('filePath is an absolute path to the discovered file', () => {
|
|
174
|
-
touch('mod.ts');
|
|
175
|
-
|
|
176
|
-
const results = scanExtensions(tempDir);
|
|
177
|
-
expect(results).toHaveLength(1);
|
|
178
|
-
expect(results[0].filePath).toBe(join(tempDir, 'mod.ts'));
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
describe('scanMultiRoot', () => {
|
|
183
|
-
it('prefixes canonicalId with namespace', () => {
|
|
184
|
-
const rootA = join(tempDir, 'rootA');
|
|
185
|
-
mkdirSync(rootA);
|
|
186
|
-
writeFileSync(join(rootA, 'handler.ts'), '');
|
|
187
|
-
|
|
188
|
-
const results = scanMultiRoot([{ root: rootA, namespace: 'ns1' }]);
|
|
189
|
-
expect(results).toHaveLength(1);
|
|
190
|
-
expect(results[0].canonicalId).toBe('ns1.handler');
|
|
191
|
-
expect(results[0].namespace).toBe('ns1');
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('auto-uses directory basename as namespace when not specified', () => {
|
|
195
|
-
const rootDir = join(tempDir, 'myextensions');
|
|
196
|
-
mkdirSync(rootDir);
|
|
197
|
-
writeFileSync(join(rootDir, 'action.ts'), '');
|
|
198
|
-
|
|
199
|
-
const results = scanMultiRoot([{ root: rootDir }]);
|
|
200
|
-
expect(results).toHaveLength(1);
|
|
201
|
-
expect(results[0].canonicalId).toBe('myextensions.action');
|
|
202
|
-
expect(results[0].namespace).toBe('myextensions');
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it('throws ConfigError for duplicate namespaces', () => {
|
|
206
|
-
const rootA = join(tempDir, 'a');
|
|
207
|
-
const rootB = join(tempDir, 'b');
|
|
208
|
-
mkdirSync(rootA);
|
|
209
|
-
mkdirSync(rootB);
|
|
210
|
-
|
|
211
|
-
expect(() =>
|
|
212
|
-
scanMultiRoot([
|
|
213
|
-
{ root: rootA, namespace: 'dup' },
|
|
214
|
-
{ root: rootB, namespace: 'dup' },
|
|
215
|
-
]),
|
|
216
|
-
).toThrow(ConfigError);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it('merges results from multiple roots', () => {
|
|
220
|
-
const rootA = join(tempDir, 'rootA');
|
|
221
|
-
const rootB = join(tempDir, 'rootB');
|
|
222
|
-
mkdirSync(rootA);
|
|
223
|
-
mkdirSync(rootB);
|
|
224
|
-
writeFileSync(join(rootA, 'foo.ts'), '');
|
|
225
|
-
writeFileSync(join(rootB, 'bar.ts'), '');
|
|
226
|
-
|
|
227
|
-
const results = scanMultiRoot([
|
|
228
|
-
{ root: rootA, namespace: 'a' },
|
|
229
|
-
{ root: rootB, namespace: 'b' },
|
|
230
|
-
]);
|
|
231
|
-
expect(results).toHaveLength(2);
|
|
232
|
-
const ids = results.map((r) => r.canonicalId).sort();
|
|
233
|
-
expect(ids).toEqual(['a.foo', 'b.bar']);
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
it('propagates ConfigNotFoundError for non-existent root', () => {
|
|
237
|
-
const bogus = join(tempDir, 'nonexistent');
|
|
238
|
-
expect(() => scanMultiRoot([{ root: bogus, namespace: 'ns' }])).toThrow(ConfigNotFoundError);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it('handles empty roots array', () => {
|
|
242
|
-
const results = scanMultiRoot([]);
|
|
243
|
-
expect(results).toEqual([]);
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it('preserves metaPath through multi-root scan', () => {
|
|
247
|
-
const rootDir = join(tempDir, 'ext');
|
|
248
|
-
mkdirSync(rootDir);
|
|
249
|
-
writeFileSync(join(rootDir, 'mod.ts'), '');
|
|
250
|
-
writeFileSync(join(rootDir, 'mod_meta.yaml'), 'description: test');
|
|
251
|
-
|
|
252
|
-
const results = scanMultiRoot([{ root: rootDir, namespace: 'pkg' }]);
|
|
253
|
-
expect(results).toHaveLength(1);
|
|
254
|
-
expect(results[0].metaPath).toBe(join(rootDir, 'mod_meta.yaml'));
|
|
255
|
-
expect(results[0].canonicalId).toBe('pkg.mod');
|
|
256
|
-
});
|
|
257
|
-
});
|
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { Type } from '@sinclair/typebox';
|
|
3
|
-
import { Registry } from '../../src/registry/registry.js';
|
|
4
|
-
import { FunctionModule } from '../../src/decorator.js';
|
|
5
|
-
import { InvalidInputError, ModuleNotFoundError } from '../../src/errors.js';
|
|
6
|
-
import {
|
|
7
|
-
getSchema,
|
|
8
|
-
exportSchema,
|
|
9
|
-
getAllSchemas,
|
|
10
|
-
exportAllSchemas,
|
|
11
|
-
} from '../../src/registry/schema-export.js';
|
|
12
|
-
|
|
13
|
-
const inputSchema = Type.Object({
|
|
14
|
-
prompt: Type.String({ description: 'The input prompt' }),
|
|
15
|
-
temperature: Type.Optional(Type.Number({ description: 'Sampling temperature' })),
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
const outputSchema = Type.Object({
|
|
19
|
-
text: Type.String(),
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
function createModule(
|
|
23
|
-
id: string,
|
|
24
|
-
overrides?: Partial<ConstructorParameters<typeof FunctionModule>[0]>,
|
|
25
|
-
): FunctionModule {
|
|
26
|
-
return new FunctionModule({
|
|
27
|
-
execute: () => ({ text: 'hello' }),
|
|
28
|
-
moduleId: id,
|
|
29
|
-
inputSchema,
|
|
30
|
-
outputSchema,
|
|
31
|
-
description: 'A test module. It does many things.\nSecond paragraph.',
|
|
32
|
-
tags: ['ai', 'test'],
|
|
33
|
-
version: '2.0.0',
|
|
34
|
-
annotations: {
|
|
35
|
-
readonly: true,
|
|
36
|
-
destructive: false,
|
|
37
|
-
idempotent: true,
|
|
38
|
-
requiresApproval: false,
|
|
39
|
-
openWorld: false,
|
|
40
|
-
streaming: false,
|
|
41
|
-
},
|
|
42
|
-
examples: [
|
|
43
|
-
{
|
|
44
|
-
title: 'Basic example',
|
|
45
|
-
inputs: { prompt: 'hi' },
|
|
46
|
-
output: { text: 'hello' },
|
|
47
|
-
description: 'Simple greeting',
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
...overrides,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function makeRegistry(...modules: Array<[string, FunctionModule]>): Registry {
|
|
55
|
-
const registry = new Registry();
|
|
56
|
-
for (const [id, mod] of modules) {
|
|
57
|
-
registry.register(id, mod);
|
|
58
|
-
}
|
|
59
|
-
return registry;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
describe('getSchema', () => {
|
|
63
|
-
it('returns null for unregistered module', () => {
|
|
64
|
-
const registry = new Registry();
|
|
65
|
-
expect(getSchema(registry, 'no.such.module')).toBeNull();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('returns schema record with all expected fields', () => {
|
|
69
|
-
const mod = createModule('test.gen');
|
|
70
|
-
const registry = makeRegistry(['test.gen', mod]);
|
|
71
|
-
|
|
72
|
-
const schema = getSchema(registry, 'test.gen');
|
|
73
|
-
expect(schema).not.toBeNull();
|
|
74
|
-
expect(schema!['module_id']).toBe('test.gen');
|
|
75
|
-
expect(schema!['description']).toBe('A test module. It does many things.\nSecond paragraph.');
|
|
76
|
-
expect(schema!['version']).toBe('2.0.0');
|
|
77
|
-
expect(schema!['tags']).toEqual(['ai', 'test']);
|
|
78
|
-
expect(schema!['input_schema']).toBeDefined();
|
|
79
|
-
expect(schema!['output_schema']).toBeDefined();
|
|
80
|
-
expect(schema!['examples']).toHaveLength(1);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('copies tags array to prevent mutation', () => {
|
|
84
|
-
const mod = createModule('test.tags');
|
|
85
|
-
const registry = makeRegistry(['test.tags', mod]);
|
|
86
|
-
|
|
87
|
-
const schema = getSchema(registry, 'test.tags');
|
|
88
|
-
const tags = schema!['tags'] as string[];
|
|
89
|
-
tags.push('injected');
|
|
90
|
-
|
|
91
|
-
expect(mod.tags).toEqual(['ai', 'test']);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('returns empty array for tags when module has null tags', () => {
|
|
95
|
-
const mod = createModule('test.notags', { tags: null });
|
|
96
|
-
const registry = makeRegistry(['test.notags', mod]);
|
|
97
|
-
const schema = getSchema(registry, 'test.notags');
|
|
98
|
-
expect(schema!['tags']).toEqual([]);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('returns null annotations when module has no annotations', () => {
|
|
102
|
-
const mod = createModule('test.noanno', { annotations: null });
|
|
103
|
-
const registry = makeRegistry(['test.noanno', mod]);
|
|
104
|
-
const schema = getSchema(registry, 'test.noanno');
|
|
105
|
-
expect(schema!['annotations']).toBeNull();
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
describe('exportSchema', () => {
|
|
110
|
-
it('returns JSON string by default', () => {
|
|
111
|
-
const mod = createModule('test.json');
|
|
112
|
-
const registry = makeRegistry(['test.json', mod]);
|
|
113
|
-
|
|
114
|
-
const result = exportSchema(registry, 'test.json');
|
|
115
|
-
const parsed = JSON.parse(result);
|
|
116
|
-
expect(parsed['module_id']).toBe('test.json');
|
|
117
|
-
expect(parsed['version']).toBe('2.0.0');
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('returns YAML string when format is yaml', () => {
|
|
121
|
-
const mod = createModule('test.yaml');
|
|
122
|
-
const registry = makeRegistry(['test.yaml', mod]);
|
|
123
|
-
|
|
124
|
-
const result = exportSchema(registry, 'test.yaml', 'yaml');
|
|
125
|
-
expect(result).toContain('module_id:');
|
|
126
|
-
expect(result).toContain('test.yaml');
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('throws ModuleNotFoundError for unregistered module', () => {
|
|
130
|
-
const registry = new Registry();
|
|
131
|
-
expect(() => exportSchema(registry, 'no.such.module')).toThrow(ModuleNotFoundError);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
it('applies strict mode to input and output schemas', () => {
|
|
135
|
-
const mod = createModule('test.strict');
|
|
136
|
-
const registry = makeRegistry(['test.strict', mod]);
|
|
137
|
-
|
|
138
|
-
const result = exportSchema(registry, 'test.strict', 'json', true);
|
|
139
|
-
const parsed = JSON.parse(result);
|
|
140
|
-
expect((parsed['input_schema'] as Record<string, unknown>)['additionalProperties']).toBe(false);
|
|
141
|
-
expect((parsed['output_schema'] as Record<string, unknown>)['additionalProperties']).toBe(false);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('compact mode truncates description at first sentence boundary', () => {
|
|
145
|
-
const mod = createModule('test.compact');
|
|
146
|
-
const registry = makeRegistry(['test.compact', mod]);
|
|
147
|
-
|
|
148
|
-
const result = exportSchema(registry, 'test.compact', 'json', false, true);
|
|
149
|
-
const parsed = JSON.parse(result);
|
|
150
|
-
expect(parsed['description']).toBe('A test module.');
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('compact mode removes examples and documentation', () => {
|
|
154
|
-
const mod = createModule('test.compact.ex', { documentation: 'Full docs' });
|
|
155
|
-
const registry = makeRegistry(['test.compact.ex', mod]);
|
|
156
|
-
|
|
157
|
-
const result = exportSchema(registry, 'test.compact.ex', 'json', false, true);
|
|
158
|
-
const parsed = JSON.parse(result);
|
|
159
|
-
expect(parsed['examples']).toBeUndefined();
|
|
160
|
-
expect(parsed['documentation']).toBeUndefined();
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it('strict takes precedence over compact when both are true', () => {
|
|
164
|
-
const mod = createModule('test.both');
|
|
165
|
-
const registry = makeRegistry(['test.both', mod]);
|
|
166
|
-
|
|
167
|
-
const result = exportSchema(registry, 'test.both', 'json', true, true);
|
|
168
|
-
const parsed = JSON.parse(result);
|
|
169
|
-
expect((parsed['input_schema'] as Record<string, unknown>)['additionalProperties']).toBe(false);
|
|
170
|
-
expect(parsed['description']).toBe('A test module. It does many things.\nSecond paragraph.');
|
|
171
|
-
expect(parsed['examples']).toBeDefined();
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
describe('getAllSchemas', () => {
|
|
176
|
-
it('returns empty object for empty registry', () => {
|
|
177
|
-
const registry = new Registry();
|
|
178
|
-
expect(getAllSchemas(registry)).toEqual({});
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('returns all module schemas keyed by module id', () => {
|
|
182
|
-
const modA = createModule('alpha');
|
|
183
|
-
const modB = createModule('beta', { version: '3.0.0' });
|
|
184
|
-
const registry = makeRegistry(['alpha', modA], ['beta', modB]);
|
|
185
|
-
|
|
186
|
-
const result = getAllSchemas(registry);
|
|
187
|
-
expect(Object.keys(result).sort()).toEqual(['alpha', 'beta']);
|
|
188
|
-
expect(result['alpha']['module_id']).toBe('alpha');
|
|
189
|
-
expect(result['beta']['version']).toBe('3.0.0');
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
describe('exportAllSchemas', () => {
|
|
194
|
-
it('serializes all schemas to JSON', () => {
|
|
195
|
-
const modA = createModule('a.mod');
|
|
196
|
-
const modB = createModule('b.mod');
|
|
197
|
-
const registry = makeRegistry(['a.mod', modA], ['b.mod', modB]);
|
|
198
|
-
|
|
199
|
-
const result = exportAllSchemas(registry);
|
|
200
|
-
const parsed = JSON.parse(result);
|
|
201
|
-
expect(Object.keys(parsed).sort()).toEqual(['a.mod', 'b.mod']);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('supports YAML format', () => {
|
|
205
|
-
const mod = createModule('yaml.mod');
|
|
206
|
-
const registry = makeRegistry(['yaml.mod', mod]);
|
|
207
|
-
|
|
208
|
-
const result = exportAllSchemas(registry, 'yaml');
|
|
209
|
-
expect(result).toContain('yaml.mod');
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it('applies strict mode to all schemas', () => {
|
|
213
|
-
const modA = createModule('strict.a');
|
|
214
|
-
const registry = makeRegistry(['strict.a', modA]);
|
|
215
|
-
|
|
216
|
-
const result = exportAllSchemas(registry, 'json', true);
|
|
217
|
-
const parsed = JSON.parse(result);
|
|
218
|
-
expect((parsed['strict.a']['input_schema'] as Record<string, unknown>)['additionalProperties']).toBe(false);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it('applies compact mode to all schemas', () => {
|
|
222
|
-
const mod = createModule('compact.all');
|
|
223
|
-
const registry = makeRegistry(['compact.all', mod]);
|
|
224
|
-
|
|
225
|
-
const result = exportAllSchemas(registry, 'json', false, true);
|
|
226
|
-
const parsed = JSON.parse(result);
|
|
227
|
-
expect(parsed['compact.all']['description']).toBe('A test module.');
|
|
228
|
-
expect(parsed['compact.all']['examples']).toBeUndefined();
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it('returns empty JSON object for empty registry', () => {
|
|
232
|
-
const registry = new Registry();
|
|
233
|
-
expect(JSON.parse(exportAllSchemas(registry))).toEqual({});
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
describe('exportSchema with profile', () => {
|
|
238
|
-
it('exports with mcp profile and returns valid JSON with MCP shape', () => {
|
|
239
|
-
const mod = createModule('mcp.mod');
|
|
240
|
-
const registry = makeRegistry(['mcp.mod', mod]);
|
|
241
|
-
|
|
242
|
-
const result = exportSchema(registry, 'mcp.mod', 'json', false, false, 'mcp');
|
|
243
|
-
const parsed = JSON.parse(result);
|
|
244
|
-
expect(parsed['name']).toBeDefined();
|
|
245
|
-
expect(parsed['description']).toBeDefined();
|
|
246
|
-
expect(parsed['inputSchema']).toBeDefined();
|
|
247
|
-
expect(parsed['annotations']).toBeDefined();
|
|
248
|
-
expect(parsed['annotations']['readOnlyHint']).toBe(true);
|
|
249
|
-
expect(parsed['annotations']['destructiveHint']).toBe(false);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it('exports with openai profile and returns function tool shape', () => {
|
|
253
|
-
const mod = createModule('openai.mod');
|
|
254
|
-
const registry = makeRegistry(['openai.mod', mod]);
|
|
255
|
-
|
|
256
|
-
const result = exportSchema(registry, 'openai.mod', 'json', false, false, 'openai');
|
|
257
|
-
const parsed = JSON.parse(result);
|
|
258
|
-
expect(parsed['type']).toBe('function');
|
|
259
|
-
expect(parsed['function']).toBeDefined();
|
|
260
|
-
expect(parsed['function']['name']).toBe('openai_mod');
|
|
261
|
-
expect(parsed['function']['description']).toBeDefined();
|
|
262
|
-
expect(parsed['function']['parameters']).toBeDefined();
|
|
263
|
-
expect(parsed['function']['strict']).toBe(true);
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it('exports with anthropic profile and returns tool shape with input_examples', () => {
|
|
267
|
-
const mod = createModule('anthro.mod');
|
|
268
|
-
const registry = makeRegistry(['anthro.mod', mod]);
|
|
269
|
-
|
|
270
|
-
const result = exportSchema(registry, 'anthro.mod', 'json', false, false, 'anthropic');
|
|
271
|
-
const parsed = JSON.parse(result);
|
|
272
|
-
expect(parsed['name']).toBe('anthro_mod');
|
|
273
|
-
expect(parsed['description']).toBeDefined();
|
|
274
|
-
expect(parsed['input_schema']).toBeDefined();
|
|
275
|
-
expect(parsed['input_examples']).toBeDefined();
|
|
276
|
-
expect((parsed['input_examples'] as unknown[]).length).toBe(1);
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it('exports with generic profile and returns module_id and schema fields', () => {
|
|
280
|
-
const mod = createModule('generic.mod');
|
|
281
|
-
const registry = makeRegistry(['generic.mod', mod]);
|
|
282
|
-
|
|
283
|
-
const result = exportSchema(registry, 'generic.mod', 'json', false, false, 'generic');
|
|
284
|
-
const parsed = JSON.parse(result);
|
|
285
|
-
expect(parsed['module_id']).toBe('generic.mod');
|
|
286
|
-
expect(parsed['description']).toBeDefined();
|
|
287
|
-
expect(parsed['input_schema']).toBeDefined();
|
|
288
|
-
expect(parsed['output_schema']).toBeDefined();
|
|
289
|
-
expect(parsed['definitions']).toBeDefined();
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
it('exports with profile using yaml format', () => {
|
|
293
|
-
const mod = createModule('mcp.yaml');
|
|
294
|
-
const registry = makeRegistry(['mcp.yaml', mod]);
|
|
295
|
-
|
|
296
|
-
const result = exportSchema(registry, 'mcp.yaml', 'yaml', false, false, 'mcp');
|
|
297
|
-
expect(result).toContain('name:');
|
|
298
|
-
expect(result).toContain('inputSchema:');
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
it('throws InvalidInputError for an unrecognized profile name', () => {
|
|
302
|
-
const mod = createModule('bad.profile');
|
|
303
|
-
const registry = makeRegistry(['bad.profile', mod]);
|
|
304
|
-
|
|
305
|
-
expect(() =>
|
|
306
|
-
exportSchema(registry, 'bad.profile', 'json', false, false, 'not_a_real_profile'),
|
|
307
|
-
).toThrow(InvalidInputError);
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
it('includes the invalid profile name in the error message', () => {
|
|
311
|
-
const mod = createModule('err.profile');
|
|
312
|
-
const registry = makeRegistry(['err.profile', mod]);
|
|
313
|
-
|
|
314
|
-
expect(() =>
|
|
315
|
-
exportSchema(registry, 'err.profile', 'json', false, false, 'bogus'),
|
|
316
|
-
).toThrowError(/bogus/);
|
|
317
|
-
});
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
describe('truncateDescription edge cases', () => {
|
|
321
|
-
it('returns the full string when there is no dot-space or newline', () => {
|
|
322
|
-
const mod = createModule('no.boundary', {
|
|
323
|
-
description: 'A simple description with no sentence boundary',
|
|
324
|
-
});
|
|
325
|
-
const registry = makeRegistry(['no.boundary', mod]);
|
|
326
|
-
|
|
327
|
-
const result = exportSchema(registry, 'no.boundary', 'json', false, true);
|
|
328
|
-
const parsed = JSON.parse(result);
|
|
329
|
-
expect(parsed['description']).toBe('A simple description with no sentence boundary');
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
it('truncates at the earlier boundary when both dot-space and newline are present', () => {
|
|
333
|
-
// newline comes before dot-space: "Line one\nSecond sentence. More text."
|
|
334
|
-
const mod = createModule('newline.first', {
|
|
335
|
-
description: 'Line one\nSecond sentence. More text.',
|
|
336
|
-
});
|
|
337
|
-
const registry = makeRegistry(['newline.first', mod]);
|
|
338
|
-
|
|
339
|
-
const result = exportSchema(registry, 'newline.first', 'json', false, true);
|
|
340
|
-
const parsed = JSON.parse(result);
|
|
341
|
-
expect(parsed['description']).toBe('Line one');
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
it('truncates at dot-space when it comes before a newline', () => {
|
|
345
|
-
// dot-space before newline: "First sentence. Second line\nThird."
|
|
346
|
-
const mod = createModule('dotspace.first', {
|
|
347
|
-
description: 'First sentence. Second line\nThird.',
|
|
348
|
-
});
|
|
349
|
-
const registry = makeRegistry(['dotspace.first', mod]);
|
|
350
|
-
|
|
351
|
-
const result = exportSchema(registry, 'dotspace.first', 'json', false, true);
|
|
352
|
-
const parsed = JSON.parse(result);
|
|
353
|
-
expect(parsed['description']).toBe('First sentence.');
|
|
354
|
-
});
|
|
355
|
-
});
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { Type } from '@sinclair/typebox';
|
|
3
|
-
import { validateModule } from '../../src/registry/validation.js';
|
|
4
|
-
|
|
5
|
-
describe('validateModule', () => {
|
|
6
|
-
it('valid module returns no errors', () => {
|
|
7
|
-
const mod = {
|
|
8
|
-
inputSchema: Type.Object({}),
|
|
9
|
-
outputSchema: Type.Object({}),
|
|
10
|
-
description: 'A test module',
|
|
11
|
-
execute: () => ({}),
|
|
12
|
-
};
|
|
13
|
-
expect(validateModule(mod)).toEqual([]);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('missing inputSchema reports error', () => {
|
|
17
|
-
const mod = {
|
|
18
|
-
outputSchema: Type.Object({}),
|
|
19
|
-
description: 'test',
|
|
20
|
-
execute: () => ({}),
|
|
21
|
-
};
|
|
22
|
-
const errors = validateModule(mod);
|
|
23
|
-
expect(errors.length).toBeGreaterThan(0);
|
|
24
|
-
expect(errors.some(e => e.includes('inputSchema'))).toBe(true);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('missing outputSchema reports error', () => {
|
|
28
|
-
const mod = {
|
|
29
|
-
inputSchema: Type.Object({}),
|
|
30
|
-
description: 'test',
|
|
31
|
-
execute: () => ({}),
|
|
32
|
-
};
|
|
33
|
-
const errors = validateModule(mod);
|
|
34
|
-
expect(errors.length).toBeGreaterThan(0);
|
|
35
|
-
expect(errors.some(e => e.includes('outputSchema'))).toBe(true);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('missing description reports error', () => {
|
|
39
|
-
const mod = {
|
|
40
|
-
inputSchema: Type.Object({}),
|
|
41
|
-
outputSchema: Type.Object({}),
|
|
42
|
-
execute: () => ({}),
|
|
43
|
-
};
|
|
44
|
-
const errors = validateModule(mod);
|
|
45
|
-
expect(errors.length).toBeGreaterThan(0);
|
|
46
|
-
expect(errors.some(e => e.includes('description'))).toBe(true);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('missing execute reports error', () => {
|
|
50
|
-
const mod = {
|
|
51
|
-
inputSchema: Type.Object({}),
|
|
52
|
-
outputSchema: Type.Object({}),
|
|
53
|
-
description: 'test',
|
|
54
|
-
};
|
|
55
|
-
const errors = validateModule(mod);
|
|
56
|
-
expect(errors.length).toBeGreaterThan(0);
|
|
57
|
-
expect(errors.some(e => e.includes('execute'))).toBe(true);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('completely empty object reports multiple errors', () => {
|
|
61
|
-
const errors = validateModule({});
|
|
62
|
-
expect(errors.length).toBe(4);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('non-function execute reports error', () => {
|
|
66
|
-
const mod = {
|
|
67
|
-
inputSchema: Type.Object({}),
|
|
68
|
-
outputSchema: Type.Object({}),
|
|
69
|
-
description: 'test',
|
|
70
|
-
execute: 'not-a-function',
|
|
71
|
-
};
|
|
72
|
-
const errors = validateModule(mod);
|
|
73
|
-
expect(errors.some(e => e.includes('execute'))).toBe(true);
|
|
74
|
-
});
|
|
75
|
-
});
|