@serfab/cadre-host 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,168 +1,168 @@
1
- /**
2
- * Contract tests for `FakeOrchestrator` itself — the handle lifecycle it borrows
3
- * from `HostProcessOrchestrator`. The donation suites lean on these semantics to
4
- * express races that only exist because the real class drops and rejects
5
- * handles, so this file exists to stop a later relaxation of the fake from
6
- * quietly turning one of those tests green. Each case names the real behaviour
7
- * it mirrors.
8
- */
9
-
10
- import { describe, expect, it } from 'vitest';
11
-
12
- import type { OrchestratorCreateRequest } from '@serfab/cadre-provider';
13
-
14
- import { FakeOrchestrator } from './fake-orchestrator.js';
15
-
16
- const request = (containerId: string): OrchestratorCreateRequest => ({
17
- containerId,
18
- partyId: 'party-P',
19
- bootstrapNodes: ['/ip4/127.0.0.1/tcp/4001/p2p/12D3KooReq'],
20
- profile: 'storage',
21
- });
22
-
23
- describe('FakeOrchestrator handle lifecycle', () => {
24
- it('drops the prior handle when a re-spawn succeeds (mirrors dropStaleHandle)', async () => {
25
- const orch = new FakeOrchestrator();
26
- const first = await orch.createContainer(request('grn_1'));
27
- const second = await orch.createContainer(request('grn_1'));
28
-
29
- await expect(orch.stopContainer(first.dockerId)).rejects.toThrow(
30
- `Container not found: ${first.dockerId}`,
31
- );
32
- // The rejected call left no trace: `stopped` records handles acted on, not
33
- // calls attempted.
34
- expect(orch.stopped).toEqual([]);
35
- // …and the container now resolves only to the new spawn.
36
- expect(orch.resolveDockerId('grn_1')).toBe(second.dockerId);
37
-
38
- await orch.stopContainer(second.dockerId);
39
- expect(orch.stopped).toEqual([second.dockerId]);
40
- });
41
-
42
- it('drops only the re-spawned container, leaving another container untouched', async () => {
43
- const orch = new FakeOrchestrator();
44
- const other = await orch.createContainer(request('grn_2'));
45
- await orch.createContainer(request('grn_1'));
46
- await orch.createContainer(request('grn_1'));
47
-
48
- // The real drop filters on containerId; a fake that cleared the whole map
49
- // would still pass every same-container case above.
50
- await expect(orch.stopContainer(other.dockerId)).resolves.toBeUndefined();
51
- expect(orch.resolveDockerId('grn_2')).toBe(other.dockerId);
52
- });
53
-
54
- it('keeps the prior handle live across the whole pre-drop await window', async () => {
55
- const orch = new FakeOrchestrator();
56
- const first = await orch.createContainer(request('grn_1'));
57
-
58
- // The invariant the donation race tests rest on: a concurrent stop started
59
- // from `onCreate` still finds the old handle. Deferring it onto a microtask
60
- // puts it strictly after `onCreate` returns and strictly before the
61
- // `createDelayMs` timer, so this one case pins the drop behind BOTH — with
62
- // no dependence on wall-clock timing. The outcome is captured rather than
63
- // rethrown so a regression fails this assertion instead of surfacing as an
64
- // unhandled rejection.
65
- orch.createDelayMs = 1;
66
- let outcome: Promise<string> | undefined;
67
- orch.onCreate = () => {
68
- outcome ??= Promise.resolve()
69
- .then(() => orch.stopContainer(first.dockerId))
70
- .then(() => 'stopped', (err: Error) => `rejected: ${err.message}`);
71
- };
72
-
73
- const second = await orch.createContainer(request('grn_1'));
74
-
75
- expect(await outcome).toBe('stopped');
76
- expect(orch.stopped).toEqual([first.dockerId]);
77
- expect(orch.resolveDockerId('grn_1')).toBe(second.dockerId);
78
- });
79
-
80
- it('leaves the prior handle in place when the re-spawn fails (mirrors restoreDroppedHandles)', async () => {
81
- const orch = new FakeOrchestrator();
82
- const first = await orch.createContainer(request('grn_1'));
83
-
84
- orch.failCreate = true;
85
- await expect(orch.createContainer(request('grn_1'))).rejects.toThrow('spawn boom');
86
-
87
- // Host state is exactly as the failed attempt found it — which is what lets
88
- // `DonationSupervisor.giveUp` still stop the child it knows about.
89
- await expect(orch.stopContainer(first.dockerId)).resolves.toBeUndefined();
90
- expect(orch.stopped).toEqual([first.dockerId]);
91
- expect(orch.resolveDockerId('grn_1')).toBe(first.dockerId);
92
- });
93
-
94
- it('rejects a never-issued dockerId (mirrors requireHandle)', async () => {
95
- const orch = new FakeOrchestrator();
96
-
97
- await expect(orch.removeContainer('dock_nope')).rejects.toThrow(
98
- 'Container not found: dock_nope',
99
- );
100
- expect(orch.removed).toEqual([]);
101
- });
102
-
103
- it('rejects a second call once a handle has been removed (mirrors removeContainer deleting it)', async () => {
104
- const orch = new FakeOrchestrator();
105
- const { dockerId } = await orch.createContainer(request('grn_1'));
106
-
107
- await orch.removeContainer(dockerId);
108
- expect(orch.removed).toEqual([dockerId]);
109
-
110
- await expect(orch.stopContainer(dockerId)).rejects.toThrow(
111
- `Container not found: ${dockerId}`,
112
- );
113
- expect(orch.stopped).toEqual([]);
114
- });
115
-
116
- it('fires onStop for a rejected stop, so a test can still observe the attempt', async () => {
117
- const orch = new FakeOrchestrator();
118
- const attempted: string[] = [];
119
- orch.onStop = (id) => { attempted.push(id); };
120
-
121
- await expect(orch.stopContainer('dock_nope')).rejects.toThrow('Container not found');
122
- expect(attempted).toEqual(['dock_nope']);
123
- expect(orch.stopped).toEqual([]);
124
- });
125
-
126
- it('refuses to reclaim the workdir of a container that still resolves (mirrors the live-handle guard)', async () => {
127
- const orch = new FakeOrchestrator();
128
- await orch.createContainer(request('grn_1'));
129
-
130
- // A live handle owns that directory; only `removeContainer` — which stops
131
- // the child first — may delete it.
132
- expect(orch.reclaimWorkdir('grn_1')).toBe(false);
133
- expect(orch.reclaimedWorkdirs).toEqual([]);
134
- });
135
-
136
- it('reclaims the workdir of a container no handle owns', async () => {
137
- const orch = new FakeOrchestrator();
138
-
139
- // Never spawned — the stuck-`provisioning` record whose host died before a
140
- // handle ever existed.
141
- expect(orch.reclaimWorkdir('grn_orphan')).toBe(true);
142
- expect(orch.reclaimedWorkdirs).toEqual(['grn_orphan']);
143
-
144
- // …and once the container's own handle is removed, its id becomes
145
- // reclaimable too.
146
- const { dockerId } = await orch.createContainer(request('grn_1'));
147
- expect(orch.reclaimWorkdir('grn_1')).toBe(false);
148
- await orch.removeContainer(dockerId);
149
- expect(orch.reclaimWorkdir('grn_1')).toBe(true);
150
- expect(orch.reclaimedWorkdirs).toEqual(['grn_orphan', 'grn_1']);
151
- });
152
-
153
- it('fires onSpawned after the drop, with the new handle live and the old one gone', async () => {
154
- const orch = new FakeOrchestrator();
155
- const first = await orch.createContainer(request('grn_1'));
156
-
157
- let observed: { spawned: string; resolves: string | undefined } | undefined;
158
- orch.onSpawned = (dockerId) => {
159
- observed = { spawned: dockerId, resolves: orch.resolveDockerId('grn_1') };
160
- };
161
- const second = await orch.createContainer(request('grn_1'));
162
-
163
- // The post-drop world: the container already resolves to the new handle, so
164
- // work driven from here sees what `abandonRespawn`'s caller would see.
165
- expect(observed).toEqual({ spawned: second.dockerId, resolves: second.dockerId });
166
- expect(second.dockerId).not.toBe(first.dockerId);
167
- });
168
- });
1
+ /**
2
+ * Contract tests for `FakeOrchestrator` itself — the handle lifecycle it borrows
3
+ * from `HostProcessOrchestrator`. The donation suites lean on these semantics to
4
+ * express races that only exist because the real class drops and rejects
5
+ * handles, so this file exists to stop a later relaxation of the fake from
6
+ * quietly turning one of those tests green. Each case names the real behaviour
7
+ * it mirrors.
8
+ */
9
+
10
+ import { describe, expect, it } from 'vitest';
11
+
12
+ import type { OrchestratorCreateRequest } from '@serfab/cadre-provider';
13
+
14
+ import { FakeOrchestrator } from './fake-orchestrator.js';
15
+
16
+ const request = (containerId: string): OrchestratorCreateRequest => ({
17
+ containerId,
18
+ partyId: 'party-P',
19
+ bootstrapNodes: ['/ip4/127.0.0.1/tcp/4001/p2p/12D3KooWA9hbnKrRnPRSPTRkzXqTHzGE8YpJ3JHZmQ5tGwLRTMmp'],
20
+ profile: 'storage',
21
+ });
22
+
23
+ describe('FakeOrchestrator handle lifecycle', () => {
24
+ it('drops the prior handle when a re-spawn succeeds (mirrors dropStaleHandle)', async () => {
25
+ const orch = new FakeOrchestrator();
26
+ const first = await orch.createContainer(request('grn_1'));
27
+ const second = await orch.createContainer(request('grn_1'));
28
+
29
+ await expect(orch.stopContainer(first.dockerId)).rejects.toThrow(
30
+ `Container not found: ${first.dockerId}`,
31
+ );
32
+ // The rejected call left no trace: `stopped` records handles acted on, not
33
+ // calls attempted.
34
+ expect(orch.stopped).toEqual([]);
35
+ // …and the container now resolves only to the new spawn.
36
+ expect(orch.resolveDockerId('grn_1')).toBe(second.dockerId);
37
+
38
+ await orch.stopContainer(second.dockerId);
39
+ expect(orch.stopped).toEqual([second.dockerId]);
40
+ });
41
+
42
+ it('drops only the re-spawned container, leaving another container untouched', async () => {
43
+ const orch = new FakeOrchestrator();
44
+ const other = await orch.createContainer(request('grn_2'));
45
+ await orch.createContainer(request('grn_1'));
46
+ await orch.createContainer(request('grn_1'));
47
+
48
+ // The real drop filters on containerId; a fake that cleared the whole map
49
+ // would still pass every same-container case above.
50
+ await expect(orch.stopContainer(other.dockerId)).resolves.toBeUndefined();
51
+ expect(orch.resolveDockerId('grn_2')).toBe(other.dockerId);
52
+ });
53
+
54
+ it('keeps the prior handle live across the whole pre-drop await window', async () => {
55
+ const orch = new FakeOrchestrator();
56
+ const first = await orch.createContainer(request('grn_1'));
57
+
58
+ // The invariant the donation race tests rest on: a concurrent stop started
59
+ // from `onCreate` still finds the old handle. Deferring it onto a microtask
60
+ // puts it strictly after `onCreate` returns and strictly before the
61
+ // `createDelayMs` timer, so this one case pins the drop behind BOTH — with
62
+ // no dependence on wall-clock timing. The outcome is captured rather than
63
+ // rethrown so a regression fails this assertion instead of surfacing as an
64
+ // unhandled rejection.
65
+ orch.createDelayMs = 1;
66
+ let outcome: Promise<string> | undefined;
67
+ orch.onCreate = () => {
68
+ outcome ??= Promise.resolve()
69
+ .then(() => orch.stopContainer(first.dockerId))
70
+ .then(() => 'stopped', (err: Error) => `rejected: ${err.message}`);
71
+ };
72
+
73
+ const second = await orch.createContainer(request('grn_1'));
74
+
75
+ expect(await outcome).toBe('stopped');
76
+ expect(orch.stopped).toEqual([first.dockerId]);
77
+ expect(orch.resolveDockerId('grn_1')).toBe(second.dockerId);
78
+ });
79
+
80
+ it('leaves the prior handle in place when the re-spawn fails (mirrors restoreDroppedHandles)', async () => {
81
+ const orch = new FakeOrchestrator();
82
+ const first = await orch.createContainer(request('grn_1'));
83
+
84
+ orch.failCreate = true;
85
+ await expect(orch.createContainer(request('grn_1'))).rejects.toThrow('spawn boom');
86
+
87
+ // Host state is exactly as the failed attempt found it — which is what lets
88
+ // `DonationSupervisor.giveUp` still stop the child it knows about.
89
+ await expect(orch.stopContainer(first.dockerId)).resolves.toBeUndefined();
90
+ expect(orch.stopped).toEqual([first.dockerId]);
91
+ expect(orch.resolveDockerId('grn_1')).toBe(first.dockerId);
92
+ });
93
+
94
+ it('rejects a never-issued dockerId (mirrors requireHandle)', async () => {
95
+ const orch = new FakeOrchestrator();
96
+
97
+ await expect(orch.removeContainer('dock_nope')).rejects.toThrow(
98
+ 'Container not found: dock_nope',
99
+ );
100
+ expect(orch.removed).toEqual([]);
101
+ });
102
+
103
+ it('rejects a second call once a handle has been removed (mirrors removeContainer deleting it)', async () => {
104
+ const orch = new FakeOrchestrator();
105
+ const { dockerId } = await orch.createContainer(request('grn_1'));
106
+
107
+ await orch.removeContainer(dockerId);
108
+ expect(orch.removed).toEqual([dockerId]);
109
+
110
+ await expect(orch.stopContainer(dockerId)).rejects.toThrow(
111
+ `Container not found: ${dockerId}`,
112
+ );
113
+ expect(orch.stopped).toEqual([]);
114
+ });
115
+
116
+ it('fires onStop for a rejected stop, so a test can still observe the attempt', async () => {
117
+ const orch = new FakeOrchestrator();
118
+ const attempted: string[] = [];
119
+ orch.onStop = (id) => { attempted.push(id); };
120
+
121
+ await expect(orch.stopContainer('dock_nope')).rejects.toThrow('Container not found');
122
+ expect(attempted).toEqual(['dock_nope']);
123
+ expect(orch.stopped).toEqual([]);
124
+ });
125
+
126
+ it('refuses to reclaim the workdir of a container that still resolves (mirrors the live-handle guard)', async () => {
127
+ const orch = new FakeOrchestrator();
128
+ await orch.createContainer(request('grn_1'));
129
+
130
+ // A live handle owns that directory; only `removeContainer` — which stops
131
+ // the child first — may delete it.
132
+ expect(orch.reclaimWorkdir('grn_1')).toBe(false);
133
+ expect(orch.reclaimedWorkdirs).toEqual([]);
134
+ });
135
+
136
+ it('reclaims the workdir of a container no handle owns', async () => {
137
+ const orch = new FakeOrchestrator();
138
+
139
+ // Never spawned — the stuck-`provisioning` record whose host died before a
140
+ // handle ever existed.
141
+ expect(orch.reclaimWorkdir('grn_orphan')).toBe(true);
142
+ expect(orch.reclaimedWorkdirs).toEqual(['grn_orphan']);
143
+
144
+ // …and once the container's own handle is removed, its id becomes
145
+ // reclaimable too.
146
+ const { dockerId } = await orch.createContainer(request('grn_1'));
147
+ expect(orch.reclaimWorkdir('grn_1')).toBe(false);
148
+ await orch.removeContainer(dockerId);
149
+ expect(orch.reclaimWorkdir('grn_1')).toBe(true);
150
+ expect(orch.reclaimedWorkdirs).toEqual(['grn_orphan', 'grn_1']);
151
+ });
152
+
153
+ it('fires onSpawned after the drop, with the new handle live and the old one gone', async () => {
154
+ const orch = new FakeOrchestrator();
155
+ const first = await orch.createContainer(request('grn_1'));
156
+
157
+ let observed: { spawned: string; resolves: string | undefined } | undefined;
158
+ orch.onSpawned = (dockerId) => {
159
+ observed = { spawned: dockerId, resolves: orch.resolveDockerId('grn_1') };
160
+ };
161
+ const second = await orch.createContainer(request('grn_1'));
162
+
163
+ // The post-drop world: the container already resolves to the new handle, so
164
+ // work driven from here sees what `abandonRespawn`'s caller would see.
165
+ expect(observed).toEqual({ spawned: second.dockerId, resolves: second.dockerId });
166
+ expect(second.dockerId).not.toBe(first.dockerId);
167
+ });
168
+ });
@@ -568,7 +568,12 @@ export class HostProcessOrchestrator implements Orchestrator {
568
568
  // pinnedOwnerKeys, so a managed child advertises only the port assigned to it here
569
569
  // — `CADRE_ANNOUNCE_ADDRS`/`CADRE_APPEND_ANNOUNCE_ADDRS` cannot reach it. Fine while
570
570
  // children are reached at that port or through a relay; if a host is ever fronted by
571
- // a proxy or DNS name, plumb an announce var through from host config.
571
+ // a proxy or DNS name, plumb an announce var through from host config. The port is
572
+ // the CHILD'S CONTROL NODE's alone: each strand node the child runs binds the same
573
+ // entry with an OS-assigned port instead, since one port cannot be held twice
574
+ // (`cadre-core/src/strand-network-config.ts`). A NAT forward of this port therefore
575
+ // reaches the control node only, and strand nodes are reached through observed
576
+ // addresses or a relay.
572
577
  CADRE_SEED_TOKEN: seedToken,
573
578
  // Pin each child's node-local state (trusted-owner anchor, retained
574
579
  // cold-start dial targets) to its OWN workdir. This is the same value the
@@ -0,0 +1,134 @@
1
+ /**
2
+ * The host's `bootstrapNodes` rule — the requester addresses a donated node is
3
+ * started with — exercised directly.
4
+ *
5
+ * This is one half of a **manual tripwire**: cadre-provider carries a
6
+ * byte-identical copy of this rule
7
+ * (`packages/cadre-provider/src/server/bootstrap-node-validation.ts`) and the table
8
+ * below is the same table
9
+ * `packages/cadre-provider/src/server/__tests__/bootstrap-node-validation.test.ts`
10
+ * pins that copy to. Neither suite can observe the other package — nothing here
11
+ * imports cadre-provider's server module — so this does not detect a change made
12
+ * over there; what it does is fail if *this* copy is changed, which is how an
13
+ * editor is landed on the comment pointing at the other one.
14
+ *
15
+ * The route contract (`POST /grants` → 400, nothing provisioned) lives in
16
+ * `grants-route.test.ts`, next to the rest of that route's HTTP behaviour.
17
+ */
18
+
19
+ import { describe, it, expect } from 'vitest';
20
+
21
+ import { validateBootstrapNodes } from '../routes/bootstrap-node-validation.js';
22
+
23
+ /**
24
+ * A real, decodable peer id. Placeholder strings like `12D3KooReq` look right and
25
+ * are not: `peerIdFromString` throws `Incorrect length` on them, which is exactly
26
+ * the typo this rule exists to catch.
27
+ */
28
+ const PEER = '12D3KooWA9hbnKrRnPRSPTRkzXqTHzGE8YpJ3JHZmQ5tGwLRTMmp';
29
+ const GOOD = `/ip4/127.0.0.1/tcp/4001/p2p/${PEER}`;
30
+ /** A second, distinct dialable address, for "which entry was bad" assertions. */
31
+ const GOOD_2 = `/dns4/bootstrap.example/tcp/443/wss/p2p/${PEER}`;
32
+
33
+ describe('validateBootstrapNodes (the host copy of the address rule)', () => {
34
+ function errorOf(value: unknown): string {
35
+ const result = validateBootstrapNodes(value);
36
+ if (!('error' in result)) throw new Error(`expected a rejection, got ${JSON.stringify(result)}`);
37
+ return result.error;
38
+ }
39
+
40
+ it('accepts a dialable address and returns it trimmed', () => {
41
+ expect(validateBootstrapNodes([` ${GOOD}\n`])).toEqual({ nodes: [GOOD] });
42
+ });
43
+
44
+ it('accepts several dialable addresses across transports', () => {
45
+ expect(validateBootstrapNodes([GOOD, GOOD_2])).toEqual({ nodes: [GOOD, GOOD_2] });
46
+ });
47
+
48
+ it('accepts a relayed address whose relay and target peer ids both decode', () => {
49
+ const relayed = `/ip4/1.2.3.4/tcp/4001/p2p/${PEER}/p2p-circuit/p2p/${PEER}`;
50
+ expect(validateBootstrapNodes([relayed])).toEqual({ nodes: [relayed] });
51
+ });
52
+
53
+ it('treats an absent field and an empty list alike: the field is required', () => {
54
+ expect(errorOf(undefined)).toBe('bootstrapNodes is required');
55
+ expect(errorOf([])).toBe('bootstrapNodes is required');
56
+ });
57
+
58
+ it('rejects a non-array, and an array with a non-string element', () => {
59
+ expect(errorOf(GOOD)).toBe('bootstrapNodes must be an array of strings');
60
+ expect(errorOf(null)).toBe('bootstrapNodes must be an array of strings');
61
+ expect(errorOf([42])).toBe('bootstrapNodes must be an array of strings');
62
+ expect(errorOf([GOOD, { addr: GOOD }])).toBe('bootstrapNodes must be an array of strings');
63
+ });
64
+
65
+ it('rejects an empty or whitespace-only entry with the blank-value message', () => {
66
+ for (const blank of ['', ' ', '\t\n']) {
67
+ expect(errorOf([blank])).toMatch(/must not be empty or whitespace-only/);
68
+ }
69
+ });
70
+
71
+ // Case 1: `@libp2p/bootstrap` maps `multiaddr()` over the list before filtering,
72
+ // so this one throws during libp2p construction and the child never starts.
73
+ it('rejects a string that is not a multiaddr, naming it', () => {
74
+ for (const bad of ['not-an-address', '42', 'bootstrap.example:4001']) {
75
+ const message = errorOf([bad]);
76
+ expect(message).toMatch(/must be multiaddrs/);
77
+ expect(message).toContain(bad);
78
+ }
79
+ });
80
+
81
+ // Case 2: the quiet one — parses, then gets filtered out inside the child and
82
+ // the node comes up healthy-looking with zero bootstrap peers.
83
+ it('rejects a valid multiaddr with no /p2p/ component, naming it', () => {
84
+ const message = errorOf(['/ip4/127.0.0.1/tcp/4001']);
85
+ expect(message).toMatch(/must include a \/p2p\/<peerId> component/);
86
+ expect(message).toContain('/ip4/127.0.0.1/tcp/4001');
87
+ });
88
+
89
+ // Case 3: `multiaddr()` does not validate the /p2p/ value; `peerIdFromString`
90
+ // does, and throws inside the child's libp2p construction.
91
+ it('rejects a /p2p/ component whose peer id does not decode, naming the entry and the id', () => {
92
+ const bad = '/ip4/127.0.0.1/tcp/4001/p2p/12D3KooReq';
93
+ const message = errorOf([bad]);
94
+ expect(message).toMatch(/must carry a decodable peer id/);
95
+ expect(message).toContain(bad);
96
+ expect(message).toContain('12D3KooReq');
97
+ });
98
+
99
+ it('rejects a relayed address whose relay peer id does not decode', () => {
100
+ expect(errorOf([`/ip4/1.2.3.4/tcp/4001/p2p/12D3KooReq/p2p-circuit/p2p/${PEER}`]))
101
+ .toMatch(/must carry a decodable peer id/);
102
+ });
103
+
104
+ // Case 4: parses, names a decodable peer, and survives `@libp2p/bootstrap`'s
105
+ // filter — but names no place, so libp2p finds no transport and the dial fails
106
+ // with no valid addresses. Same visible outcome as case 2.
107
+ it('rejects an address that names only peer ids, with no location to dial', () => {
108
+ for (const bad of [`/p2p/${PEER}`, `/p2p/${PEER}/p2p-circuit/p2p/${PEER}`]) {
109
+ const message = errorOf([bad]);
110
+ expect(message).toMatch(/must name where to reach the peer/);
111
+ expect(message).toContain(bad);
112
+ }
113
+ });
114
+
115
+ // A partial address is deliberately still accepted: which transports the child
116
+ // can dial is the embedder's choice, so only the total absence of a location is
117
+ // a boundary error.
118
+ it('accepts an address with a location but no transport, leaving that to the child', () => {
119
+ const partial = `/ip4/1.2.3.4/p2p/${PEER}`;
120
+ expect(validateBootstrapNodes([partial])).toEqual({ nodes: [partial] });
121
+ });
122
+
123
+ it('names the offending entry when only one address in a batch is bad', () => {
124
+ const message = errorOf([GOOD, '/ip4/10.0.0.9/tcp/4001', GOOD_2]);
125
+ expect(message).toContain('/ip4/10.0.0.9/tcp/4001');
126
+ });
127
+
128
+ // A requester must not be able to turn one junk string into a megabyte of log line.
129
+ it('caps the echoed value for an over-long rejected address', () => {
130
+ const message = errorOf([`/ip4/1.2.3.4/tcp/${'9'.repeat(5000)}`]);
131
+ expect(message).toContain('chars)');
132
+ expect(message.length).toBeLessThan(400);
133
+ });
134
+ });