-
Notifications
You must be signed in to change notification settings - Fork 1
Add a header to each console log #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This should better reflect the real execution order.
Verify that each constructor has as many parameters as it has dependencies.
It makes builds slightly faster.
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis pull request updates build documentation, refactors test infrastructure to use promise-based async messaging, improves JSDoc for the CommandHandler class, extracts build tool utilities for testability, and shifts plugin lifecycle patterns from buildStart to writeBundle hooks for deferred async operations. Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test Code
participant GB as Ghostbird
participant Port as serverSocket
participant BG as Background Task
Test->>GB: receives(text)
activate GB
GB->>GB: resolve serverSocket
activate Port
Port->>BG: register task
GB->>Port: send editor change payload
Port-->>GB: payload delivered
deactivate Port
GB-->>Test: Promise<void>
deactivate GB
Note over GB,BG: Async handshake enables<br/>concurrent operations
sequenceDiagram
participant Build as Build System
participant Plugin as Plugin (test_sanity/<br/>typecheck_with_tsc)
participant Hook1 as buildStart()
participant Hook2 as writeBundle()
participant Resolver as Promise Resolver
Build->>Plugin: initialize plugin
Build->>Hook1: buildStart()
activate Hook1
Hook1->>Hook1: spawn task (sync)
Hook1->>Resolver: register resolver
Hook1-->>Build: void (immediate)
deactivate Hook1
Note over Hook1: Task continues<br/>asynchronously
Build->>Hook2: writeBundle()
activate Hook2
Hook2->>Resolver: await resolution
Resolver-->>Hook2: task complete
Hook2-->>Build: Promise resolves
deactivate Hook2
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
Codecov Report❌ Patch coverage is Additional details and impacted files
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
doc/building.md (1)
52-56: Fix list indentation (markdownlint MD007)Indent this sub-item by 2 spaces instead of 4.
- - Preprocessing source files. + - Preprocessing source files.
🧹 Nitpick comments (6)
src/test/startup.test.ts (1)
96-99: Avoid brittle ctor length equality; handle default/optional/rest paramsFunction length excludes params with defaults and anything after the first default, so
ctor.length === deps.lengthcan fail even when DI is correct. Prefer parsing the constructor parameter list or assert a weaker invariant.Example safer option:
- expect(ctor).to.have.lengthOf(deps.length) + // Ensure at least the required arity covers the listed deps + expect(ctor.length).to.be.at.least(deps.length)Or parse param list:
const paramList = /\bconstructor\s*\(([^)]*)\)/.exec(String(ctor))?.[1] ?? ""; const params = paramList.split(",").map(s => s.trim()).filter(Boolean); expect(params.length).to.equal(deps.length);Please confirm whether any classes declare defaults/optionals in constructors; if yes, the strict equality is unsafe.
doc/building.md (2)
79-85: Document the new “log header” behaviorPR title suggests adding a header to console logs. The “Log output” section mentions removal of
console.login release, but not the header in development. Please clarify behavior.Suggested addition:
#### Log output -- In a release build, `console.log()` are removed. -- In a development build, `console.log()` are left in place. +– In a release build, `console.log()` calls are removed. +– In a development build, console calls are rewritten to include a header (e.g., `[Ghostbird]` or the build ID) via the replace plugin, to make logs searchable and attributable. + Other log levels like `console.info` are not removed in either case.Optionally link to the replace plugin config that injects the header for discoverability.
101-107: Clarify replace plugin configuration for loggingSince logging is modified via a built-in
replacePlugin, add a brief note (pattern, header format, env gates) or a pointer to the exact config location, so readers can find and adjust it quickly.src/test/ghostbird.test.ts (1)
200-205: Prefer dequeueReceived over clearReceived for deterministic reads.waitReady ensures at least one message; dequeueReceived returns the earliest message without flushing the buffer, which is usually what tests want.
- const received = s.clearReceived() + const received = s.dequeueReceived()tools/generate_manifest.ts (1)
86-88: Don’t blindly drop the first char of git hash; strip the optional "g" prefix.git-describe implementations sometimes prefix hashes with "g". Using slice(1) can corrupt hashes that don’t have it.
- const abbrev = hash.slice(1) + const abbrev = hash.replace(/^g/, "")tools/tsdown_config.ts (1)
74-79: Confirm intended behavior: only console.log is disabled in release, others are prefixed.If the goal is “Add a header to each console log,” keeping info/warn/error active is fine, but double-check this aligns with release requirements.
If you also want to silence debug-level noise in release:
- "console.debug(": 'console.debug("[Ghostbird]",', + "console.debug(": isRelease ? "(()=>{})(" : 'console.debug("[Ghostbird]",',
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
doc/building.md(5 hunks)src/app-background/command_handler.ts(1 hunks)src/test/ghostbird.test.ts(6 hunks)src/test/startup.test.ts(1 hunks)tools/barrelsby.ts(1 hunks)tools/generate_manifest.ts(3 hunks)tools/test_sanity.ts(1 hunks)tools/tsdown_config.ts(3 hunks)tools/typecheck_with_tsc.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/app-background/command_handler.ts (2)
src/app-background/compose_action_notifier.ts (1)
ComposeActionNotifier(5-58)src/app-background/api.ts (1)
IUiUtil(18-21)
src/test/ghostbird.test.ts (4)
src/ghosttext-runner/message.ts (1)
IMessagePort(25-60)src/thunderbird/util/promisified_message_port.ts (1)
promisifyMessageChannel(11-16)src/app-compose/compose_event_router.ts (1)
ComposeEventRouter(6-37)src/app-background/background_event_router.ts (1)
BackgroundEventRouter(6-56)
tools/tsdown_config.ts (1)
tools/generate_manifest.ts (1)
generateManifest(11-38)
🪛 markdownlint-cli2 (0.18.1)
doc/building.md
52-52: Unordered list indentation
Expected: 2; Actual: 4
(MD007, ul-indent)
🔇 Additional comments (6)
src/app-background/command_handler.ts (2)
5-5: Clarify the relationship between PR title and changes in this file.The PR title indicates "Add a header to each console log", but this file contains no console log statements and only includes documentation improvements. While the JSDoc updates are valuable, there appears to be a mismatch between the stated PR objective and the actual changes in this file.
Can you confirm whether:
- This file was included intentionally, or
- Console log changes are present in other files not shown in this review?
Also applies to: 13-18
5-5: Documentation improvements look good.The updated class documentation accurately describes the CommandHandler's role in dispatching commands from various UI sources. The added JSDoc for
runCommandproperly documents the parameters and return type, making the API clearer for consumers.Also applies to: 13-18
tools/barrelsby.ts (1)
18-27: No action required — review comment is based on incorrect assumptionBarrelsby(args) in v2.8.1 is synchronous and returns void, not a Promise. The function executes and completes before
rm()is called, so there is no race condition. The current code is correct as-is.Likely an incorrect or invalid review comment.
tools/test_sanity.ts (1)
6-7: This review comment is incorrect.Promise.withResolvers is available in Node.js starting with v22.0.0, but the codebase already uses this pattern in 7 files—including
tools/typecheck_with_tsc.tsin the same directory. If Node 20 were a hard requirement, the existing code would already be failing. The absence of.nvmrc,.node-version, orpackage.jsonengines constraints suggests the project supports Node 22+ or does not enforce a specific lower bound. The code intools/test_sanity.tsis consistent with the established pattern across the codebase and does not require a polyfill.Likely an incorrect or invalid review comment.
tools/typecheck_with_tsc.ts (1)
6-7: Remove this review comment — conflates runtime and build tool contextsThis review comment is incorrect. Both
tools/typecheck_with_tsc.tsandtools/test_sanity.tsare Rolldown build plugins that run in Node.js during the build process, not Thunderbird runtime code. The retrieved learning about Promise.withResolvers support applies only to extension runtime files insrc/, not build tools. Additionally, the project has no documented Node 20 requirement inpackage.json(only Thunderbird>= 128). Promise.withResolvers is appropriate for build tools running on modern Node.js.Likely an incorrect or invalid review comment.
src/test/ghostbird.test.ts (1)
155-157: This review comment's compatibility concern is not supported by evidence.Promise.withResolvers is available in the Node environment, and the codebase already uses this pattern extensively—including in test files (
src/util/lazy_then.ts:80uses the identical pattern). The learnings confirm it's supported in the Thunderbird extension runtime and already established in multiple utility files. Suggesting a manual resolver fallback here contradicts the codebase's established conventions and is unnecessary.Likely an incorrect or invalid review comment.
Add a preprocessing build step that prepends `[Ghostbird]` to each log output. Also, strip all `console.log()` calls in release builds.
95ff57a to
44be1ec
Compare
Summary by CodeRabbit
Documentation
Refactoring
Refactoring
Changes
doc/building.mdsrc/app-background/command_handler.tssrc/test/ghostbird.test.tssrc/test/startup.test.tstools/test_sanity.tstools/typecheck_with_tsc.tstools/barrelsby.tstools/generate_manifest.tstools/tsdown_config.ts