bailinghub 0.3.1 → 0.3.2-rc.1

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.
Files changed (63) hide show
  1. package/.env.example +3 -0
  2. package/THIRD_PARTY_NOTICES.md +1 -1
  3. package/demo/business/server.mjs +107 -59
  4. package/docs/DEMO.md +25 -0
  5. package/package.json +4 -1
  6. package/scripts/check-package-artifact.mjs +2 -1
  7. package/scripts/check-release-consistency.mjs +57 -23
  8. package/scripts/check-release-consistency.test.mjs +58 -3
  9. package/scripts/seed-demo.ts +24 -99
  10. package/scripts/validate-examples.mjs +6 -4
  11. package/sql/054_demo_dataset_state.sql +12 -0
  12. package/src/app/kernel.ts +3 -0
  13. package/src/core/config/config.test.ts +69 -0
  14. package/src/core/config/config.ts +54 -0
  15. package/src/infrastructure/config/config-chat-repository.ts +12 -1
  16. package/src/infrastructure/config/config-client-repository.ts +21 -2
  17. package/src/infrastructure/config/config-route-repository.ts +12 -1
  18. package/src/infrastructure/config/config-target-repository.ts +12 -1
  19. package/src/infrastructure/config/config-tool-provider-repository.ts +12 -1
  20. package/src/routes/admin-default.ts +2 -0
  21. package/src/routes/admin-demo-dataset.test.ts +93 -0
  22. package/src/routes/admin-demo-dataset.ts +83 -0
  23. package/src/routes/admin-host.test.ts +10 -1
  24. package/src/routes/admin.ts +14 -0
  25. package/src/services/demo-business-profile.test.ts +230 -0
  26. package/src/services/demo-dataset.test.ts +369 -0
  27. package/src/services/demo-dataset.ts +872 -0
  28. package/web/console/assets/{Accounts-Dwzm4D_V.js → Accounts-08VltF2i.js} +1 -1
  29. package/web/console/assets/{Approvals-BxhuI0ku.js → Approvals-CqgmsMau.js} +1 -1
  30. package/web/console/assets/{Audit-dFAbGynl.js → Audit-bPlpSQt3.js} +1 -1
  31. package/web/console/assets/{BrandLockup-BtZyvkM5.js → BrandLockup-DhX07g3G.js} +1 -1
  32. package/web/console/assets/{Channels-Dqg4-_yr.js → Channels-BZe0pLgx.js} +1 -1
  33. package/web/console/assets/{ChatEntries-CEGZ3NnJ.js → ChatEntries-Ca0lcGqn.js} +1 -1
  34. package/web/console/assets/{Clients-C0QD1x7g.js → Clients-BVVZfX3r.js} +1 -1
  35. package/web/console/assets/{Cost-BAJqLhpK.js → Cost-DANcjr_p.js} +1 -1
  36. package/web/console/assets/{Credentials-D_GDRgWi.js → Credentials-D_8tP2Xa.js} +1 -1
  37. package/web/console/assets/{Diagnostics-BWYnDxRj.js → Diagnostics-Bw1WImFe.js} +1 -1
  38. package/web/console/assets/{Executors-Cmryk4Vk.js → Executors-fuieN2Sl.js} +1 -1
  39. package/web/console/assets/{Kb-BSXQE0Fa.js → Kb-BaMi_7xf.js} +1 -1
  40. package/web/console/assets/{Login-BnBPqC8Z.js → Login-Cmz2ppY8.js} +1 -1
  41. package/web/console/assets/{Projects-CNHx4L_7.js → Projects-D6xIgFB3.js} +1 -1
  42. package/web/console/assets/{Routes-u5cEAEXQ.js → Routes-B90i3ZNa.js} +1 -1
  43. package/web/console/assets/{Runs-BeFUR77_.js → Runs-9qpwotOj.js} +1 -1
  44. package/web/console/assets/Setup-BIjCiA2i.js +1 -0
  45. package/web/console/assets/Setup-BuyKFofL.css +1 -0
  46. package/web/console/assets/Shell-BVIjmoY8.css +1 -0
  47. package/web/console/assets/Shell-Dm6eFcl1.js +1 -0
  48. package/web/console/assets/{StorageBuckets-DMXRJxUA.js → StorageBuckets-DY8WuJlM.js} +1 -1
  49. package/web/console/assets/{SystemSettings-B72F-loY.js → SystemSettings-O_NMPzq_.js} +1 -1
  50. package/web/console/assets/{SystemStatus-hOj_TPYE.js → SystemStatus-Cok3S7S3.js} +1 -1
  51. package/web/console/assets/{Targets-UVVf7twC.js → Targets-YWBoxqvy.js} +1 -1
  52. package/web/console/assets/{Tools-ihkr9R9x.js → Tools-BgXDw7Mg.js} +1 -1
  53. package/web/console/assets/{index-DxvruykG.js → index-S_J0I0Zh.js} +2 -2
  54. package/web/console/assets/{request-BisL2T9B.js → request-FM608Kfz.js} +1 -1
  55. package/web/console/assets/{schema-CzpUpoLk.js → schema-DWnFqTkB.js} +1 -1
  56. package/web/console/index.html +1 -1
  57. package/web-admin/package-lock.json +3 -3
  58. package/web-admin/src/layout/Shell.vue +5 -4
  59. package/web-admin/src/pages/Setup.vue +12 -9
  60. package/web/console/assets/Setup-BjZfrmfN.js +0 -1
  61. package/web/console/assets/Setup-QjlHZKdB.css +0 -1
  62. package/web/console/assets/Shell-CbGNTN91.css +0 -1
  63. package/web/console/assets/Shell-EJuYf3OO.js +0 -1
