# 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. Chicken-and-egg: first script emits setup_complete, entrypoint does not.
#    Validate times out and prints a diagnostic about the deadlock.
build-image chicken-egg:latest chicken_egg
! snouty validate config_chicken_egg --timeout 1
stderr 'timed out waiting for setup-complete event.*'
stderr 'suite/first_emit_setup in service runner emits setup_complete.*deadlock.*'

# 9. 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: setup-emitter:latest
    pull_policy: never

-- all_types/suite/first_setup --
#!/bin/sh
# Emit an SDK event to sdk.jsonl to verify that non-setup_complete events
# in first scripts don't trigger the chicken-and-egg diagnostic.
echo '{"antithesis_assert":{"hit":true,"must_hit":true,"assert_type":"sometimes","display_type":"Sometimes","message":"first_setup ran","condition":true,"id":"first_setup","location":{},"details":null}}' >> "$ANTITHESIS_OUTPUT_DIR/sdk.jsonl"
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: all-types:latest
    pull_policy: never
  sidecar:
    image: setup-emitter:latest
    pull_policy: never

-- 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: fail-with-finally:latest
    pull_policy: never

-- 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: nodrivers:latest
    pull_policy: never

-- 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: unknown-prefix:latest
    pull_policy: never

-- 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: noexec:latest
    pull_policy: never

-- 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: net-check:latest
    pull_policy: never

-- chicken_egg/suite/first_emit_setup --
#!/bin/sh
echo '{"antithesis_setup":{"status":"complete"}}' >> "$ANTITHESIS_OUTPUT_DIR/sdk.jsonl"

-- chicken_egg/suite/parallel_driver_noop --
#!/bin/sh
echo "driver ran"

-- chicken_egg/Dockerfile --
FROM busybox
COPY suite/ /opt/antithesis/test/v1/suite/
RUN chmod +x /opt/antithesis/test/v1/suite/*
CMD sleep 3600
-- config_chicken_egg/docker-compose.yaml --
services:
  runner:
    image: chicken-egg:latest
    pull_policy: never

-- 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: sdk-local-emitter:latest
    pull_policy: never
