Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mobile): 纯构建脚本跟进——selfhost 必填自查、dry-run 纯本地、烘焙 env 透明、iOS exportMethod (#242)

Lizi611550403aef
diff --git a/apps/mobile/scripts/build-android.mjs b/apps/mobile/scripts/build-android.mjs
index 04cc76b50d..f125a06519 100644
--- a/apps/mobile/scripts/build-android.mjs
+++ b/apps/mobile/scripts/build-android.mjs
@@ -2,11 +2,13 @@
// =============================================================================
// build-android.mjs —— Android 纯构建(本机出自签 APK,不含任何上传 / 分发 / 发布)
//
-// 流程:git 闸门 → expo prebuild(注入 versionCode)→ patch build.gradle 用自有
+// 流程(--execute):git 闸门 → expo prebuild(注入 versionCode)→ patch build.gradle 用自有
// keystore 自签 → gradlew assembleRelease → app-release.apk
// → 从 APK 回读内嵌 runtimeVersion(assets/fingerprint,仅报告)
// → aapt2 本地校验 package/versionCode(找不到 aapt2 时降级 warn)
// → 产物留在 gradle 输出目录并打印路径(--out 可另拷一份)。
+// dry-run 纯本地:校验配置 + 打印计划,git 闸门(含 origin/main 远端比对)只在
+// --execute 时执行,分支/离线环境也能直接看计划。
//
// 与发布无关:不读写任何远端(无版本基线拉取、无 OSS/CDN、无分发平台)。
// versionCode 缺省取 android-version.json 现值,可用 --version-code 覆盖
@@ -20,8 +22,11 @@
// --region cn|global|dev 必填。从 scripts/self-host-regions.json 取应用身份
// (androidPackage)与签名配置(androidSigning)。该文件
// 不入仓(gitignore),按 self-host-regions.json.example
-// 复制填写;构建只需 authRegion / androidPackage /
-// androidSigning 三项,其余字段可留空。
+// 复制填写;构建必填 authRegion / androidPackage /
+// androidSigning,以及 selfhost 包烘焙必填的 tapdb 两字段
+// (global 另需 google 三字段)——prebuild 期 app.config.js
+// 硬校验,本脚本 dry-run 预告缺失、--execute 前置拦截;
+// 商店 ID / OSS / npkgExpectBundle 等纯发布字段可留空。
// dev 区域还需先按 config/endpoint.dev.json.example
// 复制出 config/endpoint.dev.json(同样 gitignore),
// 并把 cdnBaseUrl 换成实际的无凭据 HTTPS 基址
@@ -32,7 +37,8 @@
// --desktop-version x.y.z 可选。配对的桌面产品线版本号(设置页展示用),
// 不传则不注入、设置页不显示该行。
// --out <dir> 可选。构建完把 .apk 另拷到该目录。
-// --skip-git-gate 跳过 main/clean/HEAD 校验(仅本地迭代用)。
+// --skip-git-gate 跳过 --execute 的 main/clean/HEAD 校验(仅本地迭代用;
+// dry-run 本就不校验)。
//
// 签名配置(全部本地,仓内零敏感值):
// self-host-regions.json 的 <region>.androidSigning:keystorePath / keyAlias
@@ -62,7 +68,7 @@ import { resolveJavaRuntimeEnv } from './java-runtime-env.mjs';
import { clearBundlerCache } from './lib/bundler-cache.mjs';
import { readEmbeddedRuntimeVersionFromApk } from './lib/embedded-runtime.mjs';
import { loadEndpointManifestBaseUrl, mobileClientBuildEnv } from '../../../scripts/shared/client-endpoint-build-env.mjs';
-import { SELF_HOST_REGIONS, loadSelfHostRegions, stripSelfHostRegionEnv } from './lib/self-host-region.mjs';
+import { SELF_HOST_REGIONS, loadSelfHostRegions, missingSelfHostBakeFields, stripSelfHostRegionEnv } from './lib/self-host-region.mjs';
const MOBILE_DIR = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const NPX = process.platform === 'win32' ? 'npx.cmd' : 'npx';
@@ -194,8 +200,9 @@ async function main() {
const args = parseArgs(process.argv.slice(2));
// --region 必填(cn|global|dev):选出本次出包身份 + 签名配置(见 lib/self-host-region.mjs)。
// 不走 resolveSelfHostRegion:它对 dev 强校验发布专用的 npkgExpectBundle,与纯构建
- // 「只需身份 + 签名」的契约不符。这里等价解析 region,装载用 mode 'local'(发布面
- // 字段——商店 ID / TapDB / Google——允许留空),构建面身份字段自查。
+ // 契约不符。这里等价解析 region,装载用 mode 'local'(纯发布字段——商店 ID / OSS /
+ // npkgExpectBundle——允许留空);构建面身份与 selfhost 烘焙必填字段(tapdb,global
+ // 另有 google)由本脚本自查,口径同 prebuild 期 app.config.js 的硬校验。
const rawRegion = typeof args.region === 'string' ? args.region.trim() : '';
if (!rawRegion) {
throw new Error('必须显式指定 --region cn|global|dev(不提供默认值);例:pnpm mobile:build:android -- --region global');
@@ -220,11 +227,23 @@ async function main() {
const versionCode = rawVersionCode || readAndroidVersionCode(MOBILE_DIR);
const desktopVersion = typeof args.desktopVersion === 'string' ? args.desktopVersion : '';
- if (!args.skipGitGate) assertProductionGitGate();
- else log(' warn: --skip-git-gate,跳过 main/clean/HEAD 校验(仅本地迭代用)');
+ // selfhost 烘焙必填字段(prebuild 期 app.config.js 硬校验)提前自查:dry-run 只预告,
+ // --execute 在 prebuild 白跑数分钟之前 fail-fast。
+ const missingBake = missingSelfHostBakeFields(region);
- // 签名配置预检:缺配置尽早暴露,不白跑数分钟 prebuild(取用值在 buildApk 内再解析一次)。
- if (args.execute) resolveAndroidSigningEnv(region, process.env);
+ // git 闸门只管真构建:dry-run 纯本地(不做 origin/main 远端比对,分支/离线可跑)。
+ if (args.execute) {
+ if (!args.skipGitGate) assertProductionGitGate();
+ else log(' warn: --skip-git-gate,跳过 main/clean/HEAD 校验(仅本地迭代用)');
+ if (missingBake.length) {
+ throw new Error(
+ `self-host-regions.json 的 ${region.authRegion} 缺少 selfhost 构建必填字段: ${missingBake.join(', ')} ` +
+ '(prebuild 期 app.config.js 硬校验; tapdb 为包内统计防漏填, global 的 google 为 Google 登录配置)',
+ );
+ }
+ // 签名配置预检:缺配置尽早暴露,不白跑数分钟 prebuild(取用值在 buildApk 内再解析一次)。
+ resolveAndroidSigningEnv(region, process.env);
+ }
// env 必须在 versionCode 决定之后构建:经 XDT_ANDROID_VERSION_CODE 注入 prebuild。
const env = selfhostEnv(region, versionCode, desktopVersion);
@@ -238,7 +257,16 @@ async function main() {
const pwPreview = (base) => (process.env[`${base}_${suffix}`]?.trim() || (suffix === 'CN' ? process.env[base]?.trim() : '')) ? 'set' : '未设';
console.log(`sign: 自有 keystore 自签,path=${aSign.keystorePath || '(JSON 未填)'} alias=${aSign.keyAlias || '(JSON 未填)'} storePw(env ${suffix})=${pwPreview('XDT_ANDROID_KEYSTORE_PASSWORD')} keyPw(env ${suffix})=${pwPreview('XDT_ANDROID_KEY_PASSWORD')}`);
console.log('steps: prebuild → patch build.gradle 签名 → gradlew assembleRelease → 从 APK 回读 runtimeVersion → aapt2 本地校验(仅构建,无上传/发布)');
- for (const line of formatBakedEnvLines(bakedDisplayEnv(region, versionCode, desktopVersion), { extraKeys: ['XDT_ANDROID_VERSION_CODE'] })) console.log(line);
+ if (missingBake.length) {
+ console.log(`selfhost 必填缺失: ${missingBake.join(', ')}(--execute 前须在 self-host-regions.json 补齐;prebuild 期 app.config.js 硬校验)`);
+ }
+ const display = bakedDisplayEnv(region, versionCode, desktopVersion);
+ for (const line of formatBakedEnvLines(display, { extraKeys: ['XDT_ANDROID_VERSION_CODE'] })) console.log(line);
+ // 实际构建 env 从打包机 process.env 起步(微信 AppId 等公开配置本就由打包机 env 注入),
+ // 计划里如实列出将一并烤入的继承键——只列键名不打值,不引机密入日志。
+ const injectedKeys = new Set(Object.keys(display));
+ const inheritedPublicKeys = Object.keys(env).filter((k) => k.startsWith('EXPO_PUBLIC_') && !injectedKeys.has(k)).sort();
+ console.log(`打包机 env 继承的 EXPO_PUBLIC_*(将随构建一并烤入,仅列键名): ${inheritedPublicKeys.join(', ') || '(无)'}`);
if (!args.execute) {
console.log('dry-run: 传 --execute 才真正构建(需 Android SDK + JDK 17 + keystore 口令 env)');
return;
diff --git a/apps/mobile/scripts/build-ios.mjs b/apps/mobile/scripts/build-ios.mjs
index 2d4065758c..8a293acbfe 100644
--- a/apps/mobile/scripts/build-ios.mjs
+++ b/apps/mobile/scripts/build-ios.mjs
@@ -2,9 +2,11 @@
// =============================================================================
// build-ios.mjs —— iOS 纯构建(本机出签名 .ipa,不含任何上传 / 分发 / 发布)
//
-// 流程:git 闸门 → expo prebuild → pod install → xcodebuild archive/export → .ipa
-// → 从 .ipa 回读内嵌 runtimeVersion(EXUpdates.bundle/fingerprint,仅报告)
+// 流程(--execute):git 闸门 → expo prebuild → pod install → xcodebuild archive/export
+// → .ipa → 从 .ipa 回读内嵌 runtimeVersion(EXUpdates.bundle/fingerprint,仅报告)
// → 产物留在导出目录并打印路径(--out 可另拷一份)。
+// dry-run 纯本地:校验配置 + 打印计划,git 闸门(含 origin/main 远端比对)只在
+// --execute 时执行,分支/离线环境也能直接看计划。
//
// 与发布无关:不读写任何远端(无版本基线拉取、无 OSS/CDN、无分发平台),
// 版本号(app.json 的 expo.version / expo.ios.buildNumber)按仓内现值烤入,
@@ -18,8 +20,11 @@
// --region cn|global|dev 必填。从 scripts/self-host-regions.json 取应用身份
// (iosBundleId)与签名描述符(iosSigning)。该文件不入仓
// (gitignore),按 self-host-regions.json.example 复制填写;
-// 构建只需 authRegion / iosBundleId / iosSigning 四项,
-// 其余字段可留空。dev 区域还需先按
+// 构建必填 authRegion / iosBundleId / iosSigning,以及
+// selfhost 包烘焙必填的 tapdb 两字段(global 另需 google
+// 三字段)——prebuild 期 app.config.js 硬校验,本脚本
+// dry-run 预告缺失、--execute 前置拦截;商店 ID / OSS /
+// npkgExpectBundle 等纯发布字段可留空。dev 区域还需先按
// config/endpoint.dev.json.example 复制出
// config/endpoint.dev.json(同样 gitignore),并把
// cdnBaseUrl 换成实际的无凭据 HTTPS 基址
@@ -28,12 +33,17 @@
// --desktop-version x.y.z 可选。配对的桌面产品线版本号(设置页展示用),
// 不传则不注入、设置页不显示该行。
// --out <dir> 可选。构建完把 .ipa 另拷到该目录。
-// --skip-git-gate 跳过 main/clean/HEAD 校验(仅本地迭代用)。
+// --skip-git-gate 跳过 --execute 的 main/clean/HEAD 校验(仅本地迭代用;
+// dry-run 本就不校验)。
//
// 签名配置(全部本地,仓内零敏感值):
// self-host-regions.json 的 <region>.iosSigning:
// teamId / profileName / signIdentity 必填(--execute 时校验)
// profilePath 可选;有值时自动安装描述文件到系统目录
+// exportMethod 可选;development / ad-hoc / enterprise /
+// app-store,留空默认 development(与旧发布
+// 线一致,产物交发布方重签;描述文件为分发
+// 类型时填对应值直接出分发签名 .ipa)
// 证书 p12 / 描述文件本体在仓库外目录,须预先装入本机钥匙串。
// =============================================================================
@@ -53,7 +63,7 @@ import { buildExportOptionsPlist, resolveIosSigningEnv } from './lib/ios-local.m
import { clearBundlerCache } from './lib/bundler-cache.mjs';
import { readEmbeddedRuntimeVersionFromIpa } from './lib/embedded-runtime.mjs';
import { loadEndpointManifestBaseUrl, mobileClientBuildEnv } from '../../../scripts/shared/client-endpoint-build-env.mjs';
-import { SELF_HOST_REGIONS, loadSelfHostRegions, stripSelfHostRegionEnv } from './lib/self-host-region.mjs';
+import { SELF_HOST_REGIONS, loadSelfHostRegions, missingSelfHostBakeFields, stripSelfHostRegionEnv } from './lib/self-host-region.mjs';
const MOBILE_DIR = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const NPX = process.platform === 'win32' ? 'npx.cmd' : 'npx';
@@ -136,6 +146,9 @@ function buildIpa(env, region) {
profileName: sign.profileName,
// 与 archive 的 CODE_SIGN_IDENTITY 同一张证书:避免钥匙串多证书时 export 自选到 profile 外的那张。
signingCertificate: sign.identity,
+ // 分发方式来自 iosSigning.exportMethod(缺省 development,与旧发布线一致);
+ // 描述文件为 ad-hoc / enterprise / app-store 时须填对应值,export 才能出分发签名 .ipa。
+ method: sign.exportMethod,
}));
// xcodebuild 的 RN embed 阶段内部触发 expo export:embed 打 JS bundle,无法透传 --clear;
@@ -160,8 +173,9 @@ async function main() {
const args = parseArgs(process.argv.slice(2));
// --region 必填(cn|global|dev):选出本次出包身份 + 签名描述符(见 lib/self-host-region.mjs)。
// 不走 resolveSelfHostRegion:它对 dev 强校验发布专用的 npkgExpectBundle,与纯构建
- // 「只需身份 + 签名」的契约不符。这里等价解析 region,装载用 mode 'local'(发布面
- // 字段——商店 ID / TapDB / Google——允许留空),构建面身份字段自查。
+ // 契约不符。这里等价解析 region,装载用 mode 'local'(纯发布字段——商店 ID / OSS /
+ // npkgExpectBundle——允许留空);构建面身份与 selfhost 烘焙必填字段(tapdb,global
+ // 另有 google)由本脚本自查,口径同 prebuild 期 app.config.js 的硬校验。
const rawRegion = typeof args.region === 'string' ? args.region.trim() : '';
if (!rawRegion) {
throw new Error('必须显式指定 --region cn|global|dev(不提供默认值);例:pnpm mobile:build:ios -- --region global');
@@ -179,11 +193,23 @@ async function main() {
const version = appJson?.expo?.version ?? '';
const buildNumber = appJson?.expo?.ios?.buildNumber ?? '';
- if (!args.skipGitGate) assertProductionGitGate();
- else log(' warn: --skip-git-gate,跳过 main/clean/HEAD 校验(仅本地迭代用)');
+ // selfhost 烘焙必填字段(prebuild 期 app.config.js 硬校验)提前自查:dry-run 只预告,
+ // --execute 在 prebuild 白跑数分钟之前 fail-fast。
+ const missingBake = missingSelfHostBakeFields(region);
- // 签名描述符预检:dry-run 也提前暴露缺配置(取用值在 buildIpa 内再解析一次)。
- if (args.execute) resolveIosSigningEnv(region);
+ // git 闸门只管真构建:dry-run 纯本地(不做 origin/main 远端比对,分支/离线可跑)。
+ if (args.execute) {
+ if (!args.skipGitGate) assertProductionGitGate();
+ else log(' warn: --skip-git-gate,跳过 main/clean/HEAD 校验(仅本地迭代用)');
+ if (missingBake.length) {
+ throw new Error(
+ `self-host-regions.json 的 ${region.authRegion} 缺少 selfhost 构建必填字段: ${missingBake.join(', ')} ` +
+ '(prebuild 期 app.config.js 硬校验; tapdb 为包内统计防漏填, global 的 google 为 Google 登录配置)',
+ );
+ }
+ // 签名描述符预检:提前暴露缺配置(取用值在 buildIpa 内再解析一次)。
+ resolveIosSigningEnv(region);
+ }
// 计划打印
console.log('');
@@ -191,9 +217,18 @@ async function main() {
console.log(`version / buildNumber: ${version} / ${buildNumber || '(app.json 未填)'}(取 app.json 现值,构建脚本不做版本决策)`);
const sPreview = (name, value) => value?.trim() || `(${region.authRegion}.iosSigning.${name} 未填,--execute 时必填)`;
const iosS = region.iosSigning ?? {};
- console.log(`sign: team=${sPreview('teamId', iosS.teamId)} profile=${sPreview('profileName', iosS.profileName)} identity="${sPreview('signIdentity', iosS.signIdentity)}"(来自 self-host-regions.json 的 ${region.authRegion}.iosSigning)`);
+ console.log(`sign: team=${sPreview('teamId', iosS.teamId)} profile=${sPreview('profileName', iosS.profileName)} identity="${sPreview('signIdentity', iosS.signIdentity)}" export=${iosS.exportMethod?.trim() || 'development'}(来自 self-host-regions.json 的 ${region.authRegion}.iosSigning)`);
console.log('steps: prebuild → pod-install → xcodebuild archive/export → 从 .ipa 回读 runtimeVersion(仅构建,无上传/发布)');
- for (const line of formatBakedEnvLines(bakedDisplayEnv(region, desktopVersion))) console.log(line);
+ if (missingBake.length) {
+ console.log(`selfhost 必填缺失: ${missingBake.join(', ')}(--execute 前须在 self-host-regions.json 补齐;prebuild 期 app.config.js 硬校验)`);
+ }
+ const display = bakedDisplayEnv(region, desktopVersion);
+ for (const line of formatBakedEnvLines(display)) console.log(line);
+ // 实际构建 env 从打包机 process.env 起步(微信 AppId 等公开配置本就由打包机 env 注入),
+ // 计划里如实列出将一并烤入的继承键——只列键名不打值,不引机密入日志。
+ const injectedKeys = new Set(Object.keys(display));
+ const inheritedPublicKeys = Object.keys(env).filter((k) => k.startsWith('EXPO_PUBLIC_') && !injectedKeys.has(k)).sort();
+ console.log(`打包机 env 继承的 EXPO_PUBLIC_*(将随构建一并烤入,仅列键名): ${inheritedPublicKeys.join(', ') || '(无)'}`);
if (!args.execute) {
console.log('dry-run: 传 --execute 才真正构建(需 macOS + Xcode + 已装证书/描述文件)');
return;
diff --git a/apps/mobile/scripts/lib/ios-local.mjs b/apps/mobile/scripts/lib/ios-local.mjs
index 6ff2be0872..ceebcb8723 100644
--- a/apps/mobile/scripts/lib/ios-local.mjs
+++ b/apps/mobile/scripts/lib/ios-local.mjs
@@ -132,6 +132,9 @@ export function replaceBuildNumberInAppJson(rawText, nextBuildNumber) {
return String(rawText).replace(/("buildNumber"\s*:\s*")[^"]*(")/, `$1${nextBuildNumber}$2`);
}
+/** xcodebuild -exportArchive 支持的分发方式;缺省 development 与旧发布线一致(产物交发布方重签)。 */
+export const IOS_EXPORT_METHODS = Object.freeze(['development', 'ad-hoc', 'enterprise', 'app-store']);
+
/**
* 解析 iOS 本地签名描述符(供 xcodebuild archive/export 消费)。
* iOS 签名不含任何机密(无口令),故 teamId / profileName / signIdentity / profilePath **全部从
@@ -143,8 +146,10 @@ export function replaceBuildNumberInAppJson(rawText, nextBuildNumber) {
* 部分名("Apple Development: Jane Doe")走 CODE_SIGN_IDENTITY 子串匹配同样有歧义,
* 多证书钥匙串下都钉不住证书,必须在预检就拒掉(security find-identity -v -p codesigning 可查完整名)。
* 签名套件本体(profile + p12)在打包机的仓库外目录,不入仓。
- * @param {{ authRegion?: string, iosSigning?: { teamId?: string, profileName?: string, signIdentity?: string, profilePath?: string } }} regionConfig
- * @returns {{ teamId: string, profileName: string, identity: string, profilePath: string }}
+ * exportMethod 可选:xcodebuild -exportArchive 的分发方式,白名单校验,留空默认
+ * development(与旧发布线一致,产物交发布方重签)。
+ * @param {{ authRegion?: string, iosSigning?: { teamId?: string, profileName?: string, signIdentity?: string, profilePath?: string, exportMethod?: string } }} regionConfig
+ * @returns {{ teamId: string, profileName: string, identity: string, profilePath: string, exportMethod: string }}
*/
export function resolveIosSigningEnv(regionConfig) {
const s = regionConfig?.iosSigning ?? {};
@@ -153,6 +158,12 @@ export function resolveIosSigningEnv(regionConfig) {
const profileName = String(s.profileName ?? '').trim();
const identity = String(s.signIdentity ?? '').trim();
const profilePath = String(s.profilePath ?? '').trim();
+ const exportMethod = String(s.exportMethod ?? '').trim() || 'development';
+ if (!IOS_EXPORT_METHODS.includes(exportMethod)) {
+ throw new Error(
+ `self-host-regions.json 的 ${region}.iosSigning.exportMethod 只能是 ${IOS_EXPORT_METHODS.join(' / ')}(留空默认 development),收到 ${JSON.stringify(exportMethod)}`,
+ );
+ }
const missing = [];
if (!teamId) missing.push('teamId');
if (!profileName) missing.push('profileName');
@@ -171,7 +182,7 @@ export function resolveIosSigningEnv(regionConfig) {
`self-host-regions.json 的 ${region}.iosSigning.signIdentity 必须是完整证书名(形如 "Apple Development: 姓名 (TEAMID)",末尾括号 ID 不能省)或 40 位 SHA-1,收到 ${JSON.stringify(identity)}——裸类型名/部分名对 xcodebuild 是自动选择器或模糊匹配,多证书钥匙串下钉不住证书(完整名用 security find-identity -v -p codesigning 查)`,
);
}
- return { teamId, profileName, identity, profilePath };
+ return { teamId, profileName, identity, profilePath, exportMethod };
}
/** plist <string> 值的 XML 转义(证书名等来自配置的外部输入,防意外特殊字符产出坏 plist)。 */
diff --git a/apps/mobile/scripts/lib/self-host-region.mjs b/apps/mobile/scripts/lib/self-host-region.mjs
index 3a2165be74..182ae3b7cd 100644
--- a/apps/mobile/scripts/lib/self-host-region.mjs
+++ b/apps/mobile/scripts/lib/self-host-region.mjs
@@ -249,6 +249,29 @@ export function resolveSelfHostRegion(args, options = {}) {
return block;
}
+/**
+ * selfhost 构建(EXPO_PUBLIC_XDT_OTA_SELFHOST=1 的 prebuild)在 app.config.js 装载
+ * region 配置时硬校验的烘焙字段:TapDB 两字段全区域必填(防漏填统计静默发出无统计
+ * 正式包),global 另需 google 三字段(Google 登录)。返回缺失字段名列表(空数组 =
+ * 齐全),供纯构建脚本 dry-run 预告、--execute 在 prebuild 前 fail-fast;校验口径以
+ * apps/mobile/app.config.js 的 loadRegionBuildConfig 为准,此处只查非空,格式校验
+ * (google client id 后缀 / iosUrlScheme 反写)仍由 app.config.js 把关。
+ */
+export function missingSelfHostBakeFields(regionConfig) {
+ const missing = [];
+ const tapdb = regionConfig?.tapdb ?? {};
+ for (const key of REQUIRED_TAPDB_KEYS) {
+ if (!String(tapdb[key] ?? '').trim()) missing.push(`tapdb.${key}`);
+ }
+ if (regionConfig?.authRegion === 'global') {
+ const google = regionConfig?.google ?? {};
+ for (const key of REQUIRED_GOOGLE_KEYS) {
+ if (!String(google[key] ?? '').trim()) missing.push(`google.${key}`);
+ }
+ }
+ return missing;
+}
+
/**
* 判定 iOS 自建 canary 冷更的安装入口模式(显式配置优先):
* - iosAppStoreId 是纯数字(任何 region)→ App Store 模式,record 写商店网页 + deep link;
diff --git a/apps/mobile/scripts/self-host-regions.json.example b/apps/mobile/scripts/self-host-regions.json.example
index 440404fe96..3407e0c9c8 100644
--- a/apps/mobile/scripts/self-host-regions.json.example
+++ b/apps/mobile/scripts/self-host-regions.json.example
@@ -20,7 +20,8 @@
"teamId": "",
"profileName": "",
"signIdentity": "",
- "profilePath": ""
+ "profilePath": "",
+ "exportMethod": ""
},
"androidSigning": {
"keyAlias": "",
@@ -53,7 +54,8 @@
"teamId": "",
"profileName": "",
"signIdentity": "",
- "profilePath": ""
+ "profilePath": "",
+ "exportMethod": ""
},
"androidSigning": {
"keyAlias": "",
@@ -81,7 +83,8 @@
"teamId": "",
"profileName": "",
"signIdentity": "",
- "profilePath": ""
+ "profilePath": "",
+ "exportMethod": ""
},
"androidSigning": {
"keyAlias": "",
diff --git a/apps/mobile/src/__tests__/iosLocal.test.ts b/apps/mobile/src/__tests__/iosLocal.test.ts
index 7e44dd77db..d36cbc66c1 100644
--- a/apps/mobile/src/__tests__/iosLocal.test.ts
+++ b/apps/mobile/src/__tests__/iosLocal.test.ts
@@ -61,9 +61,10 @@ describe('resolveIosSigningEnv(从 region JSON 的 iosSigning 取值,非机密
iosSigning: { teamId: 'TEAM123456', profileName: 'some_profile', signIdentity: FULL_IDENTITY },
};
const withSigning = (patch) => ({ ...REGION, iosSigning: { ...REGION.iosSigning, ...patch } });
- it('三项齐全 → 透传;profilePath 可选缺省为空串', () => {
+ it('三项齐全 → 透传;profilePath 可选缺省为空串,exportMethod 缺省 development', () => {
expect(resolveIosSigningEnv(REGION)).toEqual({
teamId: 'TEAM123456', profileName: 'some_profile', identity: FULL_IDENTITY, profilePath: '',
+ exportMethod: 'development',
});
expect(resolveIosSigningEnv(withSigning({ profilePath: '/tmp/p.mobileprovision' })).profilePath)
.toBe('/tmp/p.mobileprovision');
@@ -91,6 +92,16 @@ describe('resolveIosSigningEnv(从 region JSON 的 iosSigning 取值,非机密
const sha1 = 'A1B2C3D4E5F60718293A4B5C6D7E8F9012345678';
expect(resolveIosSigningEnv(withSigning({ signIdentity: sha1 })).identity).toBe(sha1);
});
+ it('exportMethod 留空 → development;白名单值透传', () => {
+ expect(resolveIosSigningEnv(withSigning({ exportMethod: '' })).exportMethod).toBe('development');
+ expect(resolveIosSigningEnv(withSigning({ exportMethod: 'enterprise' })).exportMethod).toBe('enterprise');
+ expect(resolveIosSigningEnv(withSigning({ exportMethod: 'app-store' })).exportMethod).toBe('app-store');
+ expect(resolveIosSigningEnv(withSigning({ exportMethod: 'ad-hoc' })).exportMethod).toBe('ad-hoc');
+ });
+ it('exportMethod 非白名单值 → 拒(防拼错被 xcodebuild 晚期才报)', () => {
+ expect(() => resolveIosSigningEnv(withSigning({ exportMethod: 'adhoc' }))).toThrow(/exportMethod/);
+ expect(() => resolveIosSigningEnv(withSigning({ exportMethod: 'AppStore' }))).toThrow(/exportMethod/);
+ });
});
describe('buildExportOptionsPlist', () => {
@@ -124,6 +135,13 @@ describe('buildExportOptionsPlist', () => {
it('缺参抛错', () => {
expect(() => buildExportOptionsPlist({ teamId: 'x', bundleId: 'y' })).toThrow();
});
+ it('传 method 时使用指定分发方式(纯构建 exportMethod 直通)', () => {
+ const plist = buildExportOptionsPlist({
+ teamId: 'TEAMID1234', bundleId: 'com.xd.cindycn', profileName: 'cindycn_dist', method: 'enterprise',
+ });
+ expect(plist).toContain('<string>enterprise</string>');
+ expect(plist).not.toContain('<string>development</string>');
+ });
});
describe('buildReleaseRecord', () => {
diff --git a/apps/mobile/src/__tests__/selfHostRegion.test.ts b/apps/mobile/src/__tests__/selfHostRegion.test.ts
index 6bb47fa26a..30a1d93c73 100644
--- a/apps/mobile/src/__tests__/selfHostRegion.test.ts
+++ b/apps/mobile/src/__tests__/selfHostRegion.test.ts
@@ -8,6 +8,7 @@ import {
regionEnvOverrides,
formatSelfHostReleaseCommand,
assertRegionOssComplete,
+ missingSelfHostBakeFields,
resolveIosInstallEntryMode,
stripSelfHostRegionEnv,
} from '../../scripts/lib/self-host-region.mjs';
@@ -278,6 +279,30 @@ describe('assertRegionOssComplete', () => {
});
});
+describe('missingSelfHostBakeFields(selfhost prebuild 硬校验字段自查)', () => {
+ it('tapdb 齐全 → cn/global 均无缺失', () => {
+ const v = clone();
+ expect(missingSelfHostBakeFields(v.cn)).toEqual([]);
+ expect(missingSelfHostBakeFields(v.global)).toEqual([]);
+ });
+ it('tapdb 留空 → 逐项点名(全区域一致,dev 也不例外)', () => {
+ const v = clone();
+ expect(missingSelfHostBakeFields(v.dev)).toEqual(['tapdb.clientId', 'tapdb.clientToken']);
+ v.cn.tapdb.clientToken = ' ';
+ expect(missingSelfHostBakeFields(v.cn)).toEqual(['tapdb.clientToken']);
+ });
+ it('global 缺 google → 点名 google.*;cn 不要求 google', () => {
+ const v = clone();
+ v.global.google = { webClientId: '', iosClientId: '', iosUrlScheme: '' };
+ expect(missingSelfHostBakeFields(v.global)).toEqual([
+ 'google.webClientId',
+ 'google.iosClientId',
+ 'google.iosUrlScheme',
+ ]);
+ expect(missingSelfHostBakeFields(v.cn)).toEqual([]);
+ });
+});
+
describe('resolveIosInstallEntryMode', () => {
it('配了纯数字 App Store ID(任何 region)→ appstore 模式', () => {
expect(resolveIosInstallEntryMode(VALID.cn)).toEqual({ mode: 'appstore', appStoreId: '6788711632' });