jsii icon indicating copy to clipboard operation
jsii copied to clipboard

feat: implement automatic bidirectional environment variable synchronization

Open tinovyatkin opened this issue 4 months ago • 1 comments

Summary

This PR implements automatic bidirectional environment variable synchronization between Python JSII runtime and Node.js kernel processes, as specified in the design document.

Key Features

  • Zero configuration required - works automatically when both runtimes are active
  • Immediate synchronization via synchronous IPC communication
  • Bidirectional sync - changes in either Python or Node.js are reflected in both
  • Thread-safe operations with proper locking for concurrent access
  • Comprehensive test coverage with 79 passing tests

Implementation Components

Node.js/TypeScript Side

  • EnvironmentMonitor class: Proxy-based monitoring of process.env changes
  • Enhanced Kernel API: Added env.notifyChange method for external synchronization
  • Comprehensive tests: Full coverage of EnvironmentMonitor, Kernel integration, and API types

Python Side

  • PythonEnvironmentMonitor: Wrapper for os.environ with automatic change detection
  • Enhanced ProcessProvider: Bidirectional sync logic between runtimes
  • Thread-safe implementation: Proper locking mechanisms for concurrent access

Test Infrastructure

  • TypeScript tests: 3 test suites with 79 passing tests
  • Python tests: Comprehensive testing of Python-side functionality
  • Integration utilities: Test helpers in jsii-calc for end-to-end validation

Technical Details

The implementation uses:

  • Proxy objects to intercept environment variable access
  • Synchronous IPC for immediate change propagation
  • Callback-based architecture for cross-runtime communication
  • Proper type definitions for TypeScript and Python
  • Extensive error handling and edge case coverage

Files Changed

  • 12 files modified with 2,078 insertions and 3 deletions
  • 7 new files created for core functionality and comprehensive testing
  • 5 existing files enhanced to support environment synchronization

Test plan

  • [x] All existing tests continue to pass
  • [x] New TypeScript tests pass (79/79 tests passing)
  • [x] New Python tests pass with comprehensive coverage
  • [x] Manual testing of bidirectional synchronization
  • [x] Edge case testing (null/undefined values, concurrent access, etc.)
  • [x] Integration testing with jsii-calc utilities

🤖 Generated with Claude Code

tinovyatkin avatar Jul 31 '25 12:07 tinovyatkin

This PR is missing a description of what problem it is solving, and why and how it solves it.

rix0rrr avatar Oct 29 '25 08:10 rix0rrr