@serfab/cadre-host 0.10.0 → 0.12.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 (158) hide show
  1. package/README.md +406 -296
  2. package/dist/bin/host.d.ts +11 -7
  3. package/dist/bin/host.js +40 -12
  4. package/dist/bin/host.js.map +1 -1
  5. package/dist/installer/config.d.ts +4 -4
  6. package/dist/installer/config.js +5 -39
  7. package/dist/installer/config.js.map +1 -1
  8. package/dist/installer/identity.d.ts +8 -1
  9. package/dist/installer/identity.js +8 -1
  10. package/dist/installer/identity.js.map +1 -1
  11. package/dist/orchestrator/host-process-orchestrator.d.ts +2 -2
  12. package/dist/orchestrator/host-process-orchestrator.js +9 -4
  13. package/dist/orchestrator/host-process-orchestrator.js.map +1 -1
  14. package/dist/server/settings-store.d.ts +1 -1
  15. package/dist/server/settings-store.js +5 -1
  16. package/dist/server/settings-store.js.map +1 -1
  17. package/dist/server/static.js +38 -38
  18. package/dist/ui/assets/index-C-iks41M.js.map +1 -1
  19. package/dist/ui/index.html +12 -12
  20. package/package.json +4 -4
  21. package/service/cadre-host.service.tmpl +16 -16
  22. package/service/com.serfab.cadre-host.plist.tmpl +35 -35
  23. package/service/install-service.ps1 +98 -98
  24. package/service/uninstall-service.ps1 +19 -19
  25. package/src/__tests__/build-targets.test.ts +26 -26
  26. package/src/__tests__/cli-invite.smoke.test.ts +192 -192
  27. package/src/__tests__/cli-nat.smoke.test.ts +212 -212
  28. package/src/__tests__/cli.smoke.test.ts +51 -46
  29. package/src/__tests__/global-setup.ts +56 -51
  30. package/src/__tests__/host-owner.smoke.test.ts +123 -123
  31. package/src/__tests__/orchestrator-env-scrub.test.ts +140 -140
  32. package/src/__tests__/orchestrator-node-identity.test.ts +5 -5
  33. package/src/__tests__/orchestrator-owner.test.ts +198 -198
  34. package/src/__tests__/orchestrator-pin-keys.test.ts +153 -153
  35. package/src/__tests__/orchestrator-push.test.ts +145 -145
  36. package/src/__tests__/orchestrator.test.ts +951 -951
  37. package/src/auth/__tests__/duration.test.ts +28 -28
  38. package/src/auth/__tests__/self-label.test.ts +85 -85
  39. package/src/auth/__tests__/trust-circle-store.test.ts +115 -115
  40. package/src/auth/__tests__/trust-circle.test.ts +445 -445
  41. package/src/auth/duration.ts +33 -33
  42. package/src/auth/index.ts +21 -21
  43. package/src/auth/self-label.ts +74 -74
  44. package/src/auth/trust-circle-store.ts +155 -155
  45. package/src/auth/types.ts +99 -99
  46. package/src/bin/__tests__/cli-reference.test.ts +167 -0
  47. package/src/bin/host.ts +1326 -1299
  48. package/src/donation/__tests__/donation-service.test.ts +1068 -1068
  49. package/src/donation/__tests__/donation-supervisor.test.ts +510 -510
  50. package/src/donation/__tests__/fake-orchestrator.test.ts +168 -168
  51. package/src/donation/__tests__/fake-orchestrator.ts +225 -225
  52. package/src/donation/__tests__/grant-service.test.ts +213 -213
  53. package/src/donation/__tests__/grant-store.test.ts +113 -113
  54. package/src/donation/donation-service.ts +962 -962
  55. package/src/donation/donation-store.ts +171 -171
  56. package/src/donation/donation-supervisor.ts +388 -388
  57. package/src/donation/grant-service.ts +200 -200
  58. package/src/donation/grant-store.ts +152 -152
  59. package/src/donation/index.ts +64 -64
  60. package/src/donation/types.ts +243 -243
  61. package/src/installer/__tests__/config.test.ts +134 -112
  62. package/src/installer/__tests__/identity.test.ts +34 -34
  63. package/src/installer/__tests__/paths.test.ts +47 -47
  64. package/src/installer/__tests__/service-host.test.ts +62 -62
  65. package/src/installer/__tests__/wizard.test.ts +64 -64
  66. package/src/installer/config.ts +5 -43
  67. package/src/installer/identity.ts +56 -49
  68. package/src/installer/paths.ts +109 -109
  69. package/src/installer/platform.ts +27 -27
  70. package/src/installer/service-host/index.ts +21 -21
  71. package/src/installer/service-host/template.ts +21 -21
  72. package/src/installer/wizard.ts +103 -103
  73. package/src/nat/__tests__/address-resolver.test.ts +82 -82
  74. package/src/nat/__tests__/ddns-duckdns.test.ts +83 -83
  75. package/src/nat/__tests__/ddns-updater.test.ts +253 -253
  76. package/src/nat/__tests__/external-ip.test.ts +124 -124
  77. package/src/nat/__tests__/nat-service.test.ts +18 -0
  78. package/src/nat/__tests__/nat-store.test.ts +93 -93
  79. package/src/nat/__tests__/port-mapper.test.ts +191 -191
  80. package/src/nat/__tests__/reachability.test.ts +24 -24
  81. package/src/nat/__tests__/secrets.test.ts +178 -178
  82. package/src/nat/address-resolver.ts +51 -51
  83. package/src/nat/ddns/duckdns.ts +76 -76
  84. package/src/nat/ddns/index.ts +55 -55
  85. package/src/nat/ddns/updater.ts +243 -243
  86. package/src/nat/external-ip.ts +154 -154
  87. package/src/nat/index.ts +71 -71
  88. package/src/nat/nat-service.ts +501 -501
  89. package/src/nat/nat-store.ts +154 -154
  90. package/src/nat/port-mapper.ts +329 -329
  91. package/src/nat/reachability.ts +34 -34
  92. package/src/nat/secrets/file-store.ts +130 -130
  93. package/src/nat/secrets/index.ts +112 -112
  94. package/src/nat/secrets/keytar-store.ts +67 -67
  95. package/src/nat/types.ts +159 -159
  96. package/src/orchestrator/__tests__/node-identity.test.ts +62 -62
  97. package/src/orchestrator/host-process-orchestrator.ts +9 -4
  98. package/src/orchestrator/index.ts +10 -10
  99. package/src/orchestrator/log-rotator.ts +53 -53
  100. package/src/orchestrator/node-identity.ts +40 -40
  101. package/src/orchestrator/pid-liveness.ts +24 -24
  102. package/src/orchestrator/port-allocator.ts +91 -91
  103. package/src/orchestrator/state-store.ts +90 -90
  104. package/src/orchestrator/types.ts +141 -141
  105. package/src/owner/__tests__/owner-node-client.test.ts +194 -194
  106. package/src/owner/index.ts +12 -12
  107. package/src/owner/owner-node-client.ts +259 -259
  108. package/src/push/__tests__/push.test.ts +90 -90
  109. package/src/push/index.ts +146 -146
  110. package/src/server/__tests__/bus.test.ts +38 -38
  111. package/src/server/__tests__/error-handler.test.ts +118 -118
  112. package/src/server/__tests__/grants-admin-route.test.ts +73 -73
  113. package/src/server/__tests__/grants-route.test.ts +263 -263
  114. package/src/server/__tests__/nodes-route.test.ts +259 -259
  115. package/src/server/__tests__/origin-guard.test.ts +72 -72
  116. package/src/server/__tests__/publishers.test.ts +216 -216
  117. package/src/server/__tests__/server.smoke.test.ts +253 -253
  118. package/src/server/__tests__/settings-route.test.ts +195 -194
  119. package/src/server/__tests__/sse-route.test.ts +119 -119
  120. package/src/server/__tests__/static.test.ts +145 -145
  121. package/src/server/__tests__/status-route.test.ts +134 -134
  122. package/src/server/__tests__/strands-route.test.ts +233 -233
  123. package/src/server/error-handler.ts +178 -178
  124. package/src/server/events/bus.ts +42 -42
  125. package/src/server/events/sse-route.ts +81 -81
  126. package/src/server/events/types.ts +23 -23
  127. package/src/server/index.ts +267 -267
  128. package/src/server/origin-guard.ts +84 -84
  129. package/src/server/routes/grants-admin.ts +41 -41
  130. package/src/server/routes/grants.ts +210 -210
  131. package/src/server/routes/nat.ts +63 -63
  132. package/src/server/routes/nodes.ts +170 -170
  133. package/src/server/routes/settings.ts +123 -123
  134. package/src/server/routes/status.ts +118 -118
  135. package/src/server/routes/strands.ts +54 -54
  136. package/src/server/routes/trust-circle.ts +49 -49
  137. package/src/server/routes/update.ts +43 -43
  138. package/src/server/server.ts +122 -122
  139. package/src/server/settings-store.ts +5 -1
  140. package/src/server/static.ts +207 -207
  141. package/src/strands/__tests__/strand-service.test.ts +165 -165
  142. package/src/strands/index.ts +14 -14
  143. package/src/strands/strand-service.ts +135 -135
  144. package/src/strands/types.ts +102 -102
  145. package/src/update/__tests__/apply.test.ts +158 -158
  146. package/src/update/__tests__/manifest.test.ts +128 -128
  147. package/src/update/__tests__/release-key.test.ts +42 -42
  148. package/src/update/__tests__/sign.test.ts +78 -78
  149. package/src/update/__tests__/store.test.ts +81 -81
  150. package/src/update/__tests__/update-service.integration.test.ts +256 -256
  151. package/src/update/__tests__/version.test.ts +31 -31
  152. package/src/update/apply.ts +190 -190
  153. package/src/update/index.ts +341 -341
  154. package/src/update/release-key.ts +71 -71
  155. package/src/update/sign.ts +74 -74
  156. package/src/update/store.ts +101 -101
  157. package/src/update/types.ts +109 -109
  158. package/src/update/version.ts +80 -80
@@ -1,191 +1,191 @@
1
- import { describe, expect, it } from 'vitest';
2
-
3
- import { NatError } from '../types.js';
4
- import {
5
- PortMapperService,
6
- type PortMapper,
7
- type PortMappingResult,
8
- } from '../port-mapper.js';
9
-
10
- interface FakeOpts {
11
- mapShouldThrow?: Error;
12
- verifyResult?: boolean;
13
- verifyShouldThrow?: Error;
14
- externalIp?: string | null;
15
- }
16
-
17
- function makeFakeMapper(initial: FakeOpts = {}): PortMapper & {
18
- calls: { map: number; verify: number; unmap: number; stop: number };
19
- options: FakeOpts;
20
- } {
21
- const opts = { ...initial };
22
- const calls = { map: 0, verify: 0, unmap: 0, stop: 0 };
23
- return {
24
- options: opts,
25
- calls,
26
- async map(o): Promise<PortMappingResult> {
27
- calls.map++;
28
- if (opts.mapShouldThrow) throw opts.mapShouldThrow;
29
- return {
30
- mode: 'auto-upnp',
31
- externalIp: opts.externalIp ?? '203.0.113.1',
32
- externalPort: o.externalPort,
33
- internalPort: o.internalPort,
34
- protocol: o.protocol ?? 'tcp',
35
- leaseExpiresAt: new Date(Date.now() + (o.ttlMs ?? 60_000)),
36
- };
37
- },
38
- async verify() {
39
- calls.verify++;
40
- if (opts.verifyShouldThrow) throw opts.verifyShouldThrow;
41
- return opts.verifyResult ?? true;
42
- },
43
- async externalIp() {
44
- return opts.externalIp ?? '203.0.113.1';
45
- },
46
- async unmap() {
47
- calls.unmap++;
48
- },
49
- async stop() {
50
- calls.stop++;
51
- },
52
- };
53
- }
54
-
55
- function fakeTimers(): {
56
- setTimer: (fn: () => void, ms: number) => NodeJS.Timeout;
57
- clearTimer: (h: NodeJS.Timeout) => void;
58
- fire(): void;
59
- pending: number;
60
- } {
61
- let callback: (() => void) | null = null;
62
- return {
63
- setTimer: (fn) => {
64
- callback = fn;
65
- return {} as NodeJS.Timeout;
66
- },
67
- clearTimer: () => {
68
- callback = null;
69
- },
70
- fire: () => {
71
- const cb = callback;
72
- callback = null;
73
- cb?.();
74
- },
75
- get pending() { return callback ? 1 : 0; },
76
- };
77
- }
78
-
79
- describe('PortMapperService', () => {
80
- it('installs the mapping on start and records mode + externalIp', async () => {
81
- const mapper = makeFakeMapper({ externalIp: '203.0.113.42' });
82
- const timers = fakeTimers();
83
- const svc = new PortMapperService({
84
- mapper,
85
- externalPort: 4001,
86
- internalPort: 4001,
87
- setTimer: timers.setTimer,
88
- clearTimer: timers.clearTimer,
89
- });
90
-
91
- await svc.start();
92
- const state = svc.getState();
93
- expect(state.mode).toBe('auto-upnp');
94
- expect(state.routerExternalIp).toBe('203.0.113.42');
95
- expect(state.externalPort).toBe(4001);
96
- expect(state.lastError).toBeNull();
97
- expect(mapper.calls.map).toBe(1);
98
- });
99
-
100
- it('flips to mode=failed when the mapper throws', async () => {
101
- const mapper = makeFakeMapper({ mapShouldThrow: new NatError('mapping_failed', 'router said no') });
102
- const timers = fakeTimers();
103
- const svc = new PortMapperService({
104
- mapper,
105
- externalPort: 4001,
106
- internalPort: 4001,
107
- setTimer: timers.setTimer,
108
- clearTimer: timers.clearTimer,
109
- });
110
-
111
- await svc.start();
112
- expect(svc.getState().mode).toBe('failed');
113
- expect(svc.getState().lastError).toContain('router said no');
114
- });
115
-
116
- it('unmaps and stops the mapper on stop()', async () => {
117
- const mapper = makeFakeMapper();
118
- const timers = fakeTimers();
119
- const svc = new PortMapperService({
120
- mapper,
121
- externalPort: 4001,
122
- internalPort: 4001,
123
- setTimer: timers.setTimer,
124
- clearTimer: timers.clearTimer,
125
- });
126
- await svc.start();
127
- await svc.stop();
128
- expect(mapper.calls.unmap).toBeGreaterThanOrEqual(1);
129
- expect(mapper.calls.stop).toBeGreaterThanOrEqual(1);
130
- expect(svc.getState().mode).toBe('disabled');
131
- });
132
-
133
- it('stop() is idempotent', async () => {
134
- const mapper = makeFakeMapper();
135
- const timers = fakeTimers();
136
- const svc = new PortMapperService({
137
- mapper, externalPort: 4001, internalPort: 4001,
138
- setTimer: timers.setTimer, clearTimer: timers.clearTimer,
139
- });
140
- await svc.start();
141
- await svc.stop();
142
- await svc.stop();
143
- expect(mapper.calls.unmap).toBe(1);
144
- });
145
-
146
- it('refresh() re-maps when verify fails', async () => {
147
- const mapper = makeFakeMapper({ verifyResult: false });
148
- const timers = fakeTimers();
149
- const svc = new PortMapperService({
150
- mapper, externalPort: 4001, internalPort: 4001,
151
- setTimer: timers.setTimer, clearTimer: timers.clearTimer,
152
- });
153
- await svc.start();
154
- expect(mapper.calls.map).toBe(1);
155
-
156
- await svc.refresh();
157
- // verify=false → re-map
158
- expect(mapper.calls.map).toBe(2);
159
- });
160
-
161
- it('refresh() re-issues the mapping when verify succeeds (extends lease)', async () => {
162
- const mapper = makeFakeMapper({ verifyResult: true });
163
- const timers = fakeTimers();
164
- const svc = new PortMapperService({
165
- mapper, externalPort: 4001, internalPort: 4001,
166
- setTimer: timers.setTimer, clearTimer: timers.clearTimer,
167
- });
168
- await svc.start();
169
- expect(mapper.calls.map).toBe(1);
170
- await svc.refresh();
171
- expect(mapper.calls.map).toBe(2);
172
- expect(mapper.calls.verify).toBe(1);
173
- });
174
-
175
- it('schedules a refresh timer', async () => {
176
- const mapper = makeFakeMapper();
177
- const timers = fakeTimers();
178
- const svc = new PortMapperService({
179
- mapper, externalPort: 4001, internalPort: 4001,
180
- setTimer: timers.setTimer, clearTimer: timers.clearTimer,
181
- });
182
- await svc.start();
183
- expect(timers.pending).toBe(1);
184
-
185
- // Fire the timer — should re-arm after the inner refresh resolves.
186
- timers.fire();
187
- // Wait for the async refresh chain to complete.
188
- await new Promise((r) => setTimeout(r, 0));
189
- expect(timers.pending).toBe(1);
190
- });
191
- });
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { NatError } from '../types.js';
4
+ import {
5
+ PortMapperService,
6
+ type PortMapper,
7
+ type PortMappingResult,
8
+ } from '../port-mapper.js';
9
+
10
+ interface FakeOpts {
11
+ mapShouldThrow?: Error;
12
+ verifyResult?: boolean;
13
+ verifyShouldThrow?: Error;
14
+ externalIp?: string | null;
15
+ }
16
+
17
+ function makeFakeMapper(initial: FakeOpts = {}): PortMapper & {
18
+ calls: { map: number; verify: number; unmap: number; stop: number };
19
+ options: FakeOpts;
20
+ } {
21
+ const opts = { ...initial };
22
+ const calls = { map: 0, verify: 0, unmap: 0, stop: 0 };
23
+ return {
24
+ options: opts,
25
+ calls,
26
+ async map(o): Promise<PortMappingResult> {
27
+ calls.map++;
28
+ if (opts.mapShouldThrow) throw opts.mapShouldThrow;
29
+ return {
30
+ mode: 'auto-upnp',
31
+ externalIp: opts.externalIp ?? '203.0.113.1',
32
+ externalPort: o.externalPort,
33
+ internalPort: o.internalPort,
34
+ protocol: o.protocol ?? 'tcp',
35
+ leaseExpiresAt: new Date(Date.now() + (o.ttlMs ?? 60_000)),
36
+ };
37
+ },
38
+ async verify() {
39
+ calls.verify++;
40
+ if (opts.verifyShouldThrow) throw opts.verifyShouldThrow;
41
+ return opts.verifyResult ?? true;
42
+ },
43
+ async externalIp() {
44
+ return opts.externalIp ?? '203.0.113.1';
45
+ },
46
+ async unmap() {
47
+ calls.unmap++;
48
+ },
49
+ async stop() {
50
+ calls.stop++;
51
+ },
52
+ };
53
+ }
54
+
55
+ function fakeTimers(): {
56
+ setTimer: (fn: () => void, ms: number) => NodeJS.Timeout;
57
+ clearTimer: (h: NodeJS.Timeout) => void;
58
+ fire(): void;
59
+ pending: number;
60
+ } {
61
+ let callback: (() => void) | null = null;
62
+ return {
63
+ setTimer: (fn) => {
64
+ callback = fn;
65
+ return {} as NodeJS.Timeout;
66
+ },
67
+ clearTimer: () => {
68
+ callback = null;
69
+ },
70
+ fire: () => {
71
+ const cb = callback;
72
+ callback = null;
73
+ cb?.();
74
+ },
75
+ get pending() { return callback ? 1 : 0; },
76
+ };
77
+ }
78
+
79
+ describe('PortMapperService', () => {
80
+ it('installs the mapping on start and records mode + externalIp', async () => {
81
+ const mapper = makeFakeMapper({ externalIp: '203.0.113.42' });
82
+ const timers = fakeTimers();
83
+ const svc = new PortMapperService({
84
+ mapper,
85
+ externalPort: 4001,
86
+ internalPort: 4001,
87
+ setTimer: timers.setTimer,
88
+ clearTimer: timers.clearTimer,
89
+ });
90
+
91
+ await svc.start();
92
+ const state = svc.getState();
93
+ expect(state.mode).toBe('auto-upnp');
94
+ expect(state.routerExternalIp).toBe('203.0.113.42');
95
+ expect(state.externalPort).toBe(4001);
96
+ expect(state.lastError).toBeNull();
97
+ expect(mapper.calls.map).toBe(1);
98
+ });
99
+
100
+ it('flips to mode=failed when the mapper throws', async () => {
101
+ const mapper = makeFakeMapper({ mapShouldThrow: new NatError('mapping_failed', 'router said no') });
102
+ const timers = fakeTimers();
103
+ const svc = new PortMapperService({
104
+ mapper,
105
+ externalPort: 4001,
106
+ internalPort: 4001,
107
+ setTimer: timers.setTimer,
108
+ clearTimer: timers.clearTimer,
109
+ });
110
+
111
+ await svc.start();
112
+ expect(svc.getState().mode).toBe('failed');
113
+ expect(svc.getState().lastError).toContain('router said no');
114
+ });
115
+
116
+ it('unmaps and stops the mapper on stop()', async () => {
117
+ const mapper = makeFakeMapper();
118
+ const timers = fakeTimers();
119
+ const svc = new PortMapperService({
120
+ mapper,
121
+ externalPort: 4001,
122
+ internalPort: 4001,
123
+ setTimer: timers.setTimer,
124
+ clearTimer: timers.clearTimer,
125
+ });
126
+ await svc.start();
127
+ await svc.stop();
128
+ expect(mapper.calls.unmap).toBeGreaterThanOrEqual(1);
129
+ expect(mapper.calls.stop).toBeGreaterThanOrEqual(1);
130
+ expect(svc.getState().mode).toBe('disabled');
131
+ });
132
+
133
+ it('stop() is idempotent', async () => {
134
+ const mapper = makeFakeMapper();
135
+ const timers = fakeTimers();
136
+ const svc = new PortMapperService({
137
+ mapper, externalPort: 4001, internalPort: 4001,
138
+ setTimer: timers.setTimer, clearTimer: timers.clearTimer,
139
+ });
140
+ await svc.start();
141
+ await svc.stop();
142
+ await svc.stop();
143
+ expect(mapper.calls.unmap).toBe(1);
144
+ });
145
+
146
+ it('refresh() re-maps when verify fails', async () => {
147
+ const mapper = makeFakeMapper({ verifyResult: false });
148
+ const timers = fakeTimers();
149
+ const svc = new PortMapperService({
150
+ mapper, externalPort: 4001, internalPort: 4001,
151
+ setTimer: timers.setTimer, clearTimer: timers.clearTimer,
152
+ });
153
+ await svc.start();
154
+ expect(mapper.calls.map).toBe(1);
155
+
156
+ await svc.refresh();
157
+ // verify=false → re-map
158
+ expect(mapper.calls.map).toBe(2);
159
+ });
160
+
161
+ it('refresh() re-issues the mapping when verify succeeds (extends lease)', async () => {
162
+ const mapper = makeFakeMapper({ verifyResult: true });
163
+ const timers = fakeTimers();
164
+ const svc = new PortMapperService({
165
+ mapper, externalPort: 4001, internalPort: 4001,
166
+ setTimer: timers.setTimer, clearTimer: timers.clearTimer,
167
+ });
168
+ await svc.start();
169
+ expect(mapper.calls.map).toBe(1);
170
+ await svc.refresh();
171
+ expect(mapper.calls.map).toBe(2);
172
+ expect(mapper.calls.verify).toBe(1);
173
+ });
174
+
175
+ it('schedules a refresh timer', async () => {
176
+ const mapper = makeFakeMapper();
177
+ const timers = fakeTimers();
178
+ const svc = new PortMapperService({
179
+ mapper, externalPort: 4001, internalPort: 4001,
180
+ setTimer: timers.setTimer, clearTimer: timers.clearTimer,
181
+ });
182
+ await svc.start();
183
+ expect(timers.pending).toBe(1);
184
+
185
+ // Fire the timer — should re-arm after the inner refresh resolves.
186
+ timers.fire();
187
+ // Wait for the async refresh chain to complete.
188
+ await new Promise((r) => setTimeout(r, 0));
189
+ expect(timers.pending).toBe(1);
190
+ });
191
+ });
@@ -1,24 +1,24 @@
1
- import { describe, expect, it } from 'vitest';
2
-
3
- import { evaluateReachability } from '../reachability.js';
4
-
5
- describe('evaluateReachability', () => {
6
- it('returns cgnat when cgnatDetected is true (overrides portMode)', () => {
7
- expect(evaluateReachability({ portMode: 'auto-upnp', cgnatDetected: true })).toBe('cgnat');
8
- expect(evaluateReachability({ portMode: 'failed', cgnatDetected: true })).toBe('cgnat');
9
- });
10
-
11
- it('returns reachable for auto-upnp / auto-natpmp', () => {
12
- expect(evaluateReachability({ portMode: 'auto-upnp', cgnatDetected: false })).toBe('reachable');
13
- expect(evaluateReachability({ portMode: 'auto-natpmp', cgnatDetected: false })).toBe('reachable');
14
- });
15
-
16
- it('returns unreachable when port mapping failed', () => {
17
- expect(evaluateReachability({ portMode: 'failed', cgnatDetected: false })).toBe('unreachable');
18
- });
19
-
20
- it('returns unknown for manual / disabled', () => {
21
- expect(evaluateReachability({ portMode: 'manual', cgnatDetected: false })).toBe('unknown');
22
- expect(evaluateReachability({ portMode: 'disabled', cgnatDetected: false })).toBe('unknown');
23
- });
24
- });
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { evaluateReachability } from '../reachability.js';
4
+
5
+ describe('evaluateReachability', () => {
6
+ it('returns cgnat when cgnatDetected is true (overrides portMode)', () => {
7
+ expect(evaluateReachability({ portMode: 'auto-upnp', cgnatDetected: true })).toBe('cgnat');
8
+ expect(evaluateReachability({ portMode: 'failed', cgnatDetected: true })).toBe('cgnat');
9
+ });
10
+
11
+ it('returns reachable for auto-upnp / auto-natpmp', () => {
12
+ expect(evaluateReachability({ portMode: 'auto-upnp', cgnatDetected: false })).toBe('reachable');
13
+ expect(evaluateReachability({ portMode: 'auto-natpmp', cgnatDetected: false })).toBe('reachable');
14
+ });
15
+
16
+ it('returns unreachable when port mapping failed', () => {
17
+ expect(evaluateReachability({ portMode: 'failed', cgnatDetected: false })).toBe('unreachable');
18
+ });
19
+
20
+ it('returns unknown for manual / disabled', () => {
21
+ expect(evaluateReachability({ portMode: 'manual', cgnatDetected: false })).toBe('unknown');
22
+ expect(evaluateReachability({ portMode: 'disabled', cgnatDetected: false })).toBe('unknown');
23
+ });
24
+ });