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

RUN apt-get update && apt-get install -y --no-install-recommends \
      build-essential \
      gcc \
      g++ \
      pkg-config \
      python3-dev \
      libssl-dev \
      zlib1g-dev \
      libbz2-dev \
    && rm -rf /var/lib/apt/lists/*

# 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=061c97f8a01bf9e721835978b039303c5051501c
RUN git clone https://github.com/narwhals-dev/narwhals . \
 && 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 pip3 install -e ".[pandas,polars,pyarrow,duckdb,sqlframe,sql]" -e test-plugin && \
    pip3 install \
      "covdefaults" \
      "pytest>=8.3.3,<9" \
      "pytest-cov>=6.0.0,<7" \
      "pytest-env" \
      "pytest-randomly" \
      "pytest-xdist>=3.6.1,<4" \
      "hypothesis>=6.119.4,<7" \
      "pytest-timeout>=2.4.0,<3"

# Pin polars to the validated <1.40 line. polars 1.40 deprecated the dataframe-interchange
# protocol (DeprecationWarning-as-error on the interchange tests) and changed get_column(int)'s
# TypeError message, breaking pre-existing baseline tests. The narwhals extras leave polars
# unpinned, so unpinned builds drifted to 1.40.x.
RUN pip3 install "polars<1.40"

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

# Disable git commit hooks (husky etc.): dev-workflow tooling, not task content.
# Broken hook environments otherwise block the agent's (and oracle's) commits.
RUN cd /app && git config core.hooksPath /dev/null

CMD ["/bin/bash"]
