@fugood/bricks-ctor 2.25.0-beta.60 → 2.25.0-beta.62

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 (192) hide show
  1. package/package.json +4 -28
  2. package/tools/__tests__/legacy-forwarder.test.js +91 -0
  3. package/tools/_forward.ts +26 -0
  4. package/tools/deploy.ts +3 -175
  5. package/tools/mcp-server.ts +3 -35
  6. package/tools/postinstall.ts +3 -291
  7. package/tools/pull.ts +3 -198
  8. package/tools/push-config.ts +3 -113
  9. package/tools/simulator.ts +3 -149
  10. package/compile/__tests__/config-diff.test.js +0 -100
  11. package/compile/__tests__/index.test.js +0 -461
  12. package/compile/__tests__/util.test.js +0 -450
  13. package/compile/action-name-map.ts +0 -1079
  14. package/compile/config-diff.ts +0 -155
  15. package/compile/index.ts +0 -1594
  16. package/compile/util.ts +0 -482
  17. package/index.ts +0 -6
  18. package/skills/bricks-ctor/SKILL.md +0 -38
  19. package/skills/bricks-ctor/references/animation.md +0 -160
  20. package/skills/bricks-ctor/references/architecture-patterns.md +0 -88
  21. package/skills/bricks-ctor/references/automations.md +0 -232
  22. package/skills/bricks-ctor/references/buttress.md +0 -245
  23. package/skills/bricks-ctor/references/data-calculation.md +0 -252
  24. package/skills/bricks-ctor/references/local-sync.md +0 -129
  25. package/skills/bricks-ctor/references/media-flow.md +0 -165
  26. package/skills/bricks-ctor/references/remote-data-bank.md +0 -196
  27. package/skills/bricks-ctor/references/simulator.md +0 -132
  28. package/skills/bricks-ctor/references/source-editing-tools.md +0 -81
  29. package/skills/bricks-ctor/references/standby-transition.md +0 -124
  30. package/skills/bricks-ctor/references/verification-toolchain.md +0 -200
  31. package/skills/bricks-design/SKILL.md +0 -171
  32. package/skills/bricks-design/references/architecture-truths.md +0 -132
  33. package/skills/bricks-design/references/avoiding-complexity.md +0 -91
  34. package/skills/bricks-design/references/design-critique.md +0 -195
  35. package/skills/bricks-design/references/design-languages.md +0 -265
  36. package/skills/bricks-design/references/performance.md +0 -116
  37. package/skills/bricks-design/references/presentation-and-slideshow.md +0 -137
  38. package/skills/bricks-design/references/translating-inputs.md +0 -152
  39. package/skills/bricks-design/references/variations-and-tweaks.md +0 -124
  40. package/skills/bricks-design/references/when-the-brief-is-branded.md +0 -284
  41. package/skills/bricks-design/references/when-the-brief-is-vague.md +0 -85
  42. package/skills/bricks-design/references/workflow.md +0 -134
  43. package/skills/bricks-ux/SKILL.md +0 -114
  44. package/skills/bricks-ux/references/accessibility.md +0 -162
  45. package/skills/bricks-ux/references/flow-states.md +0 -175
  46. package/skills/bricks-ux/references/interaction-archetypes.md +0 -189
  47. package/skills/bricks-ux/references/monitoring-screens.md +0 -153
  48. package/skills/bricks-ux/references/pressable-composition.md +0 -126
  49. package/skills/bricks-ux/references/user-journey.md +0 -168
  50. package/skills/bricks-ux/references/ux-critique.md +0 -256
  51. package/skills/rive-marketplace/SKILL.md +0 -99
  52. package/tools/__tests__/_cli-error.test.ts +0 -35
  53. package/tools/__tests__/_mcp-config.test.ts +0 -67
  54. package/tools/__tests__/pull.test.ts +0 -108
  55. package/tools/_cli-error.ts +0 -17
  56. package/tools/_edits-log.ts +0 -41
  57. package/tools/_git-author.ts +0 -37
  58. package/tools/_last-pushed-commit.ts +0 -28
  59. package/tools/_mcp-config.ts +0 -42
  60. package/tools/_shell.ts +0 -180
  61. package/tools/icons/.gitattributes +0 -1
  62. package/tools/icons/fa6pro-glyphmap.json +0 -4686
  63. package/tools/icons/fa6pro-meta.json +0 -1
  64. package/tools/mcp-env.ts +0 -13
  65. package/tools/mcp-tools/__tests__/data-calc-editing.test.js +0 -516
  66. package/tools/mcp-tools/__tests__/entry-editing.test.js +0 -866
  67. package/tools/mcp-tools/__tests__/huggingface.test.ts +0 -49
  68. package/tools/mcp-tools/__tests__/icons.test.ts +0 -21
  69. package/tools/mcp-tools/__tests__/mcp-env.test.js +0 -19
  70. package/tools/mcp-tools/_editing-helpers.ts +0 -98
  71. package/tools/mcp-tools/_verify.ts +0 -50
  72. package/tools/mcp-tools/compile.ts +0 -104
  73. package/tools/mcp-tools/data-calc-editing.ts +0 -1311
  74. package/tools/mcp-tools/entry-editing.ts +0 -2297
  75. package/tools/mcp-tools/huggingface.ts +0 -772
  76. package/tools/mcp-tools/icons.ts +0 -97
  77. package/tools/mcp-tools/lottie.ts +0 -102
  78. package/tools/mcp-tools/media.ts +0 -113
  79. package/tools/simulator-main.mjs +0 -488
  80. package/tools/simulator-preload.cjs +0 -16
  81. package/types/animation.d.ts +0 -116
  82. package/types/automation.d.ts +0 -231
  83. package/types/brick-base.d.ts +0 -80
  84. package/types/bricks/Camera.d.ts +0 -246
  85. package/types/bricks/Chart.d.ts +0 -372
  86. package/types/bricks/GenerativeMedia.d.ts +0 -290
  87. package/types/bricks/Icon.d.ts +0 -98
  88. package/types/bricks/Image.d.ts +0 -126
  89. package/types/bricks/Items.d.ts +0 -480
  90. package/types/bricks/Lottie.d.ts +0 -168
  91. package/types/bricks/Maps.d.ts +0 -262
  92. package/types/bricks/QrCode.d.ts +0 -117
  93. package/types/bricks/Rect.d.ts +0 -150
  94. package/types/bricks/RichText.d.ts +0 -131
  95. package/types/bricks/Rive.d.ts +0 -220
  96. package/types/bricks/Scene3D.d.ts +0 -676
  97. package/types/bricks/Sketch.d.ts +0 -256
  98. package/types/bricks/Slideshow.d.ts +0 -201
  99. package/types/bricks/Svg.d.ts +0 -99
  100. package/types/bricks/Text.d.ts +0 -148
  101. package/types/bricks/TextInput.d.ts +0 -242
  102. package/types/bricks/Video.d.ts +0 -242
  103. package/types/bricks/VideoStreaming.d.ts +0 -112
  104. package/types/bricks/WebRtcStream.d.ts +0 -65
  105. package/types/bricks/WebView.d.ts +0 -168
  106. package/types/bricks/index.d.ts +0 -23
  107. package/types/canvas.d.ts +0 -82
  108. package/types/common.d.ts +0 -141
  109. package/types/data-calc-command/base.d.ts +0 -57
  110. package/types/data-calc-command/collection.d.ts +0 -418
  111. package/types/data-calc-command/color.d.ts +0 -432
  112. package/types/data-calc-command/constant.d.ts +0 -50
  113. package/types/data-calc-command/datetime.d.ts +0 -147
  114. package/types/data-calc-command/file.d.ts +0 -129
  115. package/types/data-calc-command/index.d.ts +0 -13
  116. package/types/data-calc-command/iteratee.d.ts +0 -23
  117. package/types/data-calc-command/logictype.d.ts +0 -190
  118. package/types/data-calc-command/math.d.ts +0 -275
  119. package/types/data-calc-command/object.d.ts +0 -119
  120. package/types/data-calc-command/sandbox.d.ts +0 -66
  121. package/types/data-calc-command/string.d.ts +0 -407
  122. package/types/data-calc-script.d.ts +0 -21
  123. package/types/data-calc.d.ts +0 -12
  124. package/types/data.d.ts +0 -97
  125. package/types/generators/AlarmClock.d.ts +0 -110
  126. package/types/generators/Assistant.d.ts +0 -640
  127. package/types/generators/BleCentral.d.ts +0 -247
  128. package/types/generators/BlePeripheral.d.ts +0 -208
  129. package/types/generators/CanvasMap.d.ts +0 -74
  130. package/types/generators/CastlesPay.d.ts +0 -87
  131. package/types/generators/DataBank.d.ts +0 -160
  132. package/types/generators/File.d.ts +0 -432
  133. package/types/generators/GraphQl.d.ts +0 -132
  134. package/types/generators/Http.d.ts +0 -222
  135. package/types/generators/HttpServer.d.ts +0 -230
  136. package/types/generators/Information.d.ts +0 -103
  137. package/types/generators/Intent.d.ts +0 -168
  138. package/types/generators/Iterator.d.ts +0 -108
  139. package/types/generators/Keyboard.d.ts +0 -105
  140. package/types/generators/LlmAnthropicCompat.d.ts +0 -212
  141. package/types/generators/LlmAppleBuiltin.d.ts +0 -159
  142. package/types/generators/LlmGgml.d.ts +0 -903
  143. package/types/generators/LlmMediaTekNeuroPilot.d.ts +0 -235
  144. package/types/generators/LlmMlx.d.ts +0 -228
  145. package/types/generators/LlmOnnx.d.ts +0 -213
  146. package/types/generators/LlmOpenAiCompat.d.ts +0 -312
  147. package/types/generators/LlmQualcommAiEngine.d.ts +0 -247
  148. package/types/generators/Mcp.d.ts +0 -637
  149. package/types/generators/McpServer.d.ts +0 -289
  150. package/types/generators/MediaFlow.d.ts +0 -170
  151. package/types/generators/MqttBroker.d.ts +0 -141
  152. package/types/generators/MqttClient.d.ts +0 -141
  153. package/types/generators/Question.d.ts +0 -408
  154. package/types/generators/RealtimeTranscription.d.ts +0 -287
  155. package/types/generators/RerankerGgml.d.ts +0 -195
  156. package/types/generators/SerialPort.d.ts +0 -151
  157. package/types/generators/SoundPlayer.d.ts +0 -94
  158. package/types/generators/SoundRecorder.d.ts +0 -139
  159. package/types/generators/SpeechToTextGgml.d.ts +0 -424
  160. package/types/generators/SpeechToTextOnnx.d.ts +0 -236
  161. package/types/generators/SpeechToTextPlatform.d.ts +0 -85
  162. package/types/generators/SqLite.d.ts +0 -159
  163. package/types/generators/Step.d.ts +0 -107
  164. package/types/generators/SttAppleBuiltin.d.ts +0 -153
  165. package/types/generators/Tcp.d.ts +0 -126
  166. package/types/generators/TcpServer.d.ts +0 -147
  167. package/types/generators/TextToSpeechAppleBuiltin.d.ts +0 -127
  168. package/types/generators/TextToSpeechGgml.d.ts +0 -221
  169. package/types/generators/TextToSpeechOnnx.d.ts +0 -178
  170. package/types/generators/TextToSpeechOpenAiLike.d.ts +0 -121
  171. package/types/generators/ThermalPrinter.d.ts +0 -193
  172. package/types/generators/Tick.d.ts +0 -83
  173. package/types/generators/Udp.d.ts +0 -120
  174. package/types/generators/VadGgml.d.ts +0 -260
  175. package/types/generators/VadOnnx.d.ts +0 -231
  176. package/types/generators/VadTraditional.d.ts +0 -138
  177. package/types/generators/VectorStore.d.ts +0 -257
  178. package/types/generators/Watchdog.d.ts +0 -107
  179. package/types/generators/WebCrawler.d.ts +0 -103
  180. package/types/generators/WebRtc.d.ts +0 -181
  181. package/types/generators/WebSocket.d.ts +0 -148
  182. package/types/generators/index.d.ts +0 -57
  183. package/types/index.d.ts +0 -13
  184. package/types/subspace.d.ts +0 -60
  185. package/types/switch.d.ts +0 -51
  186. package/types/system.d.ts +0 -707
  187. package/utils/__tests__/calc.test.js +0 -25
  188. package/utils/__tests__/id.test.js +0 -154
  189. package/utils/calc.ts +0 -130
  190. package/utils/data.ts +0 -495
  191. package/utils/event-props.ts +0 -912
  192. package/utils/id.ts +0 -133
