The easiest way to get the extra code (the dummy Serial class) into the program is just to put a line like
#include "arduinostuff.cpp"
at the start of the program in globalextra. Then add to the question a support file arduinostuff.cpp that contains all the extra code.
If you want to hide the include from students you can change the line in the template
raw_prog = """{{ QUESTION.globalextra | e('py') }}"""
to
raw_prog = """#include "arduinostuff.cpp"\n{{ QUESTION.globalextra | e('py') }}"""
For more flexibility again you could set up a template parameter that specified the name(s) of extra files to be included. That way the same question type can be used with different support files.
Checking the indentation of the C code is probably not relevant with gap fillers. But when the student is writing whole functions or programs it's certainly nice to check it. Assuming you're running some variant of the c_via_python question type, the submitted code (for non gap-filler questions) is available as as a string
e.g. by
student_answer = """ {{ STUDENT_ANSWER | e('py') }}"""
and it's over to you to check it however you like.
Our own horrendously complex C question type runs the astyle program over the student's code and checks if the code has changed as a result. If so, it prints any discrepancies and aborts execution. Student's are told that they are required to lay out the code exactly as astyle does (with a particular style convention) and their code editor has a button to run astyle with a single mouse click or control-key. So they have no excuse for submitting non-astyle-compliant code.
Our checking also includes parsing the submitted C code with the pycparser Python module and checking things like function length and choice of identifiers. However you can't use pycparser with Arduino C as it's really C++. I don't know of any C++ parser written in Python.
To be fair to the student, you need to provide a Precheck button that does all style checking
so they don't pay penalties for trivial stylistic defects.
I suggest you start small and just add simple checks to your base question type and built up its capabilities over time (possibly years).