refactor: Improve code review suggestions and logging logic#384
Conversation
- W-2: 以 parseArgsToContext 取代 devLogSink 中的重複手動展開邏輯 - N-1: 移除 buildHighlightBlocks 兩處誤導性 fallback,並更新對應測試 - N-2: 為 Logger 補充輸出等級設計決策說明(warn/error 永遠輸出) - N-4: 為 _shouldReturnCachedStatus 補充完整 JSDoc 及遷移後強制驗證說明
Summary of ChangesHello, 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
Using Gemini Code AssistThe 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
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 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
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Code Review
此拉取請求主要進行了代碼重構與文件完善。在 saveHandlers.js 中,引入了 parseArgsToContext 函數以統一處理日誌參數解析,並簡化了 buildHighlightBlocks 的調用邏輯,移除了冗餘的 fallback 檢查。同時,為 _shouldReturnCachedStatus 函數添加了詳細的 JSDoc 註釋,說明了在 key 遷移後的快取驗證邏輯。在 Logger.js 中,新增了關於不同日誌等級(如 debug/info 與 warn/error)輸出行為的設計決策說明。此外,單元測試也隨之更新,移除了過時的 fallback 測試並加強了標註處理的驗證。目前沒有發現具體問題,無進一步反饋。
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
📝 WalkthroughWalkthrough本次变更移除围绕 buildHighlightBlocks 的防御性回退,processContentResult 与 _handleExistingPageUpdate 现在始终调用 buildHighlightBlocks(highlights)。在 checkPageStatus 的缓存验证逻辑中,当 migratedFromOldKey 为 true 时强制不返回缓存状态(改为继续向 Notion 重新校验)。将 devLogSink 中对 request.args 的解析集中为 parseArgsToContext(args)。新增/调整了相关单元测试,并在 Logger.js 中加入关于可观察日志级别行为的设计注释(仅注释,无运行时改动)。 Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ 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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
scripts/background/handlers/saveHandlers.jsscripts/utils/Logger.jstests/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.jsscripts/background/handlers/saveHandlers.jstests/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.jsscripts/background/handlers/saveHandlers.jstests/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.jsscripts/background/handlers/saveHandlers.jstests/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.jsscripts/background/handlers/saveHandlers.jstests/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 prefertextContentfor DOM operations. If SVG mixed content requires text updates, find the TEXT_NODE and update itstextContentrather than usinginnerHTMLon the parent.
Rely onLogSanitizerto strip sensitive properties (likesender,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.jsscripts/background/handlers/saveHandlers.jstests/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.jsscripts/background/handlers/saveHandlers.jstests/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.jsscripts/background/handlers/saveHandlers.jstests/unit/background/handlers/actionHandlers.coverage.test.js
**/*
⚙️ CodeRabbit configuration file
**/*: # Project Specific Guidelines
- Language: All user-facing UI text, strings, and messages MUST be in Traditional Chinese (zh-TW).
- Architecture: Follow the defined storage structures and specs. Do not introduce unauthorized storage fields.
- 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.jsscripts/background/handlers/saveHandlers.jstests/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.jstests/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.jsscripts/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.jsscripts/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.jsscripts/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.jstests/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.jstests/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.jstests/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。無需額外修正。
- 修改 saveHandlers.js 中的註解,強調從舊 key 遷移後不應直接信任快取,必須重新向 Notion 驗證。 - 更新 Logger.js 中的註解,明確指出 warn/error 訊息的輸出行為。 - 在 actionHandlers.coverage.test.js 中新增對 buildHighlightBlocks 的測試,確保在有標註時正確呼叫並合併結果。
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
scripts/background/handlers/saveHandlers.jsscripts/utils/Logger.jstests/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.jstests/unit/background/handlers/actionHandlers.coverage.test.jsscripts/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.jstests/unit/background/handlers/actionHandlers.coverage.test.jsscripts/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.jstests/unit/background/handlers/actionHandlers.coverage.test.jsscripts/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.jstests/unit/background/handlers/actionHandlers.coverage.test.jsscripts/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 prefertextContentfor DOM operations. If SVG mixed content requires text updates, find the TEXT_NODE and update itstextContentrather than usinginnerHTMLon the parent.
Rely onLogSanitizerto strip sensitive properties (likesender,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.jstests/unit/background/handlers/actionHandlers.coverage.test.jsscripts/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.jstests/unit/background/handlers/actionHandlers.coverage.test.jsscripts/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.jstests/unit/background/handlers/actionHandlers.coverage.test.jsscripts/background/handlers/saveHandlers.js
**/*
⚙️ CodeRabbit configuration file
**/*: # Project Specific Guidelines
- Language: All user-facing UI text, strings, and messages MUST be in Traditional Chinese (zh-TW).
- Architecture: Follow the defined storage structures and specs. Do not introduce unauthorized storage fields.
- 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.jstests/unit/background/handlers/actionHandlers.coverage.test.jsscripts/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.jstests/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.jsscripts/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.jsscripts/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.jsscripts/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.jsscripts/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.jsscripts/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.jsscripts/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.jsscripts/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.jsscripts/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/info與warn/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
在 actionHandlers.coverage.test.js 中新增測試案例,當 migratedFromOldKey 為 true 時,應略過快取並驗證頁面存在性。測試中模擬了快取仍在有效期內的情況,並確保即使快取有效,仍會呼叫 checkPageExists 以確認頁面存在。這有助於確保在遷移過程中頁面的正確性。
|



Pull Request
📋 變更描述
改善代碼審核建議的四個問題,重構日誌處理邏輯以提高可讀性和一致性。
🎯 變更類型
🤖 提交者聲明
✅ 提交前檢查清單
feat:,fix:,refactor:),以確保release-please正常分析版本號。PR_WORKFLOW.md中的測試規範、代碼規範與安全性指引。🔗 相關 Issue
Closes #
變更
parseArgsToContext取代devLogSink中的重複邏輯。buildHighlightBlocks中的誤導性 fallback。Logger補充輸出等級的設計決策說明。_shouldReturnCachedStatus的 JSDoc 及強制驗證說明。測試
尚未測試。