dsh-postapi 0.0.0-stage → 0.0.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 (75) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +139 -2
  3. package/cordis.patch.yml +3 -0
  4. package/dist/client.js +5651 -0
  5. package/docs/DETAIL.md +27 -0
  6. package/docs/apifox-design-spec.md +101 -0
  7. package/docs/apifox-research/analysis.md +254 -0
  8. package/docs/apifox-ui-delivery.md +150 -0
  9. package/docs/apifox-visual-parity-spec.md +353 -0
  10. package/docs/feature-matrix.md +112 -0
  11. package/docs/flow-reference/sequence-reference.html +163 -0
  12. package/docs/interface-contract-v2.md +175 -0
  13. package/docs/interface-contract.md +105 -0
  14. package/docs/nav-layout-v2-spec.md +107 -0
  15. package/docs/preview.svg +9 -0
  16. package/docs/probe-client.legacy.js +31 -0
  17. package/docs/rootcause-sidebar-vanish.md +95 -0
  18. package/docs/rootcause.md +86 -0
  19. package/docs/sidebar-notes.md +153 -0
  20. package/docs/ui-audit.md +197 -0
  21. package/docs/ui-notes.md +98 -0
  22. package/docs/v2-delivery.md +99 -0
  23. package/icon.svg +4 -0
  24. package/index.js +5 -0
  25. package/locale/en.json +7 -0
  26. package/locale/zh.json +7 -0
  27. package/package.json +73 -4
  28. package/src/client/index.js +132 -0
  29. package/src/client/jsx-shim.js +9 -0
  30. package/src/client/pages/__tests__/heights.test.js +135 -0
  31. package/src/client/pages/components/AssertTable.jsx +122 -0
  32. package/src/client/pages/components/BodyEditor.jsx +91 -0
  33. package/src/client/pages/components/EmptyState.jsx +52 -0
  34. package/src/client/pages/components/FolderTree.jsx +109 -0
  35. package/src/client/pages/components/JsonEditor.jsx +45 -0
  36. package/src/client/pages/components/ParamTable.jsx +226 -0
  37. package/src/client/pages/components/ResponsePanel.jsx +278 -0
  38. package/src/client/pages/components/ScriptPanel.jsx +99 -0
  39. package/src/client/pages/components/StatusPill.jsx +35 -0
  40. package/src/client/pages/components/__tests__/apifox-ui.test.js +291 -0
  41. package/src/client/pages/components/__tests__/pages-a.test.js +392 -0
  42. package/src/client/pages/components/__tests__/tree.test.js +379 -0
  43. package/src/client/pages/components/headerPresets.js +63 -0
  44. package/src/client/pages/debug.jsx +576 -0
  45. package/src/client/pages/design-tokens.css +2604 -0
  46. package/src/client/pages/doc.jsx +552 -0
  47. package/src/client/pages/env.jsx +378 -0
  48. package/src/client/pages/flow.jsx +349 -0
  49. package/src/client/pages/history.jsx +238 -0
  50. package/src/client/pages/import.jsx +396 -0
  51. package/src/client/pages/mock.jsx +316 -0
  52. package/src/client/pages/overview.jsx +348 -0
  53. package/src/client/pages/schema.jsx +317 -0
  54. package/src/client/pages/search.jsx +216 -0
  55. package/src/client/pages/sequence.jsx +344 -0
  56. package/src/client/pages/settings.jsx +205 -0
  57. package/src/client/pages/test.jsx +470 -0
  58. package/src/client/pages/theme.js +27 -0
  59. package/src/client/pages-entry.js +20 -0
  60. package/src/client/shell/ApiTitle.js +19 -0
  61. package/src/client/shell/Body.js +492 -0
  62. package/src/client/shell/definition.js +57 -0
  63. package/src/client/shell/locales.js +185 -0
  64. package/src/client/shell/menu.js +174 -0
  65. package/src/client/shell/registry.js +530 -0
  66. package/src/host/bridge.js +407 -0
  67. package/src/host/codegen.js +356 -0
  68. package/src/host/import-export.js +1044 -0
  69. package/src/host/index.js +102 -0
  70. package/src/host/mock-server.js +303 -0
  71. package/src/host/request.js +336 -0
  72. package/src/host/script-sandbox.js +272 -0
  73. package/src/host/storage.js +803 -0
  74. package/src/host/test-runner.js +126 -0
  75. package/src/host/variables.js +108 -0
