@milesroxas/design-hub 0.11.2 → 0.13.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 +8 -6
- package/core/prototype.test.ts +52 -0
- package/core/prototype.ts +59 -0
- package/core/review/model.ts +20 -0
- package/core/review/service.test.ts +262 -37
- package/core/review/service.ts +276 -52
- package/core/review/store.ts +12 -6
- package/core/review/suite-kv.ts +17 -0
- package/dist/core/prototype.d.ts +50 -0
- package/dist/core/prototype.js +38 -0
- package/dist/core/review/model.d.ts +22 -0
- package/dist/core/review/model.js +8 -0
- package/dist/core/review/service.d.ts +98 -18
- package/dist/core/review/service.js +248 -46
- package/dist/core/review/store.d.ts +10 -4
- package/dist/core/review/store.js +2 -2
- package/dist/core/review/suite-kv.d.ts +7 -0
- package/dist/core/review/suite-kv.js +12 -0
- package/dist/scripts/client.d.ts +3 -3
- package/dist/scripts/client.js +55 -69
- package/dist/scripts/lib/cli.js +5 -0
- package/dist/scripts/lib/dns.d.ts +32 -0
- package/dist/scripts/lib/dns.js +69 -1
- package/dist/scripts/lib/fake-host.d.ts +35 -11
- package/dist/scripts/lib/fake-host.js +27 -13
- package/dist/scripts/lib/host.d.ts +13 -25
- package/dist/scripts/lib/host.js +15 -324
- package/dist/scripts/lib/studio-deps.d.ts +16 -0
- package/dist/scripts/lib/studio-deps.js +41 -16
- package/dist/scripts/lib/studios.d.ts +17 -5
- package/dist/scripts/lib/studios.js +25 -5
- package/dist/scripts/lib/vercel-host.d.ts +17 -0
- package/dist/scripts/lib/vercel-host.js +410 -0
- package/dist/scripts/people.d.ts +7 -4
- package/dist/scripts/people.js +147 -39
- package/dist/scripts/share.js +3 -2
- package/dist/scripts/studio.d.ts +10 -4
- package/dist/scripts/studio.js +136 -22
- package/dist/server/api.d.ts +12 -13
- package/dist/server/api.js +141 -52
- package/dist/server/gate.d.ts +97 -0
- package/dist/server/gate.js +537 -0
- package/dist/server/hosts.d.ts +3 -3
- package/dist/server/hosts.js +10 -10
- package/dist/server/mark.d.ts +17 -0
- package/dist/server/mark.js +46 -1
- package/dist/server/session.d.ts +9 -1
- package/dist/server/session.js +10 -3
- package/dist/server/stores/backends.d.ts +22 -0
- package/dist/server/stores/backends.js +96 -0
- package/dist/server/{fake-upstash.js → stores/fake-upstash.js} +1 -1
- package/dist/server/stores/index.d.ts +41 -0
- package/dist/server/stores/index.js +63 -0
- package/dist/server/stores/pglite.d.ts +16 -0
- package/dist/server/stores/pglite.js +98 -0
- package/dist/server/stores/postgres.d.ts +63 -0
- package/dist/server/stores/postgres.js +153 -0
- package/dist/server/{upstash.d.ts → stores/upstash.d.ts} +1 -1
- package/dist/vercel/files.js +1 -1
- package/dist/vercel/proxy.d.ts +6 -78
- package/dist/vercel/proxy.js +18 -359
- package/dist/vite/plugin.d.ts +6 -2
- package/dist/vite/plugin.js +22 -4
- package/package.json +3 -1
- package/shell/Index.tsx +29 -0
- package/shell/review/People.tsx +79 -49
- package/shell/review/Review.tsx +49 -1
- package/shell/review/ThreadCard.tsx +13 -1
- package/shell/review/client.ts +54 -21
- package/shell/review/review.css +1 -0
- package/shell/review/unsent.test.ts +63 -0
- package/shell/review/unsent.ts +64 -0
- package/shell/review/view.ts +22 -6
- package/shell/studio/ClientHub.tsx +9 -36
- package/shell/studio/StudioHub.tsx +293 -0
- package/shell/studio/hub.css +80 -5
- package/shell/studio/page.tsx +57 -0
- package/shell/studio/studio.html +14 -0
- package/shell/studio/studio.tsx +19 -0
- package/skills/miles-deploy/SKILL.md +17 -6
- package/skills/miles-design-hub/SKILL.md +3 -3
- package/skills/miles-review/SKILL.md +1 -1
- package/templates/studio/.env.example +3 -0
- package/templates/studio/README.md +45 -13
- package/templates/studio/package.json +1 -1
- /package/dist/server/{fake-upstash.d.ts → stores/fake-upstash.d.ts} +0 -0
- /package/dist/server/{upstash.js → stores/upstash.js} +0 -0
|
@@ -2,7 +2,8 @@ import assert from 'node:assert/strict';
|
|
|
2
2
|
import { beforeEach, test } from 'node:test';
|
|
3
3
|
import { type Anchor, accessEnd, type Comment, type Person, type Scope, threadLabel } from './model.ts';
|
|
4
4
|
import { createReview, REUSE_SECONDS, type Review, ReviewError } from './service.ts';
|
|
5
|
-
import { type KV, keyOf,
|
|
5
|
+
import { type KV, keyOf, type Snapshot } from './store.ts';
|
|
6
|
+
import { suiteKV } from './suite-kv.ts';
|
|
6
7
|
|
|
7
8
|
const anchor: Anchor = {
|
|
8
9
|
prototype: 'sample-list',
|
|
@@ -55,7 +56,7 @@ const LIVE = live('acme', 'bravo');
|
|
|
55
56
|
|
|
56
57
|
beforeEach(async () => {
|
|
57
58
|
clock = Date.parse('2030-01-01T00:00:00Z');
|
|
58
|
-
review = createReview(
|
|
59
|
+
review = createReview(suiteKV(LIVE), {
|
|
59
60
|
now: () => {
|
|
60
61
|
clock += 1000;
|
|
61
62
|
return new Date(clock);
|
|
@@ -144,7 +145,7 @@ test('a revoke ends every session and link, and a revoked person gets no new lin
|
|
|
144
145
|
});
|
|
145
146
|
|
|
146
147
|
test('a store failure before the claim leaves the link usable', async () => {
|
|
147
|
-
const kv =
|
|
148
|
+
const kv = suiteKV(LIVE);
|
|
148
149
|
let failPeople = false;
|
|
149
150
|
const flaky: KV = {
|
|
150
151
|
...kv,
|
|
@@ -165,7 +166,7 @@ test('a store failure before the claim leaves the link usable', async () => {
|
|
|
165
166
|
test('the store never holds a link token in clear', async () => {
|
|
166
167
|
let seen: Snapshot = { hashes: {}, sets: {} };
|
|
167
168
|
const r = createReview(
|
|
168
|
-
|
|
169
|
+
suiteKV(LIVE, (snapshot) => {
|
|
169
170
|
seen = snapshot;
|
|
170
171
|
}),
|
|
171
172
|
);
|
|
@@ -183,7 +184,7 @@ test('the store never holds a link token in clear', async () => {
|
|
|
183
184
|
|
|
184
185
|
test('a revoke writes revocation and epoch, never the profile, before it drops their links', async () => {
|
|
185
186
|
const writes: string[] = [];
|
|
186
|
-
const kv =
|
|
187
|
+
const kv = suiteKV(LIVE);
|
|
187
188
|
const watched: KV = {
|
|
188
189
|
...kv,
|
|
189
190
|
hset: async (key, field, value) => {
|
|
@@ -216,7 +217,7 @@ test('a revoke writes revocation and epoch, never the profile, before it drops t
|
|
|
216
217
|
* until the test releases it: a real interleaving, not two calls in a row.
|
|
217
218
|
*/
|
|
218
219
|
function pausingKV() {
|
|
219
|
-
const kv =
|
|
220
|
+
const kv = suiteKV(LIVE);
|
|
220
221
|
let arm = false;
|
|
221
222
|
let reached = () => {};
|
|
222
223
|
let release = () => {};
|
|
@@ -330,7 +331,7 @@ for (const [what, run] of [
|
|
|
330
331
|
['a sign out everywhere', (r: Review, root: Person, id: string) => r.signOutEverywhere(A, root, id)],
|
|
331
332
|
] as const)
|
|
332
333
|
test(`a link used while ${what} lands signs nobody in`, async () => {
|
|
333
|
-
const { store, arm, pauses } = pausing(
|
|
334
|
+
const { store, arm, pauses } = pausing(suiteKV(LIVE), {
|
|
334
335
|
claim: { method: 'hdel', key: keyOf(A, 'links') },
|
|
335
336
|
drop: { method: 'hgetall', key: keyOf(A, 'links') },
|
|
336
337
|
});
|
|
@@ -353,7 +354,7 @@ for (const [what, run] of [
|
|
|
353
354
|
});
|
|
354
355
|
|
|
355
356
|
test('any revocation record means revoked, and an access end that does not parse means no access', async () => {
|
|
356
|
-
const kv =
|
|
357
|
+
const kv = suiteKV(LIVE);
|
|
357
358
|
const r = createReview(kv);
|
|
358
359
|
const root = { ...studio, id: 'cli' };
|
|
359
360
|
const a = (await r.addPerson(A, root, { name: 'Rae', team: 'Acme' })).person;
|
|
@@ -369,7 +370,7 @@ test('any revocation record means revoked, and an access end that does not parse
|
|
|
369
370
|
});
|
|
370
371
|
|
|
371
372
|
test('a profile that is not a well-formed person is no person, and listPeople skips it', async () => {
|
|
372
|
-
const kv =
|
|
373
|
+
const kv = suiteKV(LIVE);
|
|
373
374
|
const r = createReview(kv);
|
|
374
375
|
const root = { ...studio, id: 'cli' };
|
|
375
376
|
const { person } = await r.addPerson(A, root, { name: 'Rae', team: 'Acme' });
|
|
@@ -411,7 +412,7 @@ test('two sign outs everywhere at once both end the earlier sessions', async ()
|
|
|
411
412
|
});
|
|
412
413
|
|
|
413
414
|
test('a profile write never carries revocation or epoch', async () => {
|
|
414
|
-
const kv =
|
|
415
|
+
const kv = suiteKV(LIVE);
|
|
415
416
|
const r = createReview(kv);
|
|
416
417
|
const root = { ...studio, id: 'cli' };
|
|
417
418
|
const { person } = await r.addPerson(A, root, { name: 'Rae', team: 'Acme' });
|
|
@@ -543,7 +544,7 @@ test('records under an older key prefix are never read: the unscoped hub3 store
|
|
|
543
544
|
);
|
|
544
545
|
const link = JSON.stringify({ person: 'old', expiresAt: '2999-01-01T00:00:00Z' });
|
|
545
546
|
const comment = JSON.stringify({ id: 'x', thread: 'x', audience: 'client', anchor });
|
|
546
|
-
const kv =
|
|
547
|
+
const kv = suiteKV({
|
|
547
548
|
hashes: {
|
|
548
549
|
...LIVE.hashes,
|
|
549
550
|
'hub3:people': { old: JSON.stringify(profile) },
|
|
@@ -615,7 +616,7 @@ test('bad input names every problem', async () => {
|
|
|
615
616
|
|
|
616
617
|
test('triage runs on add, and a failing triager never loses the comment', async () => {
|
|
617
618
|
const seen: string[][] = [];
|
|
618
|
-
const triaged = createReview(
|
|
619
|
+
const triaged = createReview(suiteKV(LIVE), {
|
|
619
620
|
triage: async ({ states }) => {
|
|
620
621
|
seen.push(states);
|
|
621
622
|
return { kind: 'bug', state: states[0] ?? null, by: 'jev', confidence: 0.9 };
|
|
@@ -629,7 +630,7 @@ test('triage runs on add, and a failing triager never loses the comment', async
|
|
|
629
630
|
});
|
|
630
631
|
assert.deepEqual(seen, [['Empty', 'Real list']]);
|
|
631
632
|
assert.equal(c.triage?.kind, 'bug');
|
|
632
|
-
const failing = createReview(
|
|
633
|
+
const failing = createReview(suiteKV(LIVE), { triage: async () => Promise.reject(new Error('down')) });
|
|
633
634
|
await failing.setAudience(A, studio, anchor.prototype, 'client');
|
|
634
635
|
assert.equal((await failing.add(A, client, { body: 'Still saved', anchor })).triage, null);
|
|
635
636
|
});
|
|
@@ -795,7 +796,7 @@ test('numbers count per prototype', async () => {
|
|
|
795
796
|
});
|
|
796
797
|
|
|
797
798
|
test('the internal count starts past internal threads numbered while the two shared one count', async () => {
|
|
798
|
-
const kv =
|
|
799
|
+
const kv = suiteKV(LIVE);
|
|
799
800
|
const r = createReview(kv);
|
|
800
801
|
const root = { ...studio, id: 'cli' };
|
|
801
802
|
// Under one shared count: internal 1, client-facing 2, internal 3.
|
|
@@ -830,7 +831,7 @@ test('the internal count starts past internal threads numbered while the two sha
|
|
|
830
831
|
});
|
|
831
832
|
|
|
832
833
|
test('a stored comment without an audience is internal, and one without a number has none', async () => {
|
|
833
|
-
const kv =
|
|
834
|
+
const kv = suiteKV(LIVE);
|
|
834
835
|
const r = createReview(kv);
|
|
835
836
|
const root = { ...studio, id: 'cli' };
|
|
836
837
|
const rae = (await r.addPerson(A, root, { name: 'Rae', team: 'Acme' })).person;
|
|
@@ -878,7 +879,7 @@ test('a prototype is internal until Studio marks it client-facing, and internal
|
|
|
878
879
|
});
|
|
879
880
|
|
|
880
881
|
test('only client-facing is stored: internal deletes the field, and absent or garbage reads as internal', async () => {
|
|
881
|
-
const kv =
|
|
882
|
+
const kv = suiteKV(LIVE);
|
|
882
883
|
const own = createReview(kv);
|
|
883
884
|
await own.setAudience(A, studio, 'secret-plan', 'client');
|
|
884
885
|
assert.deepEqual(await kv.hgetall(keyOf(A, 'audiences')), { 'secret-plan': 'client' });
|
|
@@ -1011,7 +1012,7 @@ test('a Client acting on a client-facing thread of an internal prototype is told
|
|
|
1011
1012
|
|
|
1012
1013
|
// Slice 6: what Studio marks on a prototype's dials and variants.
|
|
1013
1014
|
test('controls: Studio marks a dial either way and a variant on or off, one field each', async () => {
|
|
1014
|
-
const kv =
|
|
1015
|
+
const kv = suiteKV(LIVE);
|
|
1015
1016
|
const own = createReview(kv);
|
|
1016
1017
|
const mark = (kind: string, id: string, audience: string) =>
|
|
1017
1018
|
own.setControl(A, studio, { prototype: 'sample-list', kind, id, audience });
|
|
@@ -1195,6 +1196,13 @@ const STUDIO_WIDE: [string, (actor: Person | null) => Promise<unknown>][] = [
|
|
|
1195
1196
|
['studioAccess', (a) => review.studioAccess(a)],
|
|
1196
1197
|
['setStudioAccess', (a) => review.setStudioAccess(a, 'open')],
|
|
1197
1198
|
['clientWait', (a) => review.clientWait(a, { slug: 'acme', host: 'acme.studio.test' })],
|
|
1199
|
+
['setStudioHost', (a) => review.setStudioHost(a, 'studio.studio.test')],
|
|
1200
|
+
['listClients', (a) => review.listClients(a)],
|
|
1201
|
+
['startHandoff', (a) => review.startHandoff(a, { client: 'acme', project: null })],
|
|
1202
|
+
['studioClient', (a) => review.studioClient(a, 'acme')],
|
|
1203
|
+
['studioHostProven', (a) => review.studioHostProven(a)],
|
|
1204
|
+
['startStudioProof', (a) => review.startStudioProof(a)],
|
|
1205
|
+
['endStudioProof', (a) => review.endStudioProof(a)],
|
|
1198
1206
|
];
|
|
1199
1207
|
/** The ops that name an id, whose answer to an unknown one is what out of scope must match. */
|
|
1200
1208
|
const BY_ID = new Set([
|
|
@@ -1218,19 +1226,22 @@ const ACTORLESS = [
|
|
|
1218
1226
|
'useLink',
|
|
1219
1227
|
'audienceOf',
|
|
1220
1228
|
'clientOfHost',
|
|
1229
|
+
'siteOfHost',
|
|
1221
1230
|
'projectOf',
|
|
1222
1231
|
'proofAnswer',
|
|
1232
|
+
'claimHandoff',
|
|
1233
|
+
'studioProofAnswer',
|
|
1223
1234
|
];
|
|
1224
1235
|
|
|
1225
1236
|
test('every op of the review service is in the cross-client test or named as having no actor', () => {
|
|
1226
1237
|
const listed = [...OPS.map(([name]) => name), ...STUDIO_WIDE.map(([name]) => name), ...ACTORLESS].sort();
|
|
1227
|
-
assert.deepEqual(Object.keys(createReview(
|
|
1238
|
+
assert.deepEqual(Object.keys(createReview(suiteKV())).sort(), listed);
|
|
1228
1239
|
});
|
|
1229
1240
|
|
|
1230
1241
|
test('every op from client A’s person on client B’s scope answers as an unknown id does, and changes nothing', async () => {
|
|
1231
1242
|
let snapshot = '';
|
|
1232
1243
|
review = createReview(
|
|
1233
|
-
|
|
1244
|
+
suiteKV(live('acme'), (s) => {
|
|
1234
1245
|
snapshot = JSON.stringify(s);
|
|
1235
1246
|
}),
|
|
1236
1247
|
);
|
|
@@ -1264,7 +1275,7 @@ const ON_RECORD = new Set(['addClient', 'clientRecord', 'archiveClient', 'forget
|
|
|
1264
1275
|
test('every op in a client archived, forgotten or never added answers as an unknown id, and writes nothing', async () => {
|
|
1265
1276
|
let snapshot = '';
|
|
1266
1277
|
review = createReview(
|
|
1267
|
-
|
|
1278
|
+
suiteKV(undefined, (s) => {
|
|
1268
1279
|
snapshot = JSON.stringify(s);
|
|
1269
1280
|
}),
|
|
1270
1281
|
);
|
|
@@ -1291,7 +1302,7 @@ test('every op in a client archived, forgotten or never added answers as an unkn
|
|
|
1291
1302
|
|
|
1292
1303
|
test('a client added over keys an earlier client of its slug left starts clean, every kind of key', async () => {
|
|
1293
1304
|
let seen: Snapshot = { hashes: {}, sets: {} };
|
|
1294
|
-
const kv =
|
|
1305
|
+
const kv = suiteKV(undefined, (s) => {
|
|
1295
1306
|
seen = s;
|
|
1296
1307
|
});
|
|
1297
1308
|
const r = createReview(kv);
|
|
@@ -1363,7 +1374,7 @@ test('a client added over keys an earlier client of its slug left starts clean,
|
|
|
1363
1374
|
});
|
|
1364
1375
|
|
|
1365
1376
|
test('the local store’s client, which has no record, runs every op as before, and no studio may add a client by its name', async () => {
|
|
1366
|
-
const kv =
|
|
1377
|
+
const kv = suiteKV();
|
|
1367
1378
|
const r = createReview(kv);
|
|
1368
1379
|
const SITE: Scope = { client: 'site', project: 'site' };
|
|
1369
1380
|
const ed = (
|
|
@@ -1444,7 +1455,7 @@ test('a project’s comments, numbers, marks and audiences are its own, the same
|
|
|
1444
1455
|
test('every record lives under its own scope’s keys, and Studio’s under the studio’s', async () => {
|
|
1445
1456
|
let seen: Snapshot = { hashes: {}, sets: {} };
|
|
1446
1457
|
review = createReview(
|
|
1447
|
-
|
|
1458
|
+
suiteKV(undefined, (s) => {
|
|
1448
1459
|
seen = s;
|
|
1449
1460
|
}),
|
|
1450
1461
|
);
|
|
@@ -1488,7 +1499,7 @@ test('every record lives under its own scope’s keys, and Studio’s under the
|
|
|
1488
1499
|
});
|
|
1489
1500
|
|
|
1490
1501
|
test('a profile stored at the wrong home is no person: a Client with the studio, Studio with a client', async () => {
|
|
1491
|
-
const kv =
|
|
1502
|
+
const kv = suiteKV(LIVE);
|
|
1492
1503
|
const r = createReview(kv);
|
|
1493
1504
|
const rae = (await r.addPerson(A, studio, { name: 'Rae', team: 'Acme' })).person;
|
|
1494
1505
|
const profile = JSON.parse((await kv.hget(keyOf(A, 'people'), rae.id)) ?? '{}');
|
|
@@ -1505,7 +1516,7 @@ test('a profile stored at the wrong home is no person: a Client with the studio,
|
|
|
1505
1516
|
});
|
|
1506
1517
|
|
|
1507
1518
|
test('a host names its client while the client is live and its records agree; anything else is no client', async () => {
|
|
1508
|
-
review = createReview(
|
|
1519
|
+
review = createReview(suiteKV());
|
|
1509
1520
|
const acme = await review.addClient(studio, { slug: 'acme', host: 'acme.studio.test', name: 'Acme' });
|
|
1510
1521
|
assert.deepEqual(acme, {
|
|
1511
1522
|
slug: 'acme',
|
|
@@ -1521,7 +1532,7 @@ test('a host names its client while the client is live and its records agree; an
|
|
|
1521
1532
|
for (const host of ['', 'nope.studio.test', 'studio.test', 'acme.studio.test.evil', 'a b'])
|
|
1522
1533
|
assert.equal(await review.clientOfHost(host), null, host);
|
|
1523
1534
|
// A host table entry the client's own record does not agree with, or an archived client, is no client.
|
|
1524
|
-
const kv =
|
|
1535
|
+
const kv = suiteKV();
|
|
1525
1536
|
const r = createReview(kv);
|
|
1526
1537
|
await r.addClient(studio, { slug: 'acme', host: 'acme.studio.test', name: 'Acme' });
|
|
1527
1538
|
await kv.hset(keyOf('studio', 'hosts'), 'alias.studio.test', 'acme');
|
|
@@ -1536,7 +1547,7 @@ test('a host names its client while the client is live and its records agree; an
|
|
|
1536
1547
|
});
|
|
1537
1548
|
|
|
1538
1549
|
test('a client is Studio’s to add, with a slug and a host nobody has, and never a name the studio keeps', async () => {
|
|
1539
|
-
review = createReview(
|
|
1550
|
+
review = createReview(suiteKV());
|
|
1540
1551
|
await review.addClient(studio, { slug: 'acme', host: 'acme.studio.test', name: 'Acme' });
|
|
1541
1552
|
await rejects(review.addClient(studio, { slug: 'acme', host: 'other.studio.test', name: 'A' }), 'invalid');
|
|
1542
1553
|
await rejects(review.addClient(studio, { slug: 'other', host: 'acme.studio.test', name: 'A' }), 'invalid');
|
|
@@ -1552,7 +1563,7 @@ test('a client is Studio’s to add, with a slug and a host nobody has, and neve
|
|
|
1552
1563
|
});
|
|
1553
1564
|
|
|
1554
1565
|
test('a project is its client’s: listed with a build, opened only from its own client', async () => {
|
|
1555
|
-
review = createReview(
|
|
1566
|
+
review = createReview(suiteKV());
|
|
1556
1567
|
const acme = { client: 'acme' };
|
|
1557
1568
|
await rejects(review.addProject(acme, studio, { slug: 'rebrand', name: 'Rebrand' }), 'not_found');
|
|
1558
1569
|
await review.addClient(studio, { slug: 'acme', host: 'acme.studio.test', name: 'Acme' });
|
|
@@ -1603,7 +1614,7 @@ test('a project is its client’s: listed with a build, opened only from its own
|
|
|
1603
1614
|
test('a Client is refused every studio-wide op, and a signed-out caller is unauthorized, with nothing written', async () => {
|
|
1604
1615
|
let snapshot = '';
|
|
1605
1616
|
review = createReview(
|
|
1606
|
-
|
|
1617
|
+
suiteKV(LIVE, (x) => {
|
|
1607
1618
|
snapshot = JSON.stringify(x);
|
|
1608
1619
|
}),
|
|
1609
1620
|
);
|
|
@@ -1688,7 +1699,7 @@ test('the People tab’s default access reads and sets the same value: the clien
|
|
|
1688
1699
|
});
|
|
1689
1700
|
|
|
1690
1701
|
test('of two adds at once, one gets the slug and one the host; the other is refused and holds nothing', async () => {
|
|
1691
|
-
review = createReview(
|
|
1702
|
+
review = createReview(suiteKV());
|
|
1692
1703
|
const make = (slug: string, host: string) => outcome(review.addClient(studio, { slug, host, name: slug }));
|
|
1693
1704
|
const sameSlug = await Promise.all([make('acme', 'one.studio.test'), make('acme', 'two.studio.test')]);
|
|
1694
1705
|
assert.equal(sameSlug.filter((o) => 'value' in o).length, 1);
|
|
@@ -1710,7 +1721,7 @@ test('of two adds at once, one gets the slug and one the host; the other is refu
|
|
|
1710
1721
|
});
|
|
1711
1722
|
|
|
1712
1723
|
test('archiving a client removes every key it has, so the slug and host start clean when added again', async () => {
|
|
1713
|
-
const kv =
|
|
1724
|
+
const kv = suiteKV();
|
|
1714
1725
|
const tick = () => {
|
|
1715
1726
|
clock += 1000;
|
|
1716
1727
|
return new Date(clock);
|
|
@@ -1801,7 +1812,7 @@ test('archiving a client removes every key it has, so the slug and host start cl
|
|
|
1801
1812
|
});
|
|
1802
1813
|
|
|
1803
1814
|
test('an archive keeps a host another client has, and frees a slug or host whose add stopped part way', async () => {
|
|
1804
|
-
const kv =
|
|
1815
|
+
const kv = suiteKV();
|
|
1805
1816
|
let now = Date.parse('2030-01-01T00:00:00Z');
|
|
1806
1817
|
const r = createReview(kv, { now: () => new Date(now) });
|
|
1807
1818
|
const record = (slug: string, host: string) =>
|
|
@@ -1861,7 +1872,7 @@ test('an archive keeps a host another client has, and frees a slug or host whose
|
|
|
1861
1872
|
});
|
|
1862
1873
|
|
|
1863
1874
|
test('a host proof is Studio’s to start and end, answers only its own ask in its own client, and keeps no ask', async () => {
|
|
1864
|
-
const kv =
|
|
1875
|
+
const kv = suiteKV();
|
|
1865
1876
|
const r = createReview(kv);
|
|
1866
1877
|
await r.addClient(studio, { slug: 'acme', host: 'acme.studio.test', name: 'Acme' });
|
|
1867
1878
|
await r.addClient(studio, { slug: 'bravo', host: 'bravo.studio.test', name: 'Bravo' });
|
|
@@ -1939,7 +1950,7 @@ for (const lands of ['during the archive', 'after the forget'] as const)
|
|
|
1939
1950
|
return new Date(at);
|
|
1940
1951
|
},
|
|
1941
1952
|
};
|
|
1942
|
-
const kv =
|
|
1953
|
+
const kv = suiteKV();
|
|
1943
1954
|
const held = holdingKV(kv);
|
|
1944
1955
|
const site = createReview(held.kv, deps);
|
|
1945
1956
|
const cli = createReview(kv, deps);
|
|
@@ -1983,7 +1994,7 @@ for (const lands of ['during the archive', 'after the forget'] as const)
|
|
|
1983
1994
|
test('a sweep reaches its own scope’s keys only: never acme-two’s, a sibling project’s, the studio’s or the directory’s', async () => {
|
|
1984
1995
|
let at = Date.parse('2030-01-01T00:00:00Z');
|
|
1985
1996
|
let seen: Snapshot = { hashes: {}, sets: {} };
|
|
1986
|
-
const kv =
|
|
1997
|
+
const kv = suiteKV(undefined, (s) => {
|
|
1987
1998
|
seen = s;
|
|
1988
1999
|
});
|
|
1989
2000
|
const r = createReview(kv, {
|
|
@@ -2068,7 +2079,7 @@ test('a sweep reaches its own scope’s keys only: never acme-two’s, a sibling
|
|
|
2068
2079
|
|
|
2069
2080
|
test('the local store is never swept: archive and forget of its client change nothing, and a project added in it deletes nothing', async () => {
|
|
2070
2081
|
let snapshot = '';
|
|
2071
|
-
const kv =
|
|
2082
|
+
const kv = suiteKV(undefined, (s) => {
|
|
2072
2083
|
snapshot = JSON.stringify(s);
|
|
2073
2084
|
});
|
|
2074
2085
|
const r = createReview(kv);
|
|
@@ -2094,7 +2105,7 @@ test('the local store is never swept: archive and forget of its client change no
|
|
|
2094
2105
|
});
|
|
2095
2106
|
|
|
2096
2107
|
test('a client default set while the client’s record goes is refused, and never lands as the studio’s', async () => {
|
|
2097
|
-
const kv =
|
|
2108
|
+
const kv = suiteKV();
|
|
2098
2109
|
const r = createReview(kv);
|
|
2099
2110
|
await r.addClient(studio, { slug: 'acme', host: 'acme.studio.test', name: 'Acme' });
|
|
2100
2111
|
// The record is there for the live check, and gone by the time the default is written: a forget landed between.
|
|
@@ -2140,3 +2151,217 @@ test('a project points only at a build started for it, never one started before
|
|
|
2140
2151
|
await review.addProject(acme, studio, { slug: 'atlas', name: 'Atlas' });
|
|
2141
2152
|
await rejects(review.setBuild({ client: 'acme', project: 'atlas' }, studio, fast), 'invalid');
|
|
2142
2153
|
});
|
|
2154
|
+
|
|
2155
|
+
// ── The studio's own host and the handoff ──────────────────────────────────
|
|
2156
|
+
|
|
2157
|
+
/** A store with acme added (its host proven) and bravo still waiting for its host, on a clock a test moves. */
|
|
2158
|
+
async function handoffStudio() {
|
|
2159
|
+
const kv = suiteKV();
|
|
2160
|
+
let t = Date.parse('2030-01-01T00:00:00Z');
|
|
2161
|
+
const r = createReview(kv, { now: () => new Date(t) });
|
|
2162
|
+
const ed = await r.addStudioPerson({ ...studio, id: 'cli' }, { name: 'Ed', team: 'Studio' });
|
|
2163
|
+
await r.addClient(ed, { slug: 'acme', host: 'acme.studio.test', name: 'Acme' });
|
|
2164
|
+
await r.addClient(ed, { slug: 'bravo', host: 'bravo.studio.test', name: 'Bravo' });
|
|
2165
|
+
await r.endProof({ client: 'acme' }, ed);
|
|
2166
|
+
await r.addProject({ client: 'acme' }, ed, { slug: 'rebrand', name: 'Rebrand' });
|
|
2167
|
+
await r.addProject({ client: 'acme' }, ed, { slug: 'draft', name: 'Draft' });
|
|
2168
|
+
await r.startBuild({ client: 'acme', project: 'rebrand' }, ed, 'a'.repeat(32));
|
|
2169
|
+
await r.setBuild({ client: 'acme', project: 'rebrand' }, ed, 'a'.repeat(32));
|
|
2170
|
+
return { kv, r, ed, move: (ms: number) => (t += ms) };
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
test('the client a studio-host op names is an added, live client of the studio, or not found as an unknown one; Studio only', async () => {
|
|
2174
|
+
const { r, ed } = await handoffStudio();
|
|
2175
|
+
assert.equal((await r.studioClient(ed, 'acme')).host, 'acme.studio.test');
|
|
2176
|
+
// bravo still waits for its host; zeta is unknown; the rest are no client's slug.
|
|
2177
|
+
for (const slug of ['bravo', 'zeta', 'studio', 'site', '../acme', 'ACME', '', null, 42, { client: 'acme' }])
|
|
2178
|
+
await rejects(r.studioClient(ed, slug), 'not_found');
|
|
2179
|
+
const rae = await r.addPerson({ client: 'acme' }, ed, { name: 'Rae', team: 'Acme' });
|
|
2180
|
+
await rejects(r.studioClient(rae.person, 'acme'), 'forbidden');
|
|
2181
|
+
await rejects(r.studioClient(null, 'acme'), 'unauthorized');
|
|
2182
|
+
await r.archiveClient({ client: 'acme' }, ed);
|
|
2183
|
+
await rejects(r.studioClient(ed, 'acme'), 'not_found');
|
|
2184
|
+
});
|
|
2185
|
+
|
|
2186
|
+
test('people on the studio’s own host are the studio’s alone, Studio only, and no Client is made or found there', async () => {
|
|
2187
|
+
const { kv, r, ed } = await handoffStudio();
|
|
2188
|
+
const at = 'studio' as const;
|
|
2189
|
+
const rae = await r.addPerson({ client: 'acme' }, ed, { name: 'Rae', team: 'Acme' });
|
|
2190
|
+
const sam = await r.addPerson(at, ed, { name: 'Sam', kind: 'studio' });
|
|
2191
|
+
assert.deepEqual([sam.person.client, sam.person.kind, sam.person.team], [null, 'studio', 'Studio']);
|
|
2192
|
+
assert.equal(sam.person.accessEndsAt, null);
|
|
2193
|
+
assert.equal((await r.useLink(at, sam.token))?.id, sam.person.id);
|
|
2194
|
+
assert.deepEqual(
|
|
2195
|
+
(await r.listPeople(at, ed)).map((p) => p.name),
|
|
2196
|
+
['Ed', 'Sam'],
|
|
2197
|
+
);
|
|
2198
|
+
// A Client belongs to a client: none is named here, so none is made.
|
|
2199
|
+
const before = JSON.stringify(await kv.hgetall(keyOf('studio', 'people')));
|
|
2200
|
+
await rejects(r.addPerson(at, ed, { name: 'Oz', team: 'Acme', kind: 'client' }), 'invalid');
|
|
2201
|
+
assert.equal(JSON.stringify(await kv.hgetall(keyOf('studio', 'people'))), before);
|
|
2202
|
+
// A Client's id is no one here, for every op by id.
|
|
2203
|
+
await rejects(r.newLink(at, ed, rae.person.id), 'not_found');
|
|
2204
|
+
await rejects(r.signOutEverywhere(at, ed, rae.person.id), 'not_found');
|
|
2205
|
+
await rejects(r.revoke(at, ed, rae.person.id), 'not_found');
|
|
2206
|
+
await rejects(r.setAccess(at, ed, rae.person.id, '6m'), 'not_found');
|
|
2207
|
+
assert.equal(
|
|
2208
|
+
(await r.listPeople({ client: 'acme' }, ed)).some((p) => p.id === rae.person.id),
|
|
2209
|
+
true,
|
|
2210
|
+
);
|
|
2211
|
+
// Each op on the studio's own people works there.
|
|
2212
|
+
assert.match((await r.newLink(at, ed, sam.person.id)).token, /^[\w-]{43}$/);
|
|
2213
|
+
assert.equal((await r.signOutEverywhere(at, ed, sam.person.id)).person.epoch, 1);
|
|
2214
|
+
assert.notEqual((await r.setAccess(at, ed, sam.person.id, '3m')).accessEndsAt, null);
|
|
2215
|
+
assert.ok((await r.revoke(at, ed, sam.person.id)).revokedAt);
|
|
2216
|
+
await rejects(r.revoke(at, ed, ed.id), 'invalid');
|
|
2217
|
+
// A Client, even signed in, and a caller signed out get nothing, and nothing is written.
|
|
2218
|
+
const snapshot = JSON.stringify(await kv.hgetall(keyOf('studio', 'people')));
|
|
2219
|
+
for (const [who, actor, code] of [
|
|
2220
|
+
['a Client', rae.person, 'forbidden'],
|
|
2221
|
+
['signed out', null, 'unauthorized'],
|
|
2222
|
+
] as const) {
|
|
2223
|
+
await rejects(r.listPeople(at, actor), code);
|
|
2224
|
+
await rejects(r.addPerson(at, actor, { name: 'Oz', kind: 'studio' }), code);
|
|
2225
|
+
await rejects(r.newLink(at, actor, ed.id), code);
|
|
2226
|
+
await rejects(r.signOutEverywhere(at, actor, ed.id), code);
|
|
2227
|
+
await rejects(r.revoke(at, actor, ed.id), code);
|
|
2228
|
+
await rejects(r.setAccess(at, actor, ed.id, 'open'), code);
|
|
2229
|
+
assert.equal(JSON.stringify(await kv.hgetall(keyOf('studio', 'people'))), snapshot, who);
|
|
2230
|
+
}
|
|
2231
|
+
});
|
|
2232
|
+
|
|
2233
|
+
test('the studio’s own host is Studio’s to set, once; it is no client’s, and no client may take it', async () => {
|
|
2234
|
+
const { r, ed } = await handoffStudio();
|
|
2235
|
+
const rae = await r.addPerson({ client: 'acme' }, ed, { name: 'Rae', team: 'Acme' });
|
|
2236
|
+
await rejects(r.setStudioHost(rae.person, 'studio.studio.test'), 'forbidden');
|
|
2237
|
+
assert.equal(await r.siteOfHost('studio.studio.test'), null);
|
|
2238
|
+
assert.equal(await r.setStudioHost(ed, 'studio.studio.test'), 'added');
|
|
2239
|
+
assert.equal(await r.setStudioHost(ed, 'studio.studio.test'), 'kept');
|
|
2240
|
+
assert.equal(await r.siteOfHost('STUDIO.studio.test.'), 'studio');
|
|
2241
|
+
assert.equal(await r.clientOfHost('studio.studio.test'), null);
|
|
2242
|
+
assert.equal(((await r.siteOfHost('acme.studio.test')) as { slug: string }).slug, 'acme');
|
|
2243
|
+
await rejects(r.setStudioHost(ed, 'acme.studio.test'), 'invalid');
|
|
2244
|
+
await rejects(r.setStudioHost(ed, 'Studio.studio.test'), 'invalid');
|
|
2245
|
+
await rejects(r.addClient(ed, { slug: 'zeta', host: 'studio.studio.test', name: 'Z' }), 'invalid');
|
|
2246
|
+
});
|
|
2247
|
+
|
|
2248
|
+
test('on the studio’s own host only Studio signs in: a Client’s link and session are nobody there', async () => {
|
|
2249
|
+
const { r, ed } = await handoffStudio();
|
|
2250
|
+
const rae = await r.addPerson({ client: 'acme' }, ed, { name: 'Rae', team: 'Acme' });
|
|
2251
|
+
assert.equal(await r.peekLink('studio', rae.token), null);
|
|
2252
|
+
assert.equal(await r.useLink('studio', rae.token), null);
|
|
2253
|
+
assert.equal(await r.sessionPerson('studio', rae.person.id, 0), null);
|
|
2254
|
+
// Rae's link was never used up by the tries there.
|
|
2255
|
+
assert.equal((await r.peekLink({ client: 'acme' }, rae.token))?.id, rae.person.id);
|
|
2256
|
+
const { token } = await r.newStudioLink(ed, ed.id);
|
|
2257
|
+
assert.equal((await r.peekLink('studio', token))?.id, ed.id);
|
|
2258
|
+
assert.equal((await r.useLink('studio', token))?.id, ed.id);
|
|
2259
|
+
assert.equal(await r.useLink('studio', token), null);
|
|
2260
|
+
assert.equal((await r.sessionPerson('studio', ed.id, 0))?.id, ed.id);
|
|
2261
|
+
assert.equal(await r.sessionPerson('studio', ed.id, 1), null);
|
|
2262
|
+
});
|
|
2263
|
+
|
|
2264
|
+
test('the studio lists every client with all its projects, by name, archived ones too; Studio only', async () => {
|
|
2265
|
+
const { r, ed } = await handoffStudio();
|
|
2266
|
+
const listed = await r.listClients(ed);
|
|
2267
|
+
assert.deepEqual(
|
|
2268
|
+
listed.map(({ client, projects }) => [
|
|
2269
|
+
client.slug,
|
|
2270
|
+
client.provenAt !== null,
|
|
2271
|
+
projects.map((p) => p.slug),
|
|
2272
|
+
]),
|
|
2273
|
+
[
|
|
2274
|
+
['acme', true, ['draft', 'rebrand']],
|
|
2275
|
+
['bravo', false, []],
|
|
2276
|
+
],
|
|
2277
|
+
);
|
|
2278
|
+
await r.archiveClient({ client: 'bravo' }, ed);
|
|
2279
|
+
assert.ok((await r.listClients(ed))[1].client.archivedAt);
|
|
2280
|
+
const rae = await r.addPerson({ client: 'acme' }, ed, { name: 'Rae', team: 'Acme' });
|
|
2281
|
+
await rejects(r.listClients(rae.person), 'forbidden');
|
|
2282
|
+
});
|
|
2283
|
+
|
|
2284
|
+
test('a handoff opens one added client once, on its own host only, within a minute', async () => {
|
|
2285
|
+
const { kv, r, ed, move } = await handoffStudio();
|
|
2286
|
+
const acme = { client: 'acme' };
|
|
2287
|
+
const made = await r.startHandoff(ed, { client: 'acme', project: null });
|
|
2288
|
+
assert.equal(made.host, 'acme.studio.test');
|
|
2289
|
+
assert.match(made.token, /^[\w-]{43}$/);
|
|
2290
|
+
// The store keeps the token's hash, never the token.
|
|
2291
|
+
assert.doesNotMatch(JSON.stringify(await kv.hgetall(keyOf(acme, 'handoffs'))), new RegExp(made.token));
|
|
2292
|
+
// Another client's host, a malformed token or the local store's client finds nothing, and uses nothing up.
|
|
2293
|
+
for (const scope of [{ client: 'bravo' }, { client: 'site' }, { client: 'zeta' }])
|
|
2294
|
+
assert.equal(await r.claimHandoff(scope, made.token), null, scope.client);
|
|
2295
|
+
assert.equal(await r.claimHandoff(acme, 'short'), null);
|
|
2296
|
+
const claimed = await r.claimHandoff(acme, made.token);
|
|
2297
|
+
assert.equal(claimed?.person.id, ed.id);
|
|
2298
|
+
assert.equal(claimed?.project, null);
|
|
2299
|
+
assert.equal(await r.claimHandoff(acme, made.token), null);
|
|
2300
|
+
// A project of the client with a build goes with it; past HANDOFF_SECONDS it is nothing.
|
|
2301
|
+
const onto = await r.startHandoff(ed, { client: 'acme', project: 'rebrand' });
|
|
2302
|
+
assert.equal((await r.claimHandoff(acme, onto.token))?.project, 'rebrand');
|
|
2303
|
+
const late = await r.startHandoff(ed, { client: 'acme', project: null });
|
|
2304
|
+
move(60_000);
|
|
2305
|
+
assert.equal(await r.claimHandoff(acme, late.token), null);
|
|
2306
|
+
// Two claims at once: one person.
|
|
2307
|
+
const twice = await r.startHandoff(ed, { client: 'acme', project: null });
|
|
2308
|
+
const both = await Promise.all([r.claimHandoff(acme, twice.token), r.claimHandoff(acme, twice.token)]);
|
|
2309
|
+
assert.equal(both.filter(Boolean).length, 1);
|
|
2310
|
+
// Unclaimed handoffs past their time go as new ones are made; claimed ones are gone already.
|
|
2311
|
+
await r.startHandoff(ed, { client: 'acme', project: null });
|
|
2312
|
+
assert.equal(Object.keys(await kv.hgetall(keyOf(acme, 'handoffs'))).length, 1);
|
|
2313
|
+
move(60_000);
|
|
2314
|
+
await r.startHandoff(ed, { client: 'acme', project: null });
|
|
2315
|
+
assert.equal(Object.keys(await kv.hgetall(keyOf(acme, 'handoffs'))).length, 1);
|
|
2316
|
+
});
|
|
2317
|
+
|
|
2318
|
+
test('no handoff for a client still being added, archived or unknown, or a project it has not built; Studio only', async () => {
|
|
2319
|
+
const { r, ed } = await handoffStudio();
|
|
2320
|
+
const asks: { client: unknown; project: unknown }[] = [
|
|
2321
|
+
{ client: 'bravo', project: null },
|
|
2322
|
+
{ client: 'zeta', project: null },
|
|
2323
|
+
{ client: 'studio', project: null },
|
|
2324
|
+
{ client: 'site', project: null },
|
|
2325
|
+
{ client: '../acme', project: null },
|
|
2326
|
+
{ client: 'acme', project: 'draft' },
|
|
2327
|
+
{ client: 'acme', project: 'nope' },
|
|
2328
|
+
{ client: 'acme', project: '../bravo' },
|
|
2329
|
+
{ client: 'acme', project: 'invite' },
|
|
2330
|
+
];
|
|
2331
|
+
for (const ask of asks) await rejects(r.startHandoff(ed, ask), 'not_found');
|
|
2332
|
+
const rae = await r.addPerson({ client: 'acme' }, ed, { name: 'Rae', team: 'Acme' });
|
|
2333
|
+
await rejects(r.startHandoff(rae.person, { client: 'acme', project: null }), 'forbidden');
|
|
2334
|
+
await rejects(r.startHandoff(null, { client: 'acme', project: null }), 'unauthorized');
|
|
2335
|
+
// Made, then the client archived, or the person revoked: the claim gives nothing.
|
|
2336
|
+
const made = await r.startHandoff(ed, { client: 'acme', project: null });
|
|
2337
|
+
const jo = await r.addStudioPerson(ed, { name: 'Jo', team: 'Studio' });
|
|
2338
|
+
const byJo = await r.startHandoff(jo, { client: 'acme', project: null });
|
|
2339
|
+
await r.revoke({ client: 'acme' }, ed, jo.id);
|
|
2340
|
+
assert.equal(await r.claimHandoff({ client: 'acme' }, byJo.token), null);
|
|
2341
|
+
await r.archiveClient({ client: 'acme' }, ed);
|
|
2342
|
+
assert.equal(await r.claimHandoff({ client: 'acme' }, made.token), null);
|
|
2343
|
+
await rejects(r.startHandoff(ed, { client: 'acme', project: null }), 'not_found');
|
|
2344
|
+
});
|
|
2345
|
+
|
|
2346
|
+
test('the studio host’s proof is Studio’s to start and end, answers only its own ask, keeps no ask, and marks the host proven once', async () => {
|
|
2347
|
+
const { kv, r, ed } = await handoffStudio();
|
|
2348
|
+
assert.equal(await r.studioHostProven(ed), false);
|
|
2349
|
+
const { ask, answer } = await r.startStudioProof(ed);
|
|
2350
|
+
assert.notEqual(ask, answer);
|
|
2351
|
+
assert.equal(await r.studioProofAnswer(ask), answer);
|
|
2352
|
+
assert.doesNotMatch(JSON.stringify(await kv.hgetall(keyOf('studio', 'proof'))), new RegExp(ask));
|
|
2353
|
+
for (const given of [answer, 'x'.repeat(43), 'short'])
|
|
2354
|
+
assert.equal(await r.studioProofAnswer(given), null, given);
|
|
2355
|
+
// A client's proof is never the studio's, nor the other way.
|
|
2356
|
+
const client = await r.startProof({ client: 'bravo' }, ed);
|
|
2357
|
+
assert.equal(await r.studioProofAnswer(client.ask), null);
|
|
2358
|
+
assert.equal(await r.proofAnswer({ client: 'bravo' }, ask), null);
|
|
2359
|
+
const next = await r.startStudioProof(ed);
|
|
2360
|
+
assert.equal(await r.studioProofAnswer(ask), null);
|
|
2361
|
+
await r.endStudioProof(ed);
|
|
2362
|
+
assert.equal(await r.studioProofAnswer(next.ask), null);
|
|
2363
|
+
assert.equal(await r.studioHostProven(ed), true);
|
|
2364
|
+
const at = await kv.hget(keyOf('studio', 'settings'), 'hostProvenAt');
|
|
2365
|
+
await r.endStudioProof(ed);
|
|
2366
|
+
assert.equal(await kv.hget(keyOf('studio', 'settings'), 'hostProvenAt'), at);
|
|
2367
|
+
});
|