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

🐛 fix: Align cache hashes #1248

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
Open

🐛 fix: Align cache hashes #1248

wants to merge 13 commits into from

Conversation

matstyler
Copy link
Collaborator

No description provided.

Copy link

vercel bot commented Nov 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
synpress ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 11, 2024 9:37am

@matstyler matstyler force-pushed the fix/align-cache-hashes branch from 3f1515b to 609f1a5 Compare December 3, 2024 10:19
@@ -16,6 +16,7 @@
"dependencies": {
"@playwright/test": "1.48.2",
"@synthetixio/synpress": "workspace:*",
"@synthetixio/synpress-cache": "workspace:*",
Copy link
Collaborator

Choose a reason for hiding this comment

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

you shouldn't need anything else other than synpress package in your tests

Copy link
Collaborator

Choose a reason for hiding this comment

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

. + wallet package

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we use dependency of dependency, and both of them are internal packages, turbo doesn't refresh the dependencies properly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok, but if I understand correctly, end user behavior will change and he will need two separate packages now, one for cache. it's breaking change which I would like to avoid.

Copy link
Collaborator

@drptbl drptbl Dec 4, 2024

Choose a reason for hiding this comment

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

also, again - I think that end user should need main synpress package and nothing else. only additional wallets. we don't want to overcomplicate setup.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no package behaviour change, the only problem is that we have examples in monorepo, not outside but I can remove this dependency now

@@ -0,0 +1,5 @@
export default {
baseUrl: 'https://www.alphabot.app/',
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is alphabot

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the page user added as an example - this test case is more for you as a prove that this issue has been fixed

Copy link
Collaborator

Choose a reason for hiding this comment

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


await metamask.connectToDapp()

await page.waitForTimeout(2000)
Copy link
Collaborator

Choose a reason for hiding this comment

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

we shouldnt need any waits, especially with timeout, they are flaky and bad practice

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it's just the same user example

Copy link
Collaborator

Choose a reason for hiding this comment

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

cool, but these are our official examples in our main repo - which are going to be copied over by other people. we don't want to have bad practices here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

after review I will remove it, feel free to use it as a testing playground


expect(createCacheForWalletSetupFunctionSpy).toHaveBeenCalledTimes(2)
expectCreateCacheForWalletSetupFunction(1, setupFunctions, 'hash1')
expectCreateCacheForWalletSetupFunction(2, setupFunctions, 'hash2')
})

it('checks if cache already exists for each entry', async () => {
it.skip('checks if cache already exists for each entry', async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

most of tests are skipped, why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

a leftover after development, should be reverted

@@ -0,0 +1,12 @@
export function extractWalletSetupFunction(sourceCode: string): string {
const match = sourceCode.match(
/defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{(?:[^{}]*|{(?:[^{}]*|{[^{}]*})*})*})\s*\)/

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings starting with 'defineWalletSetup(,async()=>{' and containing many repetitions of 'z'.

Copilot Autofix AI 20 days ago

To fix the problem, we need to modify the regular expression to remove the ambiguity and reduce the potential for excessive backtracking. This can be achieved by making the sub-expressions more specific and avoiding patterns that can match the same string in multiple ways. Specifically, we can replace [^{}]* with a more precise pattern that matches the intended input without allowing for excessive backtracking.

The best way to fix the problem is to rewrite the regular expression to avoid ambiguous sub-expressions and nested quantifiers. We can achieve this by using non-capturing groups and more specific character classes.

Suggested changeset 1
packages/cache/src/utils/extractWalletSetupFunction.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/cache/src/utils/extractWalletSetupFunction.ts b/packages/cache/src/utils/extractWalletSetupFunction.ts
--- a/packages/cache/src/utils/extractWalletSetupFunction.ts
+++ b/packages/cache/src/utils/extractWalletSetupFunction.ts
@@ -2,3 +2,3 @@
   const match = sourceCode.match(
-    /defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{(?:[^{}]*|{(?:[^{}]*|{[^{}]*})*})*})\s*\)/
+    /defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{(?:[^{}{}]*|{(?:[^{}{}]*|{[^{}{}]*})*})*})\s*\)/
   )
EOF
@@ -2,3 +2,3 @@
const match = sourceCode.match(
/defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{(?:[^{}]*|{(?:[^{}]*|{[^{}]*})*})*})\s*\)/
/defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{(?:[^{}{}]*|{(?:[^{}{}]*|{[^{}{}]*})*})*})\s*\)/
)
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
@@ -0,0 +1,12 @@
export function extractWalletSetupFunction(sourceCode: string): string {
const match = sourceCode.match(
/defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{(?:[^{}]*|{(?:[^{}]*|{[^{}]*})*})*})\s*\)/

Check failure

Code scanning / CodeQL

Inefficient regular expression High

This part of the regular expression may cause exponential backtracking on strings starting with 'defineWalletSetup(,async()=>{{' and containing many repetitions of 'z'.

Copilot Autofix AI 20 days ago

To fix the problem, we need to modify the regular expression to remove the ambiguity that leads to catastrophic backtracking. This can be achieved by making the pattern more specific and less ambiguous. In this case, we can replace the ambiguous [^{}]* with a more precise pattern that matches the expected structure of the input.

The best way to fix the problem without changing existing functionality is to rewrite the regular expression to avoid nested quantifiers and ambiguous patterns. Specifically, we can use a non-recursive approach to match the nested braces and their contents.

Suggested changeset 1
packages/cache/src/utils/extractWalletSetupFunction.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/cache/src/utils/extractWalletSetupFunction.ts b/packages/cache/src/utils/extractWalletSetupFunction.ts
--- a/packages/cache/src/utils/extractWalletSetupFunction.ts
+++ b/packages/cache/src/utils/extractWalletSetupFunction.ts
@@ -2,3 +2,3 @@
   const match = sourceCode.match(
-    /defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{(?:[^{}]*|{(?:[^{}]*|{[^{}]*})*})*})\s*\)/
+    /defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{[^{}]*(?:{[^{}]*}[^{}]*)*})\s*\)/
   )
EOF
@@ -2,3 +2,3 @@
const match = sourceCode.match(
/defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{(?:[^{}]*|{(?:[^{}]*|{[^{}]*})*})*})\s*\)/
/defineWalletSetup\s*\([^,]*,\s*(async\s*\([^)]*\)\s*=>\s*{[^{}]*(?:{[^{}]*}[^{}]*)*})\s*\)/
)
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants