chore(department): add debug logging for CI test failure

CurrentDepartmentId is set but JWT lacks current_department_id.
Adding detailed path/token logs at each iteration to diagnose.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-02 20:56:42 +08:00
parent bfbf1e91df
commit 08659f28ce
+16 -2
View File
@@ -37,19 +37,25 @@ async function loginAndDismissSelectors(page: any) {
for (let i = 0; i < 5; i++) { for (let i = 0; i < 5; i++) {
const path = await page.evaluate(() => window.location.pathname); const path = await page.evaluate(() => window.location.pathname);
console.log(`[DeptTest] iteration ${i}: path=${path}`); console.log(`[DeptTest] iteration ${i}: path=${path}`);
console.log(`[DeptTest] has Authorization:`, !!await page.evaluate(() => window.localStorage.getItem('Authorization')));
console.log(`[DeptTest] has HtySudoerToken:`, !!await page.evaluate(() => window.localStorage.getItem('HtySudoerToken')));
if (path === '/org/select') { if (path === '/org/select') {
await page.locator('.van-cell').first().click(); await page.locator('.van-cell').first().click();
console.log('[DeptTest] clicked org cell');
await page.waitForTimeout(3_000); await page.waitForTimeout(3_000);
} else if (path === '/') { } else if (path === '/') {
const rs = page.getByText('请选择您的登录身份'); const rs = page.getByText('请选择您的登录身份');
if (await rs.isVisible().catch(() => false)) { if (await rs.isVisible().catch(() => false)) {
await page.locator('.van-grid-item').first().click(); await page.locator('.van-grid-item').first().click();
console.log('[DeptTest] clicked role');
await page.waitForTimeout(3_000); await page.waitForTimeout(3_000);
} else { } else {
console.log('[DeptTest] at / but no role selector, break');
break; break;
} }
} else { } else {
console.log('[DeptTest] unexpected path, break');
break; break;
} }
} }
@@ -71,6 +77,11 @@ test.describe('单部门透明', () => {
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 }); await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
// 打印当前页面状态
console.log('[DeptTest] path before', await page.evaluate(() => window.location.pathname));
console.log('[DeptTest] has HtySudoToken:', await page.evaluate(() => !!window.localStorage.getItem('HtySudoerToken')));
console.log('[DeptTest] has CurrentOrgId:', await page.evaluate(() => window.localStorage.getItem('CurrentOrgId')));
// 等待异步的部门加载完成 // 等待异步的部门加载完成
await page.waitForTimeout(3_000); await page.waitForTimeout(3_000);
@@ -78,13 +89,14 @@ test.describe('单部门透明', () => {
const deptId = await page.evaluate(() => const deptId = await page.evaluate(() =>
window.localStorage.getItem('CurrentDepartmentId') window.localStorage.getItem('CurrentDepartmentId')
); );
const pathnameAfter = await page.evaluate(() => window.location.pathname);
console.log('[DeptTest] path after wait:', pathnameAfter);
console.log('[DeptTest] CurrentDepartmentId:', deptId); console.log('[DeptTest] CurrentDepartmentId:', deptId);
expect(deptId).toBeTruthy(); expect(deptId).toBeTruthy();
expect(deptId).toContain('dept_default_'); expect(deptId).toContain('dept_default_');
// 验证页面路径不包含 department 相关参数 // 验证页面路径不包含 department 相关参数
const pathname = await page.evaluate(() => window.location.pathname); expect(pathnameAfter).not.toContain('department');
expect(pathname).not.toContain('department');
// 验证 token 中包含 department_id // 验证 token 中包含 department_id
const authToken = await page.evaluate(() => const authToken = await page.evaluate(() =>
@@ -104,6 +116,8 @@ test.describe('单部门透明', () => {
subjectPayload = JSON.parse(payload.sub); subjectPayload = JSON.parse(payload.sub);
console.log('[JWT Debug] sub keys:', Object.keys(subjectPayload)); console.log('[JWT Debug] sub keys:', Object.keys(subjectPayload));
console.log('[JWT Debug] sub.current_department_id:', subjectPayload.current_department_id); console.log('[JWT Debug] sub.current_department_id:', subjectPayload.current_department_id);
console.log('[JWT Debug] sub.current_org_id:', subjectPayload.current_org_id);
console.log('[JWT Debug] sub.current_org_id type:', typeof subjectPayload.current_org_id);
} }
const deptIdInJwt = payload.current_department_id || subjectPayload.current_department_id; const deptIdInJwt = payload.current_department_id || subjectPayload.current_department_id;
expect(deptIdInJwt).toBeTruthy(); expect(deptIdInJwt).toBeTruthy();