from os import (
    getenv,
    #kill,
)
#from signal import SIGINT, SIGTERM
from subprocess import (
    run,
    #Popen,
)
import sys


#_child_proc: Popen | None = None


#def _forward_signal(sig, frame):
#    _ = frame
#    if _child_proc is None:
#        return
#    if _child_proc.pid in (SIGINT, SIGTERM):
#        kill(_child_proc.pid, sig)
#    else:
#        raise RuntimeError(f'Attempted to forward an unexpected signal: {sig}')


def main(argv):
    argv = list(argv)   # copy
    base_url = getenv('API_BASE_URL')
    if base_url is None:
        raise RuntimeError('API_BASE_URL is not specified')
    argv.append(base_url)   # HACK: ...
    result = run(['python', '-m', 'tester', *argv[1:]], check=False)
    return result.returncode


if __name__ == '__main__':
    sys.exit(int(main(sys.argv) or 0))
