bambuddy/Dockerfile.test
maziggy 08df660f6c Replace the embedded G-code viewer with the slicer's own renderer
Sliced files previewed through a vendored copy of PrettyGCode in an
iframe. It drew each move as a screen-space line -- a line has no
thickness in the scene, so it cannot occlude the layer behind it, which
is why prints came out stringy and shimmered where layers crossed. Being
a separate app in a frame, it could be neither themed nor translated, and
carried its own machinery for detecting a proxy refusing the embed.

Now built on libvgcode, the renderer OrcaSlicer draws its own preview
with, vendored from three-slicer (AGPL, same as us). It takes the THREE
namespace as an argument and imports nothing, so it runs on our 0.181
rather than the 0.160 its package pins.

The parser is ours; upstream renders its own kernel's output and ships no
G-code parser at all. Two things it has to get right, both found by
checking a real plate rather than assuming:

- BambuStudio does not use the OrcaSlicer/PrusaSlicer annotations. It
  writes "; FEATURE:", "; LINE_WIDTH:", "; CHANGE_LAYER" and
  "; Z_HEIGHT:", not ";TYPE:", ";WIDTH:" and ";LAYER_CHANGE". Reading
  only the latter showed a 52-layer print as 23,165 layers in one colour,
  because with no layer marker recognised every travel Z-hop split a
  layer and every segment took the fallback feature.
- It emits a tenth of its moves as G2/G3 arcs -- 706 extruding ones in a
  single plate. Ignoring them punched holes through curved walls and tree
  supports. Arcs with no X/Y are the helical travel lift and lay down
  nothing, so they interpolate as travels.

Four colour modes: filament (default, from the AMS slots the file was
sliced with), feature, layer height, line width. Speed, fan and
temperature are deliberately absent -- upstream derives those from
settings rather than the toolpath, and guesses dressed as measurements
are worse than an honest omission. The parser now carries the data to do
them properly later.

Legend entries are switches. Hiding removes the records before the mesh
is built rather than recolouring them: the shader packs colour into a
single float with no alpha, so there is no transparent to set, and
removal is the useful behaviour anyway -- a hidden support stops
occluding what it covered.

The scene is built once and only the toolpath rebuilds. Doing otherwise
constructed a new WebGLRenderer on every render, because the buildVolume
default is an object literal and so a fresh identity each time; browsers
cap live WebGL contexts and drop the oldest, which blanked the canvas
after a few interactions.

utils/framing.ts goes with the iframe, along with six now-orphaned
strings in all 13 locales. src/lib/vendor is excluded from eslint --
acting on findings in vendored code makes it impossible to re-copy on the
next upstream release.
2026-08-09 14:10:18 +02:00

63 lines
2.1 KiB
Text

# Test image for running backend and frontend tests
# syntax=docker/dockerfile:1.7
FROM python:3.13-slim AS backend-test
WORKDIR /app
# Install system dependencies for testing
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies including test dependencies.
# BuildKit cache mount makes subsequent builds re-use the pip download
# cache so the second build only does install work — the slow ~60-90s
# fetch step from the first build becomes ~5s. Requires DOCKER_BUILDKIT=1
# (already set in test_docker.sh).
COPY requirements.txt ./
COPY requirements-dev.txt ./
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -r requirements.txt -r requirements-dev.txt
# Copy backend code
COPY backend/ ./backend/
COPY pyproject.toml ./
# Create necessary directories
RUN mkdir -p /app/data /app/logs /app/archive
# Environment variables for testing
ENV PYTHONUNBUFFERED=1
ENV DATA_DIR=/app/data
ENV TESTING=1
# Test image runs pytest and exits — there is no long-running service
# to probe. HEALTHCHECK NONE is the documented Docker opt-out and
# silences Trivy DS-0026 without adding meaningless probe logic.
HEALTHCHECK NONE
# Default command runs pytest (excluding docker integration tests).
# -v dropped: 5300+ "PASSED foo::bar" lines per worker eat noticeable
# stdout I/O time and clutter test_docker.sh output. --tb=short still
# gives full failure tracebacks when something breaks.
# -n auto adapts to the host's vCPU count instead of hard-coding 30 —
# on a 2-vCPU CI / VM runner, -n 30 spawns 30 Python processes fighting
# for 2 cores, which is mostly IPC + import-thrash overhead.
CMD ["pytest", "backend/tests/", "--tb=short", "-p", "no:cacheprovider", "-n", "auto"]
# -------------------------------------------
# Frontend test stage
FROM node:22-bookworm-slim AS frontend-test
WORKDIR /app/frontend
# Copy package files and install
COPY frontend/package*.json ./
RUN npm ci
# Copy frontend source
COPY frontend/ ./
# Default command runs tests
CMD ["npm", "test", "--", "--run"]