@vellumai/credential-executor 0.11.6-dev.202608261602.96410d6 → 0.11.6-dev.202608261801.b683b42
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.
|
@@ -6,8 +6,10 @@ import {
|
|
|
6
6
|
normalizePublicBaseUrl,
|
|
7
7
|
parseRecordedAssistantId,
|
|
8
8
|
parseTunnelRecord,
|
|
9
|
+
selectRestartTunnelRecord,
|
|
9
10
|
trimmedNonEmptyString,
|
|
10
11
|
TUNNEL_PROVIDERS,
|
|
12
|
+
type TunnelRecord,
|
|
11
13
|
velayHostForPlatformHost,
|
|
12
14
|
} from "../ingress.js";
|
|
13
15
|
import {
|
|
@@ -221,6 +223,41 @@ describe("parseTunnelRecord", () => {
|
|
|
221
223
|
});
|
|
222
224
|
});
|
|
223
225
|
|
|
226
|
+
describe("selectRestartTunnelRecord", () => {
|
|
227
|
+
const PAIRING: TunnelRecord = {
|
|
228
|
+
provider: "tailscale",
|
|
229
|
+
publicBaseUrl: "https://assistant-1.example.ts.net",
|
|
230
|
+
};
|
|
231
|
+
const LAST: TunnelRecord = {
|
|
232
|
+
provider: "ngrok",
|
|
233
|
+
publicBaseUrl: "https://assistant-1.ngrok.app",
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
test("prefers the pairing tunnel over the last one that ran", () => {
|
|
237
|
+
// The pairing tunnel deliberately left the older public record beside it,
|
|
238
|
+
// so naming that one would point at an ingress nobody is using.
|
|
239
|
+
expect(
|
|
240
|
+
selectRestartTunnelRecord({ lastTunnel: LAST, pairingTunnel: PAIRING }),
|
|
241
|
+
).toEqual(PAIRING);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test("falls back to the last tunnel and to null", () => {
|
|
245
|
+
expect(selectRestartTunnelRecord({ lastTunnel: LAST })).toEqual(LAST);
|
|
246
|
+
for (const ingress of [undefined, null, {}, "nonsense", 42]) {
|
|
247
|
+
expect(selectRestartTunnelRecord(ingress)).toBeNull();
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test("skips a malformed pairing record for a usable last one", () => {
|
|
252
|
+
expect(
|
|
253
|
+
selectRestartTunnelRecord({
|
|
254
|
+
lastTunnel: LAST,
|
|
255
|
+
pairingTunnel: { provider: "wireguard", publicBaseUrl: "nope" },
|
|
256
|
+
}),
|
|
257
|
+
).toEqual(LAST);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
224
261
|
describe("trimmedNonEmptyString", () => {
|
|
225
262
|
test("trims and rejects blank or non-string values", () => {
|
|
226
263
|
expect(trimmedNonEmptyString(" assistant-1 ")).toBe("assistant-1");
|
|
@@ -147,6 +147,28 @@ export function parseTunnelRecord(value: unknown): TunnelRecord | null {
|
|
|
147
147
|
return { provider, publicBaseUrl: normalized };
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
+
/**
|
|
151
|
+
* The tunnel a reader should offer to restart, given an `ingress` section, or
|
|
152
|
+
* null when it records none.
|
|
153
|
+
*
|
|
154
|
+
* A pairing-only record wins: it is written by a tunnel that deliberately left
|
|
155
|
+
* `publicBaseUrl` (and the `lastTunnel` beside it) pointing at an older public
|
|
156
|
+
* provider, so naming that older one would send the user to rebuild an ingress
|
|
157
|
+
* they are not using instead of the tunnel actually in front of them.
|
|
158
|
+
*/
|
|
159
|
+
export function selectRestartTunnelRecord(
|
|
160
|
+
ingress: unknown,
|
|
161
|
+
): TunnelRecord | null {
|
|
162
|
+
if (typeof ingress !== "object" || ingress === null) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
const section = ingress as Record<string, unknown>;
|
|
166
|
+
return (
|
|
167
|
+
parseTunnelRecord(section[INGRESS_PAIRING_TUNNEL_KEY]) ??
|
|
168
|
+
parseTunnelRecord(section[INGRESS_LAST_TUNNEL_KEY])
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
|
|
150
172
|
/** Parse an `ingress.assistantId` value, or null when it is absent or blank. */
|
|
151
173
|
export function parseRecordedAssistantId(value: unknown): string | null {
|
|
152
174
|
return trimmedNonEmptyString(value) ?? null;
|