@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.
Files changed (198) hide show
  1. package/dist/auth/index.d.ts +2 -0
  2. package/dist/auth/index.js +1 -0
  3. package/dist/auth/index.js.map +1 -1
  4. package/dist/auth/self-label.d.ts +36 -0
  5. package/dist/auth/self-label.js +57 -0
  6. package/dist/auth/self-label.js.map +1 -0
  7. package/dist/auth/trust-circle.d.ts +36 -9
  8. package/dist/auth/trust-circle.js +40 -20
  9. package/dist/auth/trust-circle.js.map +1 -1
  10. package/dist/auth/types.d.ts +2 -2
  11. package/dist/bin/host.js +291 -54
  12. package/dist/bin/host.js.map +1 -1
  13. package/dist/donation/__tests__/fake-orchestrator.d.ts +103 -0
  14. package/dist/donation/__tests__/fake-orchestrator.js +180 -0
  15. package/dist/donation/__tests__/fake-orchestrator.js.map +1 -0
  16. package/dist/donation/donation-service.d.ts +361 -0
  17. package/dist/donation/donation-service.js +763 -0
  18. package/dist/donation/donation-service.js.map +1 -0
  19. package/dist/donation/donation-store.d.ts +49 -0
  20. package/dist/donation/donation-store.js +148 -0
  21. package/dist/donation/donation-store.js.map +1 -0
  22. package/dist/donation/donation-supervisor.d.ts +167 -0
  23. package/dist/donation/donation-supervisor.js +341 -0
  24. package/dist/donation/donation-supervisor.js.map +1 -0
  25. package/dist/donation/grant-service.d.ts +71 -0
  26. package/dist/donation/grant-service.js +163 -0
  27. package/dist/donation/grant-service.js.map +1 -0
  28. package/dist/donation/grant-store.d.ts +38 -0
  29. package/dist/donation/grant-store.js +135 -0
  30. package/dist/donation/grant-store.js.map +1 -0
  31. package/dist/donation/index.d.ts +20 -0
  32. package/dist/donation/index.js +17 -0
  33. package/dist/donation/index.js.map +1 -0
  34. package/dist/donation/types.d.ts +201 -0
  35. package/dist/donation/types.js +40 -0
  36. package/dist/donation/types.js.map +1 -0
  37. package/dist/index.d.ts +9 -5
  38. package/dist/index.js +7 -3
  39. package/dist/index.js.map +1 -1
  40. package/dist/installer/config.d.ts +26 -0
  41. package/dist/installer/config.js +13 -0
  42. package/dist/installer/config.js.map +1 -1
  43. package/dist/installer/index.d.ts +2 -0
  44. package/dist/installer/index.js +3 -0
  45. package/dist/installer/index.js.map +1 -1
  46. package/dist/installer/wizard.d.ts +4 -0
  47. package/dist/installer/wizard.js +5 -1
  48. package/dist/installer/wizard.js.map +1 -1
  49. package/dist/nat/nat-service.d.ts +5 -5
  50. package/dist/nat/nat-service.js +9 -9
  51. package/dist/nat/nat-service.js.map +1 -1
  52. package/dist/nat/types.d.ts +1 -1
  53. package/dist/orchestrator/host-process-orchestrator.d.ts +144 -32
  54. package/dist/orchestrator/host-process-orchestrator.js +397 -128
  55. package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
  56. package/dist/orchestrator/index.d.ts +3 -3
  57. package/dist/orchestrator/index.js +1 -1
  58. package/dist/orchestrator/index.js.map +1 -1
  59. package/dist/orchestrator/node-identity.d.ts +26 -0
  60. package/dist/orchestrator/node-identity.js +36 -0
  61. package/dist/orchestrator/node-identity.js.map +1 -0
  62. package/dist/orchestrator/port-allocator.d.ts +14 -0
  63. package/dist/orchestrator/port-allocator.js +45 -0
  64. package/dist/orchestrator/port-allocator.js.map +1 -1
  65. package/dist/orchestrator/state-store.d.ts +5 -5
  66. package/dist/orchestrator/state-store.js +2 -2
  67. package/dist/orchestrator/state-store.js.map +1 -1
  68. package/dist/orchestrator/types.d.ts +8 -8
  69. package/dist/owner/index.d.ts +11 -0
  70. package/dist/owner/index.js +11 -0
  71. package/dist/owner/index.js.map +1 -0
  72. package/dist/owner/owner-node-client.d.ts +110 -0
  73. package/dist/{authority/authority-node-client.js → owner/owner-node-client.js} +58 -17
  74. package/dist/owner/owner-node-client.js.map +1 -0
  75. package/dist/server/error-handler.d.ts +22 -1
  76. package/dist/server/error-handler.js +64 -1
  77. package/dist/server/error-handler.js.map +1 -1
  78. package/dist/server/events/types.d.ts +3 -0
  79. package/dist/server/index.d.ts +33 -2
  80. package/dist/server/index.js +43 -16
  81. package/dist/server/index.js.map +1 -1
  82. package/dist/server/routes/grants-admin.d.ts +17 -0
  83. package/dist/server/routes/grants-admin.js +32 -0
  84. package/dist/server/routes/grants-admin.js.map +1 -0
  85. package/dist/server/routes/grants.d.ts +28 -0
  86. package/dist/server/routes/grants.js +182 -0
  87. package/dist/server/routes/grants.js.map +1 -0
  88. package/dist/server/routes/nodes.d.ts +5 -4
  89. package/dist/server/routes/nodes.js +19 -18
  90. package/dist/server/routes/nodes.js.map +1 -1
  91. package/dist/server/routes/settings.d.ts +6 -1
  92. package/dist/server/routes/settings.js +5 -2
  93. package/dist/server/routes/settings.js.map +1 -1
  94. package/dist/server/routes/status.d.ts +8 -4
  95. package/dist/server/routes/status.js +9 -4
  96. package/dist/server/routes/status.js.map +1 -1
  97. package/dist/server/routes/strands.d.ts +20 -0
  98. package/dist/server/routes/strands.js +38 -0
  99. package/dist/server/routes/strands.js.map +1 -0
  100. package/dist/strands/index.d.ts +7 -0
  101. package/dist/strands/index.js +6 -0
  102. package/dist/strands/index.js.map +1 -0
  103. package/dist/strands/strand-service.d.ts +50 -0
  104. package/dist/strands/strand-service.js +103 -0
  105. package/dist/strands/strand-service.js.map +1 -0
  106. package/dist/strands/types.d.ts +93 -0
  107. package/dist/strands/types.js +23 -0
  108. package/dist/strands/types.js.map +1 -0
  109. package/dist/ui/assets/index-BVoqLjyX.css +1 -0
  110. package/dist/ui/assets/index-C-iks41M.js +17 -0
  111. package/dist/ui/assets/index-C-iks41M.js.map +1 -0
  112. package/dist/ui/index.html +2 -2
  113. package/dist/update/release-key.d.ts +1 -1
  114. package/dist/update/release-key.js +8 -6
  115. package/dist/update/release-key.js.map +1 -1
  116. package/package.json +5 -5
  117. package/src/__tests__/build-targets.test.ts +26 -0
  118. package/src/__tests__/global-setup.ts +51 -0
  119. package/src/__tests__/{host-authority.smoke.test.ts → host-owner.smoke.test.ts} +7 -7
  120. package/src/__tests__/orchestrator-env-scrub.test.ts +140 -0
  121. package/src/__tests__/orchestrator-node-identity.test.ts +204 -0
  122. package/src/__tests__/{orchestrator-authority.test.ts → orchestrator-owner.test.ts} +33 -33
  123. package/src/__tests__/orchestrator-pin-keys.test.ts +153 -0
  124. package/src/__tests__/orchestrator-push.test.ts +10 -10
  125. package/src/__tests__/orchestrator.test.ts +387 -6
  126. package/src/auth/__tests__/self-label.test.ts +85 -0
  127. package/src/auth/__tests__/trust-circle-integration.test.ts +152 -147
  128. package/src/auth/__tests__/trust-circle.test.ts +55 -11
  129. package/src/auth/index.ts +2 -0
  130. package/src/auth/self-label.ts +74 -0
  131. package/src/auth/trust-circle.ts +54 -22
  132. package/src/auth/types.ts +2 -2
  133. package/src/bin/host.ts +1299 -1038
  134. package/src/donation/__tests__/donation-service.test.ts +1068 -0
  135. package/src/donation/__tests__/donation-supervisor.test.ts +510 -0
  136. package/src/donation/__tests__/fake-orchestrator.test.ts +168 -0
  137. package/src/donation/__tests__/fake-orchestrator.ts +225 -0
  138. package/src/donation/__tests__/grant-service.test.ts +213 -0
  139. package/src/donation/__tests__/grant-store.test.ts +113 -0
  140. package/src/donation/donation-service.ts +962 -0
  141. package/src/donation/donation-store.ts +171 -0
  142. package/src/donation/donation-supervisor.ts +388 -0
  143. package/src/donation/grant-service.ts +200 -0
  144. package/src/donation/grant-store.ts +152 -0
  145. package/src/donation/index.ts +64 -0
  146. package/src/donation/types.ts +243 -0
  147. package/src/index.ts +51 -5
  148. package/src/installer/__tests__/config.test.ts +27 -1
  149. package/src/installer/__tests__/installer.smoke.test.ts +31 -1
  150. package/src/installer/__tests__/wizard.test.ts +5 -1
  151. package/src/installer/config.ts +34 -0
  152. package/src/installer/index.ts +5 -0
  153. package/src/installer/wizard.ts +12 -1
  154. package/src/nat/__tests__/nat-service.test.ts +5 -5
  155. package/src/nat/nat-service.ts +10 -10
  156. package/src/nat/types.ts +1 -1
  157. package/src/orchestrator/__tests__/node-identity.test.ts +62 -0
  158. package/src/orchestrator/host-process-orchestrator.ts +401 -134
  159. package/src/orchestrator/index.ts +3 -3
  160. package/src/orchestrator/node-identity.ts +40 -0
  161. package/src/orchestrator/port-allocator.ts +48 -0
  162. package/src/orchestrator/state-store.ts +7 -7
  163. package/src/orchestrator/types.ts +8 -8
  164. package/src/{authority/__tests__/authority-node-client.test.ts → owner/__tests__/owner-node-client.test.ts} +45 -17
  165. package/src/owner/index.ts +12 -0
  166. package/src/{authority/authority-node-client.ts → owner/owner-node-client.ts} +83 -23
  167. package/src/server/__tests__/error-handler.test.ts +22 -0
  168. package/src/server/__tests__/grants-admin-route.test.ts +73 -0
  169. package/src/server/__tests__/grants-route.test.ts +263 -0
  170. package/src/server/__tests__/nodes-route.test.ts +25 -25
  171. package/src/server/__tests__/server.smoke.test.ts +75 -0
  172. package/src/server/__tests__/settings-route.test.ts +17 -0
  173. package/src/server/__tests__/status-route.test.ts +21 -0
  174. package/src/server/__tests__/strands-route.test.ts +233 -0
  175. package/src/server/error-handler.ts +67 -1
  176. package/src/server/events/types.ts +1 -0
  177. package/src/server/index.ts +75 -17
  178. package/src/server/routes/grants-admin.ts +41 -0
  179. package/src/server/routes/grants.ts +210 -0
  180. package/src/server/routes/nodes.ts +19 -18
  181. package/src/server/routes/settings.ts +11 -3
  182. package/src/server/routes/status.ts +18 -8
  183. package/src/server/routes/strands.ts +54 -0
  184. package/src/strands/__tests__/strand-service.test.ts +165 -0
  185. package/src/strands/index.ts +14 -0
  186. package/src/strands/strand-service.ts +135 -0
  187. package/src/strands/types.ts +102 -0
  188. package/src/update/__tests__/release-key.test.ts +16 -3
  189. package/src/update/release-key.ts +8 -6
  190. package/dist/authority/authority-node-client.d.ts +0 -77
  191. package/dist/authority/authority-node-client.js.map +0 -1
  192. package/dist/authority/index.d.ts +0 -11
  193. package/dist/authority/index.js +0 -11
  194. package/dist/authority/index.js.map +0 -1
  195. package/dist/ui/assets/index-BlMXQPSw.js +0 -14
  196. package/dist/ui/assets/index-BlMXQPSw.js.map +0 -1
  197. package/dist/ui/assets/index-BwU5mJGF.css +0 -1
  198. package/src/authority/index.ts +0 -12