package/.env.example CHANGED
@@ -55,13 +55,16 @@
55
55
  # BAILING_BOOTSTRAP_ADMIN_PASSWORD=replace-with-a-strong-password
56
56
 
57
57
  # Docker demo 内置 MySQL 与 demo 业务系统密钥。一键安装脚本会自动生成强随机值。
58
+ # 共享体验环境请使用 stateless-readonly:business URL 指向本机回环服务,tool secret 至少 24 位且独立随机。
58
59
  # BAILING_DEMO_ADMIN_PASSWORD=bailing-demo-admin
59
60
  # BAILING_DEMO_MYSQL_ROOT_PASSWORD=bailing-root-pass
60
61
  # BAILING_DEMO_MYSQL_DATABASE=bailinghub
61
62
  # BAILING_DEMO_MYSQL_USER=bailing
62
63
  # BAILING_DEMO_MYSQL_PASSWORD=bailing-pass
64
+ # DEMO_BUSINESS_URL=http://demo-business:19080
63
65
  # DEMO_TOOL_SECRET=demo-tool-secret-change-me
64
66
  # DEMO_CLIENT_TOKEN=bailing-demo-client-token
67
+ # DEMO_PROFILE=full-local
65
68
 
66
69
  # 展示时区。
67
70
  # BAILING_DISPLAY_TZ=Asia/Shanghai
