@jieay/dsh-tester 0.1.1 → 0.1.7

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/README.md CHANGED
@@ -60,9 +60,37 @@ web_flow({
60
60
  })
61
61
  ```
62
62
 
63
- `web_audit` 对每个页面返回:主文档状态码、标题、`ok`、是否白屏(`whiteScreen`)、命中的框架错误覆盖层、console 错误、页面异常、失败请求、HTTP ≥ 400 的响应、截图路径,以及被截断的证据条数。`web_flow` 返回每一步的通过/失败,加上同样的页面证据和失败截图。
63
+ `web_audit` 对每个页面返回:主文档状态码、实际落点 `finalUrl`、标题、`ok`、是否白屏(`whiteScreen`)、
64
+ 是否跳到登录页(`redirectedToLogin`)、命中的框架错误覆盖层、console 错误、页面异常、失败请求、
65
+ HTTP ≥ 400 的响应、截图路径,以及被截断的证据条数。
64
66
 
65
- 截图和一份 JSON 证据副本会写到会话工作目录下的 `.dsh-tester/<audit|flow>-<时间戳>/`。
67
+ > **`setupSteps` 必须以真实验证结尾。** 只写 `waitFor body` 这类恒成立的等待,登录还没完成就导航走了,
68
+ > 审计会在未登录状态下跑完,把登录页当业务页报「通过」。用 `expectUrl` 指向登录后的地址最稳妥;
69
+ > 一旦报告里出现「跳到登录页」,说明这次审计无效。`web_flow` 返回每一步的通过/失败,加上同样的页面证据和失败截图。
70
+
71
+ 插件在**项目根目录**下只占用一个 `.dsh-tester/` 文件夹,所有产物按类型归类,不会把项目目录搅乱:
72
+
73
+ ```text
74
+ <项目目录>/
75
+ └── .dsh-tester/
76
+ └── test-reports/
77
+ ├── 2026-12-04_13-44-20_audit/
78
+ │ ├── report.md ← 可直接阅读的报告
79
+ │ ├── audit.json ← 完整结构化证据
80
+ │ ├── 192.168.192.25_index.php_m_my_f_index_98db71.png
81
+ │ └── 192.168.192.25_index.php_m_qa_f_index_505bfd.png
82
+ └── 2026-12-04_13-45-01_flow/
83
+ ├── report.md
84
+ ├── flow.json
85
+ └── final.png
86
+ ```
87
+
88
+ 文件夹名是「本地开始时间 + 测试类型」,截图文件名包含该页面的完整路由(含 query),所以
89
+ `index.php?m=my&f=index` 和 `index.php?m=bug&f=browse` 不会互相覆盖。
90
+
91
+ **每次运行都会写一份 `report.md`**:结论表格、失败页面证据、以及内嵌的截图(相对路径,
92
+ 在 VSCode、Typora 或代码托管页面上可以直接预览)。不打开 DSH 也能翻历史报告,
93
+ 需要归档时把某个文件夹整个提交或附到工单里即可。
66
94
 
67
95
  ## 浏览器依赖
68
96
 
@@ -81,7 +109,7 @@ web_flow({
81
109
 
82
110
  | 配置 | 默认 | 含义 |
83
111
  | --- | --- | --- |
84
- | `artifactsDir` | `.dsh-tester` | 证据目录,相对会话工作目录 |
112
+ | `artifactsDir` | `.dsh-tester/test-reports` | 证据根目录,相对会话工作目录;每次运行在其下建时间戳子目录 |
85
113
  | `channel` | 自动 | 优先使用的浏览器通道:`chrome`、`chrome-beta`、`msedge`、`chromium` |
86
114
  | `headless` | `true` | 无头运行;设为 `false` 可以看它真的在点页面 |
87
115
  | `settleMs` | `1200` | 每次导航后等待客户端渲染的静默期 |
@@ -103,6 +131,14 @@ pnpm test # 启动本地夹具服务,在真实浏览器里跑这两个工
103
131
 
104
132
  测试针对 `test/fixture.mjs`——一个故意做坏的迷你应用(一个正常页面、一个抛错导致白屏的页面、一个接口返回 500 的页面、一个登录表单)。CI 每次推送都跑同一套。
105
133
 
134
+ ### 两条硬规则
135
+
136
+ 本项目的定位是「前端必须用真实浏览器验证」:
137
+
138
+ 1. **禁止用 curl / wget / HTTP 请求代替浏览器检查。** 服务端返回 200 而页面白屏、JS 报错、按钮无响应
139
+ 的情况非常常见——HTTP 状态码不能证明前端可用。只读取证可以用 HTTP 请求,但不能据此得结论。
140
+ 2. **每次前端测试必须留截图。** 这是判断「页面到底长什么样」的唯一可靠证据。
141
+
106
142
  ### 两条必须知道的约束
107
143
 
108
144
  1. **插件不导入任何 `@deepseek-ai/*`。** 以 `link:` 方式安装的工作区 bundle,Node 会按真实路径解析,`@deepseek-ai/*` 无法解析,激活时报 `tester-tools ...: never started`。工具 schema 因此预编译在 `lib/schemas.json`,改动时直接维护这个文件,不要指望运行时 `import`。
package/cordis.patch.yml CHANGED
@@ -54,8 +54,19 @@
54
54
  - console.error 有报错但页面可用 → 风险项,逐条列出并说明影响。
55
55
  - 只做了接口测试、没做浏览器验证 → 不能下「前端没问题」的结论。
56
56
 
57
+ ## 两条硬规则(不得违反)
58
+ 1. 前端必须用真实浏览器验证。禁止用 curl、wget、httpx、fetch 之类的 HTTP 请求代替浏览器检查,
59
+ 也禁止根据 HTTP 状态码推断「前端正常」。服务端返回 200 但页面白屏、JS 报错、按钮无响应的情况非常常见。
60
+ 例外:只读取证可以用 HTTP 请求,但不能据此下前端结论。
61
+ 2. 前端测试必须留截图。每次测试都在项目目录下生成一个带时间戳的文件夹
62
+ (默认 `.dsh-tester/test-reports/<日期>_<时间>_<audit|flow>/`),里面必须包含每个页面的截图和一份 JSON 证据。
63
+ 报告里给出该文件夹的绝对路径,供人工复核。
64
+
57
65
  ## 工具纪律
58
66
  - web_audit:传 baseUrl + 相对路径数组;需要登录时先传 setupSteps 登录,之后的审计复用同一浏览器会话。
67
+ **setupSteps 的最后一步必须是真实验证**(如 `expectUrl` 指向登录后的地址,或 `expectVisible` 指向只有登录后才有的元素)。
68
+ 只写 `waitFor` 任何元素(尤其 `body`)会立即通过,导致审计在未登录状态下跑、把登录页当业务页报「通过」。
69
+ - 报告里如果出现「跳到登录页」,说明本次审计无效,必须修正 setupSteps 后重跑。
59
70
  - web_flow:steps 按顺序执行。点击用 role=button[name="登录"] 或 button:has-text("登录");不要用 text=登录,它可能命中标题而不是按钮。
60
71
  - 断言优先等元素(expectVisible / expectText 会轮询),不要用固定 wait 猜时间。
61
72
  - 报告必须给出截图路径,便于人工复核。
@@ -99,7 +110,7 @@
99
110
  - id: tester-tools
100
111
  name: '@jieay/dsh-tester'
101
112
  config:
102
- artifactsDir: .dsh-tester
113
+ artifactsDir: .dsh-tester/test-reports
103
114
  # 默认无头运行,行为可预测、不弹窗;想亲眼看它点页面时,
104
115
  # 让模型在调用里传 headless=false,或把这里改成 false。
105
116
  headless: true
package/docs/DETAIL.md CHANGED
@@ -20,7 +20,7 @@
20
20
  | 证据 | 说明 |
21
21
  | --- | --- |
22
22
  | 主文档 HTTP 状态 | 4xx/5xx 直接是路由或代理配置问题 |
23
- | 渲染判定 | **白屏**(无正文且根容器无子节点)、**框架错误覆盖层**(Vite / Next / Nuxt / Angular) |
23
+ | 渲染判定 | **白屏**(正文少于 20 字且根容器无子节点)、**框架错误覆盖层**(Vite / Next / Nuxt / Angular);正文统计包含所有子 frame |
24
24
  | `console.error` | 往往是唯一可见的故障症状 |
25
25
  | 未捕获异常 | 通常意味着应用根本没挂载起来 |
26
26
  | 请求失败 | DNS、TLS、CORS、abort |
@@ -52,6 +52,9 @@ web_flow({
52
52
 
53
53
  失败时自动截图并保留当时的页面证据,不会因为一步失败就丢掉整个报告。
54
54
 
55
+ iframe 说明:服务端渲染应用常把业务界面装在 iframe 里。`web_flow` 的选择器会跨 frame 查找,
56
+ `expectText` 不带 target 时汇总所有 frame 的文本。但**跨域 iframe** 仍不可操作(浏览器安全限制)。
57
+
55
58
  选择器说明:`target` 就是 Playwright 选择器,`#id`、`.class`、`role=button[name="登录"]`、
56
59
  `button:has-text("登录")` 都可以。注意 `text=登录` 可能命中标题而不是按钮,点击类操作优先用
57
60
  `role=` 或 `:has-text()`。
@@ -72,7 +75,21 @@ web_flow({
72
75
 
73
76
  ## 产物位置
74
77
 
75
- 截图和 JSON 证据写到会话工作目录下的 `.dsh-tester/<audit|flow>-<时间戳>/`。
78
+ 插件在项目根目录下只创建一个 `.dsh-tester/` 目录,按用途分类存放:
79
+
80
+ ```text
81
+ .dsh-tester/
82
+ └── test-reports/
83
+ └── <日期>_<时间>_<audit|flow>/
84
+ ├── report.md 可直接阅读的报告(内嵌截图)
85
+ ├── audit.json 完整结构化证据
86
+ └── <host>_<path>_<query>_<hash>.png 每页一张截图
87
+ ```
88
+
89
+ 每次运行一个独立文件夹,不会覆盖历史结果。`report.md` 里的截图使用相对路径,
90
+ 所以整个文件夹可以单独移动、归档或提交进工单,不会失效。`.dsh-tester/` 下后续还会放文档类报告,
91
+ 所以建议把它整体加入 `.gitignore`(本插件的 `.gitignore` 模板已默认包含)。截图文件名包含完整路由(含 query),
92
+ 同名路径的页面不会互相覆盖。
76
93
  每份报告末尾都会给出证据目录的绝对路径。
77
94
 
78
95
  ## 浏览器依赖
@@ -87,7 +104,7 @@ web_flow({
87
104
 
88
105
  | 配置 | 默认 | 说明 |
89
106
  | --- | --- | --- |
90
- | `artifactsDir` | `.dsh-tester` | 证据目录,相对会话工作目录 |
107
+ | `artifactsDir` | `.dsh-tester/test-reports` | 证据根目录,相对会话工作目录 |
91
108
  | `channel` | 自动 | 优先使用的浏览器通道,如 `chrome`、`msedge`、`chromium` |
92
109
  | `headless` | `true` | 无头运行;想看它真的在点页面就设为 `false` |
93
110
  | `settleMs` | `1200` | 每次导航后等待客户端渲染的静默期 |
@@ -99,7 +116,13 @@ web_flow({
99
116
  - 只测 Chromium 系浏览器;Firefox / WebKit 没有接。
100
117
  - 目前没有跨调用共享登录态(`storageState`)。每次调用要重新登录,用 `setupSteps` 表达。
101
118
  - `web_audit` 单次最多审计 25 个页面,超出的会被丢弃。
102
- - 白屏判定是启发式的:正文少于 20 字且根容器没有子节点才判白屏,纯图形页面需人工确认。
119
+ - 白屏判定是启发式的:顶层文档与所有子 frame 的正文合计少于 20 字、且根容器无子节点才判白屏;
120
+ 纯图形页面(canvas、图表)仍需人工确认。
121
+ - 跨域 iframe 读不到正文,此时只按顶层文档判定,并在 `framesUnreadable` 中记录。
122
+ - 「跳到登录页」的判定基于 URL 关键词(login / signin / passport / sso / auth)。自定义登录路径
123
+ 若不包含这些词,会漏判;此时看 `finalUrl` 与请求地址是否一致。
124
+ - `setupSteps` 不会自动验证登录是否成功。它只按你写的步骤执行,最后一步如果恒成立,
125
+ 审计就会在未登录状态下继续跑。
103
126
  - 无头模式下列出的是证据而非视觉效果;关键页面建议看截图或临时用 `headless: false` 复核。
104
127
 
105
128
  ## 开发与修改(给维护者)
package/icon.svg CHANGED
@@ -1,9 +1,11 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="Tester role">
2
- <rect x="4" y="8" width="56" height="48" rx="8" fill="none" stroke="currentColor" stroke-width="3"/>
3
- <path d="M4 20h56" stroke="currentColor" stroke-width="3"/>
4
- <circle cx="12" cy="14" r="2" fill="currentColor"/>
5
- <circle cx="20" cy="14" r="2" fill="currentColor"/>
6
- <circle cx="28" cy="14" r="2" fill="currentColor"/>
7
- <path d="M18 38l6 7 15-17" fill="none" stroke="currentColor" stroke-width="4"
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="测试工程师角色">
2
+ <!-- 显式颜色,不用 currentColor:图标以 <img> 方式加载时 currentColor 会退化成黑色。 -->
3
+ <rect x="2" y="2" width="60" height="60" rx="14" fill="#1f6feb"/>
4
+ <rect x="10" y="15" width="44" height="34" rx="5" fill="#ffffff"/>
5
+ <rect x="10" y="15" width="44" height="8" rx="4" fill="#c3d4f2"/>
6
+ <rect x="10" y="19" width="44" height="4" fill="#c3d4f2"/>
7
+ <circle cx="15.5" cy="19" r="1.6" fill="#7d95c0"/>
8
+ <circle cx="20.5" cy="19" r="1.6" fill="#7d95c0"/>
9
+ <path d="M23 33.5l5.5 5.5L46 21.5" fill="none" stroke="#1f6feb" stroke-width="5.5"
8
10
  stroke-linecap="round" stroke-linejoin="round"/>
9
11
  </svg>
package/index.js CHANGED
@@ -20,6 +20,7 @@
20
20
 
21
21
  import { readFileSync } from 'node:fs'
22
22
  import { artifactDir, auditPages, resolveUrl, runFlow } from './lib/run.js'
23
+ import { auditReportMarkdown, flowReportMarkdown } from './lib/report.js'
23
24
 
24
25
  export const name = 'tester-tools'
25
26
 
@@ -52,39 +53,7 @@ function workingDirectoryOf(ctx, agent) {
52
53
  * @returns {Array<{type: string, text: string}>} one text block.
53
54
  */
