@pikku/inspector 0.12.75 → 0.12.82

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 (223) hide show
  1. package/CHANGELOG.md +357 -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-middleware.js +66 -42
  8. package/dist/add/add-wire-addon.js +7 -4
  9. package/dist/add/add-wire-remote-addon.js +1 -0
  10. package/dist/error-codes.d.ts +1 -0
  11. package/dist/error-codes.js +1 -0
  12. package/dist/index.d.ts +3 -1
  13. package/dist/index.js +3 -1
  14. package/dist/inspector.js +5 -0
  15. package/dist/surface/collect-surface.d.ts +58 -0
  16. package/dist/surface/collect-surface.js +613 -0
  17. package/dist/types.d.ts +36 -12
  18. package/dist/utils/filter-inspector-state.js +14 -0
  19. package/dist/utils/load-addon-functions-meta.js +24 -11
  20. package/dist/utils/post-process.js +15 -0
  21. package/dist/utils/read-module-specifiers.d.ts +8 -0
  22. package/dist/utils/read-module-specifiers.js +23 -0
  23. package/dist/utils/read-tsconfig-out-dir.d.ts +5 -0
  24. package/dist/utils/read-tsconfig-out-dir.js +12 -0
  25. package/dist/utils/resolve-deploy-target.d.ts +7 -0
  26. package/dist/utils/resolve-deploy-target.js +15 -7
  27. package/dist/utils/serialize-inspector-state.d.ts +6 -0
  28. package/dist/utils/serialize-inspector-state.js +10 -0
  29. package/dist/visit.js +4 -0
  30. package/package.json +16 -6
  31. package/run-tests.sh +21 -6
  32. package/src/add/add-addon-bans.ts +0 -85
  33. package/src/add/add-agent-scorer.test.ts +0 -197
  34. package/src/add/add-agent-scorer.ts +0 -83
  35. package/src/add/add-agent.test.ts +0 -87
  36. package/src/add/add-agent.ts +0 -638
  37. package/src/add/add-approval-description.ts +0 -76
  38. package/src/add/add-auth.test.ts +0 -791
  39. package/src/add/add-auth.ts +0 -424
  40. package/src/add/add-channel.ts +0 -778
  41. package/src/add/add-cli-renderers.test.ts +0 -74
  42. package/src/add/add-cli.ts +0 -1006
  43. package/src/add/add-credential.ts +0 -186
  44. package/src/add/add-feature.test.ts +0 -306
  45. package/src/add/add-feature.ts +0 -253
  46. package/src/add/add-file-extends-core-type.ts +0 -66
  47. package/src/add/add-file-with-config.ts +0 -45
  48. package/src/add/add-file-with-factory.test.ts +0 -134
  49. package/src/add/add-file-with-factory.ts +0 -288
  50. package/src/add/add-functions.test.ts +0 -743
  51. package/src/add/add-functions.ts +0 -1548
  52. package/src/add/add-gateway.ts +0 -143
  53. package/src/add/add-http-route-ref.test.ts +0 -149
  54. package/src/add/add-http-route.ts +0 -530
  55. package/src/add/add-http-routes.ts +0 -471
  56. package/src/add/add-keyed-wiring.ts +0 -180
  57. package/src/add/add-mcp-prompt.ts +0 -157
  58. package/src/add/add-mcp-resource.ts +0 -175
  59. package/src/add/add-middleware.test.ts +0 -196
  60. package/src/add/add-middleware.ts +0 -879
  61. package/src/add/add-permission-auth.test.ts +0 -59
  62. package/src/add/add-permission.ts +0 -311
  63. package/src/add/add-personas.test.ts +0 -406
  64. package/src/add/add-personas.ts +0 -287
  65. package/src/add/add-queue-worker.ts +0 -117
  66. package/src/add/add-rpc-invocations.test.ts +0 -287
  67. package/src/add/add-rpc-invocations.ts +0 -221
  68. package/src/add/add-scenario-step.test.ts +0 -509
  69. package/src/add/add-schedule.ts +0 -120
  70. package/src/add/add-scope.test.ts +0 -419
  71. package/src/add/add-scope.ts +0 -221
  72. package/src/add/add-secret.ts +0 -10
  73. package/src/add/add-subject-scenario-steps.test.ts +0 -161
  74. package/src/add/add-system-role.test.ts +0 -297
  75. package/src/add/add-system-role.ts +0 -162
  76. package/src/add/add-trigger.ts +0 -165
  77. package/src/add/add-variable.ts +0 -10
  78. package/src/add/add-wire-addon.test.ts +0 -185
  79. package/src/add/add-wire-addon.ts +0 -146
  80. package/src/add/add-wire-remote-addon.ts +0 -80
  81. package/src/add/add-workflow-edge-cases.test.ts +0 -201
  82. package/src/add/add-workflow-fanout.test.ts +0 -166
  83. package/src/add/add-workflow-graph-foreach.test.ts +0 -174
  84. package/src/add/add-workflow-graph-input.test.ts +0 -94
  85. package/src/add/add-workflow-graph-notes.test.ts +0 -74
  86. package/src/add/add-workflow-graph.ts +0 -644
  87. package/src/add/add-workflow-on-error.test.ts +0 -118
  88. package/src/add/add-workflow-return-switch.test.ts +0 -121
  89. package/src/add/add-workflow-silent-drops.test.ts +0 -261
  90. package/src/add/add-workflow-sleep-expression.test.ts +0 -96
  91. package/src/add/add-workflow.test.ts +0 -155
  92. package/src/add/add-workflow.ts +0 -482
  93. package/src/add/addon-bans.test.ts +0 -121
  94. package/src/add/addon-contracts.test.ts +0 -221
  95. package/src/add/allow-escape-hatches.test.ts +0 -144
  96. package/src/add/audit-meta.test.ts +0 -75
  97. package/src/add/classified-sink-check.test.ts +0 -347
  98. package/src/add/config-value-metadata.test.ts +0 -263
  99. package/src/add/dynamic-import-check.test.ts +0 -119
  100. package/src/add/expect-eventually-scenario-only.test.ts +0 -108
  101. package/src/add/function-body-span.test.ts +0 -96
  102. package/src/add/inline-wiring-function.test.ts +0 -104
  103. package/src/add/pii-check.test.ts +0 -258
  104. package/src/add/rpc-type-cast.test.ts +0 -123
  105. package/src/add/scenario-instrumentation.test.ts +0 -89
  106. package/src/add/scenario-instrumentation.ts +0 -42
  107. package/src/add/scenario-marker.test.ts +0 -89
  108. package/src/add/scenario-not-extractable.test.ts +0 -159
  109. package/src/add/scenario-services.test.ts +0 -103
  110. package/src/add/scenario-skip.test.ts +0 -83
  111. package/src/add/validate-workflow-graph-addons.test.ts +0 -102
  112. package/src/add/wire-name-literal.test.ts +0 -117
  113. package/src/error-codes-emitted.test.ts +0 -76
  114. package/src/error-codes.ts +0 -145
  115. package/src/index.ts +0 -66
  116. package/src/inspector.ts +0 -575
  117. package/src/schema-generator.ts +0 -1
  118. package/src/source-file-cache.ts +0 -73
  119. package/src/tsconfig-paths.test.ts +0 -90
  120. package/src/types-map.ts +0 -141
  121. package/src/types.ts +0 -775
  122. package/src/utils/annotate-http-route-auth.test.ts +0 -161
  123. package/src/utils/annotate-http-route-auth.ts +0 -53
  124. package/src/utils/check-classified-sinks.ts +0 -215
  125. package/src/utils/check-pii-output.ts +0 -120
  126. package/src/utils/compute-diagnostics.test.ts +0 -106
  127. package/src/utils/compute-required-schemas.ts +0 -48
  128. package/src/utils/contract-hashes.test.ts +0 -553
  129. package/src/utils/contract-hashes.ts +0 -387
  130. package/src/utils/custom-types-generator.test.ts +0 -124
  131. package/src/utils/custom-types-generator.ts +0 -150
  132. package/src/utils/detect-schema-vendor.test.ts +0 -123
  133. package/src/utils/detect-schema-vendor.ts +0 -120
  134. package/src/utils/does-type-extend-core-type.ts +0 -53
  135. package/src/utils/ensure-function-metadata.ts +0 -385
  136. package/src/utils/extract-function-name.ts +0 -612
  137. package/src/utils/extract-function-node.ts +0 -70
  138. package/src/utils/extract-node-value.test.ts +0 -117
  139. package/src/utils/extract-node-value.ts +0 -172
  140. package/src/utils/extract-secret-usage.test.ts +0 -81
  141. package/src/utils/extract-secret-usage.ts +0 -73
  142. package/src/utils/extract-services.ts +0 -70
  143. package/src/utils/extract-surface-usage.test.ts +0 -147
  144. package/src/utils/extract-surface-usage.ts +0 -121
  145. package/src/utils/filter-inspector-state.test.ts +0 -2232
  146. package/src/utils/filter-inspector-state.ts +0 -1298
  147. package/src/utils/filter-utils.test.ts +0 -843
  148. package/src/utils/filter-utils.ts +0 -161
  149. package/src/utils/find-root-dir.ts +0 -68
  150. package/src/utils/find-zod-transform.test.ts +0 -70
  151. package/src/utils/find-zod-transform.ts +0 -103
  152. package/src/utils/get-exported-variable-name.ts +0 -48
  153. package/src/utils/get-files-and-methods.ts +0 -157
  154. package/src/utils/get-property-value.test.ts +0 -141
  155. package/src/utils/get-property-value.ts +0 -331
  156. package/src/utils/hash.ts +0 -26
  157. package/src/utils/literal-properties.ts +0 -97
  158. package/src/utils/load-addon-functions-meta.test.ts +0 -157
  159. package/src/utils/load-addon-functions-meta.ts +0 -508
  160. package/src/utils/load-addon-scopes.test.ts +0 -138
  161. package/src/utils/middleware.test.ts +0 -204
  162. package/src/utils/middleware.ts +0 -303
  163. package/src/utils/nested-project-filter.test.ts +0 -53
  164. package/src/utils/nested-project-filter.ts +0 -28
  165. package/src/utils/permissions-shorthand.test.ts +0 -79
  166. package/src/utils/permissions.test.ts +0 -125
  167. package/src/utils/permissions.ts +0 -129
  168. package/src/utils/post-process.test.ts +0 -1094
  169. package/src/utils/post-process.ts +0 -1604
  170. package/src/utils/resolve-addon-package.ts +0 -106
  171. package/src/utils/resolve-core-type.test.ts +0 -142
  172. package/src/utils/resolve-core-type.ts +0 -35
  173. package/src/utils/resolve-deploy-target.test.ts +0 -135
  174. package/src/utils/resolve-deploy-target.ts +0 -65
  175. package/src/utils/resolve-function-meta.ts +0 -25
  176. package/src/utils/resolve-function-types.ts +0 -42
  177. package/src/utils/resolve-identifier.ts +0 -46
  178. package/src/utils/resolve-ref-contract.ts +0 -71
  179. package/src/utils/resolve-versions.test.ts +0 -499
  180. package/src/utils/resolve-versions.ts +0 -228
  181. package/src/utils/schema-cache.test.ts +0 -124
  182. package/src/utils/schema-generator.test.ts +0 -272
  183. package/src/utils/schema-generator.ts +0 -780
  184. package/src/utils/secret-alias-services.test.ts +0 -146
  185. package/src/utils/secret-alias-services.ts +0 -58
  186. package/src/utils/serialize-inspector-state.ts +0 -742
  187. package/src/utils/serialize-mcp-json.ts +0 -150
  188. package/src/utils/serialize-middleware-groups-meta.ts +0 -36
  189. package/src/utils/serialize-openapi-json.ts +0 -277
  190. package/src/utils/serialize-permissions-groups-meta.ts +0 -7
  191. package/src/utils/single-declaration.ts +0 -57
  192. package/src/utils/type-utils.ts +0 -145
  193. package/src/utils/validate-auth-sessionless.ts +0 -30
  194. package/src/utils/validate-exposed-functions-gated.test.ts +0 -230
  195. package/src/utils/validate-exposed-functions-gated.ts +0 -103
  196. package/src/utils/validate-tags-resolve-to-middleware.test.ts +0 -108
  197. package/src/utils/validate-tags-resolve-to-middleware.ts +0 -48
  198. package/src/utils/workflow/derive-workflow-plan.test.ts +0 -178
  199. package/src/utils/workflow/derive-workflow-plan.ts +0 -117
  200. package/src/utils/workflow/dsl/deserialize-dsl-workflow.ts +0 -1465
  201. package/src/utils/workflow/dsl/deserialize-fanout-body.test.ts +0 -71
  202. package/src/utils/workflow/dsl/deserialize-fanout-fidelity.test.ts +0 -99
  203. package/src/utils/workflow/dsl/deserialize-graph-next.test.ts +0 -161
  204. package/src/utils/workflow/dsl/deserialize-roundtrip-bindings.test.ts +0 -121
  205. package/src/utils/workflow/dsl/deserialize-roundtrip-values.test.ts +0 -116
  206. package/src/utils/workflow/dsl/deserialize-roundtrip.test.ts +0 -145
  207. package/src/utils/workflow/dsl/extract-approval-policy.test.ts +0 -71
  208. package/src/utils/workflow/dsl/extract-dsl-workflow.ts +0 -2254
  209. package/src/utils/workflow/dsl/index.ts +0 -11
  210. package/src/utils/workflow/dsl/patterns.ts +0 -440
  211. package/src/utils/workflow/dsl/validation.ts +0 -203
  212. package/src/utils/workflow/graph/convert-dsl-to-graph-skip.test.ts +0 -35
  213. package/src/utils/workflow/graph/convert-dsl-to-graph.ts +0 -543
  214. package/src/utils/workflow/graph/fanout-node-identity.test.ts +0 -105
  215. package/src/utils/workflow/graph/finalize-workflow-wires.ts +0 -310
  216. package/src/utils/workflow/graph/finalize-workflows.test.ts +0 -50
  217. package/src/utils/workflow/graph/finalize-workflows.ts +0 -130
  218. package/src/utils/workflow/graph/index.ts +0 -28
  219. package/src/utils/workflow/graph/serialize-workflow-graph.ts +0 -240
  220. package/src/utils/workflow/graph/workflow-graph.types.ts +0 -281
  221. package/src/visit.ts +0 -181
  222. package/tsconfig.json +0 -19
  223. package/tsconfig.tsbuildinfo +0 -1
