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=c981f9c7aa91b83cc9bd33a09ecee9e751b06e8d
RUN git clone https://github.com/dateutil/dateutil . \
 && 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)

# The zoneinfo tarball is not in git at this commit and not covered by .gitignore;
# exclude it repo-locally (.git/info/exclude is untracked metadata) so the worktree
# stays porcelain-clean and Step 0's `git add -A` never folds it into model.patch.
RUN echo 'src/dateutil/zoneinfo/dateutil-zoneinfo.tar.gz' >> .git/info/exclude

RUN mkdir -p src/dateutil/zoneinfo && \
    if [ ! -f src/dateutil/zoneinfo/dateutil-zoneinfo.tar.gz ]; then \
      tmpdir=$(mktemp -d) && \
      pip3 download python-dateutil --no-deps --no-binary :all: -d "$tmpdir" -q && \
      cd "$tmpdir" && \
      tar xzf python-dateutil-*.tar.gz && \
      cp python-dateutil-*/src/dateutil/zoneinfo/dateutil-zoneinfo.tar.gz /app/src/dateutil/zoneinfo/ && \
      cd /app && \
      rm -rf "$tmpdir"; \
    fi

RUN pip3 install -e . && \
    pip3 install -r requirements-dev.txt

# v1.1 node-id scoring: pytest emits JUnit XML natively via --junitxml; no extra
# reporter package needed. The verifier must see a pristine worktree.
RUN test -z "$(git status --porcelain)"

# 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"]
