From f76e213005fa64bcdaacf7c1c4c82e6a5ceb2226 Mon Sep 17 00:00:00 2001 From: Paula Stachova Date: Fri, 5 Dec 2025 14:57:36 +0100 Subject: [PATCH 01/10] chore: add custom copilot instructions COMPASS-10013 --- .github/copilot-instructions.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .github/copilot-instructions.md diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 00000000000..1b37c7026ca --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,28 @@ +When reviewing code, focus on: + +## Performance Red Flags + +- Spot inefficient loops and algorithmic issues +- Check for memory leaks and resource cleanup + +## Code Quality Essentials + +- Functions should be focused and appropriately sized +- Use clear, descriptive naming conventions +- Ensure proper error handling throughout +- Suggest changes to improve code readability and maintainability + +## Best practices + +- Refer to official documentation and best practices for React.js, Redux and Node.js. If you see anti-patterns, highlight them and provide references to the relevant documentation. + +## Review Style + +- Be specific and actionable in feedback +- Explain the "why" behind recommendations + +## MongoDB Specifics + +### Performance antipatterns + +- Warn about db.stats() performance implications, especially in connection with freeStorage: 1. Provide a reference to the official MongoDB documentation. From 68f87e890934a0e4079423c7fbf5d8dc6a7048e9 Mon Sep 17 00:00:00 2001 From: Paula Stachova Date: Fri, 5 Dec 2025 15:02:07 +0100 Subject: [PATCH 02/10] temp: antipattern --- .../src/components/diagram-editor.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/compass-data-modeling/src/components/diagram-editor.tsx b/packages/compass-data-modeling/src/components/diagram-editor.tsx index 0676c3e6fa2..a0ed857ca16 100644 --- a/packages/compass-data-modeling/src/components/diagram-editor.tsx +++ b/packages/compass-data-modeling/src/components/diagram-editor.tsx @@ -62,6 +62,7 @@ import { import toNS from 'mongodb-ns'; import { getNamespaceRelationships } from '../utils/utils'; import { usePreference } from 'compass-preferences-model/provider'; +import { use } from 'chai'; const loadingContainerStyles = css({ width: '100%', @@ -233,6 +234,12 @@ const DiagramContent: React.FunctionComponent<{ isNewlyCreatedDiagram ?? false ); + // This is an antipattern example to be detected by Copilot reviewer + const [obj, setObj] = useState({ a: '' }); + useEffect(() => { + obj.a = 'abc'; + }, [obj]); + const setDiagramContainerRef = useCallback((ref: HTMLDivElement | null) => { if (ref) { // For debugging purposes, we attach the diagram to the ref. From 18fc753c70a62fc589ee062cc4884db2ef8be4a7 Mon Sep 17 00:00:00 2001 From: Paula Stachova Date: Fri, 5 Dec 2025 15:05:21 +0100 Subject: [PATCH 03/10] logs --- .github/copilot-instructions.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 1b37c7026ca..47ca94afa36 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -26,3 +26,6 @@ When reviewing code, focus on: ### Performance antipatterns - Warn about db.stats() performance implications, especially in connection with freeStorage: 1. Provide a reference to the official MongoDB documentation. + +At the start of every review, say "Started reviewing". +At the end of every review, say "Done reviewing". From 0bea5e6f6561dc8e68d80119b100527ba352ef66 Mon Sep 17 00:00:00 2001 From: Paula Stachova Date: Fri, 5 Dec 2025 15:38:37 +0100 Subject: [PATCH 04/10] update instructions --- .github/copilot-instructions.md | 2 +- .../compass-data-modeling/src/components/diagram-editor.tsx | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 47ca94afa36..1a6c58ea87a 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -14,7 +14,7 @@ When reviewing code, focus on: ## Best practices -- Refer to official documentation and best practices for React.js, Redux and Node.js. If you see anti-patterns, highlight them and provide references to the relevant documentation. +- Refer to official documentation and best practices for React.js, Redux and Node.js. If you see anti-patterns, highlight them and provide links to the relevant official documentation. ## Review Style diff --git a/packages/compass-data-modeling/src/components/diagram-editor.tsx b/packages/compass-data-modeling/src/components/diagram-editor.tsx index a0ed857ca16..d4b6aed47aa 100644 --- a/packages/compass-data-modeling/src/components/diagram-editor.tsx +++ b/packages/compass-data-modeling/src/components/diagram-editor.tsx @@ -62,7 +62,6 @@ import { import toNS from 'mongodb-ns'; import { getNamespaceRelationships } from '../utils/utils'; import { usePreference } from 'compass-preferences-model/provider'; -import { use } from 'chai'; const loadingContainerStyles = css({ width: '100%', From 2f9adeddcdc9c651de8052a98e5deb5c7055a06a Mon Sep 17 00:00:00 2001 From: Paula Stachova Date: Fri, 5 Dec 2025 15:44:05 +0100 Subject: [PATCH 05/10] . --- .github/copilot-instructions.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 1a6c58ea87a..5f9f0f6f62c 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -1,3 +1,5 @@ +Do not include an overview section in your reviews. + When reviewing code, focus on: ## Performance Red Flags @@ -26,6 +28,3 @@ When reviewing code, focus on: ### Performance antipatterns - Warn about db.stats() performance implications, especially in connection with freeStorage: 1. Provide a reference to the official MongoDB documentation. - -At the start of every review, say "Started reviewing". -At the end of every review, say "Done reviewing". From 305a5127d4ec7c36c6bbbfde27b985bb136c254d Mon Sep 17 00:00:00 2001 From: Paula Stachova Date: Fri, 5 Dec 2025 15:59:14 +0100 Subject: [PATCH 06/10] freestorage --- packages/data-service/src/data-service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/data-service/src/data-service.ts b/packages/data-service/src/data-service.ts index 371b91bda6a..4f9dcd37361 100644 --- a/packages/data-service/src/data-service.ts +++ b/packages/data-service/src/data-service.ts @@ -2883,7 +2883,7 @@ class DataServiceImpl extends WithLogContext implements DataService { const db = this._database(name, 'META'); const stats = await runCommand( db, - { dbStats: 1 }, + { dbStats: 1, freeStorage: 1 }, { enableUtf8Validation: false, ...maybeOverrideReadPreference( From 99314b722eda67ffd8e5ac1d95530dfcf017471f Mon Sep 17 00:00:00 2001 From: Paula Stachova Date: Fri, 5 Dec 2025 16:54:18 +0100 Subject: [PATCH 07/10] update instructions --- .github/copilot-instructions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 5f9f0f6f62c..48ad3d7d0ea 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -1,4 +1,4 @@ -Do not include an overview section in your reviews. +For overview, do not summarize the changes. Only provide high level feedback on code quality, performance, and best practices. When reviewing code, focus on: From 482f6df3a11558a22a4879a2f83fb42d17ace459 Mon Sep 17 00:00:00 2001 From: Paula Stachova Date: Fri, 5 Dec 2025 16:59:58 +0100 Subject: [PATCH 08/10] cleanup --- .../compass-data-modeling/src/components/diagram-editor.tsx | 6 ------ packages/data-service/src/data-service.ts | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/compass-data-modeling/src/components/diagram-editor.tsx b/packages/compass-data-modeling/src/components/diagram-editor.tsx index d4b6aed47aa..0676c3e6fa2 100644 --- a/packages/compass-data-modeling/src/components/diagram-editor.tsx +++ b/packages/compass-data-modeling/src/components/diagram-editor.tsx @@ -233,12 +233,6 @@ const DiagramContent: React.FunctionComponent<{ isNewlyCreatedDiagram ?? false ); - // This is an antipattern example to be detected by Copilot reviewer - const [obj, setObj] = useState({ a: '' }); - useEffect(() => { - obj.a = 'abc'; - }, [obj]); - const setDiagramContainerRef = useCallback((ref: HTMLDivElement | null) => { if (ref) { // For debugging purposes, we attach the diagram to the ref. diff --git a/packages/data-service/src/data-service.ts b/packages/data-service/src/data-service.ts index 4f9dcd37361..371b91bda6a 100644 --- a/packages/data-service/src/data-service.ts +++ b/packages/data-service/src/data-service.ts @@ -2883,7 +2883,7 @@ class DataServiceImpl extends WithLogContext implements DataService { const db = this._database(name, 'META'); const stats = await runCommand( db, - { dbStats: 1, freeStorage: 1 }, + { dbStats: 1 }, { enableUtf8Validation: false, ...maybeOverrideReadPreference( From 64aa340eb9c5c3c4b9ac2e8a4a82fe876a9673a9 Mon Sep 17 00:00:00 2001 From: Paula Stachova Date: Fri, 5 Dec 2025 17:16:35 +0100 Subject: [PATCH 09/10] more instructions --- .github/copilot-instructions.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 48ad3d7d0ea..6f835c1bacd 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -18,6 +18,29 @@ When reviewing code, focus on: - Refer to official documentation and best practices for React.js, Redux and Node.js. If you see anti-patterns, highlight them and provide links to the relevant official documentation. +### Testing + +- Follow the official testing guidelines for Redux and React Testing Library. +- Ensure tests are meaningful, maintainable, and cover edge cases. +- Avoid false positive tests. + +### React + +- Follow React patterns and naming conventions when designing components, “think in React”. + Be careful when using hooks, make sure that all dependencies are listed for callbacks / memos / effect. +- Keep in mind that defining non-primitive values in render (in function body or as component props) nullifies all memoization benefits. +- Same applies to non-primitive properties constructed inside Redux connect functions, they remove any benefits of granular connections +- Be especially careful when adding effects, remember that “you might not need an effect”. +- If you’re reaching for a useReducer hook, consider if it’s time to move this state and business logic to a Redux store instead. + +### Redux + +- The store state should be normalized, minimal, and based around the data you’re storing, not components. +- Keep in mind that not all state belongs in the redux store +- Be especially vigilant deciding whether something is state or a derived value produced from multiple existing sources +- As much state as possible should be calculated in reducers, reducers should own the state shape +- Store actions should be modeled around events, should not be dispatched in batches, and should handle all complex feature logic, especially the one requiring state and service access, instead of doing this in UI directly + ## Review Style - Be specific and actionable in feedback @@ -28,3 +51,9 @@ When reviewing code, focus on: ### Performance antipatterns - Warn about db.stats() performance implications, especially in connection with freeStorage: 1. Provide a reference to the official MongoDB documentation. + +## Compass Specifics + +- We're trying to stick to Redux style guide as close as possible, with two exceptions: + - Compass doesn’t use a single Redux store to manage the whole application state. + - Components inside the feature module boundaries don’t use Redux hooks API as a way to access data from stores (we do allow exposing hooks as public interfaces outside of module boundaries), using connect function instead. From 75377c7d53b9672f4d3ad25fea86e8a025229358 Mon Sep 17 00:00:00 2001 From: Paula Stachova Date: Mon, 8 Dec 2025 11:32:52 +0100 Subject: [PATCH 10/10] encourage new syntax --- .github/copilot-instructions.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 6f835c1bacd..2235a3df0c1 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -17,6 +17,7 @@ When reviewing code, focus on: ## Best practices - Refer to official documentation and best practices for React.js, Redux and Node.js. If you see anti-patterns, highlight them and provide links to the relevant official documentation. +- Encourage modern JavaScript/TypeScript features and syntax where applicable (e.g. for-of loops, nullish coalescing for Javascript; utility types or satisfied for Typescript..). ### Testing