0020: app: electron: Report rejected command exits - #7294
Conversation
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: illume The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
b71b98b to
9459619
Compare
There was a problem hiding this comment.
Pull request overview
Adds Electron IPC exit reporting for commands rejected before process creation.
Changes:
- Reports distinct exit codes for validation, permission, and consent failures.
- Expands command lifecycle unit coverage.
- Adds an Electron IPC end-to-end rejection test.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
app/electron/runCmd.ts |
Emits rejection exit events. |
app/electron/runCmd.test.ts |
Adds lifecycle and rejection tests. |
app/e2e-tests/tests/runCommand.spec.ts |
Tests renderer-to-main invalid-command handling. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
9459619 to
aaa2cd2
Compare
Cover output forwarding and child-process exit handling before changing early rejection behavior. The shared handler serves both paths, so this baseline separates regressions in existing command execution from the rejection fix and shows that successful commands keep their current IPC contract.
Exercise invalid command rejection across the real renderer, preload, and main process boundary. Unit mocks cannot prove that the desktop bridge delivers the exit event. A missing event at this boundary leaves plugin callers pending. Use the minimal app startup path so unrelated backend services cannot make this focused contract test flaky.
Send an exit event when validation, permission, or consent rejects a command. Renderer callers rely on that event to settle command state and release IPC listeners, so returning silently leaves rejected commands pending indefinitely. Distinct negative codes preserve normal child-process exits while identifying which pre-spawn gate rejected the request. Co-authored-by: René Dudfield <renedudfield@microsoft.com>
aaa2cd2 to
4a86998
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
app/electron/runCmd.ts:283
validateCommandDatarejects an empty ID, but this branch still reflects it because it checks only the type. That contradicts the stated non-empty-ID contract and sendscommand-exitfor a malformed identifier. Require a non-empty string here (and cover the empty-string handler case), as is already done by validation.
if (typeof eventData?.id === 'string') {
Summary
Report
command-exitevents when desktop command execution is rejected beforespawning a child process:
-1for invalid command data-2for rejected permission secrets-3for denied command consentThis prevents renderer-side command objects from remaining pending when the
main process rejects a request.
Source
This upstreams the command-rejection portion of:
The change was later rebased in the downstream branch as:
Patch 0020 was extracted while preparing the Headlamp source package in:
Improvements over the existing changes
app/electron/runCmd.tsbranch coverage to 93.45%. This protects the widercommand lifecycle rather than only the newly added lines.
verifies that invalid commands are rejected by the real desktop bridge and
that the renderer receives exit code
-1.command ID. This avoids reflecting malformed identifiers back over IPC.
command did not start.
Backwards compatibility
For users of the downstream patch code, rejected commands now complete with a
negative
command-exitcode instead of remaining pending. Callers that used atimeout or the absence of an exit event to infer rejection should migrate.
Callers should handle rejection codes
-1,-2, and-3explicitly. Existinglisteners already accept numeric exit codes, so no API-shape change is required.
Command IDs must be non-empty strings; malformed IDs are rejected without being
reflected over IPC.
For users of Headlamp main, valid commands are unaffected. Command validation,
permission checks, consent prompts, process spawning, output forwarding, and
real child-process exit codes retain their existing behavior. The change is
additive. It only affects requests that the main process rejects before spawn.
Those requests now terminate predictably instead of remaining unresolved.
Choosing Deny on the first consent prompt now rejects immediately, matching
the behavior of a denial already stored in settings.
Testing
npm --prefix app run tsc./node_modules/.bin/vitest run electron/runCmd.test.ts(48 tests)app/electron/runCmd.ts(93.45% branches)npm --prefix app/e2e-tests run test-app -- tests/runCommand.spec.tsThe behavior is not visual, so screenshots are not applicable.
Assisted by copilot.