@1agh/maude 0.49.1 → 0.50.0

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 (34) hide show
  1. package/apps/studio/api.ts +751 -52
  2. package/apps/studio/canvas-artifacts.ts +153 -0
  3. package/apps/studio/canvas-create.ts +23 -0
  4. package/apps/studio/canvas-slug.ts +30 -0
  5. package/apps/studio/client/app.jsx +547 -90
  6. package/apps/studio/client/panels/CloudBar.jsx +284 -0
  7. package/apps/studio/client/styles/3-shell-maude.css +26 -0
  8. package/apps/studio/client/tree-row-menu.jsx +132 -0
  9. package/apps/studio/client/use-tree-drag.js +120 -0
  10. package/apps/studio/cloud/endpoints.ts +236 -0
  11. package/apps/studio/collab/registry.ts +23 -0
  12. package/apps/studio/dist/client.bundle.js +960 -958
  13. package/apps/studio/dist/styles.css +1 -1
  14. package/apps/studio/http.ts +113 -0
  15. package/apps/studio/inspect.ts +49 -0
  16. package/apps/studio/server.ts +15 -0
  17. package/apps/studio/test/canvas-artifacts.test.ts +125 -0
  18. package/apps/studio/test/canvas-create-api.test.ts +159 -1
  19. package/apps/studio/test/canvas-move-api.test.ts +556 -0
  20. package/apps/studio/test/canvas-origin-gate.test.ts +6 -0
  21. package/apps/studio/test/fs-mkdir-api.test.ts +248 -0
  22. package/apps/studio/whats-new.json +18 -0
  23. package/cli/bin/maude.mjs +1 -0
  24. package/cli/commands/hub-workspace.mjs +294 -7
  25. package/cli/commands/init.mjs +33 -2
  26. package/cli/commands/kg.mjs +129 -4
  27. package/cli/commands/share.mjs +184 -0
  28. package/cli/lib/ddr-to-kgai.mjs +310 -82
  29. package/cli/lib/ddr-to-kgai.test.mjs +20 -0
  30. package/cli/lib/share-plan.mjs +96 -0
  31. package/cli/lib/share-plan.test.mjs +57 -0
  32. package/cli/lib/workspace-plan.mjs +130 -12
  33. package/cli/lib/workspace-plan.test.mjs +160 -0
  34. package/package.json +8 -8
@@ -0,0 +1,556 @@
1
+ // /_api/fs-move — feature-file-tree-drag-drop-folders (Task 3). Covers the
2
+ // HTTP round-trip (happy path, containment, DS refusal, collision, full
3
+ // re-key across every sidecar) plus, in-process (no server boot needed), the
4
+ // collab-pin refusal — the one guard an HTTP-only black-box test can't drive,
5
+ // since pinning a room requires reaching into the dev-server's in-memory
6
+ // collab registry.
7
+
8
+ import { describe, expect, test } from 'bun:test';
9
+ import { existsSync, mkdirSync, readFileSync, symlinkSync, writeFileSync } from 'node:fs';
10
+ import { join } from 'node:path';
11
+
12
+ import { createApi } from '../api.ts';
13
+ import { type Context, createBus } from '../context.ts';
14
+ import { bootServer, killProc, makeSandbox, nextPort } from './_helpers.ts';
15
+
16
+ async function createBoard(port: number, name: string, group?: string) {
17
+ const r = await fetch(`http://localhost:${port}/_api/canvas`, {
18
+ method: 'POST',
19
+ headers: { 'Content-Type': 'application/json' },
20
+ body: JSON.stringify({ name, kind: 'brief-board', group }),
21
+ });
22
+ return (await r.json()) as { file: string; rel: string; slug: string };
23
+ }
24
+
25
+ function move(port: number, file: string, toDir: string) {
26
+ return fetch(`http://localhost:${port}/_api/fs-move`, {
27
+ method: 'POST',
28
+ headers: { 'Content-Type': 'application/json' },
29
+ body: JSON.stringify({ file, toDir }),
30
+ });
31
+ }
32
+
33
+ describe('/_api/fs-move — POST round-trip', () => {
34
+ test('happy path: relocates the primary + meta into the destination dir', async () => {
35
+ const { root, designRoot } = makeSandbox();
36
+ const port = nextPort();
37
+ const proc = await bootServer(root, port);
38
+ try {
39
+ const created = await createBoard(port, 'Movable');
40
+ const r = await move(port, created.rel, 'ui/sub');
41
+ expect(r.status).toBe(200);
42
+ const j = (await r.json()) as {
43
+ ok: boolean;
44
+ fromRel: string;
45
+ toRel: string;
46
+ fromSlug: string;
47
+ toSlug: string;
48
+ moved: string[];
49
+ };
50
+ expect(j.ok).toBe(true);
51
+ expect(j.toRel).toBe('ui/sub/Movable.tsx');
52
+ expect(j.fromSlug).toBe('ui-movable');
53
+ expect(j.toSlug).toBe('ui-sub-movable');
54
+
55
+ expect(existsSync(join(designRoot, 'ui', 'Movable.tsx'))).toBe(false);
56
+ expect(existsSync(join(designRoot, 'ui', 'sub', 'Movable.tsx'))).toBe(true);
57
+ expect(existsSync(join(designRoot, 'ui', 'sub', 'Movable.meta.json'))).toBe(true);
58
+ } finally {
59
+ await killProc(proc);
60
+ }
61
+ });
62
+
63
+ test('full re-key: history, canvas-state view, comments, annotations, locator all follow the move', async () => {
64
+ const { root, designRoot } = makeSandbox();
65
+ const port = nextPort();
66
+ const proc = await bootServer(root, port);
67
+ try {
68
+ const created = await createBoard(port, 'Full Rekey');
69
+ const fromSlug = created.slug; // 'ui-full_rekey'
70
+
71
+ mkdirSync(join(designRoot, '_history', fromSlug), { recursive: true });
72
+ writeFileSync(join(designRoot, '_history', fromSlug, 'snap.json'), '{}');
73
+ mkdirSync(join(designRoot, '_canvas-state'), { recursive: true });
74
+ writeFileSync(
75
+ join(designRoot, '_canvas-state', `${fromSlug}.view.json`),
76
+ JSON.stringify({ viewport: { x: 1, y: 2, scale: 1 } })
77
+ );
78
+ mkdirSync(join(designRoot, '_comments'), { recursive: true });
79
+ writeFileSync(join(designRoot, '_comments', `${fromSlug}.json`), '[]');
80
+ writeFileSync(
81
+ join(designRoot, `${fromSlug}.annotations.svg`),
82
+ '<svg xmlns="http://www.w3.org/2000/svg" data-mdcc-annotations="1"></svg>'
83
+ );
84
+ const locatorAbs = join(designRoot, '_locator.json');
85
+ const locatorKey = 'ui/Full Rekey'; // locatorKeyFor shape: posix, ext-less, NOT slugified
86
+ writeFileSync(
87
+ locatorAbs,
88
+ JSON.stringify({
89
+ [locatorKey]: {
90
+ a1b2c3d4: { canvas: '/x', line: 1, col: 0, jsxPath: [], componentName: '' },
91
+ },
92
+ })
93
+ );
94
+
95
+ const r = await move(port, created.rel, 'ui/nested');
96
+ expect(r.status).toBe(200);
97
+ const j = (await r.json()) as { toSlug: string };
98
+ const toSlug = j.toSlug; // 'ui-nested-full_rekey'
99
+
100
+ expect(existsSync(join(designRoot, '_history', toSlug, 'snap.json'))).toBe(true);
101
+ expect(existsSync(join(designRoot, '_history', fromSlug))).toBe(false);
102
+ expect(existsSync(join(designRoot, '_canvas-state', `${toSlug}.view.json`))).toBe(true);
103
+ expect(existsSync(join(designRoot, '_canvas-state', `${fromSlug}.view.json`))).toBe(false);
104
+ expect(existsSync(join(designRoot, '_comments', `${toSlug}.json`))).toBe(true);
105
+ expect(existsSync(join(designRoot, `${toSlug}.annotations.svg`))).toBe(true);
106
+ expect(existsSync(join(designRoot, `${fromSlug}.annotations.svg`))).toBe(false);
107
+
108
+ const locator = JSON.parse(readFileSync(locatorAbs, 'utf8'));
109
+ expect(locator['ui/nested/Full Rekey']).toBeDefined();
110
+ expect(locator[locatorKey]).toBeUndefined();
111
+
112
+ // Forensic log for the non-atomic move.
113
+ expect(existsSync(join(designRoot, '_history', toSlug, '_move.json'))).toBe(true);
114
+ } finally {
115
+ await killProc(proc);
116
+ }
117
+ });
118
+
119
+ test('containment: a toDir escaping the design root is rejected (400), nothing moved', async () => {
120
+ const { root, designRoot } = makeSandbox();
121
+ const port = nextPort();
122
+ const proc = await bootServer(root, port);
123
+ try {
124
+ const created = await createBoard(port, 'Contained');
125
+ const r = await move(port, created.rel, '../../../../tmp');
126
+ expect(r.status).toBe(400);
127
+ expect(existsSync(join(designRoot, 'ui', 'Contained.tsx'))).toBe(true);
128
+ } finally {
129
+ await killProc(proc);
130
+ }
131
+ });
132
+
133
+ test('refuses moving a design-system canvas (400, untouched)', async () => {
134
+ const { root, designRoot } = makeSandbox();
135
+ const port = nextPort();
136
+ const proc = await bootServer(root, port);
137
+ try {
138
+ mkdirSync(join(designRoot, 'system', 'project'), { recursive: true });
139
+ const dsFile = join(designRoot, 'system', 'project', 'Spec.tsx');
140
+ writeFileSync(dsFile, 'export default function S(){return null}');
141
+ const r = await move(port, '.design/system/project/Spec.tsx', 'ui');
142
+ expect(r.status).toBe(400);
143
+ expect(existsSync(dsFile)).toBe(true);
144
+ } finally {
145
+ await killProc(proc);
146
+ }
147
+ });
148
+
149
+ test('refuses moving INTO the design-system group (400, untouched)', async () => {
150
+ const { root, designRoot } = makeSandbox();
151
+ const port = nextPort();
152
+ const proc = await bootServer(root, port);
153
+ try {
154
+ const created = await createBoard(port, 'Into DS');
155
+ const r = await move(port, created.rel, 'system/project');
156
+ expect(r.status).toBe(400);
157
+ expect(existsSync(join(designRoot, 'ui', 'Into DS.tsx'))).toBe(true);
158
+ } finally {
159
+ await killProc(proc);
160
+ }
161
+ });
162
+
163
+ test('a name collision at the destination returns 409, nothing moved', async () => {
164
+ const { root, designRoot } = makeSandbox();
165
+ const port = nextPort();
166
+ const proc = await bootServer(root, port);
167
+ try {
168
+ const created = await createBoard(port, 'Dup');
169
+ mkdirSync(join(designRoot, 'ui', 'sub'), { recursive: true });
170
+ writeFileSync(
171
+ join(designRoot, 'ui', 'sub', 'Dup.tsx'),
172
+ 'export default function D(){return null}'
173
+ );
174
+ const r = await move(port, created.rel, 'ui/sub');
175
+ expect(r.status).toBe(409);
176
+ expect(existsSync(join(designRoot, 'ui', 'Dup.tsx'))).toBe(true);
177
+ } finally {
178
+ await killProc(proc);
179
+ }
180
+ });
181
+
182
+ test('a no-op move (same dir) is rejected with 400', async () => {
183
+ const { root } = makeSandbox();
184
+ const port = nextPort();
185
+ const proc = await bootServer(root, port);
186
+ try {
187
+ const created = await createBoard(port, 'Same Dir');
188
+ const r = await move(port, created.rel, 'ui');
189
+ expect(r.status).toBe(400);
190
+ } finally {
191
+ await killProc(proc);
192
+ }
193
+ });
194
+
195
+ test('a missing source canvas returns 404', async () => {
196
+ const { root } = makeSandbox();
197
+ const port = nextPort();
198
+ const proc = await bootServer(root, port);
199
+ try {
200
+ const r = await move(port, 'ui/Nope.tsx', 'ui/sub');
201
+ expect(r.status).toBe(404);
202
+ } finally {
203
+ await killProc(proc);
204
+ }
205
+ });
206
+
207
+ test('emits a canvas-list-update "moved" action over the inspector WS', async () => {
208
+ const { root } = makeSandbox();
209
+ const port = nextPort();
210
+ const proc = await bootServer(root, port);
211
+ let socket: WebSocket | null = null;
212
+ try {
213
+ const messages: Array<{ type: string; payload?: Record<string, unknown> }> = [];
214
+ const sock = new WebSocket(`ws://localhost:${port}/_ws`);
215
+ socket = sock;
216
+ await new Promise<void>((res, rej) => {
217
+ sock.addEventListener('open', () => res());
218
+ sock.addEventListener('error', () => rej(new Error('ws error')));
219
+ setTimeout(() => rej(new Error('ws open timeout')), 2000);
220
+ });
221
+ sock.addEventListener('message', (ev) => {
222
+ try {
223
+ messages.push(JSON.parse(String(ev.data)));
224
+ } catch {
225
+ /* ignore */
226
+ }
227
+ });
228
+ const created = await createBoard(port, 'Live Move');
229
+ const r = await move(port, created.rel, 'ui/sub');
230
+ expect(r.status).toBe(200);
231
+
232
+ const deadline = Date.now() + 2000;
233
+ let hit: (typeof messages)[number] | undefined;
234
+ while (Date.now() < deadline && !hit) {
235
+ hit = messages.find(
236
+ (m) => m.type === 'canvas-list-update' && m.payload?.action === 'moved'
237
+ );
238
+ if (!hit) await Bun.sleep(25);
239
+ }
240
+ expect(hit?.payload?.toSlug ?? hit?.payload?.slug).toBeTruthy();
241
+ expect(hit?.payload?.fromSlug).toBe('ui-live_move');
242
+ } finally {
243
+ try {
244
+ socket?.close();
245
+ } catch {
246
+ /* ignore */
247
+ }
248
+ await killProc(proc);
249
+ }
250
+ }, 10_000);
251
+
252
+ test('unknown method (GET) returns 405', async () => {
253
+ const { root } = makeSandbox();
254
+ const port = nextPort();
255
+ const proc = await bootServer(root, port);
256
+ try {
257
+ const r = await fetch(`http://localhost:${port}/_api/fs-move`, { method: 'GET' });
258
+ expect(r.status).toBe(405);
259
+ } finally {
260
+ await killProc(proc);
261
+ }
262
+ });
263
+
264
+ test('rejects a cross-origin move (CSRF guard)', async () => {
265
+ const { root } = makeSandbox();
266
+ const port = nextPort();
267
+ const proc = await bootServer(root, port);
268
+ try {
269
+ const created = await createBoard(port, 'Forge Move');
270
+ const r = await fetch(`http://localhost:${port}/_api/fs-move`, {
271
+ method: 'POST',
272
+ headers: { 'Content-Type': 'application/json', Origin: 'http://evil.example' },
273
+ body: JSON.stringify({ file: created.rel, toDir: 'ui/sub' }),
274
+ });
275
+ expect(r.status).toBe(403);
276
+ } finally {
277
+ await killProc(proc);
278
+ }
279
+ });
280
+ });
281
+
282
+ // Security review finding: canvasSlugFromRel's `/`→`-` flattening is not
283
+ // injective — "ui/a-b.tsx" and "ui/a/b.tsx" both hash to slug "ui-a-b". A
284
+ // move that creates this collision would, pre-fix, silently clobber the
285
+ // OTHER canvas's history/comments/annotations the moment the primary rename
286
+ // landed. moveCanvas/moveFolder now refuse with 409 via fileForSlug().
287
+ // Security review finding: `path.resolve()`-only containment does not follow
288
+ // symlinks. A symlink planted inside a canvas group (malicious git peer, hub
289
+ // sync, or accident) pointing outside designRoot passed every pre-fix
290
+ // containment check while rename()/mkdir() followed it at the OS level.
291
+ describe('/_api/fs-move — symlink escape guard (security review finding)', () => {
292
+ test('refuses moving a canvas INTO a symlinked destination folder', async () => {
293
+ const { root, designRoot } = makeSandbox();
294
+ const outside = join(root, 'OUTSIDE');
295
+ mkdirSync(outside, { recursive: true });
296
+ const port = nextPort();
297
+ const proc = await bootServer(root, port);
298
+ try {
299
+ const created = await createBoard(port, 'Escapee');
300
+ symlinkSync(outside, join(designRoot, 'ui', 'link'));
301
+ const r = await move(port, created.rel, 'ui/link');
302
+ expect(r.status).toBe(400);
303
+ expect(existsSync(join(outside, 'Escapee.tsx'))).toBe(false);
304
+ expect(existsSync(join(designRoot, 'ui', 'Escapee.tsx'))).toBe(true);
305
+ } finally {
306
+ await killProc(proc);
307
+ }
308
+ });
309
+
310
+ test('refuses moving a symlinked FOLDER as the source', async () => {
311
+ const { root, designRoot } = makeSandbox();
312
+ const outside = join(root, 'OUTSIDE');
313
+ mkdirSync(outside, { recursive: true });
314
+ writeFileSync(join(outside, 'Secret.tsx'), 'export default function S(){return null}');
315
+ const port = nextPort();
316
+ const proc = await bootServer(root, port);
317
+ try {
318
+ symlinkSync(outside, join(designRoot, 'ui', 'evil'));
319
+ const r = await move(port, 'ui/evil', 'ui/dest');
320
+ expect(r.status).toBe(400);
321
+ expect(existsSync(join(designRoot, 'ui', 'dest'))).toBe(false);
322
+ } finally {
323
+ await killProc(proc);
324
+ }
325
+ });
326
+ });
327
+
328
+ describe('/_api/fs-move — slug-collision guard (security review finding)', () => {
329
+ test('refuses a move whose destination slug collides with an existing DIFFERENT canvas', async () => {
330
+ const { root, designRoot } = makeSandbox();
331
+ const port = nextPort();
332
+ const proc = await bootServer(root, port);
333
+ try {
334
+ // Victim: ui/a-b.tsx -> slug "ui-a-b". Give it a real annotations
335
+ // sidecar so a silent clobber would be observable.
336
+ const victim = await createBoard(port, 'a-b');
337
+ expect(victim.slug).toBe('ui-a-b');
338
+ writeFileSync(join(designRoot, `${victim.slug}.annotations.svg`), '<svg>VICTIM</svg>');
339
+
340
+ // Mover: ui/b.tsx, about to move into ui/a/ -> would become
341
+ // ui/a/b.tsx -> slug "ui-a-b" too.
342
+ const mover = await createBoard(port, 'b');
343
+ const r = await move(port, mover.rel, 'ui/a');
344
+ expect(r.status).toBe(409);
345
+ const j = (await r.json()) as { error: string };
346
+ expect(j.error).toContain('ui-a-b');
347
+
348
+ // Nothing moved; the victim's sidecar is untouched.
349
+ expect(existsSync(join(designRoot, 'ui', 'b.tsx'))).toBe(true);
350
+ expect(existsSync(join(designRoot, 'ui', 'a', 'b.tsx'))).toBe(false);
351
+ expect(readFileSync(join(designRoot, `${victim.slug}.annotations.svg`), 'utf8')).toBe(
352
+ '<svg>VICTIM</svg>'
353
+ );
354
+ } finally {
355
+ await killProc(proc);
356
+ }
357
+ });
358
+
359
+ test('a folder move refuses when a nested canvas would collide with an OUTSIDE canvas', async () => {
360
+ const { root, designRoot } = makeSandbox();
361
+ const port = nextPort();
362
+ const proc = await bootServer(root, port);
363
+ try {
364
+ // A folder move preserves the moved folder's OWN basename as a path
365
+ // segment, so to collide with "ui/dest-sub-inner.tsx" (slug
366
+ // "ui-dest-sub-inner"), move folder "ui/sub" (containing "inner.tsx")
367
+ // into "ui/dest" -> "ui/dest/sub/inner.tsx" -> same slug.
368
+ const victim = await createBoard(port, 'dest-sub-inner');
369
+ expect(victim.slug).toBe('ui-dest-sub-inner');
370
+
371
+ await createBoard(port, 'inner');
372
+ const moveIntoSub = await move(port, 'ui/inner.tsx', 'ui/sub');
373
+ expect(moveIntoSub.status).toBe(200);
374
+
375
+ const r = await move(port, 'ui/sub', 'ui/dest');
376
+ expect(r.status).toBe(409);
377
+ expect(existsSync(join(designRoot, 'ui', 'sub'))).toBe(true);
378
+ expect(existsSync(join(designRoot, 'ui', 'dest', 'sub'))).toBe(false);
379
+ } finally {
380
+ await killProc(proc);
381
+ }
382
+ });
383
+
384
+ test('does NOT refuse when the "collision" is the canvas moving into its OWN new slug (no-op false positive)', async () => {
385
+ const { root } = makeSandbox();
386
+ const port = nextPort();
387
+ const proc = await bootServer(root, port);
388
+ try {
389
+ const created = await createBoard(port, 'Solo');
390
+ const r = await move(port, created.rel, 'ui/sub');
391
+ expect(r.status).toBe(200);
392
+ } finally {
393
+ await killProc(proc);
394
+ }
395
+ });
396
+ });
397
+
398
+ describe('/_api/fs-move — folder move (Task 11)', () => {
399
+ test('moving a folder relocates every nested canvas + its sidecars', async () => {
400
+ const { root, designRoot } = makeSandbox();
401
+ const port = nextPort();
402
+ const proc = await bootServer(root, port);
403
+ try {
404
+ await createBoard(port, 'One', 'ui');
405
+ const r1 = await move(port, 'ui/One.tsx', 'ui/Src');
406
+ expect(r1.status).toBe(200);
407
+ await createBoard(port, 'Two', 'ui');
408
+ const r2 = await move(port, 'ui/Two.tsx', 'ui/Src');
409
+ expect(r2.status).toBe(200);
410
+ // Seed a history sidecar for One to prove slug-keyed sidecars follow too.
411
+ mkdirSync(join(designRoot, '_history', 'ui-src-one'), { recursive: true });
412
+ writeFileSync(join(designRoot, '_history', 'ui-src-one', 'snap.json'), '{}');
413
+
414
+ const r = await move(port, 'ui/Src', 'ui/Dest');
415
+ expect(r.status).toBe(200);
416
+ const j = (await r.json()) as { ok: boolean; toRel: string; moved: string[] };
417
+ expect(j.ok).toBe(true);
418
+ expect(j.toRel).toBe('ui/Dest/Src');
419
+
420
+ expect(existsSync(join(designRoot, 'ui', 'Src'))).toBe(false);
421
+ expect(existsSync(join(designRoot, 'ui', 'Dest', 'Src', 'One.tsx'))).toBe(true);
422
+ expect(existsSync(join(designRoot, 'ui', 'Dest', 'Src', 'Two.tsx'))).toBe(true);
423
+ expect(existsSync(join(designRoot, '_history', 'ui-dest-src-one', 'snap.json'))).toBe(true);
424
+ expect(existsSync(join(designRoot, '_history', 'ui-src-one'))).toBe(false);
425
+ } finally {
426
+ await killProc(proc);
427
+ }
428
+ });
429
+
430
+ test('refuses moving a folder into itself or a descendant (400)', async () => {
431
+ const { root, designRoot } = makeSandbox();
432
+ const port = nextPort();
433
+ const proc = await bootServer(root, port);
434
+ try {
435
+ mkdirSync(join(designRoot, 'ui', 'Parent', 'Child'), { recursive: true });
436
+ const intoSelf = await move(port, 'ui/Parent', 'ui/Parent');
437
+ expect(intoSelf.status).toBe(400);
438
+ const intoChild = await move(port, 'ui/Parent', 'ui/Parent/Child');
439
+ expect(intoChild.status).toBe(400);
440
+ expect(existsSync(join(designRoot, 'ui', 'Parent', 'Child'))).toBe(true);
441
+ } finally {
442
+ await killProc(proc);
443
+ }
444
+ });
445
+
446
+ test('refuses moving a canvas GROUP ROOT (not a user-created folder) (400)', async () => {
447
+ const { root } = makeSandbox();
448
+ const port = nextPort();
449
+ const proc = await bootServer(root, port);
450
+ try {
451
+ const r = await move(port, 'ui', 'system');
452
+ expect(r.status).toBe(400);
453
+ } finally {
454
+ await killProc(proc);
455
+ }
456
+ });
457
+
458
+ test('a missing source folder returns 404', async () => {
459
+ const { root } = makeSandbox();
460
+ const port = nextPort();
461
+ const proc = await bootServer(root, port);
462
+ try {
463
+ const r = await move(port, 'ui/Nope', 'ui/Dest');
464
+ expect(r.status).toBe(404);
465
+ } finally {
466
+ await killProc(proc);
467
+ }
468
+ });
469
+
470
+ test('a destination collision returns 409, nothing moved', async () => {
471
+ const { root, designRoot } = makeSandbox();
472
+ const port = nextPort();
473
+ const proc = await bootServer(root, port);
474
+ try {
475
+ mkdirSync(join(designRoot, 'ui', 'Src'), { recursive: true });
476
+ mkdirSync(join(designRoot, 'ui', 'Dest', 'Src'), { recursive: true });
477
+ const r = await move(port, 'ui/Src', 'ui/Dest');
478
+ expect(r.status).toBe(409);
479
+ expect(existsSync(join(designRoot, 'ui', 'Src'))).toBe(true);
480
+ } finally {
481
+ await killProc(proc);
482
+ }
483
+ });
484
+ });
485
+
486
+ // In-process: the collab-pin guard. Reaching a REAL pinned room requires the
487
+ // MAUDE_SHARED_DOC sync runtime; exercising the guard through api.moveCanvas
488
+ // directly with a stub `isRoomPinned` hook proves the refusal wiring without
489
+ // standing up the whole shared-doc machinery.
490
+ describe('moveCanvas — collab-pin guard (in-process)', () => {
491
+ function mkCtx(root: string, designRoot: string): Context {
492
+ return {
493
+ cfg: {
494
+ canvasGroups: [
495
+ { label: 'Design system', path: 'system' },
496
+ { label: 'Canvases', path: 'ui' },
497
+ ],
498
+ } as Context['cfg'],
499
+ projectLabel: 'test',
500
+ bus: createBus(),
501
+ paths: {
502
+ repoRoot: root,
503
+ designRel: '.design',
504
+ designRoot,
505
+ serverInfoFile: join(designRoot, '_server.json'),
506
+ activeFile: join(designRoot, '_active.json'),
507
+ commentsDir: join(designRoot, '_comments'),
508
+ canvasStateDir: join(designRoot, '_canvas-state'),
509
+ historyDir: join(designRoot, '_history'),
510
+ tokensUrlRel: '',
511
+ systemDirRel: 'system',
512
+ },
513
+ };
514
+ }
515
+
516
+ test('refuses the move (409) when the slug is pinned, and does not touch disk', async () => {
517
+ const { root, designRoot } = makeSandbox();
518
+ const abs = join(designRoot, 'ui', 'Pinned.tsx');
519
+ mkdirSync(join(designRoot, 'ui'), { recursive: true });
520
+ writeFileSync(abs, 'export default function P(){return null}');
521
+ const ctx = mkCtx(root, designRoot);
522
+ const api = createApi(ctx, {
523
+ onCommentsChanged: () => {},
524
+ isRoomPinned: (slug) => slug === 'ui-pinned',
525
+ flushAndDropRoom: async () => {
526
+ throw new Error('must not be called when pinned');
527
+ },
528
+ });
529
+
530
+ const result = await api.moveCanvas({ file: 'ui/Pinned.tsx', toDir: 'ui/sub' });
531
+ expect(result.ok).toBe(false);
532
+ if (!result.ok) expect(result.status).toBe(409);
533
+ expect(existsSync(abs)).toBe(true);
534
+ });
535
+
536
+ test('calls flushAndDropRoom when NOT pinned', async () => {
537
+ const { root, designRoot } = makeSandbox();
538
+ const abs = join(designRoot, 'ui', 'Unpinned.tsx');
539
+ mkdirSync(join(designRoot, 'ui'), { recursive: true });
540
+ writeFileSync(abs, 'export default function U(){return null}');
541
+ const ctx = mkCtx(root, designRoot);
542
+ let flushed = false;
543
+ const api = createApi(ctx, {
544
+ onCommentsChanged: () => {},
545
+ isRoomPinned: () => false,
546
+ flushAndDropRoom: async (slug) => {
547
+ expect(slug).toBe('ui-unpinned');
548
+ flushed = true;
549
+ },
550
+ });
551
+
552
+ const result = await api.moveCanvas({ file: 'ui/Unpinned.tsx', toDir: 'ui/sub' });
553
+ expect(result.ok).toBe(true);
554
+ expect(flushed).toBe(true);
555
+ });
556
+ });
@@ -77,6 +77,12 @@ describe('canvas-origin gate — A1/A2 traversal + privilege containment', () =>
77
77
  '/_api/export-jobs',
78
78
  '/_api/export-jobs/download',
79
79
  '/_api/canvas',
80
+ // feature-file-tree-drag-drop-folders (Task 5) — move/mkdir are
81
+ // file-write routes, same MAIN-ORIGIN-ONLY posture as /_api/canvas
82
+ // right above: absent from CANVAS_SAFE_API + startCanvasServer's
83
+ // routes, so a GET here 403s at the gate, not 405 from the handler.
84
+ '/_api/fs-move',
85
+ '/_api/fs-mkdir',
80
86
  '/_api/edit-css',
81
87
  '/_api/edit-text',
82
88
  '/_api/edit-attr',