@1agh/maude 0.54.0 → 0.56.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.
- package/apps/studio/annotations-layer.tsx +11 -1
- package/apps/studio/bin/_smart-frames.mjs +187 -20
- package/apps/studio/bin/_smart-frames.test.mjs +59 -4
- package/apps/studio/bin/_transcribe.mjs +40 -3
- package/apps/studio/bin/smoke.sh +7 -1
- package/apps/studio/canvas-build-sandbox.ts +101 -9
- package/apps/studio/canvas-build-worker.ts +7 -1
- package/apps/studio/canvas-build.ts +9 -1
- package/apps/studio/client/app.jsx +49 -3
- package/apps/studio/client/github.js +7 -0
- package/apps/studio/client/panels/CloudBar.jsx +505 -45
- package/apps/studio/client/panels/GitPanel.jsx +38 -25
- package/apps/studio/client/panels/SettingsPanel.jsx +239 -27
- package/apps/studio/client/styles/3-shell-maude.css +30 -0
- package/apps/studio/client/styles/4-components.css +72 -0
- package/apps/studio/cloud/endpoints.ts +104 -9
- package/apps/studio/collab/persistence.ts +29 -2
- package/apps/studio/config.schema.json +3 -3
- package/apps/studio/context.ts +41 -0
- package/apps/studio/dist/client.bundle.js +1545 -1545
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/generation/gemma-models.ts +312 -14
- package/apps/studio/generation/prefs.ts +7 -2
- package/apps/studio/generation/runtime-probe.ts +50 -0
- package/apps/studio/generation/whisper-models.ts +124 -0
- package/apps/studio/hmr-broadcast.ts +67 -0
- package/apps/studio/http.ts +210 -110
- package/apps/studio/input-router.tsx +55 -2
- package/apps/studio/server.ts +11 -9
- package/apps/studio/sync/autocommit.ts +61 -2
- package/apps/studio/sync/cell-pairing.ts +174 -0
- package/apps/studio/sync/codec.ts +11 -5
- package/apps/studio/sync/index.ts +239 -26
- package/apps/studio/sync/limits.ts +49 -0
- package/apps/studio/sync/loopback.ts +21 -0
- package/apps/studio/sync/projection.ts +47 -12
- package/apps/studio/sync/supervisor.ts +178 -0
- package/apps/studio/test/cloud-endpoints.test.ts +326 -4
- package/apps/studio/test/csrf-write-guard.test.ts +19 -2
- package/apps/studio/test/gemma-models.test.ts +245 -0
- package/apps/studio/test/hmr-broadcast.test.ts +57 -1
- package/apps/studio/test/input-router.test.ts +95 -0
- package/apps/studio/test/shared-doc-cell-pairing.test.ts +639 -0
- package/apps/studio/test/sync-autocommit.test.ts +47 -0
- package/apps/studio/test/sync-supervisor.test.ts +212 -0
- package/apps/studio/test/trusted-request-host.test.ts +66 -0
- package/apps/studio/test/whisper-setup.test.ts +97 -0
- package/apps/studio/whats-new.json +45 -0
- package/apps/studio/ws.ts +9 -1
- package/cli/commands/kg.mjs +9 -2
- package/package.json +8 -8
- package/plugins/design/dependencies.json +21 -3
|
@@ -0,0 +1,639 @@
|
|
|
1
|
+
// Desktop ↔ cloud live pairing (variant C2) — the invariant suite.
|
|
2
|
+
//
|
|
3
|
+
// This is the gate the feature is allowed through, and it is written against
|
|
4
|
+
// the two decisions it threads rather than against its own implementation:
|
|
5
|
+
//
|
|
6
|
+
// DDR-209 a cell does not dial out, and the hub is the sole committer;
|
|
7
|
+
// DDR-064 one shared Y.Doc per canvas, disk is a projection of it.
|
|
8
|
+
//
|
|
9
|
+
// So the tests here are not "does the code do what the code does". They are:
|
|
10
|
+
// can a cell be made to talk to anything but itself (no); can a second
|
|
11
|
+
// committer appear (no); do the browser's doc and the desktop's doc become one
|
|
12
|
+
// (yes); does a first connect between two non-empty sides duplicate anything
|
|
13
|
+
// (no); does one edit produce one reload (yes).
|
|
14
|
+
//
|
|
15
|
+
// The convergence LAWS themselves live in `shared-doc-convergence.test.ts` and
|
|
16
|
+
// are not repeated — this suite covers the cell TOPOLOGY on top of them.
|
|
17
|
+
|
|
18
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
19
|
+
import { execFileSync } from 'node:child_process';
|
|
20
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
21
|
+
import { tmpdir } from 'node:os';
|
|
22
|
+
import { join } from 'node:path';
|
|
23
|
+
import { Awareness } from 'y-protocols/awareness';
|
|
24
|
+
import * as Y from 'yjs';
|
|
25
|
+
|
|
26
|
+
import { Y_TYPES } from '../collab/persistence.ts';
|
|
27
|
+
import { createRegistry } from '../collab/registry.ts';
|
|
28
|
+
import type { RoomCallbacks } from '../collab/room.ts';
|
|
29
|
+
import type { Context, DevServerConfig } from '../context.ts';
|
|
30
|
+
import { createBus } from '../context.ts';
|
|
31
|
+
import { resolveCellPairing } from '../sync/cell-pairing.ts';
|
|
32
|
+
import { applyCommentsToDoc, Y_SYNC_TYPES } from '../sync/codec.ts';
|
|
33
|
+
import {
|
|
34
|
+
admitCanvases,
|
|
35
|
+
type CanvasDescriptor,
|
|
36
|
+
createSyncRuntime,
|
|
37
|
+
DEFAULT_MAX_PINNED_ROOMS,
|
|
38
|
+
type SyncProvider,
|
|
39
|
+
} from '../sync/index.ts';
|
|
40
|
+
import { migrateSeed } from '../sync/migrate-seed.ts';
|
|
41
|
+
|
|
42
|
+
const LOOPBACK = 'http://127.0.0.1:1234';
|
|
43
|
+
|
|
44
|
+
/** The full, valid pairing environment. Tests mutate ONE key at a time from
|
|
45
|
+
* here, so a test that passes for the wrong reason is hard to write. */
|
|
46
|
+
function pairingEnv(over: Record<string, string | undefined> = {}) {
|
|
47
|
+
return {
|
|
48
|
+
MAUDE_WORKSPACE_MODE: '1',
|
|
49
|
+
MAUDE_CELL_PAIRING: '1',
|
|
50
|
+
MAUDE_LOOPBACK_SYNC_URL: LOOPBACK,
|
|
51
|
+
MAUDE_LOOPBACK_SYNC_TOKEN: 'cell-token',
|
|
52
|
+
MAUDE_SYNC_NO_AUTOCOMMIT: '1',
|
|
53
|
+
MAUDE_SHARED_DOC: '1',
|
|
54
|
+
...over,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
let dir: string;
|
|
59
|
+
const SAVED_ENV_KEYS = [
|
|
60
|
+
'MAUDE_WORKSPACE_MODE',
|
|
61
|
+
'MAUDE_CELL_PAIRING',
|
|
62
|
+
'MAUDE_LOOPBACK_SYNC_URL',
|
|
63
|
+
'MAUDE_LOOPBACK_SYNC_TOKEN',
|
|
64
|
+
'MAUDE_SYNC_NO_AUTOCOMMIT',
|
|
65
|
+
'MAUDE_SHARED_DOC',
|
|
66
|
+
'MAUDE_MAX_PINNED_ROOMS',
|
|
67
|
+
'HUBS_CONFIG_PATH',
|
|
68
|
+
] as const;
|
|
69
|
+
let saved: Record<string, string | undefined>;
|
|
70
|
+
|
|
71
|
+
beforeEach(() => {
|
|
72
|
+
dir = mkdtempSync(join(tmpdir(), 'cell-pairing-'));
|
|
73
|
+
saved = {};
|
|
74
|
+
for (const k of SAVED_ENV_KEYS) saved[k] = process.env[k];
|
|
75
|
+
// A cell has no `~/.config/maude/hubs.json`; point the reader at a path that
|
|
76
|
+
// does not exist so a stray person-credential can never satisfy a test.
|
|
77
|
+
process.env.HUBS_CONFIG_PATH = join(dir, 'absent-hubs.json');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
afterEach(() => {
|
|
81
|
+
for (const k of SAVED_ENV_KEYS) {
|
|
82
|
+
// Assigning `undefined` stringifies to "undefined"; delete is the restore.
|
|
83
|
+
if (saved[k] === undefined) delete process.env[k];
|
|
84
|
+
else process.env[k] = saved[k];
|
|
85
|
+
}
|
|
86
|
+
rmSync(dir, { recursive: true, force: true });
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
/** Install a pairing environment for the duration of one test. */
|
|
90
|
+
function setEnv(env: Record<string, string | undefined>): void {
|
|
91
|
+
for (const k of SAVED_ENV_KEYS) delete process.env[k];
|
|
92
|
+
process.env.HUBS_CONFIG_PATH = join(dir, 'absent-hubs.json');
|
|
93
|
+
for (const [k, v] of Object.entries(env)) {
|
|
94
|
+
if (v !== undefined) process.env[k] = v;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function makeCtx(linkedHub?: DevServerConfig['linkedHub'], repoRoot = dir): Context {
|
|
99
|
+
const designRoot = join(repoRoot, 'design');
|
|
100
|
+
mkdirSync(join(designRoot, 'ui'), { recursive: true });
|
|
101
|
+
mkdirSync(join(designRoot, '_comments'), { recursive: true });
|
|
102
|
+
return {
|
|
103
|
+
// The Lock-2 sandbox, so `.tsx` bodies are admitted to sync (DDR-060).
|
|
104
|
+
canvasOrigin: 'http://canvas.localhost',
|
|
105
|
+
sharedDoc: true,
|
|
106
|
+
cfg: {
|
|
107
|
+
name: 'test',
|
|
108
|
+
projectLabel: null,
|
|
109
|
+
designRoot: 'design',
|
|
110
|
+
canvasGroups: [{ label: 'Canvases', path: 'ui' }],
|
|
111
|
+
rootClass: 'app',
|
|
112
|
+
themeDefault: 'dark',
|
|
113
|
+
tokensCssRel: 'system/colors.css',
|
|
114
|
+
teamAccentDefault: null,
|
|
115
|
+
handoffTargets: [],
|
|
116
|
+
newCanvasDir: 'ui',
|
|
117
|
+
newComponentDir: 'ui/components',
|
|
118
|
+
linkedHub,
|
|
119
|
+
_source: 'defaults',
|
|
120
|
+
},
|
|
121
|
+
projectLabel: 'test',
|
|
122
|
+
paths: {
|
|
123
|
+
repoRoot,
|
|
124
|
+
designRel: 'design',
|
|
125
|
+
designRoot,
|
|
126
|
+
serverInfoFile: join(designRoot, '_server.json'),
|
|
127
|
+
activeFile: join(designRoot, '_active.json'),
|
|
128
|
+
commentsDir: join(designRoot, '_comments'),
|
|
129
|
+
canvasStateDir: join(designRoot, '_canvas-state'),
|
|
130
|
+
historyDir: join(designRoot, '_history'),
|
|
131
|
+
tokensUrlRel: 'design/system/colors.css',
|
|
132
|
+
systemDirRel: 'system',
|
|
133
|
+
},
|
|
134
|
+
bus: createBus(),
|
|
135
|
+
} as Context;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function noopCallbacks(): RoomCallbacks {
|
|
139
|
+
return { async seed() {}, async persistJson() {}, async persistBinary() {} };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* The cell topology in one object: the BROWSER's room doc (the registry's), the
|
|
144
|
+
* DESKTOP's doc (`peerOf`, the other end of the hub), and a record of every URL
|
|
145
|
+
* and token the runtime actually dialled.
|
|
146
|
+
*/
|
|
147
|
+
function cellHarness() {
|
|
148
|
+
const registry = createRegistry(noopCallbacks());
|
|
149
|
+
const peers = new Map<string, Y.Doc>();
|
|
150
|
+
const dialled: Array<{ url: string; token: string; documentName: string }> = [];
|
|
151
|
+
const TRANSPORT = Symbol('hub-transport');
|
|
152
|
+
|
|
153
|
+
const factory = (args: {
|
|
154
|
+
url: string;
|
|
155
|
+
token: string;
|
|
156
|
+
documentName: string;
|
|
157
|
+
document?: Y.Doc;
|
|
158
|
+
}): SyncProvider => {
|
|
159
|
+
dialled.push({ url: args.url, token: args.token, documentName: args.documentName });
|
|
160
|
+
const ownsLocal = !args.document;
|
|
161
|
+
const local = args.document ?? new Y.Doc();
|
|
162
|
+
// The desktop peer, on the far side of the hub's Hocuspocus document.
|
|
163
|
+
const desktop = new Y.Doc();
|
|
164
|
+
local.on('update', (u: Uint8Array, origin: unknown) => {
|
|
165
|
+
if (origin === TRANSPORT) return;
|
|
166
|
+
Y.applyUpdate(desktop, u, TRANSPORT);
|
|
167
|
+
});
|
|
168
|
+
desktop.on('update', (u: Uint8Array, origin: unknown) => {
|
|
169
|
+
if (origin === TRANSPORT) return;
|
|
170
|
+
Y.applyUpdate(local, u, TRANSPORT);
|
|
171
|
+
});
|
|
172
|
+
peers.set(args.documentName, desktop);
|
|
173
|
+
return {
|
|
174
|
+
document: local,
|
|
175
|
+
awareness: new Awareness(local),
|
|
176
|
+
async onceSynced() {},
|
|
177
|
+
destroy() {
|
|
178
|
+
if (ownsLocal) local.destroy();
|
|
179
|
+
desktop.destroy();
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
registry,
|
|
186
|
+
factory,
|
|
187
|
+
dialled,
|
|
188
|
+
/** The doc the DESKTOP app holds for this canvas. */
|
|
189
|
+
desktopDoc: (documentName: string) => {
|
|
190
|
+
const d = peers.get(documentName);
|
|
191
|
+
if (!d) throw new Error(`no provider for ${documentName}`);
|
|
192
|
+
return d;
|
|
193
|
+
},
|
|
194
|
+
/** The doc the BROWSER's collab room holds for this canvas. */
|
|
195
|
+
browserDoc: (slug: string) => registry.getDoc(slug),
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/* ------------------------------------------------------- Task 1: the guard */
|
|
200
|
+
|
|
201
|
+
describe('Task 1 — the workspace-mode guard opens only for loopback + commit-disabled', () => {
|
|
202
|
+
test('the full, valid environment resolves a pairing', () => {
|
|
203
|
+
const { pairing, refusal } = resolveCellPairing(pairingEnv());
|
|
204
|
+
expect(refusal).toBeUndefined();
|
|
205
|
+
expect(pairing).toEqual({ url: LOOPBACK, token: 'cell-token' });
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
test.each([
|
|
209
|
+
['localhost', 'http://localhost:1234'],
|
|
210
|
+
['127.0.0.1', 'http://127.0.0.1:9999'],
|
|
211
|
+
['[::1]', 'http://[::1]:1234'],
|
|
212
|
+
])('accepts the loopback host %s', (_label, url) => {
|
|
213
|
+
expect(resolveCellPairing(pairingEnv({ MAUDE_LOOPBACK_SYNC_URL: url })).pairing).not.toBeNull();
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test.each([
|
|
217
|
+
['a public hub', 'https://hub.example.com'],
|
|
218
|
+
['a LAN address that merely looks local', 'http://192.168.1.10:1234'],
|
|
219
|
+
['a host whose NAME contains localhost', 'https://localhost.evil.example.com'],
|
|
220
|
+
['a private-range address', 'http://10.0.0.5:1234'],
|
|
221
|
+
['not a URL at all', 'hub.example.com'],
|
|
222
|
+
])('refuses %s — a cell syncs to itself or to nothing', (_label, url) => {
|
|
223
|
+
const { pairing, refusal, detail } = resolveCellPairing(
|
|
224
|
+
pairingEnv({ MAUDE_LOOPBACK_SYNC_URL: url })
|
|
225
|
+
);
|
|
226
|
+
expect(pairing).toBeNull();
|
|
227
|
+
expect(refusal).toBe('not-loopback');
|
|
228
|
+
// The operator asked for pairing, so the refusal is never silent.
|
|
229
|
+
expect(detail).toBeTruthy();
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test('refuses when autocommit is not explicitly disabled', () => {
|
|
233
|
+
// Absent — the default. "I forgot to set it" must not read as "it is off".
|
|
234
|
+
expect(resolveCellPairing(pairingEnv({ MAUDE_SYNC_NO_AUTOCOMMIT: undefined })).refusal).toBe(
|
|
235
|
+
'autocommit-enabled'
|
|
236
|
+
);
|
|
237
|
+
// And explicitly on.
|
|
238
|
+
expect(resolveCellPairing(pairingEnv({ MAUDE_SYNC_NO_AUTOCOMMIT: '0' })).refusal).toBe(
|
|
239
|
+
'autocommit-enabled'
|
|
240
|
+
);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
test('refuses when shared-doc is off — pairing IS the single-doc model', () => {
|
|
244
|
+
expect(resolveCellPairing(pairingEnv({ MAUDE_SHARED_DOC: undefined })).refusal).toBe(
|
|
245
|
+
'shared-doc-off'
|
|
246
|
+
);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('refuses when the token is missing', () => {
|
|
250
|
+
expect(resolveCellPairing(pairingEnv({ MAUDE_LOOPBACK_SYNC_TOKEN: '' })).refusal).toBe(
|
|
251
|
+
'no-token'
|
|
252
|
+
);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test('is inert outside workspace mode and when not requested', () => {
|
|
256
|
+
expect(resolveCellPairing(pairingEnv({ MAUDE_WORKSPACE_MODE: '0' })).refusal).toBe(
|
|
257
|
+
'not-workspace-mode'
|
|
258
|
+
);
|
|
259
|
+
expect(resolveCellPairing(pairingEnv({ MAUDE_CELL_PAIRING: undefined })).refusal).toBe(
|
|
260
|
+
'not-requested'
|
|
261
|
+
);
|
|
262
|
+
// A refusal that was never asked for gets no `detail` — nothing to say.
|
|
263
|
+
expect(
|
|
264
|
+
resolveCellPairing(pairingEnv({ MAUDE_CELL_PAIRING: undefined })).detail
|
|
265
|
+
).toBeUndefined();
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
describe('Task 1 — createSyncRuntime honours the guard', () => {
|
|
270
|
+
test('workspace + loopback + autocommit-off ⇒ the runtime starts', async () => {
|
|
271
|
+
setEnv(pairingEnv());
|
|
272
|
+
const ctx = makeCtx();
|
|
273
|
+
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.tsx'), 'export default () => null;');
|
|
274
|
+
|
|
275
|
+
const h = cellHarness();
|
|
276
|
+
const runtime = createSyncRuntime(ctx, {
|
|
277
|
+
providerFactory: h.factory,
|
|
278
|
+
registry: h.registry,
|
|
279
|
+
});
|
|
280
|
+
expect(runtime).not.toBeNull();
|
|
281
|
+
await runtime?.start();
|
|
282
|
+
expect(runtime?.size()).toBe(1);
|
|
283
|
+
await runtime?.stop();
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
test('workspace + a non-loopback linkedHub in the TENANT config ⇒ still null', () => {
|
|
287
|
+
// No pairing env at all — just workspace mode and a tenant config pointing
|
|
288
|
+
// at somebody else's hub. This is the DDR-209 case, unchanged.
|
|
289
|
+
setEnv({ MAUDE_WORKSPACE_MODE: '1' });
|
|
290
|
+
const ctx = makeCtx({ url: 'https://someone-elses-hub.example.com', linkedAt: 1 });
|
|
291
|
+
expect(createSyncRuntime(ctx)).toBeNull();
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test('workspace + pairing on + autocommit NOT disabled ⇒ still null', () => {
|
|
295
|
+
setEnv(pairingEnv({ MAUDE_SYNC_NO_AUTOCOMMIT: undefined }));
|
|
296
|
+
const ctx = makeCtx();
|
|
297
|
+
expect(createSyncRuntime(ctx)).toBeNull();
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test('the tenant config cannot steer the socket — only the workspace id crosses', async () => {
|
|
301
|
+
setEnv(pairingEnv());
|
|
302
|
+
// A hostile / merely stale committed config: a hub URL we must ignore, and
|
|
303
|
+
// a workspace id we MUST honour (it decides the document name the desktop
|
|
304
|
+
// peer is on — see cell-pairing.ts).
|
|
305
|
+
const ctx = makeCtx({
|
|
306
|
+
url: 'https://attacker.example.com',
|
|
307
|
+
linkedAt: 1,
|
|
308
|
+
workspaceId: 'acme-web',
|
|
309
|
+
});
|
|
310
|
+
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.tsx'), 'export default () => null;');
|
|
311
|
+
// Namespacing is what turns workspaceId into the wire name.
|
|
312
|
+
execFileSync('git', ['init', '-q'], { cwd: dir });
|
|
313
|
+
|
|
314
|
+
const h = cellHarness();
|
|
315
|
+
const runtime = createSyncRuntime(ctx, {
|
|
316
|
+
providerFactory: h.factory,
|
|
317
|
+
registry: h.registry,
|
|
318
|
+
});
|
|
319
|
+
await runtime?.start();
|
|
320
|
+
|
|
321
|
+
expect(h.dialled).toHaveLength(1);
|
|
322
|
+
expect(h.dialled[0]?.url).toBe(LOOPBACK);
|
|
323
|
+
expect(h.dialled[0]?.token).toBe('cell-token');
|
|
324
|
+
// The tenant's workspace id reached the WIRE NAME — without it the browser
|
|
325
|
+
// and the desktop would sit on two differently-named documents and this
|
|
326
|
+
// whole feature would silently do nothing.
|
|
327
|
+
expect(h.dialled[0]?.documentName).toContain('acme-web');
|
|
328
|
+
|
|
329
|
+
await runtime?.stop();
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
/* ------------------------------------------ Task 3: the hub is sole committer */
|
|
334
|
+
|
|
335
|
+
describe('Task 3 — no second committer appears inside the cell', () => {
|
|
336
|
+
test('a full edit cycle under pairing leaves git untouched', async () => {
|
|
337
|
+
setEnv(pairingEnv());
|
|
338
|
+
// A REAL repo, so an autocommit that existed would leave a real commit.
|
|
339
|
+
const repo = mkdtempSync(join(tmpdir(), 'cell-pairing-repo-'));
|
|
340
|
+
try {
|
|
341
|
+
execFileSync('git', ['init', '-q'], { cwd: repo });
|
|
342
|
+
execFileSync('git', ['config', 'user.email', 't@t.test'], { cwd: repo });
|
|
343
|
+
execFileSync('git', ['config', 'user.name', 'T'], { cwd: repo });
|
|
344
|
+
|
|
345
|
+
const ctx = makeCtx(undefined, repo);
|
|
346
|
+
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.tsx'), 'export default () => null;');
|
|
347
|
+
execFileSync('git', ['add', '-A'], { cwd: repo });
|
|
348
|
+
execFileSync('git', ['commit', '-qm', 'seed'], { cwd: repo });
|
|
349
|
+
const before = execFileSync('git', ['rev-list', '--count', 'HEAD'], {
|
|
350
|
+
cwd: repo,
|
|
351
|
+
encoding: 'utf8',
|
|
352
|
+
}).trim();
|
|
353
|
+
|
|
354
|
+
const h = cellHarness();
|
|
355
|
+
const runtime = createSyncRuntime(ctx, {
|
|
356
|
+
providerFactory: h.factory,
|
|
357
|
+
registry: h.registry,
|
|
358
|
+
});
|
|
359
|
+
await runtime?.start();
|
|
360
|
+
|
|
361
|
+
// The desktop peer edits the body — the exact traffic that, on the hub
|
|
362
|
+
// side, triggers `afterStoreDocument` and the ONE legitimate commit.
|
|
363
|
+
h.desktopDoc('ui-screen').getText(Y_SYNC_TYPES.html).insert(0, 'export const x = 1;\n');
|
|
364
|
+
// stop() is where an autocommit would flush its quiescence window.
|
|
365
|
+
await runtime?.stop();
|
|
366
|
+
|
|
367
|
+
const after = execFileSync('git', ['rev-list', '--count', 'HEAD'], {
|
|
368
|
+
cwd: repo,
|
|
369
|
+
encoding: 'utf8',
|
|
370
|
+
}).trim();
|
|
371
|
+
expect(after).toBe(before);
|
|
372
|
+
// Not merely uncommitted — never staged either.
|
|
373
|
+
const staged = execFileSync('git', ['diff', '--cached', '--name-only'], {
|
|
374
|
+
cwd: repo,
|
|
375
|
+
encoding: 'utf8',
|
|
376
|
+
}).trim();
|
|
377
|
+
expect(staged).toBe('');
|
|
378
|
+
} finally {
|
|
379
|
+
rmSync(repo, { recursive: true, force: true });
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
test('pairing never writes .claudeignore into the tenant repo', async () => {
|
|
384
|
+
setEnv(pairingEnv());
|
|
385
|
+
const ctx = makeCtx();
|
|
386
|
+
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.tsx'), 'export default () => null;');
|
|
387
|
+
|
|
388
|
+
const h = cellHarness();
|
|
389
|
+
const runtime = createSyncRuntime(ctx, {
|
|
390
|
+
providerFactory: h.factory,
|
|
391
|
+
registry: h.registry,
|
|
392
|
+
});
|
|
393
|
+
await runtime?.start();
|
|
394
|
+
// The marker's audience (Claude reading this checkout) does not exist in a
|
|
395
|
+
// cell, and the hub would commit and mirror the file to the tenant's repo.
|
|
396
|
+
expect(existsSync(join(ctx.paths.repoRoot, '.claudeignore'))).toBe(false);
|
|
397
|
+
await runtime?.stop();
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
/* --------------------------------- Task 5 + the headline: the two ends meet */
|
|
402
|
+
|
|
403
|
+
describe('presence and edits cross both ways', () => {
|
|
404
|
+
test('the browser room doc and the desktop doc are ONE doc', async () => {
|
|
405
|
+
setEnv(pairingEnv());
|
|
406
|
+
const ctx = makeCtx();
|
|
407
|
+
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.tsx'), 'export default () => null;');
|
|
408
|
+
|
|
409
|
+
const h = cellHarness();
|
|
410
|
+
const runtime = createSyncRuntime(ctx, {
|
|
411
|
+
providerFactory: h.factory,
|
|
412
|
+
registry: h.registry,
|
|
413
|
+
});
|
|
414
|
+
await runtime?.start();
|
|
415
|
+
|
|
416
|
+
// Browser → desktop.
|
|
417
|
+
h.browserDoc('ui-screen')
|
|
418
|
+
.getArray(Y_TYPES.comments)
|
|
419
|
+
.push([{ id: 'from-browser', text: 'hi' }]);
|
|
420
|
+
expect(h.desktopDoc('ui-screen').getArray(Y_TYPES.comments).toArray()).toEqual([
|
|
421
|
+
{ id: 'from-browser', text: 'hi' },
|
|
422
|
+
]);
|
|
423
|
+
|
|
424
|
+
// Desktop → browser.
|
|
425
|
+
h.desktopDoc('ui-screen').getMap(Y_TYPES.annotations).set('svg', '<svg><rect/></svg>');
|
|
426
|
+
expect(h.browserDoc('ui-screen').getMap(Y_TYPES.annotations).get('svg')).toBe(
|
|
427
|
+
'<svg><rect/></svg>'
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
await runtime?.stop();
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
test('the hub-synced awareness is bridged to the room, so cursors relay', async () => {
|
|
434
|
+
setEnv(pairingEnv());
|
|
435
|
+
const ctx = makeCtx();
|
|
436
|
+
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.tsx'), 'export default () => null;');
|
|
437
|
+
|
|
438
|
+
const h = cellHarness();
|
|
439
|
+
let attaches = 0;
|
|
440
|
+
const runtime = createSyncRuntime(ctx, {
|
|
441
|
+
providerFactory: h.factory,
|
|
442
|
+
registry: {
|
|
443
|
+
getDoc: (s) => h.registry.getDoc(s),
|
|
444
|
+
pin: (s) => h.registry.pin(s),
|
|
445
|
+
unpin: (s) => h.registry.unpin(s),
|
|
446
|
+
attachHubAwareness: (s, a) => {
|
|
447
|
+
attaches++;
|
|
448
|
+
return h.registry.attachHubAwareness(s, a);
|
|
449
|
+
},
|
|
450
|
+
},
|
|
451
|
+
});
|
|
452
|
+
await runtime?.start();
|
|
453
|
+
// Presence crosses for free BECAUSE the awareness is the provider's — this
|
|
454
|
+
// is the bridge, and without it a cursor stops at the process boundary.
|
|
455
|
+
expect(attaches).toBe(1);
|
|
456
|
+
await runtime?.stop();
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
describe('Task 5 — first connect between two non-empty sides', () => {
|
|
461
|
+
test('desktop state and browser files converge without duplicating comments', async () => {
|
|
462
|
+
// The cell's disk holds what the BROWSER has been writing; the doc holds
|
|
463
|
+
// what the DESKTOP synced up. Both non-empty — the case a naive
|
|
464
|
+
// `applyUpdate` merge turns into every comment appearing twice.
|
|
465
|
+
const designRoot = join(dir, 'design');
|
|
466
|
+
mkdirSync(join(designRoot, 'ui'), { recursive: true });
|
|
467
|
+
mkdirSync(join(designRoot, '_comments'), { recursive: true });
|
|
468
|
+
const paths = {
|
|
469
|
+
html: join(designRoot, 'ui', 'screen.tsx'),
|
|
470
|
+
comments: join(designRoot, '_comments', 'ui-screen.json'),
|
|
471
|
+
annotations: join(designRoot, 'ui-screen.annotations.svg'),
|
|
472
|
+
};
|
|
473
|
+
writeFileSync(paths.html, 'export const BROWSER = 1;\n');
|
|
474
|
+
writeFileSync(
|
|
475
|
+
paths.comments,
|
|
476
|
+
JSON.stringify([
|
|
477
|
+
{ id: 'shared-1', text: 'both sides have this' },
|
|
478
|
+
{ id: 'browser-only', text: 'only on disk' },
|
|
479
|
+
])
|
|
480
|
+
);
|
|
481
|
+
|
|
482
|
+
const doc = new Y.Doc();
|
|
483
|
+
doc.getText(Y_SYNC_TYPES.html).insert(0, 'export const DESKTOP = 1;\n');
|
|
484
|
+
applyCommentsToDoc(
|
|
485
|
+
doc,
|
|
486
|
+
[
|
|
487
|
+
{ id: 'shared-1', text: 'both sides have this' },
|
|
488
|
+
{ id: 'desktop-only', text: 'only in the doc' },
|
|
489
|
+
],
|
|
490
|
+
Symbol('seed')
|
|
491
|
+
);
|
|
492
|
+
|
|
493
|
+
const result = await migrateSeed({ slug: 'ui-screen', doc, paths });
|
|
494
|
+
|
|
495
|
+
// ONE authoritative body — never a concatenation of the two.
|
|
496
|
+
const body = doc.getText(Y_SYNC_TYPES.html).toString();
|
|
497
|
+
expect([result]).not.toContain('empty');
|
|
498
|
+
expect(body === 'export const BROWSER = 1;\n' || body === 'export const DESKTOP = 1;\n').toBe(
|
|
499
|
+
true
|
|
500
|
+
);
|
|
501
|
+
|
|
502
|
+
// Comments are id-unioned, so nothing is lost AND nothing is doubled.
|
|
503
|
+
const ids = (doc.getArray(Y_TYPES.comments).toArray() as Array<{ id: string }>).map(
|
|
504
|
+
(c) => c.id
|
|
505
|
+
);
|
|
506
|
+
expect([...ids].sort()).toEqual(['browser-only', 'desktop-only', 'shared-1']);
|
|
507
|
+
expect(ids).toHaveLength(new Set(ids).size);
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
test('re-running the seed is a no-op — a restarting cell cannot accumulate', async () => {
|
|
511
|
+
const designRoot = join(dir, 'design');
|
|
512
|
+
mkdirSync(join(designRoot, '_comments'), { recursive: true });
|
|
513
|
+
mkdirSync(join(designRoot, 'ui'), { recursive: true });
|
|
514
|
+
const paths = {
|
|
515
|
+
html: join(designRoot, 'ui', 'screen.tsx'),
|
|
516
|
+
comments: join(designRoot, '_comments', 'ui-screen.json'),
|
|
517
|
+
annotations: join(designRoot, 'ui-screen.annotations.svg'),
|
|
518
|
+
};
|
|
519
|
+
writeFileSync(paths.html, 'export const A = 1;\n');
|
|
520
|
+
writeFileSync(paths.comments, JSON.stringify([{ id: 'c1', text: 'one' }]));
|
|
521
|
+
|
|
522
|
+
const doc = new Y.Doc();
|
|
523
|
+
await migrateSeed({ slug: 'ui-screen', doc, paths });
|
|
524
|
+
const first = doc.getArray(Y_TYPES.comments).toArray();
|
|
525
|
+
for (let i = 0; i < 3; i++) await migrateSeed({ slug: 'ui-screen', doc, paths });
|
|
526
|
+
expect(doc.getArray(Y_TYPES.comments).toArray()).toEqual(first);
|
|
527
|
+
});
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
/* ------------------------------------- Task 6: exactly one reload per edit */
|
|
531
|
+
|
|
532
|
+
describe('Task 6 — a doc-originated edit produces exactly one reload signal', () => {
|
|
533
|
+
test('a projection write announces itself, once per file', async () => {
|
|
534
|
+
setEnv(pairingEnv());
|
|
535
|
+
const ctx = makeCtx();
|
|
536
|
+
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.tsx'), 'export const A = 1;\n');
|
|
537
|
+
|
|
538
|
+
const seen: string[] = [];
|
|
539
|
+
ctx.bus.on('fs:any', (rel: string) => seen.push(rel));
|
|
540
|
+
|
|
541
|
+
const h = cellHarness();
|
|
542
|
+
const runtime = createSyncRuntime(ctx, {
|
|
543
|
+
providerFactory: h.factory,
|
|
544
|
+
registry: h.registry,
|
|
545
|
+
});
|
|
546
|
+
await runtime?.start();
|
|
547
|
+
seen.length = 0; // ignore the cold-start materialize
|
|
548
|
+
|
|
549
|
+
// A desktop peer edits the body. The container's fs.watch would miss the
|
|
550
|
+
// atomic write that follows, so without the announcement the browser's
|
|
551
|
+
// canvas iframe never reloads — the bug this hook exists for.
|
|
552
|
+
h.desktopDoc('ui-screen').getText(Y_SYNC_TYPES.html).insert(0, '// edited\n');
|
|
553
|
+
await Bun.sleep(1400); // projection debounce (800 ms) + announce delay (250 ms)
|
|
554
|
+
|
|
555
|
+
const bodyEvents = seen.filter((r) => r === 'ui/screen.tsx');
|
|
556
|
+
expect(bodyEvents).toHaveLength(1);
|
|
557
|
+
// And the file really did land — the signal is not announcing a phantom.
|
|
558
|
+
expect(readFileSync(join(ctx.paths.designRoot, 'ui', 'screen.tsx'), 'utf8')).toContain(
|
|
559
|
+
'// edited'
|
|
560
|
+
);
|
|
561
|
+
|
|
562
|
+
await runtime?.stop();
|
|
563
|
+
}, 10_000);
|
|
564
|
+
|
|
565
|
+
test('the announcement does not loop back into the doc', async () => {
|
|
566
|
+
setEnv(pairingEnv());
|
|
567
|
+
const ctx = makeCtx();
|
|
568
|
+
writeFileSync(join(ctx.paths.designRoot, 'ui', 'screen.tsx'), 'export const A = 1;\n');
|
|
569
|
+
|
|
570
|
+
const h = cellHarness();
|
|
571
|
+
const runtime = createSyncRuntime(ctx, {
|
|
572
|
+
providerFactory: h.factory,
|
|
573
|
+
registry: h.registry,
|
|
574
|
+
});
|
|
575
|
+
await runtime?.start();
|
|
576
|
+
|
|
577
|
+
const doc = h.browserDoc('ui-screen');
|
|
578
|
+
let updates = 0;
|
|
579
|
+
doc.on('update', () => updates++);
|
|
580
|
+
|
|
581
|
+
h.desktopDoc('ui-screen').getText(Y_SYNC_TYPES.html).insert(0, '// edited\n');
|
|
582
|
+
const afterEdit = updates;
|
|
583
|
+
// Long enough for the write, the announcement, the fs read and any import
|
|
584
|
+
// it might have produced. The echo guard is what makes this terminate.
|
|
585
|
+
await Bun.sleep(1600);
|
|
586
|
+
expect(updates).toBe(afterEdit);
|
|
587
|
+
|
|
588
|
+
await runtime?.stop();
|
|
589
|
+
}, 10_000);
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
/* --------------------------- DDR-064 pre-cutover checklist (A4 / A6 gates) */
|
|
593
|
+
|
|
594
|
+
describe('DDR-064 pre-cutover — slug collisions and the pinned-room ceiling', () => {
|
|
595
|
+
const canvas = (slug: string, html: string): CanvasDescriptor => ({
|
|
596
|
+
slug,
|
|
597
|
+
html,
|
|
598
|
+
comments: `/c/${slug}.json`,
|
|
599
|
+
annotations: `/a/${slug}.svg`,
|
|
600
|
+
meta: html.replace(/\.tsx$/, '.meta.json'),
|
|
601
|
+
css: html.replace(/\.tsx$/, '.css'),
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
test('A4 — two files that flatten to one slug BOTH refuse to sync', () => {
|
|
605
|
+
// `ui/a/b.tsx` and `ui/a-b.tsx` both flatten to `ui-a-b`. One document for
|
|
606
|
+
// two files means each receives the other's body as a remote change and
|
|
607
|
+
// writes it over itself, forever.
|
|
608
|
+
const admitted = admitCanvases(
|
|
609
|
+
[
|
|
610
|
+
canvas('ui-a-b', '/d/ui/a/b.tsx'),
|
|
611
|
+
canvas('ui-a-b', '/d/ui/a-b.tsx'),
|
|
612
|
+
canvas('ui-ok', '/d/ui/ok.tsx'),
|
|
613
|
+
],
|
|
614
|
+
true
|
|
615
|
+
);
|
|
616
|
+
expect(admitted.map((c) => c.slug)).toEqual(['ui-ok']);
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
test('A4 — a clean set passes through untouched', () => {
|
|
620
|
+
const set = [canvas('a', '/d/ui/a.tsx'), canvas('b', '/d/ui/b.tsx')];
|
|
621
|
+
expect(admitCanvases(set, true)).toEqual(set);
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
test('A6 — the pinned-room ceiling bounds the shared-doc set', () => {
|
|
625
|
+
process.env.MAUDE_MAX_PINNED_ROOMS = '2';
|
|
626
|
+
const set = [
|
|
627
|
+
canvas('a', '/d/ui/a.tsx'),
|
|
628
|
+
canvas('b', '/d/ui/b.tsx'),
|
|
629
|
+
canvas('c', '/d/ui/c.tsx'),
|
|
630
|
+
];
|
|
631
|
+
expect(admitCanvases(set, true)).toHaveLength(2);
|
|
632
|
+
// Flag OFF is unpinned, so the ceiling does not apply to it.
|
|
633
|
+
expect(admitCanvases(set, false)).toHaveLength(3);
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
test('A6 — the default ceiling is far above any real project', () => {
|
|
637
|
+
expect(DEFAULT_MAX_PINNED_ROOMS).toBeGreaterThanOrEqual(500);
|
|
638
|
+
});
|
|
639
|
+
});
|
|
@@ -167,6 +167,53 @@ describe('committing, against a real repo', () => {
|
|
|
167
167
|
expect((await log('%s')).length).toBe(1);
|
|
168
168
|
});
|
|
169
169
|
|
|
170
|
+
test('a steady stream of notes cannot defer the commit forever', async () => {
|
|
171
|
+
// Quiescence batching resets the timer on every note, so without a ceiling
|
|
172
|
+
// anyone able to drive notes faster than `debounceMs` holds the project's
|
|
173
|
+
// history open indefinitely. In a cell that is reachable by the LOWEST role:
|
|
174
|
+
// a viewer holds `comment`, a comment updates the doc, the doc stores, and
|
|
175
|
+
// the hub notes on every store. Bounded now by `maxDebounceMs`.
|
|
176
|
+
const auto = createAutoCommit({
|
|
177
|
+
repoRoot: repo,
|
|
178
|
+
run: git,
|
|
179
|
+
debounceMs: 100, // never quiet: notes arrive every 20 ms, below this
|
|
180
|
+
maxDebounceMs: 300,
|
|
181
|
+
log: silent(),
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
write(REL, 'export default () => <main>held open</main>;\n');
|
|
185
|
+
const started = Date.now();
|
|
186
|
+
// 600 ms of chatter at 20 ms — six times the quiescence window, so the
|
|
187
|
+
// un-ceilinged version commits nothing at all in this span.
|
|
188
|
+
while (Date.now() - started < 600) {
|
|
189
|
+
auto.note(REL, ALICE);
|
|
190
|
+
await new Promise((r) => setTimeout(r, 20));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const subjects = await log('%s');
|
|
194
|
+
expect(subjects.length).toBe(2); // seed + the ceiling-forced autosave
|
|
195
|
+
auto.stop();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('an unrelated STAGED entry cannot wedge the agent', async () => {
|
|
199
|
+
// The no-op probe asks "did OUR paths stage anything". Unscoped, a stray
|
|
200
|
+
// index entry answers yes, and `commit --only -- <our unchanged paths>`
|
|
201
|
+
// then exits non-zero forever — the agent re-queues but never re-arms, so
|
|
202
|
+
// it fails identically from then on while /health stays green. Routine
|
|
203
|
+
// since the commit set stopped being "files we just wrote" (cell pairing:
|
|
204
|
+
// the studio child's projector writes the bytes first).
|
|
205
|
+
write('stray.txt', 'staged by somebody else\n');
|
|
206
|
+
await git(['add', '--', 'stray.txt'], { cwd: repo });
|
|
207
|
+
|
|
208
|
+
const auto = createAutoCommit({ repoRoot: repo, run: git, debounceMs: 5, log: silent() });
|
|
209
|
+
auto.note(REL, ALICE); // unchanged bytes
|
|
210
|
+
const outcome = await auto.flush();
|
|
211
|
+
expect(outcome?.ok).toBe(false);
|
|
212
|
+
expect(outcome && !outcome.ok && outcome.reason).toBe('nothing-to-commit');
|
|
213
|
+
// And it must not have swept the stray file into a commit either.
|
|
214
|
+
expect((await log('%s')).length).toBe(1);
|
|
215
|
+
});
|
|
216
|
+
|
|
170
217
|
test('only the NOTED files are staged — an unrelated dirty file is left alone', async () => {
|
|
171
218
|
// `git add -A` in a workspace would sweep in whatever else is in the tree.
|
|
172
219
|
// The cell must never commit something it wasn't told about.
|