Skip to content

refactor: Improve code review suggestions and logging logic#384

Merged
cowcfj merged 3 commits intomainfrom
fix/code-review-w2-n1-n2-n4
Apr 4, 2026
Merged

refactor: Improve code review suggestions and logging logic#384
cowcfj merged 3 commits intomainfrom
fix/code-review-w2-n1-n2-n4

Conversation

@cowcfj
Copy link
Copy Markdown
Owner

@cowcfj cowcfj commented Apr 4, 2026

Pull Request

📋 變更描述

改善代碼審核建議的四個問題,重構日誌處理邏輯以提高可讀性和一致性。

🎯 變更類型

  • ✨ 新功能 (Feature)
  • 🐛 Bug 修復 (Bug Fix)
  • 🔨 重構 (Refactor)
  • 📝 文檔更新 (Documentation)
  • 🧪 測試改進 (Testing)
  • ⚡ 性能優化 (Performance)
  • 🔒 安全性改進 (Security)

🤖 提交者聲明

  • 👨‍💻 由人類開發者手動提交
  • 🤖 由 AI Agent 自動建立 (請註明: Antigravity)

✅ 提交前檢查清單

  • PR 標題合規: 我的 PR 標題確實遵循 Conventional Commits 規範 (如 feat: , fix: , refactor: ),以確保 release-please 正常分析版本號。
  • 流程與安全自評: 我已閱讀並確認變更符合 PR_WORKFLOW.md 中的測試規範、代碼規範與安全性指引。

🔗 相關 Issue

Closes #

變更

  • 使用 parseArgsToContext 取代 devLogSink 中的重複邏輯。
  • 移除 buildHighlightBlocks 中的誤導性 fallback。
  • Logger 補充輸出等級的設計決策說明。
  • 補充 _shouldReturnCachedStatus 的 JSDoc 及強制驗證說明。

測試

尚未測試。

- W-2: 以 parseArgsToContext 取代 devLogSink 中的重複手動展開邏輯
- N-1: 移除 buildHighlightBlocks 兩處誤導性 fallback,並更新對應測試
- N-2: 為 Logger 補充輸出等級設計決策說明(warn/error 永遠輸出)
- N-4: 為 _shouldReturnCachedStatus 補充完整 JSDoc 及遷移後強制驗證說明
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

本次重構主要針對代碼審核建議進行優化,重點在於簡化日誌處理流程、移除不必要的防禦性編程邏輯,並透過完善註解與文檔來提升系統行為的可預測性與可維護性。

Highlights

  • 日誌處理邏輯重構: 使用統一的 parseArgsToContext 函數取代了 devLogSink 中重複的參數解析邏輯,提升代碼一致性。
  • 移除冗餘邏輯: 移除了 buildHighlightBlocks 調用中不必要的 fallback 函數,並同步更新了相關單元測試。
  • 日誌設計決策說明: 在 Logger 模組中補充了關於日誌輸出等級的設計決策說明,明確了 warnerror 等級在靜默模式下的行為。
  • 快取邏輯文檔化: 為 _shouldReturnCachedStatus 函數補充了詳細的 JSDoc,特別說明了 migratedFromOldKey 的強制驗證機制。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 4, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cowcfj cowcfj marked this pull request as ready for review April 4, 2026 13:24
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

此拉取請求主要進行了代碼重構與文件完善。在 saveHandlers.js 中,引入了 parseArgsToContext 函數以統一處理日誌參數解析,並簡化了 buildHighlightBlocks 的調用邏輯,移除了冗餘的 fallback 檢查。同時,為 _shouldReturnCachedStatus 函數添加了詳細的 JSDoc 註釋,說明了在 key 遷移後的快取驗證邏輯。在 Logger.js 中,新增了關於不同日誌等級(如 debug/info 與 warn/error)輸出行為的設計決策說明。此外,單元測試也隨之更新,移除了過時的 fallback 測試並加強了標註處理的驗證。目前沒有發現具體問題,無進一步反饋。

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 4, 2026

Warning

Rate limit exceeded

@cowcfj has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 0 minutes and 20 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 0 minutes and 20 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6d112711-02e2-4426-92f9-73cea0c103f3

📥 Commits

Reviewing files that changed from the base of the PR and between 4e43ef6 and a721017.

⛔ Files ignored due to path filters (1)
  • coverage/jest/lcov.info is excluded by !coverage/**
📒 Files selected for processing (1)
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📝 Walkthrough

Walkthrough

本次变更移除围绕 buildHighlightBlocks 的防御性回退,processContentResult 与 _handleExistingPageUpdate 现在始终调用 buildHighlightBlocks(highlights)。在 checkPageStatus 的缓存验证逻辑中,当 migratedFromOldKey 为 true 时强制不返回缓存状态(改为继续向 Notion 重新校验)。将 devLogSink 中对 request.args 的解析集中为 parseArgsToContext(args)。新增/调整了相关单元测试,并在 Logger.js 中加入关于可观察日志级别行为的设计注释(仅注释,无运行时改动)。

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Frontend
participant BackgroundHandler as Background
participant Cache
participant NotionAPI as Notion
Frontend->>Background: 请求保存/检查页面 (args)
Background->>Background: parseArgsToContext(args)
Background->>Cache: 查询页面状态
alt migratedFromOldKey == true
Background->>Notion: 直接查询/验证页面状态
Notion-->>Background: 返回最新状态
else cached valid
Cache-->>Background: 返回缓存状态
end
Background->>Background: processContentResult -> buildHighlightBlocks(highlights)
Background->>Notion: 创建或更新页面(包含高亮块)
Notion-->>Background: 确认创建/更新
Background-->>Frontend: 返回结果

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

Review effort 2/5

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive PR 标题使用了 Conventional Commits 格式(refactor:),但内容过于宽泛,未能准确反映主要变更内容。 建议改为更具体的标题,例如:'refactor: Remove buildHighlightBlocks fallback and centralize devLogSink parsing',以更清楚地反映核心变更。
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed PR 描述遵循仓库模板结构,选中了重构类型,声明了 AI Agent(Antigravity)自动创建,但两项提交前检查清单项目均未勾选。
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/background/handlers/saveHandlers.js`:
- Around line 140-152: The JSDoc and the inline comment disagree about handling
migratedFromOldKey: JSDoc says when migratedFromOldKey === true we must skip the
cache, but an inline comment still states "剛遷移可直接信任快取"; update the inline
comment in scripts/background/handlers/saveHandlers.js (the code that reads
migratedFromOldKey, forceRefresh and isCacheValid—the cache decision logic) to
match the JSDoc by clearly stating that migratedFromOldKey === true forces
skipping the cache (do not trust cached data) so both JSDoc and inline comment
convey the same behavior.

In `@scripts/utils/Logger.js`:
- Line 394: The comment referencing the flag uses "debugEnabled" but the actual
implementation and internal state use "_debugEnabled"; update the comment to
refer to "_debugEnabled" (or rename the internal variable to match if you prefer
public API consistency) so the comment and the implementation align—look for the
comment near the warn/error behavior and the internal flag _debugEnabled in
Logger.js (methods like warn, error, and any references to _debugEnabled) and
make the naming consistent.

In `@tests/unit/background/handlers/actionHandlers.coverage.test.js`:
- Around line 258-264: The test currently asserts only the output shape but not
that the mocked buildHighlightBlocks was invoked; update the test "有標註時
processContentResult 應呼叫 buildHighlightBlocks 並合併結果" to also assert that the
mock buildHighlightBlocks was called with the highlights input used in the call
to processContentResult (and any expected surrounding args such as the original
content or blocks if processContentResult passes them through), using
toHaveBeenCalledWith (or a suitable matcher like expect.arrayContaining) against
the highlights parameter so the test fails if the implementation stops invoking
buildHighlightBlocks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9e9885b8-9c94-4a56-a2f8-b5308057bcf2

📥 Commits

Reviewing files that changed from the base of the PR and between 2f55eeb and 2253e49.

📒 Files selected for processing (3)
  • scripts/background/handlers/saveHandlers.js
  • scripts/utils/Logger.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📜 Review details
🧰 Additional context used
📓 Path-based instructions (12)
**/*.js

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

此專案為 Chrome Extension (Manifest V3),必須使用 Vanilla JavaScript (ES6+ Modules) 作為核心語言,CommonJS 用於 Node 腳本。

Files:

  • scripts/utils/Logger.js
  • scripts/background/handlers/saveHandlers.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

禁止使用 TypeScript(除非明確要求)、React、Vue、Webpack。

Do not use console.log() statements in production code

Files:

  • scripts/utils/Logger.js
  • scripts/background/handlers/saveHandlers.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
**/*.{js,ts,tsx,jsx,py,java,cs,rb,go,swift,kt,php,md}

📄 CodeRabbit inference engine (.agents/.shared/knowledge/linter_rules.json)

Use Traditional Chinese (zh-TW) for all code comments, documentation, and string content, with strict enforcement except for technical terms and variable names

Files:

  • scripts/utils/Logger.js
  • scripts/background/handlers/saveHandlers.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
**/*.{js,ts,tsx,jsx,py,java,cs,rb,go,swift,kt,php}

📄 CodeRabbit inference engine (.agents/.shared/knowledge/linter_rules.json)

**/*.{js,ts,tsx,jsx,py,java,cs,rb,go,swift,kt,php}: Do not use magic numbers in code; extract them to constants defined in a dedicated constants module
Use a dedicated constants module for defining and exporting all constant values

Files:

  • scripts/utils/Logger.js
  • scripts/background/handlers/saveHandlers.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (.agents/.shared/knowledge/security_rules.json)

**/*.{js,ts,jsx,tsx}: Force strict whitelisting for file downloads: appended files must be restricted to '.json' or '.txt' extensions with explicitly designated MIME types. Never use arbitrary user input for filenames to prevent Reflected File Download (RFD) attacks.
Always prefer textContent for DOM operations. If SVG mixed content requires text updates, find the TEXT_NODE and update its textContent rather than using innerHTML on the parent.
Rely on LogSanitizer to strip sensitive properties (like sender, tab, PII) before emitting logs in production.

Follow the project's ESLint configuration and do not emit DeepSource (skipcq) comments.

**/*.{js,ts,jsx,tsx}: Reject PR if attempting to log complete sender, tab, request objects or raw HTML content. Require using IDs only (e.g., sender?.id, tab?.id), and wrapping URLs with sanitizeUrlForLogging() and API errors with sanitizeApiError().
Reject PR if attempting to store large HTML content, Base64 images, or heavy payloads into chrome.storage.sync. Require storing large payloads in chrome.storage.local or IndexedDB.
Reject PR if introducing new core business logic without corresponding unit or E2E tests. Require TDD and ensure Codecov checks do not fail (< 50%).
Avoid exposing internal-only, non-actionable, non-blocking cleanup/reconciliation/retry failures directly as user-facing errors. Keep the canonical user-facing state, log the internal failure, and handle retry/recovery inside the relevant service or canonical path unless the failure truly blocks the user's next action.
Verify all Logger.info/error calls correctly sanitize data with no PII and no raw HTML.
Verify cache and large data usage strictly targets chrome.storage.local rather than chrome.storage.sync.

Files:

  • scripts/utils/Logger.js
  • scripts/background/handlers/saveHandlers.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.agents/.shared/knowledge/debugging_rules.json)

**/*.{ts,tsx,js,jsx}: Use Logger.success(msg, ctx?) for operation success confirmation in Notion Chrome Extension. Output prefix: [INFO] ✅. The Logger class auto-manages the emoji icon.
Use Logger.start(msg, ctx?) for process launch notifications in Notion Chrome Extension. Output prefix: [INFO] 🚀. The Logger class auto-manages the emoji icon.
Use Logger.ready(msg, ctx?) for module or resource readiness notifications in Notion Chrome Extension. Output prefix: [INFO] 📦. The Logger class auto-manages the emoji icon.
Use Logger.info(msg, ctx?) for general informational messages in Notion Chrome Extension. Output prefix: [INFO]. No auto-managed emoji icon.
Use Logger.debug(msg, ctx?) for development debugging in Notion Chrome Extension. Output prefix: [DEBUG]. Controlled by enableDebugLogs switch.
Use Logger.warn(msg, ctx?) for non-fatal warnings in Notion Chrome Extension. Output prefix: [WARN] ⚠️. The Logger class auto-manages the emoji icon.
Use Logger.error(msg, ctx?) for error recording in Notion Chrome Extension. Output prefix: [ERROR] ❌. The Logger class auto-manages the emoji icon. Always displayed regardless of debug switch.
Do NOT manually insert emoji icons (✅, 🚀, 📦, ⚠️, ❌) into log messages. The Logger class auto-manages these icons. Only manually use special semantic emoji like 🔍 (search) or 🗑️ (delete) when needed for semantic clarity.
Use 'action' field in Logger context to record public API function names (e.g., 'loadHighlights', 'savePage') for structured logging in Notion Chrome Extension.
Use 'operation' field in Logger context to record internal operation steps (e.g., 'parseLocalStorage', 'buildUrl') for structured logging in Notion Chrome Extension.
Use 'phase' field in Logger context (optional) to record execution stages (e.g., 'validation', 'apiCall') for structured logging in Notion Chrome Extension.
Use 'result' field in Logger context to record operation results (e.g., 'blocked', 'success', 'failed') for structured logging in Notion Chr...

