Write promise class from scratch.
Implement a Python function that defines and exercises a Promise-like abstraction. It must support fulfillment, rejection, chaining with then, exception propagation, thenable assimilation, self-resolution protection, finally, and the all and race combinators.
Use the supplied scenario object as the grading contract. Return a plain dictionary containing the final state and either value or the exception type in error.
Function signature: def promise_class(scenario):
def promise_class(scenario):