-
Notifications
You must be signed in to change notification settings - Fork 451
refactor: centralized tasks manager #13223
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
refactor: centralized tasks manager #13223
Conversation
📝 Walkthrough""" WalkthroughThe changes refactor the Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Assessment against linked issues
Assessment against linked issues: Out-of-scope changesNo out-of-scope changes found. Possibly related PRs
Suggested reviewers
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
c827ea5
to
5e7701e
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
5e7701e
to
545cf54
Compare
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.
Hey @gastoner - I've reviewed your changes - here's some feedback:
- Consider extracting the repetitive TaskManager instantiation in the tests into a helper/factory to reduce boilerplate and improve readability.
- Since you changed the
tasks.Manager
schema to typeobject
without a default, you may want to explicitly define a default value or add handling forundefined
to prevent unexpected behavior.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the repetitive TaskManager instantiation in the tests into a helper/factory to reduce boilerplate and improve readability.
- Since you changed the `tasks.Manager` schema to type `object` without a default, you may want to explicitly define a default value or add handling for `u
8000
ndefined` to prevent unexpected behavior.
## Individual Comments
### Comment 1
<location> `packages/main/src/plugin/tasks/task-manager.spec.ts:61` </location>
<code_context>
test('task manager init should register a configuration option', async () => {
- const taskManager = new TaskManager(apiSender, statusBarRegistry, commandRegistry, configurationRegistry);
+ const taskManager = new TaskManager(
+ apiSender,
+ statusBarRegistry,
</code_context>
<issue_to_address>
Consider introducing a factory function or shared setup to avoid repeating the five-argument TaskManager construction in every test.
Consider pulling the new fifth argument out into a small factory (or reusing a shared `taskManager` via `beforeEach`) so you don’t have to repeat all five params in every test. For example:
```ts
// near the top of the file
const experimentalConfigurationManager = {/* …your mock… */};
function createTaskManager() {
return new TaskManager(
apiSender,
statusBarRegistry,
commandRegistry,
configurationRegistry,
experimentalConfigurationManager,
);
}
```
Then your tests shrink from:
```ts
const taskManager = new TaskManager(
apiSender,
statusBarRegistry,
commandRegistry,
configurationRegistry,
experimentalConfigurationManager,
);
```
to:
```ts
const taskManager = createTaskManager();
```
—or even—
```ts
let taskManager: TaskManager;
beforeEach(() => {
taskManager = createTaskManager();
vi.resetAllMocks();
});
test('create task with title', () => {
const task = taskManager.createTask({ title: 'title' });
// …
});
```
This preserves all behavior while removing the boilerplate of passing that fifth parameter everywhere.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
||
test('task manager init should register a configuration option', async () => { | ||
const taskManager = new TaskManager(apiSender, statusBarRegistry, commandRegistry, configurationRegistry); | ||
const taskManager = new TaskManager( |
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.
issue (complexity): Consider introducing a factory function or shared setup to avoid repeating the five-argument TaskManager construction in every test.
Consider pulling the new fifth argument out into a small factory (or reusing a shared taskManager
via beforeEach
) so you don’t have to repeat all five params in every test. For example:
// near the top of the file
const experimentalConfigurationManager = {/* …your mock… */};
function createTaskManager() {
return new TaskManager(
apiSender,
statusBarRegistry,
commandRegistry,
configurationRegistry,
experimentalConfigurationManager,
);
}
Then your tests shrink from:
const taskManager = new TaskManager(
apiSender,
statusBarRegistry,
commandRegistry,
configurationRegistry,
experimentalConfigurationManager,
);
to:
const taskManager = createTaskManager();
—or even—
let taskManager: TaskManager;
beforeEach(() => {
taskManager = createTaskManager();
vi.resetAllMocks();
});
test('create task with title', () => {
const task = taskManager.createTask({ title: 'title' });
// …
});
This preserves all behavior while removing the boilerplate of passing that fifth parameter everywhere.
|
||
test('task dispose should send `task-removed` message', async () => { | ||
const taskManager = new TaskManager(apiSender, statusBarRegistry, commandRegistry, configurationRegistry); | ||
const taskManager = new TaskManager( |
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.
I've seen that this const
is used in several test. Could it be possible to move outside tests, for example in the describe
block?
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.
Updated
|
||
test('Ensure statusbar registry', async () => { | ||
const taskManager = new TaskManager(apiSender, statusBarRegistry, commandRegistry, configurationRegistry); | ||
const taskManager = new TaskManager( |
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.
Did you forget to remove this one to use the one in beforeEach
instead?
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.
Yess :D
c0bc225
to
378f335
Compare
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.
LGTM codewise
Needs rebase after #13227 |
Signed-off-by: Evzen Gasta <evzen.ml@seznam.cz>
Signed-off-by: Evzen Gasta <evzen.ml@seznam.c 9E81 z>
378f335
to
c48de1f
Compare
What does this PR do?
Changes logic from storing boolean value to object/undefined for experimental features, uses new experimental configuration manager #13316
More info in #13095
Screenshot / video of UI
What issues does this PR fix or reference?
Closes #13201
Needs rebase after #13227 is merged
THOSE PRs MUST be merged together:
#13225
#13224
#13223
#13226
#13227
How to test this PR?