Files:

  • scripts/utils/Logger.js
  • scripts/background/handlers/saveHandlers.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
**/*.{js,ts,jsx,tsx,md}

📄 CodeRabbit inference engine (.agents/.shared/knowledge/code_review_rules.json)

Maintain code comments and documentation in Traditional Chinese.

Files:

  • scripts/utils/Logger.js
  • scripts/background/handlers/saveHandlers.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
**/*

⚙️ CodeRabbit configuration file

**/*: # Project Specific Guidelines

  1. Language: All user-facing UI text, strings, and messages MUST be in Traditional Chinese (zh-TW).
  2. Architecture: Follow the defined storage structures and specs. Do not introduce unauthorized storage fields.
  3. Code Quality: Avoid N+1 issues, blocking operations, and ensure high code quality. Suggest optimizations that follow modern JavaScript/Chrome Extension best practices.

Files:

  • scripts/utils/Logger.js
  • scripts/background/handlers/saveHandlers.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
scripts/background/handlers/*.js

📄 CodeRabbit inference engine (.agents/.shared/knowledge/message_bus.json)

scripts/background/handlers/*.js: All Chrome Extension runtime message bus actions must be defined in the message registry with type definitions for payload and response structures
Save action handlers must implement savePage, openNotionPage, checkNotionPageExists, and checkPageStatus message actions with specified payload and response types
Highlight action handlers must implement USER_ACTIVATE_SHORTCUT, startHighlight, updateHighlights, syncHighlights, and CLEAR_HIGHLIGHTS message actions with specified payload and response types
Auth action handlers must implement refreshOAuthToken message action with specified payload and response types, delegating all OAuth refresh requests through this single coordination entrypoint
Utility action handlers must implement devLogSink message action to forward content script logs to the background worker with level, message, and args payload parameters
syncHighlights action must handle remote page deletion detection by returning PAGE_DELETION_PENDING status without clearing the Notion binding on first detection, and only return PAGE_DELETED and clear the binding after confirmation-window reoccurrence
CLEAR_HIGHLIGHTS action must clear local highlights through the canonical Background storage path and perform best-effort visual cleanup on the page
All message responses must include a success boolean field indicating whether the action completed successfully

Files:

  • scripts/background/handlers/saveHandlers.js
**/*.test.js

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

單元測試邏輯使用 Jest,需要使用 Mocking patterns。

Files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
**/*.{test,spec}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.agents/.shared/knowledge/debugging_rules.json)

**/*.{test,spec}.{ts,tsx,js,jsx}: Run failing tests with command 'npx jest <path/to/test.js> --no-coverage' instead of full test suites in Notion Chrome Extension for faster feedback loops during logic fixes.
When mocking objects in Notion Chrome Extension tests, ensure mock object depth is sufficient. For example, mocking an img tag requires including 'dataset: {}' property.
When mocking Logger in Notion Chrome Extension tests, ensure all methods (success, start, ready, info, debug, warn, error) are defined as jest.fn() in the mock setup.
In Notion Chrome Extension tests using ErrorHandler.formatUserMessage, target assertions against Chinese strings (user-facing messages) rather than original English API messages for I18N awareness.
In Notion Chrome Extension tests, avoid vague string matching for Logger assertions. Use 'expect.objectContaining' to assert exact expected metadata objects for Logger calls.

Files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
**/*.{test,spec}.{js,ts}

📄 CodeRabbit inference engine (.agents/.shared/knowledge/testing_rules.json)

**/*.{test,spec}.{js,ts}: Always reference data structures (HTML snippets, Notion JSON responses) from .agents/.shared/references/ instead of hardcoding large payloads in test files.
Use .agents/.shared/references/notion_api/ for Notion block structures and database properties in test fixtures.
Do not mutate window.chrome directly. Override global.chrome for mocking Chrome API in tests.
Declare mock variables and spies at the top level and initialize them in beforeEach for Chrome API mocking setup.
Execute jest.clearAllMocks() and clean up global.chrome in afterEach to prevent test pollution.

Files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
🧠 Learnings (30)
📓 Common learnings
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/code_review_rules.json:0-0
Timestamp: 2026-03-23T04:16:46.480Z
Learning: Ensure the PR focuses on one specific issue without sneaking in unrelated refactoring (Single Responsibility).
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use Logger.debug(msg, ctx?) for development debugging in Notion Chrome Extension. Output prefix: [DEBUG]. Controlled by enableDebugLogs switch.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use 'reason' field in Logger context to record reason codes (e.g., 'restricted_url', 'timeout') for structured logging in Notion Chrome Extension.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use Logger.info(msg, ctx?) for general informational messages in Notion Chrome Extension. Output prefix: [INFO]. No auto-managed emoji icon.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{test,spec}.{ts,tsx,js,jsx} : When mocking Logger in Notion Chrome Extension tests, ensure all methods (success, start, ready, info, debug, warn, error) are defined as jest.fn() in the mock setup.

Applied to files:

  • scripts/utils/Logger.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use Logger.start(msg, ctx?) for process launch notifications in Notion Chrome Extension. Output prefix: [INFO] 🚀. The Logger class auto-manages the emoji icon.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-23T04:16:46.480Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/code_review_rules.json:0-0
