# snouty launch --config — image push and pinning
#
# When --config is used, snouty detects local build images, tags them
# with the ANTITHESIS_REPOSITORY prefix, and pushes them alongside a
# config image.
# Both get pinned references (name@sha256:digest) in the webhook params.

# Local build images are tagged with registry prefix, pushed and pinned.
mock-server 200 '{"status": "ok"}'
build-image myapp:latest images/myapp
build-image sidecar:v1 images/sidecar
snouty launch -w basic_test -c push_config --duration 30
stderr '"antithesis.config_image":.*@sha256:'
stderr '"antithesis.images":.*myapp@sha256:'
stderr '"antithesis.images":.*sidecar@sha256:'

# No compose images match the registry — only config image is pinned.
mock-server 200 '{"status": "ok"}'
snouty launch -w basic_test -c external_config --duration 30
stderr '"antithesis.config_image":.*@sha256:'
! stderr '"antithesis.images"'

# Mixed: local build image is tagged+pushed, external image is skipped.
mock-server 200 '{"status": "ok"}'
build-image myapp:latest images/myapp
snouty launch -w basic_test -c mixed_config --duration 30
stderr '"antithesis.images":.*myapp@sha256:'
! stderr 'nginx.*@sha256:'
stderr '"antithesis.config_image":.*@sha256:'

# Local image without build stanza is not pushed.
mock-server 200 '{"status": "ok"}'
snouty launch -w basic_test -c local_no_build_config --duration 30
stderr '"antithesis.config_image":.*@sha256:'
! stderr '"antithesis.images"'

# A non-amd64 image scheduled for push is rejected before any push happens.
mock-server 200 '{"status": "ok"}'
build-image --platform linux/arm64 arm-launch:latest images/arm_launch
! snouty launch -w basic_test -c arm_push_config --duration 30
stderr 'x86-64 \(amd64\).*'
stderr 'image '\''.*arm-launch:latest'\'' has architecture '\''arm64'\''.*'
! stderr 'Pushing image:'

# A non-amd64 image that is NOT pushed (no registry prefix, no build) does
# not trigger the architecture check.
mock-server 200 '{"status": "ok"}'
build-image --platform linux/arm64 arm-external:latest images/arm_launch
snouty launch -w basic_test -c arm_external_config --duration 30
stderr '"antithesis.config_image":.*@sha256:'
! stderr '"antithesis.images"'

# Kubernetes config: builds and pushes the config image, never sets
# antithesis.images (the platform pulls images from the manifests).
mock-server 200 '{"status": "ok"}'
snouty launch -w basic_k8s_test -c k8s_config --duration 30
stderr '"antithesis.config_image":.*@sha256:'
! stderr '"antithesis.images"'

-- images/myapp/content --
placeholder
-- images/sidecar/content --
placeholder
-- images/arm_launch/Dockerfile --
FROM scratch
-- push_config/docker-compose.yaml --
services:
  app:
    build: .
    image: myapp:latest
  sidecar:
    build: .
    image: sidecar:v1
-- external_config/docker-compose.yaml --
services:
  app:
    image: docker.io/library/nginx:latest
-- mixed_config/docker-compose.yaml --
services:
  app:
    build: .
    image: myapp:latest
  nginx:
    image: docker.io/library/nginx:latest
-- local_no_build_config/docker-compose.yaml --
services:
  app:
    image: localapp:latest
-- arm_push_config/docker-compose.yaml --
services:
  app:
    build: .
    image: arm-launch:latest
-- arm_external_config/docker-compose.yaml --
services:
  app:
    image: arm-external:latest
-- k8s_config/manifests/ns.yaml --
apiVersion: v1
kind: Namespace
metadata:
  name: snouty-demo
