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=765f00d3f202f83f61d03f882f80a2d5142d81f8
RUN git clone https://github.com/PyCQA/bandit.git . \
 && 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)

# pbr (bandit's build backend) writes ChangeLog/AUTHORS into the worktree during
# install; skip them so the image stays porcelain-clean for model.patch capture.
ENV SKIP_WRITE_GIT_CHANGELOG=1 SKIP_GENERATE_AUTHORS=1
RUN pip install --no-cache-dir -e . && \
    pip install --no-cache-dir pytest testtools stestr GitPython beautifulsoup4 'sarif-om>=1.0.4' 'jschema-to-python>=1.2.3' PyYAML tomli lxml fixtures

# v1.1 node-id scoring: pytest emits JUnit XML natively via --junitxml; no extra
# reporter package needed. Assert the image is porcelain-clean.
RUN git status --porcelain && 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"]
