I am working in a one year and a half contract on a specific project (I am developing an application). This is my first real job. The hierarchy of the company is a bit confuse but basically it is a big structure with many sub-entities that are in practice quite independent. My boss is not officially at the head of anything I'm affiliated to but in practice they consider I am supposed to follow what they ask me to do.
The problem is that they are not a good manager. Here are some examples (there is way more than that):
they come to my office at random hours without warning and start an improvised reunion that sometimes lasts for hours. Sometimes it happens on several consecutive days.
they ask for the progress to be written in a specific place and don't read them (they ask me to tell them instead during those surprise reunions)
they sometimes flood the communication tools, other times they have very long periods (~2 months) during which I can't meet them and they don't answer to mails
they always get excited about new ideas and change the specifications. Actually they never read the specs I wrote and count on me to update them as they change their mind even about things they don't tell me.
they tell me not to worry about a point and that an other colleague will do it, and months later tell me it's not done and I should have asked the colleague sooner.
Also they have a very high opinion of themselves and have a bad reaction to critics. They also have quite a reputation due to their past career.
Now I am close to the end of my contract and they start to panic and put the responsibility of the failure on me. I certainly did some mistakes (it's my first job after all) but with everything considered I still think the failure is mostly due to their interventions. The problem is that soon I will have to present my work to the people at the head department of the structure and I am not comfortable with any of the possibilities I have considered:
let the project fail while doing my best, present the failed result and tell it is my boss's fault. It probably won't work because of their position and will sound as excuses for my bad work
work alone, ignore deliberately my boss, and present something correct. I am confident that I can do that if I manage to be left really alone, but they will probably get angry and interrupt me even more
let the project fail, present the failed result and do nothing special. It seems like the easiest solution but it means I will be seen as someone who provides bad results by the head dep of the structure and I won't be able to show what I have done to my next employer.
What should I do to conclude this contract with the best possible outcome?