From 9bb4b57824b6098d2695876befa3fe88ccee2210 Mon Sep 17 00:00:00 2001 From: Raymond Khalife Date: Thu, 11 Jun 2026 16:12:53 -0400 Subject: [PATCH 1/5] feat(tests): containerized template test harness (M1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds the first milestone of the template testing pipeline: a thin test image over ghcr.io/dfinity/icp-dev-env-all and a bash harness that renders a template from the local checkout via `icp new`, builds, deploys to a local network, and verifies a backend call — all inside the container, against the icp CLI pinned in the image. Covers a single hardcoded permutation (rust template, defaults); the full matrix follows in M2. Co-Authored-By: Claude Fable 5 --- Makefile | 13 ++++++ tests/Dockerfile | 19 +++++++++ tests/lib.sh | 107 +++++++++++++++++++++++++++++++++++++++++++++++ tests/run.sh | 32 ++++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 Makefile create mode 100644 tests/Dockerfile create mode 100644 tests/lib.sh create mode 100755 tests/run.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c200ac4 --- /dev/null +++ b/Makefile @@ -0,0 +1,13 @@ +# Template testing pipeline — see docs/template-testing-prd.md. +# Tests always run inside the container, against the icp CLI pinned in the +# image; the host only needs Docker. + +IMAGE ?= icp-template-tests + +.PHONY: test test-image + +test-image: + docker build -t $(IMAGE) tests + +test: test-image + docker run --rm -v "$(CURDIR)":/repo:ro $(IMAGE) /repo/tests/run.sh diff --git a/tests/Dockerfile b/tests/Dockerfile new file mode 100644 index 0000000..b4f507a --- /dev/null +++ b/tests/Dockerfile @@ -0,0 +1,19 @@ +# Test image for the template testing pipeline (docs/template-testing-prd.md). +# +# Thin layer over the official ICP dev environment, which already ships the +# icp CLI (with embedded cargo-generate and PocketIC), Rust + wasm32 target, +# mops, and Node.js. We only add yq for parsing the rendered icp.yaml files. +ARG BASE_TAG=0.3.2 +FROM ghcr.io/dfinity/icp-dev-env-all:${BASE_TAG} + +# cargo-generate (inside `icp new`) requires $USER; the base image runs as +# root without it. Also opt out of icp telemetry for test runs. +ENV USER=root \ + DO_NOT_TRACK=1 + +ARG YQ_VERSION=v4.53.3 +RUN ARCH="$(dpkg --print-architecture)" \ + && curl -fsSL "https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${ARCH}" \ + -o /usr/local/bin/yq \ + && chmod +x /usr/local/bin/yq \ + && yq --version diff --git a/tests/lib.sh b/tests/lib.sh new file mode 100644 index 0000000..f15e556 --- /dev/null +++ b/tests/lib.sh @@ -0,0 +1,107 @@ +# Shared test steps for the template testing pipeline. +# Sourced by run.sh; runs inside the test container (see tests/Dockerfile). + +# Repo root as mounted into the container (read-only). +REPO="${REPO:-/repo}" +GATEWAY_PORT=8000 + +# Never send icp telemetry from test runs (also set in tests/Dockerfile, but +# exported here so it holds however the harness is invoked). +export DO_NOT_TRACK=1 + +step() { printf '\n==> %s\n' "$*"; } +fail() { printf 'FAIL: %s\n' "$*" >&2; exit 1; } + +# prepare_template_source +# Copies the repo into , restricted to files git would track +# (tracked + untracked-but-not-ignored). Local build artifacts in template +# dirs (target/, node_modules/, ...) would otherwise be copied and +# template-substituted by cargo-generate, which is slow and fails on +# binaries. Sets TEMPLATE_SRC. +prepare_template_source() { + TEMPLATE_SRC="$1" + mkdir -p "$TEMPLATE_SRC" + # The repo bind-mount is owned by the host user; git refuses to read it + # from a different uid without this. + git config --global --add safe.directory "$REPO" + (cd "$REPO" && git ls-files --cached --others --exclude-standard -z \ + | tar --null --ignore-failed-read -cf - -T -) \ + | tar -xf - -C "$TEMPLATE_SRC" \ + || fail "could not copy template source from $REPO" +} + +# render