@fugood/bricks-ctor 2.25.0-beta.11 → 2.25.0-beta.12
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/compile/__tests__/util.test.js +278 -0
- package/package.json +3 -3
- package/tools/deploy.ts +4 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { generateCalulationMap, validateConfig } from '../util'
|
|
2
|
+
|
|
3
|
+
const baseConfig = (overrides = {}) => ({
|
|
4
|
+
inputs: {},
|
|
5
|
+
enable_async: false,
|
|
6
|
+
disabled_triggers: {},
|
|
7
|
+
output: null,
|
|
8
|
+
outputs: {},
|
|
9
|
+
error: null,
|
|
10
|
+
code: 'return inputs',
|
|
11
|
+
...overrides,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const SANDBOX_PREFIX = 'PROPERTY_BANK_COMMAND_NODE_'
|
|
15
|
+
|
|
16
|
+
const sandboxNodeIds = (map) =>
|
|
17
|
+
Object.entries(map)
|
|
18
|
+
.filter(([id, node]) => id.startsWith(SANDBOX_PREFIX) && node.type === 'command-node-sandbox')
|
|
19
|
+
.map(([id, node]) => ({ id, command: node.properties.command }))
|
|
20
|
+
|
|
21
|
+
const findSandboxIds = (map) => {
|
|
22
|
+
const sandbox = sandboxNodeIds(map)
|
|
23
|
+
return {
|
|
24
|
+
run: sandbox.find((s) => s.command === 'SANDBOX_RUN_JAVASCRIPT')?.id,
|
|
25
|
+
error: sandbox.find((s) => s.command === 'SANDBOX_GET_ERROR')?.id,
|
|
26
|
+
result: sandbox.find((s) => s.command === 'SANDBOX_GET_RETURN_VALUE')?.id,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('validateConfig', () => {
|
|
31
|
+
test('returns without throwing for a clean config', () => {
|
|
32
|
+
expect(() => validateConfig(baseConfig({ inputs: { a: 'foo' } }))).not.toThrow()
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
test('skips overlap checks in manual trigger mode', () => {
|
|
36
|
+
const config = baseConfig({
|
|
37
|
+
trigger_mode: 'manual',
|
|
38
|
+
inputs: { a: 'foo' },
|
|
39
|
+
output: 'a',
|
|
40
|
+
error: 'a',
|
|
41
|
+
outputs: { x: ['a'] },
|
|
42
|
+
})
|
|
43
|
+
expect(() => validateConfig(config)).not.toThrow()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test('throws when error key collides with an input id', () => {
|
|
47
|
+
const config = baseConfig({ inputs: { a: 'foo' }, error: 'a' })
|
|
48
|
+
expect(() => validateConfig(config)).toThrow(/key: error/)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test('throws when output key collides with an input id', () => {
|
|
52
|
+
const config = baseConfig({ inputs: { a: 'foo' }, output: 'a' })
|
|
53
|
+
expect(() => validateConfig(config)).toThrow(/key: output/)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('throws when any outputs entry references an input id', () => {
|
|
57
|
+
const config = baseConfig({
|
|
58
|
+
inputs: { a: 'foo', b: 'bar' },
|
|
59
|
+
outputs: { x: ['c', 'b'] },
|
|
60
|
+
})
|
|
61
|
+
expect(() => validateConfig(config)).toThrow(/key: outputs/)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('does not throw when error/output are falsy and inputs are empty', () => {
|
|
65
|
+
expect(() => validateConfig(baseConfig())).not.toThrow()
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
describe('generateCalulationMap', () => {
|
|
70
|
+
test('produces only the three sandbox nodes for an empty config', () => {
|
|
71
|
+
const result = generateCalulationMap(baseConfig())
|
|
72
|
+
|
|
73
|
+
expect(Object.keys(result.map)).toHaveLength(3)
|
|
74
|
+
const { run, error, result: returnValue } = findSandboxIds(result.map)
|
|
75
|
+
|
|
76
|
+
expect(result.map[run].in.inputs).toEqual([])
|
|
77
|
+
expect(result.map[error].out.result).toEqual([])
|
|
78
|
+
expect(result.map[returnValue].out.result).toEqual([])
|
|
79
|
+
expect(Object.keys(result.editor_info)).toHaveLength(3)
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
test('chains multiple inputs through OBJECT_SET commands', () => {
|
|
83
|
+
const result = generateCalulationMap(baseConfig({ inputs: { a: 'foo.bar', b: 'baz' } }))
|
|
84
|
+
|
|
85
|
+
const { run } = findSandboxIds(result.map)
|
|
86
|
+
|
|
87
|
+
// Each input gets a data-node + an OBJECT_SET command-node.
|
|
88
|
+
expect(result.map.a.type).toBe('data-node')
|
|
89
|
+
expect(result.map.b.type).toBe('data-node')
|
|
90
|
+
|
|
91
|
+
const aCommandId = result.map.a.out.value[0].id
|
|
92
|
+
const bCommandId = result.map.b.out.value[0].id
|
|
93
|
+
expect(aCommandId).not.toBe(bCommandId)
|
|
94
|
+
|
|
95
|
+
const aCmd = result.map[aCommandId]
|
|
96
|
+
const bCmd = result.map[bCommandId]
|
|
97
|
+
expect(aCmd.properties.command).toBe('OBJECT_SET')
|
|
98
|
+
expect(aCmd.properties.args.path).toBe('foo.bar')
|
|
99
|
+
expect(bCmd.properties.command).toBe('OBJECT_SET')
|
|
100
|
+
expect(bCmd.properties.args.path).toBe('baz')
|
|
101
|
+
|
|
102
|
+
// First command has no upstream obj; second command's obj input is the first command.
|
|
103
|
+
expect(aCmd.in.obj).toBeNull()
|
|
104
|
+
expect(bCmd.in.obj).toEqual([{ id: aCommandId, port: 'result' }])
|
|
105
|
+
// First command forwards its result to the second command's `obj` input.
|
|
106
|
+
expect(aCmd.out.result).toEqual([{ id: bCommandId, port: 'obj' }])
|
|
107
|
+
// The last command feeds the SANDBOX_RUN_JAVASCRIPT `inputs` port.
|
|
108
|
+
expect(bCmd.out.result).toEqual([{ id: run, port: 'inputs' }])
|
|
109
|
+
expect(result.map[run].in.inputs).toEqual([{ id: bCommandId, port: 'result' }])
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
test('builds OBJECT_GET commands and target data-nodes for outputs', () => {
|
|
113
|
+
const result = generateCalulationMap(baseConfig({ outputs: { resultPath: ['pb1', 'pb2'] } }))
|
|
114
|
+
|
|
115
|
+
const { result: returnValue } = findSandboxIds(result.map)
|
|
116
|
+
|
|
117
|
+
// Both target property-bank nodes are created as data-nodes.
|
|
118
|
+
expect(result.map.pb1.type).toBe('data-node')
|
|
119
|
+
expect(result.map.pb2.type).toBe('data-node')
|
|
120
|
+
|
|
121
|
+
// The SANDBOX_GET_RETURN_VALUE forwards to the OBJECT_GET command for the output entry.
|
|
122
|
+
const objectGetRefs = result.map[returnValue].out.result
|
|
123
|
+
expect(objectGetRefs).toHaveLength(1)
|
|
124
|
+
const getCommandId = objectGetRefs[0].id
|
|
125
|
+
expect(objectGetRefs[0].port).toBe('obj')
|
|
126
|
+
|
|
127
|
+
const getCmd = result.map[getCommandId]
|
|
128
|
+
expect(getCmd.type).toBe('command-node-object')
|
|
129
|
+
expect(getCmd.properties.command).toBe('OBJECT_GET')
|
|
130
|
+
expect(getCmd.properties.args.path).toBe('resultPath')
|
|
131
|
+
expect(getCmd.in.obj).toEqual([{ id: returnValue, port: 'result' }])
|
|
132
|
+
|
|
133
|
+
// OBJECT_GET feeds both target data-nodes' `change` ports.
|
|
134
|
+
expect(getCmd.out.result).toEqual([
|
|
135
|
+
{ id: 'pb1', port: 'change' },
|
|
136
|
+
{ id: 'pb2', port: 'change' },
|
|
137
|
+
])
|
|
138
|
+
// Target data-nodes consume the OBJECT_GET result via their `change` port.
|
|
139
|
+
expect(result.map.pb1.in.change).toEqual([{ id: getCommandId, port: 'result' }])
|
|
140
|
+
expect(result.map.pb2.in.change).toEqual([{ id: getCommandId, port: 'result' }])
|
|
141
|
+
|
|
142
|
+
// Without input usage their `out.value` defaults to null.
|
|
143
|
+
expect(result.map.pb1.out.value).toBeNull()
|
|
144
|
+
expect(result.map.pb2.out.value).toBeNull()
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
// Manual mode is the only mode that lets an output target reuse an input id
|
|
148
|
+
// (see validateConfig tests). When that happens, generateCalulationMap must
|
|
149
|
+
// keep the input-side `out.value` so the data-node remains a usable input.
|
|
150
|
+
test.each([
|
|
151
|
+
['outputs', { outputs: { result: ['shared'] } }],
|
|
152
|
+
['output', { output: 'shared' }],
|
|
153
|
+
['error', { error: 'shared' }],
|
|
154
|
+
])('preserves input out.value when %s target reuses an input id', (_, overrides) => {
|
|
155
|
+
const result = generateCalulationMap(
|
|
156
|
+
baseConfig({ trigger_mode: 'manual', inputs: { shared: 'foo' }, ...overrides }),
|
|
157
|
+
)
|
|
158
|
+
expect(Array.isArray(result.map.shared.out.value)).toBe(true)
|
|
159
|
+
expect(result.map[result.map.shared.out.value[0].id].properties.command).toBe('OBJECT_SET')
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
test('also rewires in.change to OBJECT_GET when an outputs target reuses an input id', () => {
|
|
163
|
+
const result = generateCalulationMap(
|
|
164
|
+
baseConfig({
|
|
165
|
+
trigger_mode: 'manual',
|
|
166
|
+
inputs: { shared: 'foo' },
|
|
167
|
+
outputs: { result: ['shared'] },
|
|
168
|
+
}),
|
|
169
|
+
)
|
|
170
|
+
expect(result.map.shared.in.change).toHaveLength(1)
|
|
171
|
+
expect(result.map[result.map.shared.in.change[0].id].properties.command).toBe('OBJECT_GET')
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
test('preserves out.value when the same pb appears in multiple outputs entries', () => {
|
|
175
|
+
// Two outputs entries both target `pb1`. The reduce visits each entry in turn
|
|
176
|
+
// and must preserve the accumulated `out.value` from the first iteration via
|
|
177
|
+
// `acc.map[pb]` rather than wiping it on the second.
|
|
178
|
+
const result = generateCalulationMap(
|
|
179
|
+
baseConfig({ outputs: { first: ['pb1'], second: ['pb1'] } }),
|
|
180
|
+
)
|
|
181
|
+
expect(result.map.pb1.type).toBe('data-node')
|
|
182
|
+
// Without an input, out.value remains null after both passes.
|
|
183
|
+
expect(result.map.pb1.out.value).toBeNull()
|
|
184
|
+
// The latest OBJECT_GET wins as the change source — each iteration overwrites
|
|
185
|
+
// `in.change`, so we end up pointing at the second outputs entry's command.
|
|
186
|
+
expect(result.map.pb1.in.change).toHaveLength(1)
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
test('wires the error data-node when error is configured', () => {
|
|
190
|
+
const result = generateCalulationMap(baseConfig({ error: 'errNode' }))
|
|
191
|
+
|
|
192
|
+
const { error } = findSandboxIds(result.map)
|
|
193
|
+
// SANDBOX_GET_ERROR now broadcasts to the error data-node's `change` port.
|
|
194
|
+
expect(result.map[error].out.result).toEqual([{ id: 'errNode', port: 'change' }])
|
|
195
|
+
expect(result.map.errNode.type).toBe('data-node')
|
|
196
|
+
expect(result.map.errNode.in.change).toEqual([{ id: error, port: 'result' }])
|
|
197
|
+
// No upstream input → out.value falls back to null.
|
|
198
|
+
expect(result.map.errNode.out.value).toBeNull()
|
|
199
|
+
// editor_info contains the new node.
|
|
200
|
+
expect(result.editor_info.errNode).toBeDefined()
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
test('wires the output data-node when output is configured', () => {
|
|
204
|
+
const result = generateCalulationMap(baseConfig({ output: 'outNode' }))
|
|
205
|
+
|
|
206
|
+
const { result: returnValue } = findSandboxIds(result.map)
|
|
207
|
+
expect(result.map[returnValue].out.result).toEqual([{ id: 'outNode', port: 'change' }])
|
|
208
|
+
expect(result.map.outNode.type).toBe('data-node')
|
|
209
|
+
expect(result.map.outNode.in.change).toEqual([{ id: returnValue, port: 'result' }])
|
|
210
|
+
expect(result.editor_info.outNode).toBeDefined()
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
test('manual trigger mode sets disable_trigger_command on input value ports', () => {
|
|
214
|
+
const result = generateCalulationMap(
|
|
215
|
+
baseConfig({
|
|
216
|
+
trigger_mode: 'manual',
|
|
217
|
+
inputs: { a: 'foo', b: 'bar' },
|
|
218
|
+
}),
|
|
219
|
+
)
|
|
220
|
+
const aCmdId = result.map.a.out.value[0].id
|
|
221
|
+
const bCmdId = result.map.b.out.value[0].id
|
|
222
|
+
expect(result.map[aCmdId].in.value[0].disable_trigger_command).toBe(true)
|
|
223
|
+
expect(result.map[bCmdId].in.value[0].disable_trigger_command).toBe(true)
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
test('auto trigger mode honours per-key disabled_triggers', () => {
|
|
227
|
+
const result = generateCalulationMap(
|
|
228
|
+
baseConfig({
|
|
229
|
+
inputs: { a: 'foo', b: 'bar' },
|
|
230
|
+
disabled_triggers: { a: true, b: false },
|
|
231
|
+
}),
|
|
232
|
+
)
|
|
233
|
+
const aCmdId = result.map.a.out.value[0].id
|
|
234
|
+
const bCmdId = result.map.b.out.value[0].id
|
|
235
|
+
expect(result.map[aCmdId].in.value[0].disable_trigger_command).toBe(true)
|
|
236
|
+
// Falsy disabled_triggers entry → property is not set (or set to undefined).
|
|
237
|
+
expect(result.map[bCmdId].in.value[0].disable_trigger_command).toBeUndefined()
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
test('auto trigger mode without disabled_triggers leaves disable_trigger_command undefined', () => {
|
|
241
|
+
const result = generateCalulationMap(baseConfig({ inputs: { a: 'foo' } }))
|
|
242
|
+
const aCmdId = result.map.a.out.value[0].id
|
|
243
|
+
expect(result.map[aCmdId].in.value[0].disable_trigger_command).toBeUndefined()
|
|
244
|
+
})
|
|
245
|
+
|
|
246
|
+
test('snapshotMode forwards to makeId so generated ids are sequential', () => {
|
|
247
|
+
const result = generateCalulationMap(baseConfig({ inputs: { a: 'foo' } }), {
|
|
248
|
+
snapshotMode: true,
|
|
249
|
+
})
|
|
250
|
+
const sandboxIds = sandboxNodeIds(result.map).map((s) => s.id)
|
|
251
|
+
// Snapshot-mode ids embed a 12-digit counter — stable suffix lets us assert order.
|
|
252
|
+
sandboxIds.forEach((id) => {
|
|
253
|
+
expect(id).toMatch(/^PROPERTY_BANK_COMMAND_NODE_00000000-0000-0000-0000-\d{12}$/)
|
|
254
|
+
})
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
test('validateConfig errors propagate out of generateCalulationMap', () => {
|
|
258
|
+
expect(() => generateCalulationMap(baseConfig({ inputs: { a: 'foo' }, error: 'a' }))).toThrow(
|
|
259
|
+
/key: error/,
|
|
260
|
+
)
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
test('SANDBOX_GET_RETURN_VALUE broadcasts to both output target and outputs commands', () => {
|
|
264
|
+
const result = generateCalulationMap(
|
|
265
|
+
baseConfig({
|
|
266
|
+
output: 'outNode',
|
|
267
|
+
outputs: { foo: ['pb1'] },
|
|
268
|
+
}),
|
|
269
|
+
)
|
|
270
|
+
const { result: returnValue } = findSandboxIds(result.map)
|
|
271
|
+
const refs = result.map[returnValue].out.result
|
|
272
|
+
// First entry is the output data-node's `change` port; remainder are OBJECT_GET ids.
|
|
273
|
+
expect(refs[0]).toEqual({ id: 'outNode', port: 'change' })
|
|
274
|
+
expect(refs).toHaveLength(2)
|
|
275
|
+
expect(refs[1].port).toBe('obj')
|
|
276
|
+
expect(result.map[refs[1].id].properties.command).toBe('OBJECT_GET')
|
|
277
|
+
})
|
|
278
|
+
})
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fugood/bricks-ctor",
|
|
3
|
-
"version": "2.25.0-beta.
|
|
3
|
+
"version": "2.25.0-beta.12",
|
|
4
4
|
"main": "index.ts",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"typecheck": "tsc --noEmit",
|
|
7
7
|
"build": "bun scripts/build.js"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@fugood/bricks-cli": "^2.25.0-beta.
|
|
10
|
+
"@fugood/bricks-cli": "^2.25.0-beta.12",
|
|
11
11
|
"@huggingface/gguf": "^0.3.2",
|
|
12
12
|
"@iarna/toml": "^3.0.0",
|
|
13
13
|
"@modelcontextprotocol/sdk": "^1.15.0",
|
|
@@ -25,5 +25,5 @@
|
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"oxfmt": "^0.36.0"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "a732a16341bd23fb7ee8e83dbbe0f0c07bad0eb3"
|
|
29
29
|
}
|
package/tools/deploy.ts
CHANGED
|
@@ -141,6 +141,10 @@ await writeFile(configPath, JSON.stringify(releaseConfig))
|
|
|
141
141
|
|
|
142
142
|
const args = ['bricks', command, 'release', app.id, '-c', configPath, '--json']
|
|
143
143
|
|
|
144
|
+
if (app.name) {
|
|
145
|
+
args.push('--name', app.name)
|
|
146
|
+
}
|
|
147
|
+
|
|
144
148
|
if (version) {
|
|
145
149
|
args.push('--version', version)
|
|
146
150
|
}
|