@@ -128,7 +128,7 @@ The package license texts and copyright notices remain in the installed package
128
128
  | Console | [magic-string](https://www.npmjs.com/package/magic-string) | 0.30.21 | MIT | runtime |
129
129
  | Console | [mammoth](https://www.npmjs.com/package/mammoth) | 1.12.0 | BSD-2-Clause | runtime |
130
130
  | Console | [memoize-one](https://www.npmjs.com/package/memoize-one) | 6.0.0 | MIT | runtime |
131
- | Console | [nanoid](https://www.npmjs.com/package/nanoid) | 3.3.16 | MIT | runtime |
131
+ | Console | [nanoid](https://www.npmjs.com/package/nanoid) | 3.3.18 | MIT | runtime |
132
132
  | Console | [normalize-wheel-es](https://www.npmjs.com/package/normalize-wheel-es) | 1.2.0 | BSD-3-Clause | runtime |
133
133
  | Console | [option](https://www.npmjs.com/package/option) | 0.2.4 | BSD-2-Clause | runtime |
134
134
  | Console | [pako](https://www.npmjs.com/package/pako) | 1.0.11 | (MIT AND Zlib) | runtime |
@@ -3,9 +3,22 @@ import { createServer } from 'node:http';
3
3
 
4
4
  const host = process.env.DEMO_HOST || '127.0.0.1';
5
5
  const port = Number(process.env.DEMO_PORT || 19080);
6
+ const profile = process.env.DEMO_PROFILE || 'full-local';
7
+ if (profile !== 'full-local' && profile !== 'stateless-readonly') {
8
+ throw new Error('DEMO_PROFILE 只支持 full-local 或 stateless-readonly');
9
+ }
10
+ const statelessReadonly = profile === 'stateless-readonly';
11
+ if (statelessReadonly && !['127.0.0.1', '::1', 'localhost'].includes(host.toLowerCase())) {
12
+ throw new Error('stateless-readonly 模式的 DEMO_HOST 必须是本机回环地址');
13
+ }
6
14
  const secret = process.env.DEMO_TOOL_SECRET || 'demo-tool-secret-change-me';
7
- const clientToken = process.env.DEMO_CLIENT_TOKEN || 'bailing-demo-client-token';
8
- const hubUrl = (process.env.DEMO_HUB_URL || 'http://localhost:18900').replace(/\/+$/, '');
15
+ if (statelessReadonly && (secret.trim().length < 24 || secret !== secret.trim()
16
+ || /^(?:replace|change|demo|test|example|sample)(?:[_-]|$)/i.test(secret))) {
17
+ throw new Error('stateless-readonly 模式的 DEMO_TOOL_SECRET 不安全:请使用至少 24 位的独立随机密钥');
18
+ }
19
+ // 公共只读 profile 不需要回调 Hub,因此不读取也不使用客户端 token/Hub URL。
20
+ const clientToken = statelessReadonly ? '' : (process.env.DEMO_CLIENT_TOKEN || 'bailing-demo-client-token');
21
+ const hubUrl = statelessReadonly ? '' : (process.env.DEMO_HUB_URL || 'http://localhost:18900').replace(/\/+$/, '');
9
22
 
10
23
  const principals = new Map([
11
24
  ['demo-user-001', { uid: 'demo-user-001', tenant: 'demo-shop', name: 'Alice' }],
@@ -47,11 +60,8 @@ function acc(scope, opts = {}) {
47
60
  return capability;
48
61
  }
49
62
 
50
- const toolSpec = {
51
- openapi: '3.1.0',
52
- info: { title: 'Bailing demo business tools', version: '1.0.0' },
53
- 'x-bailing-authz-probe': { method: 'POST', path: '/.well-known/bailing/authz-probe' },
54
- paths: {
63
+ function buildToolSpec(selectedProfile) {
64
+ const paths = {
55
65
  '/orders': {
56
66
  get: {
57
67
  operationId: 'list_demo_orders',
@@ -59,84 +69,79 @@ const toolSpec = {
59
69
  description: '按订单号或客户名查询 demo 订单。无过滤条件时返回当前主体可见的最近订单。',
60
70
  'x-agent-capability': acc('demo.order.read', {
61
71
  requiresSubject: true,
72
+ readonly: true,
62
73
  whenToUse: '用户询问订单状态、付款状态、物流状态或历史订单时使用。',
63
74
  returns: '订单号、客户、商品、金额、状态、物流状态。',
64
75
  }),
65
76
  parameters: [
66
- { name: 'order_no', in: 'query', required: false, description: '订单号,例如 SO-1001。用户没给订单号时不要编造。', schema: { type: 'string' } },
77
+ { name: 'order_no', in: 'query', required: false, description: '订单号,例如 SO-1001。', schema: { type: 'string' } },
67
78
  { name: 'customer', in: 'query', required: false, description: '客户名,可用于模糊过滤。', schema: { type: 'string' } },
68
79
  ],
80
+ responses: { '200': { description: 'OK' } },
81
+ },
82
+ },
83
+ '/failure-demo': {
84
+ get: {
85
+ operationId: 'demo_failure_probe',
86
+ summary: '触发一个可观测失败',
87
+ description: '用于演示中枢 trace 如何记录业务工具 5xx、错误正文和排障路径。',
88
+ 'x-agent-capability': acc('demo.failure.read', { requiresSubject: true, readonly: true }),
89
+ responses: { '500': { description: 'Intentional demo failure' } },
69
90
  },
70
91
  },
71
- '/tickets': {
92
+ };
93
+ if (selectedProfile === 'full-local') {
94
+ paths['/tickets'] = {
72
95
  post: {
73
96
  operationId: 'create_demo_ticket',
74
97
  summary: '为当前操作主体创建售后工单',
75
98
  description: '当用户明确要求登记问题、创建工单或需要人工跟进时使用。',
76
99
  'x-agent-capability': acc('demo.ticket.create', {
77
- risk: 'medium',
78
- requiresSubject: true,
79
- idempotent: false,
100
+ risk: 'medium', requiresSubject: true, idempotent: false,
80
101
  whenToUse: '用户要求人工处理、售后跟进、开工单或记录问题时使用。',
81
102
  returns: '工单编号与当前状态。',
82
103
  }),
83
104
  requestBody: {
84
105
  required: true,
85
- content: {
86
- 'application/json': {
87
- schema: {
88
- type: 'object',
89
- properties: {
90
- order_no: { type: 'string', description: '关联订单号,例如 SO-1001。' },
91
- title: { type: 'string', description: '工单标题,简短概括用户问题。' },
92
- message: { type: 'string', description: '工单正文,记录用户诉求和已查询到的关键信息。' },
93
- },
94
- required: ['title', 'message'],
95
- },
96
- },
97
- },
106
+ content: { 'application/json': { schema: {
107
+ type: 'object',
108
+ properties: { order_no: { type: 'string' }, title: { type: 'string' }, message: { type: 'string' } },
109
+ required: ['title', 'message'],
110
+ } } },
98
111
  },
112
+ responses: { '200': { description: 'OK' } },
99
113
  },
100
- },
101
- '/refunds': {
114
+ };
115
+ paths['/refunds'] = {
102
116
  post: {
103
117
  operationId: 'request_demo_refund',
104
118
  summary: '提交退款申请',
105
- description: '高风险示例工具:会产生退款申请,必须进入中枢审批车道。',
119
+ description: '本地单组织 demo 的高风险工具:会产生内存中的退款申请,必须进入审批车道。',
106
120
  'x-agent-capability': acc('demo.refund.request', {
107
- risk: 'high',
108
- confirm: true,
109
- requiresSubject: true,
110
- confirmPrompt: '确认要为订单 {{order_no}} 申请退款 {{amount}} 元吗?',
121
+ risk: 'high', requiresSubject: true,
122
+ confirm: true, confirmPrompt: '确认要为订单 {{order_no}} 申请退款 {{amount}} 元吗?',
111
123
  }),
112
124
  requestBody: {
113
125
  required: true,
114
- content: {
115
- 'application/json': {
116
- schema: {
117
- type: 'object',
118
- properties: {
119
- order_no: { type: 'string', description: '订单号。' },
120
- amount: { type: 'number', description: '退款金额。' },
121
- reason: { type: 'string', description: '退款原因。' },
122
- },
123
- required: ['order_no', 'amount', 'reason'],
124
- },
125
- },
126
- },
126
+ content: { 'application/json': { schema: {
127
+ type: 'object',
128
+ properties: { order_no: { type: 'string' }, amount: { type: 'number' }, reason: { type: 'string' } },
129
+ required: ['order_no', 'amount', 'reason'],
130
+ } } },
127
131
  },
132
+ responses: { '202': { description: 'Accepted' } },
128
133
  },
129
- },
130
- '/failure-demo': {
131
- get: {
132
- operationId: 'demo_failure_probe',
133
- summary: '触发一个可观测失败',
134
- description: '用于演示中枢 trace 如何记录业务工具 5xx、错误正文和排障路径。',
135
- 'x-agent-capability': acc('demo.failure.read', { requiresSubject: true }),
136
- },
137
- },
138
- },
139
- };
134
+ };
135
+ }
136
+ return {
137
+ openapi: '3.1.0',
138
+ info: { title: 'Bailing demo business tools', version: '1.0.0' },
139
+ 'x-bailing-authz-probe': { method: 'POST', path: '/.well-known/bailing/authz-probe' },
140
+ paths,
141
+ };
142
+ }
143
+
144
+ const toolSpec = buildToolSpec(profile);
140
145
 
141
146
  function json(res, status, data) {
142
147
  const body = JSON.stringify(data);
@@ -259,6 +264,40 @@ async function sendApprovalDecision(approval, decision) {
259
264
  return body;
260
265
  }
261
266
 
267
+ function renderReadonlyPage() {
268
+ const orderRows = orders.map((o) => `<tr><td>${o.order_no}</td><td>${o.customer}</td><td>${o.item}</td><td>${o.amount}</td><td>${o.status}</td><td>${o.logistics}</td></tr>`).join('');
269
+ return `<!doctype html>
270
+ <html lang="zh-CN">
271
+ <head>
272
+ <meta charset="utf-8" />
273
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
274
+ <title>Bailing Demo Business</title>
275
+ <style>
276
+ :root { color-scheme: dark; font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: #0b0d10; color: #e8eaed; }
277
+ body { margin: 0; padding: 28px; }
278
+ main { max-width: 980px; margin: 0 auto; }
279
+ p { color: #a7adb7; line-height: 1.7; }
280
+ a { color: #57d178; margin-right: 14px; text-decoration: none; }
281
+ section { margin-top: 20px; border: 1px solid #252a33; border-radius: 8px; background: #12151a; padding: 16px; }
282
+ table { width: 100%; border-collapse: collapse; font-size: 13px; }
283
+ th, td { border-bottom: 1px solid #252a33; padding: 8px; text-align: left; }
284
+ th { color: #a7adb7; font-weight: 500; }
285
+ </style>
286
+ </head>
287
+ <body>
288
+ <main>
289
+ <h1>Demo 业务系统</h1>
290
+ <p>公共体验环境仅提供无副作用的订单查询和故障 trace 演示,不创建工单、退款或审批状态。</p>
291
+ <nav><a href="/health">Health</a><a href="/.well-known/bailing/tools.json">Tools Spec</a></nav>
292
+ <section>
293
+ <h2>固定演示订单</h2>
294
+ <table><thead><tr><th>订单号</th><th>客户</th><th>商品</th><th>金额</th><th>状态</th><th>物流</th></tr></thead><tbody>${orderRows}</tbody></table>
295
+ </section>
296
+ </main>
297
+ </body>
298
+ </html>`;
299
+ }
300
+
262
301
  function renderPage() {
263
302
  const orderRows = orders.map((o) => `<tr><td>${o.order_no}</td><td>${o.customer}</td><td>${o.item}</td><td>${o.amount}</td><td>${o.status}</td><td>${o.logistics}</td></tr>`).join('');
264
303
  const ticketRows = tickets.slice().reverse().map((t) => `<tr><td>${t.ticket_id}</td><td>${t.order_no || '-'}</td><td>${escapeHtml(t.title)}</td><td>${t.status}</td></tr>`).join('') || '<tr><td colspan="4" class="muted">暂无工单</td></tr>';
@@ -357,17 +396,26 @@ function renderPage() {
357
396
  createServer(async (req, res) => {
358
397
  const url = new URL(req.url || '/', `http://${req.headers.host || 'localhost'}`);
359
398
  if (req.method === 'GET' && url.pathname === '/') {
360
- html(res, 200, renderPage());
399
+ html(res, 200, statelessReadonly ? renderReadonlyPage() : renderPage());
361
400
  return;
362
401
  }
363
402
  if (req.method === 'GET' && url.pathname === '/health') {
364
- json(res, 200, { ok: true, app: 'demo-business' });
403
+ json(res, 200, { ok: true, app: 'demo-business', profile });
365
404
  return;
366
405
  }
367
406
  if (req.method === 'GET' && url.pathname === '/.well-known/bailing/tools.json') {
368
407
  json(res, 200, toolSpec);
369
408
  return;
370
409
  }
410
+ if (statelessReadonly && !(
411
+ (req.method === 'POST' && url.pathname === '/.well-known/bailing/authz-probe')
412
+ || (req.method === 'GET' && url.pathname === '/orders')
413
+ || (req.method === 'GET' && url.pathname === '/failure-demo')
414
+ )) {
415
+ // 在公共体验环境中先于读 body/验签返回 404,不暴露也不触发任何可变逻辑。
416
+ json(res, 404, { error: 'not found' });
417
+ return;
418
+ }
371
419
  if (req.method === 'GET' && url.pathname === '/api/state') {
372
420
  json(res, 200, { orders, tickets, refunds, approvals });
373
421
  return;
@@ -479,5 +527,5 @@ createServer(async (req, res) => {
479
527
 
480
528
  json(res, 404, { error: 'not found' });
481
529
  }).listen(port, host, () => {
482
- console.log(`[demo-business] listening http://${host}:${port}`);
530
+ console.log(`[demo-business] listening http://${host}:${port} profile=${profile}`);
483
531
  });
package/docs/DEMO.md CHANGED
@@ -78,6 +78,31 @@ curl -fsSL https://www.bailinghub.com/install.sh | env \
78
78
  - token:`bailing-demo-client-token`
79
79
  - 可调用路由:`demo_support`
80
80
 
81
+ ## 控制台导入与无状态只读 profile
82
+
83
+ Core 同时提供一套可从“上手向导”导入的演示数据集。它只导入调度目标、工具源、路由和接入方等配置;不伪造任务、审批、成本或审计记录。导入后运行 smoke,才会由真实调用生成 job 和 trace。
84
+
85
+ 配置由运行环境注入:
86
+
87
+ ```bash
88
+ DEMO_BUSINESS_URL=http://127.0.0.1:19080
89
+ DEMO_TOOL_SECRET=<independent-random-secret>
90
+ DEMO_PROFILE=stateless-readonly
91
+ ```
92
+
93
+ - `full-local`:Docker 本地完整演示,包含查单、工单、退款审批和故障工具;
94
+ - `stateless-readonly`:共享或宿主式体验环境,`demo-business` 必须绑定本机回环地址,只声明订单查询与故障观测工具,不保存请求状态、不使用 Hub 回调,也不创建公开聊天入口。
95
+
96
+ Core 用 `bz_demo_datasets` 中的持久 ownership manifest 记录它实际创建的固定对象和指纹。再次导入只刷新已证明归属的对象;同名占用、指纹漂移或其他配置引用都会返回 `409`,不猜测所有权。清理只删除 manifest 能证明且未被修改的演示配置,任务、消息、trace 和审计账本会继续保留。
97
+
98
+ 对应的 Core 后台 API 为:
99
+
100
+ - `GET /admin/api/demo-dataset/status`
101
+ - `POST /admin/api/demo-dataset/import`
102
+ - `DELETE /admin/api/demo-dataset`
103
+
104
+ 导入与清理同时要求 `targets:write`、`tools:write`、`routes:write` 和 `clients:write`;查看状态要求审计读权限或上述聚合写权限。
105
+
81
106
  ## 触发一条任务
82
107
 
83
108
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bailinghub",
3
- "version": "0.3.1",
3
+ "version": "0.3.2-rc.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Open-source ACC runtime and agent control plane for existing business systems.",
@@ -46,6 +46,9 @@
46
46
  "engines": {
47
47
  "node": ">=22"
48
48
  },
49
+ "publishConfig": {
50
+ "tag": "next"
51
+ },
49
52
  "scripts": {
50
53
  "start": "tsx src/server.ts",
51
54
  "dev": "tsx watch src/server.ts",
@@ -53,7 +53,8 @@ const requiredFiles = [
53
53
  'src/infrastructure/schema/core-schema-migrator.ts',
54
54
  'src/infrastructure/schema/retired-migrations.ts',
55
55
  'sql/001_init_state.sql',
56
- 'sql/053_tool_spec_access_policy.sql',
56
+ 'sql/054_demo_dataset_state.sql',
57
+ 'demo/business/server.mjs',
57
58
  'web/console/index.html',
58
59
  'web/widget/widget.js',
59
60
  ];
@@ -3,6 +3,7 @@ import { resolve } from 'node:path';
3
3
  import { pathToFileURL } from 'node:url';
4
4
 
5
5
  const VERSION_RE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
6
+ const STABLE_VERSION_RE = /^\d+\.\d+\.\d+$/;
6
7
 
7
8
  export const releaseConsistencyFiles = [
8
9
  'package.json',
@@ -50,6 +51,20 @@ function normalizeExpectedVersion(value) {
50
51
  return String(value).trim().replace(/^v/, '');
51
52
  }
52
53
 
54
+ function currentStableVersion(changelog, findings) {
55
+ const version = extractSingleVersion(
56
+ changelog,
57
+ /^## v(?<version>\d+\.\d+\.\d+) /m,
58
+ 'docs/CHANGELOG.md',
59
+ 'current stable release entry',
60
+ findings,
61
+ );
62
+ if (version && !STABLE_VERSION_RE.test(version)) {
63
+ findings.push(`docs/CHANGELOG.md: current stable release entry must be semantic, received ${version}`);
64
+ }
65
+ return version;
66
+ }
67
+
53
68
  function extractSingleVersion(text, regex, file, label, findings) {
54
69
  const match = text.match(regex);
55
70
  if (!match?.groups?.version) {
@@ -76,11 +91,24 @@ export function checkReleaseConsistency({ root = process.cwd(), expected = '' }
76
91
  const findings = [];
77
92
  const pkg = readJson(root, 'package.json', findings);
78
93
  const version = String(pkg.version ?? '').trim();
94
+ const isPrerelease = version.includes('-');
95
+ const publishTag = String(pkg.publishConfig?.tag ?? '').trim();
79
96
 
80
97
  if (!VERSION_RE.test(version)) {
81
98
  findings.push(`package.json: version must be semantic, received ${version || '<empty>'}`);
82
99
  }
83
100
 
101
+ if (isPrerelease && publishTag !== 'next') {
102
+ findings.push(
103
+ `package.json: prerelease versions must use publishConfig.tag "next", received ${publishTag || '<empty>'}`,
104
+ );
105
+ }
106
+ if (!isPrerelease && publishTag && publishTag !== 'latest') {
107
+ findings.push(
108
+ `package.json: stable versions may only use publishConfig.tag "latest" or omit it, received ${publishTag}`,
109
+ );
110
+ }
111
+
84
112
  const expectedVersion = normalizeExpectedVersion(
85
113
  expected
86
114
  || (process.env.GITHUB_REF_TYPE === 'tag' ? process.env.GITHUB_REF_NAME : ''),
@@ -93,6 +121,9 @@ export function checkReleaseConsistency({ root = process.cwd(), expected = '' }
93
121
  expectVersion(String(lock.version ?? ''), version, 'package-lock.json', 'top-level version', findings);
94
122
  expectVersion(String(lock.packages?.['']?.version ?? ''), version, 'package-lock.json', 'root package version', findings);
95
123
 
124
+ const changelog = readText(root, 'docs/CHANGELOG.md', findings);
125
+ const stableVersion = isPrerelease ? currentStableVersion(changelog, findings) : version;
126
+
96
127
  const compose = readText(root, 'docker-compose.images.yml', findings);
97
128
  for (const image of ['bailinghub', 'bailing-demo-business']) {
98
129
  const escaped = image.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
@@ -103,7 +134,7 @@ export function checkReleaseConsistency({ root = process.cwd(), expected = '' }
103
134
  `${image} default image tag`,
104
135
  findings,
105
136
  );
106
- expectVersion(imageVersion, version, 'docker-compose.images.yml', `${image} default image tag`, findings);
137
+ expectVersion(imageVersion, stableVersion, 'docker-compose.images.yml', `${image} default image tag`, findings);
107
138
  }
108
139
 
109
140
  const fallbackChecks = [
@@ -126,55 +157,55 @@ export function checkReleaseConsistency({ root = process.cwd(), expected = '' }
126
157
  for (const check of fallbackChecks) {
127
158
  const text = readText(root, check.file, findings);
128
159
  const actual = extractSingleVersion(text, check.regex, check.file, check.label, findings);
129
- expectVersion(actual, version, check.file, check.label, findings);
160
+ expectVersion(actual, stableVersion, check.file, check.label, findings);
130
161
  }
131
162
 
132
163
  for (const [file, baselineText] of [
133
- ['docs/INDEPENDENT_VALIDATION.md', `稳定基线:\`v${version}\``],
134
- ['docs/INDEPENDENT_VALIDATION.en.md', `Stable baseline: \`v${version}\``],
164
+ ['docs/INDEPENDENT_VALIDATION.md', `稳定基线:\`v${stableVersion}\``],
165
+ ['docs/INDEPENDENT_VALIDATION.en.md', `Stable baseline: \`v${stableVersion}\``],
135
166
  ]) {
136
167
  const text = readText(root, file, findings);
137
168
  expectContains(text, baselineText, file, 'current validation baseline', findings);
138
- expectContains(text, `--branch v${version}`, file, 'current validation clone command', findings);
139
- expectContains(text, `RELEASE_NOTES_v${version}`, file, 'current release-note link', findings);
169
+ expectContains(text, `--branch v${stableVersion}`, file, 'current validation clone command', findings);
170
+ expectContains(text, `RELEASE_NOTES_v${stableVersion}`, file, 'current release-note link', findings);
140
171
  }
141
172
 
142
173
  const issueTemplate = readText(root, '.github/ISSUE_TEMPLATE/independent_validation.yml', findings);
143
174
  expectContains(
144
175
  issueTemplate,
145
- `placeholder: "v${version};`,
176
+ `placeholder: "v${stableVersion};`,
146
177
  '.github/ISSUE_TEMPLATE/independent_validation.yml',
147
178
  'current validation placeholder',
148
179
  findings,
149
180
  );
150
181
 
151
182
  const releaseNotes = [
152
- `docs/RELEASE_NOTES_v${version}.md`,
153
- `docs/RELEASE_NOTES_v${version}.en.md`,
183
+ `docs/RELEASE_NOTES_v${stableVersion}.md`,
184
+ `docs/RELEASE_NOTES_v${stableVersion}.en.md`,
154
185
  ];
155
186
  for (const file of releaseNotes) {
156
187
  readText(root, file, findings);
157
188
  }
158
189
 
159
190
  const referenceChecks = [
160
- ['README.md', `docs/RELEASE_NOTES_v${version}.md`],
161
- ['README.en.md', `docs/RELEASE_NOTES_v${version}.en.md`],
162
- ['docs/README.md', `RELEASE_NOTES_v${version}.md`],
163
- ['docs/README.md', `RELEASE_NOTES_v${version}.en.md`],
164
- ['docs/README.en.md', `RELEASE_NOTES_v${version}.md`],
165
- ['docs/README.en.md', `RELEASE_NOTES_v${version}.en.md`],
166
- ['docs/CHANGELOG.md', `## v${version} `],
167
- ['docs/CHANGELOG.en.md', `## v${version} `],
168
- ['scripts/check-doc-links.mjs', `docs/RELEASE_NOTES_v${version}.md`],
169
- ['scripts/release-audit.mjs', `docs/RELEASE_NOTES_v${version}.md`],
170
- ['scripts/verify-github-repo.mjs', `docs/RELEASE_NOTES_v${version}.md`],
191
+ ['README.md', `docs/RELEASE_NOTES_v${stableVersion}.md`],
192
+ ['README.en.md', `docs/RELEASE_NOTES_v${stableVersion}.en.md`],
193
+ ['docs/README.md', `RELEASE_NOTES_v${stableVersion}.md`],
194
+ ['docs/README.md', `RELEASE_NOTES_v${stableVersion}.en.md`],
195
+ ['docs/README.en.md', `RELEASE_NOTES_v${stableVersion}.md`],
196
+ ['docs/README.en.md', `RELEASE_NOTES_v${stableVersion}.en.md`],
197
+ ['docs/CHANGELOG.md', `## v${stableVersion} `],
198
+ ['docs/CHANGELOG.en.md', `## v${stableVersion} `],
199
+ ['scripts/check-doc-links.mjs', `docs/RELEASE_NOTES_v${stableVersion}.md`],
200
+ ['scripts/release-audit.mjs', `docs/RELEASE_NOTES_v${stableVersion}.md`],
201
+ ['scripts/verify-github-repo.mjs', `docs/RELEASE_NOTES_v${stableVersion}.md`],
171
202
  ];
172
203
  for (const [file, expectedText] of referenceChecks) {
173
204
  const text = readText(root, file, findings);
174
205
  expectContains(text, expectedText, file, 'current release reference', findings);
175
206
  }
176
207
 
177
- return { version, expectedVersion, findings };
208
+ return { version, stableVersion, expectedVersion, isPrerelease, publishTag, findings };
178
209
  }
179
210
 
180
211
  function parseExpected(argv) {
@@ -191,8 +222,11 @@ function runCli() {
191
222
  process.exitCode = 1;
192
223
  return;
193
224
  }
194
- const ref = result.expectedVersion ? ` (release ref ${result.expectedVersion})` : '';
195
- console.log(`Release consistency check passed for ${result.version}${ref}.`);
225
+ const ref = result.expectedVersion ? `, release ref ${result.expectedVersion}` : '';
226
+ const channel = result.isPrerelease
227
+ ? `, stable release surface ${result.stableVersion}, npm tag ${result.publishTag}`
228
+ : `, npm tag ${result.publishTag || 'latest (default)'}`;
229
+ console.log(`Release consistency check passed for ${result.version}${channel}${ref}.`);
196
230
  }
197
231
 
198
232
  const entry = process.argv[1] ? pathToFileURL(resolve(process.argv[1])).href : '';
@@ -18,21 +18,54 @@ function createFixture() {
18
18
  mkdirSync(dirname(destination), { recursive: true });
19
19
  cpSync(source, destination);
20
20
  }
21
- const pkg = JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf8'));
21
+ const { stableVersion } = checkReleaseConsistency({ root: repoRoot });
22
22
  for (const suffix of ['.md', '.en.md']) {
23
- const source = resolve(repoRoot, `docs/RELEASE_NOTES_v${pkg.version}${suffix}`);
24
- const destination = resolve(root, `docs/RELEASE_NOTES_v${pkg.version}${suffix}`);
23
+ const source = resolve(repoRoot, `docs/RELEASE_NOTES_v${stableVersion}${suffix}`);
24
+ const destination = resolve(root, `docs/RELEASE_NOTES_v${stableVersion}${suffix}`);
25
25
  mkdirSync(dirname(destination), { recursive: true });
26
26
  cpSync(source, destination);
27
27
  }
28
28
  return root;
29
29
  }
30
30
 
31
+ function updateJson(root, relativePath, update) {
32
+ const path = resolve(root, relativePath);
33
+ const value = JSON.parse(readFileSync(path, 'utf8'));
34
+ update(value);
35
+ writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`);
36
+ }
37
+
31
38
  test('current release surface is internally consistent', () => {
32
39
  const result = checkReleaseConsistency({ root: repoRoot });
33
40
  assert.deepEqual(result.findings, []);
41
+ assert.equal(result.version, '0.3.2-rc.1');
42
+ assert.equal(result.stableVersion, '0.3.1');
43
+ assert.equal(result.publishTag, 'next');
34
44
  });
35
45
 
46
+ for (const [label, tag] of [
47
+ ['missing', undefined],
48
+ ['wrong', 'latest'],
49
+ ]) {
50
+ test(`RC ${label} next publish tag is rejected`, () => {
51
+ const root = createFixture();
52
+ try {
53
+ updateJson(root, 'package.json', (pkg) => {
54
+ if (tag === undefined) delete pkg.publishConfig;
55
+ else pkg.publishConfig = { tag };
56
+ });
57
+
58
+ const result = checkReleaseConsistency({ root });
59
+ assert.ok(
60
+ result.findings.some((finding) => finding.includes('prerelease versions must use publishConfig.tag "next"')),
61
+ result.findings.join('\n'),
62
+ );
63
+ } finally {
64
+ rmSync(root, { recursive: true, force: true });
65
+ }
66
+ });
67
+ }
68
+
36
69
  test('mismatched image tag is rejected before release', () => {
37
70
  const root = createFixture();
38
71
  try {
@@ -61,3 +94,25 @@ test('tag and package version mismatch is rejected', () => {
61
94
  );
62
95
  });
63
96
 
97
+ test('stable version cannot retain the next publish tag', () => {
98
+ const root = createFixture();
99
+ try {
100
+ const { stableVersion } = checkReleaseConsistency({ root });
101
+ updateJson(root, 'package.json', (pkg) => {
102
+ pkg.version = stableVersion;
103
+ pkg.publishConfig = { tag: 'next' };
104
+ });
105
+ updateJson(root, 'package-lock.json', (lock) => {
106
+ lock.version = stableVersion;
107
+ lock.packages[''].version = stableVersion;
108
+ });
109
+
110
+ const result = checkReleaseConsistency({ root });
111
+ assert.ok(
112
+ result.findings.some((finding) => finding.includes('stable versions may only use publishConfig.tag "latest" or omit it')),
113
+ result.findings.join('\n'),
114
+ );
115
+ } finally {
116
+ rmSync(root, { recursive: true, force: true });
117
+ }
118
+ });