@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,866 @@
|
|
|
1
|
+
import { mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
|
|
5
|
+
jest.mock('oxfmt', () => ({
|
|
6
|
+
format: async (_file, source) => ({ code: source, errors: [] }),
|
|
7
|
+
}))
|
|
8
|
+
|
|
9
|
+
import { register, __test__ } from '../entry-editing'
|
|
10
|
+
|
|
11
|
+
const writeFixtureProject = async () => {
|
|
12
|
+
const projectDir = await mkdtemp(path.join(os.tmpdir(), 'bricks-entry-editing-'))
|
|
13
|
+
const subspaceDir = path.join(projectDir, 'subspaces/subspace-0')
|
|
14
|
+
await mkdir(subspaceDir, { recursive: true })
|
|
15
|
+
await writeFile(
|
|
16
|
+
path.join(subspaceDir, 'data.ts'),
|
|
17
|
+
`import type { Data } from 'bricks-ctor'
|
|
18
|
+
import { makeId } from 'bricks-ctor'
|
|
19
|
+
|
|
20
|
+
export const dMessage: Data = {
|
|
21
|
+
__typename: 'Data',
|
|
22
|
+
id: makeId('data'),
|
|
23
|
+
alias: 'message',
|
|
24
|
+
title: 'Message',
|
|
25
|
+
type: 'string',
|
|
26
|
+
schema: {},
|
|
27
|
+
events: {},
|
|
28
|
+
value: 'Hello',
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const dCount: Data = {
|
|
32
|
+
__typename: 'Data',
|
|
33
|
+
id: makeId('data'),
|
|
34
|
+
alias: 'count',
|
|
35
|
+
title: 'Count',
|
|
36
|
+
type: 'number',
|
|
37
|
+
schema: {},
|
|
38
|
+
events: {},
|
|
39
|
+
value: 0,
|
|
40
|
+
}
|
|
41
|
+
`,
|
|
42
|
+
)
|
|
43
|
+
await writeFile(
|
|
44
|
+
path.join(subspaceDir, 'bricks.ts'),
|
|
45
|
+
`import type { BrickText } from 'bricks-ctor'
|
|
46
|
+
import { linkData, makeId } from 'bricks-ctor'
|
|
47
|
+
import * as data from './data'
|
|
48
|
+
|
|
49
|
+
export const bWelcome: BrickText = {
|
|
50
|
+
__typename: 'Brick',
|
|
51
|
+
id: makeId('brick'),
|
|
52
|
+
alias: 'welcome',
|
|
53
|
+
templateKey: 'BRICK_TEXT',
|
|
54
|
+
title: 'Welcome',
|
|
55
|
+
property: {
|
|
56
|
+
text: 'Hello',
|
|
57
|
+
source: linkData(() => data.dMessage),
|
|
58
|
+
},
|
|
59
|
+
events: {},
|
|
60
|
+
outlets: {
|
|
61
|
+
response: () => data.dMessage,
|
|
62
|
+
},
|
|
63
|
+
animation: {},
|
|
64
|
+
switches: [
|
|
65
|
+
{
|
|
66
|
+
id: makeId('switch'),
|
|
67
|
+
title: 'When message matches',
|
|
68
|
+
conds: [
|
|
69
|
+
{
|
|
70
|
+
method: '==',
|
|
71
|
+
cond: {
|
|
72
|
+
__typename: 'SwitchCondData',
|
|
73
|
+
data: () => data.dMessage,
|
|
74
|
+
value: 'Hello',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
property: {},
|
|
79
|
+
events: {},
|
|
80
|
+
outlets: {},
|
|
81
|
+
animation: {},
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const bButton: BrickText = {
|
|
87
|
+
__typename: 'Brick',
|
|
88
|
+
id: makeId('brick'),
|
|
89
|
+
alias: 'button',
|
|
90
|
+
templateKey: 'BRICK_TEXT',
|
|
91
|
+
title: 'Button',
|
|
92
|
+
property: {},
|
|
93
|
+
events: {},
|
|
94
|
+
outlets: {},
|
|
95
|
+
animation: {},
|
|
96
|
+
switches: [],
|
|
97
|
+
}
|
|
98
|
+
`,
|
|
99
|
+
)
|
|
100
|
+
await writeFile(
|
|
101
|
+
path.join(subspaceDir, 'canvases.ts'),
|
|
102
|
+
`import type { Canvas } from 'bricks-ctor'
|
|
103
|
+
import { makeId } from 'bricks-ctor'
|
|
104
|
+
|
|
105
|
+
export const cMain: Canvas = {
|
|
106
|
+
__typename: 'Canvas',
|
|
107
|
+
id: makeId('canvas'),
|
|
108
|
+
alias: 'main',
|
|
109
|
+
title: 'Main',
|
|
110
|
+
property: {},
|
|
111
|
+
events: {},
|
|
112
|
+
switches: [],
|
|
113
|
+
items: [],
|
|
114
|
+
}
|
|
115
|
+
`,
|
|
116
|
+
)
|
|
117
|
+
await writeFile(
|
|
118
|
+
path.join(subspaceDir, 'generators.ts'),
|
|
119
|
+
`import type { GeneratorHTTP } from 'bricks-ctor'
|
|
120
|
+
import { makeId } from 'bricks-ctor'
|
|
121
|
+
|
|
122
|
+
export const gApi: GeneratorHTTP = {
|
|
123
|
+
__typename: 'Generator',
|
|
124
|
+
id: makeId('generator'),
|
|
125
|
+
alias: 'api',
|
|
126
|
+
templateKey: 'GENERATOR_HTTP',
|
|
127
|
+
title: 'API',
|
|
128
|
+
property: {},
|
|
129
|
+
events: {},
|
|
130
|
+
outlets: {},
|
|
131
|
+
switches: [],
|
|
132
|
+
}
|
|
133
|
+
`,
|
|
134
|
+
)
|
|
135
|
+
await writeFile(
|
|
136
|
+
path.join(subspaceDir, 'animations.ts'),
|
|
137
|
+
`import type { Animation } from 'bricks-ctor'
|
|
138
|
+
import { makeId } from 'bricks-ctor'
|
|
139
|
+
|
|
140
|
+
export const aFade: Animation = {
|
|
141
|
+
__typename: 'Animation',
|
|
142
|
+
id: makeId('animation'),
|
|
143
|
+
alias: 'fade',
|
|
144
|
+
title: 'Fade',
|
|
145
|
+
runType: 'once',
|
|
146
|
+
property: 'opacity',
|
|
147
|
+
config: {
|
|
148
|
+
__type: 'AnimationTimingConfig',
|
|
149
|
+
toValue: 1,
|
|
150
|
+
duration: 300,
|
|
151
|
+
easing: '',
|
|
152
|
+
delay: 0,
|
|
153
|
+
isInteraction: true,
|
|
154
|
+
},
|
|
155
|
+
}
|
|
156
|
+
`,
|
|
157
|
+
)
|
|
158
|
+
return projectDir
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const readProjectFile = (projectDir, relPath) => readFile(path.join(projectDir, relPath), 'utf8')
|
|
162
|
+
|
|
163
|
+
const readAudit = async (projectDir) =>
|
|
164
|
+
(await readFile(path.join(projectDir, '.bricks/edits.jsonl'), 'utf8'))
|
|
165
|
+
.trim()
|
|
166
|
+
.split('\n')
|
|
167
|
+
.map((line) => JSON.parse(line))
|
|
168
|
+
|
|
169
|
+
describe('ctor MCP entry-editing tools', () => {
|
|
170
|
+
let projectDir
|
|
171
|
+
|
|
172
|
+
afterEach(async () => {
|
|
173
|
+
if (projectDir) await rm(projectDir, { recursive: true, force: true })
|
|
174
|
+
projectDir = null
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
test('registers the six entry-editing MCP tools', () => {
|
|
178
|
+
const calls = []
|
|
179
|
+
register(
|
|
180
|
+
{
|
|
181
|
+
tool(...args) {
|
|
182
|
+
calls.push(args)
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
'/tmp/project',
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
expect(calls.map(([name]) => name)).toEqual([
|
|
189
|
+
'edit_entry',
|
|
190
|
+
'edit_events',
|
|
191
|
+
'edit_canvas_items',
|
|
192
|
+
'edit_switches',
|
|
193
|
+
'new_entry',
|
|
194
|
+
'remove_entry',
|
|
195
|
+
])
|
|
196
|
+
expect(
|
|
197
|
+
calls.every(([, description]) => typeof description === 'string' && description.length > 20),
|
|
198
|
+
).toBe(true)
|
|
199
|
+
const editEntrySchema = calls[0][2]
|
|
200
|
+
expect(editEntrySchema.file.description).toContain('Project-relative')
|
|
201
|
+
expect(editEntrySchema.set.description).toContain('dotted paths')
|
|
202
|
+
expect(editEntrySchema.set.description).toContain('{ link')
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
test('edit_entry updates nested facets and resolves link/ref values', async () => {
|
|
206
|
+
projectDir = await writeFixtureProject()
|
|
207
|
+
|
|
208
|
+
const result = await __test__.editEntry(projectDir, {
|
|
209
|
+
file: 'subspaces/subspace-0/bricks.ts',
|
|
210
|
+
entry: 'bWelcome',
|
|
211
|
+
set: {
|
|
212
|
+
title: 'Updated Welcome',
|
|
213
|
+
'property.text': 'Hi',
|
|
214
|
+
'property.count': { link: 'count' },
|
|
215
|
+
'outlets.count': { ref: 'count' },
|
|
216
|
+
},
|
|
217
|
+
verify: false,
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
expect(result.outcome).toBe('ok')
|
|
221
|
+
const source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
|
|
222
|
+
expect(source).toMatch(/title: ['"]Updated Welcome['"]/)
|
|
223
|
+
expect(source).toMatch(/text: ['"]Hi['"]/)
|
|
224
|
+
expect(source).toContain('count: linkData(() => data.dCount)')
|
|
225
|
+
expect(source).toContain('count: () => data.dCount')
|
|
226
|
+
const audit = await readAudit(projectDir)
|
|
227
|
+
expect(audit.at(-1).summary).toContain('edited bWelcome')
|
|
228
|
+
const gitignore = await readProjectFile(projectDir, '.gitignore')
|
|
229
|
+
expect(gitignore).toContain('.bricks/edits.jsonl')
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
test('edit_entry removes the correct elements when unsetting multiple array indices', async () => {
|
|
233
|
+
// Regression: unset paths were applied in input order, but unsetPathValue
|
|
234
|
+
// splices arrays in place — removing items[1] shifts items[2] down, so the
|
|
235
|
+
// second unset hit the wrong element (or no-op'd). Both requested elements
|
|
236
|
+
// must be removed regardless of order.
|
|
237
|
+
projectDir = await writeFixtureProject()
|
|
238
|
+
const target = { file: 'subspaces/subspace-0/bricks.ts', entry: 'bButton', verify: false }
|
|
239
|
+
|
|
240
|
+
const built = await __test__.editEntry(projectDir, {
|
|
241
|
+
...target,
|
|
242
|
+
set: {
|
|
243
|
+
'property.list[0]': 'ITEM_A',
|
|
244
|
+
'property.list[1]': 'ITEM_B',
|
|
245
|
+
'property.list[2]': 'ITEM_C',
|
|
246
|
+
},
|
|
247
|
+
})
|
|
248
|
+
expect(built.outcome).toBe('ok')
|
|
249
|
+
|
|
250
|
+
const unset = await __test__.editEntry(projectDir, {
|
|
251
|
+
...target,
|
|
252
|
+
unset: ['property.list[1]', 'property.list[2]'],
|
|
253
|
+
})
|
|
254
|
+
expect(unset.outcome).toBe('ok')
|
|
255
|
+
|
|
256
|
+
const source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
|
|
257
|
+
expect(source).toContain('ITEM_A')
|
|
258
|
+
expect(source).not.toContain('ITEM_B') // items[1] removed
|
|
259
|
+
expect(source).not.toContain('ITEM_C') // items[2] removed (survived before the fix)
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
test('edit_events adds a typed system event action', async () => {
|
|
263
|
+
projectDir = await writeFixtureProject()
|
|
264
|
+
|
|
265
|
+
const result = await __test__.editEvents(projectDir, {
|
|
266
|
+
file: 'subspaces/subspace-0/bricks.ts',
|
|
267
|
+
entry: 'bButton',
|
|
268
|
+
event: 'onPress',
|
|
269
|
+
op: 'add',
|
|
270
|
+
action: {
|
|
271
|
+
handler: 'system',
|
|
272
|
+
name: 'CHANGE_CANVAS',
|
|
273
|
+
params: {
|
|
274
|
+
canvasId: { ref: 'main' },
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
verify: false,
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
expect(result.outcome).toBe('ok')
|
|
281
|
+
const source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
|
|
282
|
+
expect(source).toContain('SystemActionChangeCanvas')
|
|
283
|
+
expect(source).toMatch(/handler: ['"]system['"]/)
|
|
284
|
+
expect(source).toMatch(/__actionName: ['"]CHANGE_CANVAS['"]/)
|
|
285
|
+
expect(source).toContain('value: () => canvases.cMain')
|
|
286
|
+
expect(source).toMatch(/import \* as canvases from ['"]\.\/canvases['"]/)
|
|
287
|
+
})
|
|
288
|
+
|
|
289
|
+
test('edit_canvas_items places a brick on a canvas', async () => {
|
|
290
|
+
projectDir = await writeFixtureProject()
|
|
291
|
+
|
|
292
|
+
const result = await __test__.editCanvasItems(projectDir, {
|
|
293
|
+
file: 'subspaces/subspace-0/canvases.ts',
|
|
294
|
+
entry: 'cMain',
|
|
295
|
+
op: 'add',
|
|
296
|
+
item: {
|
|
297
|
+
ref: 'welcome',
|
|
298
|
+
frame: { x: 1, y: 2, width: 10, height: 5 },
|
|
299
|
+
},
|
|
300
|
+
verify: false,
|
|
301
|
+
})
|
|
302
|
+
|
|
303
|
+
expect(result.outcome).toBe('ok')
|
|
304
|
+
const source = await readProjectFile(projectDir, 'subspaces/subspace-0/canvases.ts')
|
|
305
|
+
expect(source).toMatch(/import \* as bricks from ['"]\.\/bricks['"]/)
|
|
306
|
+
expect(source).toContain('item: () => bricks.bWelcome')
|
|
307
|
+
expect(source).toContain('width: 10')
|
|
308
|
+
})
|
|
309
|
+
|
|
310
|
+
test('edit_switches adds a switch with a data condition', async () => {
|
|
311
|
+
projectDir = await writeFixtureProject()
|
|
312
|
+
|
|
313
|
+
const result = await __test__.editSwitches(projectDir, {
|
|
314
|
+
file: 'subspaces/subspace-0/bricks.ts',
|
|
315
|
+
entry: 'bButton',
|
|
316
|
+
op: 'add',
|
|
317
|
+
switch: {
|
|
318
|
+
title: 'Count positive',
|
|
319
|
+
conds: [
|
|
320
|
+
{
|
|
321
|
+
method: '>',
|
|
322
|
+
cond: {
|
|
323
|
+
type: 'property_bank',
|
|
324
|
+
ref: 'count',
|
|
325
|
+
value: 0,
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
],
|
|
329
|
+
override: { property: true },
|
|
330
|
+
},
|
|
331
|
+
verify: false,
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
expect(result.outcome).toBe('ok')
|
|
335
|
+
const source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
|
|
336
|
+
expect(source).toMatch(/title: ['"]Count positive['"]/)
|
|
337
|
+
expect(source).toMatch(/__typename: ['"]SwitchCondData['"]/)
|
|
338
|
+
expect(source).toContain('data: () => data.dCount')
|
|
339
|
+
expect(source).toMatch(/override:\s*{\s*property: true\s*}/)
|
|
340
|
+
expect((source.match(/id:\s*makeId\(['"]switch['"]\)/g) || []).length).toBe(2)
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
test('new_entry creates a standard skeleton and applies initial values', async () => {
|
|
344
|
+
projectDir = await writeFixtureProject()
|
|
345
|
+
|
|
346
|
+
const result = await __test__.newEntry(projectDir, {
|
|
347
|
+
file: 'subspaces/subspace-0/generators.ts',
|
|
348
|
+
type: 'GeneratorHTTP',
|
|
349
|
+
templateKey: 'GENERATOR_HTTP',
|
|
350
|
+
alias: 'weatherApi',
|
|
351
|
+
title: 'Weather API',
|
|
352
|
+
set: {
|
|
353
|
+
'property.url': 'https://api.example.test',
|
|
354
|
+
},
|
|
355
|
+
verify: false,
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
expect(result.outcome).toBe('ok')
|
|
359
|
+
expect(result.entry).toBe('weatherApi')
|
|
360
|
+
const source = await readProjectFile(projectDir, 'subspaces/subspace-0/generators.ts')
|
|
361
|
+
expect(source).toContain('export const weatherApi: GeneratorHTTP =')
|
|
362
|
+
expect(source).toMatch(/id: makeId\(['"]generator['"], ['"]weatherApi['"]\)/)
|
|
363
|
+
expect(source).toMatch(/templateKey: ['"]GENERATOR_HTTP['"]/)
|
|
364
|
+
expect(source).toMatch(/url: ['"]https:\/\/api\.example\.test['"]/)
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
test('new_entry can be retried with the same alias in one server session', async () => {
|
|
368
|
+
projectDir = await writeFixtureProject()
|
|
369
|
+
|
|
370
|
+
const first = await __test__.newEntry(projectDir, {
|
|
371
|
+
file: 'subspaces/subspace-0/generators.ts',
|
|
372
|
+
type: 'GeneratorHTTP',
|
|
373
|
+
templateKey: 'GENERATOR_HTTP',
|
|
374
|
+
alias: 'retryApi',
|
|
375
|
+
verify: false,
|
|
376
|
+
})
|
|
377
|
+
const second = await __test__.newEntry(projectDir, {
|
|
378
|
+
file: 'subspaces/subspace-0/generators.ts',
|
|
379
|
+
type: 'GeneratorHTTP',
|
|
380
|
+
templateKey: 'GENERATOR_HTTP',
|
|
381
|
+
alias: 'retryApi',
|
|
382
|
+
verify: false,
|
|
383
|
+
})
|
|
384
|
+
|
|
385
|
+
expect(first.outcome).toBe('ok')
|
|
386
|
+
expect(second.outcome).toBe('ok')
|
|
387
|
+
expect(second.entry).toBe('retryApi1')
|
|
388
|
+
expect(first.id).toBeUndefined()
|
|
389
|
+
expect(second.id).toBeUndefined()
|
|
390
|
+
// First use of the alias gets the order-stable aliased id; the duplicate falls
|
|
391
|
+
// back to the counter form so compile does not hit a makeId alias collision.
|
|
392
|
+
expect(first.idExpression).toBe("makeId('generator', 'retryApi')")
|
|
393
|
+
expect(second.idExpression).toBe("makeId('generator')")
|
|
394
|
+
const source = await readProjectFile(projectDir, 'subspaces/subspace-0/generators.ts')
|
|
395
|
+
expect((source.match(/id:\s*makeId\(['"]generator['"]\)/g) || []).length).toBe(2)
|
|
396
|
+
expect(source).toMatch(/makeId\(['"]generator['"], ['"]retryApi['"]\)/)
|
|
397
|
+
})
|
|
398
|
+
|
|
399
|
+
test('entry targeting falls back to entity aliases', async () => {
|
|
400
|
+
projectDir = await writeFixtureProject()
|
|
401
|
+
|
|
402
|
+
const result = await __test__.editEntry(projectDir, {
|
|
403
|
+
file: 'subspaces/subspace-0/bricks.ts',
|
|
404
|
+
entry: 'welcome',
|
|
405
|
+
set: { title: 'Aliased Edit' },
|
|
406
|
+
verify: false,
|
|
407
|
+
})
|
|
408
|
+
|
|
409
|
+
expect(result.outcome).toBe('ok')
|
|
410
|
+
expect(result.entry).toBe('bWelcome')
|
|
411
|
+
const source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
|
|
412
|
+
expect(source).toMatch(/title: ['"]Aliased Edit['"]/)
|
|
413
|
+
})
|
|
414
|
+
|
|
415
|
+
test('parse failures tell the caller to use file tools', async () => {
|
|
416
|
+
projectDir = await writeFixtureProject()
|
|
417
|
+
await writeFile(path.join(projectDir, 'subspaces/subspace-0/bricks.ts'), 'export const =')
|
|
418
|
+
|
|
419
|
+
const result = await __test__.editEntry(projectDir, {
|
|
420
|
+
file: 'subspaces/subspace-0/bricks.ts',
|
|
421
|
+
entry: 'bWelcome',
|
|
422
|
+
set: { title: 'Nope' },
|
|
423
|
+
verify: false,
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
expect(result.outcome).toBe('error')
|
|
427
|
+
expect(result.isError).toBe(true)
|
|
428
|
+
expect(result.error.message).toContain('Edit this file directly')
|
|
429
|
+
})
|
|
430
|
+
|
|
431
|
+
test('edit_events accepts the compiled EventAction shape, supports move, and casts stay editable', async () => {
|
|
432
|
+
projectDir = await writeFixtureProject()
|
|
433
|
+
const target = {
|
|
434
|
+
file: 'subspaces/subspace-0/bricks.ts',
|
|
435
|
+
entry: 'bButton',
|
|
436
|
+
event: 'onPress',
|
|
437
|
+
verify: false,
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const added = await __test__.editEvents(projectDir, {
|
|
441
|
+
...target,
|
|
442
|
+
op: 'add',
|
|
443
|
+
action: { handler: 'system', name: 'CHANGE_CANVAS', params: { canvasId: { ref: 'main' } } },
|
|
444
|
+
})
|
|
445
|
+
expect(added.outcome).toBe('ok')
|
|
446
|
+
|
|
447
|
+
// Replace using the compiled source shape ({ handler, action: {...}, waitAsync }).
|
|
448
|
+
const replaced = await __test__.editEvents(projectDir, {
|
|
449
|
+
...target,
|
|
450
|
+
op: 'replace',
|
|
451
|
+
index: 0,
|
|
452
|
+
action: {
|
|
453
|
+
handler: 'system',
|
|
454
|
+
action: {
|
|
455
|
+
__actionName: 'PROPERTY_BANK',
|
|
456
|
+
parent: 'System',
|
|
457
|
+
name: 'PROPERTY_BANK',
|
|
458
|
+
dataParams: [{ input: { ref: 'count' }, value: '1' }],
|
|
459
|
+
},
|
|
460
|
+
waitAsync: false,
|
|
461
|
+
},
|
|
462
|
+
})
|
|
463
|
+
expect(replaced.outcome).toBe('ok')
|
|
464
|
+
let source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
|
|
465
|
+
expect(source).toMatch(/__actionName: ['"]PROPERTY_BANK['"]/)
|
|
466
|
+
expect(source).toContain('input: () => data.dCount')
|
|
467
|
+
|
|
468
|
+
// Deep edit_entry paths see through the `as SystemAction...` cast.
|
|
469
|
+
const deepEdit = await __test__.editEntry(projectDir, {
|
|
470
|
+
file: 'subspaces/subspace-0/bricks.ts',
|
|
471
|
+
entry: 'bButton',
|
|
472
|
+
set: { 'events.onPress[0].action.dataParams[0].value': '2' },
|
|
473
|
+
verify: false,
|
|
474
|
+
})
|
|
475
|
+
expect(deepEdit.outcome).toBe('ok')
|
|
476
|
+
source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
|
|
477
|
+
expect(source).toMatch(/value: ['"]2['"]/)
|
|
478
|
+
expect(source).toContain('as SystemActionPropertyBank')
|
|
479
|
+
|
|
480
|
+
const addedSecond = await __test__.editEvents(projectDir, {
|
|
481
|
+
...target,
|
|
482
|
+
op: 'add',
|
|
483
|
+
action: { handler: 'system', name: 'CHANGE_CANVAS', params: { canvasId: { ref: 'main' } } },
|
|
484
|
+
})
|
|
485
|
+
expect(addedSecond.outcome).toBe('ok')
|
|
486
|
+
|
|
487
|
+
const moved = await __test__.editEvents(projectDir, { ...target, op: 'move', index: 1, to: 0 })
|
|
488
|
+
expect(moved.outcome).toBe('ok')
|
|
489
|
+
source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
|
|
490
|
+
expect(source.indexOf('CHANGE_CANVAS')).toBeLessThan(source.indexOf('PROPERTY_BANK'))
|
|
491
|
+
})
|
|
492
|
+
|
|
493
|
+
test('edit_canvas_items validates frames and accepts a top-level frame on add', async () => {
|
|
494
|
+
projectDir = await writeFixtureProject()
|
|
495
|
+
const target = { file: 'subspaces/subspace-0/canvases.ts', entry: 'cMain', verify: false }
|
|
496
|
+
|
|
497
|
+
const missingFrame = await __test__.editCanvasItems(projectDir, {
|
|
498
|
+
...target,
|
|
499
|
+
op: 'add',
|
|
500
|
+
item: { ref: 'welcome' },
|
|
501
|
+
})
|
|
502
|
+
expect(missingFrame.outcome).toBe('error')
|
|
503
|
+
expect(missingFrame.error.message).toContain('requires frame')
|
|
504
|
+
|
|
505
|
+
const badFrame = await __test__.editCanvasItems(projectDir, {
|
|
506
|
+
...target,
|
|
507
|
+
op: 'add',
|
|
508
|
+
item: { ref: 'welcome', frame: { x: 1, y: 2, width: 10 } },
|
|
509
|
+
})
|
|
510
|
+
expect(badFrame.outcome).toBe('error')
|
|
511
|
+
expect(badFrame.error.message).toContain('numeric height')
|
|
512
|
+
|
|
513
|
+
const topLevelFrame = await __test__.editCanvasItems(projectDir, {
|
|
514
|
+
...target,
|
|
515
|
+
op: 'add',
|
|
516
|
+
item: { ref: 'welcome' },
|
|
517
|
+
frame: { x: 1, y: 2, width: 10, height: 5 },
|
|
518
|
+
})
|
|
519
|
+
expect(topLevelFrame.outcome).toBe('ok')
|
|
520
|
+
const source = await readProjectFile(projectDir, 'subspaces/subspace-0/canvases.ts')
|
|
521
|
+
expect(source).toContain('item: () => bricks.bWelcome')
|
|
522
|
+
expect(source).toContain('height: 5')
|
|
523
|
+
})
|
|
524
|
+
|
|
525
|
+
test('edit_canvas_items move requires a frame', async () => {
|
|
526
|
+
projectDir = await writeFixtureProject()
|
|
527
|
+
|
|
528
|
+
const result = await __test__.editCanvasItems(projectDir, {
|
|
529
|
+
file: 'subspaces/subspace-0/canvases.ts',
|
|
530
|
+
entry: 'cMain',
|
|
531
|
+
op: 'move',
|
|
532
|
+
index: 0,
|
|
533
|
+
verify: false,
|
|
534
|
+
})
|
|
535
|
+
|
|
536
|
+
expect(result.outcome).toBe('error')
|
|
537
|
+
expect(result.error.message).toContain('move requires frame')
|
|
538
|
+
})
|
|
539
|
+
|
|
540
|
+
test('inner-state outlet switch conditions require outlet or key', async () => {
|
|
541
|
+
projectDir = await writeFixtureProject()
|
|
542
|
+
|
|
543
|
+
const result = await __test__.editSwitches(projectDir, {
|
|
544
|
+
file: 'subspaces/subspace-0/bricks.ts',
|
|
545
|
+
entry: 'bButton',
|
|
546
|
+
op: 'add',
|
|
547
|
+
switch: {
|
|
548
|
+
conds: [
|
|
549
|
+
{
|
|
550
|
+
cond: {
|
|
551
|
+
type: 'inner_state',
|
|
552
|
+
value: true,
|
|
553
|
+
},
|
|
554
|
+
},
|
|
555
|
+
],
|
|
556
|
+
},
|
|
557
|
+
verify: false,
|
|
558
|
+
})
|
|
559
|
+
|
|
560
|
+
expect(result.outcome).toBe('error')
|
|
561
|
+
expect(result.error.message).toContain('requires outlet or key')
|
|
562
|
+
})
|
|
563
|
+
|
|
564
|
+
test('remove_entry cascades references and strict mode refuses referenced entries', async () => {
|
|
565
|
+
projectDir = await writeFixtureProject()
|
|
566
|
+
|
|
567
|
+
const strictResult = await __test__.removeEntry(projectDir, {
|
|
568
|
+
file: 'subspaces/subspace-0/data.ts',
|
|
569
|
+
entry: 'dMessage',
|
|
570
|
+
strict: true,
|
|
571
|
+
verify: false,
|
|
572
|
+
})
|
|
573
|
+
expect(strictResult.outcome).toBe('refused')
|
|
574
|
+
expect(strictResult.touchedSites.length).toBeGreaterThan(0)
|
|
575
|
+
|
|
576
|
+
const result = await __test__.removeEntry(projectDir, {
|
|
577
|
+
file: 'subspaces/subspace-0/data.ts',
|
|
578
|
+
entry: 'dMessage',
|
|
579
|
+
verify: false,
|
|
580
|
+
})
|
|
581
|
+
expect(result.outcome).toBe('ok')
|
|
582
|
+
|
|
583
|
+
const data = await readProjectFile(projectDir, 'subspaces/subspace-0/data.ts')
|
|
584
|
+
const bricks = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
|
|
585
|
+
expect(data).not.toContain('dMessage')
|
|
586
|
+
expect(bricks).not.toContain('data.dMessage')
|
|
587
|
+
expect(bricks).toContain('source: undefined')
|
|
588
|
+
expect(bricks).not.toContain('response:')
|
|
589
|
+
})
|
|
590
|
+
|
|
591
|
+
test('remove_entry strict mode sees same-file references outside the target entry', async () => {
|
|
592
|
+
projectDir = await writeFixtureProject()
|
|
593
|
+
await __test__.editEntry(projectDir, {
|
|
594
|
+
file: 'subspaces/subspace-0/bricks.ts',
|
|
595
|
+
entry: 'bButton',
|
|
596
|
+
set: {
|
|
597
|
+
'property.peer': { ref: 'welcome' },
|
|
598
|
+
},
|
|
599
|
+
verify: false,
|
|
600
|
+
})
|
|
601
|
+
|
|
602
|
+
const result = await __test__.removeEntry(projectDir, {
|
|
603
|
+
file: 'subspaces/subspace-0/bricks.ts',
|
|
604
|
+
entry: 'bWelcome',
|
|
605
|
+
strict: true,
|
|
606
|
+
verify: false,
|
|
607
|
+
})
|
|
608
|
+
|
|
609
|
+
expect(result.outcome).toBe('refused')
|
|
610
|
+
expect(result.touchedSites.some((site) => site.file === 'subspaces/subspace-0/bricks.ts')).toBe(
|
|
611
|
+
true,
|
|
612
|
+
)
|
|
613
|
+
})
|
|
614
|
+
|
|
615
|
+
test('edit_events validates indices and drops emptied event keys', async () => {
|
|
616
|
+
projectDir = await writeFixtureProject()
|
|
617
|
+
const target = {
|
|
618
|
+
file: 'subspaces/subspace-0/bricks.ts',
|
|
619
|
+
entry: 'bButton',
|
|
620
|
+
event: 'onPress',
|
|
621
|
+
verify: false,
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
const added = await __test__.editEvents(projectDir, {
|
|
625
|
+
...target,
|
|
626
|
+
op: 'add',
|
|
627
|
+
action: { handler: 'system', name: 'CHANGE_CANVAS' },
|
|
628
|
+
})
|
|
629
|
+
expect(added.outcome).toBe('ok')
|
|
630
|
+
|
|
631
|
+
const outOfRange = await __test__.editEvents(projectDir, { ...target, op: 'remove', index: 5 })
|
|
632
|
+
expect(outOfRange.outcome).toBe('error')
|
|
633
|
+
expect(outOfRange.error.message).toContain('remove index out of range')
|
|
634
|
+
|
|
635
|
+
const removed = await __test__.editEvents(projectDir, { ...target, op: 'remove', index: 0 })
|
|
636
|
+
expect(removed.outcome).toBe('ok')
|
|
637
|
+
const source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
|
|
638
|
+
expect(source).not.toContain('onPress')
|
|
639
|
+
|
|
640
|
+
const cleared = await __test__.editEvents(projectDir, {
|
|
641
|
+
...target,
|
|
642
|
+
event: 'neverExisted',
|
|
643
|
+
op: 'clear',
|
|
644
|
+
})
|
|
645
|
+
expect(cleared.outcome).toBe('ok')
|
|
646
|
+
const clearedSource = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
|
|
647
|
+
expect(clearedSource).not.toContain('neverExisted')
|
|
648
|
+
})
|
|
649
|
+
|
|
650
|
+
test('edit_events validates PROPERTY_BANK_EXPRESSION against the runtime fold rules', async () => {
|
|
651
|
+
projectDir = await writeFixtureProject()
|
|
652
|
+
const target = {
|
|
653
|
+
file: 'subspaces/subspace-0/bricks.ts',
|
|
654
|
+
entry: 'bButton',
|
|
655
|
+
event: 'onPress',
|
|
656
|
+
op: 'add',
|
|
657
|
+
verify: false,
|
|
658
|
+
}
|
|
659
|
+
const expressionAction = (expression) => ({
|
|
660
|
+
handler: 'system',
|
|
661
|
+
name: 'PROPERTY_BANK_EXPRESSION',
|
|
662
|
+
params: { expression, variables: [], result: { expr: '() => data.dCount' } },
|
|
663
|
+
})
|
|
664
|
+
|
|
665
|
+
const ifStatement = await __test__.editEvents(projectDir, {
|
|
666
|
+
...target,
|
|
667
|
+
action: expressionAction('if (count > 0) { count + 1 } else { 0 }'),
|
|
668
|
+
})
|
|
669
|
+
expect(ifStatement.outcome).toBe('error')
|
|
670
|
+
expect(ifStatement.error.message).toContain('an if statement')
|
|
671
|
+
expect(ifStatement.error.message).toContain('ternaries')
|
|
672
|
+
|
|
673
|
+
const earlyReturn = await __test__.editEvents(projectDir, {
|
|
674
|
+
...target,
|
|
675
|
+
action: expressionAction('(() => { if (count > 12) return count; return count + 1 })()'),
|
|
676
|
+
})
|
|
677
|
+
expect(earlyReturn.outcome).toBe('error')
|
|
678
|
+
|
|
679
|
+
const iife = await __test__.editEvents(projectDir, {
|
|
680
|
+
...target,
|
|
681
|
+
action: expressionAction(
|
|
682
|
+
'(() => { const next = String(count); return next.length > 12 ? next.slice(0, 12) : next })()',
|
|
683
|
+
),
|
|
684
|
+
})
|
|
685
|
+
expect(iife.outcome).toBe('ok')
|
|
686
|
+
})
|
|
687
|
+
|
|
688
|
+
test('edit_events rejects non-brick/generator action handlers', async () => {
|
|
689
|
+
projectDir = await writeFixtureProject()
|
|
690
|
+
|
|
691
|
+
const result = await __test__.editEvents(projectDir, {
|
|
692
|
+
file: 'subspaces/subspace-0/bricks.ts',
|
|
693
|
+
entry: 'bButton',
|
|
694
|
+
event: 'onPress',
|
|
695
|
+
op: 'add',
|
|
696
|
+
action: { handler: { ref: 'main' }, name: 'SHOW' },
|
|
697
|
+
verify: false,
|
|
698
|
+
})
|
|
699
|
+
|
|
700
|
+
expect(result.outcome).toBe('error')
|
|
701
|
+
expect(result.error.message).toContain('must be a brick or generator')
|
|
702
|
+
})
|
|
703
|
+
|
|
704
|
+
test('edit_switches accepts compiled __typename cond shapes and switch facets', async () => {
|
|
705
|
+
projectDir = await writeFixtureProject()
|
|
706
|
+
|
|
707
|
+
const result = await __test__.editSwitches(projectDir, {
|
|
708
|
+
file: 'subspaces/subspace-0/bricks.ts',
|
|
709
|
+
entry: 'bButton',
|
|
710
|
+
op: 'add',
|
|
711
|
+
switch: {
|
|
712
|
+
title: 'Pressed shadow',
|
|
713
|
+
conds: [
|
|
714
|
+
{
|
|
715
|
+
method: '==',
|
|
716
|
+
cond: {
|
|
717
|
+
__typename: 'SwitchCondInnerStateOutlet',
|
|
718
|
+
outlet: 'brickPressing',
|
|
719
|
+
value: true,
|
|
720
|
+
},
|
|
721
|
+
},
|
|
722
|
+
],
|
|
723
|
+
property: { opacity: 0.92 },
|
|
724
|
+
override: { property: false },
|
|
725
|
+
},
|
|
726
|
+
verify: false,
|
|
727
|
+
})
|
|
728
|
+
|
|
729
|
+
expect(result.outcome).toBe('ok')
|
|
730
|
+
const source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
|
|
731
|
+
expect(source).toMatch(/__typename: ['"]SwitchCondInnerStateOutlet['"]/)
|
|
732
|
+
expect(source).toMatch(/outlet: ['"]brickPressing['"]/)
|
|
733
|
+
expect(source).toMatch(/Pressed shadow[\s\S]*?property:\s*{\s*opacity: 0\.92\s*}/)
|
|
734
|
+
})
|
|
735
|
+
|
|
736
|
+
test('edit_switches validates explicit ids and rejects events/unknown fields', async () => {
|
|
737
|
+
projectDir = await writeFixtureProject()
|
|
738
|
+
const target = { file: 'subspaces/subspace-0/bricks.ts', entry: 'bButton', verify: false }
|
|
739
|
+
|
|
740
|
+
const badId = await __test__.editSwitches(projectDir, {
|
|
741
|
+
...target,
|
|
742
|
+
op: 'add',
|
|
743
|
+
switch: { id: 'SWITCH_pressed_shadow' },
|
|
744
|
+
})
|
|
745
|
+
expect(badId.outcome).toBe('error')
|
|
746
|
+
expect(badId.error.message).toContain('BRICK_STATE_GROUP_<uuid>')
|
|
747
|
+
|
|
748
|
+
const events = await __test__.editSwitches(projectDir, {
|
|
749
|
+
...target,
|
|
750
|
+
op: 'add',
|
|
751
|
+
switch: { events: { onPress: [] } },
|
|
752
|
+
})
|
|
753
|
+
expect(events.outcome).toBe('error')
|
|
754
|
+
expect(events.error.message).toContain('edit_events')
|
|
755
|
+
|
|
756
|
+
const unknown = await __test__.editSwitches(projectDir, {
|
|
757
|
+
...target,
|
|
758
|
+
op: 'add',
|
|
759
|
+
switch: { titel: 'typo' },
|
|
760
|
+
})
|
|
761
|
+
expect(unknown.outcome).toBe('error')
|
|
762
|
+
expect(unknown.error.message).toContain('Unknown switch field')
|
|
763
|
+
expect(unknown.input).toBeDefined()
|
|
764
|
+
})
|
|
765
|
+
|
|
766
|
+
test('edit_switches move rejects out-of-range indices', async () => {
|
|
767
|
+
projectDir = await writeFixtureProject()
|
|
768
|
+
|
|
769
|
+
const result = await __test__.editSwitches(projectDir, {
|
|
770
|
+
file: 'subspaces/subspace-0/bricks.ts',
|
|
771
|
+
entry: 'bWelcome',
|
|
772
|
+
op: 'move',
|
|
773
|
+
index: 5,
|
|
774
|
+
to: 0,
|
|
775
|
+
verify: false,
|
|
776
|
+
})
|
|
777
|
+
|
|
778
|
+
expect(result.outcome).toBe('error')
|
|
779
|
+
expect(result.error.message).toContain('valid switch id or index')
|
|
780
|
+
})
|
|
781
|
+
|
|
782
|
+
test('new_entry brick skeleton includes the animation facet', async () => {
|
|
783
|
+
projectDir = await writeFixtureProject()
|
|
784
|
+
|
|
785
|
+
const result = await __test__.newEntry(projectDir, {
|
|
786
|
+
file: 'subspaces/subspace-0/bricks.ts',
|
|
787
|
+
type: 'BrickText',
|
|
788
|
+
templateKey: 'BRICK_TEXT',
|
|
789
|
+
alias: 'newBrick',
|
|
790
|
+
verify: false,
|
|
791
|
+
})
|
|
792
|
+
|
|
793
|
+
expect(result.outcome).toBe('ok')
|
|
794
|
+
const source = await readProjectFile(projectDir, 'subspaces/subspace-0/bricks.ts')
|
|
795
|
+
expect(source).toMatch(/newBrick[\s\S]*animation: \{\}/)
|
|
796
|
+
})
|
|
797
|
+
|
|
798
|
+
test('remove_entry cleans data-calc IO references instead of breaking them', async () => {
|
|
799
|
+
projectDir = await writeFixtureProject()
|
|
800
|
+
const dataCalcDir = path.join(projectDir, 'subspaces/subspace-0/data-calc')
|
|
801
|
+
await mkdir(dataCalcDir, { recursive: true })
|
|
802
|
+
await writeFile(
|
|
803
|
+
path.join(dataCalcDir, 'data-calculation-calc.ts'),
|
|
804
|
+
`import type { DataCalculationScript } from 'bricks-ctor'
|
|
805
|
+
import { makeId } from 'bricks-ctor'
|
|
806
|
+
import * as data from '../data'
|
|
807
|
+
|
|
808
|
+
export const dataCalculation: DataCalculationScript = {
|
|
809
|
+
__typename: 'DataCalculationScript',
|
|
810
|
+
id: makeId('property_bank_calc'),
|
|
811
|
+
alias: 'calc',
|
|
812
|
+
code: 'return inputs.message',
|
|
813
|
+
enableAsync: false,
|
|
814
|
+
inputs: [
|
|
815
|
+
{ key: 'message', data: () => data.dMessage, trigger: true },
|
|
816
|
+
{ key: 'count', data: () => data.dCount, trigger: true },
|
|
817
|
+
],
|
|
818
|
+
output: () => data.dMessage,
|
|
819
|
+
outputs: [{ key: 'copy', data: () => data.dMessage }],
|
|
820
|
+
error: null,
|
|
821
|
+
}
|
|
822
|
+
`,
|
|
823
|
+
)
|
|
824
|
+
|
|
825
|
+
const result = await __test__.removeEntry(projectDir, {
|
|
826
|
+
file: 'subspaces/subspace-0/data.ts',
|
|
827
|
+
entry: 'dMessage',
|
|
828
|
+
verify: false,
|
|
829
|
+
})
|
|
830
|
+
|
|
831
|
+
expect(result.outcome).toBe('ok')
|
|
832
|
+
const calc = await readProjectFile(
|
|
833
|
+
projectDir,
|
|
834
|
+
'subspaces/subspace-0/data-calc/data-calculation-calc.ts',
|
|
835
|
+
)
|
|
836
|
+
expect(calc).not.toContain('dMessage')
|
|
837
|
+
expect(calc).toContain('output: null')
|
|
838
|
+
expect(calc).toMatch(/key: ['"]count['"]/)
|
|
839
|
+
expect(result.touchedSites.some((site) => site.action === 'remove_io_item')).toBe(true)
|
|
840
|
+
expect(result.touchedSites.some((site) => site.action === 'null_output')).toBe(true)
|
|
841
|
+
})
|
|
842
|
+
|
|
843
|
+
test('non-standard entries return a fallback recommendation and are logged', async () => {
|
|
844
|
+
projectDir = await writeFixtureProject()
|
|
845
|
+
await writeFile(
|
|
846
|
+
path.join(projectDir, 'subspaces/subspace-0/data.ts'),
|
|
847
|
+
`import type { Data } from 'bricks-ctor'
|
|
848
|
+
import { useSystemData } from 'bricks-ctor'
|
|
849
|
+
|
|
850
|
+
export const dSystem: Data = useSystemData('currentTime')
|
|
851
|
+
`,
|
|
852
|
+
)
|
|
853
|
+
|
|
854
|
+
const result = await __test__.editEntry(projectDir, {
|
|
855
|
+
file: 'subspaces/subspace-0/data.ts',
|
|
856
|
+
entry: 'dSystem',
|
|
857
|
+
set: { title: 'Current Time' },
|
|
858
|
+
verify: false,
|
|
859
|
+
})
|
|
860
|
+
|
|
861
|
+
expect(result.outcome).toBe('fallback_recommended')
|
|
862
|
+
expect(result.error.message).toContain('not a top-level exported object literal')
|
|
863
|
+
const audit = await readAudit(projectDir)
|
|
864
|
+
expect(audit.at(-1).outcome).toBe('fallback_recommended')
|
|
865
|
+
})
|
|
866
|
+
})
|