Working with the CSSstyleSheet API
- Changing the selectorText -

Test 4 - adapting the script

In the tests 1/2/3 it looks like the initial selectorText is repeated after the update (except the explicit javascript driven .otherClass change). - Aha, that is the pitfall!
The let myRules = ... definition (pointing to the initial values of the selectorText) is a global variable if it's not inside a function, and when recalled in the update function it's using exactly the same values.
When defining the let myRules = ... anew in the update function, the suffering should have been suffered.
See what happens!

Testing a style update

  1. Use the Developer Tool of the browser and go to the 2nd <style> block in the <head>.
  2. Click right and "Edit as HTML".
  3. Delete the word main of the selector rule  main code { ... }
  4. Delete the whole style rule .testbox-1 { background: turquoise; color: black } and leave the editor by clicking somewhere in the Developer Pane outside the editor box.
  5. Then use the button to update the selectorText via the CSSStyleSheet API.

This is ".testbox1"This is ".testbox2"

The initial selectorText for each style rule of the 2nd style block is:

*
main code
.testbox1
.testbox2

The updated selectorText for each style rule of the 2nd style block is:

*
code
.otherClass
 

Results

Conclusion