@@ -1,10 +1,10 @@
1
1
  /**
2
- * HostProcessOrchestrator authority-node lifecycle tests.
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 AuthorityNodeClient round-trip, and init() re-attach.
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, AUTHORITY_CONTAINER_ID } from '../orchestrator/host-process-orchestrator.js';
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 { AuthorityNodeClient } from '../authority/authority-node-client.js';
19
+ import { OwnerNodeClient } from '../owner/owner-node-client.js';
20
20
 
21
- const FAKE_AUTHORITY_CLI = `
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 authority up');
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-authority.mjs');
69
- writeFileSync(scriptPath, FAKE_AUTHORITY_CLI, 'utf8');
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.stopAuthorityNode(); } catch { /* ignore */ }
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.ensureAuthorityNode', () => {
117
- it('spawns the authority node, allocates+persists an admin port', async () => {
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.ensureAuthorityNode(CFG);
120
+ const node = await orch.ensureOwnerNode(CFG);
121
121
 
122
- expect(node.id).toBe(AUTHORITY_CONTAINER_ID);
123
- expect(node.authority).toBe(true);
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.getAuthorityAdminEndpoint();
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 + authority flag + authorityConfig.
131
+ // Persisted with admin port + owner flag + ownerConfig.
132
132
  const persisted = new StateStore(join(tmpRoot, 'a')).load();
133
- expect(persisted.authorityConfig).toMatchObject({ partyId: 'install-id-123', libp2pPort: 4555 });
134
- const ph = persisted.handles.find((h) => h.containerId === AUTHORITY_CONTAINER_ID);
135
- expect(ph?.authority).toBe(true);
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.ensureAuthorityNode(CFG);
142
+ const first = await orch.ensureOwnerNode(CFG);
143
143
  await waitFor(() => orch.isRunning(first.dockerId));
144
144
 
145
- const second = await orch.ensureAuthorityNode(CFG);
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 AuthorityNodeClient reaches the spawned admin channel', async () => {
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.ensureAuthorityNode(CFG);
153
+ const node = await orch.ensureOwnerNode(CFG);
154
154
  await waitFor(() => orch.isRunning(node.dockerId));
155
155
 
156
- const client = new AuthorityNodeClient(() => orch.getAuthorityAdminEndpoint());
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('getAuthorityAdminEndpoint() survives an init() re-attach', async () => {
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.ensureAuthorityNode(CFG);
167
+ const node = await a.ensureOwnerNode(CFG);
168
168
  await waitFor(() => a.isRunning(node.dockerId));
169
- const before = a.getAuthorityAdminEndpoint();
169
+ const before = a.getOwnerAdminEndpoint();
170
170
 
171
171
  const b = makeOrchestrator(rootDir);
172
172
  await b.init();
173
- expect(b.isAuthorityNode(AUTHORITY_CONTAINER_ID)).toBe(true);
174
- expect(b.hasAuthorityConfig()).toBe(true);
175
- const after = b.getAuthorityAdminEndpoint();
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('restartAuthorityNode preserves the workdir and re-spawns', async () => {
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.ensureAuthorityNode(CFG);
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.restartAuthorityNode();
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, AUTHORITY_CONTAINER_ID } from '../orchestrator/host-process-orchestrator.js';
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.stopAuthorityNode(); } catch { /* ignore */ }
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 = AUTHORITY_CONTAINER_ID): Record<string, unknown> {
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.ensureAuthorityNode(CFG);
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.ensureAuthorityNode(CFG);
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.ensureAuthorityNode(CFG);
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.ensureAuthorityNode(CFG);
110
- expect(node.id).toBe(AUTHORITY_CONTAINER_ID);
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.ensureAuthorityNode(CFG);
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.restartAuthorityNode();
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();