@pikku/inspector 0.12.42 → 0.12.44
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.
- package/CHANGELOG.md +266 -0
- package/dist/add/add-addon-bans.js +1 -0
- package/dist/add/add-ai-agent.d.ts +3 -1
- package/dist/add/add-ai-agent.js +82 -0
- package/dist/add/add-credential.js +5 -1
- package/dist/add/add-functions.js +10 -9
- package/dist/add/add-gateway.js +3 -0
- package/dist/add/add-http-route.js +2 -2
- package/dist/add/add-keyed-wiring.js +2 -0
- package/dist/add/add-mcp-prompt.js +0 -1
- package/dist/add/add-mcp-resource.js +0 -1
- package/dist/add/add-permission.d.ts +1 -1
- package/dist/add/add-permission.js +3 -177
- package/dist/add/add-queue-worker.js +3 -0
- package/dist/add/add-schedule.js +3 -0
- package/dist/add/add-scope.d.ts +2 -0
- package/dist/add/add-scope.js +146 -0
- package/dist/add/add-trigger.js +3 -0
- package/dist/add/add-wire-remote-addon.d.ts +10 -0
- package/dist/add/add-wire-remote-addon.js +66 -0
- package/dist/add/add-workflow-graph.js +32 -3
- package/dist/add/add-workflow.js +9 -4
- package/dist/error-codes.d.ts +3 -0
- package/dist/error-codes.js +4 -0
- package/dist/inspector.js +11 -5
- package/dist/types.d.ts +19 -13
- package/dist/utils/custom-types-generator.js +2 -1
- package/dist/utils/ensure-function-metadata.d.ts +15 -0
- package/dist/utils/ensure-function-metadata.js +24 -0
- package/dist/utils/filter-inspector-state.js +9 -0
- package/dist/utils/get-property-value.d.ts +7 -2
- package/dist/utils/get-property-value.js +48 -1
- package/dist/utils/load-addon-functions-meta.js +81 -6
- package/dist/utils/permissions.d.ts +1 -21
- package/dist/utils/permissions.js +17 -108
- package/dist/utils/post-process.d.ts +30 -1
- package/dist/utils/post-process.js +150 -72
- package/dist/utils/schema-generator.js +19 -4
- package/dist/utils/serialize-inspector-state.d.ts +13 -8
- package/dist/utils/serialize-inspector-state.js +12 -6
- package/dist/utils/serialize-permissions-groups-meta.d.ts +0 -2
- package/dist/utils/serialize-permissions-groups-meta.js +0 -26
- package/dist/utils/workflow/derive-workflow-plan.js +9 -3
- package/dist/utils/workflow/dsl/deserialize-dsl-workflow.js +373 -91
- package/dist/utils/workflow/dsl/extract-dsl-workflow.js +274 -100
- package/dist/utils/workflow/dsl/patterns.d.ts +4 -0
- package/dist/utils/workflow/dsl/patterns.js +11 -0
- package/dist/utils/workflow/graph/convert-dsl-to-graph.js +76 -5
- package/dist/utils/workflow/graph/finalize-workflows.d.ts +7 -0
- package/dist/utils/workflow/graph/finalize-workflows.js +11 -2
- package/dist/utils/workflow/graph/serialize-workflow-graph.d.ts +2 -0
- package/dist/utils/workflow/graph/serialize-workflow-graph.js +4 -0
- package/dist/utils/workflow/graph/workflow-graph.types.d.ts +8 -4
- package/dist/visit.js +4 -0
- package/package.json +3 -3
- package/run-tests.sh +1 -1
- package/src/add/add-addon-bans.ts +1 -0
- package/src/add/add-ai-agent.test.ts +87 -0
- package/src/add/add-ai-agent.ts +122 -0
- package/src/add/add-credential.ts +8 -0
- package/src/add/add-functions.ts +10 -12
- package/src/add/add-gateway.ts +11 -0
- package/src/add/add-http-route.ts +2 -8
- package/src/add/add-keyed-wiring.ts +2 -0
- package/src/add/add-mcp-prompt.ts +0 -1
- package/src/add/add-mcp-resource.ts +0 -1
- package/src/add/add-permission.ts +4 -242
- package/src/add/add-queue-worker.ts +11 -0
- package/src/add/add-schedule.ts +11 -0
- package/src/add/add-scope.test.ts +346 -0
- package/src/add/add-scope.ts +225 -0
- package/src/add/add-trigger.ts +11 -0
- package/src/add/add-wire-remote-addon.ts +77 -0
- package/src/add/add-workflow-edge-cases.test.ts +201 -0
- package/src/add/add-workflow-fanout.test.ts +60 -0
- package/src/add/add-workflow-graph-input.test.ts +94 -0
- package/src/add/add-workflow-graph-notes.test.ts +74 -0
- package/src/add/add-workflow-graph.ts +35 -3
- package/src/add/add-workflow-on-error.test.ts +118 -0
- package/src/add/add-workflow-return-switch.test.ts +121 -0
- package/src/add/add-workflow-silent-drops.test.ts +163 -0
- package/src/add/add-workflow-sleep-expression.test.ts +97 -0
- package/src/add/add-workflow.ts +9 -4
- package/src/add/config-value-metadata.test.ts +169 -0
- package/src/add/inline-wiring-function.test.ts +104 -0
- package/src/add/validate-workflow-graph-addons.test.ts +102 -0
- package/src/error-codes.ts +5 -0
- package/src/inspector.ts +14 -4
- package/src/types.ts +16 -17
- package/src/utils/custom-types-generator.test.ts +26 -1
- package/src/utils/custom-types-generator.ts +2 -1
- package/src/utils/ensure-function-metadata.ts +42 -0
- package/src/utils/filter-inspector-state.test.ts +0 -2
- package/src/utils/filter-inspector-state.ts +9 -0
- package/src/utils/get-property-value.test.ts +141 -0
- package/src/utils/get-property-value.ts +62 -1
- package/src/utils/load-addon-functions-meta.test.ts +157 -0
- package/src/utils/load-addon-functions-meta.ts +94 -6
- package/src/utils/load-addon-scopes.test.ts +138 -0
- package/src/utils/permissions.test.ts +7 -232
- package/src/utils/permissions.ts +20 -160
- package/src/utils/post-process.test.ts +269 -4
- package/src/utils/post-process.ts +216 -95
- package/src/utils/schema-generator.test.ts +164 -0
- package/src/utils/schema-generator.ts +26 -3
- package/src/utils/serialize-inspector-state.ts +22 -25
- package/src/utils/serialize-permissions-groups-meta.ts +0 -28
- package/src/utils/workflow/derive-workflow-plan.test.ts +41 -3
- package/src/utils/workflow/derive-workflow-plan.ts +11 -4
- package/src/utils/workflow/dsl/deserialize-dsl-workflow.ts +480 -119
- package/src/utils/workflow/dsl/deserialize-fanout-body.test.ts +71 -0
- package/src/utils/workflow/dsl/deserialize-fanout-fidelity.test.ts +99 -0
- package/src/utils/workflow/dsl/deserialize-graph-next.test.ts +161 -0
- package/src/utils/workflow/dsl/deserialize-roundtrip-bindings.test.ts +121 -0
- package/src/utils/workflow/dsl/deserialize-roundtrip-values.test.ts +116 -0
- package/src/utils/workflow/dsl/deserialize-roundtrip.test.ts +145 -0
- package/src/utils/workflow/dsl/extract-dsl-workflow.ts +311 -105
- package/src/utils/workflow/dsl/patterns.ts +18 -0
- package/src/utils/workflow/graph/convert-dsl-to-graph.ts +82 -10
- package/src/utils/workflow/graph/fanout-node-identity.test.ts +105 -0
- package/src/utils/workflow/graph/finalize-workflows.test.ts +50 -0
- package/src/utils/workflow/graph/finalize-workflows.ts +13 -2
- package/src/utils/workflow/graph/serialize-workflow-graph.ts +6 -0
- package/src/utils/workflow/graph/workflow-graph.types.ts +11 -2
- package/src/visit.ts +4 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,145 @@
|
|
|
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 { deserializeDslWorkflow } from './deserialize-dsl-workflow.js'
|
|
9
|
+
|
|
10
|
+
function makeLogger(): InspectorLogger {
|
|
11
|
+
return {
|
|
12
|
+
debug: () => {},
|
|
13
|
+
info: () => {},
|
|
14
|
+
warn: () => {},
|
|
15
|
+
error: () => {},
|
|
16
|
+
diagnostic: () => {},
|
|
17
|
+
critical: () => {},
|
|
18
|
+
hasCriticalErrors: () => false,
|
|
19
|
+
} as any
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const STEP_FILE = [
|
|
23
|
+
"import { pikkuSessionlessFunc } from '@pikku/core'",
|
|
24
|
+
'export const discount = pikkuSessionlessFunc({',
|
|
25
|
+
' func: async () => ({ amount: 1 }),',
|
|
26
|
+
'})',
|
|
27
|
+
'export const notifySales = pikkuSessionlessFunc({',
|
|
28
|
+
' func: async () => ({ ok: true }),',
|
|
29
|
+
'})',
|
|
30
|
+
'export const provision = pikkuSessionlessFunc({',
|
|
31
|
+
' func: async () => ({ ok: true }),',
|
|
32
|
+
'})',
|
|
33
|
+
'export const auditLog = pikkuSessionlessFunc({',
|
|
34
|
+
' func: async () => ({ ok: true }),',
|
|
35
|
+
'})',
|
|
36
|
+
].join('\n')
|
|
37
|
+
|
|
38
|
+
/** Extract a workflow from source, then regenerate its code from the graph. */
|
|
39
|
+
async function roundTrip(body: string): Promise<string> {
|
|
40
|
+
const rootDir = await mkdtemp(join(tmpdir(), 'pikku-rt-'))
|
|
41
|
+
const stepFile = join(rootDir, 'w.steps.ts')
|
|
42
|
+
const wfFile = join(rootDir, 'w.workflow.ts')
|
|
43
|
+
await writeFile(stepFile, STEP_FILE)
|
|
44
|
+
await writeFile(
|
|
45
|
+
wfFile,
|
|
46
|
+
[
|
|
47
|
+
"import { pikkuWorkflowFunc } from '@pikku/core/workflow'",
|
|
48
|
+
'export const wf = pikkuWorkflowFunc(async (_, data: any, { workflow }) => {',
|
|
49
|
+
body,
|
|
50
|
+
'})',
|
|
51
|
+
].join('\n')
|
|
52
|
+
)
|
|
53
|
+
try {
|
|
54
|
+
const state: any = await inspect(makeLogger(), [stepFile, wfFile], {
|
|
55
|
+
rootDir,
|
|
56
|
+
})
|
|
57
|
+
const gm = state.workflows.graphMeta
|
|
58
|
+
const graph = (
|
|
59
|
+
gm instanceof Map ? [...gm.values()] : Object.values(gm)
|
|
60
|
+
)[0] as any
|
|
61
|
+
assert.ok(graph, 'a graph should have been produced')
|
|
62
|
+
return deserializeDslWorkflow(graph)
|
|
63
|
+
} finally {
|
|
64
|
+
await rm(rootDir, { recursive: true, force: true })
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
describe('DSL round-trip — code must survive graph regeneration', () => {
|
|
69
|
+
test('every step inside an if-branch survives', async () => {
|
|
70
|
+
const code = await roundTrip(
|
|
71
|
+
[
|
|
72
|
+
' if (data.total > 100) {',
|
|
73
|
+
" await workflow.do('Apply discount', 'discount', {})",
|
|
74
|
+
" await workflow.do('Notify sales', 'notifySales', {})",
|
|
75
|
+
' }',
|
|
76
|
+
' return { ok: true }',
|
|
77
|
+
].join('\n')
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
assert.ok(code.includes("'discount'"), 'first branch step should survive')
|
|
81
|
+
assert.ok(
|
|
82
|
+
code.includes("'notifySales'"),
|
|
83
|
+
`second branch step must not be deleted, got:\n${code}`
|
|
84
|
+
)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
test('every step inside a switch case survives', async () => {
|
|
88
|
+
const code = await roundTrip(
|
|
89
|
+
[
|
|
90
|
+
' switch (data.kind) {',
|
|
91
|
+
" case 'premium':",
|
|
92
|
+
" await workflow.do('Provision premium', 'provision', {})",
|
|
93
|
+
" await workflow.do('Audit premium', 'auditLog', {})",
|
|
94
|
+
' break',
|
|
95
|
+
' }',
|
|
96
|
+
' return { ok: true }',
|
|
97
|
+
].join('\n')
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
assert.ok(code.includes("'provision'"), 'first case step should survive')
|
|
101
|
+
assert.ok(
|
|
102
|
+
code.includes("'auditLog'"),
|
|
103
|
+
`second case step must not be deleted, got:\n${code}`
|
|
104
|
+
)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('step names survive — they are the durable replay cache key', async () => {
|
|
108
|
+
const code = await roundTrip(
|
|
109
|
+
[
|
|
110
|
+
" await workflow.do('Apply discount', 'discount', {})",
|
|
111
|
+
' return { ok: true }',
|
|
112
|
+
].join('\n')
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
assert.ok(
|
|
116
|
+
code.includes("'Apply discount'"),
|
|
117
|
+
`the authored step name must be preserved, got:\n${code}`
|
|
118
|
+
)
|
|
119
|
+
assert.ok(
|
|
120
|
+
!code.includes("'Call discount'"),
|
|
121
|
+
'the step must not be renamed to the Call <rpc> fallback'
|
|
122
|
+
)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
test('a suspend does not dead-end the graph and delete the steps after it', async () => {
|
|
126
|
+
const code = await roundTrip(
|
|
127
|
+
[
|
|
128
|
+
" await workflow.do('Create draft', 'discount', {})",
|
|
129
|
+
" await workflow.suspend('await legal review')",
|
|
130
|
+
" await workflow.do('Publish', 'notifySales', {})",
|
|
131
|
+
' return { ok: true }',
|
|
132
|
+
].join('\n')
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
assert.ok(code.includes("'discount'"), 'step before suspend should survive')
|
|
136
|
+
assert.ok(
|
|
137
|
+
code.includes("workflow.suspend('await legal review')"),
|
|
138
|
+
`the suspend itself must be regenerated, got:\n${code}`
|
|
139
|
+
)
|
|
140
|
+
assert.ok(
|
|
141
|
+
code.includes("'notifySales'"),
|
|
142
|
+
`steps after a suspend must not be deleted, got:\n${code}`
|
|
143
|
+
)
|
|
144
|
+
})
|
|
145
|
+
})
|