@stalfh233/omc-fake-platform 0.6.6 → 0.6.10

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.
package/dist/app.js CHANGED
@@ -5,6 +5,17 @@ export const appRoute = (ctx, input) => {
5
5
  const body = (input.body ?? {});
6
6
  switch (input.path) {
7
7
  case "/api/api/app/apppackage/list":
8
+ // r28g 回归(真机语义 1.1.25):真实平台**每个应用都有默认目录**;应用不论是
9
+ // 经 create 还是本来就存在于租户,树里都至少有一个顶层 Folder。
10
+ // 早期 fake 在**树路由**里"缺就合成一个"来兜底,r28d F7 为了能测出
11
+ // 「删光目录 → 空树」把这层兜底去掉了,于是 `applicationList` 里预置的
12
+ // 应用(不走 apppackage/create)一个目录都没有,model.create 直接
13
+ // 302001 no folder found。兜底应当发生在**应用出现时**,不是每次读树时。
14
+ for (const app of ctx.options.applicationList ?? [])
15
+ ctx.ensureDefaultFolder(app.appCode);
16
+ // `options.applicationList` 是"租户完整应用清单"的覆盖项(语义是**取代**,
17
+ // 不是追加)——所以这里只读它,不合并 state(合并会把内置 test 应用也算进去,
18
+ // 让 applicationCount 从 2 变 3)。seedApp 建的应用由 seedApp 自己追加进该清单。
8
19
  return ctx.options.applicationList ?? [...ctx.state.apps.values()].map((app) => ({ appCode: app.code, appName: app.name, id: app.id, groupId: app.groupId, published: app.published !== false }));
9
20
  case "/api/api/app/apppackage/list_all_group":
10
21
  return [...ctx.state.appGroups.values()].map((group) => ({
@@ -16,6 +27,18 @@ export const appRoute = (ctx, input) => {
16
27
  case "/api/api/app/apppackage/create": {
17
28
  const code = String(body.code);
18
29
  ctx.state.apps.set(code, { id: `app-${ctx.state.apps.size + 1}`, code, name: String(body.name ?? code), groupId: String(body.groupId ?? [...ctx.state.appGroups.keys()][0] ?? "group-1") });
30
+ // Live 1.1.25 (r28d F2): apppackage/create seeds one top-level Folder
31
+ // whose name_i18n.en is the stable token `defaultGroup`.
32
+ if (![...ctx.state.folders.values()].some((folder) => folder.appCode === code)) {
33
+ const id = `folder-default-${code}`;
34
+ ctx.state.folders.set(id, {
35
+ id,
36
+ appCode: code,
37
+ name: "默认分组",
38
+ code: `default-${code}`,
39
+ name_i18n: JSON.stringify({ en: "defaultGroup", zh: "默认分组", zh_TW: "預設分組" }),
40
+ });
41
+ }
19
42
  return null;
20
43
  }
21
44
  case "/api/api/app/apppackage/get": {
package/dist/index.d.ts CHANGED
@@ -50,6 +50,12 @@ export declare class FakeCloudPivot implements CloudPivotHttp {
50
50
  /** Test accessor: every recorded request body for the given path (in order). */
51
51
  bodiesFor(path: string): unknown[];
52
52
  queriesFor(path: string): (Record<string, string> | undefined)[];
53
+ /**
54
+ * 真机保真:字段/规则/数据都不可能脱离模型存在。读面(r28g)现在会先探模型
55
+ * ——对幻影 schema 不补建预置、不当成"空清单"——所以 seed* 必须把模型一起种上,
56
+ * 否则种子数据会被**正确地**判定为不存在。
57
+ */
58
+ private ensureSeedModel;
53
59
  seedRule(rule: Partial<FakeRule> & Pick<FakeRule, "schemaCode" | "code">): void;
54
60
  seedDataRow(schemaCode: string, data: Record<string, unknown>, id?: string): void;
55
61
  /**
@@ -64,5 +70,11 @@ export declare class FakeCloudPivot implements CloudPivotHttp {
64
70
  status: number;
65
71
  body: unknown;
66
72
  }>;
73
+ /**
74
+ * 真实平台:应用出现即有一个顶层「默认分组」。只在**没有**任何目录时种,
75
+ * 所以「用户删光了目录」仍是空树(r28d F7),而「应用预置但没建过目录」
76
+ * 也不会让 model.create 302001(r28g 回归)。
77
+ */
78
+ private ensureDefaultFolder;
67
79
  private route;
68
80
  }
package/dist/index.js CHANGED
@@ -58,7 +58,25 @@ export class FakeCloudPivot {
58
58
  queriesFor(path) {
59
59
  return this.state.callLog.filter((entry) => entry.path === path).map((entry) => entry.query);
60
60
  }
61
+ /**
62
+ * 真机保真:字段/规则/数据都不可能脱离模型存在。读面(r28g)现在会先探模型
63
+ * ——对幻影 schema 不补建预置、不当成"空清单"——所以 seed* 必须把模型一起种上,
64
+ * 否则种子数据会被**正确地**判定为不存在。
65
+ */
66
+ ensureSeedModel(schemaCode) {
67
+ if (this.state.models.has(schemaCode))
68
+ return;
69
+ const n = this.state.models.size + 1;
70
+ this.state.models.set(schemaCode, {
71
+ id: `model-${n}-fn`,
72
+ recordId: `model-${n}-rec`,
73
+ code: schemaCode,
74
+ name: schemaCode,
75
+ appCode: "test",
76
+ });
77
+ }
61
78
  seedRule(rule) {
79
+ this.ensureSeedModel(rule.schemaCode);
62
80
  const id = rule.id ?? `rule-${this.state.rules.size + 1}`;
63
81
  this.state.rules.set(`${rule.schemaCode}#${rule.code}`, {
64
82
  ...rule,
@@ -70,6 +88,7 @@ export class FakeCloudPivot {
70
88
  });
71
89
  }
72
90
  seedDataRow(schemaCode, data, id = `row-${this.state.dataRows.size + 1}`) {
91
+ this.ensureSeedModel(schemaCode);
73
92
  this.state.dataRows.set(id, { bizObjectId: id, schemaCode, ...data });
74
93
  }
75
94
  /**
@@ -88,8 +107,21 @@ export class FakeCloudPivot {
88
107
  groupId: app.groupId ?? [...this.state.appGroups.keys()][0] ?? "group-1",
89
108
  ...(app.published !== undefined ? { published: app.published } : {}),
90
109
  });
110
+ // r28g 回归(ticket 78):真实平台里应用一出现就有顶层默认分组。此前只有
111
+ // `apppackage/list` 才补,于是 `seedApp` 建的应用在 model.create 解析目录时
112
+ // 还是空的 → `302001 no folder found`,连带「未发布应用」的预检整条失效。
113
+ // 在应用**出现时**种,且只在没有任何目录时种(删光目录仍是空树,r28d F7)。
114
+ this.ensureDefaultFolder(app.code);
115
+ // 同理:`options.applicationList` 若被显式给定(覆盖语义),它不会自动包含
116
+ // 这里新建的应用——applicationList 就"看不见"它,ticket-78 的 corroboration
117
+ // (要读 published === false)拿不到行。追加进去,保持"完整清单"的语义。
118
+ const preset = this.options.applicationList;
119
+ if (preset !== undefined && !preset.some((entry) => entry.appCode === app.code)) {
120
+ preset.push({ appCode: app.code, appName: String(app.name ?? app.code) });
121
+ }
91
122
  }
92
123
  seedField(schemaCode, code, propertyType, published = true, options) {
124
+ this.ensureSeedModel(schemaCode);
93
125
  this.state.fields.set(`${schemaCode}#${code}`, { code, name: code, type: String(propertyType), published, ...(options !== undefined ? { options: JSON.stringify(options) } : {}) });
94
126
  }
95
127
  async request(input) {
@@ -135,6 +167,27 @@ export class FakeCloudPivot {
135
167
  }
136
168
  return { status: 200, body: { errcode: 0, errmsg: "ok", data: handler } };
137
169
  }
170
+ /**
171
+ * 真实平台:应用出现即有一个顶层「默认分组」。只在**没有**任何目录时种,
172
+ * 所以「用户删光了目录」仍是空树(r28d F7),而「应用预置但没建过目录」
173
+ * 也不会让 model.create 302001(r28g 回归)。
174
+ */
175
+ ensureDefaultFolder(appCode) {
176
+ // 只种**一次**:应用首次出现时必须有顶层目录;用户删光后不再补(r28d F7)。
177
+ if (this.state.foldersSeeded.has(appCode))
178
+ return;
179
+ this.state.foldersSeeded.add(appCode);
180
+ if ([...this.state.folders.values()].some((folder) => folder.appCode === appCode))
181
+ return;
182
+ const id = `folder-default-${appCode}`;
183
+ this.state.folders.set(id, {
184
+ id,
185
+ appCode,
186
+ name: "默认分组",
187
+ code: `default-${appCode}`,
188
+ name_i18n: JSON.stringify({ en: "defaultGroup", zh: "默认分组", zh_TW: "預設分組" }),
189
+ });
190
+ }
138
191
  route(input) {
139
192
  const ctx = {
140
193
  state: this.state,
@@ -142,6 +195,7 @@ export class FakeCloudPivot {
142
195
  forceSubmitMissingObjectId: this.forceSubmitMissingObjectId,
143
196
  forceSubmitMismatchedObjectId: this.forceSubmitMismatchedObjectId,
144
197
  omitDraftSaveWorkItem: this.omitDraftSaveWorkItem,
198
+ ensureDefaultFolder: (appCode) => this.ensureDefaultFolder(appCode),
145
199
  };
146
200
  return dispatchFakeRoute(ctx, input);
147
201
  }
package/dist/model.js CHANGED
@@ -20,12 +20,14 @@ export const modelRoute = (ctx, input) => {
20
20
  // discover_environment with applicationCode returned no models. Consumers
21
21
  // must flattenTreeRows (as resolveModelTreeNode already does); the fake
22
22
  // must nest so a regression cannot pass.
23
+ // r28d F7 vs r28g 回归:应用首次出现要有默认目录(真实平台如此),
24
+ // 但删光之后不再补。用 foldersSeeded 区分这两种"没有目录"。
25
+ for (const app of ctx.state.apps.values())
26
+ ctx.ensureDefaultFolder(app.code);
23
27
  const folders = [...ctx.state.folders.values()].filter((folder) => appCode === undefined || folder.appCode === appCode);
24
- // Every real application has at least one folder (the designer's default
25
- // group). An app seeded without one still needs a resolvable folder or
26
- // model.create could never run there — synthesize the default.
27
- if (appCode !== undefined && !folders.some((folder) => folder.appCode === appCode))
28
- folders.push({ id: `folder-${appCode}`, appCode, name: "General", code: "general" });
28
+ // Live 1.1.25 (r28d F7): a known app with every folder deleted returns an
29
+ // empty tree — do NOT synthesize a default here. app.create already seeds
30
+ // the defaultGroup folder; the initial "test" app keeps folder-1.
29
31
  const models = [...ctx.state.models.values()].filter((model) => !model.treeHidden && (appCode === undefined || (model.appCode ?? "test") === appCode));
30
32
  const ROOT = "folder-1";
31
33
  const nodeOf = (folder) => ({
@@ -33,6 +35,7 @@ export const modelRoute = (ctx, input) => {
33
35
  type: "Folder",
34
36
  code: folder.code ?? null,
35
37
  name: folder.name,
38
+ ...(folder.name_i18n !== undefined ? { name_i18n: folder.name_i18n } : {}),
36
39
  parentId: folder.parentId ?? ROOT,
37
40
  children: [],
38
41
  });
@@ -73,7 +76,11 @@ export const modelRoute = (ctx, input) => {
73
76
  code,
74
77
  name: String(body.name ?? code),
75
78
  appCode: String(body.applicationCode ?? body.appCode ?? "test"),
76
- ...(body.folderId !== undefined && body.folderId !== null && String(body.folderId) !== "" ? { parentId: String(body.folderId) } : {}),
79
+ // Live wire uses parentId; older callers/tests sometimes still send folderId.
80
+ ...((() => {
81
+ const parent = body.parentId ?? body.folderId;
82
+ return parent !== undefined && parent !== null && String(parent) !== "" ? { parentId: String(parent) } : {};
83
+ })()),
77
84
  });
78
85
  // Live fidelity (ticket 42): bizmodels/create seeds NO form — the model
79
86
  // has no h_biz_sheet row until the form is created (bizsheet/create, or
package/dist/state.d.ts CHANGED
@@ -354,6 +354,12 @@ export interface FakeState {
354
354
  rules: Map<string, FakeRule>;
355
355
  buttons: Map<string, FakeButton>;
356
356
  folders: Map<string, FakeFolder>;
357
+ /**
358
+ * 已种过「默认分组」的应用(r28d F7 vs r28g 回归的分界线):
359
+ * 应用**第一次出现**时必须有一个顶层目录(真实平台如此);
360
+ * 但用户把目录**删光**之后树必须真的是空的——不能每次读树都重新合成。
361
+ */
362
+ foldersSeeded: Set<string>;
357
363
  /** Schema codes for which bizproperty/list answers 601003 (see field.ts). */
358
364
  fieldListUnavailable: Set<string>;
359
365
  /**
@@ -523,6 +529,12 @@ export interface FakeRouteContext {
523
529
  readonly forceSubmitMismatchedObjectId: boolean;
524
530
  /** Live-observed shape: form/save's FormSaveVO omits workItem (uncommitted TX read). */
525
531
  readonly omitDraftSaveWorkItem: boolean;
532
+ /**
533
+ * r28g 回归:真实平台每个应用都有默认目录。应用出现时(create 或本来就
534
+ * 存在于 applicationList)种一个;**已存在则不覆盖**——用户把目录删光之后
535
+ * 树必须是空的(r28d F7 要求能测出这种情况)。
536
+ */
537
+ readonly ensureDefaultFolder: (appCode: string) => void;
526
538
  }
527
539
  /** Sentinel returned by a lane route when the path is outside its lane. */
528
540
  export declare const NOT_HANDLED: unique symbol;
package/dist/state.js CHANGED
@@ -43,7 +43,8 @@ export function createFakeState(options = {}) {
43
43
  // model.create resolves the first Folder in the tree when no folderId is
44
44
  // given; this row is that default. Its parent is the app package (implicit
45
45
  // root), so it is a top-level tree node.
46
- folders: new Map([["folder-1", { id: "folder-1", appCode: "test", name: "General", code: "general" }]]),
46
+ folders: new Map([["folder-1", { id: "folder-1", appCode: "test", name: "General", code: "general", name_i18n: JSON.stringify({ en: "defaultGroup", zh: "默认分组", zh_TW: "預設分組" }) }]]),
47
+ foldersSeeded: new Set(["test"]),
47
48
  fieldListUnavailable: new Set(),
48
49
  ruleHistory: [],
49
50
  ruleSeq: 0,
package/dist/workflow.js CHANGED
@@ -474,10 +474,10 @@ export const workflowRoute = (ctx, input) => {
474
474
  }
475
475
  const seededRoles = [{ id: "role-lead", name: "部门负责人", code: "SYS260630023816197", roleType: "SYS", corpId: "corp-1" }];
476
476
  const groups = [
477
- { id: "grp-1", name: "默认", code: "SYS_1000000", group: true, children: [...seededRoles, ...(rolesByGroup.get("grp-1") ?? [])] },
477
+ { id: "grp-1", name: "默认", code: "SYS_1000000", group: true, parentId: null, children: [...seededRoles, ...(rolesByGroup.get("grp-1") ?? [])] },
478
478
  ...[...ctx.state.orgGroups.values()]
479
479
  .filter((group) => group.id !== "grp-1")
480
- .map((group) => ({ id: group.id, name: group.name, code: group.code, group: true, children: rolesByGroup.get(group.id) ?? [] })),
480
+ .map((group) => ({ id: group.id, name: group.name, code: group.code, group: true, parentId: group.parentId, children: rolesByGroup.get(group.id) ?? [] })),
481
481
  ];
482
482
  return [
483
483
  ...groups,
@@ -562,8 +562,17 @@ export const workflowRoute = (ctx, input) => {
562
562
  }
563
563
  case "/api/api/organization/department/list_user": {
564
564
  const deptId = String(q.deptId ?? "");
565
+ // Seed the same fixture users search returns so the no-keyword roster
566
+ // path (department-tree aggregation) is non-empty in tests (r28h F4).
567
+ const seeded = [
568
+ { id: "user-1", username: "18900000001", name: "付文彬", departmentId: "dept-1", mobile: null },
569
+ { id: "user-2", username: "18900000002", name: "李四", departmentId: "dept-2", mobile: null },
570
+ ].filter((user) => user.departmentId === deptId);
565
571
  const users = [...ctx.state.orgUsers.values()].filter((user) => user.departmentId === deptId);
566
- return users.map((user) => ({ id: user.id, name: user.name, username: user.username, mobile: user.mobile }));
572
+ return [
573
+ ...seeded,
574
+ ...users.map((user) => ({ id: user.id, name: user.name, username: user.username, mobile: user.mobile })),
575
+ ];
567
576
  }
568
577
  case "/api/api/organization/user/add": {
569
578
  for (const key of ["userLabelIds", "userManagerConfigList"]) {
@@ -619,18 +628,25 @@ export const workflowRoute = (ctx, input) => {
619
628
  }
620
629
  case "/api/api/organization/role/add_role_group": {
621
630
  const id = `grp-${ctx.state.orgGroups.size + 1}`;
622
- ctx.state.orgGroups.set(id, { id, name: String(body.roleGroupName ?? ""), code: body.code ? String(body.code) : null, parentId: body.parentId ? String(body.parentId) : null });
623
- return { roleGroupId: id, roleGroupName: body.roleGroupName, code: ctx.state.orgGroups.get(id).code, corpId: body.corpId ?? "other" };
631
+ // Mirror live 1.1.25: create response often leaves code null; the next
632
+ // /role/list fills SYS… (r28h F9). Assign the code into state immediately
633
+ // so a re-read after create sees it, but still return null on the create face.
634
+ const assigned = body.code ? String(body.code) : `SYS_FAKE_${id}`;
635
+ ctx.state.orgGroups.set(id, { id, name: String(body.roleGroupName ?? ""), code: assigned, parentId: body.parentId ? String(body.parentId) : null });
636
+ return { roleGroupId: id, roleGroupName: body.roleGroupName, code: body.code ? String(body.code) : null, corpId: body.corpId ?? "other" };
624
637
  }
625
638
  case "/api/api/organization/role/add_role": {
626
639
  const groupId = String(body.roleGroupId ?? "");
627
640
  if (!groupId)
628
641
  return businessRefusal(10005, "角色组不能为空");
629
- if (groupId !== "grp-1" && !ctx.state.orgGroups.has(groupId))
642
+ if (groupId !== "grp-1" && groupId !== "0" && !ctx.state.orgGroups.has(groupId))
630
643
  return businessRefusal(10011, "角色组不存在");
631
644
  const id = `role-${ctx.state.orgRoles.size + 1}`;
632
- ctx.state.orgRoles.set(id, { id, name: String(body.roleName ?? ""), code: body.code ? String(body.code) : null, roleGroupId: groupId, roleGroupName: body.roleGroupName ? String(body.roleGroupName) : null, roleType: String(body.roleType ?? "SYS"), corpId: String(body.corpId ?? "other") });
633
- return { roleId: id, roleName: body.roleName, code: ctx.state.orgRoles.get(id).code, roleGroupId: groupId, roleGroupName: body.roleGroupName ?? null, roleType: body.roleType ?? "SYS", corpId: body.corpId ?? "other" };
645
+ const assigned = body.code ? String(body.code) : `SYS_FAKE_${id}`;
646
+ ctx.state.orgRoles.set(id, { id, name: String(body.roleName ?? ""), code: assigned, roleGroupId: groupId, roleGroupName: body.roleGroupName ? String(body.roleGroupName) : null, roleType: String(body.roleType ?? "SYS"), corpId: String(body.corpId ?? "other") });
647
+ // Create face echoes null code when the caller didn't supply one (live
648
+ // platform behaviour); state already holds the assigned SYS… for list.
649
+ return { roleId: id, roleName: body.roleName, code: body.code ? String(body.code) : null, roleGroupId: groupId, roleGroupName: body.roleGroupName ?? null, roleType: body.roleType ?? "SYS", corpId: body.corpId ?? "other" };
634
650
  }
635
651
  case "/api/api/organization/role/get": {
636
652
  const role = ctx.state.orgRoles.get(String(q.roleId ?? ""));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stalfh233/omc-fake-platform",
3
- "version": "0.6.6",
3
+ "version": "0.6.10",
4
4
  "description": "OMC 的内存假 CloudPivot 平台(wire 接缝的第二个适配器)+ HTTP 假服务器——@stalfh233/omc-cli 的测试与 bench 基准基座",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",