Skip to content
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

build: track circular dependency in the codebase #29811

Merged
merged 26 commits into from
Feb 3, 2025

Conversation

dbrans
Copy link
Contributor

@dbrans dbrans commented Jan 20, 2025

Description

This PR introduces circular dependency detection, tracking, and CODEOWNERS.

Here are the key changes:

  1. Added a new circular dependency detection system:

    • New script development/circular-deps.ts that uses madge to detect circular dependencies
    • New config file .madgerc for TypeScript-specific settings
    • Generated baseline file development/circular-deps.json containing current circular dependencies
  2. Added new yarn scripts in package.json:

    • yarn circular-deps:check - Verifies circular dependencies match baseline
    • yarn circular-deps:update - Updates baseline with current circular dependencies
  3. Added CI integration:

    • Added .github/workflows/test-circular-deps.yml to run circular dependency check
  4. Assigning appropriate CODEOWNERS to circular-deps.jsonc

The PR essentially sets up a process to track new circular dependencies while acknowledging existing ones in the codebase.

Open in GitHub Codespaces

Related issues

Manual testing steps

  1. Remove (or add) a circular dependency in the code.
  2. Run yarn circular-deps:check => should report that codebase is out of sync with circular-deps.jsonc
  3. Run yarn circular-deps:update => should update circular-deps.jsonc to match the codebase. Inspect the diff.
  4. Run yarn circular-deps:check => should pass.

Screenshots/Recordings

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-extension-platform Extension Platform team label Jan 20, 2025
@metamaskbot metamaskbot added INVALID-PR-TEMPLATE PR's body doesn't match template and removed INVALID-PR-TEMPLATE PR's body doesn't match template labels Jan 20, 2025
@dbrans dbrans marked this pull request as ready for review January 20, 2025 21:29
@metamaskbot
Copy link
Collaborator

Builds ready [171032a]
Page Load Metrics (1662 ± 50 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint15342026166510450
domContentLoaded1484197216419947
load15342027166210550
domInteractive2410143189
backgroundConnect65320157
firstReactRender16102572914
getState472162110
initialActions01000
loadScripts1078144611837837
setupStore616721
uiStartup171624822030236113
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

.madgerc Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
Comment on lines 23 to 24
- name: Check circular dependencies
run: yarn circular-deps:check
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't a great place to put this step, because test-lint was already the slowest job in this part of the pipeline. I would put this step in a separate job that runs on a separate machine.

Copy link
Contributor

Choose a reason for hiding this comment

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

@HowardBraham I think it should be added to yarn lint and yarn lint:fix, since this really is just a lint step. Developers already run yarn lint:fix (and often yarn lint) before pushing to CI, so while it might slow the lint job in CI a small amount, it won't cause total CI failures due to developers forgetting to run a yarn lint:fix plus an additional circular-lint:fix step.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can do both: If we make the circular dependency fix part of yarn lint:fix for developers, but run the check as a separate CI job to avoid slowing down test-lint. This gives us convenient local fixes and efficient CI checks.

Thoughts?

Copy link
Contributor Author

@dbrans dbrans Jan 28, 2025

Choose a reason for hiding this comment

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

I've made these changes:

  • circular-deps:check now runs as a separate CI job
  • circular-deps:update now is part of yarn lint:fix, which does not run on CI

Copy link
Contributor

Choose a reason for hiding this comment

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

@dbrans I think you forgot to make this actually run... main.yml needs to call it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

package.json Show resolved Hide resolved
development/circular-deps.ts Outdated Show resolved Hide resolved
development/circular-deps.ts Outdated Show resolved Hide resolved
Copy link

socket-security bot commented Jan 28, 2025

New, updated, and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@babel/[email protected] None 0 1.91 MB nicolo-ribaudo
npm/@dependents/[email protected] 🔁 npm/@dependents/[email protected] None 0 6.45 kB xhmikosr
npm/@jridgewell/[email protected] 🔁 npm/@jridgewell/[email protected] None 0 113 kB jridgewell
npm/@ts-graphviz/[email protected] None 0 30.5 kB kamiazya
npm/@ts-graphviz/[email protected] None 0 284 kB kamiazya
npm/@ts-graphviz/[email protected] None 0 216 kB kamiazya
npm/@ts-graphviz/[email protected] None 0 86.6 kB kamiazya
npm/@types/[email protected] None 0 9.66 kB types
npm/@vue/[email protected] 🔁 npm/@vue/[email protected] None 0 619 kB yyx990803
npm/@vue/[email protected] 🔁 npm/@vue/[email protected] None 0 639 kB yyx990803
npm/@vue/[email protected] 🔁 npm/@vue/[email protected] eval, filesystem, unsafe 0 2.62 MB yyx990803
npm/@vue/[email protected] 🔁 npm/@vue/[email protected] None 0 47.7 kB yyx990803
npm/@vue/[email protected] 🔁 npm/@vue/[email protected] None 0 86.5 kB yyx990803
npm/[email protected] 🔁 npm/[email protected] None 0 11.8 kB xhmikosr
npm/[email protected] 🔁 npm/[email protected] None 0 21 kB xhmikosr
npm/[email protected] 🔁 npm/[email protected] None 0 10 kB xhmikosr
npm/[email protected] 🔁 npm/[email protected] None 0 5.17 kB xhmikosr
npm/[email protected] 🔁 npm/[email protected] None 0 5.39 kB xhmikosr
npm/[email protected] 🔁 npm/[email protected] None 0 8.56 kB xhmikosr
npm/[email protected] 🔁 npm/[email protected] None 0 6.65 kB xhmikosr
npm/[email protected] 🔁 npm/[email protected] None 0 6.67 kB xhmikosr
npm/[email protected] 🔁 npm/[email protected] None 0 4.54 kB xhmikosr
npm/[email protected] 🔁 npm/[email protected] None 0 7.94 kB xhmikosr
npm/[email protected] None 0 5.65 kB havunen
npm/[email protected] 🔁 npm/[email protected] None 0 212 kB evilebottnawi
npm/[email protected] 🔁 npm/[email protected] Transitive: environment +3 23 MB xhmikosr
npm/[email protected] 🔁 npm/[email protected] None 0 6.66 kB xhmikosr
npm/[email protected] None 0 33.5 kB ljharb
npm/[email protected] filesystem, shell +1 250 kB pahen
npm/[email protected] 🔁 npm/[email protected], npm/[email protected] None 0 467 kB antfu
npm/[email protected] 🔁 npm/[email protected] None 0 7.57 kB xhmikosr
npm/[email protected] 🔁 npm/[email protected] None 0 11.2 kB xhmikosr
npm/[email protected] 🔁 npm/[email protected] None 0 9.28 kB xhmikosr
npm/[email protected] 🔁 npm/[email protected] None 0 202 kB ai
npm/[email protected] 🔁 npm/[email protected] None 0 13.3 kB xhmikosr
npm/[email protected] 🔁 npm/[email protected] None 0 1.28 MB jrburke
npm/[email protected] 🔁 npm/[email protected] None 0 6.8 kB xhmikosr
npm/[email protected] environment, filesystem 0 146 kB ljharb
npm/[email protected] 🔁 npm/[email protected] None 0 9.12 kB xhmikosr
npm/[email protected] 🔁 npm/[email protected] None 0 140 kB 7rulnik
npm/[email protected] 🔁 npm/[email protected] None 0 7.52 kB mrjoelkemp, pahen, xhmikosr
npm/[email protected] 🔁 npm/[email protected] None 0 77.3 kB kamiazya

🚮 Removed packages: npm/@lgbot/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected], npm/[email protected]

