Skip to content

chore: unclutter adt server testing#692

Draft
ssbarnea wants to merge 1 commit intomainfrom
feat/adt-server-testing
Draft

chore: unclutter adt server testing#692
ssbarnea wants to merge 1 commit intomainfrom
feat/adt-server-testing

Conversation

@ssbarnea
Copy link
Copy Markdown
Member

@ssbarnea ssbarnea commented Feb 26, 2026

  • ensures that we capture the output of the server in both cases, container and outside container
  • consolidate logic for starting the servers
  • resolves problem with verbosity_assertions pytest option
  • improves coverage reporting

@github-actions github-actions bot added the chore label Feb 26, 2026
@ssbarnea ssbarnea force-pushed the feat/adt-server-testing branch from 6a8b844 to e134128 Compare February 26, 2026 14:30
@github-actions github-actions bot added chore and removed chore labels Feb 26, 2026
@ssbarnea ssbarnea force-pushed the feat/adt-server-testing branch from e134128 to 674dd21 Compare February 26, 2026 14:37
@github-actions github-actions bot added chore and removed chore labels Feb 26, 2026
@ssbarnea ssbarnea force-pushed the feat/adt-server-testing branch from 674dd21 to a11b9bf Compare February 26, 2026 14:43
@github-actions github-actions bot added chore and removed chore labels Feb 26, 2026
@ssbarnea ssbarnea force-pushed the feat/adt-server-testing branch from a11b9bf to a9284d0 Compare February 26, 2026 17:32
@github-actions github-actions bot added chore and removed chore labels Feb 26, 2026
@ssbarnea ssbarnea force-pushed the feat/adt-server-testing branch from a9284d0 to 3f16e1f Compare February 26, 2026 17:34
@github-actions github-actions bot added chore and removed chore labels Feb 26, 2026
@ssbarnea ssbarnea force-pushed the feat/adt-server-testing branch from 3f16e1f to 9636f0d Compare March 6, 2026 16:36
Copilot AI review requested due to automatic review settings March 6, 2026 16:36
@github-actions github-actions bot added chore and removed chore labels Mar 6, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors test infrastructure bootstrapping for the ADT server to unify container/non-container startup, capture server output to log files, and adjust pytest warning/verbosity and coverage-related behavior.

Changes:

  • Replace hard-coded server ports with shared constants and reuse them across fixtures/startup logic.
  • Consolidate container and host server startup into a single _start_server(container=...) code path and log server output to per-mode log files.
  • Update pytest warning filtering to avoid failing the run on pytest.PytestWarning.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.

File Description
src/ansible_dev_tools/tests/conftest.py Refactors server/container startup and URL/port handling; adds log capture for server processes.
pyproject.toml Adjusts pytest warning filters to always emit (and not error on) pytest.PytestWarning.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 497 to +508
assert INFRASTRUCTURE is not None
bin_path = shutil.which("adt")
if bin_path is None:
msg = "adt not found in $PATH"
raise RuntimeError(msg)
server_log_file = Path(os.environ.get("TOX_ENV_DIR", ".tox")) / "log" / "server.log"
log_file_name = "server.log" if not container else "container-server.log"
server_log_file = Path(os.environ.get("TOX_ENV_DIR", ".tox")) / "log" / log_file_name

server_log_file.parent.mkdir(parents=True, exist_ok=True)
LOGGER.warning("Starting adt server with log file at %s", server_log_file)
cmd = (
f"{bin_path} server -p {ADT_SERVER_PORT} --debug" if not container else _get_container_cmd()
)
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_start_server unconditionally requires adt to be present on the host (bin_path = shutil.which("adt")), but in the container=True path the command is built from _get_container_cmd() and runs adt server inside the container. This means --only-container runs will fail unnecessarily if adt isn't installed on the host. Consider only resolving/validating bin_path when container is false.

Copilot uses AI. Check for mistakes.
Comment on lines +269 to +275
if INFRASTRUCTURE.container:
_start_server(container=True)
if INFRASTRUCTURE.server:
_start_server(container=False)
if not INFRASTRUCTURE.container and not INFRASTRUCTURE.server:
err = "Cannot run tests with any server option."
pytest.exit(err, 2)
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In --include-container mode, Infrastructure.__post_init__ sets both container=True and server=True, so pytest_sessionstart calls _start_server() twice. Since _start_server stores the process in INFRASTRUCTURE.proc, the second call overwrites the first process handle, so the container server process is no longer tracked (and readiness checks/logging can be misleading). Consider keeping separate process slots (e.g., proc_host/proc_container) or restoring separate _start_container() / _start_server() responsibilities so both servers can be started and stopped reliably in the same run.

