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
package/tests/test-acl.test.ts
DELETED
|
@@ -1,423 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { writeFileSync, mkdtempSync, rmSync } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { tmpdir } from 'node:os';
|
|
5
|
-
import { ACL } from '../src/acl.js';
|
|
6
|
-
import { ACLRuleError, ConfigNotFoundError } from '../src/errors.js';
|
|
7
|
-
import { Context, createIdentity } from '../src/context.js';
|
|
8
|
-
|
|
9
|
-
function makeContext(opts: {
|
|
10
|
-
callerId?: string | null;
|
|
11
|
-
callChain?: string[];
|
|
12
|
-
identityType?: string;
|
|
13
|
-
roles?: string[];
|
|
14
|
-
} = {}): Context {
|
|
15
|
-
const identity = opts.identityType
|
|
16
|
-
? createIdentity('test-user', opts.identityType, opts.roles ?? [])
|
|
17
|
-
: null;
|
|
18
|
-
return new Context(
|
|
19
|
-
'trace-test',
|
|
20
|
-
opts.callerId ?? null,
|
|
21
|
-
opts.callChain ?? [],
|
|
22
|
-
null,
|
|
23
|
-
identity,
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
describe('ACL', () => {
|
|
28
|
-
it('allows access when allow rule matches', () => {
|
|
29
|
-
const acl = new ACL([
|
|
30
|
-
{ callers: ['module.a'], targets: ['module.b'], effect: 'allow', description: '' },
|
|
31
|
-
]);
|
|
32
|
-
expect(acl.check('module.a', 'module.b')).toBe(true);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('denies access when deny rule matches', () => {
|
|
36
|
-
const acl = new ACL([
|
|
37
|
-
{ callers: ['module.a'], targets: ['module.b'], effect: 'deny', description: '' },
|
|
38
|
-
]);
|
|
39
|
-
expect(acl.check('module.a', 'module.b')).toBe(false);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('returns default deny when no rule matches', () => {
|
|
43
|
-
const acl = new ACL([
|
|
44
|
-
{ callers: ['module.a'], targets: ['module.b'], effect: 'allow', description: '' },
|
|
45
|
-
]);
|
|
46
|
-
expect(acl.check('module.x', 'module.y')).toBe(false);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('first-match-wins: deny before allow', () => {
|
|
50
|
-
const acl = new ACL([
|
|
51
|
-
{ callers: ['module.a'], targets: ['module.b'], effect: 'deny', description: '' },
|
|
52
|
-
{ callers: ['module.a'], targets: ['module.b'], effect: 'allow', description: '' },
|
|
53
|
-
]);
|
|
54
|
-
expect(acl.check('module.a', 'module.b')).toBe(false);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('first-match-wins: allow before deny', () => {
|
|
58
|
-
const acl = new ACL([
|
|
59
|
-
{ callers: ['module.a'], targets: ['module.b'], effect: 'allow', description: '' },
|
|
60
|
-
{ callers: ['module.a'], targets: ['module.b'], effect: 'deny', description: '' },
|
|
61
|
-
]);
|
|
62
|
-
expect(acl.check('module.a', 'module.b')).toBe(true);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('default effect allow when no rules match', () => {
|
|
66
|
-
const acl = new ACL([], 'allow');
|
|
67
|
-
expect(acl.check('any', 'thing')).toBe(true);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('maps null callerId to @external', () => {
|
|
71
|
-
const acl = new ACL([
|
|
72
|
-
{ callers: ['@external'], targets: ['public.api'], effect: 'allow', description: '' },
|
|
73
|
-
]);
|
|
74
|
-
expect(acl.check(null, 'public.api')).toBe(true);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('does not match @external for real module caller', () => {
|
|
78
|
-
const acl = new ACL([
|
|
79
|
-
{ callers: ['@external'], targets: ['public.api'], effect: 'allow', description: '' },
|
|
80
|
-
]);
|
|
81
|
-
expect(acl.check('module.a', 'public.api')).toBe(false);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('wildcard * matches all callers', () => {
|
|
85
|
-
const acl = new ACL([
|
|
86
|
-
{ callers: ['*'], targets: ['public.api'], effect: 'allow', description: '' },
|
|
87
|
-
]);
|
|
88
|
-
expect(acl.check('module.a', 'public.api')).toBe(true);
|
|
89
|
-
expect(acl.check('module.b', 'public.api')).toBe(true);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('wildcard * matches all targets', () => {
|
|
93
|
-
const acl = new ACL([
|
|
94
|
-
{ callers: ['module.admin'], targets: ['*'], effect: 'allow', description: '' },
|
|
95
|
-
]);
|
|
96
|
-
expect(acl.check('module.admin', 'anything')).toBe(true);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('prefix wildcard matching', () => {
|
|
100
|
-
const acl = new ACL([
|
|
101
|
-
{ callers: ['core.*'], targets: ['data.*'], effect: 'allow', description: '' },
|
|
102
|
-
]);
|
|
103
|
-
expect(acl.check('core.auth', 'data.store')).toBe(true);
|
|
104
|
-
expect(acl.check('other.x', 'data.y')).toBe(false);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('@system matches system identity type', () => {
|
|
108
|
-
const acl = new ACL([
|
|
109
|
-
{ callers: ['@system'], targets: ['*'], effect: 'allow', description: '' },
|
|
110
|
-
]);
|
|
111
|
-
const ctx = makeContext({ identityType: 'system' });
|
|
112
|
-
expect(acl.check('any.module', 'any.target', ctx)).toBe(true);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('@system does not match non-system identity', () => {
|
|
116
|
-
const acl = new ACL([
|
|
117
|
-
{ callers: ['@system'], targets: ['*'], effect: 'allow', description: '' },
|
|
118
|
-
]);
|
|
119
|
-
const ctx = makeContext({ identityType: 'user' });
|
|
120
|
-
expect(acl.check('any.module', 'any.target', ctx)).toBe(false);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('conditions: identity_types allows matching type', () => {
|
|
124
|
-
const acl = new ACL([{
|
|
125
|
-
callers: ['*'], targets: ['admin'], effect: 'allow', description: '',
|
|
126
|
-
conditions: { identity_types: ['admin'] },
|
|
127
|
-
}]);
|
|
128
|
-
const ctx = makeContext({ identityType: 'admin' });
|
|
129
|
-
expect(acl.check('mod.a', 'admin', ctx)).toBe(true);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('conditions: identity_types denies non-matching type', () => {
|
|
133
|
-
const acl = new ACL([{
|
|
134
|
-
callers: ['*'], targets: ['admin'], effect: 'allow', description: '',
|
|
135
|
-
conditions: { identity_types: ['admin'] },
|
|
136
|
-
}]);
|
|
137
|
-
const ctx = makeContext({ identityType: 'user' });
|
|
138
|
-
expect(acl.check('mod.a', 'admin', ctx)).toBe(false);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('conditions: roles allows matching role', () => {
|
|
142
|
-
const acl = new ACL([{
|
|
143
|
-
callers: ['*'], targets: ['settings'], effect: 'allow', description: '',
|
|
144
|
-
conditions: { roles: ['editor', 'admin'] },
|
|
145
|
-
}]);
|
|
146
|
-
const ctx = makeContext({ identityType: 'user', roles: ['editor'] });
|
|
147
|
-
expect(acl.check('mod.a', 'settings', ctx)).toBe(true);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('conditions: roles denies missing role', () => {
|
|
151
|
-
const acl = new ACL([{
|
|
152
|
-
callers: ['*'], targets: ['settings'], effect: 'allow', description: '',
|
|
153
|
-
conditions: { roles: ['admin'] },
|
|
154
|
-
}]);
|
|
155
|
-
const ctx = makeContext({ identityType: 'user', roles: ['viewer'] });
|
|
156
|
-
expect(acl.check('mod.a', 'settings', ctx)).toBe(false);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('conditions: max_call_depth allows within limit', () => {
|
|
160
|
-
const acl = new ACL([{
|
|
161
|
-
callers: ['*'], targets: ['deep'], effect: 'allow', description: '',
|
|
162
|
-
conditions: { max_call_depth: 3 },
|
|
163
|
-
}]);
|
|
164
|
-
const ctx = makeContext({ callChain: ['a', 'b'] });
|
|
165
|
-
expect(acl.check('mod.a', 'deep', ctx)).toBe(true);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it('conditions: max_call_depth denies exceeding limit', () => {
|
|
169
|
-
const acl = new ACL([{
|
|
170
|
-
callers: ['*'], targets: ['deep'], effect: 'allow', description: '',
|
|
171
|
-
conditions: { max_call_depth: 2 },
|
|
172
|
-
}]);
|
|
173
|
-
const ctx = makeContext({ callChain: ['a', 'b', 'c'] });
|
|
174
|
-
expect(acl.check('mod.a', 'deep', ctx)).toBe(false);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it('conditions fail when no context provided', () => {
|
|
178
|
-
const acl = new ACL([{
|
|
179
|
-
callers: ['*'], targets: ['deep'], effect: 'allow', description: '',
|
|
180
|
-
conditions: { max_call_depth: 5 },
|
|
181
|
-
}]);
|
|
182
|
-
expect(acl.check('mod.a', 'deep')).toBe(false);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it('addRule adds to highest priority', () => {
|
|
186
|
-
const acl = new ACL([
|
|
187
|
-
{ callers: ['*'], targets: ['*'], effect: 'deny', description: '' },
|
|
188
|
-
]);
|
|
189
|
-
expect(acl.check('mod.a', 'mod.b')).toBe(false);
|
|
190
|
-
|
|
191
|
-
acl.addRule({ callers: ['mod.a'], targets: ['mod.b'], effect: 'allow', description: '' });
|
|
192
|
-
expect(acl.check('mod.a', 'mod.b')).toBe(true);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it('removeRule removes matching rule', () => {
|
|
196
|
-
const acl = new ACL([
|
|
197
|
-
{ callers: ['mod.a'], targets: ['mod.b'], effect: 'allow', description: '' },
|
|
198
|
-
]);
|
|
199
|
-
expect(acl.check('mod.a', 'mod.b')).toBe(true);
|
|
200
|
-
|
|
201
|
-
const removed = acl.removeRule(['mod.a'], ['mod.b']);
|
|
202
|
-
expect(removed).toBe(true);
|
|
203
|
-
expect(acl.check('mod.a', 'mod.b')).toBe(false);
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('removeRule returns false when no match', () => {
|
|
207
|
-
const acl = new ACL([]);
|
|
208
|
-
expect(acl.removeRule(['x'], ['y'])).toBe(false);
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
describe('ACL.load', () => {
|
|
213
|
-
let tmpDir: string;
|
|
214
|
-
|
|
215
|
-
beforeEach(() => {
|
|
216
|
-
tmpDir = mkdtempSync(join(tmpdir(), 'acl-test-'));
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
afterEach(() => {
|
|
220
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it('loads valid ACL from a YAML file', () => {
|
|
224
|
-
const yamlContent = `
|
|
225
|
-
rules:
|
|
226
|
-
- callers: ["module.a"]
|
|
227
|
-
targets: ["module.b"]
|
|
228
|
-
effect: allow
|
|
229
|
-
description: "allow a to b"
|
|
230
|
-
`;
|
|
231
|
-
const filePath = join(tmpDir, 'acl.yaml');
|
|
232
|
-
writeFileSync(filePath, yamlContent, 'utf-8');
|
|
233
|
-
|
|
234
|
-
const acl = ACL.load(filePath);
|
|
235
|
-
expect(acl.check('module.a', 'module.b')).toBe(true);
|
|
236
|
-
expect(acl.check('module.x', 'module.y')).toBe(false);
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it('loads ACL with custom default_effect from YAML', () => {
|
|
240
|
-
const yamlContent = `
|
|
241
|
-
default_effect: allow
|
|
242
|
-
rules: []
|
|
243
|
-
`;
|
|
244
|
-
const filePath = join(tmpDir, 'acl.yaml');
|
|
245
|
-
writeFileSync(filePath, yamlContent, 'utf-8');
|
|
246
|
-
|
|
247
|
-
const acl = ACL.load(filePath);
|
|
248
|
-
expect(acl.check('any.caller', 'any.target')).toBe(true);
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
it('throws ConfigNotFoundError for missing file', () => {
|
|
252
|
-
const missingPath = join(tmpDir, 'nonexistent.yaml');
|
|
253
|
-
expect(() => ACL.load(missingPath)).toThrow(ConfigNotFoundError);
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
it('throws ACLRuleError for invalid YAML syntax', () => {
|
|
257
|
-
const filePath = join(tmpDir, 'bad.yaml');
|
|
258
|
-
writeFileSync(filePath, ':\n :\n - [invalid', 'utf-8');
|
|
259
|
-
|
|
260
|
-
expect(() => ACL.load(filePath)).toThrow(ACLRuleError);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it('throws ACLRuleError when YAML is not a mapping', () => {
|
|
264
|
-
const filePath = join(tmpDir, 'array.yaml');
|
|
265
|
-
writeFileSync(filePath, '- item1\n- item2\n', 'utf-8');
|
|
266
|
-
|
|
267
|
-
expect(() => ACL.load(filePath)).toThrow(ACLRuleError);
|
|
268
|
-
expect(() => ACL.load(filePath)).toThrow(/must be a mapping/);
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
it('throws ACLRuleError when YAML is a scalar', () => {
|
|
272
|
-
const filePath = join(tmpDir, 'scalar.yaml');
|
|
273
|
-
writeFileSync(filePath, 'just a string\n', 'utf-8');
|
|
274
|
-
|
|
275
|
-
expect(() => ACL.load(filePath)).toThrow(ACLRuleError);
|
|
276
|
-
expect(() => ACL.load(filePath)).toThrow(/must be a mapping/);
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it('throws ACLRuleError when rules key is missing', () => {
|
|
280
|
-
const filePath = join(tmpDir, 'norules.yaml');
|
|
281
|
-
writeFileSync(filePath, 'default_effect: allow\n', 'utf-8');
|
|
282
|
-
|
|
283
|
-
expect(() => ACL.load(filePath)).toThrow(ACLRuleError);
|
|
284
|
-
expect(() => ACL.load(filePath)).toThrow(/missing required 'rules' key/);
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it('throws ACLRuleError when rules is not an array', () => {
|
|
288
|
-
const filePath = join(tmpDir, 'badrules.yaml');
|
|
289
|
-
writeFileSync(filePath, 'rules: "not-a-list"\n', 'utf-8');
|
|
290
|
-
|
|
291
|
-
expect(() => ACL.load(filePath)).toThrow(ACLRuleError);
|
|
292
|
-
expect(() => ACL.load(filePath)).toThrow(/'rules' must be a list/);
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
it('loads ACL with multiple rules and conditions', () => {
|
|
296
|
-
const yamlContent = `
|
|
297
|
-
rules:
|
|
298
|
-
- callers: ["*"]
|
|
299
|
-
targets: ["admin.panel"]
|
|
300
|
-
effect: allow
|
|
301
|
-
description: "admin access"
|
|
302
|
-
conditions:
|
|
303
|
-
roles: ["admin"]
|
|
304
|
-
- callers: ["*"]
|
|
305
|
-
targets: ["*"]
|
|
306
|
-
effect: deny
|
|
307
|
-
description: "deny all"
|
|
308
|
-
`;
|
|
309
|
-
const filePath = join(tmpDir, 'multi.yaml');
|
|
310
|
-
writeFileSync(filePath, yamlContent, 'utf-8');
|
|
311
|
-
|
|
312
|
-
const acl = ACL.load(filePath);
|
|
313
|
-
const adminCtx = makeContext({ identityType: 'user', roles: ['admin'] });
|
|
314
|
-
const userCtx = makeContext({ identityType: 'user', roles: ['viewer'] });
|
|
315
|
-
|
|
316
|
-
expect(acl.check('mod.a', 'admin.panel', adminCtx)).toBe(true);
|
|
317
|
-
expect(acl.check('mod.a', 'admin.panel', userCtx)).toBe(false);
|
|
318
|
-
});
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
describe('ACL.reload', () => {
|
|
322
|
-
let tmpDir: string;
|
|
323
|
-
|
|
324
|
-
beforeEach(() => {
|
|
325
|
-
tmpDir = mkdtempSync(join(tmpdir(), 'acl-reload-'));
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
afterEach(() => {
|
|
329
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
it('reloads updated rules from the same YAML file', () => {
|
|
333
|
-
const filePath = join(tmpDir, 'acl.yaml');
|
|
334
|
-
writeFileSync(filePath, `
|
|
335
|
-
rules:
|
|
336
|
-
- callers: ["module.a"]
|
|
337
|
-
targets: ["module.b"]
|
|
338
|
-
effect: deny
|
|
339
|
-
description: "initial deny"
|
|
340
|
-
`, 'utf-8');
|
|
341
|
-
|
|
342
|
-
const acl = ACL.load(filePath);
|
|
343
|
-
expect(acl.check('module.a', 'module.b')).toBe(false);
|
|
344
|
-
|
|
345
|
-
writeFileSync(filePath, `
|
|
346
|
-
rules:
|
|
347
|
-
- callers: ["module.a"]
|
|
348
|
-
targets: ["module.b"]
|
|
349
|
-
effect: allow
|
|
350
|
-
description: "updated allow"
|
|
351
|
-
`, 'utf-8');
|
|
352
|
-
|
|
353
|
-
acl.reload();
|
|
354
|
-
expect(acl.check('module.a', 'module.b')).toBe(true);
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
it('throws ACLRuleError when ACL was not loaded from a file', () => {
|
|
358
|
-
const acl = new ACL([
|
|
359
|
-
{ callers: ['*'], targets: ['*'], effect: 'allow', description: '' },
|
|
360
|
-
]);
|
|
361
|
-
|
|
362
|
-
expect(() => acl.reload()).toThrow(ACLRuleError);
|
|
363
|
-
expect(() => acl.reload()).toThrow(/Cannot reload/);
|
|
364
|
-
});
|
|
365
|
-
});
|
|
366
|
-
|
|
367
|
-
describe('ACL constructor validation', () => {
|
|
368
|
-
it('throws ACLRuleError for invalid defaultEffect', () => {
|
|
369
|
-
expect(() => new ACL([], 'block')).toThrow(ACLRuleError);
|
|
370
|
-
expect(() => new ACL([], 'block')).toThrow(/Invalid default_effect/);
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
it('throws ACLRuleError for empty string defaultEffect', () => {
|
|
374
|
-
expect(() => new ACL([], '')).toThrow(ACLRuleError);
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
describe('ACL condition validation', () => {
|
|
379
|
-
it('returns false when identity_types condition is not an array', () => {
|
|
380
|
-
const acl = new ACL([{
|
|
381
|
-
callers: ['*'], targets: ['target'], effect: 'allow', description: '',
|
|
382
|
-
conditions: { identity_types: 'admin' },
|
|
383
|
-
}]);
|
|
384
|
-
const ctx = makeContext({ identityType: 'admin' });
|
|
385
|
-
expect(acl.check('mod.a', 'target', ctx)).toBe(false);
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
it('returns false when roles condition is not an array', () => {
|
|
389
|
-
const acl = new ACL([{
|
|
390
|
-
callers: ['*'], targets: ['target'], effect: 'allow', description: '',
|
|
391
|
-
conditions: { roles: 'admin' },
|
|
392
|
-
}]);
|
|
393
|
-
const ctx = makeContext({ identityType: 'user', roles: ['admin'] });
|
|
394
|
-
expect(acl.check('mod.a', 'target', ctx)).toBe(false);
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
it('returns false when max_call_depth condition is not a number', () => {
|
|
398
|
-
const acl = new ACL([{
|
|
399
|
-
callers: ['*'], targets: ['target'], effect: 'allow', description: '',
|
|
400
|
-
conditions: { max_call_depth: '5' },
|
|
401
|
-
}]);
|
|
402
|
-
const ctx = makeContext({ callChain: ['a'] });
|
|
403
|
-
expect(acl.check('mod.a', 'target', ctx)).toBe(false);
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
it('returns false for roles condition when identity is null', () => {
|
|
407
|
-
const acl = new ACL([{
|
|
408
|
-
callers: ['*'], targets: ['target'], effect: 'allow', description: '',
|
|
409
|
-
conditions: { roles: ['admin'] },
|
|
410
|
-
}]);
|
|
411
|
-
const ctx = makeContext({});
|
|
412
|
-
expect(acl.check('mod.a', 'target', ctx)).toBe(false);
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
it('returns false for identity_types condition when identity is null', () => {
|
|
416
|
-
const acl = new ACL([{
|
|
417
|
-
callers: ['*'], targets: ['target'], effect: 'allow', description: '',
|
|
418
|
-
conditions: { identity_types: ['admin'] },
|
|
419
|
-
}]);
|
|
420
|
-
const ctx = makeContext({});
|
|
421
|
-
expect(acl.check('mod.a', 'target', ctx)).toBe(false);
|
|
422
|
-
});
|
|
423
|
-
});
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { mkdtempSync, writeFileSync, mkdirSync, rmSync } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
import { tmpdir } from 'node:os';
|
|
5
|
-
import { BindingLoader } from '../src/bindings.js';
|
|
6
|
-
import { Registry } from '../src/registry/registry.js';
|
|
7
|
-
import {
|
|
8
|
-
BindingInvalidTargetError,
|
|
9
|
-
BindingFileInvalidError,
|
|
10
|
-
BindingModuleNotFoundError,
|
|
11
|
-
BindingCallableNotFoundError,
|
|
12
|
-
BindingNotCallableError,
|
|
13
|
-
} from '../src/errors.js';
|
|
14
|
-
|
|
15
|
-
let tmpDir: string;
|
|
16
|
-
let loader: BindingLoader;
|
|
17
|
-
let registry: Registry;
|
|
18
|
-
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
tmpDir = mkdtempSync(join(tmpdir(), 'apcore-binding-test-'));
|
|
21
|
-
loader = new BindingLoader();
|
|
22
|
-
registry = new Registry();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
afterEach(() => {
|
|
26
|
-
rmSync(tmpDir, { recursive: true, force: true });
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
function writeTempModule(filename: string, content: string): string {
|
|
30
|
-
const filePath = join(tmpDir, filename);
|
|
31
|
-
writeFileSync(filePath, content, 'utf-8');
|
|
32
|
-
return filePath;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function writeTempYaml(filename: string, content: string): string {
|
|
36
|
-
const filePath = join(tmpDir, filename);
|
|
37
|
-
writeFileSync(filePath, content, 'utf-8');
|
|
38
|
-
return filePath;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
describe('BindingLoader', () => {
|
|
42
|
-
describe('instantiation', () => {
|
|
43
|
-
it('creates a new instance', () => {
|
|
44
|
-
expect(new BindingLoader()).toBeInstanceOf(BindingLoader);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('has loadBindings, loadBindingDir, and resolveTarget methods', () => {
|
|
48
|
-
const bl = new BindingLoader();
|
|
49
|
-
expect(typeof bl.loadBindings).toBe('function');
|
|
50
|
-
expect(typeof bl.loadBindingDir).toBe('function');
|
|
51
|
-
expect(typeof bl.resolveTarget).toBe('function');
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('resolveTarget', () => {
|
|
56
|
-
it('throws BindingInvalidTargetError for target without colon', async () => {
|
|
57
|
-
await expect(loader.resolveTarget('no_colon_here')).rejects.toThrow(BindingInvalidTargetError);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('throws BindingModuleNotFoundError for non-existent module path', async () => {
|
|
61
|
-
await expect(
|
|
62
|
-
loader.resolveTarget('/nonexistent/path/to/module.mjs:someFunc'),
|
|
63
|
-
).rejects.toThrow(BindingModuleNotFoundError);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('successfully resolves a function export from a real JS module', async () => {
|
|
67
|
-
const modPath = writeTempModule(
|
|
68
|
-
'func_export.mjs',
|
|
69
|
-
'export function greet(name) { return `Hello, ${name}`; }\n',
|
|
70
|
-
);
|
|
71
|
-
const fn = await loader.resolveTarget(`${modPath}:greet`);
|
|
72
|
-
expect(typeof fn).toBe('function');
|
|
73
|
-
expect(fn('World')).toBe('Hello, World');
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('successfully resolves a class method', async () => {
|
|
77
|
-
const modPath = writeTempModule(
|
|
78
|
-
'class_export.mjs',
|
|
79
|
-
`export class Calculator {\n add(a, b) { return a + b; }\n}\n`,
|
|
80
|
-
);
|
|
81
|
-
const fn = await loader.resolveTarget(`${modPath}:Calculator.add`);
|
|
82
|
-
expect(typeof fn).toBe('function');
|
|
83
|
-
expect(fn(2, 3)).toBe(5);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('throws BindingCallableNotFoundError for missing callable', async () => {
|
|
87
|
-
const modPath = writeTempModule('missing_callable.mjs', 'export function exists() { return true; }\n');
|
|
88
|
-
await expect(loader.resolveTarget(`${modPath}:doesNotExist`)).rejects.toThrow(BindingCallableNotFoundError);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('throws BindingNotCallableError for non-function export', async () => {
|
|
92
|
-
const modPath = writeTempModule('non_callable.mjs', 'export const MY_CONSTANT = 42;\n');
|
|
93
|
-
await expect(loader.resolveTarget(`${modPath}:MY_CONSTANT`)).rejects.toThrow(BindingNotCallableError);
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
describe('loadBindings', () => {
|
|
98
|
-
it('throws BindingFileInvalidError for non-existent file', async () => {
|
|
99
|
-
await expect(
|
|
100
|
-
loader.loadBindings('/nonexistent/path/binding.yaml', registry),
|
|
101
|
-
).rejects.toThrow(BindingFileInvalidError);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('throws BindingFileInvalidError for invalid YAML', async () => {
|
|
105
|
-
const yamlPath = writeTempYaml('invalid.binding.yaml', '{ invalid yaml: [unclosed');
|
|
106
|
-
await expect(loader.loadBindings(yamlPath, registry)).rejects.toThrow(BindingFileInvalidError);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('throws BindingFileInvalidError for empty file', async () => {
|
|
110
|
-
const yamlPath = writeTempYaml('empty.binding.yaml', '');
|
|
111
|
-
await expect(loader.loadBindings(yamlPath, registry)).rejects.toThrow(BindingFileInvalidError);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('throws BindingFileInvalidError for missing bindings key', async () => {
|
|
115
|
-
const yamlPath = writeTempYaml('nokey.binding.yaml', 'other_key: value\n');
|
|
116
|
-
await expect(loader.loadBindings(yamlPath, registry)).rejects.toThrow(BindingFileInvalidError);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('throws BindingFileInvalidError for non-array bindings value', async () => {
|
|
120
|
-
const yamlPath = writeTempYaml('notarray.binding.yaml', 'bindings: "not an array"\n');
|
|
121
|
-
await expect(loader.loadBindings(yamlPath, registry)).rejects.toThrow(BindingFileInvalidError);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('throws BindingFileInvalidError for binding entry missing module_id', async () => {
|
|
125
|
-
const modPath = writeTempModule('dummy_mod.mjs', 'export function dummy() { return {}; }\n');
|
|
126
|
-
const yamlPath = writeTempYaml('noid.binding.yaml', `bindings:\n - target: "${modPath}:dummy"\n`);
|
|
127
|
-
await expect(loader.loadBindings(yamlPath, registry)).rejects.toThrow(BindingFileInvalidError);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('throws BindingFileInvalidError for binding entry missing target', async () => {
|
|
131
|
-
const yamlPath = writeTempYaml('notarget.binding.yaml', 'bindings:\n - module_id: "test.module"\n');
|
|
132
|
-
await expect(loader.loadBindings(yamlPath, registry)).rejects.toThrow(BindingFileInvalidError);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('successfully loads valid binding with inline schemas', async () => {
|
|
136
|
-
const modPath = writeTempModule(
|
|
137
|
-
'inline_schema_mod.mjs',
|
|
138
|
-
'export function process(inputs) { return { result: inputs.name }; }\n',
|
|
139
|
-
);
|
|
140
|
-
const yamlPath = writeTempYaml(
|
|
141
|
-
'inline.binding.yaml',
|
|
142
|
-
`bindings:\n - module_id: "test.inline"\n target: "${modPath}:process"\n description: "Inline schema test"\n version: "2.0.0"\n tags:\n - demo\n input_schema:\n type: object\n properties:\n name:\n type: string\n output_schema:\n type: object\n properties:\n result:\n type: string\n`,
|
|
143
|
-
);
|
|
144
|
-
const results = await loader.loadBindings(yamlPath, registry);
|
|
145
|
-
expect(results).toHaveLength(1);
|
|
146
|
-
expect(results[0].moduleId).toBe('test.inline');
|
|
147
|
-
expect(results[0].description).toBe('Inline schema test');
|
|
148
|
-
expect(results[0].version).toBe('2.0.0');
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('successfully loads binding with permissive fallback (no schema)', async () => {
|
|
152
|
-
const modPath = writeTempModule('permissive_mod.mjs', 'export function loose(inputs) { return { ok: true }; }\n');
|
|
153
|
-
const yamlPath = writeTempYaml(
|
|
154
|
-
'permissive.binding.yaml',
|
|
155
|
-
`bindings:\n - module_id: "test.permissive"\n target: "${modPath}:loose"\n`,
|
|
156
|
-
);
|
|
157
|
-
const results = await loader.loadBindings(yamlPath, registry);
|
|
158
|
-
expect(results).toHaveLength(1);
|
|
159
|
-
expect(results[0].moduleId).toBe('test.permissive');
|
|
160
|
-
expect(results[0].inputSchema).toBeDefined();
|
|
161
|
-
expect(results[0].outputSchema).toBeDefined();
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('registers modules in the registry', async () => {
|
|
165
|
-
const modPath = writeTempModule('registered_mod.mjs', 'export function handler() { return {}; }\n');
|
|
166
|
-
const yamlPath = writeTempYaml(
|
|
167
|
-
'register.binding.yaml',
|
|
168
|
-
`bindings:\n - module_id: "test.registered"\n target: "${modPath}:handler"\n`,
|
|
169
|
-
);
|
|
170
|
-
await loader.loadBindings(yamlPath, registry);
|
|
171
|
-
expect(registry.has('test.registered')).toBe(true);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('loads multiple binding entries from single file', async () => {
|
|
175
|
-
const modPath = writeTempModule(
|
|
176
|
-
'multi_mod.mjs',
|
|
177
|
-
`export function funcA() { return { a: true }; }\nexport function funcB() { return { b: true }; }\n`,
|
|
178
|
-
);
|
|
179
|
-
const yamlPath = writeTempYaml(
|
|
180
|
-
'multi.binding.yaml',
|
|
181
|
-
`bindings:\n - module_id: "test.multi.a"\n target: "${modPath}:funcA"\n - module_id: "test.multi.b"\n target: "${modPath}:funcB"\n`,
|
|
182
|
-
);
|
|
183
|
-
const results = await loader.loadBindings(yamlPath, registry);
|
|
184
|
-
expect(results).toHaveLength(2);
|
|
185
|
-
expect(registry.has('test.multi.a')).toBe(true);
|
|
186
|
-
expect(registry.has('test.multi.b')).toBe(true);
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
describe('loadBindingDir', () => {
|
|
191
|
-
it('throws BindingFileInvalidError for non-existent directory', async () => {
|
|
192
|
-
await expect(loader.loadBindingDir('/nonexistent/dir/path', registry)).rejects.toThrow(BindingFileInvalidError);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it('loads all *.binding.yaml files in directory', async () => {
|
|
196
|
-
const bindDir = join(tmpDir, 'bindings');
|
|
197
|
-
mkdirSync(bindDir);
|
|
198
|
-
|
|
199
|
-
const modPath = writeTempModule(
|
|
200
|
-
'dir_mod.mjs',
|
|
201
|
-
`export function alpha() { return { alpha: true }; }\nexport function beta() { return { beta: true }; }\n`,
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
writeTempYaml(
|
|
205
|
-
join('bindings', 'alpha.binding.yaml'),
|
|
206
|
-
`bindings:\n - module_id: "dir.alpha"\n target: "${modPath}:alpha"\n`,
|
|
207
|
-
);
|
|
208
|
-
writeTempYaml(
|
|
209
|
-
join('bindings', 'beta.binding.yaml'),
|
|
210
|
-
`bindings:\n - module_id: "dir.beta"\n target: "${modPath}:beta"\n`,
|
|
211
|
-
);
|
|
212
|
-
|
|
213
|
-
const results = await loader.loadBindingDir(bindDir, registry);
|
|
214
|
-
expect(results).toHaveLength(2);
|
|
215
|
-
expect(registry.has('dir.alpha')).toBe(true);
|
|
216
|
-
expect(registry.has('dir.beta')).toBe(true);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it('returns empty array for directory with no binding files', async () => {
|
|
220
|
-
const emptyDir = join(tmpDir, 'empty');
|
|
221
|
-
mkdirSync(emptyDir);
|
|
222
|
-
|
|
223
|
-
const results = await loader.loadBindingDir(emptyDir, registry);
|
|
224
|
-
expect(results).toHaveLength(0);
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
});
|