54
55
  function renderAudit(value) {
55
- const lines = [`# 页面审计:${value.ok ? '通过' : '发现问题'}`, '']
56
- lines.push(`浏览器 ${value.browser} · 页面 ${value.summary.pages} 个 · 失败 ${value.summary.failed} 个`)
57
- if (!value.setup.ok) lines.push(`\n前置步骤失败:${value.setup.detail}`)
58
- lines.push('', '| 页面 | 状态 | 结果 | 关键证据 |', '| --- | --- | --- | --- |')
59
- for (const page of value.pages) {
60
- const problems = []
61
- if (page.whiteScreen) problems.push('白屏')
62
- if (page.errorOverlay) problems.push(`错误覆盖层 ${page.errorOverlay}`)
63
- if (page.pageErrors.length) problems.push(`未捕获异常 ${page.pageErrors.length}`)
64
- if (page.httpErrors.length) problems.push(`HTTP 错误 ${page.httpErrors.length}`)
65
- if (page.navigationError) problems.push('导航失败')
66
- if (page.consoleErrors.length) problems.push(`console.error ${page.consoleErrors.length}`)
67
- lines.push(`| ${page.url} | ${page.status} | ${page.ok ? '通过' : '失败'} | ${problems.join(';') || '—'} |`)
68
- }
69
- const broken = value.pages.filter((page) => !page.ok)
70
- if (broken.length > 0) {
71
- lines.push('', '## 失败页面证据')
72
- for (const page of broken) {
73
- lines.push('', `### ${page.url}`, `- 标题:${page.title || '(空)'};正文长度 ${page.textLength}`)
74
- if (page.whiteScreen) lines.push('- 判定白屏:页面没有可见内容,通常是脚本报错或根组件未挂载')
75
- if (page.errorOverlay) lines.push(`- 框架错误覆盖层:${page.errorOverlay}`)
76
- if (page.navigationError) lines.push(`- 导航失败:${page.navigationError}`)
77
- for (const error of page.pageErrors) lines.push(`- 未捕获异常:${error}`)
78
- for (const error of page.httpErrors) lines.push(`- HTTP:${error}`)
79
- for (const error of page.failedRequests) lines.push(`- 请求失败:${error}`)
80
- for (const error of page.consoleErrors) lines.push(`- console.error:${error}`)
81
- if (page.screenshot) lines.push(`- 截图:${page.screenshot}`)
82
- }
83
- }
84
- const dropped = value.pages.reduce((total, page) => total + page.omitted, 0)
85
- if (dropped) lines.push('', `(另有 ${dropped} 条证据因长度上限未展示)`)
86
- lines.push('', `证据目录:${value.artifactsDir}`)
87
- return [{ type: 'text', text: lines.join('\n') }]
56
+ return [{ type: 'text', text: auditReportMarkdown(value) }]
88
57
  }
89
58
 
90
59
  /**
@@ -93,27 +62,7 @@ function renderAudit(value) {
93
62
  * @returns {Array<{type: string, text: string}>} one text block.
94
63
  */
95
64
  function renderFlow(value) {
96
- const lines = [`# 流程测试:${value.ok ? '通过' : '失败'}`, '']
97
- lines.push(`起点 ${value.url} · 浏览器 ${value.browser} · 通过 ${value.passed} 步 / 失败 ${value.failed} 步`)
98
- lines.push('', '| # | 动作 | 结果 | 说明 |', '| --- | --- | --- | --- |')
99
- for (const step of value.steps) {
100
- lines.push(`| ${step.index} | ${step.action} | ${step.ok ? '通过' : '失败'} | ${step.detail.replace(/\|/g, '\\|')} |`)
101
- }
102
- if (value.whiteScreen) lines.push('', '页面当前处于白屏状态。')
103
- const problems = [
104
- ...value.pageErrors.map((error) => `未捕获异常:${error}`),
105
- ...value.httpErrors.map((error) => `HTTP:${error}`),
106
- ...value.failedRequests.map((error) => `请求失败:${error}`),
107
- ...value.consoleErrors.map((error) => `console.error:${error}`),
108
- ]
109
- if (problems.length > 0) {
110
- lines.push('', '## 页面证据')
111
- for (const problem of problems) lines.push(`- ${problem}`)
112
- }
113
- if (value.screenshot) lines.push('', `截图:${value.screenshot}`)
114
- if (value.omitted) lines.push(`(另有 ${value.omitted} 条证据因长度上限未展示)`)
115
- lines.push('', `证据目录:${value.artifactsDir}`)
116
- return [{ type: 'text', text: lines.join('\n') }]
65
+ return [{ type: 'text', text: flowReportMarkdown(value) }]
117
66
  }
118
67
 
119
68
  /**
package/lib/audit.js CHANGED
@@ -15,6 +15,7 @@
15
15
  * @module @jieay/dsh-tester/audit
16
16
  */
17
17
 
18
+ import { createHash } from 'node:crypto'
18
19
  import { mkdir, writeFile } from 'node:fs/promises'
19
20
  import { join } from 'node:path'
20
21
 
@@ -36,6 +37,28 @@ const OVERLAY_SELECTORS = [
36
37
  '[data-hydration-error]',
37
38
  ]
38
39
 
