Well, I am slightly further along with this problem.
I’ve figured out how to call bpy.ops.node.group_ungroup() without the context incorrect problem.
The issue I have now is that I want to change the active material slot on an object while the script is running so that the correct material’s nodes are actually shown in the node editor.
I can make this change, but it doesn’t take effect until the script is stopped, so that’s no use to me.
Currently looking for a way to pause the script to allow Blender to update, and then resume it. Might end up being some overly complicated arrangement using timers.