apcore-js 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- 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/approval.d.ts +85 -0
- package/dist/approval.d.ts.map +1 -0
- package/dist/approval.js +73 -0
- package/dist/approval.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 +204 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +364 -0
- package/dist/errors.js.map +1 -0
- package/dist/executor.d.ts +82 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/executor.js +489 -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 +239 -0
- package/dist/extensions.js.map +1 -0
- package/{src/index.ts → dist/index.d.ts} +6 -63
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -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 +24 -3
- 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,133 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { tmpdir } from 'node:os';
|
|
5
|
-
import { pathToFileURL } from 'node:url';
|
|
6
|
-
import { snakeToPascal, resolveEntryPoint } from '../../src/registry/entry-point.js';
|
|
7
|
-
import { ModuleLoadError } from '../../src/errors.js';
|
|
8
|
-
|
|
9
|
-
function validModuleSource(name: string): string {
|
|
10
|
-
return `{
|
|
11
|
-
inputSchema: { type: 'object' },
|
|
12
|
-
outputSchema: { type: 'object' },
|
|
13
|
-
description: '${name} module',
|
|
14
|
-
execute: function() { return {}; },
|
|
15
|
-
}`;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
describe('snakeToPascal', () => {
|
|
19
|
-
it('returns empty string for empty input', () => {
|
|
20
|
-
expect(snakeToPascal('')).toBe('');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('capitalises a single word', () => {
|
|
24
|
-
expect(snakeToPascal('hello')).toBe('Hello');
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('converts two-word snake_case', () => {
|
|
28
|
-
expect(snakeToPascal('hello_world')).toBe('HelloWorld');
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('converts multi-word snake_case', () => {
|
|
32
|
-
expect(snakeToPascal('my_module_name')).toBe('MyModuleName');
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('capitalises a word with no underscores', () => {
|
|
36
|
-
expect(snakeToPascal('already')).toBe('Already');
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe('resolveEntryPoint', () => {
|
|
41
|
-
let tmpDir: string;
|
|
42
|
-
|
|
43
|
-
beforeEach(() => {
|
|
44
|
-
tmpDir = mkdtempSync(join(tmpdir(), 'apcore-entry-test-'));
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
afterEach(() => {
|
|
48
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
function fileUrl(filePath: string): string {
|
|
52
|
-
return pathToFileURL(filePath).href;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
it('throws ModuleLoadError for a non-existent file path', async () => {
|
|
56
|
-
const badPath = fileUrl(join(tmpDir, 'does_not_exist.js'));
|
|
57
|
-
await expect(resolveEntryPoint(badPath)).rejects.toThrow(ModuleLoadError);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('finds default export that satisfies isModuleClass', async () => {
|
|
61
|
-
const filePath = join(tmpDir, 'default_mod.mjs');
|
|
62
|
-
writeFileSync(filePath, `const mod = ${validModuleSource('Default')};\nexport default mod;\n`);
|
|
63
|
-
const result = await resolveEntryPoint(fileUrl(filePath));
|
|
64
|
-
expect(result).toBeDefined();
|
|
65
|
-
expect((result as Record<string, unknown>)['description']).toBe('Default module');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('finds a single named export that satisfies isModuleClass', async () => {
|
|
69
|
-
const filePath = join(tmpDir, 'named_mod.mjs');
|
|
70
|
-
writeFileSync(filePath, `export const MyModule = ${validModuleSource('Named')};\n`);
|
|
71
|
-
const result = await resolveEntryPoint(fileUrl(filePath));
|
|
72
|
-
expect(result).toBeDefined();
|
|
73
|
-
expect((result as Record<string, unknown>)['description']).toBe('Named module');
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('throws ModuleLoadError when no export satisfies isModuleClass', async () => {
|
|
77
|
-
const filePath = join(tmpDir, 'no_valid.mjs');
|
|
78
|
-
writeFileSync(filePath, `export const notAModule = { foo: 'bar' };\nexport const alsoNot = 42;\n`);
|
|
79
|
-
await expect(resolveEntryPoint(fileUrl(filePath))).rejects.toThrow(ModuleLoadError);
|
|
80
|
-
await expect(resolveEntryPoint(fileUrl(filePath))).rejects.toThrow(/No Module subclass found/);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('throws ModuleLoadError when multiple exports satisfy isModuleClass', async () => {
|
|
84
|
-
const filePath = join(tmpDir, 'ambiguous.mjs');
|
|
85
|
-
writeFileSync(filePath, `export const ModuleA = ${validModuleSource('A')};\nexport const ModuleB = ${validModuleSource('B')};\n`);
|
|
86
|
-
await expect(resolveEntryPoint(fileUrl(filePath))).rejects.toThrow(ModuleLoadError);
|
|
87
|
-
await expect(resolveEntryPoint(fileUrl(filePath))).rejects.toThrow(/Ambiguous entry point/);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('uses meta entry_point to find a specific named class', async () => {
|
|
91
|
-
const filePath = join(tmpDir, 'meta_override.mjs');
|
|
92
|
-
writeFileSync(filePath, `export const Alpha = ${validModuleSource('Alpha')};\nexport const Beta = ${validModuleSource('Beta')};\n`);
|
|
93
|
-
const meta = { entry_point: 'some.path:Beta' };
|
|
94
|
-
const result = await resolveEntryPoint(fileUrl(filePath), meta);
|
|
95
|
-
expect((result as Record<string, unknown>)['description']).toBe('Beta module');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it('throws ModuleLoadError when meta entry_point class does not exist', async () => {
|
|
99
|
-
const filePath = join(tmpDir, 'meta_missing.mjs');
|
|
100
|
-
writeFileSync(filePath, `export const Alpha = ${validModuleSource('Alpha')};\n`);
|
|
101
|
-
const meta = { entry_point: 'mod:NonExistent' };
|
|
102
|
-
await expect(resolveEntryPoint(fileUrl(filePath), meta)).rejects.toThrow(ModuleLoadError);
|
|
103
|
-
await expect(resolveEntryPoint(fileUrl(filePath), meta)).rejects.toThrow(/Entry point class 'NonExistent' not found/);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('prefers default export over named exports when both are valid', async () => {
|
|
107
|
-
const filePath = join(tmpDir, 'default_priority.mjs');
|
|
108
|
-
writeFileSync(filePath, `const def = ${validModuleSource('DefaultPriority')};\nexport default def;\nexport const Named = ${validModuleSource('NamedSibling')};\n`);
|
|
109
|
-
const result = await resolveEntryPoint(fileUrl(filePath));
|
|
110
|
-
expect((result as Record<string, unknown>)['description']).toBe('DefaultPriority module');
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('falls back to auto-infer when meta is null', async () => {
|
|
114
|
-
const filePath = join(tmpDir, 'null_meta.mjs');
|
|
115
|
-
writeFileSync(filePath, `export const OnlyModule = ${validModuleSource('OnlyMeta')};\n`);
|
|
116
|
-
const result = await resolveEntryPoint(fileUrl(filePath), null);
|
|
117
|
-
expect((result as Record<string, unknown>)['description']).toBe('OnlyMeta module');
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('ignores exports missing execute function', async () => {
|
|
121
|
-
const filePath = join(tmpDir, 'missing_execute.mjs');
|
|
122
|
-
writeFileSync(filePath, `export const Incomplete = {\n inputSchema: { type: 'object' },\n outputSchema: { type: 'object' },\n description: 'no execute',\n};\nexport const Complete = ${validModuleSource('Complete')};\n`);
|
|
123
|
-
const result = await resolveEntryPoint(fileUrl(filePath));
|
|
124
|
-
expect((result as Record<string, unknown>)['description']).toBe('Complete module');
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('ignores primitive and null exports', async () => {
|
|
128
|
-
const filePath = join(tmpDir, 'primitives.mjs');
|
|
129
|
-
writeFileSync(filePath, `export const aNumber = 42;\nexport const aString = 'hello';\nexport const aNull = null;\nexport const Valid = ${validModuleSource('Valid')};\n`);
|
|
130
|
-
const result = await resolveEntryPoint(fileUrl(filePath));
|
|
131
|
-
expect((result as Record<string, unknown>)['description']).toBe('Valid module');
|
|
132
|
-
});
|
|
133
|
-
});
|
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { tmpdir } from 'node:os';
|
|
5
|
-
import {
|
|
6
|
-
loadMetadata,
|
|
7
|
-
parseDependencies,
|
|
8
|
-
mergeModuleMetadata,
|
|
9
|
-
loadIdMap,
|
|
10
|
-
} from '../../src/registry/metadata.js';
|
|
11
|
-
import { ConfigError, ConfigNotFoundError } from '../../src/errors.js';
|
|
12
|
-
|
|
13
|
-
describe('loadMetadata', () => {
|
|
14
|
-
let tmpDir: string;
|
|
15
|
-
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
tmpDir = mkdtempSync(join(tmpdir(), 'metadata-test-'));
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
afterEach(() => {
|
|
21
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('returns empty object for non-existent file', () => {
|
|
25
|
-
const result = loadMetadata(join(tmpDir, 'does_not_exist.yaml'));
|
|
26
|
-
expect(result).toEqual({});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('parses valid YAML and returns record', () => {
|
|
30
|
-
const metaPath = join(tmpDir, '_meta.yaml');
|
|
31
|
-
writeFileSync(metaPath, 'description: hello\nversion: "2.0.0"\ntags:\n - alpha\n - beta\n');
|
|
32
|
-
const result = loadMetadata(metaPath);
|
|
33
|
-
expect(result).toEqual({
|
|
34
|
-
description: 'hello',
|
|
35
|
-
version: '2.0.0',
|
|
36
|
-
tags: ['alpha', 'beta'],
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('returns empty object for null YAML content', () => {
|
|
41
|
-
const metaPath = join(tmpDir, '_meta.yaml');
|
|
42
|
-
writeFileSync(metaPath, '');
|
|
43
|
-
const result = loadMetadata(metaPath);
|
|
44
|
-
expect(result).toEqual({});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('returns empty object for YAML file containing only null', () => {
|
|
48
|
-
const metaPath = join(tmpDir, '_meta.yaml');
|
|
49
|
-
writeFileSync(metaPath, 'null\n');
|
|
50
|
-
const result = loadMetadata(metaPath);
|
|
51
|
-
expect(result).toEqual({});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('throws ConfigError for invalid YAML syntax', () => {
|
|
55
|
-
const metaPath = join(tmpDir, '_meta.yaml');
|
|
56
|
-
writeFileSync(metaPath, ':\n :\n bad: {{{\n');
|
|
57
|
-
expect(() => loadMetadata(metaPath)).toThrow(ConfigError);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('throws ConfigError if YAML content is a list instead of mapping', () => {
|
|
61
|
-
const metaPath = join(tmpDir, '_meta.yaml');
|
|
62
|
-
writeFileSync(metaPath, '- item1\n- item2\n');
|
|
63
|
-
expect(() => loadMetadata(metaPath)).toThrow(ConfigError);
|
|
64
|
-
expect(() => loadMetadata(metaPath)).toThrow(/must be a YAML mapping/);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
describe('parseDependencies', () => {
|
|
69
|
-
it('returns empty array for empty input', () => {
|
|
70
|
-
expect(parseDependencies([])).toEqual([]);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('returns empty array for null/undefined input', () => {
|
|
74
|
-
expect(parseDependencies(null as unknown as Array<Record<string, unknown>>)).toEqual([]);
|
|
75
|
-
expect(parseDependencies(undefined as unknown as Array<Record<string, unknown>>)).toEqual([]);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('parses dependencies with moduleId, version, optional', () => {
|
|
79
|
-
const raw = [
|
|
80
|
-
{ module_id: 'core.auth', version: '1.2.0', optional: true },
|
|
81
|
-
{ module_id: 'core.db', version: '3.0.0', optional: false },
|
|
82
|
-
];
|
|
83
|
-
const result = parseDependencies(raw);
|
|
84
|
-
expect(result).toEqual([
|
|
85
|
-
{ moduleId: 'core.auth', version: '1.2.0', optional: true },
|
|
86
|
-
{ moduleId: 'core.db', version: '3.0.0', optional: false },
|
|
87
|
-
]);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('skips entries without module_id', () => {
|
|
91
|
-
const raw = [
|
|
92
|
-
{ module_id: 'valid.module' },
|
|
93
|
-
{ version: '1.0.0' },
|
|
94
|
-
{ optional: true },
|
|
95
|
-
{},
|
|
96
|
-
];
|
|
97
|
-
const result = parseDependencies(raw);
|
|
98
|
-
expect(result).toHaveLength(1);
|
|
99
|
-
expect(result[0].moduleId).toBe('valid.module');
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('defaults version to null and optional to false', () => {
|
|
103
|
-
const raw = [{ module_id: 'some.module' }];
|
|
104
|
-
const result = parseDependencies(raw);
|
|
105
|
-
expect(result).toEqual([
|
|
106
|
-
{ moduleId: 'some.module', version: null, optional: false },
|
|
107
|
-
]);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('handles mixed entries with partial fields', () => {
|
|
111
|
-
const raw = [
|
|
112
|
-
{ module_id: 'a', version: '1.0.0' },
|
|
113
|
-
{ module_id: 'b', optional: true },
|
|
114
|
-
{ module_id: 'c' },
|
|
115
|
-
];
|
|
116
|
-
const result = parseDependencies(raw);
|
|
117
|
-
expect(result).toEqual([
|
|
118
|
-
{ moduleId: 'a', version: '1.0.0', optional: false },
|
|
119
|
-
{ moduleId: 'b', version: null, optional: true },
|
|
120
|
-
{ moduleId: 'c', version: null, optional: false },
|
|
121
|
-
]);
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
describe('mergeModuleMetadata', () => {
|
|
126
|
-
it('YAML values win over code values for all top-level fields', () => {
|
|
127
|
-
const moduleObj = {
|
|
128
|
-
description: 'code desc',
|
|
129
|
-
name: 'code-name',
|
|
130
|
-
tags: ['code-tag'],
|
|
131
|
-
version: '1.0.0',
|
|
132
|
-
annotations: { codeAnnot: true },
|
|
133
|
-
examples: [{ code: 'code-example' }],
|
|
134
|
-
documentation: 'code docs',
|
|
135
|
-
metadata: { codeKey: 'codeVal' },
|
|
136
|
-
};
|
|
137
|
-
const meta = {
|
|
138
|
-
description: 'yaml desc',
|
|
139
|
-
name: 'yaml-name',
|
|
140
|
-
tags: ['yaml-tag'],
|
|
141
|
-
version: '2.0.0',
|
|
142
|
-
annotations: { yamlAnnot: true },
|
|
143
|
-
examples: [{ code: 'yaml-example' }],
|
|
144
|
-
documentation: 'yaml docs',
|
|
145
|
-
metadata: { yamlKey: 'yamlVal' },
|
|
146
|
-
};
|
|
147
|
-
const result = mergeModuleMetadata(moduleObj, meta);
|
|
148
|
-
expect(result['description']).toBe('yaml desc');
|
|
149
|
-
expect(result['name']).toBe('yaml-name');
|
|
150
|
-
expect(result['tags']).toEqual(['yaml-tag']);
|
|
151
|
-
expect(result['version']).toBe('2.0.0');
|
|
152
|
-
expect(result['annotations']).toEqual({ yamlAnnot: true });
|
|
153
|
-
expect(result['examples']).toEqual([{ code: 'yaml-example' }]);
|
|
154
|
-
expect(result['documentation']).toBe('yaml docs');
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('code values used as fallback when YAML is empty', () => {
|
|
158
|
-
const moduleObj = {
|
|
159
|
-
description: 'code desc',
|
|
160
|
-
name: 'code-name',
|
|
161
|
-
tags: ['code-tag'],
|
|
162
|
-
version: '1.0.0',
|
|
163
|
-
metadata: { codeKey: 'codeVal' },
|
|
164
|
-
};
|
|
165
|
-
const meta: Record<string, unknown> = {};
|
|
166
|
-
const result = mergeModuleMetadata(moduleObj, meta);
|
|
167
|
-
expect(result['description']).toBe('code desc');
|
|
168
|
-
expect(result['name']).toBe('code-name');
|
|
169
|
-
expect(result['tags']).toEqual(['code-tag']);
|
|
170
|
-
expect(result['version']).toBe('1.0.0');
|
|
171
|
-
expect(result['metadata']).toEqual({ codeKey: 'codeVal' });
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('metadata records are shallow-merged with YAML spread over code', () => {
|
|
175
|
-
const moduleObj = { metadata: { shared: 'from-code', codeOnly: 'value' } };
|
|
176
|
-
const meta = { metadata: { shared: 'from-yaml', yamlOnly: 'value' } };
|
|
177
|
-
const result = mergeModuleMetadata(moduleObj, meta);
|
|
178
|
-
expect(result['metadata']).toEqual({
|
|
179
|
-
shared: 'from-yaml',
|
|
180
|
-
codeOnly: 'value',
|
|
181
|
-
yamlOnly: 'value',
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it('default values used when both code and YAML are absent', () => {
|
|
186
|
-
const result = mergeModuleMetadata({}, {});
|
|
187
|
-
expect(result['description']).toBe('');
|
|
188
|
-
expect(result['name']).toBeNull();
|
|
189
|
-
expect(result['tags']).toEqual([]);
|
|
190
|
-
expect(result['version']).toBe('1.0.0');
|
|
191
|
-
expect(result['annotations']).toBeNull();
|
|
192
|
-
expect(result['examples']).toEqual([]);
|
|
193
|
-
expect(result['metadata']).toEqual({});
|
|
194
|
-
expect(result['documentation']).toBeNull();
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
it('YAML empty array for tags overrides code tags', () => {
|
|
198
|
-
const moduleObj = { tags: ['code-tag'] };
|
|
199
|
-
const meta = { tags: [] };
|
|
200
|
-
const result = mergeModuleMetadata(moduleObj, meta);
|
|
201
|
-
expect(result['tags']).toEqual([]);
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
describe('loadIdMap', () => {
|
|
206
|
-
let tmpDir: string;
|
|
207
|
-
|
|
208
|
-
beforeEach(() => {
|
|
209
|
-
tmpDir = mkdtempSync(join(tmpdir(), 'idmap-test-'));
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
afterEach(() => {
|
|
213
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it('throws ConfigNotFoundError for non-existent file', () => {
|
|
217
|
-
expect(() => loadIdMap(join(tmpDir, 'nonexistent.yaml'))).toThrow(ConfigNotFoundError);
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
it('throws ConfigError for invalid YAML syntax', () => {
|
|
221
|
-
const idMapPath = join(tmpDir, 'id_map.yaml');
|
|
222
|
-
writeFileSync(idMapPath, ':\n bad: {{{\n');
|
|
223
|
-
expect(() => loadIdMap(idMapPath)).toThrow(ConfigError);
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it('throws ConfigError when mappings key is missing', () => {
|
|
227
|
-
const idMapPath = join(tmpDir, 'id_map.yaml');
|
|
228
|
-
writeFileSync(idMapPath, 'some_key: value\n');
|
|
229
|
-
expect(() => loadIdMap(idMapPath)).toThrow(ConfigError);
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it('throws ConfigError when mappings is not an array', () => {
|
|
233
|
-
const idMapPath = join(tmpDir, 'id_map.yaml');
|
|
234
|
-
writeFileSync(idMapPath, 'mappings:\n key: value\n');
|
|
235
|
-
expect(() => loadIdMap(idMapPath)).toThrow(ConfigError);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it('parses valid mappings with file, id, and class fields', () => {
|
|
239
|
-
const idMapPath = join(tmpDir, 'id_map.yaml');
|
|
240
|
-
writeFileSync(
|
|
241
|
-
idMapPath,
|
|
242
|
-
['mappings:', ' - file: module_a.ts', ' id: custom.module.a', ' class: ModuleA', ' - file: module_b.ts', ' id: custom.module.b', ''].join('\n'),
|
|
243
|
-
);
|
|
244
|
-
const result = loadIdMap(idMapPath);
|
|
245
|
-
expect(result['module_a.ts']).toEqual({ id: 'custom.module.a', class: 'ModuleA' });
|
|
246
|
-
expect(result['module_b.ts']).toEqual({ id: 'custom.module.b', class: null });
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
it('skips entries without file field', () => {
|
|
250
|
-
const idMapPath = join(tmpDir, 'id_map.yaml');
|
|
251
|
-
writeFileSync(
|
|
252
|
-
idMapPath,
|
|
253
|
-
['mappings:', ' - file: valid.ts', ' id: valid.id', ' - id: orphan.id', ''].join('\n'),
|
|
254
|
-
);
|
|
255
|
-
const result = loadIdMap(idMapPath);
|
|
256
|
-
expect(Object.keys(result)).toEqual(['valid.ts']);
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it('handles empty mappings array', () => {
|
|
260
|
-
const idMapPath = join(tmpDir, 'id_map.yaml');
|
|
261
|
-
writeFileSync(idMapPath, 'mappings: []\n');
|
|
262
|
-
const result = loadIdMap(idMapPath);
|
|
263
|
-
expect(result).toEqual({});
|
|
264
|
-
});
|
|
265
|
-
});
|