# Path: e2e-test-server/e2e_test_server/constants.py
# PROJECT_ID = os.environ["PROJECT_ID"]
# 
# PUSH_PORT = (
#     os.environ["PUSH_PORT"]
#     if SUBSCRIPTION_MODE is SubscriptionMode.PUSH
#     else None
# )
# 
# REQUEST_SUBSCRIPTION_NAME = os.environ["REQUEST_SUBSCRIPTION_NAME"]
# 
# RESPONSE_TOPIC_NAME = os.environ["RESPONSE_TOPIC_NAME"]
# 
# SCENARIO = "scenario"
# 
# STATUS_CODE = "status_code"
# 
# TEST_ID = "test_id"


import base64
import logging
from typing import Literal
from google.cloud import pubsub_v1
from google.cloud.pubsub_v1.subscriber.message import Message
from google.rpc import code_pb2
from . import scenarios, types
from .constants import (
    PROJECT_ID,
    PUSH_PORT,
    REQUEST_SUBSCRIPTION_NAME,
    RESPONSE_TOPIC_NAME,
    SCENARIO,
    STATUS_CODE,
    TEST_ID,
)
    from flask import Flask, Response, request
    from waitress import serve
        logger.info(f"publishing {data=} and {attributes=}")

        self._publisher.publish(
            self._response_topic,
            data,
            **attributes,
        )


def handle_message(
    message: types.PubsubMessage, responder: _Responder
) -> Literal["ack", "nack"]:
    """Execute a scenario based on the incoming message from the test runner.
    Return whether to ack or nack the message"""
    if TEST_ID not in message.attributes:
        # don't even know how to write back to the publisher that the
        # message is invalid, so nack()
        return "nack"
    test_id: str = message.attributes[TEST_ID]

    if SCENARIO not in message.attributes:
        responder.respond(
            test_id,
            scenarios.Response(
                status_code=code_pb2.INVALID_ARGUMENT,
                data=f'Expected attribute "{SCENARIO}" is missing'.encode(),
            ),
        )
        return "ack"


# Path: e2e-test-server/e2e_test_server/constants.py
# PROJECT_ID = os.environ["PROJECT_ID"]
# 
# PUSH_PORT = (
#     os.environ["PUSH_PORT"]
#     if SUBSCRIPTION_MODE is SubscriptionMode.PUSH
#     else None
# )
# 
# REQUEST_SUBSCRIPTION_NAME = os.environ["REQUEST_SUBSCRIPTION_NAME"]
# 
# RESPONSE_TOPIC_NAME = os.environ["RESPONSE_TOPIC_NAME"]
# 
# SCENARIO = "scenario"
# 
# STATUS_CODE = "status_code"
# 
# TEST_ID = "test_id"


# Path: e2e-test-server/e2e_test_server/server.py
import base64
import logging
from typing import Literal
from google.cloud import pubsub_v1
from google.cloud.pubsub_v1.subscriber.message import Message
from google.rpc import code_pb2
from . import scenarios, types
from .constants import (
    PROJECT_ID,
    PUSH_PORT,
    REQUEST_SUBSCRIPTION_NAME,
    RESPONSE_TOPIC_NAME,
    SCENARIO,
    STATUS_CODE,
    TEST_ID,
)
    from flask import Flask, Response, request
    from waitress import serve

        logger.info(f"publishing {data=} and {attributes=}")

        self._publisher.publish(
            self._response_topic,
            data,
            **attributes,
        )


def handle_message(
    message: types.PubsubMessage, responder: _Responder
) -> Literal["ack", "nack"]:
    """Execute a scenario based on the incoming message from the test runner.
    Return whether to ack or nack the message"""
    if TEST_ID not in message.attributes:
        # don't even know how to write back to the publisher that the
        # message is invalid, so nack()
        return "nack"
    test_id: str = message.attributes[TEST_ID]

    if SCENARIO not in message.attributes:
        responder.respond(
            test_id,
            scenarios.Response(
                status_code=code_pb2.INVALID_ARGUMENT,
                data=f'Expected attribute "{SCENARIO}" is missing'.encode(),
            ),
        )
        return "ack"


    scenario = message.attributes[SCENARIO]