Skip to content

Conversation

@purplecabbage
Copy link
Member

@purplecabbage purplecabbage commented May 30, 2025

Description

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@purplecabbage purplecabbage requested a review from Copilot May 30, 2025 21:46
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request addresses the side effects caused by running an action by ensuring that process.env and the current working directory are restored after the action executes.

  • Captures process.env before any changes by cloning it.
  • Stores the original working directory to restore it later.
  • Restores both process.env and cwd after the action function is executed.

@codecov
Copy link

codecov bot commented May 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (bfd5622) to head (4d6bd5e).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #153   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            7         7           
  Lines          642       647    +5     
  Branches       132       132           
=========================================
+ Hits           642       647    +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@shazron shazron left a comment

Choose a reason for hiding this comment

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

good idea from Copilot about the try-finally block

@purplecabbage purplecabbage requested a review from Copilot June 3, 2025 00:29
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that any modifications to the process environment and working directory during action invocation are reverted afterward to prevent side-effects.

  • Snapshot process.env and cwd before running the action
  • Wrap action execution in try/finally to restore environment and directory
  • Added comments to clarify restore logic
Comments suppressed due to low confidence (1)

src/lib/run-dev.js:355

  • [nitpick] The variable name preCallEnv is ambiguous; consider renaming it to originalEnvSnapshot or envBackup for clarity.
const preCallEnv = cloneDeep(process.env)

purplecabbage and others added 2 commits June 2, 2025 17:34
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@purplecabbage purplecabbage requested a review from Copilot June 3, 2025 00:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that the environment variables and working directory are reset after executing an action that may have side-effects.

  • Capture a snapshot of process.env and current working directory before action execution
  • Inject an OpenWhisk‐style activation ID into process.env
  • Restore process.env and CWD in a finally block after the action runs
Comments suppressed due to low confidence (1)

src/lib/run-dev.js:353

  • There are no tests covering the restoration of process.env and CWD after an action; consider adding unit tests that change env vars and directory during an action and assert they are reset.
// if we run an action, we will restore the process.env after the call

}
} finally {
logger.debug('restoring process.env and cwd')
process.env = preCallEnv // restore the environment variables
Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

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

Reassigning process.env can break references elsewhere; instead clear the existing process.env and reassign properties, e.g. delete all keys then Object.assign(process.env, preCallEnv), to preserve the env object identity.

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@purplecabbage purplecabbage merged commit afad051 into main Jun 4, 2025
10 checks passed
@purplecabbage purplecabbage deleted the IOEXT-1308 branch June 4, 2025 19:10
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.

4 participants