Would it actually be legal to alternate between Andorra and France or Spain?
Yes, on condition that when entering Andorra you have a Schengen Area exit stamp and when leaving Andorra have a Schengen Area entry stamp.
As far as the Schengen Border Code is concerned, it is the proper entry/exit stamps that counts (assuming you don't require a visa) for short term stays.
Without the entry/exit stamps you are assumed to have overstayed, unless you can prove otherwise.
Sources:
- How to Get a Residence Permit in Andorra | Andorra Guides
Section 4
...
The regime for entry and movement in France and Spain for foreigners holding an Andorran residence permit is identical to that which applies to foreigners holding a French or Spanish residence permit.Google Translate Original text
- Andorra Schengen Visa Explained | Andorra Guides