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=227883606023d62275fb48701aeac90f2b604143
RUN git clone https://github.com/sharkdp/fd . \
 && 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 cargo fetch --locked

# v1.1 node-id scoring: cargo-nextest (pinned prebuilt binary) emits JUnit XML.
# Reporter config lives OUTSIDE the repo (--config-file) so the model can't
# hijack it via .config/nextest.toml.
ARG NEXTEST_VERSION=0.9.97
RUN curl -LsSf "https://get.nexte.st/${NEXTEST_VERSION}/linux" | tar zxf - -C /usr/local/bin \
 && cargo nextest --version
RUN mkdir -p /opt/nextest \
 && printf '[profile.junit]\nfail-fast = false\n\n[profile.junit.junit]\npath = "junit.xml"\n' > /opt/nextest/nextest.toml

# Official ctrf-io converter, pinned: nextest JUnit XML -> CTRF JSON.
# mars-base ships node (v24.12.0 today); the node --version guard fails the
# build loudly if the base ever drops it.
# Fallback ONLY if a future base image lacks node (not needed today):
#   RUN curl -fsSL https://nodejs.org/dist/v22.17.0/node-v22.17.0-linux-x64.tar.xz | tar -xJ -C /opt \
#    && ln -s /opt/node-v22.17.0-linux-x64/bin/node /usr/local/bin/node \
#    && ln -s /opt/node-v22.17.0-linux-x64/bin/npm /usr/local/bin/npm
RUN node --version && npm install -g junit-to-ctrf@0.0.14 --ignore-scripts && junit-to-ctrf --version

# Warm the build cache so verifier runs only recompile the fd crate delta.
RUN cargo nextest run --test tests --no-run --config-file /opt/nextest/nextest.toml --profile junit

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