Skip to content

Conversation

@error414
Copy link
Contributor

@error414 error414 commented Dec 22, 2025

User description

Note: I don't think this PR should be merget to updatream, my solution is quite brutal force, but it shows where is the issue. My knowledge is not enought to fix vite build correctly.

There were two bugs.

  1. exe files were not copied to package, should solve bfb2f99#diff-0afe94b5ad1971b035d2d538a77509ebe4f7ecd7a16313e3ac63025dfd865f8bR12

  2. wrong patches to executable files for dev and for package, should solve bfb2f99#diff-34ac9400ad8aa4c5573db2b1e27555eb25fce827f5ed8a86907ff1a492f76636R214

Tested, it workd for
npm run start
and for
npm run package


PR Type

Bug fix


Description

This description is generated by an AI tool. It may have inaccuracies

  • Add SITL resources to packaged application via extraResource configuration

  • Implement dynamic SITL base path resolution for dev and production environments

  • Fix executable file path resolution to work in both development and packaged modes


Diagram Walkthrough

flowchart LR
  A["forge.config.js"] -- "adds extraResource" --> B["SITL resources included in package"]
  C["main.js"] -- "adds getSitlBasePath function" --> D["Dynamic path resolution"]
  D -- "checks app.isPackaged" --> E["Dev: resources/public/sitl"]
  D -- "checks app.isPackaged" --> F["Package: process.resourcesPath/sitl"]
  G["startChildProcess handler"] -- "uses getSitlBasePath" --> H["Correct executable paths"]
Loading

File Walkthrough

Relevant files
Configuration changes
forge.config.js
Add SITL resources to package configuration                           

forge.config.js

  • Add extraResource configuration to include SITL resources in packaged
    application
  • Specify resources/public/sitl directory to be copied during packaging
+3/-0     
Bug fix
main.js
Implement dynamic SITL path resolution for environments   

js/main/main.js

  • Implement getSitlBasePath() function to resolve SITL directory path
    dynamically
  • Check app.isPackaged to determine correct path: packaged vs
    development
  • Update startChildProcess handler to use dynamic path resolution
    instead of hardcoded __dirname
+9/-1     

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Dec 22, 2025

You are nearing your monthly Qodo Merge usage quota. For more information, please visit here.

PR Compliance Guide 🔍

All compliance sections have been disabled in the configurations.