Timestamp: 2026-03-23T04:16:46.480Z
Learning: Applies to **/*.{js,ts,jsx,tsx} : Verify all Logger.info/error calls correctly sanitize data with no PII and no raw HTML.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use 'operation' field in Logger context to record internal operation steps (e.g., 'parseLocalStorage', 'buildUrl') for structured logging in Notion Chrome Extension.

Applied to files:

  • scripts/utils/Logger.js
  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-22T05:25:18.555Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/message_bus.json:0-0
Timestamp: 2026-03-22T05:25:18.555Z
Learning: Applies to scripts/background/handlers/*.js : Utility action handlers must implement devLogSink message action to forward content script logs to the background worker with level, message, and args payload parameters

Applied to files:

  • scripts/utils/Logger.js
  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use Logger.error(msg, ctx?) for error recording in Notion Chrome Extension. Output prefix: [ERROR] ❌. The Logger class auto-manages the emoji icon. Always displayed regardless of debug switch.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-03T12:37:10.274Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/security_rules.json:0-0
Timestamp: 2026-03-03T12:37:10.274Z
Learning: Applies to **/*.{js,ts,jsx,tsx} : Rely on `LogSanitizer` to strip sensitive properties (like `sender`, `tab`, PII) before emitting logs in production.

Applied to files:

  • scripts/utils/Logger.js
  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use Logger.ready(msg, ctx?) for module or resource readiness notifications in Notion Chrome Extension. Output prefix: [INFO] 📦. The Logger class auto-manages the emoji icon.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-14T15:55:36.020Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/storage_schema.json:0-0
Timestamp: 2026-03-14T15:55:36.020Z
Learning: Applies to scripts/background/services/StorageService.js : Store debug logging preference in `enableDebugLogs` key (boolean) in chrome.storage.sync

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: When debugging content script highlighting in Notion Chrome Extension, verify initialization completion by checking for '[INFO] ✅ 初始化完成' log message from Logger.success('初始化完成', { action: 'initialize' }) call.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use Logger.warn(msg, ctx?) for non-fatal warnings in Notion Chrome Extension. Output prefix: [WARN] ⚠️. The Logger class auto-manages the emoji icon.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-22T05:25:18.555Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/message_bus.json:0-0
Timestamp: 2026-03-22T05:25:18.555Z
Learning: Applies to scripts/background/handlers/*.js : CLEAR_HIGHLIGHTS action must clear local highlights through the canonical Background storage path and perform best-effort visual cleanup on the page

Applied to files:

  • scripts/background/handlers/saveHandlers.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-22T05:25:18.555Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/message_bus.json:0-0
Timestamp: 2026-03-22T05:25:18.555Z
Learning: Applies to scripts/background/handlers/*.js : syncHighlights action must handle remote page deletion detection by returning PAGE_DELETION_PENDING status without clearing the Notion binding on first detection, and only return PAGE_DELETED and clear the binding after confirmation-window reoccurrence

Applied to files:

  • scripts/background/handlers/saveHandlers.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-22T05:25:18.555Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/message_bus.json:0-0
Timestamp: 2026-03-22T05:25:18.555Z
Learning: Applies to scripts/background/handlers/*.js : Highlight action handlers must implement USER_ACTIVATE_SHORTCUT, startHighlight, updateHighlights, syncHighlights, and CLEAR_HIGHLIGHTS message actions with specified payload and response types

Applied to files:

  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use 'action' field in Logger context to record public API function names (e.g., 'loadHighlights', 'savePage') for structured logging in Notion Chrome Extension.

Applied to files:

  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-14T15:55:36.020Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/storage_schema.json:0-0
Timestamp: 2026-03-14T15:55:36.020Z
Learning: Applies to scripts/background/services/StorageService.js : Use `page_{stableUrl}` key pattern to store unified page state containing Notion metadata and highlights in chrome.storage.local, with fields: notion (object | null), highlights (array), and metadata (object)

Applied to files:

  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: When investigating highlight recovery failures in Notion Chrome Extension, verify URL consistency between stored highlights and current page, check for text content mutations on the source page, and confirm CSS Highlight API support exists.

Applied to files:

  • scripts/background/handlers/saveHandlers.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-14T15:55:36.020Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/storage_schema.json:0-0
Timestamp: 2026-03-14T15:55:36.020Z
Learning: Applies to scripts/background/services/StorageService.js : Store highlight content sync style in `highlightContentStyle` key (string) in chrome.storage.sync

Applied to files:

  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-23T04:16:46.480Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/code_review_rules.json:0-0
Timestamp: 2026-03-23T04:16:46.480Z
Learning: Applies to **/*.{js,ts,jsx,tsx} : Reject PR if attempting to log complete sender, tab, request objects or raw HTML content. Require using IDs only (e.g., sender?.id, tab?.id), and wrapping URLs with sanitizeUrlForLogging() and API errors with sanitizeApiError().