@@ -0,0 +1,99 @@
1
+ // ScriptPanel — 调试台「脚本」页签:前置脚本 / 后置脚本 / 断言 / 等待时间
2
+ // 受控组件:value = { preScript, postScript, assertions, waitMs }。
3
+ // 任何一处改动都回传**完整新 value 对象**(debug.jsx 用 setDraft(prev => ({ ...prev, ...next }))
4
+ // 直接合并,所以这里不能传 patch)。
5
+ // 断言表抽在 AssertTable.jsx:ScriptPanel 内部复用它,同时对外导出常量供测试单独断言。
6
+ import { AssertTable, ASSERT_SOURCES, ASSERT_OPS } from './AssertTable.jsx'
7
+
8
+ export { ASSERT_SOURCES, ASSERT_OPS }
9
+
10
+ /** 空 value:缺字段时按此兜底,组件永远拿到四种字段齐全的对象。 */
11
+ export const EMPTY_SCRIPT_VALUE = { preScript: '', postScript: '', assertions: [], waitMs: 0 }
12
+
13
+ /** 归一化:外部数据可能缺字段或类型不对,统一收敛成契约形状。 */
14
+ function normalize(value) {
15
+ const v = value || {}
16
+ return {
17
+ preScript: v.preScript == null ? '' : String(v.preScript),
18
+ postScript: v.postScript == null ? '' : String(v.postScript),
19
+ assertions: Array.isArray(v.assertions) ? v.assertions : [],
20
+ waitMs: Number.isFinite(v.waitMs) ? v.waitMs : 0,
21
+ }
22
+ }
23
+
24
+ /** 等待时间只收非负整数(输入框里粘贴带单位/字母的串也要能吃掉)。 */
25
+ function parseWait(text) {
26
+ const digits = String(text == null ? '' : text).replace(/[^0-9]/g, '')
27
+ return digits === '' ? 0 : Number(digits)
28
+ }
29
+
30
+ /**
31
+ * @param value 当前值 { preScript, postScript, assertions, waitMs }
32
+ * @param onChange 收到完整新 value 对象
33
+ */
34
+ export function ScriptPanel({ value, onChange }) {
35
+ const current = normalize(value)
36
+ const emit = (next) => {
37
+ if (typeof onChange === 'function') onChange({ ...current, ...next })
38
+ }
39
+
40
+ return (
41
+ <div>
42
+ <div className="pp-script-block">
43
+ <div className="pp-group-head">
44
+ <span className="pp-group-title">前置脚本</span>
45
+ </div>
46
+ <textarea
47
+ className="pp-textarea pp-input-mono"
48
+ rows={6}
49
+ placeholder="// 请求发送前执行"
50
+ value={current.preScript}
51
+ onChange={(e) => emit({ preScript: e.target.value })}
52
+ />
53
+ <p className="pp-meta">可用 pm.request / pm.environment.set / console.log</p>
54
+ </div>
55
+
56
+ <div className="pp-script-block">
57
+ <div className="pp-group-head">
58
+ <span className="pp-group-title">后置脚本</span>
59
+ </div>
60
+ <textarea
61
+ className="pp-textarea pp-input-mono"
62
+ rows={6}
63
+ placeholder="// 响应返回后执行"
64
+ value={current.postScript}
65
+ onChange={(e) => emit({ postScript: e.target.value })}
66
+ />
67
+ <p className="pp-meta">可用 pm.response / pm.test / pm.globals.set</p>
68
+ </div>
69
+
70
+ <div className="pp-script-block">
71
+ <div className="pp-group-head">
72
+ <span className="pp-group-title">断言</span>
73
+ </div>
74
+ <div className="pp-table-wrap">
75
+ <AssertTable rows={current.assertions} onChange={(rows) => emit({ assertions: rows })} />
76
+ </div>
77
+ </div>
78
+
79
+ <div className="pp-script-block">
80
+ <div className="pp-group-head">
81
+ <span className="pp-group-title">等待时间</span>
82
+ </div>
83
+ <div className="pp-form-row">
84
+ <label className="pp-form-label" htmlFor="pp-wait-ms">等待</label>
85
+ <input
86
+ id="pp-wait-ms"
87
+ className="pp-input pp-input-sm"
88
+ type="number"
89
+ min="0"
90
+ step="100"
91
+ value={String(current.waitMs)}
92
+ onChange={(e) => emit({ waitMs: parseWait(e.target.value) })}
93
+ />
94
+ <span className="pp-meta">ms · 发送前等待</span>
95
+ </div>
96
+ </div>
97
+ </div>
98
+ )
99
+ }
@@ -0,0 +1,35 @@
1
+ // StatusPill — 响应状态胶囊(Apifox .pp-pill 三档:pp-pill-ok / pp-pill-warn / pp-pill-bad)
2
+ // 色阶完全由 CSS 类承载(1px 同色边框 + 同色文字、无底色),组件不写任何内联颜色。
3
+
4
+ /** 状态码 → token 色阶。保留旧契约:返回 var(--*) 字符串,供需要色值的调用方。 */
5
+ export function statusTone(status) {
6
+ const code = Number(status)
7
+ if (!Number.isFinite(code) || code <= 0) return 'var(--error)'
8
+ if (code < 300) return 'var(--success)'
9
+ if (code < 400) return 'var(--warning)'
10
+ return 'var(--error)'
11
+ }
12
+
13
+ /** 状态码 → .pp-pill 修饰类(Apifox 三档:2xx 绿 / 3xx 橙 / 其余红)。 */
14
+ export function statusToneClass(status) {
15
+ const code = Number(status)
16
+ if (!Number.isFinite(code) || code <= 0) return 'pp-pill-bad'
17
+ if (code < 300) return 'pp-pill-ok'
18
+ if (code < 400) return 'pp-pill-warn'
19
+ return 'pp-pill-bad'
20
+ }
21
+
22
+ /** tone 兼容层:接受 ok/warn/bad/accent 短名或完整 .pp-pill-* 类名。 */
23
+ const TONE_ALIAS = { ok: 'pp-pill-ok', warn: 'pp-pill-warn', bad: 'pp-pill-bad', accent: 'pp-pill-accent' }
24
+
25
+ export function StatusPill({ status, text = '', tone }) {
26
+ const cls = tone
27
+ ? TONE_ALIAS[tone] || (String(tone).indexOf('pp-pill') === 0 ? String(tone) : statusToneClass(status))
28
+ : statusToneClass(status)
29
+ return (
30
+ <span className={'pp-pill ' + cls}>
31
+ {status == null || status === '' ? '-' : String(status)}
32
+ {text ? ' ' + text : ''}
33
+ </span>
34
+ )
35
+ }
@@ -0,0 +1,291 @@
1
+ // apifox-ui.test.js — Apifox 化改造专项断言(doc / debug 两页 + 四个共用组件)
2
+ // 双模式:node 直跑(mini runner),或由 pages-a.test.js 展开收录进 tests/run.js。
3
+ // 只做静态结构与纯函数行为断言,不引 react-dom。
4
+ import { readFileSync, existsSync } from 'node:fs'
5
+ import { fileURLToPath } from 'node:url'
6
+ import { dirname, join, resolve } from 'node:path'
7
+ import { createRequire } from 'node:module'
8
+ import vm from 'node:vm'
9
+
10
+ const __dirname = dirname(fileURLToPath(import.meta.url))
11
+ const COMPONENTS_DIR = resolve(__dirname, '..')
12
+ const PAGES_DIR = resolve(COMPONENTS_DIR, '..')
13
+ const ROOT = resolve(PAGES_DIR, '..', '..', '..')
14
+
15
+ const FILE = {
16
+ doc: join(PAGES_DIR, 'doc.jsx'),
17
+ tree: join(COMPONENTS_DIR, 'FolderTree.jsx'),
18
+ debug: join(PAGES_DIR, 'debug.jsx'),
19
+ responsePanel: join(COMPONENTS_DIR, 'ResponsePanel.jsx'),
20
+ bodyEditor: join(COMPONENTS_DIR, 'BodyEditor.jsx'),
21
+ scriptPanel: join(COMPONENTS_DIR, 'ScriptPanel.jsx'),
22
+ paramTable: join(COMPONENTS_DIR, 'ParamTable.jsx'),
23
+ jsonEditor: join(COMPONENTS_DIR, 'JsonEditor.jsx'),
24
+ statusPill: join(COMPONENTS_DIR, 'StatusPill.jsx'),
25
+ emptyState: join(COMPONENTS_DIR, 'EmptyState.jsx'),
26
+ }
27
+
28
+ const read = (file) => (existsSync(file) ? readFileSync(file, 'utf8') : '')
29
+ const assert = (cond, message) => { if (!cond) throw new Error(message) }
30
+
31
+ /** 出现次数(用于断言「至少 N 处」)。 */
32
+ const count = (src, needle) => String(src).split(needle).length - 1
33
+
34
+ function loadEsbuild() {
35
+ for (const dir of [ROOT, join(ROOT, '.research', 'sidebar')]) {
36
+ if (existsSync(join(dir, 'node_modules', 'esbuild'))) {
37
+ return createRequire(join(dir, 'noop.js'))('esbuild')
38
+ }
39
+ }
40
+ throw new Error('esbuild 不可用(工作区与 .research/sidebar 均未安装)')
41
+ }
42
+
43
+ const fakeReact = {
44
+ createElement: (type, props, ...children) => ({ type, props, children }),
45
+ Fragment: 'Fragment',
46
+ useState: (v) => [typeof v === 'function' ? v() : v, () => {}],
47
+ useEffect: () => {},
48
+ useRef: (v) => ({ current: v }),
49
+ useMemo: (fn) => fn(),
50
+ useCallback: (fn) => fn(),
51
+ useLayoutEffect: () => {},
52
+ }
53
+
54
+ async function loadModule(file) {
55
+ const esbuild = loadEsbuild()
56
+ const built = await esbuild.build({
57
+ entryPoints: [file],
58
+ bundle: true,
59
+ write: false,
60
+ format: 'cjs',
61
+ platform: 'browser',
62
+ target: ['es2022'],
63
+ jsx: 'transform',
64
+ // 与 build.mjs 一致:classic runtime + 显式工厂,否则默认产出 React.createElement 而宿主只给 createElement
65
+ jsxFactory: 'createElement',
66
+ jsxFragment: 'Fragment',
67
+ inject: [join(ROOT, 'src', 'client', 'jsx-shim.js')],
68
+ loader: { '.js': 'jsx' },
69
+ external: ['react'],
70
+ logLevel: 'silent',
71
+ })
72
+ const module = { exports: {} }
73
+ const sandbox = {
74
+ window: { __postapiQueue: [] },
75
+ module,
76
+ exports: module.exports,
77
+ console,
78
+ require: (name) => {
79
+ if (name === 'react') return fakeReact
80
+ throw new Error('意外的宿主 require: ' + name)
81
+ },
82
+ }
83
+ vm.createContext(sandbox)
84
+ vm.runInContext(built.outputFiles[0].text, sandbox, { filename: file })
85
+ return module.exports
86
+ }
87
+
88
+ /** 方法徽标必须全部带 data-method(Apifox 白字彩底靠属性选择器上色)。 */
89
+ function bareMethodBadges(src) {
90
+ const bad = []
91
+ const re = /<span className="pp-method"(?![^>]*data-method)/g
92
+ let m
93
+ while ((m = re.exec(src))) bad.push(src.slice(0, m.index).split('\n').length)
94
+ return bad
95
+ }
96
+
97
+ export const tests = [
98
+ {
99
+ name: 'apifox-ui: doc 页 v2 骨架(面板树 + 主列 + 顶部锚点条,无右栏)',
100
+ fn() {
101
+ const src = read(FILE.doc)
102
+ // v2:左树改面板 .pp-panel,右 TOC 改成主区顶部 sticky 锚点条 .pp-anchor-bar
103
+ for (const cls of ['pp-split', 'pp-panel', 'pp-doc-main', 'pp-anchor-bar']) {
104
+ assert(src.includes(cls), 'doc.jsx 缺 v2 骨架类 ' + cls)
105
+ }
106
+ // 右栏常驻 TOC 必须彻底消失:它会在窄容器里吃掉 240px
107
+ for (const cls of ['pp-col-right', 'pp-body-3col', 'pp-toc']) {
108
+ assert(!src.includes(cls), 'doc.jsx 不应再出现 ' + cls + '(v2 已改锚点条)')
109
+ }
110
+ // 多级目录树已抽成 FolderTree 组件(递归 parentId),doc.jsx 只负责挂载
111
+ assert(src.includes('FolderTree'), 'doc.jsx 未挂载 FolderTree 多级目录树')
112
+ assert(!src.includes('className="pp-tree"'), 'doc.jsx 不应再手写树(已抽 FolderTree)')
113
+ const treeSrc = read(FILE.tree)
114
+ for (const cls of ['pp-tree', 'pp-tree-group', 'pp-tree-row', 'pp-tree-row-count']) {
115
+ assert(treeSrc.includes(cls), 'FolderTree.jsx 缺 ' + cls)
116
+ }
117
+ for (const cls of ['pp-anchor-chip']) {
118
+ assert(src.includes(cls), 'doc.jsx 锚点条缺 ' + cls)
119
+ }
120
+ for (const cls of ['pp-doc-h1', 'pp-doc-section', 'pp-doc-h2']) {
121
+ assert(src.includes(cls), 'doc.jsx 主区缺 ' + cls)
122
+ }
123
+ assert(count(src, 'pp-doc-section') >= 7, 'doc.jsx 分区数量不足(Path/Query/Headers/Cookies/Body/Auth/Response/Code)')
124
+ },
125
+ },
126
+ {
127
+ name: 'apifox-ui: doc / debug 方法徽标全部带 data-method(无裸 .pp-method)',
128
+ fn() {
129
+ for (const [label, file] of [['doc', FILE.doc], ['debug', FILE.debug]]) {
130
+ const bad = bareMethodBadges(read(file))
131
+ assert(bad.length === 0, label + '.jsx 第 ' + bad.join(',') + ' 行方法徽标缺 data-method')
132
+ }
133
+ },
134
+ },
135
+ {
136
+ name: 'apifox-ui: doc 页复制 cURL 用 .pp-btn-sm 且成功提示走 .pp-note-ok',
137
+ fn() {
138
+ const src = read(FILE.doc)
139
+ assert(src.includes('复制为 cURL'), 'doc.jsx 缺「复制为 cURL」按钮')
140
+ assert(/className="pp-btn pp-btn-sm"[^>]*onClick=\{copyCurl\}|onClick=\{copyCurl\}/.test(src), 'doc.jsx 复制按钮未用 pp-btn-sm')
141
+ assert(src.includes('pp-note-ok'), 'doc.jsx 复制成功提示未用 pp-note-ok')
142
+ },
143
+ },
144
+ {
145
+ name: 'apifox-ui: debug 页 Apifox 调试台结构(URL 行 / 页签 / 响应面板 / 断言表)',
146
+ fn() {
147
+ const src = read(FILE.debug)
148
+ // 页面本体:URL 行 + 请求页签 + 上下分栏 + 发送按钮
149
+ for (const cls of ['pp-url-row', 'pp-tabs', 'pp-tab', 'pp-pane', 'pp-debug-split', 'pp-debug-request', 'pp-debug-response', 'pp-btn-primary']) {
150
+ assert(src.includes(cls), 'debug.jsx 缺 ' + cls)
151
+ }
152
+ assert(src.includes('data-active={tab === t.id}'), 'debug.jsx 页签缺 data-active 切换')
153
+ assert(src.includes('pp-meta'), 'debug.jsx 耗时/大小未用 pp-meta')
154
+ // 响应面板已抽成组件:结构断言落到组件源码,不再要求页面内出现
155
+ assert(src.includes('ResponsePanel'), 'debug.jsx 未使用 ResponsePanel')
156
+ assert(src.includes('BodyEditor'), 'debug.jsx 未使用 BodyEditor')
157
+ assert(src.includes('ScriptPanel'), 'debug.jsx 未使用 ScriptPanel')
158
+ const respSrc = read(FILE.responsePanel)
159
+ for (const cls of ['pp-pre', 'pp-pre-scroll', 'pp-table', 'pp-table-wrap', 'pp-pill', 'pp-resp-bar', 'pp-resp-tabs']) {
160
+ assert(respSrc.includes(cls), 'ResponsePanel.jsx 缺 ' + cls)
161
+ }
162
+ assert(respSrc.includes('data-active={bodyView ==='), 'ResponsePanel.jsx 响应体美化/原文页签缺 data-active')
163
+ assert(respSrc.includes('测试结果'), 'ResponsePanel.jsx 缺「测试结果」页签')
164
+ assert(respSrc.includes('控制台'), 'ResponsePanel.jsx 缺「控制台」页签')
165
+ // 断言编辑器在 ScriptPanel 里
166
+ const scriptSrc = read(FILE.scriptPanel)
167
+ for (const word of ['前置脚本', '后置脚本', '断言', '等待']) {
168
+ assert(scriptSrc.includes(word), 'ScriptPanel.jsx 缺「' + word + '」段落')
169
+ }
170
+ },
171
+ },
172
+ {
173
+ name: 'apifox-ui: ParamTable 走 .pp-table 且可编辑单元格用 .pp-input-sm',
174
+ fn() {
175
+ const src = read(FILE.paramTable)
176
+ assert(/className="pp-table[ "]/.test(src), 'ParamTable.jsx 未用 .pp-table')
177
+ assert(src.includes('pp-input-sm'), 'ParamTable.jsx 可编辑单元格未用 .pp-input-sm')
178
+ assert(!src.includes('className="pp-input pp-input-mono"'), 'ParamTable.jsx 仍在用旧 pp-input 编辑单元格')
179
+ assert(src.includes('EmptyState'), 'ParamTable.jsx 空态未走 EmptyState')
180
+ assert(src.includes('emptyHint'), 'ParamTable.jsx 缺 emptyHint 透传')
181
+ },
182
+ },
183
+ {
184
+ name: 'apifox-ui: JsonEditor 走 .pp-json-editor,校验提示走 .pp-error-text',
185
+ fn() {
186
+ const src = read(FILE.jsonEditor)
187
+ assert(src.includes('pp-json-editor'), 'JsonEditor.jsx 未用 .pp-json-editor')
188
+ assert(src.includes('pp-error-text'), 'JsonEditor.jsx 校验提示未用 .pp-error-text')
189
+ assert(!/style=\{\{[^}]*height:/.test(src), 'JsonEditor.jsx 不应内联 height(交给 .pp-json-editor)')
190
+ assert(src.includes('pp-btn-sm'), 'JsonEditor.jsx 工具按钮未用 pp-btn-sm')
191
+ },
192
+ },
193
+ {
194
+ name: 'apifox-ui: StatusPill 三档 .pp-pill-ok/warn/bad 且不写内联颜色',
195
+ fn() {
196
+ const src = read(FILE.statusPill)
197
+ for (const cls of ['pp-pill-ok', 'pp-pill-warn', 'pp-pill-bad']) {
198
+ assert(src.includes(cls), 'StatusPill.jsx 缺 ' + cls)
199
+ }
200
+ assert(!/style=\{\{/.test(src), 'StatusPill.jsx 仍写内联 style(颜色应由类承载)')
201
+ assert(src.includes('statusToneClass'), 'StatusPill.jsx 缺 statusToneClass 导出')
202
+ },
203
+ },
204
+ {
205
+ name: 'apifox-ui: EmptyState 用 .pp-empty,hint 行走 .pp-meta',
206
+ fn() {
207
+ const src = read(FILE.emptyState)
208
+ assert(src.includes('pp-empty'), 'EmptyState.jsx 未用 .pp-empty')
209
+ assert(src.includes('pp-meta'), 'EmptyState.jsx hint 未用 .pp-meta')
210
+ },
211
+ },
212
+ {
213
+ name: 'apifox-ui: statusToneClass 三档分级(2xx 绿 / 3xx 橙 / 其余红)',
214
+ async fn() {
215
+ const exports = await loadModule(FILE.statusPill)
216
+ assert(typeof exports.statusToneClass === 'function', 'StatusPill.jsx 未导出 statusToneClass')
217
+ assert(exports.statusToneClass(200) === 'pp-pill-ok', '200 应为 pp-pill-ok')
218
+ assert(exports.statusToneClass(204) === 'pp-pill-ok', '204 应为 pp-pill-ok')
219
+ assert(exports.statusToneClass(302) === 'pp-pill-warn', '302 应为 pp-pill-warn')
220
+ assert(exports.statusToneClass(404) === 'pp-pill-bad', '404 应为 pp-pill-bad')
221
+ assert(exports.statusToneClass(500) === 'pp-pill-bad', '500 应为 pp-pill-bad')
222
+ assert(exports.statusToneClass(0) === 'pp-pill-bad', '0 应为 pp-pill-bad')
223
+ assert(exports.statusToneClass(undefined) === 'pp-pill-bad', 'undefined 应为 pp-pill-bad')
224
+ // 旧契约保留:statusTone 仍返回 var(--*) 色值
225
+ assert(exports.statusTone(200) === 'var(--success)', 'statusTone 契约变更(应仍返回 var(--success))')
226
+ },
227
+ },
228
+ {
229
+ name: 'apifox-ui: StatusPill 渲染 pp-pill + 三档类,tone 兼容短名',
230
+ async fn() {
231
+ const exports = await loadModule(FILE.statusPill)
232
+ const ok = exports.StatusPill({ status: 200, text: 'OK' })
233
+ assert(ok.props.className === 'pp-pill pp-pill-ok', 'StatusPill 默认类不正确:' + ok.props.className)
234
+ const warn = exports.StatusPill({ status: 200, tone: 'warn' })
235
+ assert(warn.props.className === 'pp-pill pp-pill-warn', 'tone 短名未映射:' + warn.props.className)
236
+ const bad = exports.StatusPill({ status: 0, tone: 'pp-pill-bad' })
237
+ assert(bad.props.className === 'pp-pill pp-pill-bad', 'tone 全类名未透传:' + bad.props.className)
238
+ assert(bad.props.style === undefined, 'StatusPill 不应输出内联 style')
239
+ },
240
+ },
241
+ {
242
+ name: 'apifox-ui: ParamTable 只读渲染 pp-table 表头列与空态',
243
+ async fn() {
244
+ const exports = await loadModule(FILE.paramTable)
245
+ const table = exports.ParamTable({ rows: [{ key: 'page', value: '1', type: 'number', required: false, enabled: true, description: '' }], readOnly: true })
246
+ assert(String(table.props.className).split(/\s+/).includes('pp-table'), 'ParamTable 根缺 .pp-table')
247
+ const thead = table.children[0]
248
+ assert(thead.type === 'thead', '第一子节点不是 thead')
249
+ // columns.map 作为单个 JSX 子表达式传入,children 里是一层数组,需要 flat 展开
250
+ const ths = thead.children[0].children.flat(Infinity).filter(Boolean)
251
+ assert(ths.length === 6, '默认六列不符:' + ths.length)
252
+ const secondTitle = ths[1].children.flat(Infinity).filter((v) => typeof v === 'string').join('')
253
+ assert(secondTitle === '参数', '第二列表头应为「参数」:' + secondTitle)
254
+ const empty = exports.ParamTable({ rows: [], readOnly: true, emptyText: '无参数', emptyHint: '提示' })
255
+ assert(typeof empty.type === 'function', 'ParamTable 空态未渲染 EmptyState 组件')
256
+ assert(empty.props.text === '无参数' && empty.props.hint === '提示', '空态文案未透传:' + JSON.stringify(empty.props))
257
+ const emptyNode = empty.type(empty.props)
258
+ assert(emptyNode.props.className === 'pp-empty', '空态根类不是 .pp-empty')
259
+ assert(exports.blankParamRow().type === 'string', 'blankParamRow 模板类型不符')
260
+ },
261
+ },
262
+ ]
263
+
264
+ /* ---------------- mini runner ---------------- */
265
+
266
+ const isMain = (() => {
267
+ try {
268
+ const argv1 = process.argv[1]
269
+ return Boolean(argv1) && resolve(argv1) === fileURLToPath(import.meta.url)
270
+ } catch {
271
+ return false
272
+ }
273
+ })()
274
+
275
+ if (isMain) {
276
+ let passed = 0
277
+ let failed = 0
278
+ for (const t of tests) {
279
+ try {
280
+ await t.fn()
281
+ passed += 1
282
+ console.log('PASS ' + t.name)
283
+ } catch (err) {
284
+ failed += 1
285
+ console.log('FAIL ' + t.name)
286
+ console.log(' ' + (err && err.message ? err.message : err))
287
+ }
288
+ }
289
+ console.log('\napifox-ui.test:通过 ' + passed + ',失败 ' + failed + ',共 ' + (passed + failed))
290
+ process.exit(failed === 0 ? 0 : 1)
291
+ }