@pikku/inspector 0.12.74 → 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 +347 -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 +23 -13
  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 -2207
  142. package/src/utils/filter-inspector-state.ts +0 -1302
  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,48 +0,0 @@
1
- import type { FunctionsMeta } from '@pikku/core/services'
2
- import type { TypesMap } from '../types-map.js'
3
- import type { SchemaRef } from '../types.js'
4
-
5
- const PRIMITIVE_TYPES = new Set([
6
- 'boolean',
7
- 'string',
8
- 'number',
9
- 'null',
10
- 'undefined',
11
- 'void',
12
- 'any',
13
- 'unknown',
14
- 'never',
15
- ])
16
-
17
- export function computeRequiredSchemas(
18
- functionsMeta: FunctionsMeta,
19
- typesMap: TypesMap,
20
- additionalTypes?: string[],
21
- schemaLookup?: Map<string, SchemaRef>
22
- ): Set<string> {
23
- return new Set<string>([
24
- ...Object.values(functionsMeta)
25
- .flatMap(({ inputs, outputs }) => {
26
- const types: (string | undefined)[] = []
27
- if (inputs?.[0]) {
28
- try {
29
- types.push(typesMap.getUniqueName(inputs[0]))
30
- } catch {
31
- types.push(inputs[0])
32
- }
33
- }
34
- if (outputs?.[0]) {
35
- try {
36
- types.push(typesMap.getUniqueName(outputs[0]))
37
- } catch {
38
- types.push(outputs[0])
39
- }
40
- }
41
- return types
42
- })
43
- .filter((s): s is string => !!s && !PRIMITIVE_TYPES.has(s)),
44
- ...typesMap.customTypes.keys(),
45
- ...(additionalTypes || []),
46
- ...(schemaLookup ? Array.from(schemaLookup.keys()) : []),
47
- ])
48
- }
@@ -1,553 +0,0 @@
1
- import { strict as assert } from 'assert'
2
- import { describe, test } from 'node:test'
3
- import { canonicalJSON } from './hash.js'
4
- import {
5
- computeContractHash,
6
- createEmptyManifest,
7
- serializeManifest,
8
- validateContracts,
9
- updateManifest,
10
- extractContractsFromMeta,
11
- } from './contract-hashes.js'
12
- import type { ContractEntry, VersionManifest } from './contract-hashes.js'
13
- import type { FunctionsMeta } from '@pikku/core/services'
14
- import { ErrorCode } from '../error-codes.js'
15
-
16
- function makeContracts(
17
- entries: Record<
18
- string,
19
- {
20
- functionKey: string
21
- version: number
22
- contractHash: string
23
- inputHash?: string
24
- outputHash?: string
25
- }
26
- >
27
- ): Map<string, ContractEntry> {
28
- const map = new Map<string, ContractEntry>()
29
- for (const [id, entry] of Object.entries(entries)) {
30
- map.set(id, {
31
- ...entry,
32
- inputHash: entry.inputHash ?? entry.contractHash.slice(0, 8),
33
- outputHash: entry.outputHash ?? entry.contractHash.slice(0, 8),
34
- })
35
- }
36
- return map
37
- }
38
-
39
- describe('canonicalJSON', () => {
40
- test('sorts object keys alphabetically', () => {
41
- assert.strictEqual(canonicalJSON({ b: 2, a: 1 }), '{"a":1,"b":2}')
42
- })
43
-
44
- test('sorts nested objects recursively', () => {
45
- const input = { z: { b: 2, a: 1 }, a: { d: 4, c: 3 } }
46
- const expected = '{"a":{"c":3,"d":4},"z":{"a":1,"b":2}}'
47
- assert.strictEqual(canonicalJSON(input), expected)
48
- })
49
-
50
- test('preserves array order', () => {
51
- assert.strictEqual(canonicalJSON([3, 1, 2]), '[3,1,2]')
52
- assert.strictEqual(
53
- canonicalJSON([
54
- { b: 1, a: 2 },
55
- { d: 3, c: 4 },
56
- ]),
57
- '[{"a":2,"b":1},{"c":4,"d":3}]'
58
- )
59
- })
60
-
61
- test('handles null/undefined/primitives', () => {
62
- assert.strictEqual(canonicalJSON(null), 'null')
63
- assert.strictEqual(canonicalJSON(undefined), undefined)
64
- assert.strictEqual(canonicalJSON(42), '42')
65
- assert.strictEqual(canonicalJSON('hello'), '"hello"')
66
- assert.strictEqual(canonicalJSON(true), 'true')
67
- })
68
-
69
- test('deterministic regardless of insertion order', () => {
70
- const a: Record<string, number> = {}
71
- a['x'] = 1
72
- a['a'] = 2
73
- a['m'] = 3
74
-
75
- const b: Record<string, number> = {}
76
- b['m'] = 3
77
- b['a'] = 2
78
- b['x'] = 1
79
-
80
- assert.strictEqual(canonicalJSON(a), canonicalJSON(b))
81
- })
82
- })
83
-
84
- describe('computeContractHash', () => {
85
- test('returns 16-char hex string', () => {
86
- const hash = computeContractHash({
87
- functionKey: 'createUser',
88
- inputSchema: { type: 'object' },
89
- outputSchema: { type: 'object' },
90
- })
91
- assert.match(hash, /^[0-9a-f]{16}$/)
92
- })
93
-
94
- test('stable across calls', () => {
95
- const data = {
96
- functionKey: 'getUser',
97
- inputSchema: { id: 'string' },
98
- outputSchema: { name: 'string' },
99
- }
100
- assert.strictEqual(computeContractHash(data), computeContractHash(data))
101
- })
102
-
103
- test('different functionKey produces different hash', () => {
104
- const schema = { type: 'object' }
105
- const hash1 = computeContractHash({
106
- functionKey: 'createUser',
107
- inputSchema: schema,
108
- outputSchema: schema,
109
- })
110
- const hash2 = computeContractHash({
111
- functionKey: 'deleteUser',
112
- inputSchema: schema,
113
- outputSchema: schema,
114
- })
115
- assert.notStrictEqual(hash1, hash2)
116
- })
117
-
118
- test('different schema produces different hash', () => {
119
- const hash1 = computeContractHash({
120
- functionKey: 'createUser',
121
- inputSchema: { type: 'string' },
122
- outputSchema: null,
123
- })
124
- const hash2 = computeContractHash({
125
- functionKey: 'createUser',
126
- inputSchema: { type: 'number' },
127
- outputSchema: null,
128
- })
129
- assert.notStrictEqual(hash1, hash2)
130
- })
131
- })
132
-
133
- describe('createEmptyManifest', () => {
134
- test('returns empty manifest with version 1', () => {
135
- assert.deepStrictEqual(createEmptyManifest(), {
136
- manifestVersion: 1,
137
- contracts: {},
138
- })
139
- })
140
- })
141
-
142
- describe('serializeManifest', () => {
143
- test('sorts contract keys alphabetically', () => {
144
- const manifest: VersionManifest = {
145
- manifestVersion: 1,
146
- contracts: {
147
- zeta: { latest: 1, versions: { '1': 'abc' } },
148
- alpha: { latest: 1, versions: { '1': 'def' } },
149
- },
150
- }
151
- const result = serializeManifest(manifest)
152
- const keys = Object.keys(JSON.parse(result).contracts)
153
- assert.deepStrictEqual(keys, ['alpha', 'zeta'])
154
- })
155
-
156
- test('sorts version keys numerically', () => {
157
- const manifest: VersionManifest = {
158
- manifestVersion: 1,
159
- contracts: {
160
- func: { latest: 10, versions: { '10': 'c', '2': 'b', '1': 'a' } },
161
- },
162
- }
163
- const result = serializeManifest(manifest)
164
- const versionKeys = Object.keys(JSON.parse(result).contracts.func.versions)
165
- assert.deepStrictEqual(versionKeys, ['1', '2', '10'])
166
- })
167
-
168
- test('ends with trailing newline', () => {
169
- const manifest: VersionManifest = {
170
- manifestVersion: 1,
171
- contracts: {},
172
- }
173
- const result = serializeManifest(manifest)
174
- assert.ok(result.endsWith('\n'))
175
- })
176
-
177
- test('idempotent', () => {
178
- const manifest: VersionManifest = {
179
- manifestVersion: 1,
180
- contracts: {
181
- beta: { latest: 2, versions: { '2': 'xyz', '1': 'abc' } },
182
- alpha: { latest: 1, versions: { '1': 'def' } },
183
- },
184
- }
185
- const first = serializeManifest(manifest)
186
- const second = serializeManifest(JSON.parse(first))
187
- assert.strictEqual(first, second)
188
- })
189
- })
190
-
191
- describe('validateContracts', () => {
192
- describe('PKU861 — FUNCTION_VERSION_MODIFIED', () => {
193
- test('hash changed for existing version produces error', () => {
194
- const manifest: VersionManifest = {
195
- manifestVersion: 1,
196
- contracts: {
197
- createUser: { latest: 1, versions: { '1': 'oldhash1234567890' } },
198
- },
199
- }
200
- const contracts = makeContracts({
201
- createUser: {
202
- functionKey: 'createUser',
203
- version: 1,
204
- contractHash: 'newhash1234567890',
205
- },
206
- })
207
- const result = validateContracts(manifest, contracts)
208
- assert.strictEqual(result.valid, false)
209
- assert.strictEqual(result.errors.length, 1)
210
- assert.strictEqual(
211
- result.errors[0].code,
212
- ErrorCode.FUNCTION_VERSION_MODIFIED
213
- )
214
- })
215
-
216
- test('hash unchanged for existing version produces no error', () => {
217
- const manifest: VersionManifest = {
218
- manifestVersion: 1,
219
- contracts: {
220
- createUser: { latest: 1, versions: { '1': 'samehash123456789' } },
221
- },
222
- }
223
- const contracts = makeContracts({
224
- createUser: {
225
- functionKey: 'createUser',
226
- version: 1,
227
- contractHash: 'samehash123456789',
228
- },
229
- })
230
- const result = validateContracts(manifest, contracts)
231
- assert.strictEqual(result.valid, true)
232
- assert.strictEqual(result.errors.length, 0)
233
- })
234
- })
235
-
236
- describe('PKU862 — CONTRACT_CHANGED_REQUIRES_BUMP', () => {
237
- test('latest hash changed without recorded version produces bump error', () => {
238
- const manifest: VersionManifest = {
239
- manifestVersion: 1,
240
- contracts: {
241
- getUser: { latest: 1, versions: {} },
242
- },
243
- }
244
- const contracts = makeContracts({
245
- getUser: {
246
- functionKey: 'getUser',
247
- version: 1,
248
- contractHash: 'newhash1234567890',
249
- },
250
- })
251
- const result = validateContracts(manifest, contracts)
252
- const bump = result.errors.find(
253
- (e) => e.code === ErrorCode.CONTRACT_CHANGED_REQUIRES_BUMP
254
- )
255
- assert.ok(bump)
256
- })
257
-
258
- test('function removed from code but still in manifest produces no error', () => {
259
- const manifest: VersionManifest = {
260
- manifestVersion: 1,
261
- contracts: {
262
- deletedFunc: { latest: 1, versions: { '1': 'abc1234567890abc' } },
263
- },
264
- }
265
- const contracts = makeContracts({})
266
- const result = validateContracts(manifest, contracts)
267
- assert.strictEqual(result.valid, true)
268
- assert.strictEqual(result.errors.length, 0)
269
- })
270
- })
271
-
272
- describe('PKU863 — VERSION_REGRESSION_OR_CONFLICT', () => {
273
- test('new version <= latest but not recorded produces error', () => {
274
- const manifest: VersionManifest = {
275
- manifestVersion: 1,
276
- contracts: {
277
- createUser: {
278
- latest: 3,
279
- versions: { '1': 'aaa', '2': 'bbb', '3': 'ccc' },
280
- },
281
- },
282
- }
283
- const contracts = makeContracts({
284
- 'createUser@v2': {
285
- functionKey: 'createUser',
286
- version: 2,
287
- contractHash: 'bbb',
288
- },
289
- 'createUser@v3': {
290
- functionKey: 'createUser',
291
- version: 3,
292
- contractHash: 'ccc',
293
- },
294
- 'createUser@v1': {
295
- functionKey: 'createUser',
296
- version: 1,
297
- contractHash: 'different_hash!',
298
- },
299
- })
300
- const result = validateContracts(manifest, contracts)
301
- const regression = result.errors.find(
302
- (e) => e.code === ErrorCode.VERSION_REGRESSION_OR_CONFLICT
303
- )
304
- assert.strictEqual(regression, undefined)
305
-
306
- const manifest2: VersionManifest = {
307
- manifestVersion: 1,
308
- contracts: {
309
- myFunc: { latest: 3, versions: { '1': 'aaa', '3': 'ccc' } },
310
- },
311
- }
312
- const contracts2 = makeContracts({
313
- 'myFunc@v2': { functionKey: 'myFunc', version: 2, contractHash: 'xxx' },
314
- 'myFunc@v3': { functionKey: 'myFunc', version: 3, contractHash: 'ccc' },
315
- })
316
- const result2 = validateContracts(manifest2, contracts2)
317
- const regression2 = result2.errors.find(
318
- (e) => e.code === ErrorCode.VERSION_REGRESSION_OR_CONFLICT
319
- )
320
- assert.ok(regression2)
321
- })
322
- })
323
-
324
- describe('PKU864 — VERSION_GAP_NOT_ALLOWED', () => {
325
- test('new version > latest + 1 produces error', () => {
326
- const manifest: VersionManifest = {
327
- manifestVersion: 1,
328
- contracts: {
329
- createUser: { latest: 1, versions: { '1': 'aaa' } },
330
- },
331
- }
332
- const contracts = makeContracts({
333
- 'createUser@v3': {
334
- functionKey: 'createUser',
335
- version: 3,
336
- contractHash: 'xxx',
337
- },
338
- })
339
- const result = validateContracts(manifest, contracts)
340
- const gap = result.errors.find(
341
- (e) => e.code === ErrorCode.VERSION_GAP_NOT_ALLOWED
342
- )
343
- assert.ok(gap)
344
- })
345
- })
346
-
347
- describe('PKU865 — MANIFEST_INTEGRITY_ERROR', () => {
348
- test('latest field not matching max version key produces error', () => {
349
- const manifest: VersionManifest = {
350
- manifestVersion: 1,
351
- contracts: {
352
- createUser: { latest: 1, versions: { '1': 'aaa', '2': 'bbb' } },
353
- },
354
- }
355
- const contracts = makeContracts({})
356
- const result = validateContracts(manifest, contracts)
357
- const integrity = result.errors.find(
358
- (e) => e.code === ErrorCode.MANIFEST_INTEGRITY_ERROR
359
- )
360
- assert.ok(integrity)
361
- })
362
- })
363
-
364
- describe('happy paths', () => {
365
- test('new function not in manifest is valid', () => {
366
- const manifest: VersionManifest = {
367
- manifestVersion: 1,
368
- contracts: {},
369
- }
370
- const contracts = makeContracts({
371
- createUser: {
372
- functionKey: 'createUser',
373
- version: 1,
374
- contractHash: 'abc123',
375
- },
376
- })
377
- const result = validateContracts(manifest, contracts)
378
- assert.strictEqual(result.valid, true)
379
- })
380
-
381
- test('correct version bump is valid', () => {
382
- const manifest: VersionManifest = {
383
- manifestVersion: 1,
384
- contracts: {
385
- createUser: { latest: 1, versions: { '1': 'aaa' } },
386
- },
387
- }
388
- const contracts = makeContracts({
389
- 'createUser@v1': {
390
- functionKey: 'createUser',
391
- version: 1,
392
- contractHash: 'aaa',
393
- },
394
- 'createUser@v2': {
395
- functionKey: 'createUser',
396
- version: 2,
397
- contractHash: 'bbb',
398
- },
399
- })
400
- const result = validateContracts(manifest, contracts)
401
- assert.strictEqual(result.valid, true)
402
- })
403
-
404
- test('empty manifest with new contracts is valid', () => {
405
- const manifest: VersionManifest = {
406
- manifestVersion: 1,
407
- contracts: {},
408
- }
409
- const contracts = makeContracts({
410
- funcA: { functionKey: 'funcA', version: 1, contractHash: 'aaa' },
411
- funcB: { functionKey: 'funcB', version: 1, contractHash: 'bbb' },
412
- })
413
- const result = validateContracts(manifest, contracts)
414
- assert.strictEqual(result.valid, true)
415
- })
416
- })
417
- })
418
-
419
- describe('updateManifest', () => {
420
- test('adds new function to empty manifest', () => {
421
- const manifest: VersionManifest = { manifestVersion: 1, contracts: {} }
422
- const contracts = makeContracts({
423
- createUser: {
424
- functionKey: 'createUser',
425
- version: 1,
426
- contractHash: 'abc',
427
- inputHash: 'in123456',
428
- outputHash: 'out1234',
429
- },
430
- })
431
- const result = updateManifest(manifest, contracts)
432
- assert.strictEqual(result.contracts.createUser.latest, 1)
433
- assert.deepStrictEqual(result.contracts.createUser.versions['1'], {
434
- inputHash: 'in123456',
435
- outputHash: 'out1234',
436
- })
437
- })
438
-
439
- test('adds new version to existing function and updates latest', () => {
440
- const manifest: VersionManifest = {
441
- manifestVersion: 1,
442
- contracts: {
443
- createUser: { latest: 1, versions: { '1': 'aaa' } },
444
- },
445
- }
446
- const contracts = makeContracts({
447
- 'createUser@v1': {
448
- functionKey: 'createUser',
449
- version: 1,
450
- contractHash: 'aaa',
451
- inputHash: 'inaaa123',
452
- outputHash: 'outaaa12',
453
- },
454
- 'createUser@v2': {
455
- functionKey: 'createUser',
456
- version: 2,
457
- contractHash: 'bbb',
458
- inputHash: 'inbbb123',
459
- outputHash: 'outbbb12',
460
- },
461
- })
462
- const result = updateManifest(manifest, contracts)
463
- assert.strictEqual(result.contracts.createUser.latest, 2)
464
- assert.deepStrictEqual(result.contracts.createUser.versions['2'], {
465
- inputHash: 'inbbb123',
466
- outputHash: 'outbbb12',
467
- })
468
- assert.deepStrictEqual(result.contracts.createUser.versions['1'], {
469
- inputHash: 'inaaa123',
470
- outputHash: 'outaaa12',
471
- })
472
- })
473
-
474
- test('preserves deleted functions', () => {
475
- const manifest: VersionManifest = {
476
- manifestVersion: 1,
477
- contracts: {
478
- removedFunc: { latest: 1, versions: { '1': 'old' } },
479
- },
480
- }
481
- const contracts = makeContracts({
482
- newFunc: { functionKey: 'newFunc', version: 1, contractHash: 'new' },
483
- })
484
- const result = updateManifest(manifest, contracts)
485
- assert.ok(result.contracts.removedFunc)
486
- assert.strictEqual(result.contracts.removedFunc.latest, 1)
487
- assert.ok(result.contracts.newFunc)
488
- })
489
-
490
- test('does not mutate input manifest', () => {
491
- const manifest: VersionManifest = {
492
- manifestVersion: 1,
493
- contracts: {
494
- createUser: { latest: 1, versions: { '1': 'aaa' } },
495
- },
496
- }
497
- const before = JSON.stringify(manifest)
498
- const contracts = makeContracts({
499
- 'createUser@v2': {
500
- functionKey: 'createUser',
501
- version: 2,
502
- contractHash: 'bbb',
503
- },
504
- })
505
- updateManifest(manifest, contracts)
506
- assert.strictEqual(JSON.stringify(manifest), before)
507
- })
508
- })
509
-
510
- describe('extractContractsFromMeta', () => {
511
- test('extracts entries where contractHash is set', () => {
512
- const meta: FunctionsMeta = {
513
- createUser: {
514
- pikkuFuncId: 'createUser',
515
- inputSchemaName: 'CreateUserInput',
516
- outputSchemaName: 'CreateUserOutput',
517
- contractHash: 'abc123',
518
- },
519
- }
520
- const result = extractContractsFromMeta(meta)
521
- assert.strictEqual(result.size, 1)
522
- assert.ok(result.has('createUser'))
523
- assert.strictEqual(result.get('createUser')!.contractHash, 'abc123')
524
- assert.strictEqual(result.get('createUser')!.functionKey, 'createUser')
525
- assert.strictEqual(result.get('createUser')!.version, 1)
526
- })
527
-
528
- test('skips remote functions', () => {
529
- const meta: FunctionsMeta = {
530
- remoteFunc: {
531
- pikkuFuncId: 'remoteFunc',
532
- inputSchemaName: null,
533
- outputSchemaName: null,
534
- remote: true,
535
- contractHash: 'shouldskip',
536
- },
537
- }
538
- const result = extractContractsFromMeta(meta)
539
- assert.strictEqual(result.size, 0)
540
- })
541
-
542
- test('skips functions without contractHash', () => {
543
- const meta: FunctionsMeta = {
544
- noHash: {
545
- pikkuFuncId: 'noHash',
546
- inputSchemaName: null,
547
- outputSchemaName: null,
548
- },
549
- }
550
- const result = extractContractsFromMeta(meta)
551
- assert.strictEqual(result.size, 0)
552
- })
553
- })