Comment on lines 214 to 222
function getSitlBasePath() {
if (app.isPackaged) {
return path.join(process.resourcesPath, 'sitl');
} else {
return path.join(process.cwd(), 'resources', 'public', 'sitl');
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: In the getSitlBasePath function, replace process.cwd() with a relative path from __dirname to make resource location in development mode more reliable. [possible issue, importance: 7]

Suggested change
function getSitlBasePath() {
if (app.isPackaged) {
return path.join(process.resourcesPath, 'sitl');
} else {
return path.join(process.cwd(), 'resources', 'public', 'sitl');
}
}
function getSitlBasePath() {
if (app.isPackaged) {
return path.join(process.resourcesPath, 'sitl');
} else {
return path.join(__dirname, '..', '..', 'resources', 'public', 'sitl');
}
}

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 don't think that ".." is better than (process.cwd()

Copy link
Contributor

Choose a reason for hiding this comment

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

Question:

I don't think that .. is better than (process.cwd()

Answer:

You can reduce (or prevent) this kind of suggestion by adding a repo-level instruction that Qodo Merge should not “automatically” prefer __dirname-based paths over process.cwd() in Electron/dev-mode, unless it can prove a concrete failure mode in your repo setup.

Add to your .pr_agent.toml (or wiki .pr_agent.toml) something like:

[pr_code_suggestions]
extra_instructions = """\
When reviewing Electron/Node path handling:
- Do NOT suggest replacing process.cwd() with __dirname-based relative paths by default.
- Only propose changing the base path if you can explain a concrete reliability issue in this repository's workflow (e.g., cwd differs between dev scripts, tests, packaging, or CI).
- If unsure, ask for context (how the app is launched in dev) instead of proposing a path refactor.
"""

If you still want the tool to mention the tradeoff but avoid a prescriptive patch, you can add:

[pr_code_suggestions]
extra_instructions = """\
For suggestions about path base directories, prefer explaining pros/cons (cwd vs __dirname) and avoid giving a code diff unless the current approach is clearly broken in this repo.
"""

Relevant Sources:

Comment on lines 373 to 377
ipcMain.on('startChildProcess', (_event, command, args, opts) => {
child_process.start(path.join(__dirname, 'sitl', command), args, opts, mainWindow);
child_process.start(path.join(getSitlBasePath(), command), args, opts, mainWindow);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: In the startChildProcess handler, conditionally append the .exe extension to the command on Windows to ensure the executable can be found. [possible issue, importance: 8]

Suggested change
ipcMain.on('startChildProcess', (_event, command, args, opts) => {
child_process.start(path.join(__dirname, 'sitl', command), args, opts, mainWindow);
child_process.start(path.join(getSitlBasePath(), command), args, opts, mainWindow);
});
ipcMain.on('startChildProcess', (_event, command, args, opts) => {
const cmdName = process.platform === 'win32' ? `${command}.exe` : command;
const cmdPath = path.join(getSitlBasePath(), cmdName);
child_process.start(cmdPath, args, opts, mainWindow);
});

Copy link
Contributor Author

@error414 error414 Dec 22, 2025

Choose a reason for hiding this comment

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

command already contains right executable name

Copy link
Contributor

Choose a reason for hiding this comment

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

Question:

coomand already contains right executable name

Answer:

Add an improve-tool instruction to avoid platform-specific “append .exe” suggestions when the executable name is already provided by the caller.

[pr_code_suggestions]
extra_instructions = """\
- When reviewing process-spawn/child-process code, assume the `command` argument already contains the correct executable name (including any needed extension like `.exe`).
- Do NOT suggest appending `.exe` or altering executable naming unless the PR explicitly shows a bug where an extension is missing.
"""

If you want this only for a specific PR run (instead of a persistent config), you can also run:
/improve --pr_code_suggestions.extra_instructions="..."

Relevant Sources:

Comment on lines 373 to 377
ipcMain.on('startChildProcess', (_event, command, args, opts) => {
child_process.start(path.join(__dirname, 'sitl', command), args, opts, mainWindow);
child_process.start(path.join(getSitlBasePath(), command), args, opts, mainWindow);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: Validate/normalize command from IPC (reject .., absolute paths, and unknown executables) and ensure the resolved path stays within the SITL base directory before starting the child process. [Learned best practice, importance: 6]

Suggested change
ipcMain.on('startChildProcess', (_event, command, args, opts) => {
child_process.start(path.join(__dirname, 'sitl', command), args, opts, mainWindow);
child_process.start(path.join(getSitlBasePath(), command), args, opts, mainWindow);
});
ipcMain.on('startChildProcess', (_event, command, args, opts) => {
const base = getSitlBasePath();
const candidate = path.resolve(base, command);
if (!candidate.startsWith(path.resolve(base) + path.sep) || path.isAbsolute(command) || command.includes('..')) {
throw new Error(`Invalid SITL command path: ${command}`);
}
child_process.start(candidate, args, opts, mainWindow);
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

probably we don't need check if sitl exe file exists

Copy link
Contributor

Choose a reason for hiding this comment

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

Question:

probably we don't need check if sitl exe file exists

Answer:

You can steer /improve away from “check if the SITL executable exists” recommendations, while still keeping the important path-traversal / allowlist validation guidance, by adding a repo-level instruction like:

[pr_code_suggestions]
extra_instructions = """\
- Do NOT suggest checking whether an executable/file exists on disk (e.g., fs.existsSync, access checks) unless the PR explicitly adds error handling for missing files.
- For IPC-launched processes, prioritize security validation: reject absolute paths, '..' traversal, and enforce that the resolved path stays within an approved base directory; prefer allowlisting known commands when possible.
"""

Relevant Sources:

@error414 error414 force-pushed the feat-fix-sitl branch 2 times, most recently from e3dcf5a to 8eb245a Compare December 22, 2025 16:51
turn off strip for arm64 executable file in x86 linux build
@sensei-hacker sensei-hacker added the For Discussion Discussion needed label Dec 22, 2025
@sensei-hacker sensei-hacker added this to the 9.1 milestone Dec 23, 2025
@Scavanger
Copy link
Contributor

Should no longer be necessary once #2438 has been merged.

@sensei-hacker
Copy link
Member

Thanks! I did this with a few tweaks as #2496

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants