@serfab/cadre-host 0.7.1 → 0.9.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 +296 -101
- package/dist/auth/trust-circle.d.ts +45 -7
- package/dist/auth/trust-circle.js +116 -59
- package/dist/auth/trust-circle.js.map +1 -1
- package/dist/auth/types.d.ts +4 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/bin/host.js +426 -112
- package/dist/bin/host.js.map +1 -1
- package/dist/donation/donation-service.d.ts +136 -0
- package/dist/donation/donation-service.js +306 -0
- package/dist/donation/donation-service.js.map +1 -0
- package/dist/donation/donation-store.d.ts +42 -0
- package/dist/donation/donation-store.js +141 -0
- package/dist/donation/donation-store.js.map +1 -0
- package/dist/donation/grant-service.d.ts +71 -0
- package/dist/donation/grant-service.js +163 -0
- package/dist/donation/grant-service.js.map +1 -0
- package/dist/donation/grant-store.d.ts +38 -0
- package/dist/donation/grant-store.js +135 -0
- package/dist/donation/grant-store.js.map +1 -0
- package/dist/donation/index.d.ts +18 -0
- package/dist/donation/index.js +16 -0
- package/dist/donation/index.js.map +1 -0
- package/dist/donation/types.d.ts +175 -0
- package/dist/donation/types.js +40 -0
- package/dist/donation/types.js.map +1 -0
- package/dist/index.d.ts +12 -6
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/installer/browser.js +16 -17
- package/dist/installer/browser.js.map +1 -1
- package/dist/installer/config.d.ts +51 -0
- package/dist/installer/config.js +14 -1
- package/dist/installer/config.js.map +1 -1
- package/dist/installer/index.d.ts +7 -2
- package/dist/installer/index.js +17 -10
- package/dist/installer/index.js.map +1 -1
- package/dist/installer/service-host/launchd.js +1 -1
- package/dist/installer/service-host/launchd.js.map +1 -1
- package/dist/installer/service-host/systemd.js +1 -1
- package/dist/installer/service-host/systemd.js.map +1 -1
- package/dist/installer/wizard.d.ts +4 -0
- package/dist/installer/wizard.js +5 -1
- package/dist/installer/wizard.js.map +1 -1
- package/dist/nat/index.d.ts +1 -1
- package/dist/nat/nat-service.d.ts +45 -3
- package/dist/nat/nat-service.js +116 -3
- package/dist/nat/nat-service.js.map +1 -1
- package/dist/nat/secrets/index.d.ts +7 -0
- package/dist/nat/secrets/index.js +28 -2
- package/dist/nat/secrets/index.js.map +1 -1
- package/dist/nat/types.d.ts +3 -1
- package/dist/nat/types.js.map +1 -1
- package/dist/orchestrator/host-process-orchestrator.d.ts +68 -1
- package/dist/orchestrator/host-process-orchestrator.js +272 -39
- package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
- package/dist/orchestrator/index.d.ts +3 -2
- package/dist/orchestrator/index.js +1 -1
- package/dist/orchestrator/index.js.map +1 -1
- package/dist/orchestrator/state-store.d.ts +6 -5
- package/dist/orchestrator/state-store.js +10 -2
- package/dist/orchestrator/state-store.js.map +1 -1
- package/dist/orchestrator/types.d.ts +45 -10
- package/dist/orchestrator/types.js.map +1 -1
- package/dist/owner/index.d.ts +11 -0
- package/dist/owner/index.js +11 -0
- package/dist/owner/index.js.map +1 -0
- package/dist/owner/owner-node-client.d.ts +95 -0
- package/dist/owner/owner-node-client.js +167 -0
- package/dist/owner/owner-node-client.js.map +1 -0
- package/dist/push/index.d.ts +67 -0
- package/dist/push/index.js +101 -0
- package/dist/push/index.js.map +1 -0
- package/dist/server/error-handler.d.ts +17 -0
- package/dist/server/error-handler.js +45 -0
- package/dist/server/error-handler.js.map +1 -1
- package/dist/server/index.d.ts +26 -2
- package/dist/server/index.js +37 -16
- package/dist/server/index.js.map +1 -1
- package/dist/server/routes/grants-admin.d.ts +17 -0
- package/dist/server/routes/grants-admin.js +32 -0
- package/dist/server/routes/grants-admin.js.map +1 -0
- package/dist/server/routes/grants.d.ts +28 -0
- package/dist/server/routes/grants.js +163 -0
- package/dist/server/routes/grants.js.map +1 -0
- package/dist/server/routes/nodes.d.ts +5 -3
- package/dist/server/routes/nodes.js +39 -24
- package/dist/server/routes/nodes.js.map +1 -1
- package/dist/server/routes/settings.d.ts +6 -1
- package/dist/server/routes/settings.js +5 -2
- package/dist/server/routes/settings.js.map +1 -1
- package/dist/server/routes/status.d.ts +8 -4
- package/dist/server/routes/status.js +9 -4
- package/dist/server/routes/status.js.map +1 -1
- package/dist/server/static.d.ts +12 -0
- package/dist/server/static.js +24 -7
- package/dist/server/static.js.map +1 -1
- package/dist/ui/assets/index-BlMXQPSw.js +14 -0
- package/dist/ui/assets/{index-C9uChk2P.js.map → index-BlMXQPSw.js.map} +1 -1
- package/dist/ui/index.html +1 -1
- package/dist/update/apply.d.ts +23 -1
- package/dist/update/apply.js +46 -4
- package/dist/update/apply.js.map +1 -1
- package/dist/update/index.d.ts +14 -3
- package/dist/update/index.js +35 -2
- package/dist/update/index.js.map +1 -1
- package/dist/update/manifest.d.ts +28 -9
- package/dist/update/manifest.js +56 -29
- package/dist/update/manifest.js.map +1 -1
- package/dist/update/release-key.d.ts +18 -7
- package/dist/update/release-key.js +29 -14
- package/dist/update/release-key.js.map +1 -1
- package/dist/update/sign.d.ts +46 -0
- package/dist/update/sign.js +53 -0
- package/dist/update/sign.js.map +1 -0
- package/package.json +9 -4
- package/service/README.md +95 -86
- package/src/__tests__/cli-invite.smoke.test.ts +6 -1
- package/src/__tests__/cli-nat.smoke.test.ts +6 -1
- package/src/__tests__/cli.smoke.test.ts +6 -1
- package/src/__tests__/host-owner.smoke.test.ts +123 -0
- package/src/__tests__/orchestrator-owner.test.ts +198 -0
- package/src/__tests__/orchestrator-pin-keys.test.ts +153 -0
- package/src/__tests__/orchestrator-push.test.ts +145 -0
- package/src/auth/__tests__/trust-circle-integration.test.ts +44 -25
- package/src/auth/__tests__/trust-circle.test.ts +91 -24
- package/src/auth/trust-circle.ts +363 -304
- package/src/auth/types.ts +4 -1
- package/src/bin/host.ts +1258 -905
- package/src/donation/__tests__/donation-service.test.ts +290 -0
- package/src/donation/__tests__/grant-service.test.ts +213 -0
- package/src/donation/__tests__/grant-store.test.ts +113 -0
- package/src/donation/donation-service.ts +392 -0
- package/src/donation/donation-store.ts +164 -0
- package/src/donation/grant-service.ts +200 -0
- package/src/donation/grant-store.ts +152 -0
- package/src/donation/index.ts +49 -0
- package/src/donation/types.ts +220 -0
- package/src/index.ts +66 -3
- package/src/installer/__tests__/config.test.ts +27 -1
- package/src/installer/__tests__/installer.smoke.test.ts +94 -0
- package/src/installer/__tests__/wizard.test.ts +5 -1
- package/src/installer/browser.ts +40 -42
- package/src/installer/config.ts +61 -1
- package/src/installer/index.ts +23 -12
- package/src/installer/service-host/launchd.ts +1 -1
- package/src/installer/service-host/systemd.ts +1 -1
- package/src/installer/wizard.ts +12 -1
- package/src/nat/__tests__/ddns-updater.test.ts +1 -1
- package/src/nat/__tests__/nat-service.test.ts +192 -0
- package/src/nat/__tests__/port-mapper.test.ts +1 -1
- package/src/nat/__tests__/secrets.test.ts +23 -1
- package/src/nat/index.ts +1 -1
- package/src/nat/nat-service.ts +131 -5
- package/src/nat/secrets/index.ts +32 -2
- package/src/nat/types.ts +3 -1
- package/src/orchestrator/host-process-orchestrator.ts +322 -54
- package/src/orchestrator/index.ts +9 -2
- package/src/orchestrator/state-store.ts +21 -3
- package/src/orchestrator/types.ts +48 -2
- package/src/owner/__tests__/owner-node-client.test.ts +194 -0
- package/src/owner/index.ts +12 -0
- package/src/owner/owner-node-client.ts +233 -0
- package/src/push/__tests__/push.test.ts +90 -0
- package/src/push/index.ts +146 -0
- package/src/server/__tests__/error-handler.test.ts +26 -4
- package/src/server/__tests__/grants-admin-route.test.ts +73 -0
- package/src/server/__tests__/grants-route.test.ts +189 -0
- package/src/server/__tests__/nodes-route.test.ts +90 -10
- package/src/server/__tests__/publishers.test.ts +1 -1
- package/src/server/__tests__/server.smoke.test.ts +75 -0
- package/src/server/__tests__/settings-route.test.ts +17 -0
- package/src/server/__tests__/static.test.ts +145 -0
- package/src/server/__tests__/status-route.test.ts +23 -2
- package/src/server/error-handler.ts +47 -0
- package/src/server/index.ts +62 -17
- package/src/server/routes/grants-admin.ts +41 -0
- package/src/server/routes/grants.ts +186 -0
- package/src/server/routes/nodes.ts +49 -26
- package/src/server/routes/settings.ts +11 -3
- package/src/server/routes/status.ts +18 -8
- package/src/server/static.ts +24 -8
- package/src/update/__tests__/apply.test.ts +58 -1
- package/src/update/__tests__/manifest.test.ts +41 -6
- package/src/update/__tests__/release-key.test.ts +42 -0
- package/src/update/__tests__/sign.test.ts +78 -0
- package/src/update/__tests__/update-service.integration.test.ts +44 -9
- package/src/update/apply.ts +46 -4
- package/src/update/index.ts +41 -3
- package/src/update/manifest.ts +214 -172
- package/src/update/release-key.ts +31 -15
- package/src/update/sign.ts +74 -0
- package/dist/ui/assets/index-C9uChk2P.js +0 -14
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HostProcessOrchestrator owner-node lifecycle tests.
|
|
3
|
+
*
|
|
4
|
+
* Uses the `spawn.entrypoint` hook with a fake CLI that writes its startup
|
|
5
|
+
* token and binds a minimal `/admin/identity` endpoint on the admin port —
|
|
6
|
+
* enough to validate spawn, idempotency, admin-port allocation/persistence,
|
|
7
|
+
* the end-to-end OwnerNodeClient round-trip, and init() re-attach.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
11
|
+
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
12
|
+
import { tmpdir } from 'node:os';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
|
|
15
|
+
import { HostProcessOrchestrator, OWNER_CONTAINER_ID } from '../orchestrator/host-process-orchestrator.js';
|
|
16
|
+
import { StateStore } from '../orchestrator/state-store.js';
|
|
17
|
+
import { isPidAlive } from '../orchestrator/pid-liveness.js';
|
|
18
|
+
import { decodeDockerId } from '../orchestrator/types.js';
|
|
19
|
+
import { OwnerNodeClient } from '../owner/owner-node-client.js';
|
|
20
|
+
|
|
21
|
+
const FAKE_OWNER_CLI = `
|
|
22
|
+
import fs from 'node:fs';
|
|
23
|
+
import http from 'node:http';
|
|
24
|
+
|
|
25
|
+
const args = process.argv.slice(2);
|
|
26
|
+
const get = (flag) => { const i = args.indexOf(flag); return i >= 0 ? args[i + 1] : undefined; };
|
|
27
|
+
|
|
28
|
+
const tokenPath = get('--startup-token-file');
|
|
29
|
+
const adminPort = get('--admin-port');
|
|
30
|
+
const token = process.env.CADRE_STARTUP_TOKEN ?? '';
|
|
31
|
+
|
|
32
|
+
if (tokenPath && token) {
|
|
33
|
+
try { fs.writeFileSync(tokenPath, token, 'utf8'); } catch (err) { console.error('token write failed', err); }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (adminPort && token) {
|
|
37
|
+
const server = http.createServer((req, res) => {
|
|
38
|
+
const auth = req.headers['authorization'];
|
|
39
|
+
if (auth !== 'Bearer ' + token) {
|
|
40
|
+
res.writeHead(401, { 'content-type': 'application/json' });
|
|
41
|
+
res.end(JSON.stringify({ ok: false, error: { code: 'not_authorized', message: 'bad token' } }));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (req.url === '/admin/identity' && req.method === 'GET') {
|
|
45
|
+
res.writeHead(200, { 'content-type': 'application/json' });
|
|
46
|
+
res.end(JSON.stringify({ ok: true, data: { peerId: 'FAKEPEER', partyId: 'fake-party' } }));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
res.writeHead(400, { 'content-type': 'application/json' });
|
|
50
|
+
res.end(JSON.stringify({ ok: false, error: { code: 'bad_request', message: req.url } }));
|
|
51
|
+
});
|
|
52
|
+
server.listen(parseInt(adminPort, 10), '127.0.0.1', () => {
|
|
53
|
+
console.log('admin listening on ' + adminPort);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
process.on('SIGTERM', () => process.exit(0));
|
|
58
|
+
console.log('fake owner up');
|
|
59
|
+
setInterval(() => {}, 1 << 30);
|
|
60
|
+
`;
|
|
61
|
+
|
|
62
|
+
let tmpRoot: string;
|
|
63
|
+
let scriptPath: string;
|
|
64
|
+
const orchestrators: HostProcessOrchestrator[] = [];
|
|
65
|
+
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
tmpRoot = mkdtempSync(join(tmpdir(), 'cadre-host-auth-'));
|
|
68
|
+
scriptPath = join(tmpRoot, 'fake-owner.mjs');
|
|
69
|
+
writeFileSync(scriptPath, FAKE_OWNER_CLI, 'utf8');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
afterEach(async () => {
|
|
73
|
+
for (const orch of orchestrators) {
|
|
74
|
+
try { await orch.stopOwnerNode(); } catch { /* ignore */ }
|
|
75
|
+
for (const dockerId of listDockerIds(orch)) {
|
|
76
|
+
try { await orch.removeContainer(dockerId); } catch { /* ignore */ }
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
orchestrators.length = 0;
|
|
80
|
+
await sleep(50);
|
|
81
|
+
try { rmSync(tmpRoot, { recursive: true, force: true }); } catch { /* ignore */ }
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
function makeOrchestrator(rootDir: string): HostProcessOrchestrator {
|
|
85
|
+
mkdirSync(rootDir, { recursive: true });
|
|
86
|
+
const orch = new HostProcessOrchestrator({
|
|
87
|
+
rootDir,
|
|
88
|
+
portRange: { start: 18500, end: 18999 },
|
|
89
|
+
stopTimeoutMs: 1500,
|
|
90
|
+
spawn: { entrypoint: scriptPath },
|
|
91
|
+
});
|
|
92
|
+
orchestrators.push(orch);
|
|
93
|
+
return orch;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function listDockerIds(orch: HostProcessOrchestrator): string[] {
|
|
97
|
+
const state = new StateStore((orch as unknown as { rootDir: string }).rootDir);
|
|
98
|
+
return state.load().handles.map((h) => h.dockerId);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function waitFor(predicate: () => boolean | Promise<boolean>, timeoutMs = 4000, intervalMs = 50): Promise<void> {
|
|
102
|
+
const deadline = Date.now() + timeoutMs;
|
|
103
|
+
while (Date.now() < deadline) {
|
|
104
|
+
if (await predicate()) return;
|
|
105
|
+
await sleep(intervalMs);
|
|
106
|
+
}
|
|
107
|
+
throw new Error('waitFor: timed out');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function sleep(ms: number): Promise<void> {
|
|
111
|
+
return new Promise((res) => setTimeout(res, ms));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const CFG = { identityPath: 'C:/fake/identity.key', partyId: 'install-id-123', libp2pPort: 4555 };
|
|
115
|
+
|
|
116
|
+
describe('HostProcessOrchestrator.ensureOwnerNode', () => {
|
|
117
|
+
it('spawns the owner node, allocates+persists an admin port', async () => {
|
|
118
|
+
const orch = makeOrchestrator(join(tmpRoot, 'a'));
|
|
119
|
+
await orch.init();
|
|
120
|
+
const node = await orch.ensureOwnerNode(CFG);
|
|
121
|
+
|
|
122
|
+
expect(node.id).toBe(OWNER_CONTAINER_ID);
|
|
123
|
+
expect(node.owner).toBe(true);
|
|
124
|
+
expect(node.ports.admin).toBeGreaterThanOrEqual(18500);
|
|
125
|
+
expect(node.ports.p2p).toBe(4555);
|
|
126
|
+
|
|
127
|
+
const endpoint = orch.getOwnerAdminEndpoint();
|
|
128
|
+
expect(endpoint).toBeDefined();
|
|
129
|
+
expect(endpoint!.baseUrl).toBe(`http://127.0.0.1:${node.ports.admin}`);
|
|
130
|
+
|
|
131
|
+
// Persisted with admin port + owner flag + ownerConfig.
|
|
132
|
+
const persisted = new StateStore(join(tmpRoot, 'a')).load();
|
|
133
|
+
expect(persisted.ownerConfig).toMatchObject({ partyId: 'install-id-123', libp2pPort: 4555 });
|
|
134
|
+
const ph = persisted.handles.find((h) => h.containerId === OWNER_CONTAINER_ID);
|
|
135
|
+
expect(ph?.owner).toBe(true);
|
|
136
|
+
expect(typeof ph?.ports.admin).toBe('number');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('is idempotent — a second call does not spawn a second child', async () => {
|
|
140
|
+
const orch = makeOrchestrator(join(tmpRoot, 'b'));
|
|
141
|
+
await orch.init();
|
|
142
|
+
const first = await orch.ensureOwnerNode(CFG);
|
|
143
|
+
await waitFor(() => orch.isRunning(first.dockerId));
|
|
144
|
+
|
|
145
|
+
const second = await orch.ensureOwnerNode(CFG);
|
|
146
|
+
expect(second.dockerId).toBe(first.dockerId);
|
|
147
|
+
expect(orch.listNodes()).toHaveLength(1);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('the OwnerNodeClient reaches the spawned admin channel', async () => {
|
|
151
|
+
const orch = makeOrchestrator(join(tmpRoot, 'c'));
|
|
152
|
+
await orch.init();
|
|
153
|
+
const node = await orch.ensureOwnerNode(CFG);
|
|
154
|
+
await waitFor(() => orch.isRunning(node.dockerId));
|
|
155
|
+
|
|
156
|
+
const client = new OwnerNodeClient(() => orch.getOwnerAdminEndpoint());
|
|
157
|
+
await waitFor(async () => {
|
|
158
|
+
try { return (await client.getPeerId()) === 'FAKEPEER'; } catch { return false; }
|
|
159
|
+
});
|
|
160
|
+
expect(await client.getPeerId()).toBe('FAKEPEER');
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('getOwnerAdminEndpoint() survives an init() re-attach', async () => {
|
|
164
|
+
const rootDir = join(tmpRoot, 'd');
|
|
165
|
+
const a = makeOrchestrator(rootDir);
|
|
166
|
+
await a.init();
|
|
167
|
+
const node = await a.ensureOwnerNode(CFG);
|
|
168
|
+
await waitFor(() => a.isRunning(node.dockerId));
|
|
169
|
+
const before = a.getOwnerAdminEndpoint();
|
|
170
|
+
|
|
171
|
+
const b = makeOrchestrator(rootDir);
|
|
172
|
+
await b.init();
|
|
173
|
+
expect(b.isOwnerNode(OWNER_CONTAINER_ID)).toBe(true);
|
|
174
|
+
expect(b.hasOwnerConfig()).toBe(true);
|
|
175
|
+
const after = b.getOwnerAdminEndpoint();
|
|
176
|
+
expect(after).toEqual(before);
|
|
177
|
+
expect(await b.isRunning(node.dockerId)).toBe(true);
|
|
178
|
+
|
|
179
|
+
const { pid } = decodeDockerId(node.dockerId);
|
|
180
|
+
expect(isPidAlive(pid)).toBe(true);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('restartOwnerNode preserves the workdir and re-spawns', async () => {
|
|
184
|
+
const orch = makeOrchestrator(join(tmpRoot, 'e'));
|
|
185
|
+
await orch.init();
|
|
186
|
+
const first = await orch.ensureOwnerNode(CFG);
|
|
187
|
+
await waitFor(() => orch.isRunning(first.dockerId));
|
|
188
|
+
const { pid: firstPid } = decodeDockerId(first.dockerId);
|
|
189
|
+
|
|
190
|
+
const restarted = await orch.restartOwnerNode();
|
|
191
|
+
await waitFor(() => orch.isRunning(restarted.dockerId));
|
|
192
|
+
|
|
193
|
+
// New child (different pid/token), still exactly one node, workdir reused.
|
|
194
|
+
expect(restarted.dockerId).not.toBe(first.dockerId);
|
|
195
|
+
expect(orch.listNodes()).toHaveLength(1);
|
|
196
|
+
await waitFor(() => !isPidAlive(firstPid));
|
|
197
|
+
});
|
|
198
|
+
});
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HostProcessOrchestrator pinned-owner-key tests — the load-bearing wiring for
|
|
3
|
+
* the node-donation flow.
|
|
4
|
+
*
|
|
5
|
+
* A donated node joins a FOREIGN cadre and must accept a requester-signed seed,
|
|
6
|
+
* so the orchestrator threads `request.pinnedOwnerKeys` into the child as the
|
|
7
|
+
* comma-separated `CADRE_OWNER_KEYS` env var (which `cadre-cli start` turns into
|
|
8
|
+
* a cold-start pinned-key trust policy). The same signal marks the node as
|
|
9
|
+
* foreign-party, which suppresses the host's own push credentials (meaningless
|
|
10
|
+
* to another cadre's app).
|
|
11
|
+
*
|
|
12
|
+
* A fake CLI records `CADRE_OWNER_KEYS` from its environment to a file so the
|
|
13
|
+
* env threading is observable without a real cadre node.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
17
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
18
|
+
import { tmpdir } from 'node:os';
|
|
19
|
+
import { join } from 'node:path';
|
|
20
|
+
|
|
21
|
+
import type { PushCredentials } from '@serfab/cadre-core';
|
|
22
|
+
import { HostProcessOrchestrator } from '../orchestrator/host-process-orchestrator.js';
|
|
23
|
+
|
|
24
|
+
// Writes CADRE_OWNER_KEYS (as seen in the child env) next to the startup token,
|
|
25
|
+
// then behaves like a minimal long-lived node.
|
|
26
|
+
const FAKE_CLI = `
|
|
27
|
+
import fs from 'node:fs';
|
|
28
|
+
import path from 'node:path';
|
|
29
|
+
const args = process.argv.slice(2);
|
|
30
|
+
const get = (flag) => { const i = args.indexOf(flag); return i >= 0 ? args[i + 1] : undefined; };
|
|
31
|
+
const tokenPath = get('--startup-token-file');
|
|
32
|
+
const token = process.env.CADRE_STARTUP_TOKEN ?? '';
|
|
33
|
+
if (tokenPath) {
|
|
34
|
+
const dir = path.dirname(tokenPath);
|
|
35
|
+
try { fs.writeFileSync(path.join(dir, 'owner-keys.txt'), process.env.CADRE_OWNER_KEYS ?? '', 'utf8'); } catch (e) { console.error(e); }
|
|
36
|
+
if (token) { try { fs.writeFileSync(tokenPath, token, 'utf8'); } catch (e) { console.error(e); } }
|
|
37
|
+
}
|
|
38
|
+
process.on('SIGTERM', () => process.exit(0));
|
|
39
|
+
setInterval(() => {}, 1 << 30);
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
const FCM = { projectId: 'proj', clientEmail: 'svc@proj.iam', privateKey: 'FCM-SECRET-PEM' };
|
|
43
|
+
|
|
44
|
+
let tmpRoot: string;
|
|
45
|
+
let scriptPath: string;
|
|
46
|
+
const orchestrators: HostProcessOrchestrator[] = [];
|
|
47
|
+
|
|
48
|
+
beforeEach(() => {
|
|
49
|
+
tmpRoot = mkdtempSync(join(tmpdir(), 'cadre-host-pin-'));
|
|
50
|
+
scriptPath = join(tmpRoot, 'fake-cli.mjs');
|
|
51
|
+
writeFileSync(scriptPath, FAKE_CLI, 'utf8');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
afterEach(async () => {
|
|
55
|
+
for (const orch of orchestrators) {
|
|
56
|
+
for (const n of orch.listNodes()) {
|
|
57
|
+
try { await orch.removeContainer(n.dockerId); } catch { /* ignore */ }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
orchestrators.length = 0;
|
|
61
|
+
await sleep(50);
|
|
62
|
+
try { rmSync(tmpRoot, { recursive: true, force: true }); } catch { /* ignore */ }
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
function makeOrchestrator(rootDir: string, pushResolver?: () => Promise<PushCredentials | undefined>): HostProcessOrchestrator {
|
|
66
|
+
mkdirSync(rootDir, { recursive: true });
|
|
67
|
+
const orch = new HostProcessOrchestrator({
|
|
68
|
+
rootDir,
|
|
69
|
+
portRange: { start: 18500, end: 18999 },
|
|
70
|
+
stopTimeoutMs: 1500,
|
|
71
|
+
spawn: { entrypoint: scriptPath },
|
|
72
|
+
...(pushResolver ? { pushResolver } : {}),
|
|
73
|
+
});
|
|
74
|
+
orchestrators.push(orch);
|
|
75
|
+
return orch;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function readChildConfig(rootDir: string, containerId: string): Record<string, unknown> {
|
|
79
|
+
return JSON.parse(readFileSync(join(rootDir, containerId, 'cadre.json'), 'utf8')) as Record<string, unknown>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function waitForFile(path: string, timeoutMs = 5000): Promise<string> {
|
|
83
|
+
const deadline = Date.now() + timeoutMs;
|
|
84
|
+
while (Date.now() < deadline) {
|
|
85
|
+
if (existsSync(path)) return readFileSync(path, 'utf8');
|
|
86
|
+
await sleep(50);
|
|
87
|
+
}
|
|
88
|
+
throw new Error(`file never appeared: ${path}`);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function sleep(ms: number): Promise<void> {
|
|
92
|
+
return new Promise((res) => setTimeout(res, ms));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
describe('HostProcessOrchestrator pinned owner keys', () => {
|
|
96
|
+
it('threads pinnedOwnerKeys into the child as comma-separated CADRE_OWNER_KEYS', async () => {
|
|
97
|
+
const rootDir = join(tmpRoot, 'a');
|
|
98
|
+
const orch = makeOrchestrator(rootDir);
|
|
99
|
+
await orch.init();
|
|
100
|
+
|
|
101
|
+
await orch.createContainer({
|
|
102
|
+
containerId: 'donated-1',
|
|
103
|
+
partyId: 'foreign-P',
|
|
104
|
+
bootstrapNodes: [],
|
|
105
|
+
profile: 'storage',
|
|
106
|
+
pinnedOwnerKeys: ['key-a', 'key-b'],
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const keys = await waitForFile(join(rootDir, 'donated-1', 'owner-keys.txt'));
|
|
110
|
+
expect(keys).toBe('key-a,key-b');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('suppresses host push for a foreign-party (pinned-key) node even on storage profile', async () => {
|
|
114
|
+
const rootDir = join(tmpRoot, 'b');
|
|
115
|
+
const orch = makeOrchestrator(rootDir, async () => ({ fcm: FCM }));
|
|
116
|
+
await orch.init();
|
|
117
|
+
|
|
118
|
+
// Foreign-party donated node: pinned keys present → no host push injected.
|
|
119
|
+
await orch.createContainer({
|
|
120
|
+
containerId: 'donated-2',
|
|
121
|
+
partyId: 'foreign-P',
|
|
122
|
+
bootstrapNodes: [],
|
|
123
|
+
profile: 'storage',
|
|
124
|
+
pinnedOwnerKeys: ['key-a'],
|
|
125
|
+
});
|
|
126
|
+
expect(readChildConfig(rootDir, 'donated-2').push).toBeUndefined();
|
|
127
|
+
|
|
128
|
+
// Control: a host-own storage node (no pinned keys) DOES get push.
|
|
129
|
+
await orch.createContainer({
|
|
130
|
+
containerId: 'own-1',
|
|
131
|
+
partyId: 'host-P',
|
|
132
|
+
bootstrapNodes: [],
|
|
133
|
+
profile: 'storage',
|
|
134
|
+
});
|
|
135
|
+
expect(readChildConfig(rootDir, 'own-1').push).toEqual({ fcm: FCM });
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('omits CADRE_OWNER_KEYS when no pinned keys are supplied', async () => {
|
|
139
|
+
const rootDir = join(tmpRoot, 'c');
|
|
140
|
+
const orch = makeOrchestrator(rootDir);
|
|
141
|
+
await orch.init();
|
|
142
|
+
|
|
143
|
+
await orch.createContainer({
|
|
144
|
+
containerId: 'own-2',
|
|
145
|
+
partyId: 'host-P',
|
|
146
|
+
bootstrapNodes: [],
|
|
147
|
+
profile: 'storage',
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const keys = await waitForFile(join(rootDir, 'own-2', 'owner-keys.txt'));
|
|
151
|
+
expect(keys).toBe(''); // env var absent → child reads empty string
|
|
152
|
+
});
|
|
153
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HostProcessOrchestrator push-credential injection tests.
|
|
3
|
+
*
|
|
4
|
+
* Verifies the orchestrator writes `config.push` into the spawned node's
|
|
5
|
+
* cadre.json when the pushResolver yields credentials, omits it otherwise,
|
|
6
|
+
* re-resolves on every (re-)spawn, and never persists a raw private key in
|
|
7
|
+
* state.json. Uses a fake CLI entrypoint that just writes its startup token.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
11
|
+
import { mkdtempSync, mkdirSync, rmSync, readFileSync, writeFileSync } from 'node:fs';
|
|
12
|
+
import { tmpdir } from 'node:os';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
|
|
15
|
+
import type { PushCredentials } from '@serfab/cadre-core';
|
|
16
|
+
import { HostProcessOrchestrator, OWNER_CONTAINER_ID } from '../orchestrator/host-process-orchestrator.js';
|
|
17
|
+
|
|
18
|
+
const FAKE_CLI = `
|
|
19
|
+
import fs from 'node:fs';
|
|
20
|
+
const args = process.argv.slice(2);
|
|
21
|
+
const get = (flag) => { const i = args.indexOf(flag); return i >= 0 ? args[i + 1] : undefined; };
|
|
22
|
+
const tokenPath = get('--startup-token-file');
|
|
23
|
+
const token = process.env.CADRE_STARTUP_TOKEN ?? '';
|
|
24
|
+
if (tokenPath && token) { try { fs.writeFileSync(tokenPath, token, 'utf8'); } catch (e) { console.error(e); } }
|
|
25
|
+
process.on('SIGTERM', () => process.exit(0));
|
|
26
|
+
setInterval(() => {}, 1 << 30);
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
const FCM = { projectId: 'proj', clientEmail: 'svc@proj.iam', privateKey: 'FCM-SECRET-PEM' };
|
|
30
|
+
const APNS = { keyId: 'KID', teamId: 'TEAM', bundleId: 'com.example.app', privateKey: 'APNS-SECRET-P8', production: false };
|
|
31
|
+
const CFG = { identityPath: 'C:/fake/identity.key', partyId: 'install-id-123', libp2pPort: 4655 };
|
|
32
|
+
|
|
33
|
+
let tmpRoot: string;
|
|
34
|
+
let scriptPath: string;
|
|
35
|
+
const orchestrators: HostProcessOrchestrator[] = [];
|
|
36
|
+
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
tmpRoot = mkdtempSync(join(tmpdir(), 'cadre-host-push-'));
|
|
39
|
+
scriptPath = join(tmpRoot, 'fake-cli.mjs');
|
|
40
|
+
writeFileSync(scriptPath, FAKE_CLI, 'utf8');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
afterEach(async () => {
|
|
44
|
+
for (const orch of orchestrators) {
|
|
45
|
+
try { await orch.stopOwnerNode(); } catch { /* ignore */ }
|
|
46
|
+
}
|
|
47
|
+
orchestrators.length = 0;
|
|
48
|
+
await sleep(50);
|
|
49
|
+
try { rmSync(tmpRoot, { recursive: true, force: true }); } catch { /* ignore */ }
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
function makeOrchestrator(rootDir: string, pushResolver?: () => Promise<PushCredentials | undefined>): HostProcessOrchestrator {
|
|
53
|
+
mkdirSync(rootDir, { recursive: true });
|
|
54
|
+
const orch = new HostProcessOrchestrator({
|
|
55
|
+
rootDir,
|
|
56
|
+
portRange: { start: 18000, end: 18499 },
|
|
57
|
+
stopTimeoutMs: 1500,
|
|
58
|
+
spawn: { entrypoint: scriptPath },
|
|
59
|
+
...(pushResolver ? { pushResolver } : {}),
|
|
60
|
+
});
|
|
61
|
+
orchestrators.push(orch);
|
|
62
|
+
return orch;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function readChildConfig(rootDir: string, containerId = OWNER_CONTAINER_ID): Record<string, unknown> {
|
|
66
|
+
const raw = readFileSync(join(rootDir, containerId, 'cadre.json'), 'utf8');
|
|
67
|
+
return JSON.parse(raw) as Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function sleep(ms: number): Promise<void> {
|
|
71
|
+
return new Promise((res) => setTimeout(res, ms));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
describe('HostProcessOrchestrator push injection', () => {
|
|
75
|
+
it('writes config.push into cadre.json when the resolver yields credentials', async () => {
|
|
76
|
+
const rootDir = join(tmpRoot, 'a');
|
|
77
|
+
const orch = makeOrchestrator(rootDir, async () => ({ fcm: FCM, apns: APNS, cooldownMs: 1000 }));
|
|
78
|
+
await orch.init();
|
|
79
|
+
await orch.ensureOwnerNode(CFG);
|
|
80
|
+
|
|
81
|
+
const cfg = readChildConfig(rootDir);
|
|
82
|
+
expect(cfg.push).toEqual({ fcm: FCM, apns: APNS, cooldownMs: 1000 });
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('omits config.push when no resolver is configured', async () => {
|
|
86
|
+
const rootDir = join(tmpRoot, 'b');
|
|
87
|
+
const orch = makeOrchestrator(rootDir);
|
|
88
|
+
await orch.init();
|
|
89
|
+
await orch.ensureOwnerNode(CFG);
|
|
90
|
+
|
|
91
|
+
const cfg = readChildConfig(rootDir);
|
|
92
|
+
expect(cfg.push).toBeUndefined();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('omits config.push when the resolver returns undefined (push opt-in)', async () => {
|
|
96
|
+
const rootDir = join(tmpRoot, 'c');
|
|
97
|
+
const orch = makeOrchestrator(rootDir, async () => undefined);
|
|
98
|
+
await orch.init();
|
|
99
|
+
await orch.ensureOwnerNode(CFG);
|
|
100
|
+
|
|
101
|
+
expect(readChildConfig(rootDir).push).toBeUndefined();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('degrades to no push (does not fail the spawn) when the resolver throws', async () => {
|
|
105
|
+
const rootDir = join(tmpRoot, 'd');
|
|
106
|
+
const orch = makeOrchestrator(rootDir, async () => { throw new Error('partial creds'); });
|
|
107
|
+
await orch.init();
|
|
108
|
+
// Spawn still succeeds.
|
|
109
|
+
const node = await orch.ensureOwnerNode(CFG);
|
|
110
|
+
expect(node.id).toBe(OWNER_CONTAINER_ID);
|
|
111
|
+
expect(readChildConfig(rootDir).push).toBeUndefined();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('re-resolves on re-spawn and never persists a raw private key in state.json', async () => {
|
|
115
|
+
const rootDir = join(tmpRoot, 'e');
|
|
116
|
+
let current: PushCredentials | undefined = { fcm: FCM };
|
|
117
|
+
const orch = makeOrchestrator(rootDir, async () => current);
|
|
118
|
+
await orch.init();
|
|
119
|
+
await orch.ensureOwnerNode(CFG);
|
|
120
|
+
expect(readChildConfig(rootDir).push).toEqual({ fcm: FCM });
|
|
121
|
+
|
|
122
|
+
// state.json must not carry the raw key — only re-resolvable references.
|
|
123
|
+
const stateRaw = readFileSync(join(rootDir, 'state.json'), 'utf8');
|
|
124
|
+
expect(stateRaw).not.toContain('FCM-SECRET-PEM');
|
|
125
|
+
|
|
126
|
+
// Rotate the resolver's answer, then restart — the new spawn must pick it up.
|
|
127
|
+
current = { apns: APNS };
|
|
128
|
+
await orch.restartOwnerNode();
|
|
129
|
+
const cfg2 = readChildConfig(rootDir);
|
|
130
|
+
expect(cfg2.push).toEqual({ apns: APNS });
|
|
131
|
+
expect((cfg2.push as PushCredentials).fcm).toBeUndefined();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('injects push for a storage-profile managed node but not a transaction node', async () => {
|
|
135
|
+
const rootDir = join(tmpRoot, 'f');
|
|
136
|
+
const orch = makeOrchestrator(rootDir, async () => ({ fcm: FCM }));
|
|
137
|
+
await orch.init();
|
|
138
|
+
|
|
139
|
+
await orch.createContainer({ containerId: 'storage-1', partyId: 'p', bootstrapNodes: [], profile: 'storage' });
|
|
140
|
+
expect(readChildConfig(rootDir, 'storage-1').push).toEqual({ fcm: FCM });
|
|
141
|
+
|
|
142
|
+
await orch.createContainer({ containerId: 'txn-1', partyId: 'p', bootstrapNodes: [], profile: 'transaction' });
|
|
143
|
+
expect(readChildConfig(rootDir, 'txn-1').push).toBeUndefined();
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -2,10 +2,9 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
|
2
2
|
import { mkdtempSync, rmSync } from 'node:fs';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
-
import { generatePrivateKey, getPublicKey } from '@optimystic/quereus-plugin-crypto';
|
|
6
5
|
import { generateKeyPair } from '@libp2p/crypto/keys';
|
|
7
6
|
import { peerIdFromPrivateKey } from '@libp2p/peer-id';
|
|
8
|
-
import { CadreNode } from '@serfab/cadre-core';
|
|
7
|
+
import { CadreNode, ed25519KeyPairFromLibp2p } from '@serfab/cadre-core';
|
|
9
8
|
|
|
10
9
|
import { TrustCircleService } from '../trust-circle.js';
|
|
11
10
|
import { TrustCircleStore } from '../trust-circle-store.js';
|
|
@@ -30,24 +29,25 @@ describe('TrustCircleService — real CadreNode integration', () => {
|
|
|
30
29
|
let host: CadreNode;
|
|
31
30
|
let store: TrustCircleStore;
|
|
32
31
|
let service: TrustCircleService;
|
|
33
|
-
let
|
|
34
|
-
let
|
|
32
|
+
let hostOwnerPrivateKey: string;
|
|
33
|
+
let hostOwnerPublicKey: string;
|
|
35
34
|
|
|
36
35
|
beforeEach(async () => {
|
|
37
36
|
tmpRoot = mkdtempSync(join(tmpdir(), 'cadre-host-tc-int-'));
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
// Own-owner host: the node's libp2p identity key IS its owner key
|
|
39
|
+
// (the cadre-cli `--owner` shape), so registerSelf can owner-sign the
|
|
40
|
+
// INSERT of its own CadrePeer row.
|
|
41
|
+
const hostKey = await generateKeyPair('Ed25519');
|
|
42
|
+
const owner = ed25519KeyPairFromLibp2p(hostKey);
|
|
43
|
+
hostOwnerPrivateKey = owner.privateKeyB64;
|
|
44
|
+
hostOwnerPublicKey = owner.publicKeyB64;
|
|
46
45
|
|
|
47
46
|
const baseId = Math.random().toString(36).slice(2);
|
|
48
47
|
|
|
49
48
|
host = new CadreNode({
|
|
50
49
|
controlNetwork: { partyId: `host-${baseId}`, bootstrapNodes: [] },
|
|
50
|
+
privateKey: hostKey,
|
|
51
51
|
profile: 'transaction'
|
|
52
52
|
});
|
|
53
53
|
|
|
@@ -55,9 +55,14 @@ describe('TrustCircleService — real CadreNode integration', () => {
|
|
|
55
55
|
|
|
56
56
|
const db = host.getControlDatabase();
|
|
57
57
|
expect(db).not.toBeNull();
|
|
58
|
-
await db!.
|
|
58
|
+
await db!.insertOwnerKey(hostOwnerPublicKey);
|
|
59
59
|
|
|
60
|
-
host.initializeSeedBootstrap(
|
|
60
|
+
host.initializeSeedBootstrap(hostOwnerPrivateKey);
|
|
61
|
+
|
|
62
|
+
// The owner writes its own CadrePeer row up-front (the implement ticket's
|
|
63
|
+
// CLI change). After this the host's own peerId is a member, so it shows up
|
|
64
|
+
// alongside any redeemed peers in the trust-circle listing.
|
|
65
|
+
await host.registerSelf();
|
|
61
66
|
|
|
62
67
|
store = new TrustCircleStore(tmpRoot);
|
|
63
68
|
service = new TrustCircleService({ cadreNode: host, store });
|
|
@@ -68,7 +73,7 @@ describe('TrustCircleService — real CadreNode integration', () => {
|
|
|
68
73
|
try { rmSync(tmpRoot, { recursive: true, force: true }); } catch { /* ignore */ }
|
|
69
74
|
});
|
|
70
75
|
|
|
71
|
-
it('
|
|
76
|
+
it('issues → redeems → lists against the real control DB (listMembers path)', async () => {
|
|
72
77
|
// Derive a shape-valid peerId from a fresh Ed25519 key — same pattern as
|
|
73
78
|
// packages/cadre-core/test/seed-bootstrap.spec.ts. The AuthorizedInsert
|
|
74
79
|
// constraint only checks the signature over digest(PeerId,…); peerId
|
|
@@ -92,25 +97,39 @@ describe('TrustCircleService — real CadreNode integration', () => {
|
|
|
92
97
|
// Verify directly against the control DB: the row is there.
|
|
93
98
|
expect(await isInCadrePeer(host, phonePeerId)).toBe(true);
|
|
94
99
|
|
|
95
|
-
// List —
|
|
100
|
+
// List — exercises the CadreNode.listMembers() path. CadrePeer now carries
|
|
101
|
+
// the host's own self-registered row in addition to the redeemed phone.
|
|
96
102
|
const snap = await service.list();
|
|
97
|
-
expect(snap.members).toHaveLength(
|
|
98
|
-
|
|
99
|
-
expect(
|
|
103
|
+
expect(snap.members).toHaveLength(2);
|
|
104
|
+
const phoneMember = snap.members.find((m) => m.peerId === phonePeerId);
|
|
105
|
+
expect(phoneMember).toBeDefined();
|
|
106
|
+
expect(phoneMember!.label).toBe("Mom's phone");
|
|
107
|
+
// The host's own peerId is present too (unlabeled → bare peerId as label).
|
|
108
|
+
expect(snap.members.some((m) => m.peerId === host.peerId!.toString())).toBe(true);
|
|
100
109
|
expect(snap.pending).toHaveLength(0);
|
|
110
|
+
}, 90_000);
|
|
111
|
+
|
|
112
|
+
// The signed `CadrePeer` DELETE previously threw a Quereus deferred-constraint
|
|
113
|
+
// error ("No row context found for column PeerId") inside cadre-core's
|
|
114
|
+
// removePeer. That upstream bug is fixed (`quereus-cadrepeer-delete-no-row-context`,
|
|
115
|
+
// landed), so the full issue → redeem → remove cycle is now exercised here.
|
|
116
|
+
it('removes a member from CadrePeer', async () => {
|
|
117
|
+
const phoneKey = await generateKeyPair('Ed25519');
|
|
118
|
+
const phonePeerId = peerIdFromPrivateKey(phoneKey).toString();
|
|
119
|
+
|
|
120
|
+
const issued = await service.issueInvite({ label: "Mom's phone" });
|
|
121
|
+
await service.redeemInvite({ token: issued.token, peerId: phonePeerId });
|
|
122
|
+
expect(await isInCadrePeer(host, phonePeerId)).toBe(true);
|
|
101
123
|
|
|
102
|
-
// Remove
|
|
103
124
|
await service.removeMember(phonePeerId);
|
|
104
125
|
|
|
105
|
-
// CadrePeer row is gone (validates DELETE-with-context end-to-end).
|
|
106
126
|
expect(await isInCadrePeer(host, phonePeerId)).toBe(false);
|
|
107
|
-
|
|
108
|
-
// Local label is gone.
|
|
109
127
|
expect(store.getMember(phonePeerId)).toBeUndefined();
|
|
110
|
-
|
|
111
|
-
// list() reflects the removal.
|
|
112
128
|
const afterRemove = await service.list();
|
|
113
|
-
|
|
129
|
+
// The phone is gone; the host's own self-registered row remains.
|
|
130
|
+
expect(afterRemove.members.map((m) => m.peerId)).not.toContain(phonePeerId);
|
|
131
|
+
expect(afterRemove.members).toHaveLength(1);
|
|
132
|
+
expect(afterRemove.members[0]!.peerId).toBe(host.peerId!.toString());
|
|
114
133
|
}, 90_000);
|
|
115
134
|
});
|
|
116
135
|
|