@serfab/cadre-host 0.8.1 → 0.10.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/dist/auth/index.d.ts +2 -0
- package/dist/auth/index.js +1 -0
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/self-label.d.ts +36 -0
- package/dist/auth/self-label.js +57 -0
- package/dist/auth/self-label.js.map +1 -0
- package/dist/auth/trust-circle.d.ts +36 -9
- package/dist/auth/trust-circle.js +40 -20
- package/dist/auth/trust-circle.js.map +1 -1
- package/dist/auth/types.d.ts +2 -2
- package/dist/bin/host.js +291 -54
- package/dist/bin/host.js.map +1 -1
- package/dist/donation/__tests__/fake-orchestrator.d.ts +103 -0
- package/dist/donation/__tests__/fake-orchestrator.js +180 -0
- package/dist/donation/__tests__/fake-orchestrator.js.map +1 -0
- package/dist/donation/donation-service.d.ts +361 -0
- package/dist/donation/donation-service.js +763 -0
- package/dist/donation/donation-service.js.map +1 -0
- package/dist/donation/donation-store.d.ts +49 -0
- package/dist/donation/donation-store.js +148 -0
- package/dist/donation/donation-store.js.map +1 -0
- package/dist/donation/donation-supervisor.d.ts +167 -0
- package/dist/donation/donation-supervisor.js +341 -0
- package/dist/donation/donation-supervisor.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 +20 -0
- package/dist/donation/index.js +17 -0
- package/dist/donation/index.js.map +1 -0
- package/dist/donation/types.d.ts +201 -0
- package/dist/donation/types.js +40 -0
- package/dist/donation/types.js.map +1 -0
- package/dist/index.d.ts +9 -5
- package/dist/index.js +7 -3
- package/dist/index.js.map +1 -1
- package/dist/installer/config.d.ts +26 -0
- package/dist/installer/config.js +13 -0
- package/dist/installer/config.js.map +1 -1
- package/dist/installer/index.d.ts +2 -0
- package/dist/installer/index.js +3 -0
- package/dist/installer/index.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/nat-service.d.ts +5 -5
- package/dist/nat/nat-service.js +9 -9
- package/dist/nat/nat-service.js.map +1 -1
- package/dist/nat/types.d.ts +1 -1
- package/dist/orchestrator/host-process-orchestrator.d.ts +144 -32
- package/dist/orchestrator/host-process-orchestrator.js +397 -128
- package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
- package/dist/orchestrator/index.d.ts +3 -3
- package/dist/orchestrator/index.js +1 -1
- package/dist/orchestrator/index.js.map +1 -1
- package/dist/orchestrator/node-identity.d.ts +26 -0
- package/dist/orchestrator/node-identity.js +36 -0
- package/dist/orchestrator/node-identity.js.map +1 -0
- package/dist/orchestrator/port-allocator.d.ts +14 -0
- package/dist/orchestrator/port-allocator.js +45 -0
- package/dist/orchestrator/port-allocator.js.map +1 -1
- package/dist/orchestrator/state-store.d.ts +5 -5
- package/dist/orchestrator/state-store.js +2 -2
- package/dist/orchestrator/state-store.js.map +1 -1
- package/dist/orchestrator/types.d.ts +8 -8
- 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 +110 -0
- package/dist/{authority/authority-node-client.js → owner/owner-node-client.js} +58 -17
- package/dist/owner/owner-node-client.js.map +1 -0
- package/dist/server/error-handler.d.ts +22 -1
- package/dist/server/error-handler.js +64 -1
- package/dist/server/error-handler.js.map +1 -1
- package/dist/server/events/types.d.ts +3 -0
- package/dist/server/index.d.ts +33 -2
- package/dist/server/index.js +43 -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 +182 -0
- package/dist/server/routes/grants.js.map +1 -0
- package/dist/server/routes/nodes.d.ts +5 -4
- package/dist/server/routes/nodes.js +19 -18
- 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/routes/strands.d.ts +20 -0
- package/dist/server/routes/strands.js +38 -0
- package/dist/server/routes/strands.js.map +1 -0
- package/dist/strands/index.d.ts +7 -0
- package/dist/strands/index.js +6 -0
- package/dist/strands/index.js.map +1 -0
- package/dist/strands/strand-service.d.ts +50 -0
- package/dist/strands/strand-service.js +103 -0
- package/dist/strands/strand-service.js.map +1 -0
- package/dist/strands/types.d.ts +93 -0
- package/dist/strands/types.js +23 -0
- package/dist/strands/types.js.map +1 -0
- package/dist/ui/assets/index-BVoqLjyX.css +1 -0
- package/dist/ui/assets/index-C-iks41M.js +17 -0
- package/dist/ui/assets/index-C-iks41M.js.map +1 -0
- package/dist/ui/index.html +2 -2
- package/dist/update/release-key.d.ts +1 -1
- package/dist/update/release-key.js +8 -6
- package/dist/update/release-key.js.map +1 -1
- package/package.json +5 -5
- package/src/__tests__/build-targets.test.ts +26 -0
- package/src/__tests__/global-setup.ts +51 -0
- package/src/__tests__/{host-authority.smoke.test.ts → host-owner.smoke.test.ts} +7 -7
- package/src/__tests__/orchestrator-env-scrub.test.ts +140 -0
- package/src/__tests__/orchestrator-node-identity.test.ts +204 -0
- package/src/__tests__/{orchestrator-authority.test.ts → orchestrator-owner.test.ts} +33 -33
- package/src/__tests__/orchestrator-pin-keys.test.ts +153 -0
- package/src/__tests__/orchestrator-push.test.ts +10 -10
- package/src/__tests__/orchestrator.test.ts +387 -6
- package/src/auth/__tests__/self-label.test.ts +85 -0
- package/src/auth/__tests__/trust-circle-integration.test.ts +152 -147
- package/src/auth/__tests__/trust-circle.test.ts +55 -11
- package/src/auth/index.ts +2 -0
- package/src/auth/self-label.ts +74 -0
- package/src/auth/trust-circle.ts +54 -22
- package/src/auth/types.ts +2 -2
- package/src/bin/host.ts +1299 -1038
- package/src/donation/__tests__/donation-service.test.ts +1068 -0
- package/src/donation/__tests__/donation-supervisor.test.ts +510 -0
- package/src/donation/__tests__/fake-orchestrator.test.ts +168 -0
- package/src/donation/__tests__/fake-orchestrator.ts +225 -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 +962 -0
- package/src/donation/donation-store.ts +171 -0
- package/src/donation/donation-supervisor.ts +388 -0
- package/src/donation/grant-service.ts +200 -0
- package/src/donation/grant-store.ts +152 -0
- package/src/donation/index.ts +64 -0
- package/src/donation/types.ts +243 -0
- package/src/index.ts +51 -5
- package/src/installer/__tests__/config.test.ts +27 -1
- package/src/installer/__tests__/installer.smoke.test.ts +31 -1
- package/src/installer/__tests__/wizard.test.ts +5 -1
- package/src/installer/config.ts +34 -0
- package/src/installer/index.ts +5 -0
- package/src/installer/wizard.ts +12 -1
- package/src/nat/__tests__/nat-service.test.ts +5 -5
- package/src/nat/nat-service.ts +10 -10
- package/src/nat/types.ts +1 -1
- package/src/orchestrator/__tests__/node-identity.test.ts +62 -0
- package/src/orchestrator/host-process-orchestrator.ts +401 -134
- package/src/orchestrator/index.ts +3 -3
- package/src/orchestrator/node-identity.ts +40 -0
- package/src/orchestrator/port-allocator.ts +48 -0
- package/src/orchestrator/state-store.ts +7 -7
- package/src/orchestrator/types.ts +8 -8
- package/src/{authority/__tests__/authority-node-client.test.ts → owner/__tests__/owner-node-client.test.ts} +45 -17
- package/src/owner/index.ts +12 -0
- package/src/{authority/authority-node-client.ts → owner/owner-node-client.ts} +83 -23
- package/src/server/__tests__/error-handler.test.ts +22 -0
- package/src/server/__tests__/grants-admin-route.test.ts +73 -0
- package/src/server/__tests__/grants-route.test.ts +263 -0
- package/src/server/__tests__/nodes-route.test.ts +25 -25
- package/src/server/__tests__/server.smoke.test.ts +75 -0
- package/src/server/__tests__/settings-route.test.ts +17 -0
- package/src/server/__tests__/status-route.test.ts +21 -0
- package/src/server/__tests__/strands-route.test.ts +233 -0
- package/src/server/error-handler.ts +67 -1
- package/src/server/events/types.ts +1 -0
- package/src/server/index.ts +75 -17
- package/src/server/routes/grants-admin.ts +41 -0
- package/src/server/routes/grants.ts +210 -0
- package/src/server/routes/nodes.ts +19 -18
- package/src/server/routes/settings.ts +11 -3
- package/src/server/routes/status.ts +18 -8
- package/src/server/routes/strands.ts +54 -0
- package/src/strands/__tests__/strand-service.test.ts +165 -0
- package/src/strands/index.ts +14 -0
- package/src/strands/strand-service.ts +135 -0
- package/src/strands/types.ts +102 -0
- package/src/update/__tests__/release-key.test.ts +16 -3
- package/src/update/release-key.ts +8 -6
- package/dist/authority/authority-node-client.d.ts +0 -77
- package/dist/authority/authority-node-client.js.map +0 -1
- package/dist/authority/index.d.ts +0 -11
- package/dist/authority/index.js +0 -11
- package/dist/authority/index.js.map +0 -1
- package/dist/ui/assets/index-BlMXQPSw.js +0 -14
- package/dist/ui/assets/index-BlMXQPSw.js.map +0 -1
- package/dist/ui/assets/index-BwU5mJGF.css +0 -1
- package/src/authority/index.ts +0 -12
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* HostProcessOrchestrator
|
|
2
|
+
* HostProcessOrchestrator owner-node lifecycle tests.
|
|
3
3
|
*
|
|
4
4
|
* Uses the `spawn.entrypoint` hook with a fake CLI that writes its startup
|
|
5
5
|
* token and binds a minimal `/admin/identity` endpoint on the admin port —
|
|
6
6
|
* enough to validate spawn, idempotency, admin-port allocation/persistence,
|
|
7
|
-
* the end-to-end
|
|
7
|
+
* the end-to-end OwnerNodeClient round-trip, and init() re-attach.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
@@ -12,13 +12,13 @@ import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
|
12
12
|
import { tmpdir } from 'node:os';
|
|
13
13
|
import { join } from 'node:path';
|
|
14
14
|
|
|
15
|
-
import { HostProcessOrchestrator,
|
|
15
|
+
import { HostProcessOrchestrator, OWNER_CONTAINER_ID } from '../orchestrator/host-process-orchestrator.js';
|
|
16
16
|
import { StateStore } from '../orchestrator/state-store.js';
|
|
17
17
|
import { isPidAlive } from '../orchestrator/pid-liveness.js';
|
|
18
18
|
import { decodeDockerId } from '../orchestrator/types.js';
|
|
19
|
-
import {
|
|
19
|
+
import { OwnerNodeClient } from '../owner/owner-node-client.js';
|
|
20
20
|
|
|
21
|
-
const
|
|
21
|
+
const FAKE_OWNER_CLI = `
|
|
22
22
|
import fs from 'node:fs';
|
|
23
23
|
import http from 'node:http';
|
|
24
24
|
|
|
@@ -55,7 +55,7 @@ if (adminPort && token) {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
process.on('SIGTERM', () => process.exit(0));
|
|
58
|
-
console.log('fake
|
|
58
|
+
console.log('fake owner up');
|
|
59
59
|
setInterval(() => {}, 1 << 30);
|
|
60
60
|
`;
|
|
61
61
|
|
|
@@ -65,13 +65,13 @@ const orchestrators: HostProcessOrchestrator[] = [];
|
|
|
65
65
|
|
|
66
66
|
beforeEach(() => {
|
|
67
67
|
tmpRoot = mkdtempSync(join(tmpdir(), 'cadre-host-auth-'));
|
|
68
|
-
scriptPath = join(tmpRoot, 'fake-
|
|
69
|
-
writeFileSync(scriptPath,
|
|
68
|
+
scriptPath = join(tmpRoot, 'fake-owner.mjs');
|
|
69
|
+
writeFileSync(scriptPath, FAKE_OWNER_CLI, 'utf8');
|
|
70
70
|
});
|
|
71
71
|
|
|
72
72
|
afterEach(async () => {
|
|
73
73
|
for (const orch of orchestrators) {
|
|
74
|
-
try { await orch.
|
|
74
|
+
try { await orch.stopOwnerNode(); } catch { /* ignore */ }
|
|
75
75
|
for (const dockerId of listDockerIds(orch)) {
|
|
76
76
|
try { await orch.removeContainer(dockerId); } catch { /* ignore */ }
|
|
77
77
|
}
|
|
@@ -113,66 +113,66 @@ function sleep(ms: number): Promise<void> {
|
|
|
113
113
|
|
|
114
114
|
const CFG = { identityPath: 'C:/fake/identity.key', partyId: 'install-id-123', libp2pPort: 4555 };
|
|
115
115
|
|
|
116
|
-
describe('HostProcessOrchestrator.
|
|
117
|
-
it('spawns the
|
|
116
|
+
describe('HostProcessOrchestrator.ensureOwnerNode', () => {
|
|
117
|
+
it('spawns the owner node, allocates+persists an admin port', async () => {
|
|
118
118
|
const orch = makeOrchestrator(join(tmpRoot, 'a'));
|
|
119
119
|
await orch.init();
|
|
120
|
-
const node = await orch.
|
|
120
|
+
const node = await orch.ensureOwnerNode(CFG);
|
|
121
121
|
|
|
122
|
-
expect(node.id).toBe(
|
|
123
|
-
expect(node.
|
|
122
|
+
expect(node.id).toBe(OWNER_CONTAINER_ID);
|
|
123
|
+
expect(node.owner).toBe(true);
|
|
124
124
|
expect(node.ports.admin).toBeGreaterThanOrEqual(18500);
|
|
125
125
|
expect(node.ports.p2p).toBe(4555);
|
|
126
126
|
|
|
127
|
-
const endpoint = orch.
|
|
127
|
+
const endpoint = orch.getOwnerAdminEndpoint();
|
|
128
128
|
expect(endpoint).toBeDefined();
|
|
129
129
|
expect(endpoint!.baseUrl).toBe(`http://127.0.0.1:${node.ports.admin}`);
|
|
130
130
|
|
|
131
|
-
// Persisted with admin port +
|
|
131
|
+
// Persisted with admin port + owner flag + ownerConfig.
|
|
132
132
|
const persisted = new StateStore(join(tmpRoot, 'a')).load();
|
|
133
|
-
expect(persisted.
|
|
134
|
-
const ph = persisted.handles.find((h) => h.containerId ===
|
|
135
|
-
expect(ph?.
|
|
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
136
|
expect(typeof ph?.ports.admin).toBe('number');
|
|
137
137
|
});
|
|
138
138
|
|
|
139
139
|
it('is idempotent — a second call does not spawn a second child', async () => {
|
|
140
140
|
const orch = makeOrchestrator(join(tmpRoot, 'b'));
|
|
141
141
|
await orch.init();
|
|
142
|
-
const first = await orch.
|
|
142
|
+
const first = await orch.ensureOwnerNode(CFG);
|
|
143
143
|
await waitFor(() => orch.isRunning(first.dockerId));
|
|
144
144
|
|
|
145
|
-
const second = await orch.
|
|
145
|
+
const second = await orch.ensureOwnerNode(CFG);
|
|
146
146
|
expect(second.dockerId).toBe(first.dockerId);
|
|
147
147
|
expect(orch.listNodes()).toHaveLength(1);
|
|
148
148
|
});
|
|
149
149
|
|
|
150
|
-
it('the
|
|
150
|
+
it('the OwnerNodeClient reaches the spawned admin channel', async () => {
|
|
151
151
|
const orch = makeOrchestrator(join(tmpRoot, 'c'));
|
|
152
152
|
await orch.init();
|
|
153
|
-
const node = await orch.
|
|
153
|
+
const node = await orch.ensureOwnerNode(CFG);
|
|
154
154
|
await waitFor(() => orch.isRunning(node.dockerId));
|
|
155
155
|
|
|
156
|
-
const client = new
|
|
156
|
+
const client = new OwnerNodeClient(() => orch.getOwnerAdminEndpoint());
|
|
157
157
|
await waitFor(async () => {
|
|
158
158
|
try { return (await client.getPeerId()) === 'FAKEPEER'; } catch { return false; }
|
|
159
159
|
});
|
|
160
160
|
expect(await client.getPeerId()).toBe('FAKEPEER');
|
|
161
161
|
});
|
|
162
162
|
|
|
163
|
-
it('
|
|
163
|
+
it('getOwnerAdminEndpoint() survives an init() re-attach', async () => {
|
|
164
164
|
const rootDir = join(tmpRoot, 'd');
|
|
165
165
|
const a = makeOrchestrator(rootDir);
|
|
166
166
|
await a.init();
|
|
167
|
-
const node = await a.
|
|
167
|
+
const node = await a.ensureOwnerNode(CFG);
|
|
168
168
|
await waitFor(() => a.isRunning(node.dockerId));
|
|
169
|
-
const before = a.
|
|
169
|
+
const before = a.getOwnerAdminEndpoint();
|
|
170
170
|
|
|
171
171
|
const b = makeOrchestrator(rootDir);
|
|
172
172
|
await b.init();
|
|
173
|
-
expect(b.
|
|
174
|
-
expect(b.
|
|
175
|
-
const after = b.
|
|
173
|
+
expect(b.isOwnerNode(OWNER_CONTAINER_ID)).toBe(true);
|
|
174
|
+
expect(b.hasOwnerConfig()).toBe(true);
|
|
175
|
+
const after = b.getOwnerAdminEndpoint();
|
|
176
176
|
expect(after).toEqual(before);
|
|
177
177
|
expect(await b.isRunning(node.dockerId)).toBe(true);
|
|
178
178
|
|
|
@@ -180,14 +180,14 @@ describe('HostProcessOrchestrator.ensureAuthorityNode', () => {
|
|
|
180
180
|
expect(isPidAlive(pid)).toBe(true);
|
|
181
181
|
});
|
|
182
182
|
|
|
183
|
-
it('
|
|
183
|
+
it('restartOwnerNode preserves the workdir and re-spawns', async () => {
|
|
184
184
|
const orch = makeOrchestrator(join(tmpRoot, 'e'));
|
|
185
185
|
await orch.init();
|
|
186
|
-
const first = await orch.
|
|
186
|
+
const first = await orch.ensureOwnerNode(CFG);
|
|
187
187
|
await waitFor(() => orch.isRunning(first.dockerId));
|
|
188
188
|
const { pid: firstPid } = decodeDockerId(first.dockerId);
|
|
189
189
|
|
|
190
|
-
const restarted = await orch.
|
|
190
|
+
const restarted = await orch.restartOwnerNode();
|
|
191
191
|
await waitFor(() => orch.isRunning(restarted.dockerId));
|
|
192
192
|
|
|
193
193
|
// New child (different pid/token), still exactly one node, workdir reused.
|
|
@@ -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
|
+
});
|
|
@@ -13,7 +13,7 @@ import { tmpdir } from 'node:os';
|
|
|
13
13
|
import { join } from 'node:path';
|
|
14
14
|
|
|
15
15
|
import type { PushCredentials } from '@serfab/cadre-core';
|
|
16
|
-
import { HostProcessOrchestrator,
|
|
16
|
+
import { HostProcessOrchestrator, OWNER_CONTAINER_ID } from '../orchestrator/host-process-orchestrator.js';
|
|
17
17
|
|
|
18
18
|
const FAKE_CLI = `
|
|
19
19
|
import fs from 'node:fs';
|
|
@@ -42,7 +42,7 @@ beforeEach(() => {
|
|
|
42
42
|
|
|
43
43
|
afterEach(async () => {
|
|
44
44
|
for (const orch of orchestrators) {
|
|
45
|
-
try { await orch.
|
|
45
|
+
try { await orch.stopOwnerNode(); } catch { /* ignore */ }
|
|
46
46
|
}
|
|
47
47
|
orchestrators.length = 0;
|
|
48
48
|
await sleep(50);
|
|
@@ -62,7 +62,7 @@ function makeOrchestrator(rootDir: string, pushResolver?: () => Promise<PushCred
|
|
|
62
62
|
return orch;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
function readChildConfig(rootDir: string, containerId =
|
|
65
|
+
function readChildConfig(rootDir: string, containerId = OWNER_CONTAINER_ID): Record<string, unknown> {
|
|
66
66
|
const raw = readFileSync(join(rootDir, containerId, 'cadre.json'), 'utf8');
|
|
67
67
|
return JSON.parse(raw) as Record<string, unknown>;
|
|
68
68
|
}
|
|
@@ -76,7 +76,7 @@ describe('HostProcessOrchestrator push injection', () => {
|
|
|
76
76
|
const rootDir = join(tmpRoot, 'a');
|
|
77
77
|
const orch = makeOrchestrator(rootDir, async () => ({ fcm: FCM, apns: APNS, cooldownMs: 1000 }));
|
|
78
78
|
await orch.init();
|
|
79
|
-
await orch.
|
|
79
|
+
await orch.ensureOwnerNode(CFG);
|
|
80
80
|
|
|
81
81
|
const cfg = readChildConfig(rootDir);
|
|
82
82
|
expect(cfg.push).toEqual({ fcm: FCM, apns: APNS, cooldownMs: 1000 });
|
|
@@ -86,7 +86,7 @@ describe('HostProcessOrchestrator push injection', () => {
|
|
|
86
86
|
const rootDir = join(tmpRoot, 'b');
|
|
87
87
|
const orch = makeOrchestrator(rootDir);
|
|
88
88
|
await orch.init();
|
|
89
|
-
await orch.
|
|
89
|
+
await orch.ensureOwnerNode(CFG);
|
|
90
90
|
|
|
91
91
|
const cfg = readChildConfig(rootDir);
|
|
92
92
|
expect(cfg.push).toBeUndefined();
|
|
@@ -96,7 +96,7 @@ describe('HostProcessOrchestrator push injection', () => {
|
|
|
96
96
|
const rootDir = join(tmpRoot, 'c');
|
|
97
97
|
const orch = makeOrchestrator(rootDir, async () => undefined);
|
|
98
98
|
await orch.init();
|
|
99
|
-
await orch.
|
|
99
|
+
await orch.ensureOwnerNode(CFG);
|
|
100
100
|
|
|
101
101
|
expect(readChildConfig(rootDir).push).toBeUndefined();
|
|
102
102
|
});
|
|
@@ -106,8 +106,8 @@ describe('HostProcessOrchestrator push injection', () => {
|
|
|
106
106
|
const orch = makeOrchestrator(rootDir, async () => { throw new Error('partial creds'); });
|
|
107
107
|
await orch.init();
|
|
108
108
|
// Spawn still succeeds.
|
|
109
|
-
const node = await orch.
|
|
110
|
-
expect(node.id).toBe(
|
|
109
|
+
const node = await orch.ensureOwnerNode(CFG);
|
|
110
|
+
expect(node.id).toBe(OWNER_CONTAINER_ID);
|
|
111
111
|
expect(readChildConfig(rootDir).push).toBeUndefined();
|
|
112
112
|
});
|
|
113
113
|
|
|
@@ -116,7 +116,7 @@ describe('HostProcessOrchestrator push injection', () => {
|
|
|
116
116
|
let current: PushCredentials | undefined = { fcm: FCM };
|
|
117
117
|
const orch = makeOrchestrator(rootDir, async () => current);
|
|
118
118
|
await orch.init();
|
|
119
|
-
await orch.
|
|
119
|
+
await orch.ensureOwnerNode(CFG);
|
|
120
120
|
expect(readChildConfig(rootDir).push).toEqual({ fcm: FCM });
|
|
121
121
|
|
|
122
122
|
// state.json must not carry the raw key — only re-resolvable references.
|
|
@@ -125,7 +125,7 @@ describe('HostProcessOrchestrator push injection', () => {
|
|
|
125
125
|
|
|
126
126
|
// Rotate the resolver's answer, then restart — the new spawn must pick it up.
|
|
127
127
|
current = { apns: APNS };
|
|
128
|
-
await orch.
|
|
128
|
+
await orch.restartOwnerNode();
|
|
129
129
|
const cfg2 = readChildConfig(rootDir);
|
|
130
130
|
expect(cfg2.push).toEqual({ apns: APNS });
|
|
131
131
|
expect((cfg2.push as PushCredentials).fcm).toBeUndefined();
|