Applied to files:

  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{test,spec}.{ts,tsx,js,jsx} : Run failing tests with command 'npx jest <path/to/test.js> --no-coverage' instead of full test suites in Notion Chrome Extension for faster feedback loops during logic fixes.

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-10T08:21:13.819Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/testing_rules.json:0-0
Timestamp: 2026-03-10T08:21:13.819Z
Learning: Applies to **/{storage,migration,highlight}/**/*.{js,ts} : Achieve 90%+ code coverage for Storage, Migration, and Highlighting algorithms in unit tests.

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-10T08:21:13.819Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/testing_rules.json:0-0
Timestamp: 2026-03-10T08:21:13.819Z
Learning: Applies to **/*.{test,spec}.{js,ts} : Use .agents/.shared/references/notion_api/ for Notion block structures and database properties in test fixtures.

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{test,spec}.{ts,tsx,js,jsx} : In Notion Chrome Extension tests using ErrorHandler.formatUserMessage, target assertions against Chinese strings (user-facing messages) rather than original English API messages for I18N awareness.

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{test,spec}.{ts,tsx,js,jsx} : In Notion Chrome Extension tests, avoid vague string matching for Logger assertions. Use 'expect.objectContaining' to assert exact expected metadata objects for Logger calls.

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-10T08:21:13.819Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/testing_rules.json:0-0
Timestamp: 2026-03-10T08:21:13.819Z
Learning: Applies to tests/e2e/specs/**/*.spec.{js,ts} : Reference tests/e2e/specs/highlight.spec.js and use serviceWorker.evaluate for direct injection testing in e2e tests.

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-02-26T20:59:55.454Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-02-26T20:59:55.454Z
Learning: Applies to **/*.test.js : 單元測試邏輯使用 Jest,需要使用 Mocking patterns。

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
🔇 Additional comments (4)
scripts/background/handlers/saveHandlers.js (4)

20-20: parseArgsToContext 匯入重構方向正確。

將 args 解析邏輯集中到共用函式,可降低 devLogSink 後續維護時的行為分歧風險。


93-94: processContentResult 直接組裝 highlight blocks 的簡化是合理的。

這段改動讓流程更直觀,且保留由 buildHighlightBlocks 統一處理輸出格式。


527-527: 既有頁面更新路徑的 highlight 建構簡化可接受。

processContentResult 一致改成直接呼叫 buildHighlightBlocks,可減少重複防禦分支。


1140-1148: 驗證完成:Logger.addLogToBuffer() 內部已確實套用 LogSanitizer.sanitizeEntry() 進行脫敏。

程式碼路徑確認:當呼叫 Logger.addLogToBuffer({ level, message, context, ... }) 時,方法在第 515 行內部調用 LogSanitizer.sanitizeEntry(String(message), context, { isDev: _debugEnabled }),將敏感欄位(如 sender、tab、email、properties 等)脫敏後,才在第 523 行存儲到 LogBuffer。無需額外修正。

Comment thread scripts/background/handlers/saveHandlers.js
Comment thread scripts/utils/Logger.js Outdated
- 修改 saveHandlers.js 中的註解,強調從舊 key 遷移後不應直接信任快取,必須重新向 Notion 驗證。
- 更新 Logger.js 中的註解,明確指出 warn/error 訊息的輸出行為。
- 在 actionHandlers.coverage.test.js 中新增對 buildHighlightBlocks 的測試,確保在有標註時正確呼叫並合併結果。
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/unit/background/handlers/actionHandlers.coverage.test.js`:
- Around line 259-270: Add a unit test that covers the "migratedFromOldKey ===
true" path in checkPageStatus: arrange inputs where migratedFromOldKey is true
(mock any dependencies such as TTL/cache lookup), call checkPageStatus, and
assert the function bypasses TTL cache (e.g., verify the TTL/cache-check
function is not invoked or that the returned status indicates cache was
skipped). Use the same test file and mocking pattern as the existing tests so
this new test ensures the migration-flag decision is exercised.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: fdfa2830-ab7c-4889-a18b-078f17a558b6

📥 Commits

Reviewing files that changed from the base of the PR and between 2253e49 and 4e43ef6.

📒 Files selected for processing (3)
  • scripts/background/handlers/saveHandlers.js
  • scripts/utils/Logger.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📜 Review details
🧰 Additional context used
📓 Path-based instructions (12)
**/*.js

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

此專案為 Chrome Extension (Manifest V3),必須使用 Vanilla JavaScript (ES6+ Modules) 作為核心語言,CommonJS 用於 Node 腳本。

Files:

  • scripts/utils/Logger.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
  • scripts/background/handlers/saveHandlers.js
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

禁止使用 TypeScript(除非明確要求)、React、Vue、Webpack。

Do not use console.log() statements in production code

Files:

  • scripts/utils/Logger.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
  • scripts/background/handlers/saveHandlers.js
**/*.{js,ts,tsx,jsx,py,java,cs,rb,go,swift,kt,php,md}

📄 CodeRabbit inference engine (.agents/.shared/knowledge/linter_rules.json)

Use Traditional Chinese (zh-TW) for all code comments, documentation, and string content, with strict enforcement except for technical terms and variable names

Files:

  • scripts/utils/Logger.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
  • scripts/background/handlers/saveHandlers.js
**/*.{js,ts,tsx,jsx,py,java,cs,rb,go,swift,kt,php}

📄 CodeRabbit inference engine (.agents/.shared/knowledge/linter_rules.json)

**/*.{js,ts,tsx,jsx,py,java,cs,rb,go,swift,kt,php}: Do not use magic numbers in code; extract them to constants defined in a dedicated constants module
Use a dedicated constants module for defining and exporting all constant values

Files:

  • scripts/utils/Logger.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
  • scripts/background/handlers/saveHandlers.js
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (.agents/.shared/knowledge/security_rules.json)

**/*.{js,ts,jsx,tsx}: Force strict whitelisting for file downloads: appended files must be restricted to '.json' or '.txt' extensions with explicitly designated MIME types. Never use arbitrary user input for filenames to prevent Reflected File Download (RFD) attacks.
Always prefer textContent for DOM operations. If SVG mixed content requires text updates, find the TEXT_NODE and update its textContent rather than using innerHTML on the parent.
Rely on LogSanitizer to strip sensitive properties (like sender, tab, PII) before emitting logs in production.

Follow the project's ESLint configuration and do not emit DeepSource (skipcq) comments.

**/*.{js,ts,jsx,tsx}: Reject PR if attempting to log complete sender, tab, request objects or raw HTML content. Require using IDs only (e.g., sender?.id, tab?.id), and wrapping URLs with sanitizeUrlForLogging() and API errors with sanitizeApiError().
Reject PR if attempting to store large HTML content, Base64 images, or heavy payloads into chrome.storage.sync. Require storing large payloads in chrome.storage.local or IndexedDB.
Reject PR if introducing new core business logic without corresponding unit or E2E tests. Require TDD and ensure Codecov checks do not fail (< 50%).
Avoid exposing internal-only, non-actionable, non-blocking cleanup/reconciliation/retry failures directly as user-facing errors. Keep the canonical user-facing state, log the internal failure, and handle retry/recovery inside the relevant service or canonical path unless the failure truly blocks the user's next action.
Verify all Logger.info/error calls correctly sanitize data with no PII and no raw HTML.
Verify cache and large data usage strictly targets chrome.storage.local rather than chrome.storage.sync.

Files:

  • scripts/utils/Logger.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
  • scripts/background/handlers/saveHandlers.js
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.agents/.shared/knowledge/debugging_rules.json)

**/*.{ts,tsx,js,jsx}: Use Logger.success(msg, ctx?) for operation success confirmation in Notion Chrome Extension. Output prefix: [INFO] ✅. The Logger class auto-manages the emoji icon.
Use Logger.start(msg, ctx?) for process launch notifications in Notion Chrome Extension. Output prefix: [INFO] 🚀. The Logger class auto-manages the emoji icon.
Use Logger.ready(msg, ctx?) for module or resource readiness notifications in Notion Chrome Extension. Output prefix: [INFO] 📦. The Logger class auto-manages the emoji icon.
Use Logger.info(msg, ctx?) for general informational messages in Notion Chrome Extension. Output prefix: [INFO]. No auto-managed emoji icon.
Use Logger.debug(msg, ctx?) for development debugging in Notion Chrome Extension. Output prefix: [DEBUG]. Controlled by enableDebugLogs switch.
Use Logger.warn(msg, ctx?) for non-fatal warnings in Notion Chrome Extension. Output prefix: [WARN] ⚠️. The Logger class auto-manages the emoji icon.
Use Logger.error(msg, ctx?) for error recording in Notion Chrome Extension. Output prefix: [ERROR] ❌. The Logger class auto-manages the emoji icon. Always displayed regardless of debug switch.
Do NOT manually insert emoji icons (✅, 🚀, 📦, ⚠️, ❌) into log messages. The Logger class auto-manages these icons. Only manually use special semantic emoji like 🔍 (search) or 🗑️ (delete) when needed for semantic clarity.
Use 'action' field in Logger context to record public API function names (e.g., 'loadHighlights', 'savePage') for structured logging in Notion Chrome Extension.
Use 'operation' field in Logger context to record internal operation steps (e.g., 'parseLocalStorage', 'buildUrl') for structured logging in Notion Chrome Extension.
Use 'phase' field in Logger context (optional) to record execution stages (e.g., 'validation', 'apiCall') for structured logging in Notion Chrome Extension.
Use 'result' field in Logger context to record operation results (e.g., 'blocked', 'success', 'failed') for structured logging in Notion Chr...

