@tbox.cn/app-module-mall-core 0.3.0 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -157,10 +157,12 @@ function createScopeAssembly(raw, ctx) {
157
157
  }
158
158
  };
159
159
  }
160
+ function resolveMallMiniAppId(controlPlane, rootMiniAppId, mallId) {
161
+ return rootMiniAppId ?? controlPlane.malls.find((m) => m.mallId === mallId)?.miniAppId;
162
+ }
160
163
  function buildDefaultMallContext(controlPlane, rootMiniAppId) {
161
164
  if (!controlPlane.defaultMallId) return void 0;
162
- const mall = controlPlane.malls.find((m) => m.mallId === controlPlane.defaultMallId);
163
- const miniAppId = rootMiniAppId ?? mall?.miniAppId;
165
+ const miniAppId = resolveMallMiniAppId(controlPlane, rootMiniAppId, controlPlane.defaultMallId);
164
166
  if (!miniAppId) {
165
167
  deploymentLogger.warn(
166
168
  `defaultMallId=${controlPlane.defaultMallId} \u65E0 miniAppId \u771F\u6E90\uFF08root config \u4E0E\u53C2\u8003\u8868\u53CC\u7F3A\uFF09\u2014\u2014\u6309 mallId-only \u6CE8\u5165\u9ED8\u8BA4\u5546\u5708`
@@ -230,6 +232,7 @@ import { createLogger as createLogger4, getRequestContext } from "@tbox.cn/app-a
230
232
  import {
231
233
  MEMBER_SNAPSHOT_SERVICE,
232
234
  PARKING_SNAPSHOT_SERVICE,
235
+ mallScopeOrEmpty,
233
236
  withMallScopeFromQuery
234
237
  } from "@tbox.cn/app-contracts-mall";
235
238
 
@@ -378,13 +381,12 @@ function createMallHomeRouter(ctx) {
378
381
  res.json({ member: null, parking: { status: "unavailable" } });
379
382
  return;
380
383
  }
381
- const mallMiniAppId = resolveMallScopeAssembly(ctx)?.rootMiniAppId ?? resolveMallScopeAssembly(ctx)?.controlPlane.malls.find((m) => m.mallId === mallId)?.miniAppId;
384
+ const assembly = resolveMallScopeAssembly(ctx);
385
+ const mallMiniAppId = assembly ? resolveMallMiniAppId(assembly.controlPlane, assembly.rootMiniAppId, mallId) : void 0;
382
386
  if (!mallMiniAppId) {
383
387
  serverLogger.warn(
384
- `[MALL] linked-panel mallId=${mallId} \u65E0 miniAppId \u771F\u6E90\uFF08root config \u4E0E malls \u8868\u53CC\u7F3A\uFF09\u2014\u2014\u4E1A\u52A1\u69FD\u9A8C\u7B7E\u5C06\u5931\u8D25\uFF08\u62D2\u7EDD\u6CE8\u5165\u5047\u503C\uFF09`
388
+ `[MALL] linked-panel mallId=${mallId} \u65E0 miniAppId \u771F\u6E90\uFF08root config \u4E0E malls \u8868\u53CC\u7F3A\uFF09\u2014\u2014\u6309 mallId-only \u964D\u7EA7\u7EE7\u7EED`
385
389
  );
386
- res.json({ member: null, parking: { status: "error" } });
387
- return;
388
390
  }
389
391
  const reqCtxWithMall = withMallScopeFromQuery(authCtx, req.query, { miniAppId: mallMiniAppId });
390
392
  const [memberResult, parkingResult] = await Promise.allSettled([
@@ -427,7 +429,7 @@ function createMallHomeRouter(ctx) {
427
429
  });
428
430
  if (!service) return { status: "error" };
429
431
  const query = {
430
- scope: { mallId, miniAppId: mallMiniAppId },
432
+ scope: mallScopeOrEmpty(reqCtxWithMall),
431
433
  requestContext: reqCtxWithMall
432
434
  };
433
435
  return loadLinkedPanelParking(service, query, async () => {
@@ -128,6 +128,9 @@ async function fetchLinkedPanelState(token, mallId, fetcher = fetch, signal) {
128
128
  }
129
129
  }
130
130
  var MALL_CORE_API = "/api/m/mall-core";
131
+ function pickMallId(helloMallId, urlMallId) {
132
+ return helloMallId ?? urlMallId;
133
+ }
131
134
  async function fetchLinkedOrderState(token, fetcher = fetch, signal) {
132
135
  if (!token) return { status: "unauthenticated" };
133
136
  try {
@@ -1210,16 +1213,24 @@ function createMemberGate(deps) {
1210
1213
  return;
1211
1214
  }
1212
1215
  } else {
1216
+ const judgeMallId = deps.readMallId();
1213
1217
  let panel;
1214
1218
  try {
1215
- panel = await deps.loadPanel(deps.readMallId());
1219
+ panel = await deps.loadPanel(judgeMallId);
1216
1220
  } catch {
1217
1221
  if (flightSeq !== myFlight) return;
1222
+ log(`judge panel-throw mallId=${judgeMallId ?? "none"}`);
1218
1223
  setState({ phase: "failed", message: GATE_PANEL_FAILED });
1219
1224
  return;
1220
1225
  }
1221
1226
  if (flightSeq !== myFlight) return;
1222
- upgraded = identityOk && panel.member.status === "active";
1227
+ const panelStatus = panel.member.status;
1228
+ log(`judge panel status=${panelStatus} mallId=${judgeMallId ?? "none"}`);
1229
+ if (panelStatus === "unavailable" || panelStatus === "error" || panelStatus === "unknown" || panelStatus === "unauthenticated") {
1230
+ setState({ phase: "failed", message: GATE_PANEL_FAILED });
1231
+ return;
1232
+ }
1233
+ upgraded = identityOk && panelStatus === "active";
1223
1234
  }
1224
1235
  log(`judge ${upgraded ? "active" : "not-enrolled"}`);
1225
1236
  if (upgraded) {
@@ -1340,7 +1351,6 @@ function mapDirectEnrollReceipt(status) {
1340
1351
  if (status === 200) return { loginStatus: "success", message: "\u767B\u5F55\u6210\u529F" };
1341
1352
  if (status === 401) return { loginStatus: "fail", message: "\u8BF7\u5148\u767B\u5F55" };
1342
1353
  if (status === 404) return { loginStatus: "fail", message: "\u5F53\u524D\u73AF\u5883\u672A\u63D0\u4F9B\u5165\u4F1A\u670D\u52A1\uFF0C\u8BF7\u5728\u652F\u4ED8\u5B9D\u5C0F\u7A0B\u5E8F\u5185\u6253\u5F00" };
1343
- if (status === 503) return { loginStatus: "fail", message: "\u6F14\u793A\u5165\u4F1A\u4EC5\u9650\u975E\u751F\u4EA7\u73AF\u5883" };
1344
1354
  return { loginStatus: "fail", message: "\u767B\u5F55\u72B6\u6001\u540C\u6B65\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5" };
1345
1355
  }
1346
1356
  async function directLoginGate() {
@@ -1371,7 +1381,7 @@ function HomeSlotContent({ onSend, mallName }) {
1371
1381
  const retryBootstrap = useChatStore((s) => s.retryBootstrap);
1372
1382
  const isGenerating = useChatStore((s) => s.isGenerating);
1373
1383
  const helloMallId = useChatStore((s) => s.helloAck?.mallScope?.mallId);
1374
- const mallId = helloMallId ?? readMallIdFromUrl();
1384
+ const mallId = pickMallId(helloMallId, readMallIdFromUrl());
1375
1385
  const [linkedOrder, setLinkedOrder] = useState3({ status: "loading" });
1376
1386
  const [linkedOrderReloadEpoch, setLinkedOrderReloadEpoch] = useState3(0);
1377
1387
  const [member, setMember] = useState3({ status: "loading" });
@@ -1409,7 +1419,7 @@ function HomeSlotContent({ onSend, mallName }) {
1409
1419
  }
1410
1420
  return null;
1411
1421
  },
1412
- readMallId: () => readMallIdFromUrl(),
1422
+ readMallId: () => pickMallId(store.getState().helloAck?.mallScope?.mallId, readMallIdFromUrl()),
1413
1423
  refreshPanel: () => setLinkedPanelReloadEpoch((epoch) => epoch + 1),
1414
1424
  log: (message) => {
1415
1425
  gateLogger.info(message);
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  clientModule,
3
3
  client_default
4
- } from "../chunk-VA2ROMX7.js";
4
+ } from "../chunk-FATH6I75.js";
5
5
  export {
6
6
  clientModule,
7
7
  client_default as default
package/dist/index.js CHANGED
@@ -9,10 +9,10 @@ import {
9
9
  resolveMallInfo,
10
10
  resolveMallScopeAssembly,
11
11
  serverModule
12
- } from "./chunk-LJJTKND6.js";
12
+ } from "./chunk-B7ZAK6VM.js";
13
13
  import {
14
14
  clientModule
15
- } from "./chunk-VA2ROMX7.js";
15
+ } from "./chunk-FATH6I75.js";
16
16
  export {
17
17
  bindMallInfoContext,
18
18
  buildDefaultMallContext,
@@ -39,9 +39,8 @@ declare function createScopeAssembly(raw: IntegrationsRaw | undefined, ctx: Serv
39
39
  /**
40
40
  * 016:默认商圈 HELLO context(无 URL 参数访问时的服务端兜底)。
41
41
  * v4 mallId-only 注入(D8/D9):miniAppId 是尽力回填的展示值,非会话边界——
42
- * 读源统一 root config.miniAppId 优先、回落参考表 attributes.miniAppId;双缺不再
43
- * 阻断注入(此前 warn-refuse 会造成默认商圈静默失效),按 mallId-only 注入。
44
- * 缺省 defaultMallId → undefined(不兜底)。
42
+ * 读源统一经 resolveMallMiniAppId 单点;双缺不再阻断注入(此前 warn-refuse 会造成
43
+ * 默认商圈静默失效),按 mallId-only 注入。缺省 defaultMallId → undefined(不兜底)。
45
44
  */
46
45
  declare function buildDefaultMallContext(controlPlane: MallDeploymentControlPlane, rootMiniAppId?: string): Record<string, unknown> | undefined;
47
46
 
@@ -10,7 +10,7 @@ import {
10
10
  resolveMallScopeAssembly,
11
11
  serverModule,
12
12
  server_default
13
- } from "../chunk-LJJTKND6.js";
13
+ } from "../chunk-B7ZAK6VM.js";
14
14
  export {
15
15
  bindMallInfoContext,
16
16
  buildDefaultMallContext,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-module-mall-core",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "description": "商圈基础模块:scope 域装配注册 + mall-info 工具链 + mall-directory 服务 + 首页主屏(home 槽 / 联单面板 / 会员停车快览)+ 首页预览卡。",
6
6
  "exports": {
@@ -271,6 +271,19 @@ export async function fetchParkingState(
271
271
  /** 商圈基础首页面 API 命名空间(server 端 ctx.routes.register('mall-core') 挂载位——改名单点) */
272
272
  export const MALL_CORE_API = '/api/m/mall-core';
273
273
 
274
+ /**
275
+ * mallId 单一读源(面板与门禁 judge 共用;hello 优先单测锁序):
276
+ * HELLO_ACK mallScope 是服务端确认的会话 scope(URL 无 mallId 的部署经服务端
277
+ * defaultContext 下发),URL 是握手前兜底——两处消费必须同源同序,否则 judge 判定
278
+ * 的 mall 与面板展示的 mall 可能分叉。
279
+ */
280
+ export function pickMallId(
281
+ helloMallId: string | null | undefined,
282
+ urlMallId: string | null,
283
+ ): string | null {
284
+ return helloMallId ?? urlMallId;
285
+ }
286
+
274
287
  /** 将首页 HTTP 返回收敛为联单加载态,便于对鉴权、空活动与异常分别回归。 */
275
288
  export async function fetchLinkedOrderState(
276
289
  token: string | null | undefined,
@@ -20,6 +20,7 @@ import {
20
20
  loadHomeConfig,
21
21
  loadLinkedPanelState,
22
22
  loadLinkedOrderState,
23
+ pickMallId,
23
24
  } from './home-runtime';
24
25
  import type { HomeConfig, LinkedOrderLoadState, MemberLoadState, ParkingLoadState } from './home-runtime';
25
26
  import './home-slot.less';
@@ -47,7 +48,9 @@ function HomeSlotContent({ onSend, mallName }: HomeSlotRenderProps) {
47
48
  // createConversation + WS HELLO 握手;URL 缺席回退 HELLO_ACK(原逻辑不变)。HELLO 后到且值不同时,
48
49
  // 面板 effect 依赖 mallId 自动重载(以 HELLO 为准,旧请求经 AbortController 中止)。
49
50
  const helloMallId = useChatStore((s) => s.helloAck?.mallScope?.mallId);
50
- const mallId = helloMallId ?? readMallIdFromUrl();
51
+ // 与 gate judge readMallId 同源同序(pickMallId 单源):HELLO 到达后以其为准(服务端确认 scope),
52
+ // 握手前 helloAck 缺席 → URL 兜底,挂载即可发、免等握手
53
+ const mallId = pickMallId(helloMallId, readMallIdFromUrl());
51
54
 
52
55
  const [linkedOrder, setLinkedOrder] = useState<LinkedOrderLoadState>({ status: 'loading' });
53
56
  const [linkedOrderReloadEpoch, setLinkedOrderReloadEpoch] = useState(0);
@@ -92,7 +95,8 @@ function HomeSlotContent({ onSend, mallName }: HomeSlotRenderProps) {
92
95
  }
93
96
  return null;
94
97
  },
95
- readMallId: () => readMallIdFromUrl(),
98
+ readMallId: () =>
99
+ pickMallId(store.getState().helloAck?.mallScope?.mallId, readMallIdFromUrl()),
96
100
  refreshPanel: () => setLinkedPanelReloadEpoch((epoch) => epoch + 1),
97
101
  log: (message) => {
98
102
  gateLogger.info(message);
@@ -60,7 +60,8 @@ export interface MemberGateDeps {
60
60
  toast(content: string): void;
61
61
  isGenerating(): boolean;
62
62
  lastUserMessage(): { id: string; content: string } | null;
63
- /** mallId 直读(URL query,与 configureHelloContext 同源;不依赖重连后才回填的 helloAck) */
63
+ /** mallId 读源(装配方注入;与首页面板同源同序 pickMallId:HELLO_ACK 优先 + URL 兜底)。
64
+ * 消费方 = 入会轴 judge(retryBootstrap 之后,HELLO_ACK 已在 store——活读安全) */
64
65
  readMallId(): string | null;
65
66
  /** 升级成功后刷新首页面板(bumpEpoch) */
66
67
  refreshPanel(): void;
@@ -123,7 +124,8 @@ export function createMemberGate(deps: MemberGateDeps): MemberGate {
123
124
  let pendingReplay: PendingReplay | null = null;
124
125
  /** 飞行序号:dismiss 不中止升级,新一轮 confirm/retry 递增后旧流程让位 */
125
126
  let flightSeq = 0;
126
- /** 排障五锚:open(source)/receipt(loginStatus)/relogin(ok|fail)/judge(active|not-enrolled)/replay(sent|skipped:reason) */
127
+ /** 排障五锚:open(source)/receipt(loginStatus)/relogin(ok|fail)/judge(active|not-enrolled)/replay(sent|skipped:reason);
128
+ * judge 锚前另附明细行 judge panel status=<x> mallId=<y>(面板真值与判定读源,排障先看它) */
127
129
  const log = (message: string): void => {
128
130
  deps.log?.(message);
129
131
  };
@@ -201,18 +203,33 @@ export function createMemberGate(deps: MemberGateDeps): MemberGate {
201
203
  return;
202
204
  }
203
205
  } else {
204
- // 入会轴:非匿名 ∧ 面板 member.active(原语义不变)+ loadPanel 兜底
205
- // (注入方不吞错误——既有缺陷顺手修:面板失败不再让 Sheet 卡 syncing)
206
+ // 入会轴:非匿名 ∧ 面板 member.active。面板状态全谱分类(MemberLoadState):
207
+ // active → settle;not_enrolled/closed → 确认未入会(not-enrolled 态,重开完整 gate);
208
+ // unknown/unavailable/error/unauthenticated → 查询失败 ≠ 确认未入会 → failed
209
+ // (GATE_PANEL_FAILED,retry 仅重跑冷登+判定)——不再把同步失败误报成「尚未完成入会」。
210
+ const judgeMallId = deps.readMallId();
206
211
  let panel: { member: { status: string } };
207
212
  try {
208
- panel = await deps.loadPanel(deps.readMallId());
213
+ panel = await deps.loadPanel(judgeMallId);
209
214
  } catch {
210
215
  if (flightSeq !== myFlight) return;
216
+ log(`judge panel-throw mallId=${judgeMallId ?? 'none'}`);
211
217
  setState({ phase: 'failed', message: GATE_PANEL_FAILED });
212
218
  return;
213
219
  }
214
220
  if (flightSeq !== myFlight) return;
215
- upgraded = identityOk && panel.member.status === 'active';
221
+ const panelStatus = panel.member.status;
222
+ log(`judge panel status=${panelStatus} mallId=${judgeMallId ?? 'none'}`);
223
+ if (
224
+ panelStatus === 'unavailable'
225
+ || panelStatus === 'error'
226
+ || panelStatus === 'unknown'
227
+ || panelStatus === 'unauthenticated'
228
+ ) {
229
+ setState({ phase: 'failed', message: GATE_PANEL_FAILED });
230
+ return;
231
+ }
232
+ upgraded = identityOk && panelStatus === 'active';
216
233
  }
217
234
  log(`judge ${upgraded ? 'active' : 'not-enrolled'}`);
218
235
  if (upgraded) {
@@ -28,7 +28,6 @@ export function mapDirectEnrollReceipt(status: number): LoginGateReceipt {
28
28
  if (status === 200) return { loginStatus: 'success', message: '登录成功' };
29
29
  if (status === 401) return { loginStatus: 'fail', message: '请先登录' };
30
30
  if (status === 404) return { loginStatus: 'fail', message: '当前环境未提供入会服务,请在支付宝小程序内打开' };
31
- if (status === 503) return { loginStatus: 'fail', message: '演示入会仅限非生产环境' };
32
31
  return { loginStatus: 'fail', message: '登录状态同步失败,请重试' };
33
32
  }
34
33
 
@@ -136,20 +136,32 @@ export function createScopeAssembly(
136
136
  } satisfies MallScopeAssembly;
137
137
  }
138
138
 
139
+ /**
140
+ * mall miniAppId 读源单点:root config.miniAppId 优先 → 参考表按 mallId 查;双缺 → undefined。
141
+ * 软依赖契约(v4 D9):miniAppId 是尽力回填的展示/定位值,非会话边界——双缺由调用方按
142
+ * mallId-only 降级(消费点自补语义,见 contracts-mall createMallContextValidator 注释)。
143
+ * 严禁任何假值注入(09-01 事故防线:回退假字面量致真实档业务槽验签 appId 恒假 → 网关 401)。
144
+ */
145
+ export function resolveMallMiniAppId(
146
+ controlPlane: MallDeploymentControlPlane,
147
+ rootMiniAppId: string | undefined,
148
+ mallId: string,
149
+ ): string | undefined {
150
+ return rootMiniAppId ?? controlPlane.malls.find((m) => m.mallId === mallId)?.miniAppId;
151
+ }
152
+
139
153
  /**
140
154
  * 016:默认商圈 HELLO context(无 URL 参数访问时的服务端兜底)。
141
155
  * v4 mallId-only 注入(D8/D9):miniAppId 是尽力回填的展示值,非会话边界——
142
- * 读源统一 root config.miniAppId 优先、回落参考表 attributes.miniAppId;双缺不再
143
- * 阻断注入(此前 warn-refuse 会造成默认商圈静默失效),按 mallId-only 注入。
144
- * 缺省 defaultMallId → undefined(不兜底)。
156
+ * 读源统一经 resolveMallMiniAppId 单点;双缺不再阻断注入(此前 warn-refuse 会造成
157
+ * 默认商圈静默失效),按 mallId-only 注入。缺省 defaultMallId → undefined(不兜底)。
145
158
  */
146
159
  export function buildDefaultMallContext(
147
160
  controlPlane: MallDeploymentControlPlane,
148
161
  rootMiniAppId?: string,
149
162
  ): Record<string, unknown> | undefined {
150
163
  if (!controlPlane.defaultMallId) return undefined;
151
- const mall = controlPlane.malls.find((m) => m.mallId === controlPlane.defaultMallId);
152
- const miniAppId = rootMiniAppId ?? mall?.miniAppId;
164
+ const miniAppId = resolveMallMiniAppId(controlPlane, rootMiniAppId, controlPlane.defaultMallId);
153
165
  if (!miniAppId) {
154
166
  deploymentLogger.warn(
155
167
  `defaultMallId=${controlPlane.defaultMallId} 无 miniAppId 真源(root config 与参考表双缺)——按 mallId-only 注入默认商圈`,
@@ -17,13 +17,14 @@ import type { PromotionActivityDetail, PromotionQueryContext } from '@tbox.cn/ap
17
17
  import {
18
18
  MEMBER_SNAPSHOT_SERVICE,
19
19
  PARKING_SNAPSHOT_SERVICE,
20
+ mallScopeOrEmpty,
20
21
  withMallScopeFromQuery,
21
22
  } from '@tbox.cn/app-contracts-mall';
22
23
  import type {
23
24
  MemberSnapshotFactory,
24
25
  ParkingSnapshotFactory,
25
26
  } from '@tbox.cn/app-contracts-mall';
26
- import { resolveMallScopeAssembly } from './assembly.js';
27
+ import { resolveMallMiniAppId, resolveMallScopeAssembly } from './assembly.js';
27
28
  import { loadBumpinPorts } from './module-ports.js';
28
29
  import {
29
30
  buildLinkedPanelParking,
@@ -79,18 +80,19 @@ router.get('/linked-panel', async (req, res) => {
79
80
 
80
81
  // mallId 注入经 TIER1 唯一写入口(query 契约键 + opts.miniAppId 兜底),使
81
82
  // resolveMember*Port/resolveParkingQueryPort 能正常取到 mall scope
82
- // miniAppId 读源统一(对齐 WS enhanceContext):root config.miniAppId 优先 → malls[] 按 mallId 查;
83
- // 双缺(root 无 miniAppId 且动态 mall 无表可查)→ fail-fast 显性暴露——绝不回退假值
84
- // (曾回退字面量 'linked-panel' 致业务槽验签 appId 恒假 → 网关 401)
85
- const mallMiniAppId =
86
- resolveMallScopeAssembly(ctx)?.rootMiniAppId ??
87
- resolveMallScopeAssembly(ctx)?.controlPlane.malls.find((m) => m.mallId === mallId)?.miniAppId;
83
+ // miniAppId 读源单点(对齐 WS enhanceContext)= resolveMallMiniAppId(root config 优先 →
84
+ // 参考表按 mallId 查);双缺按 mallId-only 降级继续(v4 D9:miniAppId 是尽力回填的展示值,
85
+ // 非会话边界——与 HELLO defaultMallContext 同语义)。绝不注入假值(09-01 事故防线保留):
86
+ // 真实档加签读源 scope ?? config(如 wanda-headers),scope 缺席回落部署 config,无假值消费面。
87
+ // (曾回退字面量 'linked-panel' 属假值注入——与本降级有本质区别,仍被禁止)
88
+ const assembly = resolveMallScopeAssembly(ctx);
89
+ const mallMiniAppId = assembly
90
+ ? resolveMallMiniAppId(assembly.controlPlane, assembly.rootMiniAppId, mallId)
91
+ : undefined;
88
92
  if (!mallMiniAppId) {
89
93
  serverLogger.warn(
90
- `[MALL] linked-panel mallId=${mallId} 无 miniAppId 真源(root config 与 malls 表双缺)——业务槽验签将失败(拒绝注入假值)`,
94
+ `[MALL] linked-panel mallId=${mallId} 无 miniAppId 真源(root config 与 malls 表双缺)——按 mallId-only 降级继续`,
91
95
  );
92
- res.json({ member: null, parking: { status: 'error' } satisfies LinkedPanelParking });
93
- return;
94
96
  }
95
97
  const reqCtxWithMall = withMallScopeFromQuery(authCtx, req.query, { miniAppId: mallMiniAppId });
96
98
 
@@ -136,9 +138,11 @@ router.get('/linked-panel', async (req, res) => {
136
138
  });
137
139
  if (!service) return { status: 'error' } satisfies LinkedPanelParking;
138
140
 
139
- // listVehicles 需完整 ParkingQueryContext(scope + requestContext;userId 经 requestContext 传递)
141
+ // listVehicles 需完整 ParkingQueryContext(scope + requestContext;userId 经 requestContext 传递)。
142
+ // scope 回读 attributes(mallScopeOrEmpty)——与写入单源(withMallScopeFromQuery)恒一致,
143
+ // 消灭手拼 scope 与 session scope 的来源分叉(query.miniAppId 透传优先语义)
140
144
  const query = {
141
- scope: { mallId, miniAppId: mallMiniAppId },
145
+ scope: mallScopeOrEmpty(reqCtxWithMall),
142
146
  requestContext: reqCtxWithMall,
143
147
  };
144
148
  // 凭证不足以查车时由 provider 的 requiresMembership 能力口收口(未声明该口即照常查询)
@@ -13,6 +13,7 @@ import {
13
13
  parseBumpInDetailCard,
14
14
  parseMemberState,
15
15
  parseParkingState,
16
+ pickMallId,
16
17
  shouldAutoScrollConversation,
17
18
  shouldReleaseHistoryAnchorReserve,
18
19
  shouldShowHistoryEntry,
@@ -20,6 +21,28 @@ import {
20
21
  shouldShowScrollControl,
21
22
  } from '../src/client/home-runtime';
22
23
 
24
+ describe('pickMallId(面板与门禁 judge 单一读源)', () => {
25
+ it('hello 优先锁序:服务端确认 scope 恒赢 URL 兜底', () => {
26
+ expect(pickMallId('mall-hello', 'mall-url')).toBe('mall-hello');
27
+ });
28
+
29
+ it('URL 无 mallId 的部署(mallId 经 HELLO defaultContext 下发)→ 回退 hello', () => {
30
+ expect(pickMallId('mall-hello', null)).toBe('mall-hello');
31
+ });
32
+
33
+ it('握手前(helloAck 缺席)→ URL 兜底', () => {
34
+ expect(pickMallId(undefined, 'mall-url')).toBe('mall-url');
35
+ expect(pickMallId(null, 'mall-url')).toBe('mall-url');
36
+ });
37
+
38
+ it('双缺 → null(面板保持 loading,不误投影服务不可用)', () => {
39
+ expect(pickMallId(null, null)).toBeNull();
40
+ expect(pickMallId(undefined, null)).toBeNull();
41
+ // nullish 语义(?? 与原面板行为逐字一致):仅 null/undefined 回退;URL 读源恒不产空串
42
+ expect(pickMallId(undefined, '')).toBe('');
43
+ });
44
+ });
45
+
23
46
  describe('member panel state', () => {
24
47
  it('严格区分登录与会员状态,并只接受真实非负积分', () => {
25
48
  expect(parseMemberState({ authState: 'unauthenticated', state: 'unknown' }))
@@ -0,0 +1,116 @@
1
+ // @vitest-environment node
2
+ /**
3
+ * linked-panel miniAppId 软依赖降级(v4 D9 语义收口):
4
+ * miniAppId 读源双缺(root config 与参考表双缺)→ warn 留痕 + mallId-only 降级继续,
5
+ * 会员/停车照常投影——mock/演示档首页双卡不再因配置缺元数据全灭
6
+ * (回归背景:2026-09-18 N-01 同症 + 7e01d1e4 defaultInstanceId=1000001 无表形态复发)。
7
+ * 防线不变式:绝不注入假值(降级 = scope 不带键,真实档加签回落部署 config)。
8
+ */
9
+ import express from 'express';
10
+ import type { Server } from 'node:http';
11
+ import { afterAll, beforeAll, describe, expect, it } from 'vitest';
12
+ import { setRequestContext, type ServerContext } from '@tbox.cn/app-agent-sdk-server';
13
+ import type { RequestContext } from '@tbox.cn/app-contracts';
14
+ import {
15
+ MEMBER_SNAPSHOT_SERVICE,
16
+ PARKING_SNAPSHOT_SERVICE,
17
+ } from '@tbox.cn/app-contracts-mall';
18
+ import { createMallHomeRouter } from '../src/server/routes.js';
19
+
20
+ const observedAt = '2026-09-21T00:00:00.000Z';
21
+
22
+ const memberPort = {
23
+ getAccount: async () => ({ authState: 'authenticated', state: 'not_enrolled', observedAt }),
24
+ queryPoints: async () => ({ userId: 'u1', balance: 0, membershipLabel: '示例会员卡' }),
25
+ enrollUrl: 'alipays://platformapi/startapp?appId=demo&page=v/index/index',
26
+ };
27
+
28
+ const parkingService = {
29
+ listVehicles: async () => ({ bound: [{ plateNo: '京A12345' }] }),
30
+ };
31
+
32
+ function makeCtx(assembly: unknown): ServerContext {
33
+ return {
34
+ domainAssemblies: { resolve: () => assembly },
35
+ resolveService: (service: string) =>
36
+ service === MEMBER_SNAPSHOT_SERVICE
37
+ ? async () => memberPort
38
+ : service === PARKING_SNAPSHOT_SERVICE
39
+ ? async () => parkingService
40
+ : undefined,
41
+ } as unknown as ServerContext;
42
+ }
43
+
44
+ /** 双缺形态:root 无 miniAppId + 参考表空(7e01d1e4 后 mock 档真实形态) */
45
+ const assemblyNoMiniAppId = {
46
+ rootMiniAppId: undefined,
47
+ controlPlane: { malls: [], defaultMallId: 'mall-1' },
48
+ };
49
+
50
+ /** 参考表命中形态:miniAppId 由表供给(回归保护——读源路径不变) */
51
+ const assemblyWithTableHit = {
52
+ rootMiniAppId: undefined,
53
+ controlPlane: {
54
+ malls: [{ mallId: 'mall-1', name: '星河 Mock 小镇', miniAppId: 'tbl-app' }],
55
+ defaultMallId: 'mall-1',
56
+ },
57
+ };
58
+
59
+ const authCtx = { identity: { userId: 'u1', source: 'guest' }, attributes: {} } as unknown as RequestContext;
60
+
61
+ let server: Server;
62
+ let base: string;
63
+
64
+ beforeAll(async () => {
65
+ const app = express();
66
+ app.use('/api/m/mall-core', (req, _res, next) => {
67
+ setRequestContext(req, authCtx);
68
+ next();
69
+ });
70
+ app.use('/api/m/mall-core', createMallHomeRouter(makeCtx(assemblyNoMiniAppId)));
71
+ server = app.listen(0);
72
+ await new Promise<void>((resolve) => server.once('listening', () => resolve()));
73
+ const address = server.address();
74
+ if (!address || typeof address === 'string') throw new Error(`意外地址形态: ${String(address)}`);
75
+ base = `http://127.0.0.1:${address.port}`;
76
+ });
77
+
78
+ afterAll(() => {
79
+ server.close();
80
+ });
81
+
82
+ async function linkedPanel(): Promise<{ status: number; body: { member: unknown; parking: { status: string } } }> {
83
+ const res = await fetch(`${base}/api/m/mall-core/linked-panel?mallId=mall-1`);
84
+ return { status: res.status, body: (await res.json()) as { member: unknown; parking: { status: string } } };
85
+ }
86
+
87
+ describe('linked-panel miniAppId 软依赖降级', () => {
88
+ it('双缺(root 与参考表双缺)→ warn 降级继续:member/parking 照常投影(不再 member:null + parking:error)', async () => {
89
+ const { status, body } = await linkedPanel();
90
+ expect(status).toBe(200);
91
+ expect(body.member).toMatchObject({ authState: 'authenticated', state: 'not_enrolled' });
92
+ expect(body.parking.status).toBe('ready');
93
+ });
94
+
95
+ it('参考表命中(miniAppId 在场)→ 读源路径行为不变', async () => {
96
+ // 单服务器挂双路由不可行(ctx 定型于创建期)——重建独立实例验证命中分支
97
+ const app = express();
98
+ app.use('/api/m/mall-core', (req, _res, next) => {
99
+ setRequestContext(req, authCtx);
100
+ next();
101
+ });
102
+ app.use('/api/m/mall-core', createMallHomeRouter(makeCtx(assemblyWithTableHit)));
103
+ const srv = app.listen(0);
104
+ try {
105
+ const address = srv.address();
106
+ if (!address || typeof address === 'string') throw new Error(`意外地址形态: ${String(address)}`);
107
+ const res = await fetch(`http://127.0.0.1:${address.port}/api/m/mall-core/linked-panel?mallId=mall-1`);
108
+ const body = (await res.json()) as { member: unknown; parking: { status: string } };
109
+ expect(res.status).toBe(200);
110
+ expect(body.member).toMatchObject({ authState: 'authenticated', state: 'not_enrolled' });
111
+ expect(body.parking.status).toBe('ready');
112
+ } finally {
113
+ srv.close();
114
+ }
115
+ });
116
+ });
@@ -86,11 +86,12 @@ describe('createMemberGate(门禁状态机)', () => {
86
86
  expect(h.calls.sendMessage).toHaveBeenCalledWith('查询我的会员积分');
87
87
  expect(h.calls.hideCard).toHaveBeenCalledWith('card-1');
88
88
  expect(h.gate.getState()).toMatchObject({ phase: 'idle', sheetVisible: false });
89
- // 排障五锚:open → receipt → relogin → judge → replay(一条 grep 定位全链)
89
+ // 排障五锚:open → receipt → relogin → judge → replay(一条 grep 定位全链;judge 附面板明细行)
90
90
  expect(h.calls.log.mock.calls.flat()).toEqual([
91
91
  'open source=card',
92
92
  'receipt loginStatus=success',
93
93
  'relogin ok',
94
+ 'judge panel status=active mallId=mall-001',
94
95
  'judge active',
95
96
  'replay sent',
96
97
  ]);
@@ -381,4 +382,43 @@ describe('judge 分轴(SPEC-7:login 卡登录轴 / enroll 卡入会轴)',
381
382
  expect(h.gate.getState()).toMatchObject({ phase: 'failed', message: '会员状态同步失败,请重试' });
382
383
  expect(h.calls.sendMessage).not.toHaveBeenCalled();
383
384
  });
385
+
386
+ it.each(['unknown', 'unavailable', 'error', 'unauthenticated'] as const)(
387
+ 'enroll 卡:panel status=%s(查询失败非确认未入会)→ failed,不误报未入会',
388
+ async (status) => {
389
+ const h = createHarness();
390
+ h.calls.getLoginState.mockResolvedValue({ loginStatus: 'success' });
391
+ h.calls.loadPanel.mockResolvedValue({ member: { status } });
392
+ h.gate.trigger(gateCard('member-enrollment-cta'), undefined);
393
+ h.gate.confirm();
394
+ await flush();
395
+ expect(h.gate.getState()).toMatchObject({ phase: 'failed', message: '会员状态同步失败,请重试' });
396
+ expect(h.calls.refreshPanel).not.toHaveBeenCalled();
397
+ expect(h.calls.sendMessage).not.toHaveBeenCalled();
398
+ expect(h.calls.log.mock.calls.flat()).toContain(`judge panel status=${status} mallId=mall-001`);
399
+ },
400
+ );
401
+
402
+ it('enroll 卡:panel closed(厂商确认态)→ not-enrolled 而非 failed', async () => {
403
+ const h = createHarness();
404
+ h.calls.getLoginState.mockResolvedValue({ loginStatus: 'success' });
405
+ h.calls.loadPanel.mockResolvedValue({ member: { status: 'closed' } });
406
+ h.gate.trigger(gateCard('member-enrollment-cta'), undefined);
407
+ h.gate.confirm();
408
+ await flush();
409
+ expect(h.gate.getState().phase).toBe('not-enrolled');
410
+ expect(h.calls.log.mock.calls.flat()).toContain('judge not-enrolled');
411
+ });
412
+
413
+ it('enroll 卡:judge mallId 注入透传(null → loadPanel(null),明细行归 none)', async () => {
414
+ const h = createHarness({ readMallId: () => null });
415
+ h.calls.getLoginState.mockResolvedValue({ loginStatus: 'success' });
416
+ h.calls.loadPanel.mockResolvedValue({ member: { status: 'active' } });
417
+ h.gate.trigger(gateCard('member-enrollment-cta'), undefined);
418
+ h.gate.confirm();
419
+ await flush();
420
+ expect(h.calls.loadPanel).toHaveBeenCalledWith(null);
421
+ expect(h.gate.getState().phase).toBe('idle');
422
+ expect(h.calls.log.mock.calls.flat()).toContain('judge panel status=active mallId=none');
423
+ });
384
424
  });
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * mock 演示直连入会门禁测试(非壳 H5 直调 provider-mock demo enroll):
3
- * - 映射纯函数五态表驱动;
3
+ * - 映射纯函数四态表驱动(200/401/404 + 未知态兜底;503 态已随服务端 NODE_ENV 闸门删除移除);
4
4
  * - 直连实现:真实 httpPost 链(stubGlobal fetch)断言 URL/method/超时信号 + 各态映射;
5
5
  * - 门禁集成:directLoginGate 注入 createMemberGate → success 收场全链(冷登/判定/重放)。
6
6
  */
@@ -36,7 +36,6 @@ describe('mapDirectEnrollReceipt(HTTP 状态 → 门控回执纯映射)', ()
36
36
  [200, { loginStatus: 'success', message: '登录成功' }],
37
37
  [401, { loginStatus: 'fail', message: '请先登录' }],
38
38
  [404, { loginStatus: 'fail', message: '当前环境未提供入会服务,请在支付宝小程序内打开' }],
39
- [503, { loginStatus: 'fail', message: '演示入会仅限非生产环境' }],
40
39
  [500, { loginStatus: 'fail', message: '登录状态同步失败,请重试' }],
41
40
  ];
42
41
  it.each(cases)('status=%i → %j', (status, expected) => {