FROM public.ecr.aws/x8v8d7g8/mars-base:latest

WORKDIR /app

# Git time-travel: clone, then make the repo's default branch point AT the base
# commit with no future history — a real branch checkout (not a detached HEAD),
# future commits/tags gc'd away so the reference solution can't leak from history.
ARG BASE_SHA=1eb212f0a0707ad6f4c720bb2010c2b7517cf0f9
RUN git clone https://github.com/jendrikseipp/vulture . \
 && DEFAULT="$(git remote show origin | sed -n 's/.*HEAD branch: //p')" \
 && git checkout -B "$DEFAULT" "$BASE_SHA" \
 && git remote remove origin \
 && for b in $(git for-each-ref --format='%(refname:short)' refs/heads | grep -vx "$DEFAULT"); do git branch -D "$b" || true; done \
 && for t in $(git tag); do git merge-base --is-ancestor "$t" HEAD 2>/dev/null || git tag -d "$t"; done \
 && git reflog expire --expire=now --all \
 && git gc --prune=now \
 && (git submodule update --init --recursive || true)

RUN bash -lc "\
  apt-get update && apt-get install -y graphviz; \
  if [ -f requirements.txt ]; then pip install --no-cache-dir -r requirements.txt; fi; \
  if [ -f requirements_test.txt ]; then pip install --no-cache-dir -r requirements_test.txt; fi; \
  if [ -f requirements_mypy.txt ]; then pip install --no-cache-dir -r requirements_mypy.txt; fi; \
  if [ -f requirements_diagrams.txt ]; then pip install --no-cache-dir -r requirements_diagrams.txt; fi; \
  if [ -f pyproject.toml ] && command -v poetry >/dev/null 2>&1; then poetry install --no-root --no-interaction; fi; \
  if [ -f package.json ]; then npm install --no-audit --no-fund; fi; \
  pip install --no-cache-dir -e . pytest pytest-cov pyflakes pycodestyle rut coverage build twine pint"

# v1.1 node-id scoring: pytest emits JUnit XML natively via --junitxml; no extra
# reporter package needed.

CMD ["bash"]
