@jieay/dsh-tester 0.1.1 → 0.1.4
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 +28 -3
- package/cordis.patch.yml +12 -1
- package/docs/DETAIL.md +12 -4
- package/icon.svg +9 -7
- package/index.js +7 -1
- package/lib/audit.js +107 -19
- package/lib/flow.js +2 -1
- package/lib/run.js +9 -2
- package/lib/schemas.json +25 -4
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -60,9 +60,26 @@ web_flow({
|
|
|
60
60
|
})
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
`web_audit`
|
|
63
|
+
`web_audit` 对每个页面返回:主文档状态码、实际落点 `finalUrl`、标题、`ok`、是否白屏(`whiteScreen`)、
|
|
64
|
+
是否跳到登录页(`redirectedToLogin`)、命中的框架错误覆盖层、console 错误、页面异常、失败请求、
|
|
65
|
+
HTTP ≥ 400 的响应、截图路径,以及被截断的证据条数。
|
|
64
66
|
|
|
65
|
-
|
|
67
|
+
> **`setupSteps` 必须以真实验证结尾。** 只写 `waitFor body` 这类恒成立的等待,登录还没完成就导航走了,
|
|
68
|
+
> 审计会在未登录状态下跑完,把登录页当业务页报「通过」。用 `expectUrl` 指向登录后的地址最稳妥;
|
|
69
|
+
> 一旦报告里出现「跳到登录页」,说明这次审计无效。`web_flow` 返回每一步的通过/失败,加上同样的页面证据和失败截图。
|
|
70
|
+
|
|
71
|
+
每次测试都会在项目目录下新建一个带时间戳的文件夹,互不覆盖:
|
|
72
|
+
|
|
73
|
+
```text
|
|
74
|
+
test-reports/
|
|
75
|
+
└── 2026-12-04_12-42-33_audit/
|
|
76
|
+
├── 192.168.192.25_index.php_m_my_f_index_98db71.png
|
|
77
|
+
├── 192.168.192.25_index.php_m_bug_f_browse_c00e25.png
|
|
78
|
+
└── audit.json
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
文件夹名是「本地开始时间 + 测试类型」,截图文件名包含该页面的完整路由(含 query),所以
|
|
82
|
+
`index.php?m=my&f=index` 和 `index.php?m=bug&f=browse` 不会互相覆盖。
|
|
66
83
|
|
|
67
84
|
## 浏览器依赖
|
|
68
85
|
|
|
@@ -81,7 +98,7 @@ web_flow({
|
|
|
81
98
|
|
|
82
99
|
| 配置 | 默认 | 含义 |
|
|
83
100
|
| --- | --- | --- |
|
|
84
|
-
| `artifactsDir` |
|
|
101
|
+
| `artifactsDir` | `test-reports` | 证据目录,相对会话工作目录,每次运行在其下建时间戳子目录 |
|
|
85
102
|
| `channel` | 自动 | 优先使用的浏览器通道:`chrome`、`chrome-beta`、`msedge`、`chromium` |
|
|
86
103
|
| `headless` | `true` | 无头运行;设为 `false` 可以看它真的在点页面 |
|
|
87
104
|
| `settleMs` | `1200` | 每次导航后等待客户端渲染的静默期 |
|
|
@@ -103,6 +120,14 @@ pnpm test # 启动本地夹具服务,在真实浏览器里跑这两个工
|
|
|
103
120
|
|
|
104
121
|
测试针对 `test/fixture.mjs`——一个故意做坏的迷你应用(一个正常页面、一个抛错导致白屏的页面、一个接口返回 500 的页面、一个登录表单)。CI 每次推送都跑同一套。
|
|
105
122
|
|
|
123
|
+
### 两条硬规则
|
|
124
|
+
|
|
125
|
+
本项目的定位是「前端必须用真实浏览器验证」:
|
|
126
|
+
|
|
127
|
+
1. **禁止用 curl / wget / HTTP 请求代替浏览器检查。** 服务端返回 200 而页面白屏、JS 报错、按钮无响应
|
|
128
|
+
的情况非常常见——HTTP 状态码不能证明前端可用。只读取证可以用 HTTP 请求,但不能据此得结论。
|
|
129
|
+
2. **每次前端测试必须留截图。** 这是判断「页面到底长什么样」的唯一可靠证据。
|
|
130
|
+
|
|
106
131
|
### 两条必须知道的约束
|
|
107
132
|
|
|
108
133
|
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
|
+
(默认 `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:
|
|
113
|
+
artifactsDir: 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
|
-
| 渲染判定 |
|
|
23
|
+
| 渲染判定 | **白屏**(正文少于 20 字且根容器无子节点)、**框架错误覆盖层**(Vite / Next / Nuxt / Angular);正文统计包含所有子 frame |
|
|
24
24
|
| `console.error` | 往往是唯一可见的故障症状 |
|
|
25
25
|
| 未捕获异常 | 通常意味着应用根本没挂载起来 |
|
|
26
26
|
| 请求失败 | DNS、TLS、CORS、abort |
|
|
@@ -72,7 +72,9 @@ web_flow({
|
|
|
72
72
|
|
|
73
73
|
## 产物位置
|
|
74
74
|
|
|
75
|
-
截图和 JSON 证据写到会话工作目录下的
|
|
75
|
+
截图和 JSON 证据写到会话工作目录下的 `test-reports/<日期>_<时间>_<audit|flow>/`,
|
|
76
|
+
每次运行一个独立文件夹,不会覆盖历史结果。截图文件名包含完整路由(含 query),
|
|
77
|
+
同名路径的页面不会互相覆盖。
|
|
76
78
|
每份报告末尾都会给出证据目录的绝对路径。
|
|
77
79
|
|
|
78
80
|
## 浏览器依赖
|
|
@@ -87,7 +89,7 @@ web_flow({
|
|
|
87
89
|
|
|
88
90
|
| 配置 | 默认 | 说明 |
|
|
89
91
|
| --- | --- | --- |
|
|
90
|
-
| `artifactsDir` |
|
|
92
|
+
| `artifactsDir` | `test-reports` | 证据目录,相对会话工作目录 |
|
|
91
93
|
| `channel` | 自动 | 优先使用的浏览器通道,如 `chrome`、`msedge`、`chromium` |
|
|
92
94
|
| `headless` | `true` | 无头运行;想看它真的在点页面就设为 `false` |
|
|
93
95
|
| `settleMs` | `1200` | 每次导航后等待客户端渲染的静默期 |
|
|
@@ -99,7 +101,13 @@ web_flow({
|
|
|
99
101
|
- 只测 Chromium 系浏览器;Firefox / WebKit 没有接。
|
|
100
102
|
- 目前没有跨调用共享登录态(`storageState`)。每次调用要重新登录,用 `setupSteps` 表达。
|
|
101
103
|
- `web_audit` 单次最多审计 25 个页面,超出的会被丢弃。
|
|
102
|
-
-
|
|
104
|
+
- 白屏判定是启发式的:顶层文档与所有子 frame 的正文合计少于 20 字、且根容器无子节点才判白屏;
|
|
105
|
+
纯图形页面(canvas、图表)仍需人工确认。
|
|
106
|
+
- 跨域 iframe 读不到正文,此时只按顶层文档判定,并在 `framesUnreadable` 中记录。
|
|
107
|
+
- 「跳到登录页」的判定基于 URL 关键词(login / signin / passport / sso / auth)。自定义登录路径
|
|
108
|
+
若不包含这些词,会漏判;此时看 `finalUrl` 与请求地址是否一致。
|
|
109
|
+
- `setupSteps` 不会自动验证登录是否成功。它只按你写的步骤执行,最后一步如果恒成立,
|
|
110
|
+
审计就会在未登录状态下继续跑。
|
|
103
111
|
- 无头模式下列出的是证据而非视觉效果;关键页面建议看截图或临时用 `headless: false` 复核。
|
|
104
112
|
|
|
105
113
|
## 开发与修改(给维护者)
|
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="
|
|
2
|
-
|
|
3
|
-
<
|
|
4
|
-
<
|
|
5
|
-
<
|
|
6
|
-
<
|
|
7
|
-
<
|
|
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
|
@@ -63,6 +63,7 @@ function renderAudit(value) {
|
|
|
63
63
|
if (page.pageErrors.length) problems.push(`未捕获异常 ${page.pageErrors.length}`)
|
|
64
64
|
if (page.httpErrors.length) problems.push(`HTTP 错误 ${page.httpErrors.length}`)
|
|
65
65
|
if (page.navigationError) problems.push('导航失败')
|
|
66
|
+
if (page.redirectedToLogin) problems.push('跳到登录页(会话未登录)')
|
|
66
67
|
if (page.consoleErrors.length) problems.push(`console.error ${page.consoleErrors.length}`)
|
|
67
68
|
lines.push(`| ${page.url} | ${page.status} | ${page.ok ? '通过' : '失败'} | ${problems.join(';') || '—'} |`)
|
|
68
69
|
}
|
|
@@ -70,10 +71,15 @@ function renderAudit(value) {
|
|
|
70
71
|
if (broken.length > 0) {
|
|
71
72
|
lines.push('', '## 失败页面证据')
|
|
72
73
|
for (const page of broken) {
|
|
73
|
-
lines.push('', `### ${page.url}`, `- 标题:${page.title || '(空)'};正文长度 ${page.textLength}`
|
|
74
|
+
lines.push('', `### ${page.url}`, `- 标题:${page.title || '(空)'};正文长度 ${page.textLength}`
|
|
75
|
+
+ (page.frameCount > 0 ? `(顶层 ${page.topTextLength} 字 + ${page.frameCount} 个 iframe 内 ${page.textLength - page.topTextLength} 字)` : ''))
|
|
74
76
|
if (page.whiteScreen) lines.push('- 判定白屏:页面没有可见内容,通常是脚本报错或根组件未挂载')
|
|
75
77
|
if (page.errorOverlay) lines.push(`- 框架错误覆盖层:${page.errorOverlay}`)
|
|
76
78
|
if (page.navigationError) lines.push(`- 导航失败:${page.navigationError}`)
|
|
79
|
+
if (page.redirectedToLogin) {
|
|
80
|
+
lines.push(`- **落在登录页**:实际 URL 是 ${page.finalUrl}`)
|
|
81
|
+
lines.push(' → 这页的检查结果不可信:审计会话没有登录态,测到的是登录页而不是业务页。请检查 setupSteps 是否真的等到了登录完成。')
|
|
82
|
+
}
|
|
77
83
|
for (const error of page.pageErrors) lines.push(`- 未捕获异常:${error}`)
|
|
78
84
|
for (const error of page.httpErrors) lines.push(`- HTTP:${error}`)
|
|
79
85
|
for (const error of page.failedRequests) lines.push(`- 请求失败:${error}`)
|
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
|
|
109
|
+
* @returns {string} a safe stem, at most about 80 characters.
|
|
81
110
|
*/
|
|
82
111
|
export function artifactStem(url) {
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
181
|
-
*
|
|
182
|
-
*
|
|
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,
|
|
186
|
-
const
|
|
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
|
@@ -191,7 +191,8 @@ export async function runStep(page, step, index, context) {
|
|
|
191
191
|
case 'screenshot': {
|
|
192
192
|
const stem = String(step.name ?? `step-${index}`)
|
|
193
193
|
const path = await context.screenshot(context.artifactsDir, stem)
|
|
194
|
-
|
|
194
|
+
if (!path) throw new Error('screenshot failed: no file was written')
|
|
195
|
+
record.detail = `saved ${path}`
|
|
195
196
|
break
|
|
196
197
|
}
|
|
197
198
|
default:
|
package/lib/run.js
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
capture,
|
|
17
17
|
clip,
|
|
18
18
|
inspectRender,
|
|
19
|
+
looksLikeLoginUrl,
|
|
19
20
|
line,
|
|
20
21
|
prepareArtifacts,
|
|
21
22
|
writeSidecar,
|
|
@@ -140,6 +141,8 @@ export async function auditPages(request) {
|
|
|
140
141
|
} catch (error) {
|
|
141
142
|
navigationError = line(error instanceof Error ? error.message : String(error))
|
|
142
143
|
}
|
|
144
|
+
const finalUrl = page.url()
|
|
145
|
+
const redirectedToLogin = looksLikeLoginUrl(finalUrl)
|
|
143
146
|
const render = await inspectRender(page)
|
|
144
147
|
const evidence = collector.collect()
|
|
145
148
|
const consoleErrors = clip(evidence.consoleErrors)
|
|
@@ -150,7 +153,7 @@ export async function auditPages(request) {
|
|
|
150
153
|
const has5xx = evidence.httpErrors.some((entry) => /^5\d\d /.test(entry))
|
|
151
154
|
const badStatus = status >= 400
|
|
152
155
|
const ok = !navigationError && !render.whiteScreen && !render.overlay
|
|
153
|
-
&& pageErrors.items.length === 0 && !has5xx && !badStatus
|
|
156
|
+
&& pageErrors.items.length === 0 && !has5xx && !badStatus && !redirectedToLogin
|
|
154
157
|
pages.push({
|
|
155
158
|
url,
|
|
156
159
|
status,
|
|
@@ -159,6 +162,8 @@ export async function auditPages(request) {
|
|
|
159
162
|
whiteScreen: Boolean(render.whiteScreen),
|
|
160
163
|
errorOverlay: line(render.overlay ?? ''),
|
|
161
164
|
textLength: Number.isFinite(render.textLength) ? render.textLength : 0,
|
|
165
|
+
topTextLength: Number.isFinite(render.topTextLength) ? render.topTextLength : 0,
|
|
166
|
+
frameCount: Number.isFinite(render.frameCount) ? render.frameCount : 0,
|
|
162
167
|
consoleErrors: consoleErrors.items,
|
|
163
168
|
pageErrors: pageErrors.items,
|
|
164
169
|
failedRequests: failedRequests.items,
|
|
@@ -166,6 +171,8 @@ export async function auditPages(request) {
|
|
|
166
171
|
omitted: consoleErrors.omitted + pageErrors.omitted + failedRequests.omitted + httpErrors.omitted,
|
|
167
172
|
screenshot,
|
|
168
173
|
navigationError,
|
|
174
|
+
finalUrl,
|
|
175
|
+
redirectedToLogin,
|
|
169
176
|
})
|
|
170
177
|
}
|
|
171
178
|
|
|
@@ -268,6 +275,6 @@ export async function runFlow(request) {
|
|
|
268
275
|
* @returns {string} an absolute artifact parent directory.
|
|
269
276
|
*/
|
|
270
277
|
export function artifactDir(configured, workingDirectory) {
|
|
271
|
-
const base = configured && configured.trim() ? configured.trim() : '
|
|
278
|
+
const base = configured && configured.trim() ? configured.trim() : 'test-reports'
|
|
272
279
|
return resolve(workingDirectory, base)
|
|
273
280
|
}
|
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": "
|
|
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.
|
|
3
|
+
"version": "0.1.4",
|
|
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",
|