@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,197 +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
- const makeLogger = (criticals: Array<{ code: ErrorCode; message: string }>) =>
11
- ({
12
- debug: () => {},
13
- info: () => {},
14
- warn: () => {},
15
- error: () => {},
16
- diagnostic: ({ code, message }) => {
17
- criticals.push({ code, message })
18
- },
19
- critical: (code: ErrorCode, message: string) => {
20
- criticals.push({ code, message })
21
- },
22
- hasCriticalErrors: () => criticals.length > 0,
23
- }) satisfies InspectorLogger
24
-
25
- const inspectSources = async (sources: Record<string, string>) => {
26
- const rootDir = await mkdtemp(join(tmpdir(), 'pikku-add-agent-scorer-'))
27
- const files: Record<string, string> = {}
28
- for (const [name, source] of Object.entries(sources)) {
29
- files[name] = join(rootDir, name)
30
- await writeFile(files[name]!, source)
31
- }
32
- const criticals: Array<{ code: ErrorCode; message: string }> = []
33
- try {
34
- const state = await inspect(makeLogger(criticals), Object.values(files), {
35
- rootDir,
36
- })
37
- return { state, criticals }
38
- } finally {
39
- await rm(rootDir, { recursive: true, force: true })
40
- }
41
- }
42
-
43
- const inspectSource = (source: string) =>
44
- inspectSources({ 'grading.scorer.ts': source })
45
-
46
- describe('addAgentScorer', () => {
47
- test('reads the lane off which constructor was called, not off a field', async () => {
48
- const { state, criticals } = await inspectSource(
49
- [
50
- `export const brevity = pikkuAgentScorer({`,
51
- ` name: 'brevity',`,
52
- ` description: 'Shorter answers score higher',`,
53
- ` score: () => ({ score: 1 }),`,
54
- `})`,
55
- `export const helpfulness = pikkuAgentJudge({`,
56
- ` name: 'helpfulness',`,
57
- ` description: 'Does the answer help',`,
58
- ` model: 'claude-opus-5',`,
59
- ` goal: 'Grade helpfulness.',`,
60
- `})`,
61
- ].join('\n')
62
- )
63
-
64
- assert.deepEqual(criticals, [])
65
- assert.equal(state.scorers.scorersMeta['brevity']?.lane, 'fast')
66
- assert.equal(state.scorers.scorersMeta['helpfulness']?.lane, 'slow')
67
- })
68
-
69
- test('defaults an unstated sample rate to grading every run', async () => {
70
- const { state } = await inspectSource(
71
- [
72
- `export const brevity = pikkuAgentScorer({`,
73
- ` name: 'brevity',`,
74
- ` description: 'Shorter answers score higher',`,
75
- ` score: () => ({ score: 1 }),`,
76
- `})`,
77
- ].join('\n')
78
- )
79
-
80
- assert.equal(state.scorers.scorersMeta['brevity']?.sampleRate, 1)
81
- assert.equal(state.scorers.scorersMeta['brevity']?.requiresReference, false)
82
- })
83
-
84
- test('carries the sample rate and the reference requirement into the meta', async () => {
85
- const { state } = await inspectSource(
86
- [
87
- `export const correctness = pikkuAgentJudge({`,
88
- ` name: 'correctness',`,
89
- ` description: 'Is the answer right',`,
90
- ` model: 'claude-opus-5',`,
91
- ` goal: 'Grade correctness.',`,
92
- ` sampleRate: 0.1,`,
93
- ` requiresReference: true,`,
94
- `})`,
95
- ].join('\n')
96
- )
97
-
98
- assert.equal(state.scorers.scorersMeta['correctness']?.sampleRate, 0.1)
99
- assert.equal(
100
- state.scorers.scorersMeta['correctness']?.requiresReference,
101
- true
102
- )
103
- })
104
-
105
- test('rejects a sample rate that is not a fraction', async () => {
106
- const { state, criticals } = await inspectSource(
107
- [
108
- `export const brevity = pikkuAgentScorer({`,
109
- ` name: 'brevity',`,
110
- ` description: 'Shorter answers score higher',`,
111
- ` sampleRate: 50,`,
112
- ` score: () => ({ score: 1 }),`,
113
- `})`,
114
- ].join('\n')
115
- )
116
-
117
- assert.equal(criticals[0]?.code, ErrorCode.INVALID_VALUE)
118
- assert.match(criticals[0]!.message, /between 0 and 1/)
119
- assert.deepEqual(state.scorers.scorersMeta, {})
120
- })
121
-
122
- test('a scorer with no description is refused, since the meta is what names it', async () => {
123
- const { criticals } = await inspectSource(
124
- [
125
- `export const brevity = pikkuAgentScorer({`,
126
- ` name: 'brevity',`,
127
- ` score: () => ({ score: 1 }),`,
128
- `})`,
129
- ].join('\n')
130
- )
131
-
132
- assert.equal(criticals[0]?.code, ErrorCode.MISSING_DESCRIPTION)
133
- })
134
-
135
- test('records where a scorer was declared, so codegen can import it back', async () => {
136
- const { state } = await inspectSource(
137
- [
138
- `export const brevity = pikkuAgentScorer({`,
139
- ` name: 'brevity',`,
140
- ` description: 'Shorter answers score higher',`,
141
- ` score: () => ({ score: 1 }),`,
142
- `})`,
143
- ].join('\n')
144
- )
145
-
146
- assert.equal(state.scorers.files.get('brevity')?.exportedName, 'brevity')
147
- assert.match(
148
- state.scorers.files.get('brevity')?.path ?? '',
149
- /grading\.scorer\.ts$/
150
- )
151
- })
152
- })
153
-
154
- describe('an agent asking to be graded', () => {
155
- const scorerFile = [
156
- `export const brevity = pikkuAgentScorer({`,
157
- ` name: 'brevity',`,
158
- ` description: 'Shorter answers score higher',`,
159
- ` score: () => ({ score: 1 }),`,
160
- `})`,
161
- ].join('\n')
162
-
163
- const agent = (scorers: string) =>
164
- [
165
- `export const assistant = pikkuAgent({`,
166
- ` name: 'assistant',`,
167
- ` description: 'Answers questions',`,
168
- ` goal: 'Answer the question.',`,
169
- ` model: 'anthropic/claude-opus-5',`,
170
- ` scorers: [${scorers}],`,
171
- `})`,
172
- ].join('\n')
173
-
174
- test('carries the named scorers onto the agent meta', async () => {
175
- const { state, criticals } = await inspectSources({
176
- 'grading.scorer.ts': scorerFile,
177
- 'assistant.agent.ts': agent(`'brevity'`),
178
- })
179
-
180
- assert.deepEqual(criticals, [])
181
- assert.deepEqual(state.agents.agentsMeta['assistant']?.scorers, ['brevity'])
182
- })
183
-
184
- test('naming a scorer that does not exist fails the build rather than grading nothing', async () => {
185
- const { criticals } = await inspectSources({
186
- 'grading.scorer.ts': scorerFile,
187
- 'assistant.agent.ts': agent(`'brevty'`),
188
- })
189
-
190
- const finding = criticals.find(
191
- (critical) => critical.code === ErrorCode.AGENT_SCORER_NOT_FOUND
192
- )
193
- assert.ok(finding, `expected a scorer-not-found critical`)
194
- assert.match(finding!.message, /brevty/)
195
- assert.match(finding!.message, /Declared scorers: brevity/)
196
- })
197
- })
@@ -1,83 +0,0 @@
1
- import * as ts from 'typescript'
2
- import { getPropertyValue } from '../utils/get-property-value.js'
3
- import type { AddWiring } from '../types.js'
4
- import { extractFunctionName } from '../utils/extract-function-name.js'
5
- import { ErrorCode } from '../error-codes.js'
6
-
7
- /**
8
- * `pikkuAgentScorer` grades in code and `pikkuAgentJudge` grades with a model, which
9
- * is the whole difference between the two lanes — so the lane is read off which
10
- * constructor was called rather than from a field an author could contradict.
11
- */
12
- const LANES: Record<string, 'fast' | 'slow'> = {
13
- pikkuAgentScorer: 'fast',
14
- pikkuAgentJudge: 'slow',
15
- }
16
-
17
- export const addAgentScorer: AddWiring = (logger, node, checker, state) => {
18
- if (!ts.isCallExpression(node)) return
19
-
20
- const expression = node.expression
21
- if (!ts.isIdentifier(expression)) return
22
-
23
- const lane = LANES[expression.text]
24
- if (!lane) return
25
-
26
- const firstArg = node.arguments[0]
27
- if (!firstArg || !ts.isObjectLiteralExpression(firstArg)) return
28
-
29
- const obj = firstArg
30
- const { exportedName } = extractFunctionName(node, checker, state.rootDir)
31
-
32
- const nameValue = getPropertyValue(obj, 'name') as string | null
33
- if (!nameValue) {
34
- logger.critical(
35
- ErrorCode.MISSING_NAME,
36
- "AI scorer is missing the required 'name' property."
37
- )
38
- return
39
- }
40
-
41
- const description = getPropertyValue(obj, 'description') as string | null
42
- if (!description) {
43
- logger.critical(
44
- ErrorCode.MISSING_DESCRIPTION,
45
- `AI scorer '${nameValue}' is missing the required 'description' property.`
46
- )
47
- return
48
- }
49
-
50
- const sampleRateValue = getPropertyValue(obj, 'sampleRate') as number | null
51
- if (
52
- sampleRateValue !== null &&
53
- (sampleRateValue < 0 || sampleRateValue > 1)
54
- ) {
55
- logger.critical(
56
- ErrorCode.INVALID_VALUE,
57
- `AI scorer '${nameValue}' has a sampleRate of ${sampleRateValue} — it is the fraction of live runs to grade, so it must be between 0 and 1.`
58
- )
59
- return
60
- }
61
-
62
- const requiresReference =
63
- (getPropertyValue(obj, 'requiresReference') as boolean | null) ?? false
64
-
65
- const scorerKey = exportedName || nameValue
66
-
67
- if (exportedName) {
68
- state.scorers.files.set(scorerKey, {
69
- path: node.getSourceFile().fileName,
70
- exportedName,
71
- })
72
- }
73
-
74
- state.scorers.scorersMeta[scorerKey] = {
75
- name: nameValue,
76
- description,
77
- lane,
78
- sampleRate: sampleRateValue ?? 1,
79
- requiresReference,
80
- sourceFile: node.getSourceFile().fileName,
81
- exportedName: exportedName || undefined,
82
- }
83
- }
@@ -1,87 +0,0 @@
1
- import { describe, test } from 'node:test'
2
- import assert from 'node:assert'
3
- import * as ts from 'typescript'
4
-
5
- import { resolveWorkflowReferences } from './add-agent.js'
6
- import type { InspectorLogger } from '../types.js'
7
-
8
- function createSourceFile(code: string): ts.SourceFile {
9
- return ts.createSourceFile('test.ts', code, ts.ScriptTarget.ESNext, true)
10
- }
11
-
12
- function getObjectLiteral(
13
- sourceFile: ts.SourceFile
14
- ): ts.ObjectLiteralExpression {
15
- let result: ts.ObjectLiteralExpression | undefined
16
- ts.forEachChild(sourceFile, function visit(node) {
17
- if (ts.isObjectLiteralExpression(node) && !result) {
18
- result = node
19
- }
20
- ts.forEachChild(node, visit)
21
- })
22
- if (!result) throw new Error('No object literal found')
23
- return result
24
- }
25
-
26
- function createLogger(): {
27
- logger: InspectorLogger
28
- criticals: Array<{ code: unknown; message: string }>
29
- } {
30
- const criticals: Array<{ code: unknown; message: string }> = []
31
- const logger = {
32
- info: () => {},
33
- error: () => {},
34
- warn: () => {},
35
- debug: () => {},
36
- diagnostic: () => {},
37
- critical: (code: unknown, message: string) =>
38
- criticals.push({ code, message }),
39
- hasCriticalErrors: () => criticals.length > 0,
40
- } as unknown as InspectorLogger
41
- return { logger, criticals }
42
- }
43
-
44
- describe('resolveWorkflowReferences', () => {
45
- test('returns null when no workflows property exists', () => {
46
- const obj = getObjectLiteral(createSourceFile('const x = { name: "a" }'))
47
- const { logger } = createLogger()
48
- assert.strictEqual(
49
- resolveWorkflowReferences(obj, {} as any, 'a', logger),
50
- null
51
- )
52
- })
53
-
54
- test('returns null for an empty workflows array', () => {
55
- const obj = getObjectLiteral(
56
- createSourceFile('const x = { workflows: [] }')
57
- )
58
- const { logger } = createLogger()
59
- assert.strictEqual(
60
- resolveWorkflowReferences(obj, {} as any, 'a', logger),
61
- null
62
- )
63
- })
64
-
65
- test('resolves ref() and workflow() string-literal references', () => {
66
- const obj = getObjectLiteral(
67
- createSourceFile(
68
- `const x = { workflows: [ref('buildReport'), workflow('country_capitals')] }`
69
- )
70
- )
71
- const { logger, criticals } = createLogger()
72
- const result = resolveWorkflowReferences(obj, {} as any, 'planner', logger)
73
- assert.deepStrictEqual(result, ['buildReport', 'country_capitals'])
74
- assert.strictEqual(criticals.length, 0)
75
- })
76
-
77
- test('flags a raw string literal as a critical error', () => {
78
- const obj = getObjectLiteral(
79
- createSourceFile(`const x = { workflows: ['buildReport'] }`)
80
- )
81
- const { logger, criticals } = createLogger()
82
- const result = resolveWorkflowReferences(obj, {} as any, 'planner', logger)
83
- assert.strictEqual(result, null)
84
- assert.strictEqual(criticals.length, 1)
85
- assert.match(criticals[0].message, /string literal/)
86
- })
87
- })