Copilot uses AI. Check for mistakes.
if INFRASTRUCTURE.server:
_start_server(container=False)
if not INFRASTRUCTURE.container and not INFRASTRUCTURE.server:
err = "Cannot run tests with any server option."
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message Cannot run tests with any server option. reads like tests cannot run when a server option is provided; it likely meant "without any server option" (or similar).

Suggested change
err = "Cannot run tests with any server option."
err = "Cannot run tests without any server option."

Copilot uses AI. Check for mistakes.
Comment on lines +329 to 332
def _get_container_cmd() -> str:
"""Start the container.

The default image for navigator is pulled ahead of time.
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_get_container_cmd() now returns the container run command (it doesn't actually start the container), but the docstring still starts with "Start the container." This is misleading for readers and for future refactors; consider updating the summary line to reflect that it builds the command (and performs any required preflight steps) rather than starting it.

Copilot uses AI. Check for mistakes.
Comment on lines 381 to 387
else:
nav_ee = get_nav_default_ee_in_container()
_proc = _exec_container(command=f"podman pull {nav_ee}")
return cmd


def get_nav_default_ee_in_container() -> str:
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_get_container_cmd() calls _exec_container(...) (e.g., podman load / podman pull) before the container is started, but _exec_container uses <engine> exec ... which requires the container to already be running. With the new flow (starting the container via subprocess.Popen(cmd, shell=True) in _start_server(container=True)), these exec calls will fail. Consider moving these operations to after the container is launched and healthy (or run them on the host with subprocess.run instead of exec).

Copilot uses AI. Check for mistakes.
Comment on lines 506 to 529
@@ -512,7 +524,7 @@
while tries < max_tries:
try:
# timeout increased to 2s due to observed GHA macos failures
res = requests.get("http://localhost:8000", timeout=timeout)
res = requests.get(f"http://localhost:{ADT_SERVER_PORT}", timeout=timeout)
if res.status_code == requests.codes.get("not_found"):
return
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When container=True, the server runs on ADT_SERVER_CONTAINER_PORT (8001), but the readiness probe always polls http://localhost:{ADT_SERVER_PORT} (8000). This can falsely report success (if the host server is up) while the container server is down. The probe URL should switch based on container to check the correct port.

Copilot uses AI. Check for mistakes.
Comment on lines +506 to 519
cmd = (
f"{bin_path} server -p {ADT_SERVER_PORT} --debug" if not container else _get_container_cmd()
)
msg = f"Starting adt server with `{cmd}` and log file at {server_log_file}"
LOGGER.warning(msg)
start_time = time.time()
with server_log_file.open("w") as log_file:
INFRASTRUCTURE.proc = subprocess.Popen( # noqa: S603
[bin_path, "server", "-p", "8000", "--debug"],
INFRASTRUCTURE.proc = subprocess.Popen(
cmd,
env=os.environ,
shell=True,
stdout=log_file,
stderr=subprocess.STDOUT,
)
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the non-container case, _start_server now builds a single shell command string and runs it with shell=True. This is less robust than passing an argv list (e.g., paths with spaces, quoting, platform differences) and makes the container/non-container code paths harder to reason about. Consider keeping shell=False + argv list for the host server, and only using a shell command string for the container engine invocation.

Copilot uses AI. Check for mistakes.
cache_dir = "./.cache/.pytest"
filterwarnings = [
# We raise one non critical warning from our own conftest.py:
"always::pytest.PytestWarning",
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding "always::pytest.PytestWarning" before "error" means all PytestWarnings will no longer fail the test run, which can hide genuinely actionable pytest configuration warnings. If the goal is to silence a single known warning, it would be safer to filter that specific warning more narrowly (by message/module) instead of exempting the entire PytestWarning category.

Suggested change
"always::pytest.PytestWarning",
"always::pytest.PytestWarning:ansible_dev_tools.tests.conftest",

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants