I don't doubt it's this big mess you are describing, but if the engine is actively looking for test/not test and does things like turning off particle filtering after 30 minutes of driving because it knows any test will be over, it seems to me the intention is in fact to lie about the real emissions.