@1agh/maude 0.47.0 → 0.49.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/README.md +7 -6
- package/apps/studio/acp/bridge.ts +8 -1
- package/apps/studio/acp/plugin-bootstrap.ts +15 -1
- package/apps/studio/api.ts +18 -2
- package/apps/studio/assets-s3.ts +291 -0
- package/apps/studio/build.ts +1 -1
- package/apps/studio/client/export-center.jsx +7 -6
- package/apps/studio/client/github.js +11 -4
- package/apps/studio/collab/origins.ts +150 -0
- package/apps/studio/collab/protocol.ts +36 -9
- package/apps/studio/collab/room.ts +124 -0
- package/apps/studio/context.ts +9 -0
- package/apps/studio/dist/client.bundle.js +282 -282
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/dist/runtime/REMOTION-LICENSE.md +1 -1
- package/apps/studio/examples/perf-100-artboards.tsx +1 -1
- package/apps/studio/exporters/pdf.ts +35 -1
- package/apps/studio/git/service.ts +4 -1
- package/apps/studio/http.ts +45 -0
- package/apps/studio/paths.ts +37 -1
- package/apps/studio/server.ts +75 -2
- package/apps/studio/sync/autocommit.ts +299 -0
- package/apps/studio/sync/doc-name.ts +228 -0
- package/apps/studio/sync/index.ts +95 -1
- package/apps/studio/sync/workspace-signin.ts +301 -0
- package/apps/studio/test/acp-plugin-bootstrap.test.ts +34 -0
- package/apps/studio/test/acp-session-plugins.test.ts +6 -0
- package/apps/studio/test/assets-s3.test.ts +249 -0
- package/apps/studio/test/canvas-origin-gate.test.ts +7 -0
- package/apps/studio/test/collab-origin-gate.test.ts +323 -0
- package/apps/studio/test/exporters/pdf.test.ts +33 -1
- package/apps/studio/test/sync-autocommit.test.ts +334 -0
- package/apps/studio/test/sync-doc-name.test.ts +281 -0
- package/apps/studio/test/workspace-containment.test.ts +258 -0
- package/apps/studio/test/workspace-signin.test.ts +270 -0
- package/apps/studio/use-collab.tsx +28 -1
- package/apps/studio/workspace-mode.ts +210 -0
- package/apps/studio/ws.ts +11 -2
- package/cli/bin/maude.mjs +1 -0
- package/cli/commands/hub-workspace.mjs +341 -0
- package/cli/commands/hub.mjs +325 -3
- package/cli/commands/hub.test.mjs +14 -1
- package/cli/commands/init.mjs +80 -3
- package/cli/commands/kg.mjs +368 -0
- package/cli/commands/kg.test.mjs +118 -0
- package/cli/lib/cell-plan.mjs +302 -0
- package/cli/lib/cell-plan.test.mjs +225 -0
- package/cli/lib/ddr-to-kgai.mjs +648 -0
- package/cli/lib/ddr-to-kgai.test.mjs +99 -0
- package/cli/lib/flow-design-integration.test.mjs +2 -2
- package/cli/lib/gitignore-block.mjs +16 -1
- package/cli/lib/plugin-name-namespace.test.mjs +71 -0
- package/cli/lib/workspace-plan.mjs +422 -0
- package/cli/lib/workspace-plan.test.mjs +223 -0
- package/package.json +8 -8
- package/plugins/design/dependencies.json +17 -0
- package/plugins/flow/.claude-plugin/config.schema.json +66 -0
- package/plugins/flow/dependencies.json +17 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
// Cloud Phase 3 Task 1 — autosave as append-only git commits.
|
|
2
|
+
//
|
|
3
|
+
// Driven against a REAL git repository in a temp dir, not a mocked runner. The
|
|
4
|
+
// properties that matter (authorship survives, history is never rewritten, a
|
|
5
|
+
// no-op write produces no commit) are properties of git's actual behaviour, and
|
|
6
|
+
// a mock would only prove that the arguments match what I expected them to be.
|
|
7
|
+
|
|
8
|
+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
|
|
9
|
+
|
|
10
|
+
import { spawn } from 'node:child_process';
|
|
11
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
12
|
+
import { tmpdir } from 'node:os';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
commitMessage,
|
|
17
|
+
createAutoCommit,
|
|
18
|
+
formatAuthor,
|
|
19
|
+
type GitRunner,
|
|
20
|
+
pushMirror,
|
|
21
|
+
sanitizeAttribution,
|
|
22
|
+
UNKNOWN_AUTHOR,
|
|
23
|
+
} from '../sync/autocommit.ts';
|
|
24
|
+
|
|
25
|
+
const git: GitRunner = (args, { cwd }) =>
|
|
26
|
+
new Promise((resolve) => {
|
|
27
|
+
const child = spawn('git', args, {
|
|
28
|
+
cwd,
|
|
29
|
+
env: { ...process.env, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_SYSTEM: '/dev/null' },
|
|
30
|
+
});
|
|
31
|
+
let stdout = '';
|
|
32
|
+
let stderr = '';
|
|
33
|
+
child.stdout.on('data', (d) => {
|
|
34
|
+
stdout += d;
|
|
35
|
+
});
|
|
36
|
+
child.stderr.on('data', (d) => {
|
|
37
|
+
stderr += d;
|
|
38
|
+
});
|
|
39
|
+
child.on('close', (code) => resolve({ code: code ?? 1, stdout, stderr }));
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
let repo: string;
|
|
43
|
+
|
|
44
|
+
async function initRepo(): Promise<string> {
|
|
45
|
+
const dir = mkdtempSync(path.join(tmpdir(), 'maude-autocommit-'));
|
|
46
|
+
await git(['init', '--initial-branch=main'], { cwd: dir });
|
|
47
|
+
await git(['config', 'user.name', 'Seed'], { cwd: dir });
|
|
48
|
+
await git(['config', 'user.email', 'seed@example.com'], { cwd: dir });
|
|
49
|
+
mkdirSync(path.join(dir, '.design', 'ui'), { recursive: true });
|
|
50
|
+
writeFileSync(path.join(dir, '.design', 'ui', 'Screen.tsx'), 'export default () => null;\n');
|
|
51
|
+
await git(['add', '-A'], { cwd: dir });
|
|
52
|
+
await git(['commit', '-m', 'seed'], { cwd: dir });
|
|
53
|
+
return dir;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const ALICE = { name: 'Alice Novák', email: 'alice@example.com' };
|
|
57
|
+
const BOB = { name: 'Bob', email: 'bob@example.com' };
|
|
58
|
+
const REL = '.design/ui/Screen.tsx';
|
|
59
|
+
|
|
60
|
+
const write = (rel: string, body: string) => writeFileSync(path.join(repo, rel), body);
|
|
61
|
+
const log = async (fmt: string) =>
|
|
62
|
+
(await git(['log', `--pretty=format:${fmt}`], { cwd: repo })).stdout.split('\n').filter(Boolean);
|
|
63
|
+
|
|
64
|
+
beforeEach(async () => {
|
|
65
|
+
repo = await initRepo();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
afterEach(() => {
|
|
69
|
+
if (repo) rmSync(repo, { recursive: true, force: true });
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe('attribution', () => {
|
|
73
|
+
test('a missing author is UNKNOWN, never the bot', () => {
|
|
74
|
+
// Attributing an anonymous human's work to the server makes `git blame` lie
|
|
75
|
+
// in a way that is hard to notice later. "Unknown" is honest and visibly
|
|
76
|
+
// wrong.
|
|
77
|
+
expect(sanitizeAttribution(null)).toEqual(UNKNOWN_AUTHOR);
|
|
78
|
+
expect(sanitizeAttribution(undefined)).toEqual(UNKNOWN_AUTHOR);
|
|
79
|
+
expect(sanitizeAttribution({ name: '', email: '' })).toEqual(UNKNOWN_AUTHOR);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('presence-supplied identity cannot forge commit trailers', () => {
|
|
83
|
+
// Presence arrives over a semi-trusted hub (DDR-054): a name is
|
|
84
|
+
// attacker-influenceable text, and `--author` takes `Name <email>`.
|
|
85
|
+
const evil = sanitizeAttribution({
|
|
86
|
+
name: 'Real Person <real@example.com>\nSigned-off-by: Someone Else',
|
|
87
|
+
email: 'a@b.com\r\nCo-Authored-By: Nobody',
|
|
88
|
+
});
|
|
89
|
+
expect(evil.name).not.toContain('\n');
|
|
90
|
+
expect(evil.name).not.toContain('<');
|
|
91
|
+
expect(evil.name).not.toContain('>');
|
|
92
|
+
expect(evil.email).not.toContain('\r');
|
|
93
|
+
expect(formatAuthor(evil)).toMatch(/^[^<>\n]+ <[^<>\n]+>$/);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('names are bounded so one peer cannot bloat every commit', () => {
|
|
97
|
+
const long = sanitizeAttribution({ name: 'x'.repeat(500), email: 'y'.repeat(500) });
|
|
98
|
+
expect(long.name.length).toBeLessThanOrEqual(96);
|
|
99
|
+
expect(long.email.length).toBeLessThanOrEqual(96);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('unicode names survive intact — this is a real person, not a slug', () => {
|
|
103
|
+
expect(sanitizeAttribution(ALICE).name).toBe('Alice Novák');
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe('commit message', () => {
|
|
108
|
+
test('names the canvas rather than saying "autosave"', () => {
|
|
109
|
+
// 400 identical subjects is the same as no history.
|
|
110
|
+
const one = commitMessage(['.design/ui/Screen.tsx'], ALICE);
|
|
111
|
+
expect(one.split('\n')[0]).toBe('design: update Screen');
|
|
112
|
+
expect(one).toContain('Alice Novák <alice@example.com>');
|
|
113
|
+
expect(one).toContain('append-only');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('a multi-file commit summarizes and lists', () => {
|
|
117
|
+
const many = commitMessage(
|
|
118
|
+
['.design/ui/Screen.tsx', '.design/ui/Settings.tsx', '.design/ui/Screen.meta.json'],
|
|
119
|
+
ALICE
|
|
120
|
+
);
|
|
121
|
+
// Screen.tsx + Screen.meta.json are ONE canvas — a subject that said
|
|
122
|
+
// "3 canvases" would overstate what changed on every single commit.
|
|
123
|
+
expect(many.split('\n')[0]).toBe('design: update 2 canvases');
|
|
124
|
+
expect(many).toContain('- Screen');
|
|
125
|
+
expect(many).toContain('- Settings');
|
|
126
|
+
expect(many).not.toContain('- Screen.meta');
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('committing, against a real repo', () => {
|
|
131
|
+
test('an edit becomes a commit authored by the HUMAN, committed by the bot', async () => {
|
|
132
|
+
const auto = createAutoCommit({ repoRoot: repo, run: git, debounceMs: 5, log: silent() });
|
|
133
|
+
write(REL, 'export default () => <main>alice was here</main>;\n');
|
|
134
|
+
auto.note(REL, ALICE);
|
|
135
|
+
|
|
136
|
+
const outcome = await auto.flush();
|
|
137
|
+
expect(outcome?.ok).toBe(true);
|
|
138
|
+
|
|
139
|
+
// This is the point of using git's author/committer split at all: blame
|
|
140
|
+
// answers "who designed this", not "the server did".
|
|
141
|
+
expect(await log('%an|%ae')).toEqual([
|
|
142
|
+
'Alice Novák|alice@example.com',
|
|
143
|
+
'Seed|seed@example.com',
|
|
144
|
+
]);
|
|
145
|
+
expect((await log('%cn'))[0]).toBe('Maude Workspace');
|
|
146
|
+
expect((await log('%s'))[0]).toBe('design: update Screen');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('edits COALESCE — a typing session is one commit, not four hundred', async () => {
|
|
150
|
+
const auto = createAutoCommit({ repoRoot: repo, run: git, debounceMs: 5, log: silent() });
|
|
151
|
+
for (let i = 0; i < 20; i++) {
|
|
152
|
+
write(REL, `export default () => <main>v${i}</main>;\n`);
|
|
153
|
+
auto.note(REL, ALICE);
|
|
154
|
+
}
|
|
155
|
+
await auto.flush();
|
|
156
|
+
expect((await log('%s')).length).toBe(2); // seed + one autosave
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('a no-op write produces NO commit', async () => {
|
|
160
|
+
// An echo, or a write of identical bytes. Committing it would be noise.
|
|
161
|
+
const auto = createAutoCommit({ repoRoot: repo, run: git, debounceMs: 5, log: silent() });
|
|
162
|
+
auto.note(REL, ALICE);
|
|
163
|
+
const outcome = await auto.flush();
|
|
164
|
+
expect(outcome?.ok).toBe(false);
|
|
165
|
+
expect(outcome && !outcome.ok && outcome.reason).toBe('nothing-to-commit');
|
|
166
|
+
expect((await log('%s')).length).toBe(1);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('only the NOTED files are staged — an unrelated dirty file is left alone', async () => {
|
|
170
|
+
// `git add -A` in a workspace would sweep in whatever else is in the tree.
|
|
171
|
+
// The cell must never commit something it wasn't told about.
|
|
172
|
+
const auto = createAutoCommit({ repoRoot: repo, run: git, debounceMs: 5, log: silent() });
|
|
173
|
+
write(REL, 'export default () => <main>noted</main>;\n');
|
|
174
|
+
writeFileSync(path.join(repo, 'UNRELATED.md'), 'not part of the design\n');
|
|
175
|
+
auto.note(REL, ALICE);
|
|
176
|
+
await auto.flush();
|
|
177
|
+
|
|
178
|
+
const show = await git(['show', '--name-only', '--pretty=format:', 'HEAD'], { cwd: repo });
|
|
179
|
+
expect(show.stdout.trim()).toBe(REL);
|
|
180
|
+
const status = await git(['status', '--porcelain'], { cwd: repo });
|
|
181
|
+
expect(status.stdout).toContain('UNRELATED.md');
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
test('history is APPEND-ONLY — an earlier state is still reachable', async () => {
|
|
185
|
+
const auto = createAutoCommit({ repoRoot: repo, run: git, debounceMs: 5, log: silent() });
|
|
186
|
+
write(REL, 'export default () => <main>first</main>;\n');
|
|
187
|
+
auto.note(REL, ALICE);
|
|
188
|
+
await auto.flush();
|
|
189
|
+
const firstSha = (await log('%H'))[0];
|
|
190
|
+
|
|
191
|
+
write(REL, 'export default () => <main>second</main>;\n');
|
|
192
|
+
auto.note(REL, BOB);
|
|
193
|
+
await auto.flush();
|
|
194
|
+
|
|
195
|
+
// The old content is still there — the guarantee that makes a cell's
|
|
196
|
+
// autosave safe to trust with someone's only copy.
|
|
197
|
+
const old = await git(['show', `${firstSha}:${REL}`], { cwd: repo });
|
|
198
|
+
expect(old.stdout).toContain('first');
|
|
199
|
+
expect((await log('%s')).length).toBe(3);
|
|
200
|
+
expect(await log('%an')).toEqual(['Bob', 'Alice Novák', 'Seed']);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test('two peers editing before quiescence produce one commit, attributed to the last', async () => {
|
|
204
|
+
const auto = createAutoCommit({ repoRoot: repo, run: git, debounceMs: 5, log: silent() });
|
|
205
|
+
write(REL, 'export default () => <main>alice</main>;\n');
|
|
206
|
+
auto.note(REL, ALICE);
|
|
207
|
+
write(path.join('.design', 'ui', 'Second.tsx'), '');
|
|
208
|
+
writeFileSync(path.join(repo, '.design/ui/Second.tsx'), 'export default () => null;\n');
|
|
209
|
+
auto.note('.design/ui/Second.tsx', BOB);
|
|
210
|
+
await auto.flush();
|
|
211
|
+
|
|
212
|
+
expect((await log('%an'))[0]).toBe('Bob');
|
|
213
|
+
expect((await log('%s'))[0]).toBe('design: update 2 canvases');
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test('a git failure RE-QUEUES the change instead of dropping it', async () => {
|
|
217
|
+
// The bytes are already on disk, so a git error must not remove the change
|
|
218
|
+
// from history permanently — making the commit a precondition of the save
|
|
219
|
+
// would turn a transient error into data loss.
|
|
220
|
+
let failNext = true;
|
|
221
|
+
const flaky: GitRunner = async (args, opts) => {
|
|
222
|
+
if (args.includes('commit') && failNext) {
|
|
223
|
+
failNext = false;
|
|
224
|
+
return { code: 1, stdout: '', stderr: 'simulated git failure' };
|
|
225
|
+
}
|
|
226
|
+
return git(args, opts);
|
|
227
|
+
};
|
|
228
|
+
const auto = createAutoCommit({ repoRoot: repo, run: flaky, debounceMs: 5, log: silent() });
|
|
229
|
+
write(REL, 'export default () => <main>retry me</main>;\n');
|
|
230
|
+
auto.note(REL, ALICE);
|
|
231
|
+
|
|
232
|
+
const first = await auto.flush();
|
|
233
|
+
expect(first?.ok).toBe(false);
|
|
234
|
+
expect(auto.pending()).toEqual([REL]);
|
|
235
|
+
|
|
236
|
+
const second = await auto.flush();
|
|
237
|
+
expect(second?.ok).toBe(true);
|
|
238
|
+
expect((await log('%s')).length).toBe(2);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test('flush with nothing pending is a no-op, not an empty commit', async () => {
|
|
242
|
+
const auto = createAutoCommit({ repoRoot: repo, run: git, debounceMs: 5, log: silent() });
|
|
243
|
+
expect(await auto.flush()).toBe(null);
|
|
244
|
+
expect((await log('%s')).length).toBe(1);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('stop() prevents further scheduling', async () => {
|
|
248
|
+
const auto = createAutoCommit({ repoRoot: repo, run: git, debounceMs: 5, log: silent() });
|
|
249
|
+
auto.stop();
|
|
250
|
+
write(REL, 'export default () => <main>after stop</main>;\n');
|
|
251
|
+
auto.note(REL, ALICE);
|
|
252
|
+
expect(auto.pending()).toEqual([]);
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
describe('mirror push — never rewrites someone else’s work', () => {
|
|
257
|
+
test('a non-fast-forward push is REPORTED as rejected, never forced', async () => {
|
|
258
|
+
// The cell has no way to know whether merging a stranger's commits is
|
|
259
|
+
// right, so it stops and surfaces it. DDR-119's hazard, arriving from the
|
|
260
|
+
// other direction.
|
|
261
|
+
const remote = mkdtempSync(path.join(tmpdir(), 'maude-remote-'));
|
|
262
|
+
await git(['init', '--bare', '--initial-branch=main'], { cwd: remote });
|
|
263
|
+
await git(['remote', 'add', 'origin', remote], { cwd: repo });
|
|
264
|
+
await git(['push', 'origin', 'main'], { cwd: repo });
|
|
265
|
+
|
|
266
|
+
// Someone else pushes first, from a separate clone.
|
|
267
|
+
const other = mkdtempSync(path.join(tmpdir(), 'maude-other-'));
|
|
268
|
+
await git(['clone', remote, other], { cwd: path.dirname(other) });
|
|
269
|
+
await git(['config', 'user.name', 'Other'], { cwd: other });
|
|
270
|
+
await git(['config', 'user.email', 'other@example.com'], { cwd: other });
|
|
271
|
+
writeFileSync(path.join(other, 'theirs.txt'), 'their work\n');
|
|
272
|
+
await git(['add', '-A'], { cwd: other });
|
|
273
|
+
await git(['commit', '-m', 'their work'], { cwd: other });
|
|
274
|
+
await git(['push', 'origin', 'main'], { cwd: other });
|
|
275
|
+
|
|
276
|
+
// Now the cell has a diverging commit.
|
|
277
|
+
const auto = createAutoCommit({ repoRoot: repo, run: git, debounceMs: 5, log: silent() });
|
|
278
|
+
write(REL, 'export default () => <main>ours</main>;\n');
|
|
279
|
+
auto.note(REL, ALICE);
|
|
280
|
+
await auto.flush();
|
|
281
|
+
|
|
282
|
+
const res = await pushMirror({ repoRoot: repo, run: git, branch: 'main', log: silent() });
|
|
283
|
+
expect(res.ok).toBe(false);
|
|
284
|
+
expect(res.rejected).toBe(true);
|
|
285
|
+
|
|
286
|
+
// Their commit is still the remote's tip — nothing of theirs was destroyed.
|
|
287
|
+
const remoteLog = await git(['log', '--pretty=format:%s', 'main'], { cwd: remote });
|
|
288
|
+
expect(remoteLog.stdout.split('\n')[0]).toBe('their work');
|
|
289
|
+
|
|
290
|
+
rmSync(remote, { recursive: true, force: true });
|
|
291
|
+
rmSync(other, { recursive: true, force: true });
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
test('a fast-forward push succeeds', async () => {
|
|
295
|
+
const remote = mkdtempSync(path.join(tmpdir(), 'maude-remote-ok-'));
|
|
296
|
+
await git(['init', '--bare', '--initial-branch=main'], { cwd: remote });
|
|
297
|
+
await git(['remote', 'add', 'origin', remote], { cwd: repo });
|
|
298
|
+
await git(['push', 'origin', 'main'], { cwd: repo });
|
|
299
|
+
|
|
300
|
+
const auto = createAutoCommit({ repoRoot: repo, run: git, debounceMs: 5, log: silent() });
|
|
301
|
+
write(REL, 'export default () => <main>ours</main>;\n');
|
|
302
|
+
auto.note(REL, ALICE);
|
|
303
|
+
await auto.flush();
|
|
304
|
+
|
|
305
|
+
const res = await pushMirror({ repoRoot: repo, run: git, branch: 'main', log: silent() });
|
|
306
|
+
expect(res.ok).toBe(true);
|
|
307
|
+
expect(res.rejected).toBe(false);
|
|
308
|
+
|
|
309
|
+
rmSync(remote, { recursive: true, force: true });
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
test('pushMirror never passes a force flag', async () => {
|
|
313
|
+
// Pinned as an argv assertion: the guarantee is the ABSENCE of a flag, and
|
|
314
|
+
// absence is exactly what a future edit could add without any test noticing.
|
|
315
|
+
const seen: string[][] = [];
|
|
316
|
+
await pushMirror({
|
|
317
|
+
repoRoot: repo,
|
|
318
|
+
branch: 'main',
|
|
319
|
+
run: async (args) => {
|
|
320
|
+
seen.push(args);
|
|
321
|
+
return { code: 0, stdout: '', stderr: '' };
|
|
322
|
+
},
|
|
323
|
+
log: silent(),
|
|
324
|
+
});
|
|
325
|
+
const flat = seen.flat();
|
|
326
|
+
expect(flat.some((a) => /^--force/.test(a))).toBe(false);
|
|
327
|
+
expect(flat.some((a) => a.startsWith('+'))).toBe(false);
|
|
328
|
+
expect(flat).toContain('refs/heads/main:refs/heads/main');
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
function silent() {
|
|
333
|
+
return { warn: () => {}, error: () => {}, log: () => {} };
|
|
334
|
+
}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// DDR-192 §5 — the `ws/<workspace-id>/<branch>/<slug>` document namespace,
|
|
2
|
+
// client side: resolution (where the workspace id and branch come from), the
|
|
3
|
+
// opt-in rollout rule, conformance with the hub's independent implementation,
|
|
4
|
+
// and the DDR-076 fresh-doc case that makes changing doc identity safe.
|
|
5
|
+
|
|
6
|
+
import { describe, expect, test } from 'bun:test';
|
|
7
|
+
|
|
8
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { tmpdir } from 'node:os';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
|
|
12
|
+
// The HUB's implementation, imported across the package boundary on purpose —
|
|
13
|
+
// this file is what pins the two grammars to each other (see doc-name.ts).
|
|
14
|
+
import * as hub from '../../hub/src/doc-namespace.mjs';
|
|
15
|
+
import { decideColdStart } from '../sync/cold-start.ts';
|
|
16
|
+
import {
|
|
17
|
+
buildDocName,
|
|
18
|
+
createDocNameResolver,
|
|
19
|
+
isNamespaced,
|
|
20
|
+
parseDocName,
|
|
21
|
+
readBranch,
|
|
22
|
+
readOriginUrl,
|
|
23
|
+
resolveWorkspaceId,
|
|
24
|
+
sanitizeComponent,
|
|
25
|
+
workspaceIdFromRemote,
|
|
26
|
+
} from '../sync/doc-name.ts';
|
|
27
|
+
|
|
28
|
+
/** A throwaway repo skeleton: `.git/HEAD` + optionally `.git/config`. */
|
|
29
|
+
function makeRepo(opts: { head?: string; origin?: string } = {}): string {
|
|
30
|
+
const root = mkdtempSync(path.join(tmpdir(), 'maude-docname-'));
|
|
31
|
+
mkdirSync(path.join(root, '.git'), { recursive: true });
|
|
32
|
+
writeFileSync(path.join(root, '.git', 'HEAD'), opts.head ?? 'ref: refs/heads/main\n');
|
|
33
|
+
if (opts.origin) {
|
|
34
|
+
writeFileSync(
|
|
35
|
+
path.join(root, '.git', 'config'),
|
|
36
|
+
`[core]\n\trepositoryformatversion = 0\n[remote "origin"]\n\turl = ${opts.origin}\n\tfetch = +refs/heads/*:refs/remotes/origin/*\n[branch "main"]\n\tremote = origin\n`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return root;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('doc-name — resolution inputs', () => {
|
|
43
|
+
test('readBranch reads a branch, a slash-branch, and a detached HEAD', () => {
|
|
44
|
+
const a = makeRepo({ head: 'ref: refs/heads/main\n' });
|
|
45
|
+
const b = makeRepo({ head: 'ref: refs/heads/feature/cloud-arc\n' });
|
|
46
|
+
const c = makeRepo({ head: '9f1c0a2b3c4d5e6f708192a3b4c5d6e7f8091a2b\n' });
|
|
47
|
+
const none = mkdtempSync(path.join(tmpdir(), 'maude-nogit-'));
|
|
48
|
+
try {
|
|
49
|
+
expect(readBranch(a)).toBe('main');
|
|
50
|
+
expect(readBranch(b)).toBe('feature/cloud-arc');
|
|
51
|
+
// A detached HEAD gets a STABLE name for that commit, so two peers
|
|
52
|
+
// detached at the same commit meet and neither joins a branch's doc.
|
|
53
|
+
expect(readBranch(c)).toBe('detached-9f1c0a2');
|
|
54
|
+
expect(readBranch(none)).toBe(null);
|
|
55
|
+
} finally {
|
|
56
|
+
for (const d of [a, b, c, none]) rmSync(d, { recursive: true, force: true });
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('readOriginUrl picks origin out of .git/config, ignoring other remotes', () => {
|
|
61
|
+
const root = makeRepo({ origin: 'git@github.com:1aGh/maude.git' });
|
|
62
|
+
try {
|
|
63
|
+
expect(readOriginUrl(root)).toBe('git@github.com:1aGh/maude.git');
|
|
64
|
+
writeFileSync(
|
|
65
|
+
path.join(root, '.git', 'config'),
|
|
66
|
+
'[remote "upstream"]\n\turl = https://example.com/x/y.git\n'
|
|
67
|
+
);
|
|
68
|
+
expect(readOriginUrl(root)).toBe(null);
|
|
69
|
+
} finally {
|
|
70
|
+
rmSync(root, { recursive: true, force: true });
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('the same project cloned different ways yields the SAME workspace id', () => {
|
|
75
|
+
// This is the property that decides whether two peers meet at all. If SSH
|
|
76
|
+
// and HTTPS clones of one repo derived different ids, each peer would see
|
|
77
|
+
// the other's documents as simply absent.
|
|
78
|
+
const forms = [
|
|
79
|
+
'git@github.com:1aGh/maude.git',
|
|
80
|
+
'https://github.com/1aGh/maude.git',
|
|
81
|
+
'https://github.com/1aGh/maude',
|
|
82
|
+
'ssh://git@github.com/1aGh/maude.git',
|
|
83
|
+
'https://user:tok@github.com/1aGh/maude.git',
|
|
84
|
+
];
|
|
85
|
+
const ids = new Set(forms.map(workspaceIdFromRemote));
|
|
86
|
+
expect([...ids]).toEqual(['1agh-maude']);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('different projects yield different workspace ids', () => {
|
|
90
|
+
expect(workspaceIdFromRemote('git@github.com:1aGh/maude.git')).not.toBe(
|
|
91
|
+
workspaceIdFromRemote('git@github.com:1aGh/dugmate.git')
|
|
92
|
+
);
|
|
93
|
+
expect(workspaceIdFromRemote('git@github.com:acme/site.git')).not.toBe(
|
|
94
|
+
workspaceIdFromRemote('git@gitlab.com:other/site.git')
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('resolveWorkspaceId prefers explicit config, then origin, then nothing', () => {
|
|
99
|
+
const withOrigin = makeRepo({ origin: 'git@github.com:acme/site.git' });
|
|
100
|
+
const noOrigin = makeRepo();
|
|
101
|
+
try {
|
|
102
|
+
expect(resolveWorkspaceId({ explicit: 'cloud-abc123', repoRoot: withOrigin })).toBe(
|
|
103
|
+
'cloud-abc123'
|
|
104
|
+
);
|
|
105
|
+
expect(resolveWorkspaceId({ repoRoot: withOrigin })).toBe('acme-site');
|
|
106
|
+
// No origin and no config: null. NOT a directory-name fallback — a local
|
|
107
|
+
// path differs per machine, so deriving from it would split peers apart.
|
|
108
|
+
expect(resolveWorkspaceId({ repoRoot: noOrigin })).toBe(null);
|
|
109
|
+
} finally {
|
|
110
|
+
rmSync(withOrigin, { recursive: true, force: true });
|
|
111
|
+
rmSync(noOrigin, { recursive: true, force: true });
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe('doc-name — the rollout rule', () => {
|
|
117
|
+
test('unset flag + no explicit workspace id ⇒ flat (an upgrade changes nothing)', () => {
|
|
118
|
+
const root = makeRepo({ origin: 'git@github.com:acme/site.git' });
|
|
119
|
+
try {
|
|
120
|
+
const resolve = createDocNameResolver({ repoRoot: root });
|
|
121
|
+
expect(resolve('ui-screen')).toBe('ui-screen');
|
|
122
|
+
} finally {
|
|
123
|
+
rmSync(root, { recursive: true, force: true });
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('an explicitly declared workspace id opts in', () => {
|
|
128
|
+
const root = makeRepo({ origin: 'git@github.com:acme/site.git' });
|
|
129
|
+
try {
|
|
130
|
+
const resolve = createDocNameResolver({ repoRoot: root, explicitWorkspaceId: 'acme-site' });
|
|
131
|
+
expect(resolve('ui-screen')).toBe('ws/acme-site/main/ui-screen');
|
|
132
|
+
} finally {
|
|
133
|
+
rmSync(root, { recursive: true, force: true });
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test('MAUDE_HUB_NAMESPACED=0 forces flat even with an explicit id', () => {
|
|
138
|
+
const root = makeRepo({ origin: 'git@github.com:acme/site.git' });
|
|
139
|
+
try {
|
|
140
|
+
const resolve = createDocNameResolver({
|
|
141
|
+
repoRoot: root,
|
|
142
|
+
explicitWorkspaceId: 'acme-site',
|
|
143
|
+
flag: '0',
|
|
144
|
+
});
|
|
145
|
+
expect(resolve('ui-screen')).toBe('ui-screen');
|
|
146
|
+
} finally {
|
|
147
|
+
rmSync(root, { recursive: true, force: true });
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('MAUDE_HUB_NAMESPACED=1 namespaces from the origin remote', () => {
|
|
152
|
+
const root = makeRepo({
|
|
153
|
+
origin: 'git@github.com:acme/site.git',
|
|
154
|
+
head: 'ref: refs/heads/dev\n',
|
|
155
|
+
});
|
|
156
|
+
try {
|
|
157
|
+
const resolve = createDocNameResolver({ repoRoot: root, flag: '1' });
|
|
158
|
+
expect(resolve('ui-screen')).toBe('ws/acme-site/dev/ui-screen');
|
|
159
|
+
} finally {
|
|
160
|
+
rmSync(root, { recursive: true, force: true });
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('MAUDE_HUB_NAMESPACED=1 with nothing to derive from THROWS, never falls back', () => {
|
|
165
|
+
// A silent fallback here would put a project the operator asked to isolate
|
|
166
|
+
// into the shared flat namespace — the failure mode is worse than a crash.
|
|
167
|
+
const noOrigin = makeRepo();
|
|
168
|
+
const noGit = mkdtempSync(path.join(tmpdir(), 'maude-nogit-'));
|
|
169
|
+
try {
|
|
170
|
+
expect(() => createDocNameResolver({ repoRoot: noOrigin, flag: '1' })).toThrow(
|
|
171
|
+
/workspace id/i
|
|
172
|
+
);
|
|
173
|
+
expect(() =>
|
|
174
|
+
createDocNameResolver({ repoRoot: noGit, flag: '1', explicitWorkspaceId: 'acme' })
|
|
175
|
+
).toThrow(/branch/i);
|
|
176
|
+
} finally {
|
|
177
|
+
rmSync(noOrigin, { recursive: true, force: true });
|
|
178
|
+
rmSync(noGit, { recursive: true, force: true });
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('a branch with a slash is normalized, not rejected', () => {
|
|
183
|
+
const root = makeRepo({ head: 'ref: refs/heads/feature/cloud-arc\n' });
|
|
184
|
+
try {
|
|
185
|
+
const resolve = createDocNameResolver({ repoRoot: root, explicitWorkspaceId: 'acme' });
|
|
186
|
+
expect(resolve('ui-screen')).toBe('ws/acme/feature-cloud-arc/ui-screen');
|
|
187
|
+
} finally {
|
|
188
|
+
rmSync(root, { recursive: true, force: true });
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
describe('doc-name — conformance with the hub implementation', () => {
|
|
194
|
+
const components = [
|
|
195
|
+
'main',
|
|
196
|
+
'feature/cloud-arc',
|
|
197
|
+
'Release/2026.07',
|
|
198
|
+
' --weird-- ',
|
|
199
|
+
'...',
|
|
200
|
+
'',
|
|
201
|
+
'x'.repeat(200),
|
|
202
|
+
'ui-screen',
|
|
203
|
+
'a/b/c',
|
|
204
|
+
];
|
|
205
|
+
|
|
206
|
+
test('sanitizeComponent agrees byte-for-byte', () => {
|
|
207
|
+
for (const c of components) {
|
|
208
|
+
expect(sanitizeComponent(c)).toBe(hub.sanitizeComponent(c));
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('buildDocName agrees, including which inputs throw', () => {
|
|
213
|
+
for (const w of components) {
|
|
214
|
+
for (const b of ['main', '...']) {
|
|
215
|
+
const args = { workspaceId: w, branch: b, slug: 'ui-screen' };
|
|
216
|
+
let mine: string | Error;
|
|
217
|
+
let theirs: string | Error;
|
|
218
|
+
try {
|
|
219
|
+
mine = buildDocName(args);
|
|
220
|
+
} catch (e) {
|
|
221
|
+
mine = e as Error;
|
|
222
|
+
}
|
|
223
|
+
try {
|
|
224
|
+
theirs = hub.buildDocName(args);
|
|
225
|
+
} catch (e) {
|
|
226
|
+
theirs = e as Error;
|
|
227
|
+
}
|
|
228
|
+
if (mine instanceof Error || theirs instanceof Error) {
|
|
229
|
+
expect(mine instanceof Error).toBe(theirs instanceof Error);
|
|
230
|
+
} else {
|
|
231
|
+
expect(mine).toBe(theirs);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('parseDocName agrees over namespaced, legacy, and malformed names', () => {
|
|
238
|
+
const names = [
|
|
239
|
+
'ws/acme/main/ui-screen',
|
|
240
|
+
'ui-screen',
|
|
241
|
+
'',
|
|
242
|
+
'ws/acme/main',
|
|
243
|
+
'ws/acme/main/a/b',
|
|
244
|
+
'x/acme/main/ui',
|
|
245
|
+
'ws//main/ui',
|
|
246
|
+
'ws/acme//ui',
|
|
247
|
+
];
|
|
248
|
+
for (const n of names) {
|
|
249
|
+
expect(parseDocName(n)).toEqual(hub.parseDocName(n));
|
|
250
|
+
expect(isNamespaced(n)).toBe(hub.isNamespaced(n));
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
describe('doc-name — changing identity is safe (DDR-076)', () => {
|
|
256
|
+
test('a freshly namespaced doc is EMPTY, and empty never clobbers local files', () => {
|
|
257
|
+
const root = makeRepo({ origin: 'git@github.com:acme/site.git' });
|
|
258
|
+
try {
|
|
259
|
+
// The rename itself: the same canvas addressed under a new identity.
|
|
260
|
+
const flat = createDocNameResolver({ repoRoot: root });
|
|
261
|
+
const namespaced = createDocNameResolver({ repoRoot: root, flag: '1' });
|
|
262
|
+
expect(flat('ui-screen')).toBe('ui-screen');
|
|
263
|
+
expect(namespaced('ui-screen')).toBe('ws/acme-site/main/ui-screen');
|
|
264
|
+
expect(namespaced('ui-screen')).not.toBe(flat('ui-screen'));
|
|
265
|
+
|
|
266
|
+
// Consequence: on first connect the hub has nothing under the new name.
|
|
267
|
+
// DDR-076 — that means "not seeded yet", never "authoritatively blank".
|
|
268
|
+
const decision = decideColdStart({
|
|
269
|
+
localBody: '<main>real local work</main>',
|
|
270
|
+
docBody: '',
|
|
271
|
+
journalHash: null,
|
|
272
|
+
localMtimeMs: Date.now(),
|
|
273
|
+
docBodyEditAtMs: null,
|
|
274
|
+
});
|
|
275
|
+
expect(decision.action).toBe('seed-local-up');
|
|
276
|
+
expect(decision.winner).toBeUndefined();
|
|
277
|
+
} finally {
|
|
278
|
+
rmSync(root, { recursive: true, force: true });
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
});
|