View full report↗︎

Copy link

socket-security bot commented Jan 28, 2025

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSourceCI
Shell access npm/[email protected] 🚫

View full report↗︎

Next steps

What is shell access?

This module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.

Packages should avoid accessing the shell which can reduce portability, and make it easier for malicious shell access to be introduced.

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/[email protected] or ignore all packages with @SocketSecurity ignore-all

@metamaskbot
Copy link
Collaborator

Builds ready [9d4d779]
Page Load Metrics (1776 ± 132 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint140723881777270129
domContentLoaded139723691746262126
load140523881776276132
domInteractive23176543617
backgroundConnect482272512
firstReactRender14121442914
getState48915199
initialActions00000
loadScripts101718771318229110
setupStore65914168
uiStartup162027342058334160
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@dbrans
Copy link
Contributor Author

dbrans commented Jan 28, 2025

@metamaskbot update-policies

@HowardBraham
Copy link
Contributor

circular-deps.jsonc is out of sync 🙂, and I think we need one more thing before we can merge this:

Let's add development/circular-deps.jsonc to the CODEOWNERS, possibly controlled by @MetaMask/extension-security-team, or possibly by a new @MetaMask/extension-circular-deps-team?

@dbrans dbrans requested a review from a team as a code owner January 29, 2025 19:48
.github/CODEOWNERS Outdated Show resolved Hide resolved
HowardBraham
HowardBraham previously approved these changes Jan 29, 2025
davidmurdoch
davidmurdoch previously approved these changes Jan 30, 2025
Copy link
Contributor

@davidmurdoch davidmurdoch left a comment

Choose a reason for hiding this comment

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

I think I prefer having the check as part of the lint CI step, but not enough to block merging. Approved! Nice work!

@dbrans
Copy link
Contributor Author

dbrans commented Jan 30, 2025

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated.
👀 Please review the diff for suspicious new powers.

🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff

@metamaskbot metamaskbot dismissed stale reviews from davidmurdoch and HowardBraham via 94e3d78 January 30, 2025 15:47
HowardBraham
HowardBraham previously approved these changes Jan 31, 2025
@metamaskbot
Copy link
Collaborator

Builds ready [7dde616]
Page Load Metrics (1620 ± 60 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint27619811548317152
domContentLoaded13721920159811756
load14101982162012560
domInteractive2495442411
backgroundConnect876282110
firstReactRender1574342210
getState45815178
initialActions01000
loadScripts988140011699948
setupStore863202010
uiStartup15842222182313666
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [bc1c8a2]
Page Load Metrics (1702 ± 80 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint43019361562375180
domContentLoaded13922085167916077
load14002122170216780
domInteractive22172553517
backgroundConnect983312512
firstReactRender1574402311
getState47016199
initialActions01000
loadScripts9801615122414268
setupStore65514136
uiStartup15592337191619091
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@dbrans dbrans enabled auto-merge February 1, 2025 12:21
@dbrans dbrans added this pull request to the merge queue Feb 3, 2025
Merged via the queue into main with commit c89f440 Feb 3, 2025
73 of 74 checks passed
@dbrans dbrans deleted the djb/circular-deps-monitoring branch February 3, 2025 16:34
@github-actions github-actions bot locked and limited conversation to collaborators Feb 3, 2025
@metamaskbot metamaskbot added the release-12.13.0 Issue or pull request that will be included in release 12.13.0 label Feb 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.13.0 Issue or pull request that will be included in release 12.13.0 team-extension-platform Extension Platform team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants