# snouty validate — positive tests with container runtime

# 1. Setup-complete only (no test scripts) — validate succeeds.
build-image setup-emitter:latest setup_emitter
snouty validate config_no_scripts --timeout 15
stderr 'Isolating networks: default.*'
stderr 'Setup-complete event detected.*'
stderr 'No test scripts in service.*'
stderr 'Setup validation successful.*'

# 2. All script types run in correct phases, helper_ ignored.
#    Includes a sidecar without scripts to verify it doesn't block execution.
build-image all-types:latest all_types
snouty validate config_all_types --timeout 15
stderr 'Setup-complete event detected.*'
stderr 'Found 1 first, 1 driver, 1 anytime, 1 eventually, 1 finally scripts.*'
stderr 'Running \[suite/first_setup\] in service runner.*'
stderr 'Running \[suite/parallel_driver_load\] in service runner.*'
stderr 'Running \[suite/anytime_check\] in service runner.*'
stderr 'Running \[suite/eventually_verify\] in service runner.*'
stderr 'Running \[suite/finally_cleanup\] in service runner.*'
stderr 'Setup validation successful.*'

# 3. Failing script — remaining scripts still run, validate fails.
#    Captured stdout and stderr from the failed script are printed.
build-image fail-with-finally:latest fail_with_finally
! snouty validate config_fail_finally --timeout 15
stderr 'Running \[suite/first_setup\] in service runner.*'
stderr 'Running \[suite/parallel_driver_bad\] in service runner\.\.\. failed.*'
stderr 'stdout from bad script.*'
stderr 'stderr from bad script.*'
stderr 'Running \[suite/finally_cleanup\] in service runner.*'
stderr 'one or more test scripts failed.*'

# 4. No driver or anytime scripts — validate errors.
build-image nodrivers:latest nodrivers
! snouty validate config_nodrivers --timeout 15
stderr 'no driver or anytime scripts.*'

# 5. Unknown prefix file — validate errors.
build-image unknown-prefix:latest unknown_prefix
! snouty validate config_unknown --timeout 15
stderr 'unrecognized command names.*'
stderr 'suite/readme.txt.*'

# 6. Non-executable script — compose exec fails, validate reports failure.
build-image noexec:latest noexec
! snouty validate config_noexec --timeout 15
stderr 'Running .* failed.*'

# 7. Setup-complete via ANTITHESIS_SDK_LOCAL_OUTPUT (legacy env var).
build-image sdk-local-emitter:latest sdk_local_emitter
snouty validate config_sdk_local --timeout 15
stderr 'Setup-complete event detected.*'
stderr 'Setup validation successful.*'

# 8. Custom networks are isolated and outbound traffic is blocked.
build-image net-check:latest net_check
snouty validate config_net_check --timeout 15
stderr 'Isolating networks: default.*'
stderr 'Setup-complete event detected.*'
stderr 'Setup validation successful.*'

-- setup_emitter/Dockerfile --
FROM busybox
CMD sh -c 'echo "{\"antithesis_setup\":{\"status\":\"complete\"}}" >> "$ANTITHESIS_OUTPUT_DIR/sdk.jsonl" && sleep 3600'
-- config_no_scripts/docker-compose.yaml --
services:
  emitter:
    image: ${ANTITHESIS_REPOSITORY}/setup-emitter:latest

-- all_types/suite/first_setup --
#!/bin/sh
echo "first_setup ran"

-- all_types/suite/parallel_driver_load --
#!/bin/sh
echo "parallel_driver_load ran"

-- all_types/suite/anytime_check --
#!/bin/sh
echo "anytime_check ran"

-- all_types/suite/eventually_verify --
#!/bin/sh
echo "eventually_verify ran"

-- all_types/suite/finally_cleanup --
#!/bin/sh
echo "finally_cleanup ran"

-- all_types/suite/helper_utils --
#!/bin/sh
echo "helper should not run"

-- all_types/Dockerfile --
FROM busybox
COPY suite/ /opt/antithesis/test/v1/suite/
RUN chmod +x /opt/antithesis/test/v1/suite/*
CMD sh -c 'echo "{\"antithesis_setup\":{\"status\":\"complete\"}}" >> "$ANTITHESIS_OUTPUT_DIR/sdk.jsonl" && sleep 3600'
-- config_all_types/docker-compose.yaml --
services:
  runner:
    image: ${ANTITHESIS_REPOSITORY}/all-types:latest
  sidecar:
    image: ${ANTITHESIS_REPOSITORY}/setup-emitter:latest

-- fail_with_finally/suite/first_setup --
#!/bin/sh
echo "first_setup ran"

-- fail_with_finally/suite/parallel_driver_bad --
#!/bin/sh
echo "stdout from bad script"
echo "stderr from bad script" >&2
exit 1

-- fail_with_finally/suite/finally_cleanup --
#!/bin/sh
echo "finally_cleanup ran"

-- fail_with_finally/Dockerfile --
FROM busybox
COPY suite/ /opt/antithesis/test/v1/suite/
RUN chmod +x /opt/antithesis/test/v1/suite/*
CMD sh -c 'echo "{\"antithesis_setup\":{\"status\":\"complete\"}}" >> "$ANTITHESIS_OUTPUT_DIR/sdk.jsonl" && sleep 3600'
-- config_fail_finally/docker-compose.yaml --
services:
  runner:
    image: ${ANTITHESIS_REPOSITORY}/fail-with-finally:latest

-- nodrivers/suite/first_setup --
#!/bin/sh
echo "first_setup ran"

-- nodrivers/Dockerfile --
FROM busybox
COPY suite/ /opt/antithesis/test/v1/suite/
RUN chmod +x /opt/antithesis/test/v1/suite/*
CMD sh -c 'echo "{\"antithesis_setup\":{\"status\":\"complete\"}}" >> "$ANTITHESIS_OUTPUT_DIR/sdk.jsonl" && sleep 3600'
-- config_nodrivers/docker-compose.yaml --
services:
  runner:
    image: ${ANTITHESIS_REPOSITORY}/nodrivers:latest

-- unknown_prefix/suite/first_ok --
#!/bin/sh
echo "first_ok ran"

-- unknown_prefix/suite/readme.txt --
This is not a script.

-- unknown_prefix/Dockerfile --
FROM busybox
COPY suite/ /opt/antithesis/test/v1/suite/
RUN chmod +x /opt/antithesis/test/v1/suite/first_ok
CMD sh -c 'echo "{\"antithesis_setup\":{\"status\":\"complete\"}}" >> "$ANTITHESIS_OUTPUT_DIR/sdk.jsonl" && sleep 3600'
-- config_unknown/docker-compose.yaml --
services:
  runner:
    image: ${ANTITHESIS_REPOSITORY}/unknown-prefix:latest

-- noexec/suite/first_noexec --
#!/bin/sh
echo "should not run"

-- noexec/suite/parallel_driver_load --
#!/bin/sh
echo "driver ran"

-- noexec/Dockerfile --
FROM busybox
COPY suite/ /opt/antithesis/test/v1/suite/
RUN chmod +x /opt/antithesis/test/v1/suite/parallel_driver_load
CMD sh -c 'echo "{\"antithesis_setup\":{\"status\":\"complete\"}}" >> "$ANTITHESIS_OUTPUT_DIR/sdk.jsonl" && sleep 3600'
-- config_noexec/docker-compose.yaml --
services:
  runner:
    image: ${ANTITHESIS_REPOSITORY}/noexec:latest

-- net_check/suite/anytime_ping_blocked --
#!/bin/sh
if ping -c 1 -W 2 example.org >/dev/null 2>&1; then
    echo "ERROR: ping to example.org succeeded, network is not isolated"
    exit 1
fi
echo "Network isolation confirmed: ping to example.org failed"

-- net_check/Dockerfile --
FROM busybox
COPY suite/ /opt/antithesis/test/v1/suite/
RUN chmod +x /opt/antithesis/test/v1/suite/*
CMD sh -c 'echo "{\"antithesis_setup\":{\"status\":\"complete\"}}" >> "$ANTITHESIS_OUTPUT_DIR/sdk.jsonl" && sleep 3600'
-- config_net_check/docker-compose.yaml --
services:
  checker:
    image: ${ANTITHESIS_REPOSITORY}/net-check:latest

-- sdk_local_emitter/Dockerfile --
FROM busybox
CMD sh -c 'echo "{\"antithesis_setup\":{\"status\":\"complete\"}}" >> "$ANTITHESIS_SDK_LOCAL_OUTPUT" && sleep 3600'
-- config_sdk_local/docker-compose.yaml --
services:
  emitter:
    image: ${ANTITHESIS_REPOSITORY}/sdk-local-emitter:latest
