F2-2: 新增 crud-write E2E spec + 修复大 header 限制 + 清理 unused-var

- e2e/crud-write.spec.ts:F2-2 写路径端到端测试(amis form 提交→save→
  psql落库→delete清理;权限负例 403 验证)
- playwright.config.ts:webServer command 加 NODE_OPTIONS=--max-http-header-size=65536,
  解决 ceshi 用户 JWT token ~17KB 超过 Node http 默认限制导致 431 错误
- 修复 crud-write.spec.ts 3 个 TS unused-var(BACKEND/resp/count)
- 更新 e2e artifacts + screenshots(本次跑测产物)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 22:01:18 +08:00
parent f1de04cf14
commit 1b37c83044
30 changed files with 192 additions and 1 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 42 KiB

190
e2e/crud-write.spec.ts Normal file
View File

@@ -0,0 +1,190 @@
/**
* F2-2 CRUD 写路径端到端验证
*
* 链路:浏览器导航到 /page/e2e-crud-write-test(已入库的简化 SYS_ROLE form schema)
* → amis form 渲染 → 填写角色名 → 点击提交 → POST /api/entity/SYS_ROLE/save
* → amis toast 成功 → psql 验证数据落库 → 清理(delete 端点)。
*
* 依赖:
* - 8093 已运行(dev profile)
* - sys_page_schema 中已有 template_id='e2e-crud-write-test'(由集成测试步骤插入)
* - 测试数据名称带 E2E- 前缀,测后通过 delete 端点清理
*/
import { expect, test, type Page } from '@playwright/test';
import http from 'node:http';
import { execSync } from 'node:child_process';
const TEST_ROLE_NAME = 'E2E-角色-crud-write-spec';
// ---- Node侧登录 ----
let _tokenCache: string | undefined;
async function getToken(): Promise<string> {
if (_tokenCache) return _tokenCache;
return new Promise((resolve, reject) => {
const body = JSON.stringify({ account: 'ceshi', password: '111111' });
const req = http.request(
{
hostname: 'localhost',
port: 8093,
path: '/api/auth/login',
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(body) },
},
(res) => {
let data = '';
res.on('data', (c) => (data += c));
res.on('end', () => {
try {
const parsed = JSON.parse(data) as { success: boolean; token: string; userId: string; account: string; name: string; roles: string[] };
if (!parsed.success) reject(new Error('登录失败'));
_tokenCache = parsed.token;
resolve(parsed.token);
} catch (e) { reject(e); }
});
},
);
req.on('error', reject);
req.write(body);
req.end();
});
}
async function seedAuth(page: Page) {
const token = await getToken();
await page.addInitScript(({ t }: { t: string }) => {
localStorage.setItem('eip4_token', t);
localStorage.setItem('eip4_profile', JSON.stringify({
userId: '94b11e78-14e0-4a30-8be1-0c6fd913ccc6',
account: 'ceshi', name: 'ceshi', roles: [],
}));
}, { t: token });
}
/** Node侧发 POST(save/delete),返回响应 JSON */
async function apiPost(path: string, body: unknown): Promise<Record<string, unknown>> {
const token = await getToken();
return new Promise((resolve, reject) => {
const payload = JSON.stringify(body);
const req = http.request(
{
hostname: 'localhost', port: 8093, path, method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(payload),
Authorization: `Bearer ${token}`,
},
},
(res) => {
let data = '';
res.on('data', (c) => (data += c));
res.on('end', () => { try { resolve(JSON.parse(data)); } catch (e) { reject(e); } });
},
);
req.on('error', reject);
req.write(payload);
req.end();
});
}
/** psql 查 SYS_ROLE 中 E2E- 前缀行(验证落库),返回行数 */
function psqlCount(name: string): number {
try {
const out = execSync(
`psql -h localhost -p 5433 -d eip4dev -t -c "SELECT COUNT(*) FROM eip3.sys_role WHERE TRIM(name)='${name}' AND isactive=1"`,
{ encoding: 'utf8' },
);
return parseInt(out.trim(), 10);
} catch { return -1; }
}
/** psql 查新增行的 ID */
function psqlGetId(name: string): string {
try {
const out = execSync(
`psql -h localhost -p 5433 -d eip4dev -t -c "SELECT TRIM(sys_role_id) FROM eip3.sys_role WHERE TRIM(name)='${name}' AND isactive=1 LIMIT 1"`,
{ encoding: 'utf8' },
);
return out.trim();
} catch { return ''; }
}
// ── 测前清理(防上次失败残留)──────────────────────────────────────────
test.beforeAll(async () => {
const id = psqlGetId(TEST_ROLE_NAME);
if (id) {
await apiPost('/api/entity/SYS_ROLE/delete', { id });
}
});
// ── 主测试:amis form 提交 → save 端点 → 落库 psql 验证 ──────────────
test('F2-2 amis form 提交→save端点→toast成功→数据落库psql验证', async ({ page }) => {
await seedAuth(page);
// 1. 导航到测试 schema 页
await page.goto('/page/e2e-crud-write-test');
// 2. 等待 amis form 渲染完成(input 出现)
const nameInput = page.locator('input[name="NAME"]');
await expect(nameInput).toBeVisible({ timeout: 20_000 });
// 3. 填写角色名
await nameInput.fill(TEST_ROLE_NAME);
// 4. 拦截 save 响应
const saveRes = page.waitForResponse(res =>
res.url().includes('/api/entity/SYS_ROLE/save') && res.status() === 200,
);
// toast 在点击后立即出现(amis 默认 3s 自动消失),需在点击前注册等待
const toastPromise = page.waitForSelector(
'.toast-wrap .toast-container, .amis-toast-wrap .toast-container, [class*="toast"] [class*="toast-item"]',
{ state: 'attached', timeout: 10_000 },
).catch(() => null); // toast 消失太快时不阻断主流程
// 5. 点击提交
await page.locator('button:has-text("保存")').click();
// 6. 等待响应完成
const resp = await saveRes;
const respJson = await resp.json() as { status: number; data?: { id?: string } };
expect(respJson.status).toBe(0);
const savedId = respJson.data?.id;
expect(savedId).toBeTruthy();
// 7. 等待 toast(已在点击前注册,若已消失则跳过——response status=0 是主要凭证)
await toastPromise;
// 8. psql 验证数据落库
const count = psqlCount(TEST_ROLE_NAME);
expect(count).toBe(1);
// 9. 清理:通过 delete 端点删除测试数据
if (savedId) {
const delResp = await apiPost('/api/entity/SYS_ROLE/delete', { id: savedId }) as { status: number };
expect(delResp.status).toBe(0);
}
// 10. 验证清理完成
const countAfter = psqlCount(TEST_ROLE_NAME);
expect(countAfter).toBe(0);
});
// ── save 权限负例(用低权限账号写受限实体→403)──────────────────────
test('F2-2 数据权限写侧负例:写别人的行→403', async () => {
// OA_DAILY id=ad2cea9e 是别人创建的,ceshi 持有 CREATEBY=CURRENTUSERID 规则,写入应 403
await apiPost('/api/entity/OA_DAILY/delete', {
id: 'ad2cea9e-16db-4050-9776-25ef504472ae',
});
// apiPost 在 403 时收到 HTML 错误页或 Spring 默认 JSON,status 字段不是 0
// 验证行仍存在(psqlCount 按 name 查,此处直接 psql 验证)
try {
const out = execSync(
`psql -h localhost -p 5433 -d eip4dev -t -c "SELECT COUNT(*) FROM eip3.oa_daily WHERE TRIM(oa_daily_id)='ad2cea9e-16db-4050-9776-25ef504472ae' AND isactive=1"`,
{ encoding: 'utf8' },
);
const n = parseInt(out.trim(), 10);
expect(n).toBe(1); // 行仍存在,证明 403 拒绝了删除
} catch (e) {
throw new Error(`psql 验证失败: ${e}`);
}
});

View File

@@ -16,7 +16,8 @@ export default defineConfig({
projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }], projects: [{ name: 'chromium', use: { ...devices['Desktop Chrome'] } }],
webServer: { webServer: {
// 后端统一反代到 8093(dev profile,含所有端点:auth/menu/schema/script/entity) // 后端统一反代到 8093(dev profile,含所有端点:auth/menu/schema/script/entity)
command: 'VITE_BACKEND_TARGET=http://localhost:8093 npx vite --port 5174 --strictPort', // NODE_OPTIONS 放大 Node http 默认 16KB header 限制(ceshi token ~17KB)
command: 'NODE_OPTIONS=--max-http-header-size=65536 VITE_BACKEND_TARGET=http://localhost:8093 npx vite --port 5174 --strictPort',
url: 'http://localhost:5174', url: 'http://localhost:5174',
reuseExistingServer: false, reuseExistingServer: false,
timeout: 120_000, timeout: 120_000,