Li Shenron said:
This way to adjudicate is not much less blurry... What if the caster doesn't know his spell is harmful to someone?
What if you try to cast a Cure X Wounds (an uncommon case to have this and Invis, but yet) on an NPC allied to the party, only to find that such NPC is an undead?
That's why I mentioned the case of Daylight: usually it's a harmless spell, unless someone is hurt by strong light.
It is not about harm, it about effect.
If the spell "targets" the foe in any way, shape or form, then it is considered an attack, even if the spell does not harm the target in any way.
For example, Detect Magic. The foe is included in the list of targets that are applicable to this spell, hence, it is considered an attack.
A foe is not included in the list of targets that are applicable to a Bless spell, hence, it does not affect him.
A foe is not included in the area of a Wall of Iron. The wall might fall over on him, but he was not a target of the spell.
Fog Cloud, Darkness, Light, and other area effect spells (unlike Bless) effectively target every creature within their area, even if they do not harm them.
So if you target an NPC with a spell and consider that NPC to be a foe (if you do not know he is there, you cannot consider him to be a foe per se), you go visible.
In the Cure X Wounds on an ally who is really an Undead and really harmed, you stay invisible. You considered him an ally, not a foe. If you then change your mind and now consider him a foe and cast a second Cure spell on him, you become visible.
Three elements to this. The spell must target the NPC, you must consider the NPC to be a foe, and you must be aware the NPC is there. If you target an invisible foe who you are not aware is in the area of effect, you stay invisible.