feat: 补齐 Piper 集群地址环境变量并明确功能授权边界

e562ae9 移除旧 HOSE_GRAY_GATEWAY_URL 逃生口后,两个 Piper 域名一直
硬编码,且 webhook.ts 把同一域名又写了一遍,改常量不会跟着变。

- 新增 core/http/piper-endpoints.ts 收口常量与 resolvePiperBaseUrl(),
  运行时读取 HOSE_PIPER_BASE_URL / HOSE_PIPER_TEST_BASE_URL;
  script-engine-client.ts 保留历史导出并改用运行时解析。
- 工作流引擎客户端、Webhook 触发 URL、灰度节点开通三处统一走
  resolvePiperBaseUrl,不再各写一份域名。
- EASO 换票默认地址复用 EKB_BASE_URL,消除第三份硬编码。
- .env.example 补齐 Piper、AI PRO 凭证与签发方、管理员密码变量;
  README 新增环境变量小节;README.transport.md 同步。

纠正上一轮的误判:hose-use 是免费功能,凭证只作用于 hose-aipro,
「hose-use 写命令未受凭证约束」不是安全缺口。该边界已写入
README、hose-aipro Skill 与项目记忆,不再列为待办。

校验:bun test 1103 pass / 0 fail,bun run check、check:readme 通过。
This commit is contained in:
gitea committed 2026-11-05 17:13:20 +08:00
1 parent d772ff0164
commit 13c47d7569
10 files changed
+112 -11

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
import { afterEach, describe, expect, test } from "bun:test";
import { resolvePiperBaseUrl } from "./piper-endpoints.js";
const KEYS = ["HOSE_PIPER_BASE_URL", "HOSE_PIPER_TEST_BASE_URL"] as const;
afterEach(() => {
for (const key of KEYS) delete process.env[key];
});
describe("Piper 集群地址", () => {
test("未设置环境变量时使用默认地址", () => {
expect(resolvePiperBaseUrl()).toBe("https://piper.ekuaibao.com");
expect(resolvePiperBaseUrl(true)).toBe("https://piper-test.ekuaibao.net");
});
test("HOSE_PIPER_BASE_URL 覆盖标准集群并去掉尾部斜线", () => {
process.env.HOSE_PIPER_BASE_URL = "https://piper.internal.example///";
expect(resolvePiperBaseUrl()).toBe("https://piper.internal.example");
expect(resolvePiperBaseUrl(true)).toBe("https://piper-test.ekuaibao.net");
});
test("HOSE_PIPER_TEST_BASE_URL 只覆盖测试集群", () => {
process.env.HOSE_PIPER_TEST_BASE_URL = "https://piper-test.internal.example/";
expect(resolvePiperBaseUrl(true)).toBe("https://piper-test.internal.example");
expect(resolvePiperBaseUrl()).toBe("https://piper.ekuaibao.com");
});
test("空白值回退默认", () => {
process.env.HOSE_PIPER_BASE_URL = " ";
expect(resolvePiperBaseUrl()).toBe("https://piper.ekuaibao.com");
});
});
+24
View File
@@ -0,0 +1,24 @@
/**
* Piper / ScriptEngine 集群地址收口。
*
* 保持轻量(不依赖 ky、不触发网络),供 core、domains 各层共用。
* 旧版 HOSE_GRAY_GATEWAY_URL 逃生口在 e562ae9 移除后一直缺位,这里补齐。
*/
const DEFAULT_PIPER_BASE_URL = "https://piper.ekuaibao.com";
const DEFAULT_PIPER_TEST_BASE_URL = "https://piper-test.ekuaibao.net";
function envBaseUrl(value: string | undefined, fallback: string): string {
const normalized = value?.trim().replace(/\/+$/, "");
return normalized || fallback;
}
/** 运行时解析,每次读取环境变量,便于私有化/多集群部署与测试覆盖。 */
export function resolvePiperBaseUrl(isTest = false): string {
return isTest
? envBaseUrl(process.env.HOSE_PIPER_TEST_BASE_URL, DEFAULT_PIPER_TEST_BASE_URL)
: envBaseUrl(process.env.HOSE_PIPER_BASE_URL, DEFAULT_PIPER_BASE_URL);
}
/** 兼容历史常量导入;值为进程启动时的解析结果。 */
export const SCRIPT_ENGINE_BASE_URL = resolvePiperBaseUrl(false);
export const SCRIPT_ENGINE_TEST_BASE_URL = resolvePiperBaseUrl(true);
+11 -4
View File
@@ -16,10 +16,17 @@ import {
setCorpTokens,
} from "../auth/token-store.js";
export const SCRIPT_ENGINE_BASE_URL = "https://piper.ekuaibao.com";
import {
resolvePiperBaseUrl,
SCRIPT_ENGINE_BASE_URL,
SCRIPT_ENGINE_TEST_BASE_URL,
} from "./piper-endpoints.js";
/** 测试 Piper 集群,仅供显式 --is-test 的工作流灰度开通使用。 */
export const SCRIPT_ENGINE_TEST_BASE_URL = "https://piper-test.ekuaibao.net";
export {
resolvePiperBaseUrl,
SCRIPT_ENGINE_BASE_URL,
SCRIPT_ENGINE_TEST_BASE_URL,
} from "./piper-endpoints.js";
// 兼容历史常量名
export const PIPER_BASE_URL = SCRIPT_ENGINE_BASE_URL;
@@ -120,7 +127,7 @@ export async function getScriptEngineClient(
const cachedJwt = mem.jwt;
const cachedHoseToken = mem.hoseToken;
return createAuthClient({
prefixUrl: SCRIPT_ENGINE_BASE_URL,
prefixUrl: resolvePiperBaseUrl(),
getHeaders: () => {
const headers: Record<string, string> = {
Authorization: `Bearer ${scriptEngineMemoryCache.get(cacheKey)?.jwt ?? cachedJwt}`,