Files:

  • scripts/utils/Logger.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
  • scripts/background/handlers/saveHandlers.js
**/*.{js,ts,jsx,tsx,md}

📄 CodeRabbit inference engine (.agents/.shared/knowledge/code_review_rules.json)

Maintain code comments and documentation in Traditional Chinese.

Files:

  • scripts/utils/Logger.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
  • scripts/background/handlers/saveHandlers.js
**/*

⚙️ CodeRabbit configuration file

**/*: # Project Specific Guidelines

  1. Language: All user-facing UI text, strings, and messages MUST be in Traditional Chinese (zh-TW).
  2. Architecture: Follow the defined storage structures and specs. Do not introduce unauthorized storage fields.
  3. Code Quality: Avoid N+1 issues, blocking operations, and ensure high code quality. Suggest optimizations that follow modern JavaScript/Chrome Extension best practices.

Files:

  • scripts/utils/Logger.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
  • scripts/background/handlers/saveHandlers.js
**/*.test.js

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

單元測試邏輯使用 Jest,需要使用 Mocking patterns。

Files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
**/*.{test,spec}.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.agents/.shared/knowledge/debugging_rules.json)

**/*.{test,spec}.{ts,tsx,js,jsx}: Run failing tests with command 'npx jest <path/to/test.js> --no-coverage' instead of full test suites in Notion Chrome Extension for faster feedback loops during logic fixes.
When mocking objects in Notion Chrome Extension tests, ensure mock object depth is sufficient. For example, mocking an img tag requires including 'dataset: {}' property.
When mocking Logger in Notion Chrome Extension tests, ensure all methods (success, start, ready, info, debug, warn, error) are defined as jest.fn() in the mock setup.
In Notion Chrome Extension tests using ErrorHandler.formatUserMessage, target assertions against Chinese strings (user-facing messages) rather than original English API messages for I18N awareness.
In Notion Chrome Extension tests, avoid vague string matching for Logger assertions. Use 'expect.objectContaining' to assert exact expected metadata objects for Logger calls.

Files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
**/*.{test,spec}.{js,ts}

📄 CodeRabbit inference engine (.agents/.shared/knowledge/testing_rules.json)

**/*.{test,spec}.{js,ts}: Always reference data structures (HTML snippets, Notion JSON responses) from .agents/.shared/references/ instead of hardcoding large payloads in test files.
Use .agents/.shared/references/notion_api/ for Notion block structures and database properties in test fixtures.
Do not mutate window.chrome directly. Override global.chrome for mocking Chrome API in tests.
Declare mock variables and spies at the top level and initialize them in beforeEach for Chrome API mocking setup.
Execute jest.clearAllMocks() and clean up global.chrome in afterEach to prevent test pollution.

Files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
scripts/background/handlers/*.js

📄 CodeRabbit inference engine (.agents/.shared/knowledge/message_bus.json)

scripts/background/handlers/*.js: All Chrome Extension runtime message bus actions must be defined in the message registry with type definitions for payload and response structures
Save action handlers must implement savePage, openNotionPage, checkNotionPageExists, and checkPageStatus message actions with specified payload and response types
Highlight action handlers must implement USER_ACTIVATE_SHORTCUT, startHighlight, updateHighlights, syncHighlights, and CLEAR_HIGHLIGHTS message actions with specified payload and response types
Auth action handlers must implement refreshOAuthToken message action with specified payload and response types, delegating all OAuth refresh requests through this single coordination entrypoint
Utility action handlers must implement devLogSink message action to forward content script logs to the background worker with level, message, and args payload parameters
syncHighlights action must handle remote page deletion detection by returning PAGE_DELETION_PENDING status without clearing the Notion binding on first detection, and only return PAGE_DELETED and clear the binding after confirmation-window reoccurrence
CLEAR_HIGHLIGHTS action must clear local highlights through the canonical Background storage path and perform best-effort visual cleanup on the page
All message responses must include a success boolean field indicating whether the action completed successfully

Files:

  • scripts/background/handlers/saveHandlers.js
🧠 Learnings (41)
📓 Common learnings
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/code_review_rules.json:0-0
Timestamp: 2026-03-23T04:16:46.480Z
Learning: Applies to **/*.{js,ts,jsx,tsx} : Reject PR if introducing new core business logic without corresponding unit or E2E tests. Require TDD and ensure Codecov checks do not fail (< 50%).
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use 'reason' field in Logger context to record reason codes (e.g., 'restricted_url', 'timeout') for structured logging in Notion Chrome Extension.
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/code_review_rules.json:0-0
Timestamp: 2026-03-23T04:16:46.480Z
Learning: Ensure the PR focuses on one specific issue without sneaking in unrelated refactoring (Single Responsibility).
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/testing_rules.json:0-0
Timestamp: 2026-03-10T08:21:13.819Z
Learning: Applies to **/{storage,migration,highlight}/**/*.{js,ts} : Achieve 90%+ code coverage for Storage, Migration, and Highlighting algorithms in unit tests.
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use 'result' field in Logger context to record operation results (e.g., 'blocked', 'success', 'failed') for structured logging in Notion Chrome Extension.
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: When investigating highlight recovery failures in Notion Chrome Extension, check for migration completion by verifying '遷移完成' log message exists in logs.
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: When investigating highlight recovery failures in Notion Chrome Extension, verify URL consistency between stored highlights and current page, check for text content mutations on the source page, and confirm CSS Highlight API support exists.
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/message_bus.json:0-0
Timestamp: 2026-03-22T05:25:18.555Z
Learning: Applies to scripts/background/handlers/*.js : syncHighlights action must handle remote page deletion detection by returning PAGE_DELETION_PENDING status without clearing the Notion binding on first detection, and only return PAGE_DELETED and clear the binding after confirmation-window reoccurrence
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: When debugging content script highlighting in Notion Chrome Extension, verify initialization completion by checking for '[INFO] ✅ 初始化完成' log message from Logger.success('初始化完成', { action: 'initialize' }) call.
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/storage_schema.json:0-0
Timestamp: 2026-03-14T15:55:36.020Z
Learning: Applies to scripts/background/services/StorageService.js : Use `page_{stableUrl}` key pattern to store unified page state containing Notion metadata and highlights in chrome.storage.local, with fields: notion (object | null), highlights (array), and metadata (object)
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use Logger.debug(msg, ctx?) for development debugging in Notion Chrome Extension. Output prefix: [DEBUG]. Controlled by enableDebugLogs switch.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{test,spec}.{ts,tsx,js,jsx} : When mocking Logger in Notion Chrome Extension tests, ensure all methods (success, start, ready, info, debug, warn, error) are defined as jest.fn() in the mock setup.

Applied to files:

  • scripts/utils/Logger.js
  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use 'reason' field in Logger context to record reason codes (e.g., 'restricted_url', 'timeout') for structured logging in Notion Chrome Extension.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use 'operation' field in Logger context to record internal operation steps (e.g., 'parseLocalStorage', 'buildUrl') for structured logging in Notion Chrome Extension.

Applied to files:

  • scripts/utils/Logger.js
  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-23T04:16:46.480Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/code_review_rules.json:0-0
Timestamp: 2026-03-23T04:16:46.480Z
Learning: Applies to **/*.{js,ts,jsx,tsx} : Verify all Logger.info/error calls correctly sanitize data with no PII and no raw HTML.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use Logger.start(msg, ctx?) for process launch notifications in Notion Chrome Extension. Output prefix: [INFO] 🚀. The Logger class auto-manages the emoji icon.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use Logger.info(msg, ctx?) for general informational messages in Notion Chrome Extension. Output prefix: [INFO]. No auto-managed emoji icon.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-22T05:25:18.555Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/message_bus.json:0-0
Timestamp: 2026-03-22T05:25:18.555Z
Learning: Applies to scripts/background/handlers/*.js : Utility action handlers must implement devLogSink message action to forward content script logs to the background worker with level, message, and args payload parameters

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use 'action' field in Logger context to record public API function names (e.g., 'loadHighlights', 'savePage') for structured logging in Notion Chrome Extension.

Applied to files:

  • scripts/utils/Logger.js
  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use 'result' field in Logger context to record operation results (e.g., 'blocked', 'success', 'failed') for structured logging in Notion Chrome Extension.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use Logger.warn(msg, ctx?) for non-fatal warnings in Notion Chrome Extension. Output prefix: [WARN] ⚠️. The Logger class auto-manages the emoji icon.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use Logger.error(msg, ctx?) for error recording in Notion Chrome Extension. Output prefix: [ERROR] ❌. The Logger class auto-manages the emoji icon. Always displayed regardless of debug switch.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-14T15:55:36.020Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/storage_schema.json:0-0
Timestamp: 2026-03-14T15:55:36.020Z
Learning: Applies to scripts/background/services/StorageService.js : Store debug logging preference in `enableDebugLogs` key (boolean) in chrome.storage.sync

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Do NOT manually insert emoji icons (✅, 🚀, 📦, ⚠️, ❌) into log messages. The Logger class auto-manages these icons. Only manually use special semantic emoji like 🔍 (search) or 🗑️ (delete) when needed for semantic clarity.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: When debugging content script highlighting in Notion Chrome Extension, verify initialization completion by checking for '[INFO] ✅ 初始化完成' log message from Logger.success('初始化完成', { action: 'initialize' }) call.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Use Logger.ready(msg, ctx?) for module or resource readiness notifications in Notion Chrome Extension. Output prefix: [INFO] 📦. The Logger class auto-manages the emoji icon.

Applied to files:

  • scripts/utils/Logger.js
📚 Learning: 2026-03-22T05:25:18.555Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/message_bus.json:0-0
Timestamp: 2026-03-22T05:25:18.555Z
Learning: Applies to scripts/background/handlers/*.js : CLEAR_HIGHLIGHTS action must clear local highlights through the canonical Background storage path and perform best-effort visual cleanup on the page

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-10T08:21:13.819Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/testing_rules.json:0-0
Timestamp: 2026-03-10T08:21:13.819Z
Learning: Applies to **/{storage,migration,highlight}/**/*.{js,ts} : Achieve 90%+ code coverage for Storage, Migration, and Highlighting algorithms in unit tests.

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-22T05:25:18.555Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/message_bus.json:0-0
Timestamp: 2026-03-22T05:25:18.555Z
Learning: Applies to scripts/background/handlers/*.js : syncHighlights action must handle remote page deletion detection by returning PAGE_DELETION_PENDING status without clearing the Notion binding on first detection, and only return PAGE_DELETED and clear the binding after confirmation-window reoccurrence

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-10T08:21:13.819Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/testing_rules.json:0-0
Timestamp: 2026-03-10T08:21:13.819Z
Learning: Applies to tests/e2e/specs/**/*.spec.{js,ts} : Reference tests/e2e/specs/highlight.spec.js and use serviceWorker.evaluate for direct injection testing in e2e tests.

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: When investigating highlight recovery failures in Notion Chrome Extension, verify URL consistency between stored highlights and current page, check for text content mutations on the source page, and confirm CSS Highlight API support exists.

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{test,spec}.{ts,tsx,js,jsx} : Run failing tests with command 'npx jest <path/to/test.js> --no-coverage' instead of full test suites in Notion Chrome Extension for faster feedback loops during logic fixes.

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-02-26T20:59:55.454Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-02-26T20:59:55.454Z
Learning: Applies to **/*.test.js : 單元測試邏輯使用 Jest,需要使用 Mocking patterns。

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{test,spec}.{ts,tsx,js,jsx} : In Notion Chrome Extension tests using ErrorHandler.formatUserMessage, target assertions against Chinese strings (user-facing messages) rather than original English API messages for I18N awareness.

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{test,spec}.{ts,tsx,js,jsx} : In Notion Chrome Extension tests, avoid vague string matching for Logger assertions. Use 'expect.objectContaining' to assert exact expected metadata objects for Logger calls.

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{test,spec}.{ts,tsx,js,jsx} : When mocking objects in Notion Chrome Extension tests, ensure mock object depth is sufficient. For example, mocking an img tag requires including 'dataset: {}' property.

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: When investigating highlight recovery failures in Notion Chrome Extension, check for migration completion by verifying '遷移完成' log message exists in logs.

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-02-26T20:59:55.454Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2026-02-26T20:59:55.454Z
Learning: Commit Message 必須使用繁體中文,若變更的檔案僅包含測試程式碼(如 .test.js, .spec.js, tests/ 目錄),則必須使用 `test` 類型,絕不可以使用 `feat` 或 `fix`。

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: When debugging content script highlighting functionality in Notion Chrome Extension, verify CSS.highlights API support by running 'highlights' in CSS in the target website's DevTools console.

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: When debugging content script highlighting in Notion Chrome Extension, inspect local storage using 'chrome.storage.local.get(['highlights_${url}'])' and compare stored URL with current URL using normalizeUrl(window.location.href).

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-06T18:35:38.641Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/debugging_rules.json:0-0
Timestamp: 2026-03-06T18:35:38.641Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : Log only necessary IDs and sanitized error messages in Notion Chrome Extension. Follow security best practices documented in docs/guides/SECURITY_BEST_PRACTICES.md.

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-10T08:21:13.819Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/testing_rules.json:0-0
Timestamp: 2026-03-10T08:21:13.819Z
Learning: Applies to **/*.{test,spec}.{js,ts} : Use .agents/.shared/references/notion_api/ for Notion block structures and database properties in test fixtures.

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
📚 Learning: 2026-03-22T05:25:18.555Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/message_bus.json:0-0
Timestamp: 2026-03-22T05:25:18.555Z
Learning: Applies to scripts/background/handlers/*.js : Highlight action handlers must implement USER_ACTIVATE_SHORTCUT, startHighlight, updateHighlights, syncHighlights, and CLEAR_HIGHLIGHTS message actions with specified payload and response types

Applied to files:

  • tests/unit/background/handlers/actionHandlers.coverage.test.js
  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-14T15:55:36.020Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/storage_schema.json:0-0
Timestamp: 2026-03-14T15:55:36.020Z
Learning: Applies to scripts/background/services/StorageService.js : Use `page_{stableUrl}` key pattern to store unified page state containing Notion metadata and highlights in chrome.storage.local, with fields: notion (object | null), highlights (array), and metadata (object)

Applied to files:

  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-22T05:25:18.555Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/message_bus.json:0-0
Timestamp: 2026-03-22T05:25:18.555Z
Learning: Applies to scripts/background/handlers/*.js : Save action handlers must implement savePage, openNotionPage, checkNotionPageExists, and checkPageStatus message actions with specified payload and response types

Applied to files:

  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-14T15:55:36.020Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/storage_schema.json:0-0
Timestamp: 2026-03-14T15:55:36.020Z
Learning: Applies to scripts/background/services/StorageService.js : Store highlight content sync style in `highlightContentStyle` key (string) in chrome.storage.sync

Applied to files:

  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-23T04:16:46.480Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/code_review_rules.json:0-0
Timestamp: 2026-03-23T04:16:46.480Z
Learning: Applies to **/*.{js,ts,jsx,tsx} : Verify cache and large data usage strictly targets chrome.storage.local rather than chrome.storage.sync.

