@pikku/inspector 0.12.75 → 0.12.81

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 (219) hide show
  1. package/CHANGELOG.md +330 -0
  2. package/dist/add/add-analytics.d.ts +9 -0
  3. package/dist/add/add-analytics.js +178 -0
  4. package/dist/add/add-auth.js +0 -54
  5. package/dist/add/add-feature-flag.d.ts +2 -0
  6. package/dist/add/add-feature-flag.js +162 -0
  7. package/dist/add/add-wire-addon.js +1 -0
  8. package/dist/add/add-wire-remote-addon.js +1 -0
  9. package/dist/index.d.ts +3 -1
  10. package/dist/index.js +3 -1
  11. package/dist/inspector.js +4 -0
  12. package/dist/surface/collect-surface.d.ts +58 -0
  13. package/dist/surface/collect-surface.js +613 -0
  14. package/dist/types.d.ts +20 -11
  15. package/dist/utils/filter-inspector-state.js +14 -0
  16. package/dist/utils/post-process.js +15 -0
  17. package/dist/utils/read-module-specifiers.d.ts +8 -0
  18. package/dist/utils/read-module-specifiers.js +23 -0
  19. package/dist/utils/read-tsconfig-out-dir.d.ts +5 -0
  20. package/dist/utils/read-tsconfig-out-dir.js +12 -0
  21. package/dist/utils/resolve-deploy-target.d.ts +7 -0
  22. package/dist/utils/resolve-deploy-target.js +15 -7
  23. package/dist/utils/serialize-inspector-state.d.ts +5 -0
  24. package/dist/utils/serialize-inspector-state.js +8 -0
  25. package/dist/visit.js +4 -0
  26. package/package.json +16 -6
  27. package/run-tests.sh +21 -6
  28. package/src/add/add-addon-bans.ts +0 -85
  29. package/src/add/add-agent-scorer.test.ts +0 -197
  30. package/src/add/add-agent-scorer.ts +0 -83
  31. package/src/add/add-agent.test.ts +0 -87
  32. package/src/add/add-agent.ts +0 -638
  33. package/src/add/add-approval-description.ts +0 -76
  34. package/src/add/add-auth.test.ts +0 -791
  35. package/src/add/add-auth.ts +0 -424
  36. package/src/add/add-channel.ts +0 -778
  37. package/src/add/add-cli-renderers.test.ts +0 -74
  38. package/src/add/add-cli.ts +0 -1006
  39. package/src/add/add-credential.ts +0 -186
  40. package/src/add/add-feature.test.ts +0 -306
  41. package/src/add/add-feature.ts +0 -253
  42. package/src/add/add-file-extends-core-type.ts +0 -66
  43. package/src/add/add-file-with-config.ts +0 -45
  44. package/src/add/add-file-with-factory.test.ts +0 -134
  45. package/src/add/add-file-with-factory.ts +0 -288
  46. package/src/add/add-functions.test.ts +0 -743
  47. package/src/add/add-functions.ts +0 -1548
  48. package/src/add/add-gateway.ts +0 -143
  49. package/src/add/add-http-route-ref.test.ts +0 -149
  50. package/src/add/add-http-route.ts +0 -530
  51. package/src/add/add-http-routes.ts +0 -471
  52. package/src/add/add-keyed-wiring.ts +0 -180
  53. package/src/add/add-mcp-prompt.ts +0 -157
  54. package/src/add/add-mcp-resource.ts +0 -175
  55. package/src/add/add-middleware.test.ts +0 -196
  56. package/src/add/add-middleware.ts +0 -879
  57. package/src/add/add-permission-auth.test.ts +0 -59
  58. package/src/add/add-permission.ts +0 -311
  59. package/src/add/add-personas.test.ts +0 -406
  60. package/src/add/add-personas.ts +0 -287
  61. package/src/add/add-queue-worker.ts +0 -117
  62. package/src/add/add-rpc-invocations.test.ts +0 -287
  63. package/src/add/add-rpc-invocations.ts +0 -221
  64. package/src/add/add-scenario-step.test.ts +0 -509
  65. package/src/add/add-schedule.ts +0 -120
  66. package/src/add/add-scope.test.ts +0 -419
  67. package/src/add/add-scope.ts +0 -221
  68. package/src/add/add-secret.ts +0 -10
  69. package/src/add/add-subject-scenario-steps.test.ts +0 -161
  70. package/src/add/add-system-role.test.ts +0 -297
  71. package/src/add/add-system-role.ts +0 -162
  72. package/src/add/add-trigger.ts +0 -165
  73. package/src/add/add-variable.ts +0 -10
  74. package/src/add/add-wire-addon.test.ts +0 -185
  75. package/src/add/add-wire-addon.ts +0 -146
  76. package/src/add/add-wire-remote-addon.ts +0 -80
  77. package/src/add/add-workflow-edge-cases.test.ts +0 -201
  78. package/src/add/add-workflow-fanout.test.ts +0 -166
  79. package/src/add/add-workflow-graph-foreach.test.ts +0 -174
  80. package/src/add/add-workflow-graph-input.test.ts +0 -94
  81. package/src/add/add-workflow-graph-notes.test.ts +0 -74
  82. package/src/add/add-workflow-graph.ts +0 -644
  83. package/src/add/add-workflow-on-error.test.ts +0 -118
  84. package/src/add/add-workflow-return-switch.test.ts +0 -121
  85. package/src/add/add-workflow-silent-drops.test.ts +0 -261
  86. package/src/add/add-workflow-sleep-expression.test.ts +0 -96
  87. package/src/add/add-workflow.test.ts +0 -155
  88. package/src/add/add-workflow.ts +0 -482
  89. package/src/add/addon-bans.test.ts +0 -121
  90. package/src/add/addon-contracts.test.ts +0 -221
  91. package/src/add/allow-escape-hatches.test.ts +0 -144
  92. package/src/add/audit-meta.test.ts +0 -75
  93. package/src/add/classified-sink-check.test.ts +0 -347
  94. package/src/add/config-value-metadata.test.ts +0 -263
  95. package/src/add/dynamic-import-check.test.ts +0 -119
  96. package/src/add/expect-eventually-scenario-only.test.ts +0 -108
  97. package/src/add/function-body-span.test.ts +0 -96
  98. package/src/add/inline-wiring-function.test.ts +0 -104
  99. package/src/add/pii-check.test.ts +0 -258
  100. package/src/add/rpc-type-cast.test.ts +0 -123
  101. package/src/add/scenario-instrumentation.test.ts +0 -89
  102. package/src/add/scenario-instrumentation.ts +0 -42
  103. package/src/add/scenario-marker.test.ts +0 -89
  104. package/src/add/scenario-not-extractable.test.ts +0 -159
  105. package/src/add/scenario-services.test.ts +0 -103
  106. package/src/add/scenario-skip.test.ts +0 -83
  107. package/src/add/validate-workflow-graph-addons.test.ts +0 -102
  108. package/src/add/wire-name-literal.test.ts +0 -117
  109. package/src/error-codes-emitted.test.ts +0 -76
  110. package/src/error-codes.ts +0 -145
  111. package/src/index.ts +0 -66
  112. package/src/inspector.ts +0 -575
  113. package/src/schema-generator.ts +0 -1
  114. package/src/source-file-cache.ts +0 -73
  115. package/src/tsconfig-paths.test.ts +0 -90
  116. package/src/types-map.ts +0 -141
  117. package/src/types.ts +0 -775
  118. package/src/utils/annotate-http-route-auth.test.ts +0 -161
  119. package/src/utils/annotate-http-route-auth.ts +0 -53
  120. package/src/utils/check-classified-sinks.ts +0 -215
  121. package/src/utils/check-pii-output.ts +0 -120
  122. package/src/utils/compute-diagnostics.test.ts +0 -106
  123. package/src/utils/compute-required-schemas.ts +0 -48
  124. package/src/utils/contract-hashes.test.ts +0 -553
  125. package/src/utils/contract-hashes.ts +0 -387
  126. package/src/utils/custom-types-generator.test.ts +0 -124
  127. package/src/utils/custom-types-generator.ts +0 -150
  128. package/src/utils/detect-schema-vendor.test.ts +0 -123
  129. package/src/utils/detect-schema-vendor.ts +0 -120
  130. package/src/utils/does-type-extend-core-type.ts +0 -53
  131. package/src/utils/ensure-function-metadata.ts +0 -385
  132. package/src/utils/extract-function-name.ts +0 -612
  133. package/src/utils/extract-function-node.ts +0 -70
  134. package/src/utils/extract-node-value.test.ts +0 -117
  135. package/src/utils/extract-node-value.ts +0 -172
  136. package/src/utils/extract-secret-usage.test.ts +0 -81
  137. package/src/utils/extract-secret-usage.ts +0 -73
  138. package/src/utils/extract-services.ts +0 -70
  139. package/src/utils/extract-surface-usage.test.ts +0 -147
  140. package/src/utils/extract-surface-usage.ts +0 -121
  141. package/src/utils/filter-inspector-state.test.ts +0 -2232
  142. package/src/utils/filter-inspector-state.ts +0 -1298
  143. package/src/utils/filter-utils.test.ts +0 -843
  144. package/src/utils/filter-utils.ts +0 -161
  145. package/src/utils/find-root-dir.ts +0 -68
  146. package/src/utils/find-zod-transform.test.ts +0 -70
  147. package/src/utils/find-zod-transform.ts +0 -103
  148. package/src/utils/get-exported-variable-name.ts +0 -48
  149. package/src/utils/get-files-and-methods.ts +0 -157
  150. package/src/utils/get-property-value.test.ts +0 -141
  151. package/src/utils/get-property-value.ts +0 -331
  152. package/src/utils/hash.ts +0 -26
  153. package/src/utils/literal-properties.ts +0 -97
  154. package/src/utils/load-addon-functions-meta.test.ts +0 -157
  155. package/src/utils/load-addon-functions-meta.ts +0 -508
  156. package/src/utils/load-addon-scopes.test.ts +0 -138
  157. package/src/utils/middleware.test.ts +0 -204
  158. package/src/utils/middleware.ts +0 -303
  159. package/src/utils/nested-project-filter.test.ts +0 -53
  160. package/src/utils/nested-project-filter.ts +0 -28
  161. package/src/utils/permissions-shorthand.test.ts +0 -79
  162. package/src/utils/permissions.test.ts +0 -125
  163. package/src/utils/permissions.ts +0 -129
  164. package/src/utils/post-process.test.ts +0 -1094
  165. package/src/utils/post-process.ts +0 -1604
  166. package/src/utils/resolve-addon-package.ts +0 -106
  167. package/src/utils/resolve-core-type.test.ts +0 -142
  168. package/src/utils/resolve-core-type.ts +0 -35
  169. package/src/utils/resolve-deploy-target.test.ts +0 -135
  170. package/src/utils/resolve-deploy-target.ts +0 -65
  171. package/src/utils/resolve-function-meta.ts +0 -25
  172. package/src/utils/resolve-function-types.ts +0 -42
  173. package/src/utils/resolve-identifier.ts +0 -46
  174. package/src/utils/resolve-ref-contract.ts +0 -71
  175. package/src/utils/resolve-versions.test.ts +0 -499
  176. package/src/utils/resolve-versions.ts +0 -228
  177. package/src/utils/schema-cache.test.ts +0 -124
  178. package/src/utils/schema-generator.test.ts +0 -272
  179. package/src/utils/schema-generator.ts +0 -780
  180. package/src/utils/secret-alias-services.test.ts +0 -146
  181. package/src/utils/secret-alias-services.ts +0 -58
  182. package/src/utils/serialize-inspector-state.ts +0 -742
  183. package/src/utils/serialize-mcp-json.ts +0 -150
  184. package/src/utils/serialize-middleware-groups-meta.ts +0 -36
  185. package/src/utils/serialize-openapi-json.ts +0 -277
  186. package/src/utils/serialize-permissions-groups-meta.ts +0 -7
  187. package/src/utils/single-declaration.ts +0 -57
  188. package/src/utils/type-utils.ts +0 -145
  189. package/src/utils/validate-auth-sessionless.ts +0 -30
  190. package/src/utils/validate-exposed-functions-gated.test.ts +0 -230
  191. package/src/utils/validate-exposed-functions-gated.ts +0 -103
  192. package/src/utils/validate-tags-resolve-to-middleware.test.ts +0 -108
  193. package/src/utils/validate-tags-resolve-to-middleware.ts +0 -48
  194. package/src/utils/workflow/derive-workflow-plan.test.ts +0 -178
  195. package/src/utils/workflow/derive-workflow-plan.ts +0 -117
  196. package/src/utils/workflow/dsl/deserialize-dsl-workflow.ts +0 -1465
  197. package/src/utils/workflow/dsl/deserialize-fanout-body.test.ts +0 -71
  198. package/src/utils/workflow/dsl/deserialize-fanout-fidelity.test.ts +0 -99
  199. package/src/utils/workflow/dsl/deserialize-graph-next.test.ts +0 -161
  200. package/src/utils/workflow/dsl/deserialize-roundtrip-bindings.test.ts +0 -121
  201. package/src/utils/workflow/dsl/deserialize-roundtrip-values.test.ts +0 -116
  202. package/src/utils/workflow/dsl/deserialize-roundtrip.test.ts +0 -145
  203. package/src/utils/workflow/dsl/extract-approval-policy.test.ts +0 -71
  204. package/src/utils/workflow/dsl/extract-dsl-workflow.ts +0 -2254
  205. package/src/utils/workflow/dsl/index.ts +0 -11
  206. package/src/utils/workflow/dsl/patterns.ts +0 -440
  207. package/src/utils/workflow/dsl/validation.ts +0 -203
  208. package/src/utils/workflow/graph/convert-dsl-to-graph-skip.test.ts +0 -35
  209. package/src/utils/workflow/graph/convert-dsl-to-graph.ts +0 -543
  210. package/src/utils/workflow/graph/fanout-node-identity.test.ts +0 -105
  211. package/src/utils/workflow/graph/finalize-workflow-wires.ts +0 -310
  212. package/src/utils/workflow/graph/finalize-workflows.test.ts +0 -50
  213. package/src/utils/workflow/graph/finalize-workflows.ts +0 -130
  214. package/src/utils/workflow/graph/index.ts +0 -28
  215. package/src/utils/workflow/graph/serialize-workflow-graph.ts +0 -240
  216. package/src/utils/workflow/graph/workflow-graph.types.ts +0 -281
  217. package/src/visit.ts +0 -181
  218. package/tsconfig.json +0 -19
  219. package/tsconfig.tsbuildinfo +0 -1
