@fugood/bricks-ctor 2.25.0-beta.5 → 2.25.0-beta.51
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__/config-diff.test.js +100 -0
- package/compile/__tests__/index.test.js +386 -0
- package/compile/__tests__/util.test.js +337 -0
- package/compile/action-name-map.ts +64 -0
- package/compile/config-diff.ts +155 -0
- package/compile/index.ts +278 -34
- package/compile/util.ts +34 -10
- package/package.json +7 -3
- package/skills/bricks-ctor/SKILL.md +23 -17
- package/skills/bricks-ctor/{rules → references}/animation.md +3 -2
- package/skills/bricks-ctor/{rules → references}/architecture-patterns.md +18 -0
- package/skills/bricks-ctor/{rules → references}/automations.md +11 -0
- package/skills/bricks-ctor/references/buttress.md +245 -0
- package/skills/bricks-ctor/references/data-calculation.md +239 -0
- package/skills/bricks-ctor/references/simulator.md +132 -0
- package/skills/bricks-ctor/references/source-editing-tools.md +81 -0
- package/skills/bricks-ctor/references/verification-toolchain.md +200 -0
- package/skills/bricks-design/SKILL.md +150 -45
- package/skills/bricks-design/references/architecture-truths.md +132 -0
- package/skills/bricks-design/references/avoiding-complexity.md +91 -0
- package/skills/bricks-design/references/design-critique.md +195 -0
- package/skills/bricks-design/references/design-languages.md +265 -0
- package/skills/bricks-design/references/performance.md +116 -0
- package/skills/bricks-design/references/presentation-and-slideshow.md +137 -0
- package/skills/bricks-design/references/translating-inputs.md +152 -0
- package/skills/bricks-design/references/variations-and-tweaks.md +124 -0
- package/skills/bricks-design/references/when-the-brief-is-branded.md +284 -0
- package/skills/bricks-design/references/when-the-brief-is-vague.md +85 -0
- package/skills/bricks-design/references/workflow.md +134 -0
- package/skills/bricks-ux/SKILL.md +114 -0
- package/skills/bricks-ux/references/accessibility.md +162 -0
- package/skills/bricks-ux/references/flow-states.md +175 -0
- package/skills/bricks-ux/references/interaction-archetypes.md +189 -0
- package/skills/bricks-ux/references/monitoring-screens.md +153 -0
- package/skills/bricks-ux/references/pressable-composition.md +126 -0
- package/skills/bricks-ux/references/user-journey.md +168 -0
- package/skills/bricks-ux/references/ux-critique.md +256 -0
- package/tools/__tests__/_cli-error.test.ts +35 -0
- package/tools/__tests__/_mcp-config.test.ts +67 -0
- package/tools/_cli-error.ts +17 -0
- package/tools/_edits-log.ts +41 -0
- package/tools/_git-author.ts +10 -2
- package/tools/_last-pushed-commit.ts +28 -0
- package/tools/_mcp-config.ts +42 -0
- package/tools/_shell.ts +8 -1
- package/tools/deploy.ts +17 -6
- package/tools/mcp-env.ts +13 -0
- package/tools/mcp-server.ts +8 -0
- package/tools/mcp-tools/__tests__/data-calc-editing.test.js +516 -0
- package/tools/mcp-tools/__tests__/entry-editing.test.js +866 -0
- package/tools/mcp-tools/__tests__/huggingface.test.ts +49 -0
- package/tools/mcp-tools/__tests__/icons.test.ts +21 -0
- package/tools/mcp-tools/__tests__/mcp-env.test.js +19 -0
- package/tools/mcp-tools/_editing-helpers.ts +58 -0
- package/tools/mcp-tools/_verify.ts +50 -0
- package/tools/mcp-tools/compile.ts +21 -9
- package/tools/mcp-tools/data-calc-editing.ts +1349 -0
- package/tools/mcp-tools/entry-editing.ts +2336 -0
- package/tools/mcp-tools/huggingface.ts +23 -13
- package/tools/mcp-tools/icons.ts +23 -7
- package/tools/mcp-tools/media.ts +4 -1
- package/tools/postinstall.ts +95 -38
- package/tools/pull.ts +93 -22
- package/tools/push-config.ts +114 -0
- package/tools/{preview-main.mjs → simulator-main.mjs} +207 -12
- package/tools/simulator-preload.cjs +16 -0
- package/tools/{preview.ts → simulator.ts} +4 -4
- package/types/{animation.ts → animation.d.ts} +24 -8
- package/types/{automation.ts → automation.d.ts} +16 -20
- package/types/{brick-base.ts → brick-base.d.ts} +1 -1
- package/types/bricks/{Camera.ts → Camera.d.ts} +8 -8
- package/types/bricks/{Chart.ts → Chart.d.ts} +4 -4
- package/types/bricks/{GenerativeMedia.ts → GenerativeMedia.d.ts} +15 -15
- package/types/bricks/{Icon.ts → Icon.d.ts} +7 -7
- package/types/bricks/{Image.ts → Image.d.ts} +21 -9
- package/types/bricks/{Items.ts → Items.d.ts} +7 -7
- package/types/bricks/{Lottie.ts → Lottie.d.ts} +10 -10
- package/types/bricks/{Maps.ts → Maps.d.ts} +11 -11
- package/types/bricks/{QrCode.ts → QrCode.d.ts} +7 -7
- package/types/bricks/{Rect.ts → Rect.d.ts} +7 -7
- package/types/bricks/{RichText.ts → RichText.d.ts} +12 -9
- package/types/bricks/{Rive.ts → Rive.d.ts} +9 -9
- package/types/bricks/Scene3D.d.ts +676 -0
- package/types/bricks/{Sketch.ts → Sketch.d.ts} +6 -6
- package/types/bricks/{Slideshow.ts → Slideshow.d.ts} +7 -7
- package/types/bricks/{Svg.ts → Svg.d.ts} +7 -7
- package/types/bricks/{Text.ts → Text.d.ts} +9 -9
- package/types/bricks/{TextInput.ts → TextInput.d.ts} +10 -10
- package/types/bricks/{Video.ts → Video.d.ts} +12 -12
- package/types/bricks/{VideoStreaming.ts → VideoStreaming.d.ts} +10 -10
- package/types/bricks/{WebRtcStream.ts → WebRtcStream.d.ts} +1 -1
- package/types/bricks/{WebView.ts → WebView.d.ts} +4 -4
- package/types/bricks/{index.ts → index.d.ts} +1 -0
- package/types/{common.ts → common.d.ts} +3 -6
- package/types/data-calc-command/base.d.ts +57 -0
- package/types/data-calc-command/collection.d.ts +418 -0
- package/types/data-calc-command/color.d.ts +432 -0
- package/types/data-calc-command/constant.d.ts +50 -0
- package/types/data-calc-command/datetime.d.ts +147 -0
- package/types/data-calc-command/file.d.ts +129 -0
- package/types/data-calc-command/index.d.ts +13 -0
- package/types/data-calc-command/iteratee.d.ts +23 -0
- package/types/data-calc-command/logictype.d.ts +190 -0
- package/types/data-calc-command/math.d.ts +275 -0
- package/types/data-calc-command/object.d.ts +119 -0
- package/types/data-calc-command/sandbox.d.ts +66 -0
- package/types/data-calc-command/string.d.ts +407 -0
- package/types/{data-calc.ts → data-calc.d.ts} +1 -0
- package/types/{data.ts → data.d.ts} +4 -2
- package/types/generators/{Assistant.ts → Assistant.d.ts} +19 -0
- package/types/generators/{LlmGgml.ts → LlmGgml.d.ts} +43 -1
- package/types/generators/{LlmMlx.ts → LlmMlx.d.ts} +1 -0
- package/types/generators/{RerankerGgml.ts → RerankerGgml.d.ts} +5 -1
- package/types/generators/{SoundRecorder.ts → SoundRecorder.d.ts} +10 -1
- package/types/generators/{SpeechToTextGgml.ts → SpeechToTextGgml.d.ts} +6 -1
- package/types/generators/{SttAppleBuiltin.ts → SttAppleBuiltin.d.ts} +27 -4
- package/types/generators/{ThermalPrinter.ts → ThermalPrinter.d.ts} +9 -7
- package/types/generators/{VadGgml.ts → VadGgml.d.ts} +12 -2
- package/types/{subspace.ts → subspace.d.ts} +1 -1
- package/utils/__tests__/calc.test.js +25 -0
- package/utils/__tests__/id.test.js +154 -0
- package/utils/calc.ts +5 -1
- package/utils/data.ts +5 -7
- package/utils/event-props.ts +17 -0
- package/utils/id.ts +109 -56
- package/skills/bricks-ctor/rules/buttress.md +0 -156
- package/skills/bricks-ctor/rules/data-calculation.md +0 -209
- package/skills/bricks-design/LICENSE.txt +0 -180
- package/types/data-calc-command.ts +0 -7005
- /package/skills/bricks-ctor/{rules → references}/local-sync.md +0 -0
- /package/skills/bricks-ctor/{rules → references}/media-flow.md +0 -0
- /package/skills/bricks-ctor/{rules → references}/remote-data-bank.md +0 -0
- /package/skills/bricks-ctor/{rules → references}/standby-transition.md +0 -0
- /package/types/{canvas.ts → canvas.d.ts} +0 -0
- /package/types/{data-calc-script.ts → data-calc-script.d.ts} +0 -0
- /package/types/generators/{AlarmClock.ts → AlarmClock.d.ts} +0 -0
- /package/types/generators/{BleCentral.ts → BleCentral.d.ts} +0 -0
- /package/types/generators/{BlePeripheral.ts → BlePeripheral.d.ts} +0 -0
- /package/types/generators/{CanvasMap.ts → CanvasMap.d.ts} +0 -0
- /package/types/generators/{CastlesPay.ts → CastlesPay.d.ts} +0 -0
- /package/types/generators/{DataBank.ts → DataBank.d.ts} +0 -0
- /package/types/generators/{File.ts → File.d.ts} +0 -0
- /package/types/generators/{GraphQl.ts → GraphQl.d.ts} +0 -0
- /package/types/generators/{Http.ts → Http.d.ts} +0 -0
- /package/types/generators/{HttpServer.ts → HttpServer.d.ts} +0 -0
- /package/types/generators/{Information.ts → Information.d.ts} +0 -0
- /package/types/generators/{Intent.ts → Intent.d.ts} +0 -0
- /package/types/generators/{Iterator.ts → Iterator.d.ts} +0 -0
- /package/types/generators/{Keyboard.ts → Keyboard.d.ts} +0 -0
- /package/types/generators/{LlmAnthropicCompat.ts → LlmAnthropicCompat.d.ts} +0 -0
- /package/types/generators/{LlmAppleBuiltin.ts → LlmAppleBuiltin.d.ts} +0 -0
- /package/types/generators/{LlmMediaTekNeuroPilot.ts → LlmMediaTekNeuroPilot.d.ts} +0 -0
- /package/types/generators/{LlmOnnx.ts → LlmOnnx.d.ts} +0 -0
- /package/types/generators/{LlmOpenAiCompat.ts → LlmOpenAiCompat.d.ts} +0 -0
- /package/types/generators/{LlmQualcommAiEngine.ts → LlmQualcommAiEngine.d.ts} +0 -0
- /package/types/generators/{Mcp.ts → Mcp.d.ts} +0 -0
- /package/types/generators/{McpServer.ts → McpServer.d.ts} +0 -0
- /package/types/generators/{MediaFlow.ts → MediaFlow.d.ts} +0 -0
- /package/types/generators/{MqttBroker.ts → MqttBroker.d.ts} +0 -0
- /package/types/generators/{MqttClient.ts → MqttClient.d.ts} +0 -0
- /package/types/generators/{Question.ts → Question.d.ts} +0 -0
- /package/types/generators/{RealtimeTranscription.ts → RealtimeTranscription.d.ts} +0 -0
- /package/types/generators/{SerialPort.ts → SerialPort.d.ts} +0 -0
- /package/types/generators/{SoundPlayer.ts → SoundPlayer.d.ts} +0 -0
- /package/types/generators/{SpeechToTextOnnx.ts → SpeechToTextOnnx.d.ts} +0 -0
- /package/types/generators/{SpeechToTextPlatform.ts → SpeechToTextPlatform.d.ts} +0 -0
- /package/types/generators/{SqLite.ts → SqLite.d.ts} +0 -0
- /package/types/generators/{Step.ts → Step.d.ts} +0 -0
- /package/types/generators/{Tcp.ts → Tcp.d.ts} +0 -0
- /package/types/generators/{TcpServer.ts → TcpServer.d.ts} +0 -0
- /package/types/generators/{TextToSpeechAppleBuiltin.ts → TextToSpeechAppleBuiltin.d.ts} +0 -0
- /package/types/generators/{TextToSpeechGgml.ts → TextToSpeechGgml.d.ts} +0 -0
- /package/types/generators/{TextToSpeechOnnx.ts → TextToSpeechOnnx.d.ts} +0 -0
- /package/types/generators/{TextToSpeechOpenAiLike.ts → TextToSpeechOpenAiLike.d.ts} +0 -0
- /package/types/generators/{Tick.ts → Tick.d.ts} +0 -0
- /package/types/generators/{Udp.ts → Udp.d.ts} +0 -0
- /package/types/generators/{VadOnnx.ts → VadOnnx.d.ts} +0 -0
- /package/types/generators/{VadTraditional.ts → VadTraditional.d.ts} +0 -0
- /package/types/generators/{VectorStore.ts → VectorStore.d.ts} +0 -0
- /package/types/generators/{Watchdog.ts → Watchdog.d.ts} +0 -0
- /package/types/generators/{WebCrawler.ts → WebCrawler.d.ts} +0 -0
- /package/types/generators/{WebRtc.ts → WebRtc.d.ts} +0 -0
- /package/types/generators/{WebSocket.ts → WebSocket.d.ts} +0 -0
- /package/types/generators/{index.ts → index.d.ts} +0 -0
- /package/types/{index.ts → index.d.ts} +0 -0
- /package/types/{switch.ts → switch.d.ts} +0 -0
- /package/types/{system.ts → system.d.ts} +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { computeConfigChange } from '../config-diff'
|
|
2
|
+
|
|
3
|
+
describe('computeConfigChange', () => {
|
|
4
|
+
test('ignores the volatile top-level title and update_timestamp', () => {
|
|
5
|
+
const before = { title: 'App(1)', update_timestamp: 1, subspace_map: {} }
|
|
6
|
+
const after = { title: 'App(2)', update_timestamp: 2, subspace_map: {} }
|
|
7
|
+
expect(computeConfigChange(before, after)).toEqual({ status: 'ok', ops: [], opCount: 0 })
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
test('still diffs nested (subspace/brick) titles', () => {
|
|
11
|
+
const before = { title: 'App(1)', subspace_map: { S: { title: 'Home' } } }
|
|
12
|
+
const after = { title: 'App(2)', subspace_map: { S: { title: 'Start' } } }
|
|
13
|
+
expect(computeConfigChange(before, after).ops).toEqual([
|
|
14
|
+
{ op: 'set', path: ['subspace_map', 'S', 'title'], value: 'Start' },
|
|
15
|
+
])
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('emits a leaf set for a scalar property change', () => {
|
|
19
|
+
const wrap = (url) => ({ subspace_map: { S: { brick_map: { B: { property: { url } } } } } })
|
|
20
|
+
expect(computeConfigChange(wrap('a'), wrap('b')).ops).toEqual([
|
|
21
|
+
{ op: 'set', path: ['subspace_map', 'S', 'brick_map', 'B', 'property', 'url'], value: 'b' },
|
|
22
|
+
])
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test('added key → set, removed key → unset', () => {
|
|
26
|
+
const change = computeConfigChange({ m: { a: 1 } }, { m: { b: 2 } })
|
|
27
|
+
expect(change.opCount).toBe(2)
|
|
28
|
+
expect(change.ops).toContainEqual({ op: 'unset', path: ['m', 'a'] })
|
|
29
|
+
expect(change.ops).toContainEqual({ op: 'set', path: ['m', 'b'], value: 2 })
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('equal-length arrays diff element-wise', () => {
|
|
33
|
+
const before = { items: [{ x: 1 }, { x: 2 }] }
|
|
34
|
+
const after = { items: [{ x: 1 }, { x: 9 }] }
|
|
35
|
+
expect(computeConfigChange(before, after).ops).toEqual([
|
|
36
|
+
{ op: 'set', path: ['items', 1, 'x'], value: 9 },
|
|
37
|
+
])
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('length-changed arrays emit a single whole-array set', () => {
|
|
41
|
+
const before = { items: [1, 2] }
|
|
42
|
+
const after = { items: [1, 2, 3] }
|
|
43
|
+
expect(computeConfigChange(before, after).ops).toEqual([
|
|
44
|
+
{ op: 'set', path: ['items'], value: [1, 2, 3] },
|
|
45
|
+
])
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('identical configs produce no ops', () => {
|
|
49
|
+
const config = { subspace_map: { S: { brick_map: { B: { property: { a: 1, b: [1, 2] } } } } } }
|
|
50
|
+
expect(computeConfigChange(config, structuredClone(config))).toEqual({
|
|
51
|
+
status: 'ok',
|
|
52
|
+
ops: [],
|
|
53
|
+
opCount: 0,
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test('ignores object fields omitted by JSON.stringify', () => {
|
|
58
|
+
const before = { subspace_map: { S: { title: 'Home' } } }
|
|
59
|
+
const after = {
|
|
60
|
+
subspace_map: {
|
|
61
|
+
S: {
|
|
62
|
+
title: 'Home',
|
|
63
|
+
description: undefined,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
}
|
|
67
|
+
expect(computeConfigChange(before, after)).toEqual({ status: 'ok', ops: [], opCount: 0 })
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test('emits added values in JSON-compatible shape', () => {
|
|
71
|
+
const before = { m: {} }
|
|
72
|
+
const after = {
|
|
73
|
+
m: {
|
|
74
|
+
nested: {
|
|
75
|
+
keep: 1,
|
|
76
|
+
drop: undefined,
|
|
77
|
+
},
|
|
78
|
+
items: [undefined, 2],
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
const change = computeConfigChange(before, after)
|
|
82
|
+
expect(change.ops).toEqual([
|
|
83
|
+
{ op: 'set', path: ['m', 'nested'], value: { keep: 1 } },
|
|
84
|
+
{ op: 'set', path: ['m', 'items'], value: [null, 2] },
|
|
85
|
+
])
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('compares array undefined entries like JSON nulls', () => {
|
|
89
|
+
expect(computeConfigChange({ items: [null] }, { items: [undefined] })).toEqual({
|
|
90
|
+
status: 'ok',
|
|
91
|
+
ops: [],
|
|
92
|
+
opCount: 0,
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('reports no_baseline / unavailable for missing sides', () => {
|
|
97
|
+
expect(computeConfigChange(null, { a: 1 })).toEqual({ status: 'no_baseline' })
|
|
98
|
+
expect(computeConfigChange({ a: 1 }, null)).toEqual({ status: 'unavailable' })
|
|
99
|
+
})
|
|
100
|
+
})
|
|
@@ -0,0 +1,386 @@
|
|
|
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 event handlers', () => {
|
|
175
|
+
const BRICK_ID = 'BRICK_00000000-0000-0000-0000-000000000002'
|
|
176
|
+
|
|
177
|
+
test('preserves item-brick string handler casing and normalizes only system', async () => {
|
|
178
|
+
// A mixed-case ItemBrickID handler — must survive compile verbatim because the
|
|
179
|
+
// runtime resolves handlers case-sensitively (mapEventMapHandlersWithNewId).
|
|
180
|
+
const itemHandlerId = 'itemBrickHandlerId'
|
|
181
|
+
const app = makeApp()
|
|
182
|
+
app.rootSubspace.bricks = [
|
|
183
|
+
{
|
|
184
|
+
__typename: 'Brick',
|
|
185
|
+
id: BRICK_ID,
|
|
186
|
+
templateKey: 'BRICK_VIEW',
|
|
187
|
+
property: {},
|
|
188
|
+
events: {
|
|
189
|
+
onPress: [
|
|
190
|
+
{ handler: itemHandlerId, action: { __actionName: 'SCROLL_TO_INDEX' } },
|
|
191
|
+
{ handler: 'system', action: { __actionName: 'NAVIGATE' } },
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
]
|
|
196
|
+
|
|
197
|
+
const config = await compile(app)
|
|
198
|
+
const eventMap = config.subspace_map[SUBSPACE_ID].brick_map[BRICK_ID].event_map
|
|
199
|
+
const events = eventMap.BRICK_VIEW_ON_PRESS
|
|
200
|
+
|
|
201
|
+
// ItemBrickID handler kept verbatim (was wrongly uppercased to ITEMBRICKHANDLERID).
|
|
202
|
+
expect(events[0].handler).toBe(itemHandlerId)
|
|
203
|
+
// The literal 'system' handler still normalizes to SYSTEM.
|
|
204
|
+
expect(events[1].handler).toBe('SYSTEM')
|
|
205
|
+
})
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
describe('compile data remote update', () => {
|
|
209
|
+
test.each([
|
|
210
|
+
[undefined, { bank_type: 'none' }],
|
|
211
|
+
[{ type: 'auto' }, { bank_type: 'create', enable_remote_update: true }],
|
|
212
|
+
[
|
|
213
|
+
{ type: 'device-specific' },
|
|
214
|
+
{
|
|
215
|
+
bank_type: 'create-device-specific',
|
|
216
|
+
enable_remote_update: true,
|
|
217
|
+
use_remote_id_prefix: true,
|
|
218
|
+
},
|
|
219
|
+
],
|
|
220
|
+
[
|
|
221
|
+
{ type: 'global-data', id: 'GLOBAL_PROP_1' },
|
|
222
|
+
{
|
|
223
|
+
bank_type: 'global',
|
|
224
|
+
enable_remote_update: true,
|
|
225
|
+
global_remote_update_prop: 'GLOBAL_PROP_1',
|
|
226
|
+
},
|
|
227
|
+
],
|
|
228
|
+
])('emits bank_type for %p', async (remoteUpdate, expectedRemoteUpdate) => {
|
|
229
|
+
const config = await compile(makeApp([], [makeData(remoteUpdate)]))
|
|
230
|
+
|
|
231
|
+
expect(config.subspace_map[SUBSPACE_ID].property_bank_map[DATA_ID]).toMatchObject(
|
|
232
|
+
expectedRemoteUpdate,
|
|
233
|
+
)
|
|
234
|
+
})
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
describe('compile asset preload normalization', () => {
|
|
238
|
+
const makeAssetData = (id, kindType) => ({
|
|
239
|
+
__typename: 'Data',
|
|
240
|
+
id,
|
|
241
|
+
type: 'string',
|
|
242
|
+
kind: {
|
|
243
|
+
type: kindType,
|
|
244
|
+
preload: { type: 'url', hashType: 'sha256', hash: 'abc123' },
|
|
245
|
+
},
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
test('rive-file-uri normalizes preload like lottie-file-uri (hash re-keyed by hashType)', async () => {
|
|
249
|
+
const RIVE_ID = 'PROPERTY_BANK_DATA_NODE_00000000-0000-0000-0000-0000000000a1'
|
|
250
|
+
const LOTTIE_ID = 'PROPERTY_BANK_DATA_NODE_00000000-0000-0000-0000-0000000000a2'
|
|
251
|
+
const config = await compile(
|
|
252
|
+
makeApp(
|
|
253
|
+
[],
|
|
254
|
+
[makeAssetData(RIVE_ID, 'rive-file-uri'), makeAssetData(LOTTIE_ID, 'lottie-file-uri')],
|
|
255
|
+
),
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
const rive = config.subspace_map[SUBSPACE_ID].property_bank_map[RIVE_ID]
|
|
259
|
+
const lottie = config.subspace_map[SUBSPACE_ID].property_bank_map[LOTTIE_ID]
|
|
260
|
+
|
|
261
|
+
// Rive must get the same normalized preload as every sibling asset kind: the hash
|
|
262
|
+
// re-keyed under its hashType (the runtime reads preload[hashType]), not left raw under
|
|
263
|
+
// `hash`. Regression: rive was missing from preloadTypes, so it fell to the raw else
|
|
264
|
+
// branch and the runtime preload[hashType] lookup missed.
|
|
265
|
+
expect(rive.preload).toEqual({ type: 'url', hashType: 'sha256', sha256: 'abc123' })
|
|
266
|
+
expect(rive.preload).toEqual(lottie.preload)
|
|
267
|
+
})
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
describe('compile config-change audit log', () => {
|
|
271
|
+
const readAudit = async (projectDir) =>
|
|
272
|
+
(await readFile(path.join(projectDir, '.bricks/edits.jsonl'), 'utf8'))
|
|
273
|
+
.trim()
|
|
274
|
+
.split('\n')
|
|
275
|
+
.map((line) => JSON.parse(line))
|
|
276
|
+
|
|
277
|
+
const seedArtifact = async (projectDir, config) => {
|
|
278
|
+
const artifactPath = path.join(projectDir, '.bricks/build/application-config.json')
|
|
279
|
+
await mkdir(path.dirname(artifactPath), { recursive: true })
|
|
280
|
+
await writeFile(artifactPath, JSON.stringify(config))
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
test('records the config delta only in the editing-tools context', async () => {
|
|
284
|
+
const prevCwd = process.cwd()
|
|
285
|
+
const prevEnv = process.env.BRICKS_CTOR_ENABLE_EDITING_TOOLS
|
|
286
|
+
let projectDir
|
|
287
|
+
try {
|
|
288
|
+
projectDir = await mkdtemp(path.join(os.tmpdir(), 'bricks-compile-audit-'))
|
|
289
|
+
process.chdir(projectDir)
|
|
290
|
+
|
|
291
|
+
// (1) Editing tools disabled: even a real delta against a baseline is not recorded.
|
|
292
|
+
delete process.env.BRICKS_CTOR_ENABLE_EDITING_TOOLS
|
|
293
|
+
const empty = await compile(makeApp([], []))
|
|
294
|
+
await seedArtifact(projectDir, empty)
|
|
295
|
+
await compile(makeApp([], [makeData(undefined)]))
|
|
296
|
+
await expect(readFile(path.join(projectDir, '.bricks/edits.jsonl'))).rejects.toThrow()
|
|
297
|
+
|
|
298
|
+
// (2) Editing tools enabled: the compiled-config delta is recorded.
|
|
299
|
+
process.env.BRICKS_CTOR_ENABLE_EDITING_TOOLS = '1'
|
|
300
|
+
await seedArtifact(projectDir, empty)
|
|
301
|
+
const withData = await compile(makeApp([], [makeData(undefined)]))
|
|
302
|
+
const audit = await readAudit(projectDir)
|
|
303
|
+
expect(audit).toHaveLength(1)
|
|
304
|
+
expect(audit[0].tool).toBe('compile')
|
|
305
|
+
expect(audit[0].outcome).toBe('ok')
|
|
306
|
+
expect(audit[0].summary).toMatch(/compile: \d+ config op\(s\)/)
|
|
307
|
+
expect(JSON.stringify(audit[0].configChange)).toContain('property_bank_map')
|
|
308
|
+
// The audit log gets gitignored on first write.
|
|
309
|
+
const gitignore = await readFile(path.join(projectDir, '.gitignore'), 'utf8')
|
|
310
|
+
expect(gitignore).toContain('.bricks/edits.jsonl')
|
|
311
|
+
|
|
312
|
+
// (3) Recompiling with no source change records a "no config change" entry.
|
|
313
|
+
await seedArtifact(projectDir, withData)
|
|
314
|
+
await compile(makeApp([], [makeData(undefined)]))
|
|
315
|
+
const afterNoop = await readAudit(projectDir)
|
|
316
|
+
expect(afterNoop).toHaveLength(2)
|
|
317
|
+
expect(afterNoop[1].summary).toBe('compile: no config change')
|
|
318
|
+
|
|
319
|
+
// (4) Turning the flag off again (as the editing tools do for their verify compiles)
|
|
320
|
+
// suppresses the record even though there is a real delta.
|
|
321
|
+
process.env.BRICKS_CTOR_ENABLE_EDITING_TOOLS = '0'
|
|
322
|
+
await seedArtifact(projectDir, withData)
|
|
323
|
+
await compile(makeApp([], []))
|
|
324
|
+
expect(await readAudit(projectDir)).toHaveLength(2)
|
|
325
|
+
} finally {
|
|
326
|
+
if (prevEnv === undefined) delete process.env.BRICKS_CTOR_ENABLE_EDITING_TOOLS
|
|
327
|
+
else process.env.BRICKS_CTOR_ENABLE_EDITING_TOOLS = prevEnv
|
|
328
|
+
process.chdir(prevCwd)
|
|
329
|
+
if (projectDir) await rm(projectDir, { recursive: true, force: true })
|
|
330
|
+
}
|
|
331
|
+
})
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
describe('compile linked-module subspace', () => {
|
|
335
|
+
const LINKED_SUBSPACE_ID = 'SUBSPACE_00000000-0000-0000-0000-000000000002'
|
|
336
|
+
const makeLinkedApp = () => {
|
|
337
|
+
const app = makeApp()
|
|
338
|
+
app.subspaces = [
|
|
339
|
+
app.rootSubspace,
|
|
340
|
+
{
|
|
341
|
+
__typename: 'Subspace',
|
|
342
|
+
id: LINKED_SUBSPACE_ID,
|
|
343
|
+
title: 'Linked Module',
|
|
344
|
+
layout: { width: 96, height: 54 },
|
|
345
|
+
module: { link: true, id: 'MODULE_00000000-0000-0000-0000-000000000001', version: 1 },
|
|
346
|
+
},
|
|
347
|
+
]
|
|
348
|
+
return app
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
test('uses a deterministic placeholder canvas id stable across recompiles', async () => {
|
|
352
|
+
// Regression: the placeholder canvas id came from makeId('canvas'), whose count-fallback
|
|
353
|
+
// branch uses a never-reset process-global counter, so recompiling identical source produced
|
|
354
|
+
// a different id and broke compile's byte-stable-output contract (phantom config-change ops).
|
|
355
|
+
const first = await compile(makeLinkedApp())
|
|
356
|
+
const second = await compile(makeLinkedApp())
|
|
357
|
+
|
|
358
|
+
const firstKeys = Object.keys(first.subspace_map[LINKED_SUBSPACE_ID].canvas_map)
|
|
359
|
+
const secondKeys = Object.keys(second.subspace_map[LINKED_SUBSPACE_ID].canvas_map)
|
|
360
|
+
expect(firstKeys).toHaveLength(1)
|
|
361
|
+
expect(secondKeys).toEqual(firstKeys)
|
|
362
|
+
expect(first.subspace_map[LINKED_SUBSPACE_ID].root_canvas_id).toBe(firstKeys[0])
|
|
363
|
+
expect(second.subspace_map[LINKED_SUBSPACE_ID].root_canvas_id).toBe(firstKeys[0])
|
|
364
|
+
})
|
|
365
|
+
|
|
366
|
+
test('compileTestCase resolves a jump_to getter to its id (survives serialization)', () => {
|
|
367
|
+
// Regression: jump_cond[].jump_to may be a getter (() => TestCase) for dynamic case ids — the
|
|
368
|
+
// project generator emits `jump_to: () => caseVar`. compileTestCase passed it through verbatim
|
|
369
|
+
// (unlike the `run` array, which resolves getters via compileRunElement), so JSON.stringify of
|
|
370
|
+
// the compiled config dropped the function and the conditional jump silently vanished.
|
|
371
|
+
const compiled = compileTestCase({
|
|
372
|
+
__typename: 'TestCase',
|
|
373
|
+
id: 'TEST_CASE_src',
|
|
374
|
+
name: 'src',
|
|
375
|
+
run: [],
|
|
376
|
+
jump_cond: [
|
|
377
|
+
{ type: 'status', status: 'finished', jump_to: () => ({ id: 'TEST_CASE_target' }) },
|
|
378
|
+
{ type: 'status', status: 'failed', jump_to: 'TEST_CASE_literal' },
|
|
379
|
+
],
|
|
380
|
+
})
|
|
381
|
+
// The compiled config is serialized to disk, so the value must survive JSON round-tripping.
|
|
382
|
+
const serialized = JSON.parse(JSON.stringify(compiled))
|
|
383
|
+
expect(serialized.jump_cond[0].jump_to).toBe('TEST_CASE_target') // getter resolved to its id
|
|
384
|
+
expect(serialized.jump_cond[1].jump_to).toBe('TEST_CASE_literal') // string passes through
|
|
385
|
+
})
|
|
386
|
+
})
|