Applied to files:

  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-23T04:16:46.480Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/code_review_rules.json:0-0
Timestamp: 2026-03-23T04:16:46.480Z
Learning: Applies to **/*.{js,ts,jsx,tsx,md} : Maintain code comments and documentation in Traditional Chinese.

Applied to files:

  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-03T12:37:10.274Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/security_rules.json:0-0
Timestamp: 2026-03-03T12:37:10.274Z
Learning: Applies to **/*.{js,ts,jsx,tsx} : Rely on `LogSanitizer` to strip sensitive properties (like `sender`, `tab`, PII) before emitting logs in production.

Applied to files:

  • scripts/background/handlers/saveHandlers.js
📚 Learning: 2026-03-23T04:16:46.480Z
Learnt from: CR
Repo: cowcfj/save-to-notion PR: 0
File: .agents/.shared/knowledge/code_review_rules.json:0-0
Timestamp: 2026-03-23T04:16:46.480Z
Learning: Applies to **/*.{js,ts,jsx,tsx} : Reject PR if attempting to log complete sender, tab, request objects or raw HTML content. Require using IDs only (e.g., sender?.id, tab?.id), and wrapping URLs with sanitizeUrlForLogging() and API errors with sanitizeApiError().

Applied to files:

  • scripts/background/handlers/saveHandlers.js
🔇 Additional comments (4)
scripts/utils/Logger.js (1)

390-397: 設計註解與目前行為一致,方向正確。

這段說明清楚定義了 debug/infowarn/error 的可觀察行為,且與現有實作一致,能降低後續維護誤解。

scripts/background/handlers/saveHandlers.js (3)

93-95: buildHighlightBlocks 呼叫路徑已統一,這個重構是正向的。

兩條流程都改為直接建構 highlight blocks,避免分支行為不一致,後續維護成本更低。

Also applies to: 527-531


140-152: 快取策略註解已前後一致,修正到位。

JSDoc 與內嵌註解現在都明確表達「遷移後必須略過快取並重新驗證」,可避免後續誤改。

Also applies to: 1065-1065


20-20: parseArgsToContext 抽共用解析邏輯,整體可讀性更好。

devLogSink 改用同一套 args→context 規則,避免重複實作與 Error 欄位遺漏。

Also applies to: 1140-1141

Comment thread tests/unit/background/handlers/actionHandlers.coverage.test.js
在 actionHandlers.coverage.test.js 中新增測試案例,當 migratedFromOldKey 為 true 時,應略過快取並驗證頁面存在性。測試中模擬了快取仍在有效期內的情況,並確保即使快取有效,仍會呼叫 checkPageExists 以確認頁面存在。這有助於確保在遷移過程中頁面的正確性。
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 4, 2026

@cowcfj cowcfj merged commit a611736 into main Apr 4, 2026
6 checks passed
@cowcfj cowcfj deleted the fix/code-review-w2-n1-n2-n4 branch April 4, 2026 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant