@pikku/core 0.12.2 → 0.12.4

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 (282) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/crypto-utils.d.ts +10 -0
  3. package/dist/crypto-utils.js +62 -0
  4. package/dist/function/function-runner.js +4 -4
  5. package/dist/function/functions.types.d.ts +26 -1
  6. package/dist/function/functions.types.js +16 -0
  7. package/dist/handle-error.d.ts +1 -1
  8. package/dist/handle-error.js +7 -3
  9. package/dist/index.d.ts +14 -2
  10. package/dist/index.js +1 -1
  11. package/dist/pikku-state.js +3 -1
  12. package/dist/schema.js +1 -1
  13. package/dist/services/in-memory-workflow-service.d.ts +22 -3
  14. package/dist/services/in-memory-workflow-service.js +77 -1
  15. package/dist/services/workflow-service.d.ts +8 -2
  16. package/dist/testing/index.d.ts +2 -0
  17. package/dist/testing/index.js +1 -0
  18. package/dist/testing/service-tests.d.ts +31 -0
  19. package/dist/testing/service-tests.js +598 -0
  20. package/dist/types/core.types.d.ts +9 -1
  21. package/dist/types/state.types.d.ts +4 -2
  22. package/dist/utils/hash.d.ts +2 -0
  23. package/dist/utils/hash.js +23 -0
  24. package/dist/wirings/ai-agent/agent-dynamic-workflow.d.ts +6 -0
  25. package/dist/wirings/ai-agent/agent-dynamic-workflow.js +348 -0
  26. package/dist/wirings/ai-agent/ai-agent-memory.d.ts +1 -1
  27. package/dist/wirings/ai-agent/ai-agent-memory.js +6 -5
  28. package/dist/wirings/ai-agent/ai-agent-prepare.d.ts +10 -7
  29. package/dist/wirings/ai-agent/ai-agent-prepare.js +127 -47
  30. package/dist/wirings/ai-agent/ai-agent-runner.d.ts +4 -0
  31. package/dist/wirings/ai-agent/ai-agent-runner.js +381 -27
  32. package/dist/wirings/ai-agent/ai-agent-stream.d.ts +7 -2
  33. package/dist/wirings/ai-agent/ai-agent-stream.js +109 -46
  34. package/dist/wirings/ai-agent/ai-agent.types.d.ts +22 -1
  35. package/dist/wirings/ai-agent/index.d.ts +1 -2
  36. package/dist/wirings/ai-agent/index.js +1 -2
  37. package/dist/wirings/channel/channel-handler.js +5 -1
  38. package/dist/wirings/channel/channel.types.d.ts +1 -7
  39. package/dist/wirings/channel/local/local-channel-handler.d.ts +1 -1
  40. package/dist/wirings/channel/local/local-channel-handler.js +5 -3
  41. package/dist/wirings/channel/local/local-channel-runner.js +14 -4
  42. package/dist/wirings/channel/serverless/serverless-channel-runner.js +4 -1
  43. package/dist/wirings/cli/cli-runner.js +10 -2
  44. package/dist/wirings/cli/cli.types.d.ts +1 -0
  45. package/dist/wirings/http/http-routes.js +0 -1
  46. package/dist/wirings/http/http-runner.d.ts +1 -1
  47. package/dist/wirings/http/http-runner.js +25 -3
  48. package/dist/wirings/http/http.types.d.ts +3 -11
  49. package/dist/wirings/http/index.d.ts +2 -1
  50. package/dist/wirings/http/index.js +1 -0
  51. package/dist/wirings/http/pikku-fetch-http-request.d.ts +1 -0
  52. package/dist/wirings/http/pikku-fetch-http-request.js +3 -0
  53. package/dist/wirings/http/pikku-fetch-http-response.d.ts +1 -0
  54. package/dist/wirings/http/pikku-fetch-http-response.js +4 -4
  55. package/dist/wirings/http/web-request.d.ts +12 -0
  56. package/dist/wirings/http/web-request.js +85 -0
  57. package/dist/wirings/mcp/mcp-endpoint-registry.js +1 -1
  58. package/dist/wirings/mcp/mcp-runner.js +13 -1
  59. package/dist/wirings/rpc/rpc-runner.d.ts +30 -6
  60. package/dist/wirings/rpc/rpc-runner.js +36 -14
  61. package/dist/wirings/rpc/rpc-types.d.ts +6 -1
  62. package/dist/wirings/rpc/wire-addon.d.ts +1 -0
  63. package/dist/wirings/rpc/wire-addon.js +1 -1
  64. package/dist/wirings/scheduler/scheduler-runner.js +1 -0
  65. package/dist/wirings/workflow/graph/graph-validation.d.ts +3 -0
  66. package/dist/wirings/workflow/graph/graph-validation.js +175 -0
  67. package/dist/wirings/workflow/graph/index.d.ts +1 -0
  68. package/dist/wirings/workflow/graph/index.js +1 -0
  69. package/dist/wirings/workflow/index.d.ts +1 -1
  70. package/dist/wirings/workflow/pikku-workflow-service.d.ts +8 -2
  71. package/dist/wirings/workflow/pikku-workflow-service.js +1 -2
  72. package/dist/wirings/workflow/workflow.types.d.ts +10 -1
  73. package/lcov.info +18891 -0
  74. package/package.json +4 -2
  75. package/dist/wirings/ai-agent/ai-agent-assistant-ui.d.ts +0 -5
  76. package/dist/wirings/ai-agent/ai-agent-assistant-ui.js +0 -168
  77. package/src/crypto-utils.test.ts +0 -116
  78. package/src/crypto-utils.ts +0 -99
  79. package/src/errors/error-handler.ts +0 -62
  80. package/src/errors/error.test.ts +0 -195
  81. package/src/errors/errors.ts +0 -374
  82. package/src/errors/index.ts +0 -2
  83. package/src/factory-functions.test.ts +0 -109
  84. package/src/function/function-runner.test.ts +0 -536
  85. package/src/function/function-runner.ts +0 -365
  86. package/src/function/functions.types.ts +0 -267
  87. package/src/function/index.ts +0 -5
  88. package/src/handle-error.test.ts +0 -361
  89. package/src/handle-error.ts +0 -65
  90. package/src/index.ts +0 -104
  91. package/src/internal.ts +0 -6
  92. package/src/middleware/auth-apikey.test.ts +0 -363
  93. package/src/middleware/auth-apikey.ts +0 -47
  94. package/src/middleware/auth-bearer.test.ts +0 -450
  95. package/src/middleware/auth-bearer.ts +0 -72
  96. package/src/middleware/auth-cookie.test.ts +0 -528
  97. package/src/middleware/auth-cookie.ts +0 -80
  98. package/src/middleware/cors.test.ts +0 -424
  99. package/src/middleware/cors.ts +0 -104
  100. package/src/middleware/index.ts +0 -5
  101. package/src/middleware/remote-auth.test.ts +0 -488
  102. package/src/middleware/remote-auth.ts +0 -68
  103. package/src/middleware/timeout.ts +0 -15
  104. package/src/middleware-runner.test.ts +0 -418
  105. package/src/middleware-runner.ts +0 -234
  106. package/src/permissions.test.ts +0 -434
  107. package/src/permissions.ts +0 -319
  108. package/src/pikku-request.ts +0 -23
  109. package/src/pikku-response.ts +0 -5
  110. package/src/pikku-state.test.ts +0 -224
  111. package/src/pikku-state.ts +0 -214
  112. package/src/run-tests-script.test.ts +0 -49
  113. package/src/schema.test.ts +0 -249
  114. package/src/schema.ts +0 -151
  115. package/src/services/ai-agent-runner-service.ts +0 -41
  116. package/src/services/ai-run-state-service.ts +0 -20
  117. package/src/services/ai-storage-service.ts +0 -39
  118. package/src/services/content-service.ts +0 -76
  119. package/src/services/deployment-service.ts +0 -22
  120. package/src/services/gateway-service.ts +0 -20
  121. package/src/services/gopass-secrets.ts +0 -98
  122. package/src/services/in-memory-ai-run-state-service.ts +0 -73
  123. package/src/services/in-memory-trigger-service.ts +0 -64
  124. package/src/services/in-memory-workflow-service.test.ts +0 -351
  125. package/src/services/in-memory-workflow-service.ts +0 -395
  126. package/src/services/index.ts +0 -56
  127. package/src/services/jwt-service.ts +0 -30
  128. package/src/services/local-content.ts +0 -120
  129. package/src/services/local-gateway-service.ts +0 -62
  130. package/src/services/local-secrets.test.ts +0 -80
  131. package/src/services/local-secrets.ts +0 -94
  132. package/src/services/local-variables.test.ts +0 -61
  133. package/src/services/local-variables.ts +0 -39
  134. package/src/services/logger-console.test.ts +0 -118
  135. package/src/services/logger-console.ts +0 -98
  136. package/src/services/logger.ts +0 -57
  137. package/src/services/scheduler-service.ts +0 -86
  138. package/src/services/schema-service.ts +0 -33
  139. package/src/services/scoped-secret-service.test.ts +0 -74
  140. package/src/services/scoped-secret-service.ts +0 -41
  141. package/src/services/secret-service.ts +0 -38
  142. package/src/services/trigger-service.ts +0 -17
  143. package/src/services/typed-secret-service.test.ts +0 -93
  144. package/src/services/typed-secret-service.ts +0 -70
  145. package/src/services/typed-variables-service.test.ts +0 -73
  146. package/src/services/typed-variables-service.ts +0 -81
  147. package/src/services/user-session-service.test.ts +0 -113
  148. package/src/services/user-session-service.ts +0 -86
  149. package/src/services/variables-service.ts +0 -11
  150. package/src/services/workflow-service.ts +0 -84
  151. package/src/time-utils.test.ts +0 -56
  152. package/src/time-utils.ts +0 -107
  153. package/src/types/core.types.ts +0 -470
  154. package/src/types/state.types.ts +0 -186
  155. package/src/utils.test.ts +0 -350
  156. package/src/utils.ts +0 -129
  157. package/src/version.test.ts +0 -80
  158. package/src/version.ts +0 -25
  159. package/src/wirings/ai-agent/ai-agent-assistant-ui.test.ts +0 -363
  160. package/src/wirings/ai-agent/ai-agent-assistant-ui.ts +0 -238
  161. package/src/wirings/ai-agent/ai-agent-helpers.test.ts +0 -152
  162. package/src/wirings/ai-agent/ai-agent-helpers.ts +0 -76
  163. package/src/wirings/ai-agent/ai-agent-memory.ts +0 -309
  164. package/src/wirings/ai-agent/ai-agent-model-config.test.ts +0 -115
  165. package/src/wirings/ai-agent/ai-agent-model-config.ts +0 -43
  166. package/src/wirings/ai-agent/ai-agent-prepare.ts +0 -522
  167. package/src/wirings/ai-agent/ai-agent-registry.test.ts +0 -37
  168. package/src/wirings/ai-agent/ai-agent-registry.ts +0 -82
  169. package/src/wirings/ai-agent/ai-agent-runner.test.ts +0 -317
  170. package/src/wirings/ai-agent/ai-agent-runner.ts +0 -251
  171. package/src/wirings/ai-agent/ai-agent-stream.test.ts +0 -652
  172. package/src/wirings/ai-agent/ai-agent-stream.ts +0 -1060
  173. package/src/wirings/ai-agent/ai-agent.types.ts +0 -360
  174. package/src/wirings/ai-agent/index.ts +0 -41
  175. package/src/wirings/channel/channel-common.ts +0 -90
  176. package/src/wirings/channel/channel-handler.ts +0 -241
  177. package/src/wirings/channel/channel-middleware-runner.ts +0 -120
  178. package/src/wirings/channel/channel-runner.ts +0 -166
  179. package/src/wirings/channel/channel-store.ts +0 -29
  180. package/src/wirings/channel/channel.types.ts +0 -178
  181. package/src/wirings/channel/define-channel-routes.ts +0 -25
  182. package/src/wirings/channel/eventhub-service.ts +0 -34
  183. package/src/wirings/channel/eventhub-store.ts +0 -13
  184. package/src/wirings/channel/index.ts +0 -24
  185. package/src/wirings/channel/local/index.ts +0 -3
  186. package/src/wirings/channel/local/local-channel-handler.ts +0 -79
  187. package/src/wirings/channel/local/local-channel-runner.test.ts +0 -215
  188. package/src/wirings/channel/local/local-channel-runner.ts +0 -200
  189. package/src/wirings/channel/local/local-eventhub-service.test.ts +0 -95
  190. package/src/wirings/channel/local/local-eventhub-service.ts +0 -101
  191. package/src/wirings/channel/log-channels.ts +0 -20
  192. package/src/wirings/channel/pikku-abstract-channel-handler.test.ts +0 -54
  193. package/src/wirings/channel/pikku-abstract-channel-handler.ts +0 -45
  194. package/src/wirings/channel/serverless/index.ts +0 -5
  195. package/src/wirings/channel/serverless/serverless-channel-runner.ts +0 -286
  196. package/src/wirings/cli/channel/cli-channel-runner.ts +0 -136
  197. package/src/wirings/cli/channel/index.ts +0 -1
  198. package/src/wirings/cli/cli-runner.test.ts +0 -403
  199. package/src/wirings/cli/cli-runner.ts +0 -519
  200. package/src/wirings/cli/cli.types.ts +0 -357
  201. package/src/wirings/cli/command-parser.test.ts +0 -445
  202. package/src/wirings/cli/command-parser.ts +0 -504
  203. package/src/wirings/cli/define-cli-commands.ts +0 -24
  204. package/src/wirings/cli/index.ts +0 -19
  205. package/src/wirings/gateway/gateway-runner.test.ts +0 -474
  206. package/src/wirings/gateway/gateway-runner.ts +0 -411
  207. package/src/wirings/gateway/gateway.types.ts +0 -149
  208. package/src/wirings/gateway/index.ts +0 -13
  209. package/src/wirings/http/http-routes.test.ts +0 -322
  210. package/src/wirings/http/http-routes.ts +0 -198
  211. package/src/wirings/http/http-runner.test.ts +0 -144
  212. package/src/wirings/http/http-runner.ts +0 -563
  213. package/src/wirings/http/http.types.ts +0 -378
  214. package/src/wirings/http/index.ts +0 -25
  215. package/src/wirings/http/log-http-routes.ts +0 -22
  216. package/src/wirings/http/pikku-fetch-http-request.test.ts +0 -237
  217. package/src/wirings/http/pikku-fetch-http-request.ts +0 -166
  218. package/src/wirings/http/pikku-fetch-http-response.test.ts +0 -82
  219. package/src/wirings/http/pikku-fetch-http-response.ts +0 -147
  220. package/src/wirings/http/routers/http-router.ts +0 -13
  221. package/src/wirings/http/routers/path-to-regex.test.ts +0 -319
  222. package/src/wirings/http/routers/path-to-regex.ts +0 -126
  223. package/src/wirings/mcp/index.ts +0 -27
  224. package/src/wirings/mcp/mcp-endpoint-registry.test.ts +0 -389
  225. package/src/wirings/mcp/mcp-endpoint-registry.ts +0 -159
  226. package/src/wirings/mcp/mcp-runner.ts +0 -305
  227. package/src/wirings/mcp/mcp.types.ts +0 -216
  228. package/src/wirings/node/index.ts +0 -2
  229. package/src/wirings/node/node.types.ts +0 -23
  230. package/src/wirings/oauth2/index.ts +0 -3
  231. package/src/wirings/oauth2/oauth2-client.test.ts +0 -929
  232. package/src/wirings/oauth2/oauth2-client.ts +0 -335
  233. package/src/wirings/oauth2/oauth2.types.ts +0 -69
  234. package/src/wirings/oauth2/wire-oauth2-credential.ts +0 -23
  235. package/src/wirings/queue/index.ts +0 -31
  236. package/src/wirings/queue/queue-runner.test.ts +0 -710
  237. package/src/wirings/queue/queue-runner.ts +0 -192
  238. package/src/wirings/queue/queue.types.ts +0 -189
  239. package/src/wirings/queue/register-queue-helper.ts +0 -60
  240. package/src/wirings/queue/validate-worker-config.test.ts +0 -108
  241. package/src/wirings/queue/validate-worker-config.ts +0 -116
  242. package/src/wirings/rpc/index.ts +0 -4
  243. package/src/wirings/rpc/rpc-runner.ts +0 -439
  244. package/src/wirings/rpc/rpc-types.ts +0 -51
  245. package/src/wirings/rpc/wire-addon.ts +0 -20
  246. package/src/wirings/scheduler/index.ts +0 -11
  247. package/src/wirings/scheduler/log-schedulers.ts +0 -20
  248. package/src/wirings/scheduler/scheduler-runner.test.ts +0 -660
  249. package/src/wirings/scheduler/scheduler-runner.ts +0 -132
  250. package/src/wirings/scheduler/scheduler.types.ts +0 -53
  251. package/src/wirings/secret/index.ts +0 -9
  252. package/src/wirings/secret/secret.types.ts +0 -32
  253. package/src/wirings/secret/validate-secret-definitions.test.ts +0 -140
  254. package/src/wirings/secret/validate-secret-definitions.ts +0 -82
  255. package/src/wirings/trigger/index.ts +0 -10
  256. package/src/wirings/trigger/pikku-trigger-service.ts +0 -112
  257. package/src/wirings/trigger/trigger-runner.test.ts +0 -79
  258. package/src/wirings/trigger/trigger-runner.ts +0 -135
  259. package/src/wirings/trigger/trigger.types.ts +0 -178
  260. package/src/wirings/variable/index.ts +0 -8
  261. package/src/wirings/variable/validate-variable-definitions.test.ts +0 -91
  262. package/src/wirings/variable/validate-variable-definitions.ts +0 -69
  263. package/src/wirings/variable/variable.types.ts +0 -22
  264. package/src/wirings/workflow/dsl/index.ts +0 -31
  265. package/src/wirings/workflow/dsl/workflow-dsl.types.ts +0 -320
  266. package/src/wirings/workflow/dsl/workflow-runner.ts +0 -28
  267. package/src/wirings/workflow/graph/graph-node.ts +0 -222
  268. package/src/wirings/workflow/graph/graph-runner.test.ts +0 -487
  269. package/src/wirings/workflow/graph/graph-runner.ts +0 -816
  270. package/src/wirings/workflow/graph/index.ts +0 -14
  271. package/src/wirings/workflow/graph/template.test.ts +0 -49
  272. package/src/wirings/workflow/graph/template.ts +0 -42
  273. package/src/wirings/workflow/graph/wire-workflow-graph.ts +0 -29
  274. package/src/wirings/workflow/graph/workflow-graph.types.ts +0 -104
  275. package/src/wirings/workflow/index.ts +0 -81
  276. package/src/wirings/workflow/pikku-workflow-service.test.ts +0 -200
  277. package/src/wirings/workflow/pikku-workflow-service.ts +0 -1165
  278. package/src/wirings/workflow/workflow-helpers.test.ts +0 -129
  279. package/src/wirings/workflow/workflow-helpers.ts +0 -79
  280. package/src/wirings/workflow/workflow.types.ts +0 -266
  281. package/tsconfig.json +0 -14
  282. package/tsconfig.tsbuildinfo +0 -1
@@ -1,445 +0,0 @@
1
- import { test, describe } from 'node:test'
2
- import * as assert from 'assert'
3
- import { parseCLIArguments, generateCommandHelp } from './command-parser.js'
4
- import type { CLIMeta } from './cli.types.js'
5
-
6
- const testMeta: CLIMeta = {
7
- programs: {
8
- 'test-cli': {
9
- program: 'test-cli',
10
- options: {
11
- verbose: {
12
- description: 'Enable verbose output',
13
- short: 'v',
14
- default: false,
15
- },
16
- },
17
- commands: {
18
- greet: {
19
- parameters: '<name>',
20
- pikkuFuncId: 'greetFunc',
21
- positionals: [{ name: 'name', required: true }],
22
- options: {
23
- loud: {
24
- description: 'Use loud greeting',
25
- short: 'l',
26
- default: false,
27
- },
28
- },
29
- },
30
- user: {
31
- pikkuFuncId: '',
32
- positionals: [],
33
- options: {},
34
- subcommands: {
35
- create: {
36
- parameters: '<name> <email>',
37
- pikkuFuncId: 'createUserFunc',
38
- positionals: [
39
- { name: 'name', required: true },
40
- { name: 'email', required: true },
41
- ],
42
- options: {
43
- role: {
44
- description: 'User role',
45
- short: 'r',
46
- default: 'user',
47
- choices: ['admin', 'user', 'guest'],
48
- },
49
- },
50
- },
51
- delete: {
52
- parameters: '<id>',
53
- pikkuFuncId: 'deleteUserFunc',
54
- positionals: [{ name: 'id', required: true }],
55
- options: {
56
- force: {
57
- description: 'Force delete',
58
- short: 'f',
59
- default: false,
60
- },
61
- },
62
- },
63
- },
64
- },
65
- files: {
66
- parameters: '<paths...>',
67
- pikkuFuncId: 'filesFunc',
68
- positionals: [{ name: 'paths', required: true, variadic: true }],
69
- options: {},
70
- },
71
- optional: {
72
- parameters: '[name]',
73
- pikkuFuncId: 'optionalFunc',
74
- positionals: [{ name: 'name', required: false }],
75
- options: {},
76
- },
77
- },
78
- },
79
- },
80
- renderers: {},
81
- }
82
-
83
- describe('Command Parser', () => {
84
- describe('parseCLIArguments', () => {
85
- test('should parse simple command with required positional', () => {
86
- const result = parseCLIArguments(['greet', 'Alice'], 'test-cli', testMeta)
87
-
88
- assert.strictEqual(result.program, 'test-cli')
89
- assert.deepStrictEqual(result.commandPath, ['greet'])
90
- assert.deepStrictEqual(result.positionals, { name: 'Alice' })
91
- assert.strictEqual(result.errors.length, 0)
92
- })
93
-
94
- test('should parse command with boolean flag', () => {
95
- const result = parseCLIArguments(
96
- ['greet', 'Alice', '--loud'],
97
- 'test-cli',
98
- testMeta
99
- )
100
-
101
- assert.deepStrictEqual(result.positionals, { name: 'Alice' })
102
- assert.deepStrictEqual(result.options, { loud: true, verbose: false })
103
- assert.strictEqual(result.errors.length, 0)
104
- })
105
-
106
- test('should parse command with short flag', () => {
107
- const result = parseCLIArguments(
108
- ['greet', 'Alice', '-l'],
109
- 'test-cli',
110
- testMeta
111
- )
112
-
113
- assert.deepStrictEqual(result.options, { loud: true, verbose: false })
114
- assert.strictEqual(result.errors.length, 0)
115
- })
116
-
117
- test('should parse command with option value using space', () => {
118
- const result = parseCLIArguments(
119
- ['user', 'create', 'Bob', 'bob@example.com', '--role', 'admin'],
120
- 'test-cli',
121
- testMeta
122
- )
123
-
124
- assert.deepStrictEqual(result.commandPath, ['user', 'create'])
125
- assert.deepStrictEqual(result.positionals, {
126
- name: 'Bob',
127
- email: 'bob@example.com',
128
- })
129
- assert.deepStrictEqual(result.options, { role: 'admin', verbose: false })
130
- assert.strictEqual(result.errors.length, 0)
131
- })
132
-
133
- test('should parse command with option value using equals', () => {
134
- const result = parseCLIArguments(
135
- ['user', 'create', 'Bob', 'bob@example.com', '--role=admin'],
136
- 'test-cli',
137
- testMeta
138
- )
139
-
140
- assert.deepStrictEqual(result.options, { role: 'admin', verbose: false })
141
- assert.strictEqual(result.errors.length, 0)
142
- })
143
-
144
- test('should parse command with short option and value', () => {
145
- const result = parseCLIArguments(
146
- ['user', 'create', 'Bob', 'bob@example.com', '-r', 'admin'],
147
- 'test-cli',
148
- testMeta
149
- )
150
-
151
- assert.deepStrictEqual(result.options, { role: 'admin', verbose: false })
152
- assert.strictEqual(result.errors.length, 0)
153
- })
154
-
155
- test('should apply default option values', () => {
156
- const result = parseCLIArguments(['greet', 'Alice'], 'test-cli', testMeta)
157
-
158
- assert.deepStrictEqual(result.options, { loud: false, verbose: false })
159
- })
160
-
161
- test('should parse subcommands', () => {
162
- const result = parseCLIArguments(
163
- ['user', 'create', 'Alice', 'alice@example.com'],
164
- 'test-cli',
165
- testMeta
166
- )
167
-
168
- assert.deepStrictEqual(result.commandPath, ['user', 'create'])
169
- assert.deepStrictEqual(result.positionals, {
170
- name: 'Alice',
171
- email: 'alice@example.com',
172
- })
173
- })
174
-
175
- test('should parse variadic positionals', () => {
176
- const result = parseCLIArguments(
177
- ['files', 'file1.txt', 'file2.txt', 'file3.txt'],
178
- 'test-cli',
179
- testMeta
180
- )
181
-
182
- assert.deepStrictEqual(result.positionals, {
183
- paths: ['file1.txt', 'file2.txt', 'file3.txt'],
184
- })
185
- assert.strictEqual(result.errors.length, 0)
186
- })
187
-
188
- test('should parse optional positionals when provided', () => {
189
- const result = parseCLIArguments(
190
- ['optional', 'Alice'],
191
- 'test-cli',
192
- testMeta
193
- )
194
-
195
- assert.deepStrictEqual(result.positionals, { name: 'Alice' })
196
- assert.strictEqual(result.errors.length, 0)
197
- })
198
-
199
- test('should handle missing optional positionals', () => {
200
- const result = parseCLIArguments(['optional'], 'test-cli', testMeta)
201
-
202
- assert.deepStrictEqual(result.positionals, {})
203
- assert.strictEqual(result.errors.length, 0)
204
- })
205
-
206
- test('should handle global options', () => {
207
- const result = parseCLIArguments(
208
- ['greet', 'Alice', '--verbose'],
209
- 'test-cli',
210
- testMeta
211
- )
212
-
213
- assert.deepStrictEqual(result.options, { loud: false, verbose: true })
214
- assert.strictEqual(result.errors.length, 0)
215
- })
216
-
217
- test('should combine multiple short flags', () => {
218
- const result = parseCLIArguments(
219
- ['greet', 'Alice', '-lv'],
220
- 'test-cli',
221
- testMeta
222
- )
223
-
224
- assert.deepStrictEqual(result.options, { loud: true, verbose: true })
225
- assert.strictEqual(result.errors.length, 0)
226
- })
227
-
228
- test('should report error for missing required positional', () => {
229
- const result = parseCLIArguments(['greet'], 'test-cli', testMeta)
230
-
231
- assert.ok(result.errors.length > 0)
232
- assert.ok(result.errors[0].includes('Missing required argument: name'))
233
- })
234
-
235
- test('should report error for invalid choice', () => {
236
- const result = parseCLIArguments(
237
- ['user', 'create', 'Bob', 'bob@example.com', '--role', 'invalid'],
238
- 'test-cli',
239
- testMeta
240
- )
241
-
242
- assert.ok(result.errors.length > 0)
243
- assert.ok(result.errors[0].includes('Invalid value'))
244
- })
245
-
246
- test('should report error for unknown option', () => {
247
- const result = parseCLIArguments(
248
- ['greet', 'Alice', '--unknown'],
249
- 'test-cli',
250
- testMeta
251
- )
252
-
253
- // Unknown options are allowed (for forward compatibility)
254
- // They just won't have defaults or validation
255
- assert.strictEqual(result.options.unknown, true)
256
- })
257
-
258
- test('should report error for unknown short flag', () => {
259
- const result = parseCLIArguments(
260
- ['greet', 'Alice', '-x'],
261
- 'test-cli',
262
- testMeta
263
- )
264
-
265
- assert.ok(result.errors.length > 0)
266
- assert.ok(result.errors[0].includes('Unknown option: -x'))
267
- })
268
-
269
- test('should report error for extra positional arguments', () => {
270
- const result = parseCLIArguments(
271
- ['greet', 'Alice', 'Bob'],
272
- 'test-cli',
273
- testMeta
274
- )
275
-
276
- assert.ok(result.errors.length > 0)
277
- assert.ok(result.errors[0].includes('Unexpected arguments'))
278
- })
279
-
280
- test('should report error for unknown command', () => {
281
- const result = parseCLIArguments(['unknown'], 'test-cli', testMeta)
282
-
283
- assert.ok(result.errors.length > 0)
284
- assert.ok(result.errors[0].includes('Unknown command'))
285
- })
286
-
287
- test('should report error for nonexistent program', () => {
288
- const result = parseCLIArguments(['test'], 'nonexistent', testMeta)
289
-
290
- assert.ok(result.errors.length > 0)
291
- assert.ok(result.errors[0].includes('Program not found'))
292
- })
293
-
294
- test('should parse number values correctly', () => {
295
- const metaWithNumber: CLIMeta = {
296
- programs: {
297
- 'num-cli': {
298
- program: 'num-cli',
299
- options: {},
300
- commands: {
301
- test: {
302
- pikkuFuncId: 'testFunc',
303
- positionals: [],
304
- options: {
305
- port: {
306
- description: 'Port number',
307
- default: 3000,
308
- },
309
- },
310
- },
311
- },
312
- },
313
- },
314
- renderers: {},
315
- }
316
-
317
- const result = parseCLIArguments(
318
- ['test', '--port', '8080'],
319
- 'num-cli',
320
- metaWithNumber
321
- )
322
-
323
- assert.strictEqual(result.options.port, 8080)
324
- assert.strictEqual(typeof result.options.port, 'number')
325
- })
326
-
327
- test('should parse boolean values correctly', () => {
328
- const result = parseCLIArguments(
329
- ['greet', 'Alice', '--loud', 'true'],
330
- 'test-cli',
331
- testMeta
332
- )
333
-
334
- assert.strictEqual(result.options.loud, true)
335
- })
336
-
337
- test('should handle empty variadic positionals when required', () => {
338
- const result = parseCLIArguments(['files'], 'test-cli', testMeta)
339
-
340
- assert.ok(result.errors.length > 0)
341
- assert.ok(result.errors[0].includes('Missing required argument: paths'))
342
- })
343
- })
344
-
345
- describe('generateCommandHelp', () => {
346
- test('should generate help for program root', () => {
347
- const help = generateCommandHelp('test-cli', testMeta)
348
-
349
- assert.ok(help.includes('Usage: test-cli <command>'))
350
- assert.ok(help.includes('Commands:'))
351
- assert.ok(help.includes('greet'))
352
- assert.ok(help.includes('Options:'))
353
- assert.ok(help.includes('--verbose'))
354
- })
355
-
356
- test('should generate help for specific command', () => {
357
- const help = generateCommandHelp('test-cli', testMeta, ['greet'])
358
-
359
- assert.ok(help.includes('Usage: test-cli greet'))
360
- assert.ok(help.includes('<name>'))
361
- assert.ok(help.includes('--loud'))
362
- assert.ok(help.includes('Use loud greeting'))
363
- })
364
-
365
- test('should generate help for subcommand', () => {
366
- const help = generateCommandHelp('test-cli', testMeta, ['user', 'create'])
367
-
368
- assert.ok(help.includes('Usage: test-cli user create'))
369
- assert.ok(help.includes('<name>'))
370
- assert.ok(help.includes('<email>'))
371
- assert.ok(help.includes('--role'))
372
- })
373
-
374
- test('should show command description if available', () => {
375
- const metaWithDesc: CLIMeta = {
376
- programs: {
377
- 'test-cli': {
378
- program: 'test-cli',
379
- options: {},
380
- commands: {
381
- greet: {
382
- parameters: '<name>',
383
- pikkuFuncId: 'greetFunc',
384
- description: 'Greet a user',
385
- positionals: [{ name: 'name', required: true }],
386
- options: {},
387
- },
388
- },
389
- },
390
- },
391
- renderers: {},
392
- }
393
-
394
- const help = generateCommandHelp('test-cli', metaWithDesc, ['greet'])
395
-
396
- assert.ok(help.includes('Greet a user'))
397
- })
398
-
399
- test('should show option defaults in help', () => {
400
- const help = generateCommandHelp('test-cli', testMeta, ['greet'])
401
-
402
- assert.ok(help.includes('(default: false)'))
403
- })
404
-
405
- test('should show option choices in help', () => {
406
- const help = generateCommandHelp('test-cli', testMeta, ['user', 'create'])
407
-
408
- assert.ok(help.includes('[choices: admin, user, guest]'))
409
- })
410
-
411
- test('should show subcommands in help', () => {
412
- const help = generateCommandHelp('test-cli', testMeta, ['user'])
413
-
414
- assert.ok(help.includes('Subcommands:'))
415
- assert.ok(help.includes('create'))
416
- assert.ok(help.includes('delete'))
417
- })
418
-
419
- test('should show variadic positionals in help', () => {
420
- const help = generateCommandHelp('test-cli', testMeta, ['files'])
421
-
422
- assert.ok(help.includes('paths...'))
423
- assert.ok(help.includes('<required>'))
424
- })
425
-
426
- test('should show optional positionals in help', () => {
427
- const help = generateCommandHelp('test-cli', testMeta, ['optional'])
428
-
429
- assert.ok(help.includes('name'))
430
- assert.ok(help.includes('[optional]'))
431
- })
432
-
433
- test('should return error for nonexistent program', () => {
434
- const help = generateCommandHelp('nonexistent', testMeta)
435
-
436
- assert.ok(help.includes('Program not found'))
437
- })
438
-
439
- test('should return error for nonexistent command', () => {
440
- const help = generateCommandHelp('test-cli', testMeta, ['nonexistent'])
441
-
442
- assert.ok(help.includes('Unknown command'))
443
- })
444
- })
445
- })