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

New dev tools #2791

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

New dev tools #2791

wants to merge 56 commits into from

Conversation

sadan4
Copy link
Contributor

@sadan4 sadan4 commented Aug 18, 2024

Needs to be merged with this pr

not editing the description of two prs at once, see the other one for details

@sadan4 sadan4 marked this pull request as draft January 5, 2025 22:33
@sadan4 sadan4 marked this pull request as ready for review January 9, 2025 13:34
@sadan4
Copy link
Contributor Author

sadan4 commented Jan 9, 2025

If someone could review this when they have a chance that would be nice

@sadan4
Copy link
Contributor Author

sadan4 commented Jan 11, 2025

@CodiumAI-Agent /review

@CodiumAI-Agent
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 5 🔵🔵🔵🔵🔵
🧪 No relevant tests
🔒 Security concerns

Security Concern:
The use of eval in the parseNode function (e.g., in src/plugins/devCompanion.dev/util.tsx) poses a potential security risk. Dynamic code execution should be avoided or replaced with safer alternatives. Additionally, WebSocket communication in initWs should be reviewed to ensure data integrity and prevent potential injection attacks.

⚡ Recommended focus areas for review

Possible Issue

The NoticesModule is declared with any type, which can lead to runtime errors and makes the code harder to maintain. Consider defining a specific type or interface for NoticesModule.

export let NoticesModule: any;
waitFor(m => m.show && m.dismiss && !m.suppressAll, m => NoticesModule = m);
Security Concern

The parseNode function uses eval to execute code dynamically, which can introduce security vulnerabilities. Consider replacing eval with a safer alternative or validating the input rigorously.

// Safety: This comes from localhost only, which actually means we have less permissions than the source,
// since we're running in the browser sandbox, whereas the sender has host access
return (0, eval)(node.value);
Error Handling

In the initWs function, error handling for WebSocket events is minimal and may not provide sufficient feedback or recovery mechanisms in case of failures. Consider improving error logging and recovery strategies.

ws.addEventListener("error", e => {
    if (!wasConnected) return;

    hasErrored = true;

    logger.error("Dev Companion Error:", e);

    Toasts.show({
        message: "Dev Companion Error",
        id: Toasts.genId(),
        type: Toasts.Type.FAILURE,
        options: {
            position: Toasts.Position.TOP
        }
    });
});

ws.addEventListener("close", e => {
    if (!wasConnected || hasErrored) return;

    logger.info("Dev Companion Disconnected:", e.code, e.reason);

    Toasts.show({
        message: "Dev Companion Disconnected",
        id: Toasts.genId(),
        type: Toasts.Type.FAILURE,
        options: {
            position: Toasts.Position.TOP
        }
    });

@EepyElvyra
Copy link
Contributor

@CodiumAI-Agent /describe

@CodiumAI-Agent
Copy link

Title

New dev tools


User description

Needs to be merged with this pr

not editing the description of two prs at once, see the other one for details


PR Type

Enhancement, Tests, Documentation


Description

  • Introduced a "Dev Companion" plugin for enhanced debugging.

  • Added WebSocket-based communication for module testing and reporting.

  • Enhanced error handling and reporting for patching processes.

  • Updated build scripts and VSCode settings for companion integration.


Changes walkthrough 📝

Relevant files
Enhancement
11 files
Notices.ts
Export `NoticesModule` for external usage.                             
+1/-1     
reporterData.ts
Define `ReporterData` structure for debugging.                     
+52/-0   
runReporter.ts
Integrate reporter logic with WebSocket communication.     
+12/-3   
index.tsx
Refactor and simplify Dev Companion plugin initialization.
+21/-214
initWs.tsx
Implement WebSocket initialization and message handling. 
+456/-0 
index.ts
Export types for WebSocket message handling.                         
+7/-0     
recieve.ts
Define incoming WebSocket message types.                                 
+140/-0 
send.ts
Define outgoing WebSocket message types.                                 
+63/-0   
util.tsx
Add utility functions for module extraction and toggling.
+162/-0 
patchWebpack.ts
Enhance patching logic with error reporting.                         
+23/-1   
webpack.ts
Add type and improve search history tracking.                       
+3/-1     
Configuration changes
5 files
globals.d.ts
Add `IS_COMPANION_TEST` global variable.                                 
+1/-0     
settings.json
Update VSCode settings for companion sidebar.                       
+2/-2     
tasks.json
Add tasks for building companion reporter.                             
+20/-1   
build.mjs
Add `IS_COMPANION_TEST` flag to build process.                     
+2/-1     
common.mjs
Define `IS_COMPANION_TEST` for build configurations.         
+3/-0     
Documentation
1 files
README.md
Add documentation for Dev Companion plugin features.         
+42/-0   

💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

export function initWs(isManual = false) {
let wasConnected = isManual;
let hasErrored = false;
const ws = socket = new WebSocket(`ws://localhost:${PORT}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason to use both ws and socket instead of just using either?

const newSource = src.replace(matcher, replacement as string);

if (src === newSource) throw "Had no effect";
Function(newSource);
Copy link
Contributor

Choose a reason for hiding this comment

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

does this do anything?

const AllModulesNoti = ErrorBoundary.wrap(function ({ done, close }: AllModulesNotiProps) {
const [state, setState] = useState<0 | 1 | -1>(0);
done.then(setState.bind(null, 1)).catch(setState.bind(null, -1));
console.log("test");
Copy link
Contributor

Choose a reason for hiding this comment

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

needs to be removed

src/plugins/devCompanion.dev/util.tsx Show resolved Hide resolved
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.

8 participants