2026-01-26 19:24:13 -05:00
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
|
import { resolveTelegramAutoSelectFamilyDecision } from "./network-config.js";
|
|
|
|
|
|
|
|
|
|
describe("resolveTelegramAutoSelectFamilyDecision", () => {
|
|
|
|
|
it("prefers env enable over env disable", () => {
|
|
|
|
|
const decision = resolveTelegramAutoSelectFamilyDecision({
|
|
|
|
|
env: {
|
2026-01-30 03:15:10 +01:00
|
|
|
OPENCLAW_TELEGRAM_ENABLE_AUTO_SELECT_FAMILY: "1",
|
|
|
|
|
OPENCLAW_TELEGRAM_DISABLE_AUTO_SELECT_FAMILY: "1",
|
2026-01-26 19:24:13 -05:00
|
|
|
},
|
|
|
|
|
nodeMajor: 22,
|
|
|
|
|
});
|
|
|
|
|
expect(decision).toEqual({
|
|
|
|
|
value: true,
|
2026-01-30 03:15:10 +01:00
|
|
|
source: "env:OPENCLAW_TELEGRAM_ENABLE_AUTO_SELECT_FAMILY",
|
2026-01-26 19:24:13 -05:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("uses env disable when set", () => {
|
|
|
|
|
const decision = resolveTelegramAutoSelectFamilyDecision({
|
2026-01-30 03:15:10 +01:00
|
|
|
env: { OPENCLAW_TELEGRAM_DISABLE_AUTO_SELECT_FAMILY: "1" },
|
2026-01-26 19:24:13 -05:00
|
|
|
nodeMajor: 22,
|
|
|
|
|
});
|
|
|
|
|
expect(decision).toEqual({
|
|
|
|
|
value: false,
|
2026-01-30 03:15:10 +01:00
|
|
|
source: "env:OPENCLAW_TELEGRAM_DISABLE_AUTO_SELECT_FAMILY",
|
2026-01-26 19:24:13 -05:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-17 10:09:39 -05:00
|
|
|
it("prefers env enable over config", () => {
|
|
|
|
|
const decision = resolveTelegramAutoSelectFamilyDecision({
|
|
|
|
|
env: { OPENCLAW_TELEGRAM_ENABLE_AUTO_SELECT_FAMILY: "1" },
|
|
|
|
|
network: { autoSelectFamily: false },
|
|
|
|
|
nodeMajor: 22,
|
|
|
|
|
});
|
|
|
|
|
expect(decision).toEqual({
|
|
|
|
|
value: true,
|
|
|
|
|
source: "env:OPENCLAW_TELEGRAM_ENABLE_AUTO_SELECT_FAMILY",
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("prefers env disable over config", () => {
|
|
|
|
|
const decision = resolveTelegramAutoSelectFamilyDecision({
|
|
|
|
|
env: { OPENCLAW_TELEGRAM_DISABLE_AUTO_SELECT_FAMILY: "1" },
|
|
|
|
|
network: { autoSelectFamily: true },
|
|
|
|
|
nodeMajor: 22,
|
|
|
|
|
});
|
|
|
|
|
expect(decision).toEqual({
|
|
|
|
|
value: false,
|
|
|
|
|
source: "env:OPENCLAW_TELEGRAM_DISABLE_AUTO_SELECT_FAMILY",
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-26 19:24:13 -05:00
|
|
|
it("uses config override when provided", () => {
|
|
|
|
|
const decision = resolveTelegramAutoSelectFamilyDecision({
|
2026-02-14 16:20:19 +00:00
|
|
|
env: {},
|
2026-01-26 19:24:13 -05:00
|
|
|
network: { autoSelectFamily: true },
|
|
|
|
|
nodeMajor: 22,
|
|
|
|
|
});
|
|
|
|
|
expect(decision).toEqual({ value: true, source: "config" });
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-16 14:19:03 -03:00
|
|
|
it("defaults to enable on Node 22", () => {
|
2026-02-14 16:20:19 +00:00
|
|
|
const decision = resolveTelegramAutoSelectFamilyDecision({ env: {}, nodeMajor: 22 });
|
2026-02-16 14:19:03 -03:00
|
|
|
expect(decision).toEqual({ value: true, source: "default-node22" });
|
2026-01-26 19:24:13 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("returns null when no decision applies", () => {
|
2026-02-14 16:20:19 +00:00
|
|
|
const decision = resolveTelegramAutoSelectFamilyDecision({ env: {}, nodeMajor: 20 });
|
2026-01-26 19:24:13 -05:00
|
|
|
expect(decision).toEqual({ value: null });
|
|
|
|
|
});
|
|
|
|
|
});
|