@@ -1,123 +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 { ErrorCode } from '../error-codes.js'
8
- import type { InspectorLogger } from '../types.js'
9
-
10
- function makeLogger() {
11
- const criticals: Array<{ code: ErrorCode; message: string }> = []
12
- const logger: InspectorLogger = {
13
- debug: () => {},
14
- info: () => {},
15
- warn: () => {},
16
- error: () => {},
17
- diagnostic: ({ code, message }) => criticals.push({ code, message }),
18
- critical: (code, message) => criticals.push({ code, message }),
19
- hasCriticalErrors: () => criticals.length > 0,
20
- }
21
- return { logger, criticals }
22
- }
23
-
24
- async function runInspect(sourceCode: string) {
25
- const tmpDir = await mkdtemp(join(tmpdir(), 'pikku-rpc-cast-test-'))
26
- const file = join(tmpDir, 'funcs.ts')
27
- await writeFile(file, sourceCode)
28
- const { logger, criticals } = makeLogger()
29
- try {
30
- await inspect(logger, [file], { rootDir: tmpDir })
31
- } finally {
32
- await rm(tmpDir, { recursive: true, force: true })
33
- }
34
- return criticals
35
- }
36
-
37
- describe('RPC type-cast check — PKU940', () => {
38
- test('flags rpc.invoke() with an as-cast on an argument', async () => {
39
- const criticals = await runInspect(`
40
- declare const rpc: { invoke: (name: string, data: unknown) => Promise<unknown> }
41
- export async function doWork() {
42
- return rpc.invoke('someFunction', { id: 1 } as any)
43
- }
44
- `)
45
- const hit = criticals.find(
46
- (c) => c.code === ErrorCode.RPC_INVOCATION_TYPE_CAST
47
- )
48
- assert.ok(hit, `Expected PKU940 but got: ${JSON.stringify(criticals)}`)
49
- })
50
-
51
- test('flags rpc.invoke() with an angle-bracket cast on an argument', async () => {
52
- const criticals = await runInspect(`
53
- declare const rpc: { invoke: (name: string, data: unknown) => Promise<unknown> }
54
- export async function doWork() {
55
- return rpc.invoke('someFunction', <any>{ id: 1 })
56
- }
57
- `)
58
- const hit = criticals.find(
59
- (c) => c.code === ErrorCode.RPC_INVOCATION_TYPE_CAST
60
- )
61
- assert.ok(hit, `Expected PKU940 but got: ${JSON.stringify(criticals)}`)
62
- })
63
-
64
- test('flags rpc.invoke() result cast with as any', async () => {
65
- const criticals = await runInspect(`
66
- declare const rpc: { invoke: (name: string, data: unknown) => Promise<unknown> }
67
- export async function doWork() {
68
- return (rpc.invoke('someFunction', { id: 1 }) as any)
69
- }
70
- `)
71
- const hit = criticals.find(
72
- (c) => c.code === ErrorCode.RPC_INVOCATION_TYPE_CAST
73
- )
74
- assert.ok(hit, `Expected PKU940 but got: ${JSON.stringify(criticals)}`)
75
- })
76
-
77
- test('flags rpc.invoke() result cast with as never', async () => {
78
- const criticals = await runInspect(`
79
- declare const rpc: { invoke: (name: string, data: unknown) => Promise<unknown> }
80
- export async function doWork() {
81
- return (rpc.invoke('someFunction', { id: 1 }) as never)
82
- }
83
- `)
84
- const hit = criticals.find(
85
- (c) => c.code === ErrorCode.RPC_INVOCATION_TYPE_CAST
86
- )
87
- assert.ok(hit, `Expected PKU940 but got: ${JSON.stringify(criticals)}`)
88
- })
89
-
90
- test('does not flag a clean rpc.invoke() call', async () => {
91
- const criticals = await runInspect(`
92
- declare const rpc: { invoke: (name: string, data: unknown) => Promise<unknown> }
93
- export async function doWork() {
94
- return rpc.invoke('someFunction', { id: 1 })
95
- }
96
- `)
97
- const hit = criticals.find(
98
- (c) => c.code === ErrorCode.RPC_INVOCATION_TYPE_CAST
99
- )
100
- assert.equal(
101
- hit,
102
- undefined,
103
- `Expected no PKU940 but got: ${JSON.stringify(hit)}`
104
- )
105
- })
106
-
107
- test('does not flag as-casts on unrelated calls', async () => {
108
- const criticals = await runInspect(`
109
- declare function otherFn(data: unknown): Promise<unknown>
110
- export async function doWork() {
111
- return otherFn({ id: 1 } as any)
112
- }
113
- `)
114
- const hit = criticals.find(
115
- (c) => c.code === ErrorCode.RPC_INVOCATION_TYPE_CAST
116
- )
117
- assert.equal(
118
- hit,
119
- undefined,
120
- `Expected no PKU940 but got: ${JSON.stringify(hit)}`
121
- )
122
- })
123
- })
@@ -1,89 +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
- import {
9
- SCENARIO_INSTRUMENTATION_FUNCTIONS,
10
- isScenarioInstrumentationFunction,
11
- } from './scenario-instrumentation.js'
12
-
13
- const silentLogger: InspectorLogger = {
14
- debug: () => {},
15
- info: () => {},
16
- warn: () => {},
17
- error: () => {},
18
- diagnostic: () => {},
19
- critical: () => {},
20
- hasCriticalErrors: () => false,
21
- }
22
-
23
- describe('scenario instrumentation', () => {
24
- test('recognises the instrumentation names, including versioned ids', () => {
25
- for (const name of SCENARIO_INSTRUMENTATION_FUNCTIONS) {
26
- assert.ok(isScenarioInstrumentationFunction(name), name)
27
- assert.ok(isScenarioInstrumentationFunction(`${name}@v2`), `${name}@v2`)
28
- }
29
- assert.ok(!isScenarioInstrumentationFunction('createUser'))
30
- assert.ok(!isScenarioInstrumentationFunction(undefined))
31
- })
32
-
33
- test('a project still carrying the retired scaffold registers none of it', async () => {
34
- const rootDir = await mkdtemp(join(tmpdir(), 'pikku-scenario-instr-'))
35
- const file = join(rootDir, 'scenarios.gen.ts')
36
-
37
- // What `scaffold.scenarios` used to write into the project. Whatever a
38
- // project has checked in, none of it may reach the app's meta or RPC surface:
39
- // `pikku dev` registers the real implementations itself.
40
- await writeFile(
41
- file,
42
- [
43
- "import { pikkuFunc } from '@pikku/core'",
44
- 'export const pikkuScenarioTakeLiveCoverage = pikkuFunc({',
45
- " tags: ['pikku'],",
46
- ' expose: true,',
47
- ' auth: true,',
48
- ' func: async () => null,',
49
- '})',
50
- 'export const pikkuScenarioResetStubs = pikkuFunc({',
51
- " tags: ['pikku'],",
52
- ' expose: true,',
53
- ' auth: true,',
54
- ' func: async () => ({ enabled: true }),',
55
- '})',
56
- 'export const createUser = pikkuFunc({',
57
- ' expose: true,',
58
- ' func: async () => ({ ok: true }),',
59
- '})',
60
- ].join('\n')
61
- )
62
-
63
- try {
64
- const state = await inspect(silentLogger, [file], { rootDir })
65
-
66
- for (const name of SCENARIO_INSTRUMENTATION_FUNCTIONS) {
67
- assert.ok(
68
- !(name in state.functions.meta),
69
- `${name} must not be in the app function meta`
70
- )
71
- assert.ok(
72
- !(name in state.rpc.internalMeta),
73
- `${name} must not be in the internal RPC meta`
74
- )
75
- assert.ok(
76
- !(name in state.rpc.exposedMeta),
77
- `${name} must not be exposed`
78
- )
79
- }
80
-
81
- // The application function in the same file is untouched — the drop is by
82
- // name, not by file.
83
- assert.ok(state.functions.meta['createUser'])
84
- assert.strictEqual(state.rpc.exposedMeta['createUser'], 'createUser')
85
- } finally {
86
- await rm(rootDir, { recursive: true, force: true })
87
- }
88
- })
89
- })
@@ -1,42 +0,0 @@
1
- /**
2
- * The instrumentation RPCs `pikku scenario run` calls on the server it is
3
- * testing: snapshot/reset live coverage, and reset/read recorded stub calls.
4
- *
5
- * They are pikku's own, not the application's. They used to be scaffolded into
6
- * the project as ordinary `pikkuFunc`s, which made them indistinguishable from
7
- * application code — so they were registered in the app bootstrap, listed in the
8
- * app's function and RPC meta, and shipped, `expose: true`, in every deployed
9
- * bundle. A deployment has no use for them: coverage and stub inspection are
10
- * things you do to a development server.
11
- *
12
- * The inspector therefore ignores these names wherever it finds them, and
13
- * `pikku dev` registers the implementations itself. Ignoring by name (rather
14
- * than deleting the scaffold and requiring every project to regenerate) is what
15
- * keeps an existing project's checked-in `scenarios.gen.ts` from deploying.
16
- *
17
- * `pikkuScenarioGradeRun` was never scaffolded — it arrived after the split —
18
- * but it belongs here for the same reason: grading a run on demand, ignoring the
19
- * sample rate that governs live traffic, is a thing you do to a development
20
- * server, and the name is reserved so an application cannot claim it.
21
- */
22
- export const SCENARIO_INSTRUMENTATION_FUNCTIONS = [
23
- 'pikkuScenarioTakeLiveCoverage',
24
- 'pikkuScenarioResetLiveCoverage',
25
- 'pikkuScenarioResetStubs',
26
- 'pikkuScenarioGetStubCalls',
27
- 'pikkuScenarioGradeRun',
28
- ] as const
29
-
30
- export type ScenarioInstrumentationFunction =
31
- (typeof SCENARIO_INSTRUMENTATION_FUNCTIONS)[number]
32
-
33
- const names = new Set<string>(SCENARIO_INSTRUMENTATION_FUNCTIONS)
34
-
35
- /**
36
- * True for a scenario instrumentation function, by name. Versioned ids
37
- * (`name@v2`) are matched on their base so a project that bumps one is still
38
- * covered.
39
- */
40
- export const isScenarioInstrumentationFunction = (
41
- name: string | undefined
42
- ): boolean => (name ? names.has(name.split('@')[0]!) : false)
@@ -1,89 +0,0 @@
1
- /**
2
- * The `scenario` / `scenarioStep` markers in the *function* meta are what every
3
- * deployment boundary downstream reads: the codegen partition, the RPC meta
4
- * filter, the schema split and the deploy analyzer. Asserting them on a real
5
- * `pikkuScenario(...)` is what makes those filters mean anything — filters tested
6
- * against hand-written meta would keep passing if extraction stopped setting it.
7
- */
8
- import { strict as assert } from 'assert'
9
- import { describe, test } from 'node:test'
10
- import { mkdtemp, rm, writeFile } from 'node:fs/promises'
11
- import { tmpdir } from 'node:os'
12
- import { join } from 'node:path'
13
- import { inspect } from '../inspector.js'
14
- import type { InspectorLogger } from '../types.js'
15
-
16
- const logger = {
17
- debug: () => {},
18
- info: () => {},
19
- warn: () => {},
20
- error: () => {},
21
- diagnostic: () => {},
22
- critical: () => {},
23
- hasCriticalErrors: () => false,
24
- } as unknown as InspectorLogger
25
-
26
- const STEPS = [
27
- "import { pikkuScenarioStep } from '@pikku/core'",
28
- 'export const buysAnApple = pikkuScenarioStep({',
29
- " name: 'buysAnApple',",
30
- " description: 'buys an apple',",
31
- ' func: async ({ logger }, data: { qty: number }) => ({ ok: data.qty > 0 }),',
32
- '})',
33
- ].join('\n')
34
-
35
- const APP = [
36
- "import { pikkuFunc } from '@pikku/core'",
37
- 'export const createTodo = pikkuFunc({',
38
- ' expose: true,',
39
- ' func: async (_services, data: { title: string }) => ({ id: data.title }),',
40
- '})',
41
- ].join('\n')
42
-
43
- const SCENARIO = [
44
- "import { pikkuScenario } from '@pikku/core/workflow'",
45
- 'export const shopFlow = pikkuScenario({',
46
- " title: 'Buys an apple',",
47
- ' func: async (_services, _input, { scenario }: any) => {',
48
- " await scenario.when('buys an apple', 'buysAnApple', { qty: 1 })",
49
- ' return { ok: true }',
50
- ' },',
51
- '})',
52
- ].join('\n')
53
-
54
- describe('scenario markers in the function meta', () => {
55
- test('a real pikkuScenario and pikkuScenarioStep are marked, an application function is not', async () => {
56
- const rootDir = await mkdtemp(join(tmpdir(), 'pikku-scenario-marker-'))
57
- const files = [
58
- [join(rootDir, 'shop.steps.ts'), STEPS],
59
- [join(rootDir, 'shop.scenario.ts'), SCENARIO],
60
- [join(rootDir, 'todo.function.ts'), APP],
61
- ] as const
62
- await Promise.all(files.map(([path, source]) => writeFile(path, source)))
63
-
64
- try {
65
- const state = await inspect(
66
- logger,
67
- files.map(([path]) => path),
68
- { rootDir }
69
- )
70
-
71
- const scenario = state.functions.meta['shopFlow']
72
- assert.ok(scenario, 'the scenario body is a function and must have meta')
73
- assert.equal(scenario.scenario, true)
74
- assert.equal(scenario.scenarioStep, undefined)
75
-
76
- const step = state.functions.meta['buysAnApple']
77
- assert.ok(step)
78
- assert.equal(step.scenarioStep, true)
79
- assert.equal(step.scenario, undefined)
80
-
81
- const app = state.functions.meta['createTodo']
82
- assert.ok(app)
83
- assert.equal(app.scenario, undefined)
84
- assert.equal(app.scenarioStep, undefined)
85
- } finally {
86
- await rm(rootDir, { recursive: true, force: true })
87
- }
88
- })
89
- })
@@ -1,159 +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 STEPS = [
28
- "import { pikkuScenarioStep } from '@pikku/core'",
29
- 'export const buysAnApple = pikkuScenarioStep({',
30
- " name: 'buysAnApple',",
31
- " description: 'buys an apple',",
32
- ' func: async ({ logger }, data: { qty: number }) => ({ ok: data.qty > 0 }),',
33
- '})',
34
- ].join('\n')
35
-
36
- const source = (wrapper: string, body: string[]) =>
37
- [
38
- `import { ${wrapper} } from '@pikku/core/workflow'`,
39
- 'declare const actors: Record<string, any>',
40
- `export const shopFlow = ${wrapper}(async (_services, _input, { scenario, workflow }: any) => {`,
41
- ...body.map((line) => ` ${line}`),
42
- ' return { ok: true }',
43
- '})',
44
- ].join('\n')
45
-
46
- async function run(wrapper: string, body: string[]) {
47
- const rootDir = await mkdtemp(join(tmpdir(), 'pikku-scenario-extract-'))
48
- const stepsFile = join(rootDir, 'shop.steps.ts')
49
- const scenarioFile = join(rootDir, 'shop.scenario.ts')
50
- await writeFile(stepsFile, STEPS)
51
- await writeFile(scenarioFile, source(wrapper, body))
52
- const criticals: Array<{ code: string; message: string }> = []
53
- const state = await inspect(
54
- makeLogger(criticals),
55
- [stepsFile, scenarioFile],
56
- {
57
- rootDir,
58
- }
59
- )
60
- return {
61
- state,
62
- criticals,
63
- cleanup: () => rm(rootDir, { recursive: true, force: true }),
64
- }
65
- }
66
-
67
- /**
68
- * A scenario that fails DSL extraction silently registers with zero steps,
69
- * because the fallback path (`getWorkflowInvocations`) understands `do`/`sleep`
70
- * but not `step`/`given`/`when`/`then`. That is the PKU678 silent-drop class,
71
- * and for scenarios it must be loud.
72
- */
73
- describe('a scenario that cannot be extracted', () => {
74
- test('a top-level try/catch is a PKU679 critical, not a silent zero-step scenario', async () => {
75
- const { state, criticals, cleanup } = await run('pikkuScenario', [
76
- 'try {',
77
- " await scenario.given('buys an apple', 'buysAnApple', { qty: 1 }, { actor: actors.shopper })",
78
- '} catch {}',
79
- ])
80
- try {
81
- assert.equal(
82
- state.workflows.meta.shopFlow,
83
- undefined,
84
- 'an unextractable scenario must not register at all, rather than register empty'
85
- )
86
- assert.ok(
87
- criticals.find((c) => c.code === 'PKU679'),
88
- `expected a PKU679 critical for an unextractable scenario, got: ${JSON.stringify(criticals)}`
89
- )
90
- } finally {
91
- await cleanup()
92
- }
93
- })
94
-
95
- test('an extractable scenario raises no PKU679', async () => {
96
- const { criticals, cleanup } = await run('pikkuScenario', [
97
- "await scenario.given('buys an apple', 'buysAnApple', { qty: 1 }, { actor: actors.shopper })",
98
- ])
99
- try {
100
- assert.equal(
101
- criticals.filter((c) => c.code === 'PKU679').length,
102
- 0,
103
- `a valid scenario must not raise PKU679, got: ${JSON.stringify(criticals)}`
104
- )
105
- } finally {
106
- await cleanup()
107
- }
108
- })
109
-
110
- test('a scenario that declares no input parameter is still extractable', async () => {
111
- const rootDir = await mkdtemp(join(tmpdir(), 'pikku-scenario-noinput-'))
112
- const scenarioFile = join(rootDir, 'fails.scenario.ts')
113
- await writeFile(
114
- scenarioFile,
115
- [
116
- "import { pikkuScenario } from '@pikku/core/workflow'",
117
- 'export const alwaysFails = pikkuScenario({',
118
- " title: 'Always fails (test fixture)',",
119
- " tags: ['scenario'],",
120
- " func: async () => { throw new Error('always fails') },",
121
- '})',
122
- ].join('\n')
123
- )
124
- const criticals: Array<{ code: string; message: string }> = []
125
- const state = await inspect(makeLogger(criticals), [scenarioFile], {
126
- rootDir,
127
- })
128
- try {
129
- assert.ok(
130
- state.workflows.meta.alwaysFails,
131
- `a scenario that ignores its input must still register, got criticals: ${JSON.stringify(criticals)}`
132
- )
133
- assert.equal(
134
- criticals.filter((c) => c.code === 'PKU679').length,
135
- 0,
136
- `declaring no input parameter is legitimate, got: ${JSON.stringify(criticals)}`
137
- )
138
- } finally {
139
- await rm(rootDir, { recursive: true, force: true })
140
- }
141
- })
142
-
143
- test('a complex workflow still falls back quietly — only scenarios are strict', async () => {
144
- const { criticals, cleanup } = await run('pikkuWorkflowComplexFunc', [
145
- 'try {',
146
- " await workflow.do('buy', 'buysAnApple', { qty: 1 })",
147
- '} catch {}',
148
- ])
149
- try {
150
- assert.equal(
151
- criticals.filter((c) => c.code === 'PKU679').length,
152
- 0,
153
- `pikkuWorkflowComplexFunc legitimately falls back to basic extraction, got: ${JSON.stringify(criticals)}`
154
- )
155
- } finally {
156
- await cleanup()
157
- }
158
- })
159
- })
@@ -1,103 +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 }) => {
18
- criticals.push({ code, message })
19
- },
20
- critical: (code: any, message: string) => {
21
- criticals.push({ code, message })
22
- },
23
- hasCriticalErrors: () => criticals.length > 0,
24
- }
25
- }
26
-
27
- const stepFile = (dir: string) => join(dir, 'my.steps.ts')
28
- const stepSource = [
29
- "import { pikkuSessionlessFunc } from '@pikku/core'",
30
- 'export const getTodos = pikkuSessionlessFunc({',
31
- ' func: async ({ logger }) => [{ done: true }],',
32
- '})',
33
- ].join('\n')
34
-
35
- describe('scenarios may only destructure logger/config', () => {
36
- test('a scenario destructuring a real service is a PKU673 critical', async () => {
37
- const rootDir = await mkdtemp(join(tmpdir(), 'pikku-sc-svc-'))
38
- const scenarioFile = join(rootDir, 'my.scenario.ts')
39
- await writeFile(stepFile(rootDir), stepSource)
40
- await writeFile(
41
- scenarioFile,
42
- [
43
- "import { pikkuScenario } from '@pikku/core/workflow'",
44
- 'declare const actors: Record<string, any>',
45
- 'export const badFlow = pikkuScenario(async ({ kysely }: any, _input, { workflow }) => {',
46
- " await workflow.do('Read todos', 'getTodos', {}, { actor: actors.pm })",
47
- ' return { ok: true }',
48
- '})',
49
- ].join('\n')
50
- )
51
-
52
- const criticals: Array<{ code: string; message: string }> = []
53
- try {
54
- await inspect(makeLogger(criticals), [stepFile(rootDir), scenarioFile], {
55
- rootDir,
56
- })
57
- const pku673 = criticals.find((c) => c.code === 'PKU673')
58
- assert.ok(
59
- pku673,
60
- `expected a PKU673 critical for a scenario destructuring 'kysely', got: ${JSON.stringify(criticals)}`
61
- )
62
- assert.ok(
63
- pku673.message.includes('kysely'),
64
- `PKU673 should name the offending service, got: ${pku673.message}`
65
- )
66
- } finally {
67
- await rm(rootDir, { recursive: true, force: true })
68
- }
69
- })
70
-
71
- test('a scenario destructuring only logger is allowed', async () => {
72
- const rootDir = await mkdtemp(join(tmpdir(), 'pikku-sc-ok-'))
73
- const scenarioFile = join(rootDir, 'my.scenario.ts')
74
- await writeFile(stepFile(rootDir), stepSource)
75
- await writeFile(
76
- scenarioFile,
77
- [
78
- "import { pikkuScenario } from '@pikku/core/workflow'",
79
- 'declare const actors: Record<string, any>',
80
- 'export const goodFlow = pikkuScenario(async ({ logger }, _input, { workflow }) => {',
81
- " await workflow.do('Read todos', 'getTodos', {}, { actor: actors.pm })",
82
- ' return { ok: true }',
83
- '})',
84
- ].join('\n')
85
- )
86
-
87
- const criticals: Array<{ code: string; message: string }> = []
88
- try {
89
- const state = await inspect(
90
- makeLogger(criticals),
91
- [stepFile(rootDir), scenarioFile],
92
- { rootDir }
93
- )
94
- assert.ok(
95
- !criticals.some((c) => c.code === 'PKU673'),
96
- `logger is allowed in a scenario; got: ${JSON.stringify(criticals)}`
97
- )
98
- assert.equal((state.workflows.meta as any).goodFlow?.scenario, true)
99
- } finally {
100
- await rm(rootDir, { recursive: true, force: true })
101
- }
102
- })
103
- })
@@ -1,83 +0,0 @@
1
- /**
2
- * A scenario can declare why it is held out of a default run. The reason has to
3
- * reach the meta, because the runner reports skips from there — if it were
4
- * dropped in extraction the scenario would silently run anyway, which is the
5
- * opposite of what the author asked for.
6
- */
7
- import { strict as assert } from 'assert'
8
- import { describe, test } from 'node:test'
9
- import { mkdtemp, rm, writeFile } from 'node:fs/promises'
10
- import { tmpdir } from 'node:os'
11
- import { join } from 'node:path'
12
- import { inspect } from '../inspector.js'
13
- import type { InspectorLogger } from '../types.js'
14
-
15
- const logger = {
16
- debug: () => {},
17
- info: () => {},
18
- warn: () => {},
19
- error: () => {},
20
- diagnostic: () => {},
21
- critical: () => {},
22
- hasCriticalErrors: () => false,
23
- } as unknown as InspectorLogger
24
-
25
- const STEPS = [
26
- "import { pikkuScenarioStep } from '@pikku/core'",
27
- 'export const buysAnApple = pikkuScenarioStep({',
28
- " name: 'buysAnApple',",
29
- " description: 'buys an apple',",
30
- ' func: async ({ logger }, data: { qty: number }) => ({ ok: data.qty > 0 }),',
31
- '})',
32
- ].join('\n')
33
-
34
- const scenarioSource = (properties: string[]) =>
35
- [
36
- "import { pikkuScenario } from '@pikku/core/workflow'",
37
- 'export const shopFlow = pikkuScenario({',
38
- ...properties.map((line) => ` ${line}`),
39
- ' func: async (_services, _input, { scenario }: any) => {',
40
- " await scenario.when('buys an apple', 'buysAnApple', { qty: 1 })",
41
- ' return { ok: true }',
42
- ' },',
43
- '})',
44
- ].join('\n')
45
-
46
- async function inspectScenario(properties: string[]) {
47
- const rootDir = await mkdtemp(join(tmpdir(), 'pikku-scenario-skip-'))
48
- const stepsFile = join(rootDir, 'shop.steps.ts')
49
- const scenarioFile = join(rootDir, 'shop.scenario.ts')
50
- await writeFile(stepsFile, STEPS)
51
- await writeFile(scenarioFile, scenarioSource(properties))
52
- const state = await inspect(logger, [stepsFile, scenarioFile], { rootDir })
53
- return {
54
- meta: state.workflows.meta['shopFlow'] as any,
55
- cleanup: () => rm(rootDir, { recursive: true, force: true }),
56
- }
57
- }
58
-
59
- describe('scenario skip', () => {
60
- test('a declared skip reason reaches the meta', async () => {
61
- const { meta, cleanup } = await inspectScenario([
62
- "title: 'Installs an addon',",
63
- "skip: 'mutates the project — needs a fresh server',",
64
- ])
65
- try {
66
- assert.equal(meta.skip, 'mutates the project — needs a fresh server')
67
- } finally {
68
- await cleanup()
69
- }
70
- })
71
-
72
- test('a scenario that declares none carries none', async () => {
73
- const { meta, cleanup } = await inspectScenario([
74
- "title: 'Installs an addon',",
75
- ])
76
- try {
77
- assert.equal(meta.skip, undefined)
78
- assert.equal(meta.scenario, true)
79
- } finally {
80
- await cleanup()
81
- }
82
- })
83
- })