@1agh/maude 0.48.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/apps/studio/api.ts +18 -2
- package/apps/studio/assets-s3.ts +291 -0
- 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 +1 -1
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/http.ts +45 -0
- 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/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/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/commands/hub-workspace.mjs +341 -0
- package/cli/commands/hub.mjs +325 -3
- package/cli/commands/hub.test.mjs +14 -1
- package/cli/lib/cell-plan.mjs +302 -0
- package/cli/lib/cell-plan.test.mjs +225 -0
- package/cli/lib/gitignore-block.mjs +12 -1
- package/cli/lib/workspace-plan.mjs +422 -0
- package/cli/lib/workspace-plan.test.mjs +223 -0
- package/package.json +8 -8
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// Cloud Phase 3 — the containment invariant's boot-assert (DDR-193 §2).
|
|
2
|
+
//
|
|
3
|
+
// > No tenant-authored TSX is ever evaluated by vendor-operated compute.
|
|
4
|
+
//
|
|
5
|
+
// The thing being tested is a REFUSAL. So the tests that matter are the ones
|
|
6
|
+
// that prove the gate fires: a cell exposing an export route, a canvas shell, a
|
|
7
|
+
// runtime bundle, or shipping Playwright must not be able to start.
|
|
8
|
+
//
|
|
9
|
+
// The negative case matters just as much: none of this may fire outside
|
|
10
|
+
// workspace mode, or every local dev-server stops booting.
|
|
11
|
+
|
|
12
|
+
import { describe, expect, test } from 'bun:test';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
assertContainment,
|
|
16
|
+
checkContainment,
|
|
17
|
+
FORBIDDEN_MODULES,
|
|
18
|
+
FORBIDDEN_ROUTE_PREFIXES,
|
|
19
|
+
formatContainmentFailure,
|
|
20
|
+
isForbiddenRoute,
|
|
21
|
+
isWorkspaceMode,
|
|
22
|
+
pruneForWorkspace,
|
|
23
|
+
} from '../workspace-mode.ts';
|
|
24
|
+
|
|
25
|
+
const CELL = { MAUDE_WORKSPACE_MODE: '1' } as NodeJS.ProcessEnv;
|
|
26
|
+
const LAPTOP = {} as NodeJS.ProcessEnv;
|
|
27
|
+
|
|
28
|
+
/** The routes a cell legitimately serves: sync + git + assets, nothing else. */
|
|
29
|
+
const ALLOWED_ROUTES = [
|
|
30
|
+
'/_health',
|
|
31
|
+
'/_api/asset',
|
|
32
|
+
'/_api/comments',
|
|
33
|
+
'/_api/annotations',
|
|
34
|
+
'/_api/git-committers',
|
|
35
|
+
'/_config',
|
|
36
|
+
'/_ws',
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
describe('workspace mode detection', () => {
|
|
40
|
+
test('only MAUDE_WORKSPACE_MODE=1 turns it on', () => {
|
|
41
|
+
expect(isWorkspaceMode(CELL)).toBe(true);
|
|
42
|
+
expect(isWorkspaceMode(LAPTOP)).toBe(false);
|
|
43
|
+
expect(isWorkspaceMode({ MAUDE_WORKSPACE_MODE: 'true' })).toBe(false);
|
|
44
|
+
expect(isWorkspaceMode({ MAUDE_WORKSPACE_MODE: '0' })).toBe(false);
|
|
45
|
+
expect(isWorkspaceMode({ MAUDE_WORKSPACE_MODE: '' })).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('checkContainment — what a cell may serve', () => {
|
|
50
|
+
test('sync + git + asset routes pass', () => {
|
|
51
|
+
const report = checkContainment(ALLOWED_ROUTES);
|
|
52
|
+
expect(report.ok).toBe(true);
|
|
53
|
+
expect(report.routes).toEqual([]);
|
|
54
|
+
expect(report.modules).toEqual([]);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('every forbidden prefix is caught, and the reason travels with it', () => {
|
|
58
|
+
for (const { prefix, why } of FORBIDDEN_ROUTE_PREFIXES) {
|
|
59
|
+
const report = checkContainment([...ALLOWED_ROUTES, prefix]);
|
|
60
|
+
expect(report.ok).toBe(false);
|
|
61
|
+
expect(report.routes).toHaveLength(1);
|
|
62
|
+
expect(report.routes[0]?.prefix).toBe(prefix);
|
|
63
|
+
// The message has to teach, not just refuse — this is read by someone who
|
|
64
|
+
// added a route in 2027 and has never heard of this invariant.
|
|
65
|
+
expect(report.routes[0]?.why).toBe(why);
|
|
66
|
+
expect(why.length).toBeGreaterThan(20);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('a VARIANT of a forbidden route is still forbidden', () => {
|
|
71
|
+
// The realistic way this gets reintroduced: not `/_api/export` verbatim, but
|
|
72
|
+
// a sibling that does the same thing under a new name.
|
|
73
|
+
for (const route of [
|
|
74
|
+
'/_api/export-jobs',
|
|
75
|
+
'/_api/export/png',
|
|
76
|
+
'/_canvas-shell.html',
|
|
77
|
+
'/_canvas-runtime/react.js',
|
|
78
|
+
'/_ws/acp',
|
|
79
|
+
]) {
|
|
80
|
+
const report = checkContainment([...ALLOWED_ROUTES, route]);
|
|
81
|
+
expect(report.ok).toBe(false);
|
|
82
|
+
expect(report.routes[0]?.route).toBe(route);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('a route that merely CONTAINS a forbidden word is not a false positive', () => {
|
|
87
|
+
// Prefix matching, not substring — `/_api/asset` must not trip on nothing,
|
|
88
|
+
// and a route about exports in its docs must not be blocked by name alone.
|
|
89
|
+
const report = checkContainment([
|
|
90
|
+
'/_api/asset',
|
|
91
|
+
'/_api/export-history-docs-link',
|
|
92
|
+
'/_api/no-export',
|
|
93
|
+
'/_api/git-export-status',
|
|
94
|
+
]);
|
|
95
|
+
expect(report.routes.map((r) => r.route)).toEqual(['/_api/export-history-docs-link']);
|
|
96
|
+
// ...that one DOES start with /_api/export, and being caught is correct:
|
|
97
|
+
// a surface named "export-*" is exactly what needs a human to look at it.
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('a resolvable browser automation module fails the check', () => {
|
|
101
|
+
const report = checkContainment(ALLOWED_ROUTES, {
|
|
102
|
+
resolveModule: (s) => s === 'playwright',
|
|
103
|
+
});
|
|
104
|
+
expect(report.ok).toBe(false);
|
|
105
|
+
expect(report.modules).toEqual(['playwright']);
|
|
106
|
+
// All four are checked, not just the popular one.
|
|
107
|
+
const all = checkContainment(ALLOWED_ROUTES, { resolveModule: () => true });
|
|
108
|
+
expect(all.modules).toEqual([...FORBIDDEN_MODULES]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('no resolver supplied ⇒ modules are simply not checked (not silently passed)', () => {
|
|
112
|
+
const report = checkContainment(ALLOWED_ROUTES);
|
|
113
|
+
expect(report.modules).toEqual([]);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe('assertContainment — the boot gate', () => {
|
|
118
|
+
test('OUTSIDE workspace mode it never fires, whatever is exposed', () => {
|
|
119
|
+
// A developer's laptop serves every one of these. If the gate fired here,
|
|
120
|
+
// the entire local product would stop booting.
|
|
121
|
+
expect(() =>
|
|
122
|
+
assertContainment([...ALLOWED_ROUTES, ...FORBIDDEN_ROUTE_PREFIXES.map((f) => f.prefix)], {
|
|
123
|
+
env: LAPTOP,
|
|
124
|
+
resolveModule: () => true,
|
|
125
|
+
})
|
|
126
|
+
).not.toThrow();
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('in a cell, a clean route table starts', () => {
|
|
130
|
+
expect(() => assertContainment(ALLOWED_ROUTES, { env: CELL })).not.toThrow();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('in a cell, an export route REFUSES TO START', () => {
|
|
134
|
+
expect(() => assertContainment([...ALLOWED_ROUTES, '/_api/export'], { env: CELL })).toThrow(
|
|
135
|
+
/REFUSING TO START/
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('in a cell, shipping Playwright REFUSES TO START even with clean routes', () => {
|
|
140
|
+
expect(() =>
|
|
141
|
+
assertContainment(ALLOWED_ROUTES, { env: CELL, resolveModule: (s) => s === 'playwright' })
|
|
142
|
+
).toThrow(/playwright/);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('the failure message names the surface, the reason, and the way out', () => {
|
|
146
|
+
let message = '';
|
|
147
|
+
try {
|
|
148
|
+
assertContainment([...ALLOWED_ROUTES, '/_canvas-shell.html'], { env: CELL });
|
|
149
|
+
} catch (err) {
|
|
150
|
+
message = (err as Error).message;
|
|
151
|
+
}
|
|
152
|
+
expect(message).toContain('/_canvas-shell.html');
|
|
153
|
+
expect(message).toContain('DDR-193');
|
|
154
|
+
expect(message).toContain('executes a canvas module');
|
|
155
|
+
// The escape hatch is named so the next engineer doesn't invent a flag.
|
|
156
|
+
expect(message).toContain('Direction B');
|
|
157
|
+
expect(message).toContain('HARD PREREQUISITE');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('formatContainmentFailure reports routes and modules together', () => {
|
|
161
|
+
const report = checkContainment([...ALLOWED_ROUTES, '/_api/export'], {
|
|
162
|
+
resolveModule: (s) => s === 'puppeteer',
|
|
163
|
+
});
|
|
164
|
+
const message = formatContainmentFailure(report);
|
|
165
|
+
expect(message).toContain('/_api/export');
|
|
166
|
+
expect(message).toContain('puppeteer');
|
|
167
|
+
expect(message).toContain('Reachable routes');
|
|
168
|
+
expect(message).toContain('Modules that resolve');
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe('the vocabulary itself', () => {
|
|
173
|
+
test('the forbidden set covers every way a cell could evaluate tenant code', () => {
|
|
174
|
+
// Pinned deliberately: the realistic loss of this invariant is a refactor
|
|
175
|
+
// quietly dropping an entry while every other test stays green. Changing
|
|
176
|
+
// this list should require changing this test, on purpose.
|
|
177
|
+
expect(FORBIDDEN_ROUTE_PREFIXES.map((f) => f.prefix).sort()).toEqual([
|
|
178
|
+
'/_api/export',
|
|
179
|
+
'/_api/generate',
|
|
180
|
+
'/_api/photo-edit',
|
|
181
|
+
'/_canvas-runtime',
|
|
182
|
+
'/_canvas-shell',
|
|
183
|
+
'/_ws/acp',
|
|
184
|
+
]);
|
|
185
|
+
expect([...FORBIDDEN_MODULES].sort()).toEqual([
|
|
186
|
+
'playwright',
|
|
187
|
+
'playwright-core',
|
|
188
|
+
'puppeteer',
|
|
189
|
+
'puppeteer-core',
|
|
190
|
+
]);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe('pruneForWorkspace — how a cell can boot at all', () => {
|
|
195
|
+
test('keeps the sync/git/asset surface and removes exactly the forbidden one', () => {
|
|
196
|
+
const table = {
|
|
197
|
+
'/_health': 'h',
|
|
198
|
+
'/_api/asset': 'a',
|
|
199
|
+
'/_api/comments': 'c',
|
|
200
|
+
'/_api/git-committers': 'g',
|
|
201
|
+
'/_api/export': 'x',
|
|
202
|
+
'/_api/export-jobs': 'x2',
|
|
203
|
+
'/_api/photo-edit': 'p',
|
|
204
|
+
'/_api/generate/keys': 'k',
|
|
205
|
+
};
|
|
206
|
+
const { routes, removed } = pruneForWorkspace(table);
|
|
207
|
+
|
|
208
|
+
expect(Object.keys(routes).sort()).toEqual([
|
|
209
|
+
'/_api/asset',
|
|
210
|
+
'/_api/comments',
|
|
211
|
+
'/_api/git-committers',
|
|
212
|
+
'/_health',
|
|
213
|
+
]);
|
|
214
|
+
expect(removed).toEqual([
|
|
215
|
+
'/_api/export',
|
|
216
|
+
'/_api/export-jobs',
|
|
217
|
+
'/_api/generate/keys',
|
|
218
|
+
'/_api/photo-edit',
|
|
219
|
+
]);
|
|
220
|
+
// Handlers are carried through by reference — pruning must not rebuild them.
|
|
221
|
+
expect(routes['/_api/asset']).toBe('a');
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test('the pruned table then PASSES the boot assert — prune and assert agree', () => {
|
|
225
|
+
// This is the whole design: the assert is a post-condition on the pruning,
|
|
226
|
+
// so a prefix added to the vocabulary both prunes and is verified, and the
|
|
227
|
+
// two can never drift into disagreeing.
|
|
228
|
+
const table = Object.fromEntries(
|
|
229
|
+
[...FORBIDDEN_ROUTE_PREFIXES.map((f) => f.prefix), '/_health', '/_api/asset'].map((r) => [
|
|
230
|
+
r,
|
|
231
|
+
() => {},
|
|
232
|
+
])
|
|
233
|
+
);
|
|
234
|
+
const { routes } = pruneForWorkspace(table);
|
|
235
|
+
expect(() => assertContainment(Object.keys(routes), { env: CELL })).not.toThrow();
|
|
236
|
+
// ...and the unpruned table would have refused.
|
|
237
|
+
expect(() => assertContainment(Object.keys(table), { env: CELL })).toThrow(/REFUSING TO START/);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
test('pruning an already-clean table is a no-op', () => {
|
|
241
|
+
const table = Object.fromEntries(ALLOWED_ROUTES.map((r) => [r, () => {}]));
|
|
242
|
+
const { routes, removed } = pruneForWorkspace(table);
|
|
243
|
+
expect(removed).toEqual([]);
|
|
244
|
+
expect(Object.keys(routes).sort()).toEqual([...ALLOWED_ROUTES].sort());
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test('isForbiddenRoute is the single predicate both the table and fetch use', () => {
|
|
248
|
+
// The `fetch` fall-through owns paths that are not in the route table
|
|
249
|
+
// (/_ws/acp, /_canvas-shell.html, /_canvas-runtime/*), so it gates on this
|
|
250
|
+
// same function. One predicate, so the two gates cannot disagree.
|
|
251
|
+
expect(isForbiddenRoute('/_canvas-shell.html')).toBe(true);
|
|
252
|
+
expect(isForbiddenRoute('/_canvas-runtime/react.js')).toBe(true);
|
|
253
|
+
expect(isForbiddenRoute('/_ws/acp')).toBe(true);
|
|
254
|
+
expect(isForbiddenRoute('/_ws')).toBe(false);
|
|
255
|
+
expect(isForbiddenRoute('/_health')).toBe(false);
|
|
256
|
+
expect(isForbiddenRoute('/_api/asset')).toBe(false);
|
|
257
|
+
});
|
|
258
|
+
});
|