From 368a7f139f3759406960c409d52b92b3e2fcdfe2 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 24 Mar 2026 07:15:55 +0000 Subject: [PATCH] fix: address code review - sanitize error output, fix timezone calc, narrow git add scope [skip ci] Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com> Agent-Logs-Url: https://github.com/qinfendebingshuo/guanghulab/sessions/bc1b54c6-5276-4d00-8ea5-5e8c3c2bef38 --- .github/workflows/check-token-health.yml | 3 ++- .github/workflows/renew-gdrive-tokens.yml | 3 ++- scripts/gdrive/check-hibernation.js | 5 +++-- scripts/gdrive/renew-tokens.js | 6 +++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/check-token-health.yml b/.github/workflows/check-token-health.yml index 6d177ed2..cbc88c58 100644 --- a/.github/workflows/check-token-health.yml +++ b/.github/workflows/check-token-health.yml @@ -68,6 +68,7 @@ jobs: run: | git config user.name "zhuyuan-bot" git config user.email "zhuyuan@guanghulab.com" - git add config/gdrive-tokens.json grid-db/logs/ + git add config/gdrive-tokens.json + git add -f grid-db/logs/token-alert.json 2>/dev/null || true git diff --cached --quiet || git commit -m "auto: Token health check $(date -u +%Y-%m-%dT%H:%M:%SZ) [skip ci]" git push diff --git a/.github/workflows/renew-gdrive-tokens.yml b/.github/workflows/renew-gdrive-tokens.yml index fd232535..a11db3a9 100644 --- a/.github/workflows/renew-gdrive-tokens.yml +++ b/.github/workflows/renew-gdrive-tokens.yml @@ -58,7 +58,8 @@ jobs: run: | git config user.name "zhuyuan-bot" git config user.email "zhuyuan@guanghulab.com" - git add config/gdrive-tokens.json grid-db/logs/ + git add config/gdrive-tokens.json + git add -f grid-db/logs/token-alert.json 2>/dev/null || true git diff --cached --quiet || git commit -m "auto: Token renewal $(date -u +%Y-%m-%dT%H:%M:%SZ) [skip ci]" git push diff --git a/scripts/gdrive/check-hibernation.js b/scripts/gdrive/check-hibernation.js index f79376e9..cde238c2 100644 --- a/scripts/gdrive/check-hibernation.js +++ b/scripts/gdrive/check-hibernation.js @@ -17,8 +17,9 @@ function isInHibernation() { const now = new Date(); - // 转换为北京时间 - const cst = new Date(now.toLocaleString('en-US', { timeZone: 'Asia/Shanghai' })); + // 转换为北京时间(UTC+8),使用 UTC 偏移计算避免 locale 差异 + const utcMs = now.getTime() + now.getTimezoneOffset() * 60 * 1000; + const cst = new Date(utcMs + 8 * 60 * 60 * 1000); const day = cst.getDay(); // 0=周日, 6=周六 const hour = cst.getHours(); const minute = cst.getMinutes(); diff --git a/scripts/gdrive/renew-tokens.js b/scripts/gdrive/renew-tokens.js index 215b1f01..7ad5b471 100644 --- a/scripts/gdrive/renew-tokens.js +++ b/scripts/gdrive/renew-tokens.js @@ -104,8 +104,8 @@ async function main() { console.log(` ✅ 刷新成功!新过期时间: ${token.expires_at}`); results.renewed.push(token.user_id); } else { - // Google 有时不返回新的 refresh_token - console.log(` ⚠️ Google 未返回新 refresh_token,Token 可能仍然有效但无法续期`); + // Google 有时不返回新的 refresh_token(access_type 非 offline 或非首次授权时常见) + console.log(` ⚠️ Google 未返回新 refresh_token,需人类重新授权(access_type=offline + prompt=consent)`); token.status = 'expiring'; registry.renew_log.push({ user_id: token.user_id, @@ -202,7 +202,7 @@ async function refreshOAuth2Token(refreshToken) { resolve(json); } } catch (e) { - reject(new Error(`Invalid response from Google: ${data.substring(0, 200)}`)); + reject(new Error('Invalid JSON response from Google OAuth2 endpoint')); } }); });