Add staging simulation guide and refine hose integration sync

- Add comprehensive reference guide for staging simulation and production rule evolution
- Require latest CLI, skill, and plugin versions with self-update instructions in SKILL.md
- Deduplicate prod hosecloud integrations by corporationId during corps sync-test
- Support key and password fallback in enterprise source config for hose credentials
- Add unit and integration tests covering deduplication and source credential compatibility
This commit is contained in:
gitea committed 2026-09-11 15:04:49 +08:00
1 parent 0794f319b0
commit bdeca88354
4 files changed
+296 -21

No files matched your search

+79
View File
@@ -686,6 +686,85 @@ describe("sync-test hosecloud integration auto-sync", () => {
expect(parsed.hosecloudSync.skipped).toBe(true);
expect(parsed.hosecloudSync.reason).toContain("not hose");
});
test("deduplicates multiple prod integrations for the same corporationId into one test integration", async () => {
setupHoseTestEnv();
await runCli(["corps", "bind-test", "hose-prod", "hose-test", "--confirm"]);
let capturedBody: any;
// Prod has TWO integrations for the same corporationId (e.g. assisted and fully_automatic)
mockHoseSyncRequests({
prodHosecloudIntegrations: [
{
type: "hosecloud",
signKey: "prod-assisted-key",
outboundName: "辅助审批",
mode: "assisted",
apiKey: "test-app-key-123",
apiSecret: "test-app-secret-456",
apiOrigin: "wechat",
corporationId: "hose-prod"
},
{
type: "hosecloud",
signKey: "prod-auto-key",
outboundName: "全自动审批",
mode: "fully_automatic",
apiKey: "test-app-key-123",
apiSecret: "test-app-secret-456",
apiOrigin: "wechat",
corporationId: "hose-prod"
}
],
onConfigWrite: (isProd, body) => {
if (!isProd) capturedBody = body;
}
});
const result = await runCli(["corps", "sync-test", "hose-prod", "--yes"]);
expect(result.isError).toBe(false);
const parsed = JSON.parse(result.stdout);
// Synced array should contain exactly 1 entry, not 2
expect(parsed.hosecloudSync.synced).toHaveLength(1);
expect(parsed.hosecloudSync.synced[0].corporationId).toBe("hose-prod");
const writtenIntegrations = (capturedBody?.integrations ?? []).filter((i: any) => i.type === "hosecloud");
expect(writtenIntegrations).toHaveLength(1);
expect(writtenIntegrations[0].mode).toBe("assisted");
expect(writtenIntegrations[0].apiOrigin).toBe("wechat");
});
test("supports key/password fallback in source config when appKey/appSecurity are omitted", async () => {
const { enterprises } = setupHoseTestEnv();
// Overwrite hose-prod.json to use key / password instead of appKey / appSecurity
const prodCorpWithKeyPassword = JSON.parse(readFileSync(join(enterprises, "hose-prod.json"), "utf-8"));
delete prodCorpWithKeyPassword.source.appKey;
delete prodCorpWithKeyPassword.source.appSecurity;
prodCorpWithKeyPassword.source.key = "fallback-key-789";
prodCorpWithKeyPassword.source.password = "fallback-secret-012";
writeFileSync(join(enterprises, "hose-prod.json"), JSON.stringify(prodCorpWithKeyPassword, null, 2));
await runCli(["corps", "bind-test", "hose-prod", "hose-test", "--confirm"]);
let capturedBody: any;
mockHoseSyncRequests({
onConfigWrite: (isProd, body) => {
if (!isProd) capturedBody = body;
}
});
const result = await runCli(["corps", "sync-test", "hose-prod", "--yes"]);
expect(result.isError).toBe(false);
const parsed = JSON.parse(result.stdout);
expect(parsed.hosecloudSync.skipped).toBe(false);
expect(parsed.hosecloudSync.synced).toHaveLength(1);
const writtenIntegration = capturedBody?.integrations?.find((i: any) => i.type === "hosecloud");
expect(writtenIntegration?.apiKey).toBe("fallback-key-789");
expect(writtenIntegration?.apiSecret).toBe("fallback-secret-012");
});
});
describe("corps list & current", () => {
+42 -17
View File
@@ -452,23 +452,34 @@ export async function handleCorpsCommand(action: string | undefined, maybeName:
publishVersionName: versionName,
publishTarget: "test"
},
hosecloudSyncPlan: prodCorp.source.type === "hose" ? {
sourceType: "hose",
outboundName: buildTestHosecloudOutboundName(prodCorp.name),
targetMode: "assisted",
integrationsCount: (prodPref.integrations ?? []).filter((i: any) => i.type === "hosecloud").length,
integrations: (prodPref.integrations ?? [])
.filter((i: any) => i.type === "hosecloud")
.map((i: any) => ({
hosecloudSyncPlan: (() => {
if (prodCorp.source.type !== "hose") {
return {
sourceType: prodCorp.source.type,
skipped: true,
reason: "prod source is not hose; no hosecloud credentials available"
};
}
const rawHose = (prodPref.integrations ?? []).filter((i: any) => i.type === "hosecloud");
const seen = new Set<string>();
const distinct = rawHose.filter((i: any) => {
const cid = i.corporationId ?? prodCorp.id;
if (seen.has(cid)) return false;
seen.add(cid);
return true;
});
return {
sourceType: "hose",
outboundName: buildTestHosecloudOutboundName(prodCorp.name),
targetMode: "assisted",
integrationsCount: distinct.length,
integrations: distinct.map((i: any) => ({
corporationId: i.corporationId,
apiOrigin: i.apiOrigin,
customApiUrl: i.customApiUrl
}))
} : {
sourceType: prodCorp.source.type,
skipped: true,
reason: "prod source is not hose; no hosecloud credentials available"
},
};
})(),
productionGuarantees: {
prodRulesStayDraft: true,
prodVersionPublished: false
@@ -743,10 +754,10 @@ async function syncHosecloudIntegrationsToTest(
return { skipped: true, reason: "prod source is not hose; no hosecloud credentials available" }
}
const appKey = (prodCorp.source as any).appKey as string | undefined
const appSecurity = (prodCorp.source as any).appSecurity as string | undefined
const appKey = (((prodCorp.source as any).appKey ?? (prodCorp.source as any).key) as string | undefined)?.trim()
const appSecurity = (((prodCorp.source as any).appSecurity ?? (prodCorp.source as any).password) as string | undefined)?.trim()
if (!appKey || !appSecurity) {
return { skipped: true, reason: "prod hose source missing appKey/appSecurity" }
return { skipped: true, reason: "prod hose source missing appKey/appSecurity (or key/password)" }
}
const [prodPref, testPref] = await Promise.all([
@@ -759,6 +770,20 @@ async function syncHosecloudIntegrationsToTest(
return { skipped: true, reason: "prod Seal enterprise has no hosecloud integrations configured" }
}
// Deduplicate prod integrations by corporationId:
// Production enterprises may have multiple integrations (e.g. "assisted" + "fully_automatic")
// with the same corporationId. For the test environment, exactly one assisted integration per
// corporationId is needed.
const seenCorpIds = new Set<string>()
const distinctProdIntegrations: any[] = []
for (const item of prodIntegrations) {
const cid = item.corporationId ?? prodCorp.id
if (!seenCorpIds.has(cid)) {
seenCorpIds.add(cid)
distinctProdIntegrations.push(item)
}
}
const testIntegrations: any[] = (testPref.integrations ?? [])
const testByCorpId = new Map<string, any>(
testIntegrations.filter((i: any) => i.type === "hosecloud").map((i: any) => [i.corporationId, i])
@@ -767,7 +792,7 @@ async function syncHosecloudIntegrationsToTest(
const outboundName = buildTestHosecloudOutboundName(prodCorp.name)
const synced: HosecloudSyncResult["synced"] = []
const nextHosecloudIntegrations: any[] = prodIntegrations.map((prodInt: any) => {
const nextHosecloudIntegrations: any[] = distinctProdIntegrations.map((prodInt: any) => {
const existing = testByCorpId.get(prodInt.corporationId)
const signKey = existing?.signKey ?? randomBytes(6).toString("hex")
synced!.push({