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