import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import type { OpenClawConfig } from "openclaw/plugin-sdk/config-runtime"; import { afterEach, describe, expect, it, vi } from "vitest"; import { withStateDirEnv } from "../../../src/test-helpers/state-dir-env.js"; import { resolveTelegramToken } from "./token.js"; import { readTelegramUpdateOffset, writeTelegramUpdateOffset } from "./update-offset-store.js";
it("does not fall through to channel-level token when non-default accountId is not in config", () => {
vi.stubEnv("TELEGRAM_BOT_TOKEN", "");
expectNoTokenForUnknownAccount(createUnknownAccountConfig());
});
it("does not fall back to TELEGRAM_BOT_TOKEN when an explicit env SecretRef is configured but unavailable", () => {
vi.stubEnv("TELEGRAM_BOT_TOKEN", "fallback-env-token");
vi.stubEnv("TELEGRAM_REF_TOKEN", ""); const cfg = {
channels: {
telegram: {
botToken: { source: "env", provider: "default", id: "TELEGRAM_REF_TOKEN" },
},
},
} as unknown as OpenClawConfig;
expect(() => resolveTelegramToken(cfg)).toThrow(
/not allowlisted in secrets\.providers\.telegram-env\.allowlist/i,
);
});
it("throws when an env SecretRef points at a provider configured with another source", () => { const cfg = {
secrets: {
providers: { "telegram-env": {
source: "file",
path: "/tmp/secrets.json",
},
},
},
channels: {
telegram: {
botToken: { source: "env", provider: "telegram-env", id: "TELEGRAM_BOT_TOKEN" },
},
},
} as unknown as OpenClawConfig;
expect(() => resolveTelegramToken(cfg)).toThrow(
/Secret provider "telegram-env" has source "file" but ref requests "env"/i,
);
});
it("throws when an env SecretRef provider is not configured and not the default env alias", () => { const cfg = {
channels: {
telegram: {
botToken: { source: "env", provider: "ops-env", id: "TELEGRAM_BOT_TOKEN" },
},
},
} as unknown as OpenClawConfig;
expect(() => resolveTelegramToken(cfg)).toThrow(
/Secret provider "ops-env" is not configured \(ref: env:ops-env:TELEGRAM_BOT_TOKEN\)/i,
);
});
it("accepts env SecretRefs that use the configured default env provider alias", () => {
vi.stubEnv("TELEGRAM_RUNTIME_TOKEN", "secretref-env-token"); const cfg = {
secrets: {
defaults: {
env: "telegram-runtime",
},
},
channels: {
telegram: {
botToken: {
source: "env",
provider: "telegram-runtime",
id: "TELEGRAM_RUNTIME_TOKEN",
},
},
},
} as unknown as OpenClawConfig;
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.12Bemerkung:
(vorverarbeitet am 2026-06-13)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.