Remove redundant enterprise provider metadata

Drop source.provider/providerName, cached enterprise.provider, onboarding writes, CLI outputs, and the search index entry; legacy configs and token caches still parse. Add a compatibility test for stripping the old keys.
This commit is contained in:
gitea committed 2026-11-19 15:48:59 +08:00
1 parent 8adae54c54
commit 8d6b65d3d5
22 files changed
+113 -47

No files matched your search

+1 -1
View File
@@ -121,7 +121,7 @@ Import a Hose/合思 assistance link when you do not have OpenAPI app credential
seal-use corps add-link "https://wx2.ekuaibao.com/web/thirdparty.html?accessToken=<temporary-token>&ekbCorpId=<corpId>&pageType=home" [--name "企业名称"]
```
The command accepts HTTPS links from the supported Hose domains, verifies the Seal tenant with `/api/v1/auth/me`, and writes a Hose source with `provider: "hosecloud"`, `closeToken`, and `staffId`. The incoming token is never printed. Use `--overwrite` to replace an existing config explicitly.
The command accepts HTTPS links from the supported Hose domains, verifies the Seal tenant with `/api/v1/auth/me`, and writes a Hose source with `closeToken` and `staffId`. The incoming token is never printed. Use `--overwrite` to replace an existing config explicitly.
To generate a Seal delegation link directly from the same incoming Hose link without saving a config:
@@ -0,0 +1,69 @@
# 企业 provider 字段清理方案
状态:已实施并验证(2026-11-19)。范围仅限企业 provider 元数据及其直接引用。
## 结论与证据
建议删除企业配置的 `source.provider`、`source.providerName`,同时删除本地认证会话的 `enterprise.provider` 及相关输入、展示、检索、赋值和测试负载。不新增替代分类字段。
- [配置定义](../../../src/core/config/types.ts:9):`provider` 在两种 source 上均为可选自由字符串,不是三值枚举;`providerName` 只有声明,没有业务读写。
- [企业选择](../../../src/core/config/manager.ts:11):选择依据是企业 ID、名称、默认企业和 active 门禁;provider 不参与。
- [搜索](../../../src/core/corp-search/corp.ts:26):provider 作为权重 0.8 的可选匹配文本。
- [列表与当前企业](../../../src/cli/commands/corps/overview.ts:97) 使用 `provider ?? source.type`;[详情](../../../src/cli/commands/corps/shared.ts:26) 的 Hose 分支使用 `provider ?? "hosecloud"`。持久凭据企业未存 provider 时,两者输出不同值。
- [Seal 接入](../../../src/domains/seal/enterprise/onboarding.ts:142) 从输入或远端身份中复制 provider;[Hose Web 接入](../../../src/domains/hose/onboarding.ts:278) 写死 hosecloud;Hose 持久凭据不写该字段。
- [缓存类型](../../../src/core/auth/types.ts:9) 要求 enterprise.provider,由 [native](../../../src/core/auth/native.ts:18)、[seal](../../../src/core/auth/seal.ts:72)、[hose](../../../src/core/auth/hose.ts:498) 构造,但仓库内没有按它决策的消费者。
- 三处企业密钥相关输出也含固定 `provider: "hose"`,见 [corps/onboarding.ts](../../../src/cli/commands/corps/onboarding.ts:342)。它们不是企业配置写入点,但属于同一冗余标签。
证据边界:以上为仓库内静态引用调查,不能据此断言没有外部脚本读取 CLI JSON 中的 provider。此前“三种分类”以及“只需改几处展示”的描述不准确;实际涉及配置、接入、缓存、输出和测试。
## 目标与涉及文件
| 模块 | 文件 | 具体修改 |
|---|---|---|
| 配置 | [types.ts](../../../src/core/config/types.ts) | 删除 Hose、Seal source 的 provider,以及 Seal source 的 providerName |
| 本地会话 | [auth/types.ts](../../../src/core/auth/types.ts)、[native.ts](../../../src/core/auth/native.ts)、[seal.ts](../../../src/core/auth/seal.ts)、[hose.ts](../../../src/core/auth/hose.ts) | 删除 enterprise.provider 的 schema 与三处构造赋值 |
| 接入 | [seal/enterprise/onboarding.ts](../../../src/domains/seal/enterprise/onboarding.ts)、[hose/onboarding.ts](../../../src/domains/hose/onboarding.ts) | 删除 SealBearerInput.provider、远端复制和固定值写入;保留其它身份与凭据数据 |
| CLI | [corps/onboarding.ts](../../../src/cli/commands/corps/onboarding.ts)、[overview.ts](../../../src/cli/commands/corps/overview.ts)、[shared.ts](../../../src/cli/commands/corps/shared.ts) | 停止解析 add-seal-bearer 的 provider;删除列表、当前企业、详情和三处密钥相关输出中的 provider |
| 检索 | [corp-search/corp.ts](../../../src/core/corp-search/corp.ts) | 删除 provider 匹配项 |
| 文档 | [README.md](../../../README.md:124) | 删除接入后保存 provider: hosecloud 的承诺,继续说明真实凭据字段 |
测试同步范围:
- [config/types.test.ts](../../../src/core/config/types.test.ts)、[cli/commands/corps.test.ts](../../../src/cli/commands/corps.test.ts):更新字段预期,覆盖旧字段兼容和输出不再带 provider。
- [auth/native.test.ts](../../../src/core/auth/native.test.ts)、[auth/hose.test.ts](../../../src/core/auth/hose.test.ts)、[auth/seal-renew.test.ts](../../../src/core/auth/seal-renew.test.ts)、[auth/token-store.test.ts](../../../src/core/auth/token-store.test.ts):更新会话构造及断言,验证旧缓存仍可读。
- [http/factory.test.ts](../../../src/core/http/factory.test.ts)、[cli/commands/report-review-cli.test.ts](../../../src/cli/commands/report-review-cli.test.ts)、[probe.test.ts](../../../src/probe.test.ts):仅清理本地会话 fixture 的冗余标签;保留模拟远端接口的真实字段。
## 边界与取舍
保留以下内容:
1. `source.type: hose | seal`:仍决定认证实现。
2. `closeToken`、`appKey/appSecurity`、Seal token 和委托 cookie:仍决定实际凭据与认证过程。
3. `providerUserId`:接入和刷新元数据使用它,且 [onboarding.ts:141](../../../src/domains/seal/enterprise/onboarding.ts:141) 用它推导 staffId;不能因名字相似而连带删除。
4. [Seal API 用户身份判断](../../../src/domains/seal/api.ts:1283) 与 [远端类型](../../../src/domains/seal/types.ts):这里的 provider 属于服务端协议,实际参与本地密码及合思身份判断,继续保留。
5. 远端原始对象中的 provider、LLM provider 等同名概念。
6. 企业启停、环境标签、生产测试绑定、默认企业选择等其它管理机制。
不扩展到企业管理整体重构;此次明确有证据的冗余字段可独立清理。
## 兼容与预期行为变化
- 旧企业 JSON 即使仍有 provider/providerName,也应正常加载;Zod 默认剥离未声明键,运行时对象不再包含它们。不会因加载而主动改写原文件。
- 新建或经现有 schema 保存的企业配置不再写入这些键。不编写迁移脚本,也不扫描或批量重写真实企业目录。
- 旧 tokens.json 带 enterprise.provider 时仍应解析成功,后续会话不再生成该键;现有 token、有效期和其它缓存条目保留。通过隔离测试验证,不操作真实 token 文件。
- add-seal-bearer 的旧 JSON 中仍带 provider 时按无效元数据忽略,不因这一额外键报错,也不再检查或保存它。
- corps list/current/get/show 及三处密钥相关输出不再有 provider;已有 sourceType、source.type 或 kind 等字段继续按现有命令输出,避免重新添加同义标签。
- 依赖 JSON provider 字段的外部调用方需要调整;不能承诺输出结构完全兼容。
- 仅凭 provider 匹配的检索结果会消失,例如 Seal source 中曾存 feishu、用户以 feishu 搜企业。企业 ID、名称等现有搜索字段继续工作,Hose 仍可由 source.type 匹配。
- 认证与租户操作的分派依据不变,删除的是元数据链路。
## 验证方案
1. 隔离配置测试:旧 provider/providerName 存在时仍能加载,解析结果不再含键;Hose 持久凭据、Web 会话与 Seal source 仍通过校验。
2. 隔离缓存测试:带 provider 的旧缓存及不带 provider 的新缓存均能读取,token、有效期和其它条目不丢失。
3. 接入与 CLI 回归:两类 Hose 接入、Seal bearer、委托与续期既有测试;断言新配置、会话和相关 JSON 输出不再产生 provider。
4. 检索回归:验证删除 provider 搜索项后 ID、名称、source.type 等正常匹配。
5. 执行 `bun run check`、`bun run lint` 与上述受影响的 Bun 测试;测试禁用后台更新并使用临时配置路径,不访问真实企业数据。
6. 最后复查 Diff 和全仓引用,确认剩余 provider 仅属于服务端协议、其它业务概念或明确的旧格式兼容测试;若有新增发现,报告实际差异。
实施结果:已按上表完成清理,`bun run check`、`bun run lint` 与全量 `bun test`(1180 通过)均通过。未改写本机企业配置或认证缓存;旧配置与旧缓存的兼容性由隔离测试覆盖。
+4 -9
View File
@@ -45,7 +45,6 @@ describe("corps link onboarding", () => {
type: string;
closeToken: string;
staffId: string;
provider?: string;
corpId?: string;
};
};
@@ -60,7 +59,6 @@ describe("corps link onboarding", () => {
type: "hose",
closeToken: "hose-token",
staffId: "acme-01:admin",
provider: "hosecloud",
corpId: "acme-01"
}
});
@@ -117,7 +115,6 @@ describe("corps link onboarding", () => {
source: {
type: string;
token: string;
provider?: string;
};
};
expect(config).toMatchObject({
@@ -129,8 +126,7 @@ describe("corps link onboarding", () => {
},
source: {
type: "seal",
token: "mock-delegate-token",
provider: "seal"
token: "mock-delegate-token"
}
});
});
@@ -193,7 +189,7 @@ describe("corps link onboarding", () => {
expect(result.exitCode).toBe(0);
const config = JSON.parse(readFileSync(join(enterprises, "acme-01.json"), "utf-8"));
expect(config.source.type).toBe("hose");
expect(config.source.provider).toBe("hosecloud");
expect(config.source).not.toHaveProperty("provider");
expect(config.source.closeToken).toBe("hose-token");
expect(config.source.staffId).toBe("staff-1");
});
@@ -331,8 +327,7 @@ describe("corps get and search", () => {
token: "veryLongSecretBearerToken1234567890",
expiresIn: 3600,
tenantSlug: "native-slug",
tenantName: "原生租户",
provider: "feishu"
tenantName: "原生租户"
},
auth: { refreshTtl: 300 }
})
@@ -346,7 +341,7 @@ describe("corps get and search", () => {
const data = JSON.parse(result.stdout);
expect(data.id).toBe("native-seal");
expect(data.source.type).toBe("seal");
expect(data.source.provider).toBe("feishu");
expect(data.source).not.toHaveProperty("provider");
expect(data.source.hasToken).toBe(true);
expect(data.source.tokenMasked).toContain("...");
});
-4
View File
@@ -264,7 +264,6 @@ async function addSealCorp(input: Record<string, unknown>) {
tenantName: optionalString(input, "tenantName"),
corpId: optionalString(input, "corpId"),
staffId: optionalString(input, "staffId"),
provider: optionalString(input, "provider"),
force: input.force === true,
verify: input.verify === false,
overwrite: input.overwrite === true,
@@ -339,7 +338,6 @@ async function addLinkAsHoseCorp(link: string, name: string | undefined, overwri
printJson({
dryRun: true,
kind: "hose",
provider: "hose",
corpId: result.corpId,
corpName: result.corpName,
baseUrl: result.baseUrl,
@@ -394,7 +392,6 @@ export async function extractKeysFromLinkAction(link: string, options: { reveal?
if (!reveal) console.error("ℹ️ [合思子域提权] 成功提取合思 (Hose) OpenAPI 密钥。接入密码默认脱敏,附加 --reveal (或 -r) 可查看完整 appSecurity 明文;附加 --save 可将临时会话提权并持久化为标准合思企业。\n");
else console.error("⚠️ [合思子域提权] 正在以明文展示合思 (Hose) appSecurity 接入密码,请妥善保管敏感凭据。\n");
printJson({
provider: "hose",
capability: "privilege-elevation",
corpId: result.corpId,
corpName: result.corpName ?? result.corpId,
@@ -417,7 +414,6 @@ export async function showCorpKeysAction(targetCorpId: string | undefined, optio
if (!reveal) console.error("💡 [合思子域] 接入密码默认脱敏,附加 --reveal (或 -r) 可查看完整 appSecurity 明文。\n");
else console.error("⚠️ [合思子域] 正在以明文展示合思 appSecurity 接入密码,请妥善保管敏感凭据。\n");
printJson({
provider: "hose",
capability: "privilege-elevation",
corpId: corp.id,
corpName: corp.name,
-2
View File
@@ -94,7 +94,6 @@ export async function handleCorpOverview(
active: item.active ?? true,
environment: item.environment ?? "production",
sourceType: item.source.type,
provider: (item.source as any).provider ?? item.source.type,
staffId: item.source.staffId,
testCorpId: item.testCorpId,
prodCorpId: item.prodCorpId,
@@ -147,7 +146,6 @@ export async function handleCorpOverview(
active: corp.active ?? true,
environment: corp.environment ?? "production",
sourceType: corp.source.type,
provider: (corp.source as any).provider ?? corp.source.type,
staffId: corp.source.staffId,
testCorpId: corp.testCorpId,
prodCorpId: corp.prodCorpId
-2
View File
@@ -23,7 +23,6 @@ export function formatSafeSourceDetail(source: SealSource) {
const key = source.appKey ?? source.key;
return {
type: "hose",
provider: source.provider ?? "hosecloud",
domain: source.domain,
corpId: source.corpId,
staffId: source.staffId,
@@ -40,7 +39,6 @@ export function formatSafeSourceDetail(source: SealSource) {
if (source.type === "seal") {
return {
type: "seal",
provider: source.provider ?? "seal",
tenantId: source.tenantId,
tenantSlug: source.tenantSlug,
tenantName: source.tenantName,
+1 -2
View File
@@ -29,8 +29,7 @@ const testCorp: CorpConfig = {
staffId: "u-triage",
corpId: "corp-triage-test",
tenantId: "t-triage",
tenantSlug: "triage",
provider: "seal"
tenantSlug: "triage"
},
auth: { refreshTtl: 300 }
};
+1 -2
View File
@@ -137,7 +137,6 @@ describe("hose auth helpers", () => {
seal: { endpoints: { approvalStylePreferences: "" } },
source: {
type: "hose",
provider: "hosecloud",
domain: "https://wx2.ekuaibao.com",
closeToken: "hose-close-token",
staffId: "corp-web:staff-1",
@@ -149,7 +148,7 @@ describe("hose auth helpers", () => {
const session = await getHoseSealSession(corp);
expect(requestedToken).toBe("hose-close-token");
expect(session.token).toBe("seal-runtime-token");
expect(session.enterprise.provider).toBe("hose");
expect(session.enterprise).not.toHaveProperty("provider");
});
test("HOSE_STANDARD_DOMAINS contains 6 expected public platform domains", () => {
-1
View File
@@ -495,7 +495,6 @@ export async function getHoseSealSession(corp: CorpConfig): Promise<SealSession>
3600;
const enterprise: SealEnterpriseConfig = {
provider: "hose",
corpId: corp.source.corpId,
staffId: corp.source.staffId,
sealUrl: normalizeBaseUrl(sealUrl),
+1 -2
View File
@@ -31,7 +31,6 @@ describe("getNativeSealSession", () => {
const session = await getNativeSealSession(corp);
expect(session.token).toBe("bearer-token-native");
expect(session.enterprise).toEqual({
provider: "seal",
corpId: "corp-native-1",
staffId: "staff-123",
sealUrl: "https://seal.example.com",
@@ -75,7 +74,7 @@ describe("getNativeSealSession", () => {
const session = await getNativeSealSession(corp);
expect(session.token).toBe("bearer-token-native");
expect(session.enterprise.provider).toBe("seal");
expect(session.enterprise).not.toHaveProperty("provider");
expect(session.enterprise.tenantId).toBe("tenant-100");
expect(session.enterprise.tenantName).toBe("Tenant 100 Name");
expect(session.expiresAt).toBe(new Date("2026-09-22T05:30:00Z").getTime());
-1
View File
@@ -15,7 +15,6 @@ export async function getNativeSealSession(corp: CorpConfig): Promise<SealSessio
token: corp.source.token,
expiresAt,
enterprise: {
provider: corp.source.provider ?? "seal",
corpId: corp.source.corpId ?? corp.id,
staffId: corp.source.staffId,
sealUrl,
+1 -2
View File
@@ -38,8 +38,7 @@ const fixtureCorp: CorpConfig = {
corpId: "test-delegate-corp",
tenantId: "t-456",
tenantSlug: "mytenant",
tenantName: "My Tenant",
provider: "seal"
tenantName: "My Tenant"
},
auth: { refreshTtl: 300 }
};
-1
View File
@@ -69,7 +69,6 @@ export async function renewNativeSealSession(corp: CorpConfig): Promise<SealSess
token: exchanged.token,
expiresAt: Date.now() + exchanged.expiresIn * 1000,
enterprise: {
provider: source.provider ?? "seal",
corpId: source.corpId ?? corp.id,
staffId: source.staffId,
sealUrl,
-2
View File
@@ -68,7 +68,6 @@ describe("token-store", () => {
token: "test-token-123",
expiresAt: Date.now() + 3600_000,
enterprise: {
provider: "seal",
corpId: "corp-1",
staffId: "staff-1",
sealUrl: "https://seal.example.com"
@@ -136,7 +135,6 @@ describe("token-store", () => {
token: "legacy-token-456",
expiresAt: Date.now() + 3600_000,
enterprise: {
provider: "seal",
corpId: "corp-legacy",
staffId: "staff-legacy",
sealUrl: "https://seal.example.com"
-1
View File
@@ -7,7 +7,6 @@ export const TokenEntrySchema = z.object({
});
export const SealEnterpriseConfigSchema = z.object({
provider: z.string(),
corpId: z.string().optional(),
staffId: z.string(),
sealUrl: z.string().url(),
+30 -1
View File
@@ -52,7 +52,6 @@ describe("CorpConfigSchema", () => {
name: "Hose Web Session",
source: {
type: "hose",
provider: "hosecloud",
domain: "https://wx2.ekuaibao.com",
closeToken: "hose-close-token",
expiresIn: 1800,
@@ -71,6 +70,36 @@ describe("CorpConfigSchema", () => {
expect(config.source.expiresAt).toBe("2026-09-22T13:30:00+08:00");
});
test("drops legacy provider metadata instead of rejecting the config", () => {
const hoseConfig = CorpConfigSchema.parse({
id: "legacy-hose",
name: "Legacy Hose",
source: {
type: "hose",
provider: "hosecloud",
domain: "https://wx2.ekuaibao.com",
closeToken: "hose-close-token",
corpId: "corp-1",
staffId: "corp-1:staff-1"
}
});
expect(hoseConfig.source).not.toHaveProperty("provider");
const sealConfig = CorpConfigSchema.parse({
id: "legacy-seal",
name: "Legacy Seal",
source: {
type: "seal",
token: "seal-token",
sealUrl: "https://seal.sealai.cc",
provider: "feishu",
providerName: "飞书"
}
});
expect(sealConfig.source).not.toHaveProperty("provider");
expect(sealConfig.source).not.toHaveProperty("providerName");
});
test("accepts Seal Bearer source with expiry metadata and normalizes legacy UTC to +08:00", () => {
const config = CorpConfigSchema.parse({
id: "seal",
+1 -4
View File
@@ -8,7 +8,6 @@ const IsoSecondTimestampSchema = z.string().regex(
export const HoseSealSourceSchema = z.object({
type: z.literal("hose"),
provider: z.string().optional(),
domain: z.string().url().default("https://app.ekuaibao.com"),
appKey: z.string().optional(),
appSecurity: z.string().optional(),
@@ -49,9 +48,7 @@ export const NativeSealSourceSchema = z.object({
tenantId: z.string().optional(),
tenantSlug: z.string().optional(),
tenantName: z.string().optional(),
providerUserId: z.string().optional(),
provider: z.string().optional(),
providerName: z.string().optional()
providerUserId: z.string().optional()
});
export const SealSourceSchema = z.discriminatedUnion("type", [
+1 -2
View File
@@ -22,8 +22,7 @@ function corpSearchFields(corp: CorpConfig): CorpField[] {
{ text: corp.testCorpId, weight: 1.0 },
{ text: corp.prodCorpId, weight: 1.0 },
{ text: corp.environment ?? "production", weight: 0.8 },
{ text: corp.source.type, weight: 0.8 },
{ text: (corp.source as any).provider, weight: 0.8 }
{ text: corp.source.type, weight: 0.8 }
];
}
+1 -1
View File
@@ -37,7 +37,7 @@ function recoveryFixture(sourceType: "hose" | "seal", alwaysUnauthorized = false
});
setSealSession(id, {
token: "stale-token", expiresAt: Date.now() + 3600000,
enterprise: { provider: sourceType, staffId: "fixture-staff", sealUrl: "https://fixture.invalid" }
enterprise: { staffId: "fixture-staff", sealUrl: "https://fixture.invalid" }
});
const requests: Array<{ method: string; token: string | null }> = [];
let refreshes = 0;
-1
View File
@@ -275,7 +275,6 @@ export async function onboardHoseWebSession(input: HoseWebSessionInput) {
},
source: {
type: "hose",
provider: "hosecloud",
domain: details.baseUrl,
closeToken: input.accessToken,
...(input.expiresIn !== undefined ? { expiresIn: input.expiresIn } : {}),
+2 -5
View File
@@ -28,7 +28,6 @@ export type SealBearerInput = {
tenantName?: string;
corpId?: string;
staffId?: string;
provider?: string;
headers?: unknown;
cookies?: unknown;
force?: boolean;
@@ -93,7 +92,7 @@ export function persistSealDelegateSession(input: {
const tenantId = stringValue(input.session.tenant.id);
const corpId = tenantSlug ?? tenantId ?? "seal-delegate";
const saved = saveSealConfig(
{ id: corpId, corpId, name: input.name, provider: "seal", overwrite: input.overwrite },
{ id: corpId, corpId, name: input.name, overwrite: input.overwrite },
{
token: input.session.token,
sealUrl: input.session.sealUrl,
@@ -139,7 +138,6 @@ function saveSealConfig(
? normalizeBeijingIso(auth.expiresAt)
: formatBeijingIso(Date.now() + auth.expiresIn * 1000);
const staffId = input.staffId ?? stringValue(remoteUser?.providerUserId) ?? stringValue(remoteUser?.id) ?? "seal";
const provider = input.provider ?? stringValue(remoteUser?.provider) ?? stringValue((remoteTenant as { providerConfig?: { provider?: unknown } } | undefined)?.providerConfig?.provider);
const corpId = input.corpId ?? tenantSlug ?? tenantId ?? id;
const config: CorpConfig = {
id,
@@ -163,8 +161,7 @@ function saveSealConfig(
tenantId,
tenantSlug,
tenantName,
providerUserId: stringValue(remoteUser?.providerUserId),
provider
providerUserId: stringValue(remoteUser?.providerUserId)
},
auth: { refreshTtl: 300 }
};
-1
View File
@@ -91,7 +91,6 @@ describe("seal-use probe stream contract", () => {
expect(payload.corp).toEqual({ id: "demo-corp", name: "Demo Corp", sourceType: "seal" });
expect(payload.enterprise).toMatchObject({
provider: "seal",
sealUrl: "https://demo-corp.sealai.cc",
tenantName: "Demo Tenant"
});