@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,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
- })