@@ -1,461 +0,0 @@
1
- jest.mock('../../tools/_shell', () => ({
2
- sh: jest.fn(),
3
- }))
4
-
5
- // Mirrors the chainable `sh` result (supports `.nothrow()` like the real helper).
6
- const shResult = (over = {}) => {
7
- const result = Promise.resolve({ exitCode: 0, stdout: '', stderr: '', ...over })
8
- result.nothrow = () => result
9
- return result
10
- }
11
-
12
- import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
13
- import os from 'node:os'
14
- import path from 'node:path'
15
-
16
- import { sh } from '../../tools/_shell'
17
- import { checkConfig, compile, compileTestCase } from '../index'
18
-
19
- const SUBSPACE_ID = 'SUBSPACE_00000000-0000-0000-0000-000000000001'
20
- const CANVAS_ID = 'CANVAS_00000000-0000-0000-0000-000000000001'
21
- const ANIMATION_ID = 'ANIMATION_00000000-0000-0000-0000-000000000001'
22
- const DATA_ID = 'PROPERTY_BANK_DATA_NODE_00000000-0000-0000-0000-000000000001'
23
-
24
- const makeApp = (animations = [], data = []) => {
25
- const rootCanvas = {
26
- __typename: 'Canvas',
27
- id: CANVAS_ID,
28
- items: [],
29
- }
30
- const rootSubspace = {
31
- __typename: 'Subspace',
32
- id: SUBSPACE_ID,
33
- title: 'Main Subspace',
34
- layout: {
35
- width: 96,
36
- height: 54,
37
- },
38
- rootCanvas,
39
- canvases: [rootCanvas],
40
- animations,
41
- bricks: [],
42
- generators: [],
43
- data,
44
- dataRouting: [],
45
- dataCalculation: [],
46
- }
47
-
48
- return {
49
- name: 'Compile animation test',
50
- rootSubspace,
51
- subspaces: [rootSubspace],
52
- }
53
- }
54
-
55
- const makeData = (remoteUpdate) => ({
56
- __typename: 'Data',
57
- id: DATA_ID,
58
- type: 'string',
59
- remoteUpdate,
60
- })
61
-
62
- const commandOf = ([strings, ...values]) =>
63
- strings.reduce((acc, chunk, index) => `${acc}${chunk}${values[index] ?? ''}`, '')
64
-
65
- describe('checkConfig', () => {
66
- beforeEach(() => {
67
- sh.mockReset()
68
- sh.mockImplementation(() => shResult())
69
- })
70
-
71
- test('runs doctor after check-config', async () => {
72
- await checkConfig('.bricks/build/application-config.json')
73
-
74
- expect(sh.mock.calls.map(commandOf)).toEqual([
75
- 'bricks app check-config --validate-automation .bricks/build/application-config.json',
76
- 'bricks app doctor --validate-automation .bricks/build/application-config.json',
77
- ])
78
- })
79
-
80
- test('skips doctor when the CLI lacks the command', async () => {
81
- sh.mockReturnValueOnce(shResult()) // check-config
82
- sh.mockReturnValueOnce(shResult({ exitCode: 1, stderr: "error: unknown command 'doctor'" }))
83
-
84
- await expect(checkConfig('config.json')).resolves.toBeUndefined()
85
- })
86
-
87
- test('throws when doctor reports config errors', async () => {
88
- sh.mockReturnValueOnce(shResult()) // check-config
89
- sh.mockReturnValueOnce(shResult({ exitCode: 1, stderr: 'DATA_RACE: conflicting writes' }))
90
-
91
- await expect(checkConfig('config.json')).rejects.toThrow()
92
- })
93
- })
94
-
95
- describe('compile animations', () => {
96
- test('normalizes mixed legacy spring config', async () => {
97
- const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {})
98
- try {
99
- const config = await compile(
100
- makeApp([
101
- {
102
- __typename: 'Animation',
103
- id: ANIMATION_ID,
104
- alias: 'btnPressOut',
105
- title: 'Button Press Out',
106
- property: 'transform.scale',
107
- config: {
108
- __type: 'AnimationSpringConfig',
109
- toValue: 1,
110
- friction: 5,
111
- tension: 200,
112
- speed: 14,
113
- bounciness: 8,
114
- },
115
- },
116
- ]),
117
- )
118
-
119
- expect(config.subspace_map[SUBSPACE_ID].animation_map[ANIMATION_ID].config).toEqual({
120
- toValue: 1,
121
- friction: 5,
122
- tension: 200,
123
- })
124
- const warning = warnSpy.mock.calls[0][0]
125
- expect(warning).toContain('Resolved animation spring config')
126
- expect(warning).toContain('Button Press Out')
127
- expect(warning).toContain('btnPressOut')
128
- expect(warning).toContain('transform.scale')
129
- expect(warning).toContain('Main Subspace')
130
- expect(warning).not.toContain('ANIMATION_')
131
- expect(warning).not.toContain('SUBSPACE_')
132
- } finally {
133
- warnSpy.mockRestore()
134
- }
135
- })
136
-
137
- test('rejects invalid animation property', async () => {
138
- await expect(
139
- compile(
140
- makeApp([
141
- {
142
- __typename: 'Animation',
143
- id: ANIMATION_ID,
144
- property: 'transform.skewX',
145
- config: {
146
- __type: 'AnimationTimingConfig',
147
- toValue: 1,
148
- },
149
- },
150
- ]),
151
- ),
152
- ).rejects.toThrow(/Invalid animation property/)
153
- })
154
-
155
- test('rejects invalid animation config type', async () => {
156
- await expect(
157
- compile(
158
- makeApp([
159
- {
160
- __typename: 'Animation',
161
- id: ANIMATION_ID,
162
- property: 'opacity',
163
- config: {
164
- __type: 'AnimationUnknownConfig',
165
- toValue: 1,
166
- },
167
- },
168
- ]),
169
- ),
170
- ).rejects.toThrow(/Invalid animation config type/)
171
- })
172
- })
173
-
174
- describe('compile error collection', () => {
175
- test('reports every entity error in a single failure instead of bailing on the first', async () => {
176
- const app = makeApp()
177
- // Invalid ids across three independent entity loops — a fail-fast compile would only
178
- // surface the first; collection must report all three in one run.
179
- app.rootSubspace.bricks = [{ id: 'bad-brick', templateKey: 'BRICK_TEXT' }]
180
- app.rootSubspace.generators = [{ id: 'bad-generator', templateKey: 'GENERATOR_HTTP' }]
181
- app.rootSubspace.data = [{ __typename: 'Data', id: 'bad-data', type: 'string' }]
182
-
183
- let error
184
- try {
185
- await compile(app)
186
- } catch (caught) {
187
- error = caught
188
- }
189
-
190
- expect(error).toBeInstanceOf(Error)
191
- expect(error.message).toContain('Compile failed with 3 error(s)')
192
- expect(error.message).toContain('Invalid BRICK id (brick index: 0')
193
- expect(error.message).toContain('Invalid GENERATOR id (generator index: 0')
194
- expect(error.message).toContain('Invalid PROPERTY_BANK_DATA_NODE id (data index: 0')
195
- })
196
-
197
- test('skipping a bad entity does not block compiling its siblings', async () => {
198
- const app = makeApp()
199
- app.rootSubspace.data = [
200
- { __typename: 'Data', id: 'bad-data', type: 'string' },
201
- makeData(undefined), // valid DATA_ID sibling
202
- ]
203
-
204
- let error
205
- try {
206
- await compile(app)
207
- } catch (caught) {
208
- error = caught
209
- }
210
-
211
- // Only the bad sibling is reported; the valid one compiled past it in the same pass.
212
- expect(error.message).toContain('Compile failed with 1 error(s)')
213
- expect(error.message).toContain('bad-data')
214
- expect(error.message).not.toContain(DATA_ID)
215
- })
216
- })
217
-
218
- describe('compile event handlers', () => {
219
- const BRICK_ID = 'BRICK_00000000-0000-0000-0000-000000000002'
220
-
221
- test('preserves item-brick string handler casing and normalizes only system', async () => {
222
- // A mixed-case ItemBrickID handler — must survive compile verbatim because the
223
- // runtime resolves handlers case-sensitively (mapEventMapHandlersWithNewId).
224
- const itemHandlerId = 'itemBrickHandlerId'
225
- const app = makeApp()
226
- app.rootSubspace.bricks = [
227
- {
228
- __typename: 'Brick',
229
- id: BRICK_ID,
230
- templateKey: 'BRICK_VIEW',
231
- property: {},
232
- events: {
233
- onPress: [
234
- { handler: itemHandlerId, action: { __actionName: 'SCROLL_TO_INDEX' } },
235
- { handler: 'system', action: { __actionName: 'NAVIGATE' } },
236
- ],
237
- },
238
- },
239
- ]
240
-
241
- const config = await compile(app)
242
- const eventMap = config.subspace_map[SUBSPACE_ID].brick_map[BRICK_ID].event_map
243
- const events = eventMap.BRICK_VIEW_ON_PRESS
244
-
245
- // ItemBrickID handler kept verbatim (was wrongly uppercased to ITEMBRICKHANDLERID).
246
- expect(events[0].handler).toBe(itemHandlerId)
247
- // The literal 'system' handler still normalizes to SYSTEM.
248
- expect(events[1].handler).toBe('SYSTEM')
249
- })
250
- })
251
-
252
- describe('compile expanded state', () => {
253
- test('defaults canvas, bricks, and data collapsed for generated configs', async () => {
254
- const config = await compile(makeApp([], [makeData(undefined)]))
255
-
256
- expect(config.subspace_map[SUBSPACE_ID]._expanded).toEqual({
257
- brick: false,
258
- generator: true,
259
- canvas: { [CANVAS_ID]: false },
260
- property_bank: false,
261
- property_bank_calc: true,
262
- })
263
- })
264
-
265
- test('preserves explicit source unexpanded state when present', async () => {
266
- const app = makeApp()
267
- app.rootSubspace.unexpanded = {
268
- generator: true,
269
- dataCalculation: true,
270
- }
271
-
272
- const config = await compile(app)
273
- const expanded = config.subspace_map[SUBSPACE_ID]._expanded
274
-
275
- expect(expanded.brick).toBe(true)
276
- expect(expanded.generator).toBe(false)
277
- expect(expanded.canvas).toBeUndefined()
278
- expect(expanded.property_bank).toBe(true)
279
- expect(expanded.property_bank_calc).toBe(false)
280
- })
281
- })
282
-
283
- describe('compile data remote update', () => {
284
- test.each([
285
- [undefined, { bank_type: 'none' }],
286
- [{ type: 'auto' }, { bank_type: 'create', enable_remote_update: true }],
287
- [
288
- { type: 'device-specific' },
289
- {
290
- bank_type: 'create-device-specific',
291
- enable_remote_update: true,
292
- use_remote_id_prefix: true,
293
- },
294
- ],
295
- [
296
- { type: 'global-data', id: 'GLOBAL_PROP_1' },
297
- {
298
- bank_type: 'global',
299
- enable_remote_update: true,
300
- global_remote_update_prop: 'GLOBAL_PROP_1',
301
- },
302
- ],
303
- ])('emits bank_type for %p', async (remoteUpdate, expectedRemoteUpdate) => {
304
- const config = await compile(makeApp([], [makeData(remoteUpdate)]))
305
-
306
- expect(config.subspace_map[SUBSPACE_ID].property_bank_map[DATA_ID]).toMatchObject(
307
- expectedRemoteUpdate,
308
- )
309
- })
310
- })
311
-
312
- describe('compile asset preload normalization', () => {
313
- const makeAssetData = (id, kindType) => ({
314
- __typename: 'Data',
315
- id,
316
- type: 'string',
317
- kind: {
318
- type: kindType,
319
- preload: { type: 'url', hashType: 'sha256', hash: 'abc123' },
320
- },
321
- })
322
-
323
- test('rive-file-uri normalizes preload like lottie-file-uri (hash re-keyed by hashType)', async () => {
324
- const RIVE_ID = 'PROPERTY_BANK_DATA_NODE_00000000-0000-0000-0000-0000000000a1'
325
- const LOTTIE_ID = 'PROPERTY_BANK_DATA_NODE_00000000-0000-0000-0000-0000000000a2'
326
- const config = await compile(
327
- makeApp(
328
- [],
329
- [makeAssetData(RIVE_ID, 'rive-file-uri'), makeAssetData(LOTTIE_ID, 'lottie-file-uri')],
330
- ),
331
- )
332
-
333
- const rive = config.subspace_map[SUBSPACE_ID].property_bank_map[RIVE_ID]
334
- const lottie = config.subspace_map[SUBSPACE_ID].property_bank_map[LOTTIE_ID]
335
-
336
- // Rive must get the same normalized preload as every sibling asset kind: the hash
337
- // re-keyed under its hashType (the runtime reads preload[hashType]), not left raw under
338
- // `hash`. Regression: rive was missing from preloadTypes, so it fell to the raw else
339
- // branch and the runtime preload[hashType] lookup missed.
340
- expect(rive.preload).toEqual({ type: 'url', hashType: 'sha256', sha256: 'abc123' })
341
- expect(rive.preload).toEqual(lottie.preload)
342
- })
343
- })
344
-
345
- describe('compile config-change audit log', () => {
346
- const readAudit = async (projectDir) =>
347
- (await readFile(path.join(projectDir, '.bricks/edits.jsonl'), 'utf8'))
348
- .trim()
349
- .split('\n')
350
- .map((line) => JSON.parse(line))
351
-
352
- const seedArtifact = async (projectDir, config) => {
353
- const artifactPath = path.join(projectDir, '.bricks/build/application-config.json')
354
- await mkdir(path.dirname(artifactPath), { recursive: true })
355
- await writeFile(artifactPath, JSON.stringify(config))
356
- }
357
-
358
- test('records the config delta only in the editing-tools context', async () => {
359
- const prevCwd = process.cwd()
360
- const prevEnv = process.env.BRICKS_CTOR_ENABLE_EDITING_TOOLS
361
- let projectDir
362
- try {
363
- projectDir = await mkdtemp(path.join(os.tmpdir(), 'bricks-compile-audit-'))
364
- process.chdir(projectDir)
365
-
366
- // (1) Editing tools disabled: even a real delta against a baseline is not recorded.
367
- delete process.env.BRICKS_CTOR_ENABLE_EDITING_TOOLS
368
- const empty = await compile(makeApp([], []))
369
- await seedArtifact(projectDir, empty)
370
- await compile(makeApp([], [makeData(undefined)]))
371
- await expect(readFile(path.join(projectDir, '.bricks/edits.jsonl'))).rejects.toThrow()
372
-
373
- // (2) Editing tools enabled: the compiled-config delta is recorded.
374
- process.env.BRICKS_CTOR_ENABLE_EDITING_TOOLS = '1'
375
- await seedArtifact(projectDir, empty)
376
- const withData = await compile(makeApp([], [makeData(undefined)]))
377
- const audit = await readAudit(projectDir)
378
- expect(audit).toHaveLength(1)
379
- expect(audit[0].tool).toBe('compile')
380
- expect(audit[0].outcome).toBe('ok')
381
- expect(audit[0].summary).toMatch(/compile: \d+ config op\(s\)/)
382
- expect(JSON.stringify(audit[0].configChange)).toContain('property_bank_map')
383
- // The audit log gets gitignored on first write.
384
- const gitignore = await readFile(path.join(projectDir, '.gitignore'), 'utf8')
385
- expect(gitignore).toContain('.bricks/edits.jsonl')
386
-
387
- // (3) Recompiling with no source change records a "no config change" entry.
388
- await seedArtifact(projectDir, withData)
389
- await compile(makeApp([], [makeData(undefined)]))
390
- const afterNoop = await readAudit(projectDir)
391
- expect(afterNoop).toHaveLength(2)
392
- expect(afterNoop[1].summary).toBe('compile: no config change')
393
-
394
- // (4) Turning the flag off again (as the editing tools do for their verify compiles)
395
- // suppresses the record even though there is a real delta.
396
- process.env.BRICKS_CTOR_ENABLE_EDITING_TOOLS = '0'
397
- await seedArtifact(projectDir, withData)
398
- await compile(makeApp([], []))
399
- expect(await readAudit(projectDir)).toHaveLength(2)
400
- } finally {
401
- if (prevEnv === undefined) delete process.env.BRICKS_CTOR_ENABLE_EDITING_TOOLS
402
- else process.env.BRICKS_CTOR_ENABLE_EDITING_TOOLS = prevEnv
403
- process.chdir(prevCwd)
404
- if (projectDir) await rm(projectDir, { recursive: true, force: true })
405
- }
406
- })
407
- })
408
-
409
- describe('compile linked-module subspace', () => {
410
- const LINKED_SUBSPACE_ID = 'SUBSPACE_00000000-0000-0000-0000-000000000002'
411
- const makeLinkedApp = () => {
412
- const app = makeApp()
413
- app.subspaces = [
414
- app.rootSubspace,
415
- {
416
- __typename: 'Subspace',
417
- id: LINKED_SUBSPACE_ID,
418
- title: 'Linked Module',
419
- layout: { width: 96, height: 54 },
420
- module: { link: true, id: 'MODULE_00000000-0000-0000-0000-000000000001', version: 1 },
421
- },
422
- ]
423
- return app
424
- }
425
-
426
- test('uses a deterministic placeholder canvas id stable across recompiles', async () => {
427
- // Regression: the placeholder canvas id came from makeId('canvas'), whose count-fallback
428
- // branch uses a never-reset process-global counter, so recompiling identical source produced
429
- // a different id and broke compile's byte-stable-output contract (phantom config-change ops).
430
- const first = await compile(makeLinkedApp())
431
- const second = await compile(makeLinkedApp())
432
-
433
- const firstKeys = Object.keys(first.subspace_map[LINKED_SUBSPACE_ID].canvas_map)
434
- const secondKeys = Object.keys(second.subspace_map[LINKED_SUBSPACE_ID].canvas_map)
435
- expect(firstKeys).toHaveLength(1)
436
- expect(secondKeys).toEqual(firstKeys)
437
- expect(first.subspace_map[LINKED_SUBSPACE_ID].root_canvas_id).toBe(firstKeys[0])
438
- expect(second.subspace_map[LINKED_SUBSPACE_ID].root_canvas_id).toBe(firstKeys[0])
439
- })
440
-
441
- test('compileTestCase resolves a jump_to getter to its id (survives serialization)', () => {
442
- // Regression: jump_cond[].jump_to may be a getter (() => TestCase) for dynamic case ids — the
443
- // project generator emits `jump_to: () => caseVar`. compileTestCase passed it through verbatim
444
- // (unlike the `run` array, which resolves getters via compileRunElement), so JSON.stringify of
445
- // the compiled config dropped the function and the conditional jump silently vanished.
446
- const compiled = compileTestCase({
447
- __typename: 'TestCase',
448
- id: 'TEST_CASE_src',
449
- name: 'src',
450
- run: [],
451
- jump_cond: [
452
- { type: 'status', status: 'finished', jump_to: () => ({ id: 'TEST_CASE_target' }) },
453
- { type: 'status', status: 'failed', jump_to: 'TEST_CASE_literal' },
454
- ],
455
- })
456
- // The compiled config is serialized to disk, so the value must survive JSON round-tripping.
457
- const serialized = JSON.parse(JSON.stringify(compiled))
458
- expect(serialized.jump_cond[0].jump_to).toBe('TEST_CASE_target') // getter resolved to its id
459
- expect(serialized.jump_cond[1].jump_to).toBe('TEST_CASE_literal') // string passes through
460
- })
461
- })