@@ -1,186 +0,0 @@
1
- import * as ts from 'typescript'
2
- import {
3
- getPropertyValue,
4
- getArrayPropertyValue,
5
- getRecordPropertyValue,
6
- assertStringLiteralProperty,
7
- } from '../utils/get-property-value.js'
8
- import type { AddWiring } from '../types.js'
9
- import { ErrorCode } from '../error-codes.js'
10
- import { detectSchemaVendorOrError } from '../utils/detect-schema-vendor.js'
11
-
12
- export const addCredential: AddWiring = (
13
- logger,
14
- node,
15
- checker,
16
- state,
17
- _options
18
- ) => {
19
- if (!ts.isCallExpression(node)) {
20
- return
21
- }
22
-
23
- const args = node.arguments
24
- const firstArg = args[0]
25
- const expression = node.expression
26
-
27
- if (!ts.isIdentifier(expression) || expression.text !== 'defineCredential') {
28
- return
29
- }
30
-
31
- if (!firstArg) {
32
- return
33
- }
34
-
35
- if (ts.isObjectLiteralExpression(firstArg)) {
36
- const obj = firstArg
37
-
38
- assertStringLiteralProperty(obj, 'name', 'Credential', logger)
39
-
40
- const nameValue = getPropertyValue(obj, 'name') as string | null
41
- const displayNameValue = getPropertyValue(obj, 'displayName') as
42
- string | null
43
- const descriptionValue = getPropertyValue(obj, 'description') as
44
- string | null
45
- const typeValue = getPropertyValue(obj, 'type') as string | null
46
- const docsUrlValue = getPropertyValue(obj, 'docsUrl') as string | null
47
-
48
- if (!nameValue) {
49
- logger.critical(
50
- ErrorCode.MISSING_NAME,
51
- "Credential is missing the required 'name' property."
52
- )
53
- return
54
- }
55
-
56
- if (!displayNameValue) {
57
- logger.critical(
58
- ErrorCode.MISSING_NAME,
59
- `Credential '${nameValue}' is missing the required 'displayName' property.`
60
- )
61
- return
62
- }
63
-
64
- if (!typeValue || (typeValue !== 'singleton' && typeValue !== 'wire')) {
65
- logger.critical(
66
- ErrorCode.MISSING_NAME,
67
- `Credential '${nameValue}' is missing or has invalid 'type' property. Must be 'singleton' or 'wire'.`
68
- )
69
- return
70
- }
71
-
72
- let schemaVariableName: string | null = null
73
- let schemaSourceFile: string | null = null
74
- let schemaIdentifier: ts.Identifier | null = null
75
- for (const prop of obj.properties) {
76
- if (
77
- ts.isPropertyAssignment(prop) &&
78
- ts.isIdentifier(prop.name) &&
79
- prop.name.text === 'schema'
80
- ) {
81
- if (ts.isIdentifier(prop.initializer)) {
82
- schemaVariableName = prop.initializer.text
83
- schemaIdentifier = prop.initializer
84
-
85
- const symbol = checker.getSymbolAtLocation(prop.initializer)
86
- if (symbol) {
87
- const decl = symbol.valueDeclaration || symbol.declarations?.[0]
88
- if (decl) {
89
- if (ts.isImportSpecifier(decl)) {
90
- const aliasedSymbol = checker.getAliasedSymbol(symbol)
91
- if (aliasedSymbol) {
92
- const aliasedDecl =
93
- aliasedSymbol.valueDeclaration ||
94
- aliasedSymbol.declarations?.[0]
95
- if (aliasedDecl) {
96
- schemaSourceFile = aliasedDecl.getSourceFile().fileName
97
- }
98
- }
99
- } else {
100
- schemaSourceFile = decl.getSourceFile().fileName
101
- }
102
- }
103
- }
104
- }
105
- break
106
- }
107
- }
108
-
109
- let oauth2: any = undefined
110
- const oauth2Prop = obj.properties.find(
111
- (p) =>
112
- ts.isPropertyAssignment(p) &&
113
- ts.isIdentifier(p.name) &&
114
- p.name.text === 'oauth2'
115
- )
116
- if (
117
- oauth2Prop &&
118
- ts.isPropertyAssignment(oauth2Prop) &&
119
- ts.isObjectLiteralExpression(oauth2Prop.initializer)
120
- ) {
121
- const oauth2Obj = oauth2Prop.initializer
122
- const appCredentialSecretId = getPropertyValue(
123
- oauth2Obj,
124
- 'appCredentialSecretId'
125
- ) as string | null
126
- const tokenSecretId = getPropertyValue(oauth2Obj, 'tokenSecretId') as
127
- string | null
128
- const authorizationUrl = getPropertyValue(
129
- oauth2Obj,
130
- 'authorizationUrl'
131
- ) as string | null
132
- const tokenUrl = getPropertyValue(oauth2Obj, 'tokenUrl') as string | null
133
- const scopes = getArrayPropertyValue(oauth2Obj, 'scopes')
134
- const pkce = getPropertyValue(oauth2Obj, 'pkce') as boolean | null
135
- const additionalParams = getRecordPropertyValue(
136
- oauth2Obj,
137
- 'additionalParams'
138
- )
139
-
140
- if (appCredentialSecretId && authorizationUrl && tokenUrl && scopes) {
141
- oauth2 = {
142
- appCredentialSecretId,
143
- tokenSecretId: tokenSecretId || undefined,
144
- authorizationUrl,
145
- tokenUrl,
146
- scopes,
147
- pkce: pkce || undefined,
148
- additionalParams: additionalParams || undefined,
149
- }
150
- }
151
- }
152
-
153
- const sourceFile = node.getSourceFile().fileName
154
- state.credentials.files.add(sourceFile)
155
-
156
- let schemaLookupName: string | undefined
157
- if (schemaVariableName && schemaSourceFile && schemaIdentifier) {
158
- const vendor = detectSchemaVendorOrError(
159
- schemaIdentifier,
160
- checker,
161
- logger,
162
- `Credential '${nameValue}'`,
163
- schemaSourceFile
164
- )
165
- if (vendor) {
166
- schemaLookupName = `CredentialSchema_${nameValue}`
167
- state.schemaLookup.set(schemaLookupName, {
168
- variableName: schemaVariableName,
169
- sourceFile: schemaSourceFile,
170
- vendor,
171
- })
172
- }
173
- }
174
-
175
- state.credentials.definitions.push({
176
- name: nameValue,
177
- displayName: displayNameValue,
178
- description: descriptionValue || undefined,
179
- type: typeValue as 'singleton' | 'wire',
180
- docsUrl: docsUrlValue || undefined,
181
- schema: schemaLookupName,
182
- oauth2,
183
- sourceFile,
184
- })
185
- }
186
- }
@@ -1,306 +0,0 @@
1
- import { strict as assert } from 'assert'
2
- import { describe, test } from 'node:test'
3
- import { mkdtemp, rm, writeFile } from 'node:fs/promises'
4
- import { tmpdir } from 'node:os'
5
- import { join } from 'node:path'
6
- import { inspect } from '../inspector.js'
7
- import type { InspectorLogger } from '../types.js'
8
-
9
- function makeLogger(
10
- criticals: Array<{ code: string; message: string }>
11
- ): InspectorLogger {
12
- return {
13
- debug: () => {},
14
- info: () => {},
15
- warn: () => {},
16
- error: () => {},
17
- diagnostic: ({ code, message }: any) => {
18
- criticals.push({ code, message })
19
- },
20
- critical: (code: any, message: string) => {
21
- criticals.push({ code, message })
22
- },
23
- hasCriticalErrors: () => criticals.length > 0,
24
- } as InspectorLogger
25
- }
26
-
27
- const SCENARIOS = [
28
- "import { pikkuScenario } from '@pikku/core/workflow'",
29
- 'export const lazyLoadScenario = pikkuScenario({',
30
- " title: 'A credential is loaded on first use',",
31
- " tags: ['credential'],",
32
- ' func: async () => ({ ok: true }),',
33
- '})',
34
- 'export const roundTripScenario = pikkuScenario({',
35
- " title: 'A credential round-trips',",
36
- ' func: async (_services, _data: { name: string }) => ({ ok: true }),',
37
- '})',
38
- ].join('\n')
39
-
40
- async function run(featureSource: string) {
41
- const rootDir = await mkdtemp(join(tmpdir(), 'pikku-feature-'))
42
- const scenarioFile = join(rootDir, 'credential.scenario.ts')
43
- const featureFile = join(rootDir, 'credential.feature.ts')
44
- await writeFile(scenarioFile, SCENARIOS)
45
- await writeFile(featureFile, featureSource)
46
- const criticals: Array<{ code: string; message: string }> = []
47
- const state = await inspect(
48
- makeLogger(criticals),
49
- [scenarioFile, featureFile],
50
- { rootDir }
51
- )
52
- return {
53
- state,
54
- criticals,
55
- featureFile,
56
- cleanup: () => rm(rootDir, { recursive: true, force: true }),
57
- }
58
- }
59
-
60
- describe('addFeature', () => {
61
- test('records where a feature is exported from', async () => {
62
- const { state, criticals, featureFile, cleanup } = await run(
63
- [
64
- "import { pikkuFeature } from '@pikku/core/workflow'",
65
- "import { lazyLoadScenario } from './credential.scenario.js'",
66
- 'export const credentialFeature = pikkuFeature({',
67
- " name: 'Credential API',",
68
- " tags: ['credential'],",
69
- ' scenarios: [lazyLoadScenario],',
70
- '})',
71
- ].join('\n')
72
- )
73
- try {
74
- assert.deepEqual(criticals, [])
75
- assert.deepEqual(
76
- [...state.workflows.featureFiles.entries()],
77
- [
78
- [
79
- 'credentialFeature',
80
- {
81
- path: featureFile,
82
- exportedName: 'credentialFeature',
83
- name: 'Credential API',
84
- tags: ['credential'],
85
- entries: [{ scenario: 'lazyLoadScenario' }],
86
- unresolvedEntries: 0,
87
- hasBefore: false,
88
- hasAfter: false,
89
- },
90
- ],
91
- ]
92
- )
93
- } finally {
94
- await cleanup()
95
- }
96
- })
97
-
98
- test('extracts the feature name, description and tags', async () => {
99
- const { state, criticals, cleanup } = await run(
100
- [
101
- "import { pikkuFeature } from '@pikku/core/workflow'",
102
- "import { lazyLoadScenario } from './credential.scenario.js'",
103
- 'export const credentialFeature = pikkuFeature({',
104
- " name: 'Credential API',",
105
- " description: 'How credentials are loaded and rotated',",
106
- " tags: ['credential', 'console'],",
107
- ' scenarios: [lazyLoadScenario],',
108
- '})',
109
- ].join('\n')
110
- )
111
- try {
112
- assert.deepEqual(criticals, [])
113
- const feature = state.workflows.featureFiles.get('credentialFeature')!
114
- assert.equal(feature.name, 'Credential API')
115
- assert.equal(
116
- feature.description,
117
- 'How credentials are loaded and rotated'
118
- )
119
- assert.deepEqual(feature.tags, ['credential', 'console'])
120
- } finally {
121
- await cleanup()
122
- }
123
- })
124
-
125
- test('resolves a literal scenarios array to scenario names, in order', async () => {
126
- const { state, criticals, cleanup } = await run(
127
- [
128
- "import { pikkuFeature } from '@pikku/core/workflow'",
129
- "import { lazyLoadScenario, roundTripScenario } from './credential.scenario.js'",
130
- 'export const credentialFeature = pikkuFeature({',
131
- " name: 'Credential API',",
132
- ' scenarios: [roundTripScenario, lazyLoadScenario],',
133
- '})',
134
- ].join('\n')
135
- )
136
- try {
137
- assert.deepEqual(criticals, [])
138
- const feature = state.workflows.featureFiles.get('credentialFeature')!
139
- assert.deepEqual(feature.entries, [
140
- { scenario: 'roundTripScenario' },
141
- { scenario: 'lazyLoadScenario' },
142
- ])
143
- assert.equal(feature.unresolvedEntries, 0)
144
- } finally {
145
- await cleanup()
146
- }
147
- })
148
-
149
- test('resolves an aliased import back to the declared scenario name', async () => {
150
- const { state, criticals, cleanup } = await run(
151
- [
152
- "import { pikkuFeature } from '@pikku/core/workflow'",
153
- "import { lazyLoadScenario as lazy } from './credential.scenario.js'",
154
- 'export const credentialFeature = pikkuFeature({',
155
- " name: 'Credential API',",
156
- ' scenarios: [lazy],',
157
- '})',
158
- ].join('\n')
159
- )
160
- try {
161
- assert.deepEqual(criticals, [])
162
- assert.deepEqual(
163
- state.workflows.featureFiles.get('credentialFeature')!.entries,
164
- [{ scenario: 'lazyLoadScenario' }]
165
- )
166
- } finally {
167
- await cleanup()
168
- }
169
- })
170
-
171
- test('resolves a { scenario, data } entry with its literal data', async () => {
172
- const { state, criticals, cleanup } = await run(
173
- [
174
- "import { pikkuFeature } from '@pikku/core/workflow'",
175
- "import { roundTripScenario } from './credential.scenario.js'",
176
- 'export const credentialFeature = pikkuFeature({',
177
- " name: 'Credential API',",
178
- ' scenarios: [',
179
- " { scenario: roundTripScenario, data: { name: 'stripe', retries: 2 } },",
180
- " { scenario: roundTripScenario, data: { name: 'google', retries: 0 } },",
181
- ' ],',
182
- '})',
183
- ].join('\n')
184
- )
185
- try {
186
- assert.deepEqual(criticals, [])
187
- assert.deepEqual(
188
- state.workflows.featureFiles.get('credentialFeature')!.entries,
189
- [
190
- {
191
- scenario: 'roundTripScenario',
192
- data: { name: 'stripe', retries: 2 },
193
- },
194
- {
195
- scenario: 'roundTripScenario',
196
- data: { name: 'google', retries: 0 },
197
- },
198
- ]
199
- )
200
- } finally {
201
- await cleanup()
202
- }
203
- })
204
-
205
- test('records whether the feature has before/after hooks', async () => {
206
- const { state, criticals, cleanup } = await run(
207
- [
208
- "import { pikkuFeature } from '@pikku/core/workflow'",
209
- "import { lazyLoadScenario } from './credential.scenario.js'",
210
- 'export const credentialFeature = pikkuFeature({',
211
- " name: 'Credential API',",
212
- ' before: async () => {},',
213
- ' scenarios: [lazyLoadScenario],',
214
- '})',
215
- ].join('\n')
216
- )
217
- try {
218
- assert.deepEqual(criticals, [])
219
- const feature = state.workflows.featureFiles.get('credentialFeature')!
220
- assert.equal(feature.hasBefore, true)
221
- assert.equal(feature.hasAfter, false)
222
- } finally {
223
- await cleanup()
224
- }
225
- })
226
-
227
- test('a feature built by a loop keeps its literal entries and counts the rest', async () => {
228
- // A spread of `.map()` cannot be enumerated statically — membership for it
229
- // is resolved at runtime by object identity. Everything literal alongside it
230
- // is still extracted, and the dynamic portion is counted rather than lost.
231
- const { state, criticals, cleanup } = await run(
232
- [
233
- "import { pikkuFeature } from '@pikku/core/workflow'",
234
- "import { lazyLoadScenario, roundTripScenario } from './credential.scenario.js'",
235
- 'export const credentialFeature = pikkuFeature({',
236
- " name: 'Credential API',",
237
- ' scenarios: [',
238
- ' lazyLoadScenario,',
239
- " ...['stripe', 'google'].map((name) => ({",
240
- ' scenario: roundTripScenario,',
241
- ' data: { name },',
242
- ' })),',
243
- ' ],',
244
- '})',
245
- ].join('\n')
246
- )
247
- try {
248
- assert.deepEqual(criticals, [])
249
- const feature = state.workflows.featureFiles.get('credentialFeature')!
250
- assert.deepEqual(feature.entries, [{ scenario: 'lazyLoadScenario' }])
251
- assert.equal(feature.unresolvedEntries, 1)
252
- } finally {
253
- await cleanup()
254
- }
255
- })
256
-
257
- test('several features in one file are all recorded', async () => {
258
- const { state, criticals, cleanup } = await run(
259
- [
260
- "import { pikkuFeature } from '@pikku/core/workflow'",
261
- "import { lazyLoadScenario, roundTripScenario } from './credential.scenario.js'",
262
- "export const readFeature = pikkuFeature({ name: 'Read', scenarios: [lazyLoadScenario] })",
263
- "export const writeFeature = pikkuFeature({ name: 'Write', scenarios: [roundTripScenario] })",
264
- ].join('\n')
265
- )
266
- try {
267
- assert.deepEqual(criticals, [])
268
- assert.deepEqual(
269
- [...state.workflows.featureFiles.keys()],
270
- ['readFeature', 'writeFeature']
271
- )
272
- } finally {
273
- await cleanup()
274
- }
275
- })
276
-
277
- test('a feature that is not exported is a critical error', async () => {
278
- const { state, criticals, cleanup } = await run(
279
- [
280
- "import { pikkuFeature } from '@pikku/core/workflow'",
281
- "import { lazyLoadScenario } from './credential.scenario.js'",
282
- "const credentialFeature = pikkuFeature({ name: 'Credential API', scenarios: [lazyLoadScenario] })",
283
- 'void credentialFeature',
284
- ].join('\n')
285
- )
286
- try {
287
- assert.equal(state.workflows.featureFiles.size, 0)
288
- assert.equal(criticals.length, 1)
289
- assert.match(criticals[0]!.message, /must be assigned to an export/)
290
- } finally {
291
- await cleanup()
292
- }
293
- })
294
-
295
- test('a project with no features records none', async () => {
296
- const { state, criticals, cleanup } = await run(
297
- "export const nothing = 'here'\n"
298
- )
299
- try {
300
- assert.deepEqual(criticals, [])
301
- assert.equal(state.workflows.featureFiles.size, 0)
302
- } finally {
303
- await cleanup()
304
- }
305
- })
306
- })