40
+ /**
41
+ * Path and query fragments that identify a login page across common stacks.
42
+ * Chinese products name the module `user&f=login`; Anglo ones use `/login`,
43
+ * `/signin`, `/sign-in`, `/passport`, `/auth`. An audited page that ends up here
44
+ * means the session was not established — the audit measured the wrong page.
45
+ */
46
+ const LOGIN_URL_PATTERN = /(?:^|[/?&=#%])(?:login|log-in|signin|sign-in|passport|sso|auth)(?:$|[/?&=#%])/i
47
+
48
+ /**
49
+ * Decide whether a URL looks like a login page.
50
+ * @param {string} url the final URL of an audited page.
51
+ * @returns {boolean} whether the URL looks like a login entry point.
52
+ */
53
+ export function looksLikeLoginUrl(url) {
54
+ try {
55
+ const parsed = new URL(url)
56
+ return LOGIN_URL_PATTERN.test(`${parsed.pathname}${parsed.search}`)
57
+ } catch {
58
+ return LOGIN_URL_PATTERN.test(String(url ?? ''))
59
+ }
60
+ }
61
+
39
62
  /**
40
63
  * Requests that are never evidence of a broken application: browser chrome
41
64
  * asks for a favicon on every navigation, and extensions inject their own URLs.
@@ -75,14 +98,25 @@ export function clip(items, cap = EVIDENCE_CAP) {
75
98
  }
76
99
 
77
100
  /**
78
- * Make a filesystem-safe artifact name from a URL.
101
+ * Make a filesystem-safe, collision-free artifact name from a URL.
102
+ *
103
+ * The query string must take part in the name: server-rendered apps route
104
+ * entirely through it (`index.php?m=bug&f=browse`), so stripping it makes
105
+ * different pages write the same screenshot filename and overwrite each other.
106
+ * A short hash of the full URL is appended so two URLs that sanitize to the same
107
+ * text still land in different files.
79
108
  * @param {string} url the page URL.
80
- * @returns {string} a short safe stem.
109
+ * @returns {string} a safe stem, at most about 80 characters.
81
110
  */
82
111
  export function artifactStem(url) {
83
- const stripped = url.replace(/^[a-z]+:\/\//i, '').replace(/[?#].*$/, '')
84
- const safe = stripped.replace(/[^a-zA-Z0-9._-]+/g, '_').replace(/^_+|_+$/g, '')
85
- return (safe || 'page').slice(0, 80)
112
+ const withoutScheme = url.replace(/^[a-z][a-z0-9+.-]*:\/\//i, '')
113
+ const [pathPart, queryPart = ''] = withoutScheme.split(/\?/)
114
+ const clean = (value) => value.replace(/[^a-zA-Z0-9._-]+/g, '_').replace(/^_+|_+$/g, '')
115
+ const path = clean(pathPart ?? '')
116
+ const query = clean(queryPart.split('#')[0] ?? '')
117
+ const readable = [path, query].filter(Boolean).join('_') || 'page'
118
+ const hash = createHash('sha1').update(url).digest('hex').slice(0, 6)
119
+ return `${readable.slice(0, 70)}_${hash}`
86
120
  }
87
121
 
88
122
  /**
@@ -136,13 +170,20 @@ export function attachCollectors(page) {
136
170
  }
137
171
 
138
172
  /**
139
- * Inspect the rendered document for blank-page and error-overlay conditions.
173
+ * Inspect the rendered document, including child frames, for blank-page and
174
+ * error-overlay conditions.
175
+ *
176
+ * Frame awareness matters: a shell that renders its content into an `<iframe>`
177
+ * (server-rendered apps such as ZenTao do this) leaves the top document with
178
+ * only a navigation bar of text. Measuring the top document alone would report
179
+ * a misleading length and, for a thin shell, a false "blank page".
140
180
  * @param {import('playwright-core').Page} page the page to inspect.
141
- * @returns {Promise<{title: string, textLength: number, rootChildren: number, overlay: string, whiteScreen: boolean}>} render facts.
181
+ * @returns {Promise<{title: string, textLength: number, topTextLength: number, frameTextLength: number, frameCount: number, framesUnreadable: number, rootChildren: number, overlay: string, whiteScreen: boolean}>} render facts.
142
182
  */
143
183
  export async function inspectRender(page) {
184
+ let top
144
185
  try {
145
- return await page.evaluate((selectors) => {
186
+ top = await page.evaluate((selectors) => {
146
187
  const body = document.body
147
188
  const root = document.querySelector('#app, #root, [data-v-app], #__next, #__nuxt') ?? body
148
189
  const text = (body?.innerText ?? '').trim()
@@ -154,37 +195,84 @@ export async function inspectRender(page) {
154
195
  break
155
196
  }
156
197
  }
157
- const textLength = text.length
158
- const rootChildren = root ? root.children.length : 0
159
198
  return {
160
199
  title: (document.title ?? '').trim(),
161
- textLength,
162
- rootChildren,
200
+ textLength: text.length,
201
+ rootChildren: root ? root.children.length : 0,
163
202
  overlay,
164
- whiteScreen: textLength < 20 && rootChildren === 0 && !overlay,
165
203
  }
166
204
  }, OVERLAY_SELECTORS)
167
205
  } catch (error) {
168
206
  return {
169
207
  title: '',
170
208
  textLength: 0,
209
+ topTextLength: 0,
210
+ frameTextLength: 0,
211
+ frameCount: 0,
212
+ framesUnreadable: 0,
171
213
  rootChildren: 0,
172
214
  overlay: '',
173
215
  whiteScreen: false,
174
216
  inspectError: error instanceof Error ? error.message : String(error),
175
217
  }
176
218
  }
219
+
220
+ // Count the text inside every child frame. A cross-origin or detached frame
221
+ // cannot be read; that is recorded rather than treated as empty content.
222
+ let frameTextLength = 0
223
+ let frameCount = 0
224
+ let framesUnreadable = 0
225
+ for (const frame of page.frames()) {
226
+ if (frame === page.mainFrame()) continue
227
+ frameCount += 1
228
+ try {
229
+ const length = await frame.evaluate(() => (document.body ? (document.body.innerText ?? '').trim().length : 0))
230
+ if (Number.isFinite(length)) frameTextLength += length
231
+ } catch {
232
+ framesUnreadable += 1
233
+ }
234
+ }
235
+
236
+ const textLength = top.textLength + frameTextLength
237
+ return {
238
+ title: top.title,
239
+ textLength,
240
+ topTextLength: top.textLength,
241
+ frameTextLength,
242
+ frameCount,
243
+ framesUnreadable,
244
+ rootChildren: top.rootChildren,
245
+ overlay: top.overlay,
246
+ // A page with readable text in any frame is not blank. Unreadable frames do
247
+ // not count as content, so a page whose only frame is cross-origin still
248
+ // falls back to the top-document verdict.
249
+ whiteScreen: textLength < 20 && top.rootChildren === 0 && !top.overlay,
250
+ }
251
+ }
252
+
253
+ /**
254
+ * Format a local timestamp for a run directory name.
255
+ * @param {Date} date the moment of the run.
256
+ * @returns {string} `YYYY-MM-DD_HH-mm-ss` in local time.
257
+ */
258
+ export function stamp(date = new Date()) {
259
+ const pad = (value) => String(value).padStart(2, '0')
260
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
261
+ + `_${pad(date.getHours())}-${pad(date.getMinutes())}-${pad(date.getSeconds())}`
177
262
  }
178
263
 
179
264
  /**
180
- * Create the artifact directory for one tool call.
181
- * @param {string} baseDir the parent directory.
182
- * @param {string} [prefix] a run label.
265
+ * Create one directory for this run: `<baseDir>/<timestamp>_<kind>`.
266
+ *
267
+ * Every call gets its own folder so two runs never overwrite each other's
268
+ * screenshots, and the folder name carries the local start time so a human can
269
+ * match a report to the moment the test ran.
270
+ * @param {string} baseDir the parent directory, normally inside the project.
271
+ * @param {string} [kind] the run kind: `audit`, `flow`, or similar.
183
272
  * @returns {Promise<string>} the created directory.
184
273
  */
185
- export async function prepareArtifacts(baseDir, prefix = 'run') {
186
- const stamp = new Date().toISOString().replace(/[:.]/g, '-').slice(0, 19)
187
- const dir = join(baseDir, `${prefix}-${stamp}`)
274
+ export async function prepareArtifacts(baseDir, kind = 'run') {
275
+ const dir = join(baseDir, `${stamp()}_${kind}`)
188
276
  await mkdir(dir, { recursive: true })
189
277
  return dir
190
278
  }
package/lib/flow.js CHANGED
@@ -45,6 +45,53 @@ export function isSupportedAction(action) {
45
45
  return ACTIONS.has(action)
46
46
  }
47
47
 
48
+
49
+ /**
50
+ * Resolve a target to the first locator that matches it, searching the main
51
+ * frame first and then every child frame.
52
+ *
53
+ * Server-rendered shells (ZenTao and friends) put the whole application body
54
+ * inside an `<iframe>`; Playwright's `page.locator` never looks into frames, so
55
+ * without this fallback every interaction inside the app body times out while
56
+ * the page looks perfectly rendered to a human.
57
+ * @param {import('playwright-core').Page} page the page under test.
58
+ * @param {string} target a Playwright selector.
59
+ * @returns {Promise<import('playwright-core').Locator>} a locator in the frame that matched.
60
+ */
61
+ async function locateAcrossFrames(page, target) {
62
+ const main = page.locator(target)
63
+ if (await main.count().catch(() => 0) > 0) return main.first()
64
+ for (const frame of page.frames()) {
65
+ if (frame === page.mainFrame()) continue
66
+ try {
67
+ const locator = frame.locator(target)
68
+ if (await locator.count() > 0) return locator.first()
69
+ } catch {
70
+ // A detached or cross-origin frame cannot be searched; try the next one.
71
+ }
72
+ }
73
+ // Nothing matched anywhere: keep the main-frame locator so the error message
74
+ // names the selector the caller wrote.
75
+ return main.first()
76
+ }
77
+
78
+ /**
79
+ * Collect the visible text of the page and all readable child frames.
80
+ * @param {import('playwright-core').Page} page the page under test.
81
+ * @returns {Promise<string>} concatenated text.
82
+ */
83
+ async function textAcrossFrames(page) {
84
+ const parts = []
85
+ for (const frame of page.frames()) {
86
+ try {
87
+ parts.push(await frame.evaluate(() => (document.body ? document.body.innerText : '')))
88
+ } catch {
89
+ // Cross-origin or detached frames are skipped.
90
+ }
91
+ }
92
+ return parts.join('\n')
93
+ }
94
+
48
95
  /**
49
96
  * Run one assertion or action against a page.
50
97
  * @param {import('playwright-core').Page} page the page under test.
@@ -81,34 +128,34 @@ export async function runStep(page, step, index, context) {
81
128
  break
82
129
  }
83
130
  case 'click': {
84
- await page.locator(target).first().click({ timeout })
131
+ await (await locateAcrossFrames(page, target)).click({ timeout })
85
132
  record.detail = `clicked ${target}`
86
133
  break
87
134
  }
88
135
  case 'dblclick': {
89
- await page.locator(target).first().dblclick({ timeout })
136
+ await (await locateAcrossFrames(page, target)).dblclick({ timeout })
90
137
  record.detail = `double-clicked ${target}`
91
138
  break
92
139
  }
93
140
  case 'fill': {
94
- await page.locator(target).first().fill(String(step.value ?? ''), { timeout })
141
+ await (await locateAcrossFrames(page, target)).fill(String(step.value ?? ''), { timeout })
95
142
  record.detail = `filled ${target}`
96
143
  break
97
144
  }
98
145
  case 'press': {
99
146
  const key = String(step.key ?? step.value ?? '')
100
- if (target) await page.locator(target).first().press(key, { timeout })
147
+ if (target) await (await locateAcrossFrames(page, target)).press(key, { timeout })
101
148
  else await page.keyboard.press(key)
102
149
  record.detail = `pressed ${key}`
103
150
  break
104
151
  }
105
152
  case 'select': {
106
- await page.locator(target).first().selectOption(String(step.value ?? ''), { timeout })
153
+ await (await locateAcrossFrames(page, target)).selectOption(String(step.value ?? ''), { timeout })
107
154
  record.detail = `selected ${step.value} in ${target}`
108
155
  break
109
156
  }
110
157
  case 'hover': {
111
- await page.locator(target).first().hover({ timeout })
158
+ await (await locateAcrossFrames(page, target)).hover({ timeout })
112
159
  record.detail = `hovered ${target}`
113
160
  break
114
161
  }
@@ -119,28 +166,29 @@ export async function runStep(page, step, index, context) {
119
166
  break
120
167
  }
121
168
  case 'waitFor': {
122
- await page.locator(target).first().waitFor({ state: step.state === 'hidden' ? 'hidden' : 'visible', timeout })
169
+ await (await locateAcrossFrames(page, target)).waitFor({ state: step.state === 'hidden' ? 'hidden' : 'visible', timeout })
123
170
  record.detail = `waited for ${target} to become ${step.state === 'hidden' ? 'hidden' : 'visible'}`
124
171
  break
125
172
  }
126
173
  case 'expectVisible': {
127
- await page.locator(target).first().waitFor({ state: 'visible', timeout })
174
+ await (await locateAcrossFrames(page, target)).waitFor({ state: 'visible', timeout })
128
175
  record.detail = `${target} is visible`
129
176
  break
130
177
  }
131
178
  case 'expectHidden': {
132
- await page.locator(target).first().waitFor({ state: 'hidden', timeout })
179
+ await (await locateAcrossFrames(page, target)).waitFor({ state: 'hidden', timeout })
133
180
  record.detail = `${target} is hidden`
134
181
  break
135
182
  }
136
183
  case 'expectText': {
137
184
  const expected = String(step.text ?? step.value ?? '')
138
- const scope = target ? page.locator(target).first() : page.locator('body')
139
185
  const deadline = Date.now() + timeout
140
186
  let actual = ''
141
187
  for (;;) {
142
188
  try {
143
- actual = (await scope.innerText({ timeout: 1000 })) ?? ''
189
+ actual = target
190
+ ? ((await (await locateAcrossFrames(page, target)).innerText({ timeout: 1000 })) ?? '')
191
+ : await textAcrossFrames(page)
144
192
  } catch {
145
193
  actual = ''
146
194
  }
@@ -159,7 +207,7 @@ export async function runStep(page, step, index, context) {
159
207
  let actual = ''
160
208
  for (;;) {
161
209
  try {
162
- actual = await page.locator(target).first().inputValue({ timeout: 1000 })
210
+ actual = await (await locateAcrossFrames(page, target)).inputValue({ timeout: 1000 })
163
211
  } catch {
164
212
  actual = ''
165
213
  }
@@ -191,7 +239,8 @@ export async function runStep(page, step, index, context) {
191
239
  case 'screenshot': {
192
240
  const stem = String(step.name ?? `step-${index}`)
193
241
  const path = await context.screenshot(context.artifactsDir, stem)
194
- record.detail = path ? `saved ${path}` : 'screenshot failed'
242
+ if (!path) throw new Error('screenshot failed: no file was written')
243
+ record.detail = `saved ${path}`
195
244
  break
196
245
  }
197
246
  default:
package/lib/report.js ADDED
@@ -0,0 +1,173 @@
1
+ /**
2
+ * Markdown reports for one test run.
3
+ *
4
+ * The same formatter feeds two consumers:
5
+ * - the tool result, where screenshot paths must stay absolute so the model and
6
+ * the UI can act on them;
7
+ * - the `report.md` written next to the evidence, where paths must be relative
8
+ * to that file so the document renders in an editor or on a code host.
9
+ *
10
+ * Keeping one formatter prevents the two from drifting apart.
11
+ * @module @jieay/dsh-tester/report
12
+ */
13
+
14
+ import { basename } from 'node:path'
15
+
16
+ /**
17
+ * Format a timestamp for the report header.
18
+ * @param {Date} date the moment of the run.
19
+ * @returns {string} `YYYY-MM-DD HH:mm:ss` in local time.
20
+ */
21
+ export function reportTime(date = new Date()) {
22
+ const pad = (value) => String(value).padStart(2, '0')
23
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
24
+ + ` ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
25
+ }
26
+
27
+ /**
28
+ * Build the screenshot reference for one mode.
29
+ * @param {boolean} inFolder whether the output is a file inside the evidence folder.
30
+ * @param {string} path the absolute screenshot path.
31
+ * @param {string} label a human label for the image.
32
+ * @returns {string} a markdown line referencing the screenshot.
33
+ */
34
+ function screenshotRef(inFolder, path, label) {
35
+ if (!path) return ''
36
+ const target = inFolder ? basename(path) : path
37
+ return inFolder ? `![${label}](${target})` : `- 截图:${target}`
38
+ }
39
+
40
+ /**
41
+ * Format an audit report.
42
+ * @param {object} report the audit result.
43
+ * @param {object} [options] rendering options.
44
+ * @param {boolean} [options.inFolder] emit relative screenshot paths and image embeds.
45
+ * @param {Date} [options.generatedAt] the moment the report was produced.
46
+ * @returns {string} markdown text.
47
+ */
48
+ export function auditReportMarkdown(report, options = {}) {
49
+ const inFolder = options.inFolder === true
50
+ const lines = [`# 页面审计:${report.ok ? '通过' : '发现问题'}`, '']
51
+
52
+ if (inFolder) {
53
+ lines.push(`- 时间:${reportTime(options.generatedAt)}`)
54
+ lines.push(`- 浏览器:${report.browser}`)
55
+ lines.push(`- 页面:${report.summary.pages} 个,失败 ${report.summary.failed} 个`)
56
+ if (report.setup && !report.setup.ok) lines.push(`- 前置步骤:失败(${report.setup.detail})`)
57
+ lines.push('')
58
+ } else {
59
+ lines.push(`浏览器 ${report.browser} · 页面 ${report.summary.pages} 个 · 失败 ${report.summary.failed} 个`)
60
+ if (!report.setup.ok) lines.push(`\n前置步骤失败:${report.setup.detail}`)
61
+ }
62
+
63
+ lines.push('', inFolder
64
+ ? '| 页面 | 状态 | 结果 | 关键证据 | 截图 |'
65
+ : '| 页面 | 状态 | 结果 | 关键证据 |')
66
+ lines.push(inFolder ? '| --- | --- | --- | --- | --- |' : '| --- | --- | --- | --- |')
67
+
68
+ for (const page of report.pages) {
69
+ const problems = []
70
+ if (page.whiteScreen) problems.push('白屏')
71
+ if (page.errorOverlay) problems.push(`错误覆盖层 ${page.errorOverlay}`)
72
+ if (page.pageErrors.length) problems.push(`未捕获异常 ${page.pageErrors.length}`)
73
+ if (page.httpErrors.length) problems.push(`HTTP 错误 ${page.httpErrors.length}`)
74
+ if (page.navigationError) problems.push('导航失败')
75
+ if (page.redirectedToLogin) problems.push('跳到登录页(会话未登录)')
76
+ if (page.consoleErrors.length) problems.push(`console.error ${page.consoleErrors.length}`)
77
+ const cells = [page.url, page.status, page.ok ? '通过' : '失败', problems.join(';') || '—']
78
+ if (inFolder) cells.push(page.screenshot ? `[查看](${basename(page.screenshot)})` : '—')
79
+ lines.push(`| ${cells.join(' | ')} |`)
80
+ }
81
+
82
+ const broken = report.pages.filter((page) => !page.ok)
83
+ if (broken.length > 0) {
84
+ lines.push('', '## 失败页面证据')
85
+ for (const page of broken) {
86
+ lines.push('', `### ${page.url}`)
87
+ lines.push(`- 标题:${page.title || '(空)'};正文长度 ${page.textLength}`
88
+ + (page.frameCount > 0
89
+ ? `(顶层 ${page.topTextLength} 字 + ${page.frameCount} 个 iframe 内 ${page.textLength - page.topTextLength} 字)`
90
+ : ''))
91
+ if (page.whiteScreen) lines.push('- 判定白屏:页面没有可见内容,通常是脚本报错或根组件未挂载')
92
+ if (page.errorOverlay) lines.push(`- 框架错误覆盖层:${page.errorOverlay}`)
93
+ if (page.navigationError) lines.push(`- 导航失败:${page.navigationError}`)
94
+ if (page.redirectedToLogin) {
95
+ lines.push(`- **落在登录页**:实际 URL 是 ${page.finalUrl}`)
96
+ lines.push(' → 这页的检查结果不可信:审计会话没有登录态,测到的是登录页而不是业务页。请检查 setupSteps 是否真的等到了登录完成。')
97
+ }
98
+ for (const error of page.pageErrors) lines.push(`- 未捕获异常:${error}`)
99
+ for (const error of page.httpErrors) lines.push(`- HTTP:${error}`)
100
+ for (const error of page.failedRequests) lines.push(`- 请求失败:${error}`)
101
+ for (const error of page.consoleErrors) lines.push(`- console.error:${error}`)
102
+ if (page.screenshot) {
103
+ const ref = screenshotRef(inFolder, page.screenshot, `${page.url} 截图`)
104
+ lines.push(`- 截图:${basename(page.screenshot)}`)
105
+ if (inFolder) lines.push('', ref)
106
+ }
107
+ }
108
+ }
109
+
110
+ const dropped = report.pages.reduce((total, page) => total + page.omitted, 0)
111
+ if (dropped) lines.push('', `(另有 ${dropped} 条证据因长度上限未展示)`)
112
+ if (inFolder) {
113
+ lines.push('', '---', '', '同目录下的 `audit.json` 是这次运行的完整结构化证据。')
114
+ } else {
115
+ lines.push('', `证据目录:${report.artifactsDir}`)
116
+ }
117
+ return lines.join('\n')
118
+ }
119
+
120
+ /**
121
+ * Format a journey report.
122
+ * @param {object} report the flow result.
123
+ * @param {object} [options] rendering options; see {@link auditReportMarkdown}.
124
+ * @returns {string} markdown text.
125
+ */
126
+ export function flowReportMarkdown(report, options = {}) {
127
+ const inFolder = options.inFolder === true
128
+ const lines = [`# 流程测试:${report.ok ? '通过' : '失败'}`, '']
129
+
130
+ if (inFolder) {
131
+ lines.push(`- 时间:${reportTime(options.generatedAt)}`)
132
+ lines.push(`- 起点:${report.url}`)
133
+ lines.push(`- 浏览器:${report.browser}`)
134
+ lines.push(`- 步骤:通过 ${report.passed} 步 / 失败 ${report.failed} 步`)
135
+ lines.push('')
136
+ } else {
137
+ lines.push(`起点 ${report.url} · 浏览器 ${report.browser} · 通过 ${report.passed} 步 / 失败 ${report.failed} 步`)
138
+ }
139
+
140
+ lines.push('', '| # | 动作 | 结果 | 说明 |', '| --- | --- | --- | --- |')
141
+ for (const step of report.steps) {
142
+ lines.push(`| ${step.index} | ${step.action} | ${step.ok ? '通过' : '失败'} | ${step.detail.replace(/\|/g, '\\|')} |`)
143
+ }
144
+
145
+ if (report.whiteScreen) lines.push('', '页面当前处于白屏状态。')
146
+
147
+ const problems = [
148
+ ...report.pageErrors.map((error) => `未捕获异常:${error}`),
149
+ ...report.httpErrors.map((error) => `HTTP:${error}`),
150
+ ...report.failedRequests.map((error) => `请求失败:${error}`),
151
+ ...report.consoleErrors.map((error) => `console.error:${error}`),
152
+ ]
153
+ if (problems.length > 0) {
154
+ lines.push('', '## 页面证据')
155
+ for (const problem of problems) lines.push(`- ${problem}`)
156
+ }
157
+
158
+ if (report.screenshot) {
159
+ if (inFolder) {
160
+ lines.push('', `截图:${basename(report.screenshot)}`, '', screenshotRef(true, report.screenshot, '最终截图'))
161
+ } else {
162
+ lines.push('', `截图:${report.screenshot}`)
163
+ }
164
+ }
165
+ if (report.omitted) lines.push(`(另有 ${report.omitted} 条证据因长度上限未展示)`)
166
+
167
+ if (inFolder) {
168
+ lines.push('', '---', '', '同目录下的 `flow.json` 是这次运行的完整结构化证据。')
169
+ } else {
170
+ lines.push('', `证据目录:${report.artifactsDir}`)
171
+ }
172
+ return lines.join('\n')
173
+ }
package/lib/run.js CHANGED
@@ -7,7 +7,8 @@
7
7
  * @module @jieay/dsh-tester/run
8
8
  */
9
9
 
10
- import { resolve } from 'node:path'
10
+ import { writeFile } from 'node:fs/promises'
11
+ import { join, resolve } from 'node:path'
11
12
  import {
12
13
  PAGE_CAP,
13
14
  UNKNOWN_STATUS,
@@ -16,13 +17,18 @@ import {
16
17
  capture,
17
18
  clip,
18
19
  inspectRender,
20
+ looksLikeLoginUrl,
19
21
  line,
20
22
  prepareArtifacts,
21
23
  writeSidecar,
22
24
  } from './audit.js'
23
25
  import { launchBrowser } from './browser.js'
26
+ import { auditReportMarkdown, flowReportMarkdown } from './report.js'
24
27
  import { runSteps } from './flow.js'
25
28
 
29
+ /** Default evidence root, relative to the session working directory. */
30
+ export const DEFAULT_ARTIFACTS_DIR = '.dsh-tester/test-reports'
31
+
26
32
  /** Default settle delay after a navigation, for client-rendered apps. */
27
33
  export const SETTLE_MS = 1200
28
34
 
@@ -140,6 +146,8 @@ export async function auditPages(request) {
140
146
  } catch (error) {
141
147
  navigationError = line(error instanceof Error ? error.message : String(error))
142
148
  }
149
+ const finalUrl = page.url()
150
+ const redirectedToLogin = looksLikeLoginUrl(finalUrl)
143
151
  const render = await inspectRender(page)
144
152
  const evidence = collector.collect()
145
153
  const consoleErrors = clip(evidence.consoleErrors)
@@ -150,7 +158,7 @@ export async function auditPages(request) {
150
158
  const has5xx = evidence.httpErrors.some((entry) => /^5\d\d /.test(entry))
151
159
  const badStatus = status >= 400
152
160
  const ok = !navigationError && !render.whiteScreen && !render.overlay
153
- && pageErrors.items.length === 0 && !has5xx && !badStatus
161
+ && pageErrors.items.length === 0 && !has5xx && !badStatus && !redirectedToLogin
154
162
  pages.push({
155
163
  url,
156
164
  status,
@@ -159,6 +167,8 @@ export async function auditPages(request) {
159
167
  whiteScreen: Boolean(render.whiteScreen),
160
168
  errorOverlay: line(render.overlay ?? ''),
161
169
  textLength: Number.isFinite(render.textLength) ? render.textLength : 0,
170
+ topTextLength: Number.isFinite(render.topTextLength) ? render.topTextLength : 0,
171
+ frameCount: Number.isFinite(render.frameCount) ? render.frameCount : 0,
162
172
  consoleErrors: consoleErrors.items,
163
173
  pageErrors: pageErrors.items,
164
174
  failedRequests: failedRequests.items,
@@ -166,6 +176,8 @@ export async function auditPages(request) {
166
176
  omitted: consoleErrors.omitted + pageErrors.omitted + failedRequests.omitted + httpErrors.omitted,
167
177
  screenshot,
168
178
  navigationError,
179
+ finalUrl,
180
+ redirectedToLogin,
169
181
  })
170
182
  }
171
183
 
@@ -178,6 +190,8 @@ export async function auditPages(request) {
178
190
  summary: { pages: pages.length, failed: pages.filter((entry) => !entry.ok).length },
179
191
  }
180
192
  await writeSidecar(dir, 'audit', report)
193
+ await writeFile(join(dir, 'report.md'),
194
+ `${auditReportMarkdown(report, { inFolder: true })}\n`, 'utf8')
181
195
  return report
182
196
  } finally {
183
197
  request.signal?.removeEventListener('abort', onAbort)
@@ -254,6 +268,8 @@ export async function runFlow(request) {
254
268
  screenshot: finalShot,
255
269
  }
256
270
  await writeSidecar(dir, 'flow', report)
271
+ await writeFile(join(dir, 'report.md'),
272
+ `${flowReportMarkdown(report, { inFolder: true })}\n`, 'utf8')
257
273
  return report
258
274
  } finally {
259
275
  request.signal?.removeEventListener('abort', onAbort)
@@ -268,6 +284,6 @@ export async function runFlow(request) {
268
284
  * @returns {string} an absolute artifact parent directory.
269
285
  */
270
286
  export function artifactDir(configured, workingDirectory) {
271
- const base = configured && configured.trim() ? configured.trim() : '.dsh-tester'
287
+ const base = configured && configured.trim() ? configured.trim() : DEFAULT_ARTIFACTS_DIR
272
288
  return resolve(workingDirectory, base)
273
289
  }
package/lib/schemas.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "web_audit": {
3
- "description": "在真实 Chromium 浏览器里打开一组页面,报告它们究竟能不能用:渲染结果、console 报错、未捕获异常、失败请求、HTTP ≥ 400 响应,以及逐页截图。适合在构建或部署之后用来抓「接口正常但页面坏了」。传 `setupSteps` 可只登录一次,之后在同一浏览器会话里审计需要登录的页面。",
3
+ "description": "在真实 Chromium 浏览器里打开一组页面,报告它们究竟能不能用:渲染结果、console 报错、未捕获异常、失败请求、HTTP ≥ 400 响应,以及逐页截图。适合在构建或部署之后用来抓「接口正常但页面坏了」。传 `setupSteps` 可只登录一次,之后在同一浏览器会话里审计需要登录的页面。 setupSteps 必须以一条真实验证结尾(如 expectUrl 或 expectVisible 指向登录后的页面);只写 waitFor 任何元素都可能立即通过,导致审计在未登录状态下跑、把登录页当业务页报「通过」。",
4
4
  "timeoutMs": 300000,
5
5
  "parameters": {
6
6
  "type": "object",
@@ -166,14 +166,15 @@
166
166
  },
167
167
  "whiteScreen": {
168
168
  "type": "boolean",
169
- "description": "Nothing rendered: no body text and no mounted root children."
169
+ "description": "判定为白屏:正文少于 20 字、根容器无子节点、且没有框架错误覆盖层。顶层文档与所有子 frame 的文本合计,因此 iframe 装载正文的应用不会被误判。"
170
170
  },
171
171
  "errorOverlay": {
172
172
  "type": "string",
173
173
  "description": "Matched framework error overlay selector, or empty."
174
174
  },
175
175
  "textLength": {
176
- "type": "integer"
176
+ "type": "integer",
177
+ "description": "顶层文档与所有子 frame 的正文总字数。"
177
178
  },
178
179
  "consoleErrors": {
179
180
  "type": "array",
@@ -207,6 +208,22 @@
207
208
  },
208
209
  "navigationError": {
209
210
  "type": "string"
211
+ },
212
+ "topTextLength": {
213
+ "type": "integer",
214
+ "description": "仅顶层文档的正文长度;与 textLength 差值即为 iframe 内的文字量。"
215
+ },
216
+ "frameCount": {
217
+ "type": "integer",
218
+ "description": "页面里的子 frame 数量;正文在 iframe 里的应用此项大于 0。"
219
+ },
220
+ "finalUrl": {
221
+ "type": "string",
222
+ "description": "导航结束后的实际 URL。与请求地址不同说明发生了跳转。"
223
+ },
224
+ "redirectedToLogin": {
225
+ "type": "boolean",
226
+ "description": "实际落在了登录页:说明审计会话没有登录态,此时该页的「通过」不可信。"
210
227
  }
211
228
  },
212
229
  "required": [
@@ -217,13 +234,17 @@
217
234
  "whiteScreen",
218
235
  "errorOverlay",
219
236
  "textLength",
237
+ "frameCount",
238
+ "topTextLength",
220
239
  "consoleErrors",
221
240
  "pageErrors",
222
241
  "failedRequests",
223
242
  "httpErrors",
224
243
  "omitted",
225
244
  "screenshot",
226
- "navigationError"
245
+ "navigationError",
246
+ "finalUrl",
247
+ "redirectedToLogin"
227
248
  ]
228
249
  }
229
250
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jieay/dsh-tester",
3
- "version": "0.1.1",
3
+ "version": "0.1.7",
4
4
  "description": "给 DeepSeek Harness 用的测试工程师角色:预设角色 + 可委派的测试子代理 + 真实浏览器页面/旅程审计工具,专抓接口测试发现不了的前端故障。",
5
5
  "keywords": [
6
6
  "deepseek-harness",
@@ -24,6 +24,7 @@
24
24
  "bugs": {
25
25
  "url": "https://github.com/Jieay/dsh-tester/issues"
26
26
  },
27
+ "icon": "./icon.svg",
27
28
  "exports": {
28
29
  ".": "./index.js",
29
30
  "./locale/*.json": "./locale/*.json",