apcore-js 0.5.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} +3 -62
- 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} +1 -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 -214
- 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/async-task.ts +0 -267
- package/src/bindings.ts +0 -207
- package/src/cancel.ts +0 -32
- package/src/config.ts +0 -24
- package/src/context.ts +0 -160
- package/src/decorator.ts +0 -110
- package/src/errors.ts +0 -429
- package/src/executor.ts +0 -493
- package/src/extensions.ts +0 -265
- 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 -252
- 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 -580
- 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/trace-context.ts +0 -102
- package/src/utils/index.ts +0 -5
- package/src/utils/pattern.ts +0 -30
- package/tests/async-task.test.ts +0 -335
- 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 -303
- 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 -1397
- 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-cancel.test.ts +0 -71
- package/tests/test-config.test.ts +0 -76
- package/tests/test-context.test.ts +0 -266
- 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-extensions.test.ts +0 -310
- 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/test-trace-context.test.ts +0 -251
- 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,137 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for schema/annotations.ts — annotation conflict resolution.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, it, expect } from 'vitest';
|
|
6
|
-
import { mergeAnnotations, mergeExamples, mergeMetadata } from '../../src/schema/annotations.js';
|
|
7
|
-
import { DEFAULT_ANNOTATIONS } from '../../src/module.js';
|
|
8
|
-
import type { ModuleAnnotations, ModuleExample } from '../../src/module.js';
|
|
9
|
-
|
|
10
|
-
describe('mergeAnnotations', () => {
|
|
11
|
-
it('returns defaults when both inputs are null', () => {
|
|
12
|
-
const result = mergeAnnotations(null, null);
|
|
13
|
-
expect(result).toEqual(DEFAULT_ANNOTATIONS);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('returns defaults when both inputs are undefined', () => {
|
|
17
|
-
const result = mergeAnnotations(undefined, undefined);
|
|
18
|
-
expect(result).toEqual(DEFAULT_ANNOTATIONS);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('applies code annotations over defaults', () => {
|
|
22
|
-
const codeAnnotations: ModuleAnnotations = {
|
|
23
|
-
readonly: true,
|
|
24
|
-
destructive: false,
|
|
25
|
-
idempotent: true,
|
|
26
|
-
requiresApproval: false,
|
|
27
|
-
openWorld: false,
|
|
28
|
-
streaming: false,
|
|
29
|
-
};
|
|
30
|
-
const result = mergeAnnotations(null, codeAnnotations);
|
|
31
|
-
expect(result.readonly).toBe(true);
|
|
32
|
-
expect(result.idempotent).toBe(true);
|
|
33
|
-
expect(result.openWorld).toBe(false);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('yaml annotations override code annotations', () => {
|
|
37
|
-
const codeAnnotations: ModuleAnnotations = {
|
|
38
|
-
readonly: true,
|
|
39
|
-
destructive: false,
|
|
40
|
-
idempotent: false,
|
|
41
|
-
requiresApproval: false,
|
|
42
|
-
openWorld: true,
|
|
43
|
-
streaming: false,
|
|
44
|
-
};
|
|
45
|
-
const yamlAnnotations = { readonly: false, destructive: true };
|
|
46
|
-
const result = mergeAnnotations(yamlAnnotations, codeAnnotations);
|
|
47
|
-
expect(result.readonly).toBe(false);
|
|
48
|
-
expect(result.destructive).toBe(true);
|
|
49
|
-
expect(result.idempotent).toBe(false);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('ignores unknown yaml keys', () => {
|
|
53
|
-
const yamlAnnotations = { unknownKey: 'value', readonly: true };
|
|
54
|
-
const result = mergeAnnotations(yamlAnnotations, null);
|
|
55
|
-
expect(result.readonly).toBe(true);
|
|
56
|
-
expect((result as unknown as Record<string, unknown>)['unknownKey']).toBeUndefined();
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
describe('mergeExamples', () => {
|
|
61
|
-
it('returns empty array when both inputs are null', () => {
|
|
62
|
-
expect(mergeExamples(null, null)).toEqual([]);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('returns empty array when both inputs are undefined', () => {
|
|
66
|
-
expect(mergeExamples(undefined, undefined)).toEqual([]);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('returns yaml examples when present', () => {
|
|
70
|
-
const yamlExamples = [
|
|
71
|
-
{ title: 'Test', inputs: { a: 1 }, output: { b: 2 }, description: 'desc' },
|
|
72
|
-
];
|
|
73
|
-
const result = mergeExamples(yamlExamples, null);
|
|
74
|
-
expect(result).toHaveLength(1);
|
|
75
|
-
expect(result[0].title).toBe('Test');
|
|
76
|
-
expect(result[0].inputs).toEqual({ a: 1 });
|
|
77
|
-
expect(result[0].output).toEqual({ b: 2 });
|
|
78
|
-
expect(result[0].description).toBe('desc');
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('uses code examples when yaml is null', () => {
|
|
82
|
-
const codeExamples: ModuleExample[] = [
|
|
83
|
-
{ title: 'Code', inputs: { x: 1 }, output: { y: 2 } },
|
|
84
|
-
];
|
|
85
|
-
const result = mergeExamples(null, codeExamples);
|
|
86
|
-
expect(result).toEqual(codeExamples);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('yaml examples take precedence over code examples', () => {
|
|
90
|
-
const yamlExamples = [{ title: 'YAML', inputs: {}, output: {} }];
|
|
91
|
-
const codeExamples: ModuleExample[] = [
|
|
92
|
-
{ title: 'Code', inputs: {}, output: {} },
|
|
93
|
-
];
|
|
94
|
-
const result = mergeExamples(yamlExamples, codeExamples);
|
|
95
|
-
expect(result).toHaveLength(1);
|
|
96
|
-
expect(result[0].title).toBe('YAML');
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('handles yaml examples with missing optional fields', () => {
|
|
100
|
-
const yamlExamples = [{ title: 'Minimal' }];
|
|
101
|
-
const result = mergeExamples(yamlExamples as Array<Record<string, unknown>>, null);
|
|
102
|
-
expect(result[0].inputs).toEqual({});
|
|
103
|
-
expect(result[0].output).toEqual({});
|
|
104
|
-
expect(result[0].description).toBeUndefined();
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
describe('mergeMetadata', () => {
|
|
109
|
-
it('returns empty object when both inputs are null', () => {
|
|
110
|
-
expect(mergeMetadata(null, null)).toEqual({});
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('returns code metadata when yaml is null', () => {
|
|
114
|
-
const code = { key: 'value' };
|
|
115
|
-
expect(mergeMetadata(null, code)).toEqual({ key: 'value' });
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('returns yaml metadata when code is null', () => {
|
|
119
|
-
const yaml = { key: 'value' };
|
|
120
|
-
expect(mergeMetadata(yaml, null)).toEqual({ key: 'value' });
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('yaml overrides code on conflicting keys', () => {
|
|
124
|
-
const code = { a: 1, b: 2 };
|
|
125
|
-
const yaml = { b: 3, c: 4 };
|
|
126
|
-
const result = mergeMetadata(yaml, code);
|
|
127
|
-
expect(result).toEqual({ a: 1, b: 3, c: 4 });
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('does not mutate input objects', () => {
|
|
131
|
-
const code = { a: 1 };
|
|
132
|
-
const yaml = { b: 2 };
|
|
133
|
-
mergeMetadata(yaml, code);
|
|
134
|
-
expect(code).toEqual({ a: 1 });
|
|
135
|
-
expect(yaml).toEqual({ b: 2 });
|
|
136
|
-
});
|
|
137
|
-
});
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for schema/exporter.ts — SchemaExporter profile exports.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { describe, it, expect } from 'vitest';
|
|
6
|
-
import { SchemaExporter } from '../../src/schema/exporter.js';
|
|
7
|
-
import { ExportProfile } from '../../src/schema/types.js';
|
|
8
|
-
import type { SchemaDefinition } from '../../src/schema/types.js';
|
|
9
|
-
import type { ModuleAnnotations, ModuleExample } from '../../src/module.js';
|
|
10
|
-
|
|
11
|
-
function makeSchemaDef(overrides?: Partial<SchemaDefinition>): SchemaDefinition {
|
|
12
|
-
return {
|
|
13
|
-
moduleId: 'test.module',
|
|
14
|
-
description: 'A test module',
|
|
15
|
-
inputSchema: {
|
|
16
|
-
type: 'object',
|
|
17
|
-
properties: {
|
|
18
|
-
name: { type: 'string', description: 'Name', 'x-llm-description': 'LLM Name' },
|
|
19
|
-
},
|
|
20
|
-
required: ['name'],
|
|
21
|
-
},
|
|
22
|
-
outputSchema: {
|
|
23
|
-
type: 'object',
|
|
24
|
-
properties: {
|
|
25
|
-
result: { type: 'string' },
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
definitions: {},
|
|
29
|
-
version: '1.0.0',
|
|
30
|
-
...overrides,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
describe('SchemaExporter', () => {
|
|
35
|
-
const exporter = new SchemaExporter();
|
|
36
|
-
|
|
37
|
-
describe('exportGeneric', () => {
|
|
38
|
-
it('returns module_id, description, input/output schemas, and definitions', () => {
|
|
39
|
-
const sd = makeSchemaDef();
|
|
40
|
-
const result = exporter.exportGeneric(sd);
|
|
41
|
-
expect(result['module_id']).toBe('test.module');
|
|
42
|
-
expect(result['description']).toBe('A test module');
|
|
43
|
-
expect(result['input_schema']).toEqual(sd.inputSchema);
|
|
44
|
-
expect(result['output_schema']).toEqual(sd.outputSchema);
|
|
45
|
-
expect(result['definitions']).toEqual({});
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe('exportMcp', () => {
|
|
50
|
-
it('returns MCP tool format with annotations', () => {
|
|
51
|
-
const sd = makeSchemaDef();
|
|
52
|
-
const annotations: ModuleAnnotations = {
|
|
53
|
-
readonly: true,
|
|
54
|
-
destructive: false,
|
|
55
|
-
idempotent: true,
|
|
56
|
-
requiresApproval: false,
|
|
57
|
-
openWorld: false,
|
|
58
|
-
streaming: false,
|
|
59
|
-
};
|
|
60
|
-
const result = exporter.exportMcp(sd, annotations, 'MyTool');
|
|
61
|
-
expect(result['name']).toBe('MyTool');
|
|
62
|
-
expect(result['description']).toBe('A test module');
|
|
63
|
-
expect(result['inputSchema']).toEqual(sd.inputSchema);
|
|
64
|
-
const annots = result['annotations'] as Record<string, unknown>;
|
|
65
|
-
expect(annots['readOnlyHint']).toBe(true);
|
|
66
|
-
expect(annots['destructiveHint']).toBe(false);
|
|
67
|
-
expect(annots['idempotentHint']).toBe(true);
|
|
68
|
-
expect(annots['openWorldHint']).toBe(false);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('falls back to moduleId when name is null', () => {
|
|
72
|
-
const sd = makeSchemaDef();
|
|
73
|
-
const result = exporter.exportMcp(sd, null, null);
|
|
74
|
-
expect(result['name']).toBe('test.module');
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('uses default annotation values when annotations is null', () => {
|
|
78
|
-
const sd = makeSchemaDef();
|
|
79
|
-
const result = exporter.exportMcp(sd, null);
|
|
80
|
-
const annots = result['annotations'] as Record<string, unknown>;
|
|
81
|
-
expect(annots['readOnlyHint']).toBe(false);
|
|
82
|
-
expect(annots['destructiveHint']).toBe(false);
|
|
83
|
-
expect(annots['idempotentHint']).toBe(false);
|
|
84
|
-
expect(annots['openWorldHint']).toBe(true);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe('exportOpenai', () => {
|
|
89
|
-
it('returns OpenAI function calling format with strict schema', () => {
|
|
90
|
-
const sd = makeSchemaDef();
|
|
91
|
-
const result = exporter.exportOpenai(sd);
|
|
92
|
-
expect(result['type']).toBe('function');
|
|
93
|
-
const fn = result['function'] as Record<string, unknown>;
|
|
94
|
-
expect(fn['name']).toBe('test_module');
|
|
95
|
-
expect(fn['description']).toBe('A test module');
|
|
96
|
-
expect(fn['strict']).toBe(true);
|
|
97
|
-
const params = fn['parameters'] as Record<string, unknown>;
|
|
98
|
-
expect(params['additionalProperties']).toBe(false);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('applies x-llm-description to properties', () => {
|
|
102
|
-
const sd = makeSchemaDef();
|
|
103
|
-
const result = exporter.exportOpenai(sd);
|
|
104
|
-
const fn = result['function'] as Record<string, unknown>;
|
|
105
|
-
const params = fn['parameters'] as Record<string, unknown>;
|
|
106
|
-
const props = params['properties'] as Record<string, Record<string, unknown>>;
|
|
107
|
-
expect(props['name']['description']).toBe('LLM Name');
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
describe('exportAnthropic', () => {
|
|
112
|
-
it('returns Anthropic tool format', () => {
|
|
113
|
-
const sd = makeSchemaDef();
|
|
114
|
-
const result = exporter.exportAnthropic(sd);
|
|
115
|
-
expect(result['name']).toBe('test_module');
|
|
116
|
-
expect(result['description']).toBe('A test module');
|
|
117
|
-
expect(result['input_schema']).toBeDefined();
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('includes input_examples when examples are provided', () => {
|
|
121
|
-
const sd = makeSchemaDef();
|
|
122
|
-
const examples: ModuleExample[] = [
|
|
123
|
-
{ title: 'Ex1', inputs: { name: 'Alice' }, output: { result: 'ok' } },
|
|
124
|
-
];
|
|
125
|
-
const result = exporter.exportAnthropic(sd, examples);
|
|
126
|
-
const inputExamples = result['input_examples'] as Array<Record<string, unknown>>;
|
|
127
|
-
expect(inputExamples).toHaveLength(1);
|
|
128
|
-
expect(inputExamples[0]).toEqual({ name: 'Alice' });
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('omits input_examples when no examples', () => {
|
|
132
|
-
const sd = makeSchemaDef();
|
|
133
|
-
const result = exporter.exportAnthropic(sd, []);
|
|
134
|
-
expect(result['input_examples']).toBeUndefined();
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('strips x- extensions from schema', () => {
|
|
138
|
-
const sd = makeSchemaDef();
|
|
139
|
-
const result = exporter.exportAnthropic(sd);
|
|
140
|
-
const schema = result['input_schema'] as Record<string, unknown>;
|
|
141
|
-
const props = schema['properties'] as Record<string, Record<string, unknown>>;
|
|
142
|
-
expect(props['name']['x-llm-description']).toBeUndefined();
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
describe('export dispatch', () => {
|
|
147
|
-
it('dispatches to MCP profile', () => {
|
|
148
|
-
const sd = makeSchemaDef();
|
|
149
|
-
const result = exporter.export(sd, ExportProfile.MCP);
|
|
150
|
-
expect(result['name']).toBe('test.module');
|
|
151
|
-
expect(result['annotations']).toBeDefined();
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it('dispatches to OpenAI profile', () => {
|
|
155
|
-
const sd = makeSchemaDef();
|
|
156
|
-
const result = exporter.export(sd, ExportProfile.OpenAI);
|
|
157
|
-
expect(result['type']).toBe('function');
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('dispatches to Anthropic profile', () => {
|
|
161
|
-
const sd = makeSchemaDef();
|
|
162
|
-
const result = exporter.export(sd, ExportProfile.Anthropic);
|
|
163
|
-
expect(result['input_schema']).toBeDefined();
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('dispatches to Generic profile', () => {
|
|
167
|
-
const sd = makeSchemaDef();
|
|
168
|
-
const result = exporter.export(sd, ExportProfile.Generic);
|
|
169
|
-
expect(result['module_id']).toBe('test.module');
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
});
|