# ============================================================================
# GATE 8: Secret Scanning (gitleaks + detect-secrets)
# Detects secrets (API keys, passwords, tokens) in staged files.
# Tools:
#   gitleaks        -- primary, fail-closed (missing or non-0/1 exit => BLOCK, #499)
#   detect-secrets  -- secondary, baseline-diff: only blocks on secrets NOT in
#                      .secrets.baseline; silently does nothing when unavailable
# ============================================================================

 2>&1 echo ""
 2>&1 echo "→ Gate 8: Secret scanning (gitleaks + detect-secrets)..."
GATE_8_START=$(gate_start_ms)

# Temp files created below (the normalized-baseline copy and the hook output)
# are registered here and removed by this EXIT trap. Installed at FILE scope
# because a trap body runs at exit time, when a function-local variable is no
# longer visible — the first cleanup attempt called a function that read a
# function-local DS_BASELINE and therefore removed nothing.
#
# An ARRAY, not a space-separated string: `rm -f $LIST` word-splits, so a
# TMPDIR containing a space (`/c/Users/Some Name/...` is entirely ordinary on
# Windows) would be torn into fragments, none of which exist, and every gated
# commit would leak one temp file again — the exact failure this trap exists to
# prevent.
GATE8_TEMP=()
gate8_cleanup() {
  if [ "${#GATE8_TEMP[@]}" -gt 0 ]; then
    rm -f "${GATE8_TEMP[@]}" 2>/dev/null
  fi
}
# CHAIN the previous EXIT trap instead of replacing it.
#
# Measured 2026-11-19: `trap gate8_cleanup EXIT` overwrote whatever trap was
# already installed. pre-commit installs `_quality_report_on_exit` at its top
# precisely so that a BLOCKED commit still writes its report, and Gate 8 runs
# before the blocking gates -- so from the moment Gate 8 ran, that trap was gone.
#
# The consequence is the worst possible shape: a commit that PASSES writes its
# report (the epilogue calls generate_quality_report directly), and a commit that
# is BLOCKED writes nothing. The one run an operator needs to diagnose is the one
# with no record.
#
# Reproduced in a go fixture: the chain stopped at Gate 5, and
#
#     ls .xp-gate/reports/pre-commit | wc -l   ->  0
#
# while the same fixture with XP_GATE_ONLY_GATE=8 (chain completes) produced 1.
# Reading the live trap at the end of the hook showed `trap -- 'gate8_cleanup'
# EXIT` -- the report trap had been replaced, not chained.
#
# `trap -p EXIT` prints a form that can be eval'd back, which is the same
# technique pre-commit's own source_gate_lib uses to survive a sourced library
# that installs a trap. The difference here: that library wants to REINSTALL the
# old trap, whereas this gate has to RUN it, so only the command body is kept.
#
# Stripping matters and was caught by the test, not by reading: evaluating the
# whole string ("trap -- 'cmd' EXIT") reinstalls the old trap instead of invoking
# it, so the chain silently did nothing and the report still went missing.
_GATE8_PREV_EXIT_TRAP=""
_gate8_raw_trap="$(trap -p EXIT 2>/dev/null || true)"
if [ -n "$_gate8_raw_trap" ]; then
  _gate8_body="${_gate8_raw_trap#trap -- }"   # drop 'trap -- '
  _gate8_body="${_gate8_body% EXIT}"          # drop the trailing ' EXIT'
  _gate8_body="${_gate8_body#\'}"             # drop the surrounding quotes
  _gate8_body="${_gate8_body%\'}"
  _GATE8_PREV_EXIT_TRAP="$_gate8_body"
fi

gate8_cleanup_and_chain() {
  # CAPTURE $? FIRST, then RESTORE it before handing control on.
  #
  # pre-commit's `_quality_report_on_exit` reads `$?` as its very first statement
  # and exits with that status -- that is what makes the hook exit non-zero when a
  # gate blocked. Running cleanup first overwrote $? with the status of `rm`, so
  # the chained trap saw 0 and the hook exited 0.
  #
  # Measured 2026-11-19, go fixture, Gate 5 blocked (coverage 0%):
  #   before any fix          : commit refused (rc=1), report NOT written
  #   chain without restoring : commit ALLOWED  (rc=0), report written
  #
  # The second row is a WORSE bug than the one being fixed -- a chain that
  # preserves the report by letting blocked commits through. `( exit N )` on its
  # own does not help (the subshell's status is discarded), but it does set $? to
  # N for the next command in this shell, which is what the eval below observes.
  # Verified directly: a chained trap reading $? after this sequence sees the
  # original status, and the hook still exits with it.
  local _g8_saved=$?
  gate8_cleanup
  if [ -n "${_GATE8_PREV_EXIT_TRAP:-}" ]; then
    (exit "$_g8_saved")
    eval "$_GATE8_PREV_EXIT_TRAP"
    return "$_g8_saved"
  fi
  return "$_g8_saved"
}
trap gate8_cleanup_and_chain EXIT

# Gitleaks availability check
GITLEAKS_CMD=""
if command -v gitleaks >/dev/null 2>&1; then
  GITLEAKS_CMD="gitleaks"
elif [ -f "$HOME/.local/bin/gitleaks" ]; then
  GITLEAKS_CMD="$HOME/.local/bin/gitleaks"
fi

if [ -z "$GITLEAKS_CMD" ]; then
  # fail-closed (#499): an uninstalled gitleaks used to SKIP the gate, so any
  # contributor without it shipped commits with zero secret protection and no
  # signal. A security gate that cannot run must not report success.
  echo "     ❌ BLOCKED - gitleaks not installed (fail-closed, #499)."
  echo "   Secret scanning is mandatory before commit. Install gitleaks then retry:"
  echo "     macOS:   brew install gitleaks"
  echo "     Windows: winget install gitleaks"
  echo "     Linux:   scripts/install-gitleaks.sh  (or https://github.com/gitleaks/gitleaks)"
  exit 1
fi

GITLEAKS_CONFIG=""
if [ -f ".gitleaks.toml" ]; then
  # gitleaks is a native binary and may not understand MSYS/WSL paths, so pass an
  # absolute path in the host's own format when we can derive one (#449).
  #
  # #582 found this the hard way: `cygpath` exists only in Git-for-Windows/MSYS, and on
  # WSL its absence meant the fallback handed `/mnt/d/projects/<repo>/.gitleaks.toml`
  # to the native gitleaks.exe. It could not open the file, exited 1, and Gate 8
  # reported "Secrets detected". The conversion now lives in a shared library so the
  # next gate handing a path to a native binary does not re-derive it (#581).
  #
  # This script may also run standalone (archived/copied hook) without the library, so
  # the converter is used when present and the inline branch kept as the fallback.
  if declare -F to_native_path >/dev/null 2>&1; then
    GITLEAKS_CONFIG="--config=$(to_native_path "$(pwd)/.gitleaks.toml")"
  elif command -v cygpath >/dev/null 2>&1; then
    GITLEAKS_CONFIG="--config=$(cygpath -w "$(pwd)/.gitleaks.toml")"
  elif command -v wslpath >/dev/null 2>&1; then
    GITLEAKS_CONFIG="--config=$(wslpath -w "$(pwd)/.gitleaks.toml")"
  else
    GITLEAKS_CONFIG="--config=$(pwd)/.gitleaks.toml"
  fi
fi

# Scan the INDEX, not history. gitleaks 8.x `git --pre-commit` walks committed
# revisions and reports "0 commits scanned" on a pre-commit run -- so a staged
# secret was never seen and Gate 8 always passed. `git --staged` scans
# `git diff --cached`, which is exactly the pre-commit payload (#449).
#
# #616: `--all` is a different question, and the index is the wrong place to ask
# it. Under `xp-gate check . --all` the user asked "is the whole tree clean", the
# index is usually empty, `git --staged` legitimately found nothing, and that
# nothing was counted as PASSED -- a secret sitting in a tracked file was
# invisible to the one command meant to find it. The runner already exports
# GATE_SCOPE (#589); this fragment just has to read it. `dir --no-git` scans the
# filesystem so tracked-but-unmodified files are covered.
GITLEAKS_REPORT="${TMPDIR:-/tmp}/gitleaks-report.json"
rm -f "$GITLEAKS_REPORT"
if [ "${GATE_SCOPE:-diff}" = "all" ]; then
  echo "     Scope: --all (scanning the working tree, not the index)"
  # GITLEAKS_CONFIG is either empty or a single --config=PATH token; quoting it
  # would pass an empty argument to gitleaks. It is split on purpose.
  # shellcheck disable=SC2086
  GITLEAKS_OUTPUT=$($GITLEAKS_CMD dir --no-git --redact --no-banner $GITLEAKS_CONFIG --report-format=json --report-path="$GITLEAKS_REPORT" 2>&1)
  GITLEAKS_EXIT=$?
else
  # shellcheck disable=SC2086  # see above: empty or one --config= token
  GITLEAKS_OUTPUT=$($GITLEAKS_CMD git --staged --redact --no-banner $GITLEAKS_CONFIG --report-format=json --report-path="$GITLEAKS_REPORT" 2>&1)
  GITLEAKS_EXIT=$?
fi

if [ "$GITLEAKS_EXIT" -eq 0 ]; then
  # Decide SKIP from the REPORT ARTIFACT, not from log wording. Parsing stdout
  # meant a gitleaks message change would silently turn a no-evidence run into
  # a PASS -- the same fail-open class this gate just fixed (#449).
  # The report exists and is a JSON array of findings; `[]` == clean scan.
  GITLEAKS_FINDINGS="?"
  if [ -f "$GITLEAKS_REPORT" ]; then
    # A report that is not shaped like a JSON array is no evidence: leave the
    # '?' sentinel so the gate reports SKIP, never a PASS it cannot support
    # (the fail-closed-on-the-claim rule #449 established).
    if grep -q '^\[' "$GITLEAKS_REPORT" 2>/dev/null; then
      # Count occurrences, not matching lines: `grep -c` prints its own zero AND
      # exits 1 on a clean report, so the old `|| echo 0` handed the verdict table
      # $'0\n0' -- no branch matched and a clean scan was BLOCKED as if it leaked
      # (#493). wc -l emits exactly one value, and `|| true` keeps the assignment
      # errexit/pipefail-safe (#489).
      GITLEAKS_FINDINGS=$(grep -o '"RuleID"' "$GITLEAKS_REPORT" 2>/dev/null | wc -l | tr -d '[:space:]') || true
    fi
  fi

  if [ "$GITLEAKS_FINDINGS" = "0" ]; then
    echo "     ✅ PASSED - No secrets detected."
    GATE_8_STATUS="PASS"
  elif [ "$GITLEAKS_FINDINGS" = "?" ]; then
    # #592: exit 0 with no usable report has TWO very different causes, and the
    # operator can only act if we tell them which one happened:
    #
    #   (a) the scan never ran — config unreadable, FTL, bad --report-path.
    #       Nothing was checked, so this must fail closed with the tool's own
    #       words, not be filed as "no evidence about the code".
    #   (b) the scan ran and found nothing, but the tool wrote no file (reported
    #       for gitleaks 8.30.1 on WSL; measured NOT to happen in git-bash with
    #       the same version, so the code must handle both). Only stdout is left,
    #       and stdout is weaker evidence than an artifact, so it still may not
    #       produce a PASS.
    #
    # The order matters and is the point: artifact first, tool failure second,
    # tool output last (#449 established the principle; #592 re-opens it).
    if printf '%s\n' "$GITLEAKS_OUTPUT" | grep -qiE '(^|[[:space:]])(FTL|fatal error)[[:space:]:]|unable to load'; then
      echo "     ❌ BLOCKED - ENVIRONMENT: gitleaks exited 0 but reported a failure, so"
      echo "        NO secret scan took place. This is a tooling problem, not a verdict"
      echo "        about the staged code."
      printf '%s\n' "$GITLEAKS_OUTPUT" | grep -iE 'FTL|fatal|unable' | head -3 | sed 's/^/        /'
      echo "   Fix the gitleaks config/invocation above and commit again."
      exit 1
    fi

    if printf '%s\n' "$GITLEAKS_OUTPUT" | grep -q 'no leaks found'; then
      # The scan demonstrably ran and found nothing, but there is no artifact to
      # prove it beyond this line. Reporting PASS from log wording is exactly what
      # #449 forbade, so this stays SKIP — and says WHY, which the old message did
      # not: without that, SKIP is indistinguishable from "tool missing".
      echo "     ⚠️  gitleaks scanned and reported no leaks, but wrote no report file"
      echo "        (${GITLEAKS_REPORT} missing). No artifact means no PASS (#449)."
      echo "     ⏭️  SKIPPED - secret scanning produced no artifact (scan reported clean)."
    else
      echo "     ⚠️  gitleaks exited 0 but produced no readable report and no scan summary"
      echo "     ⏭️  SKIPPED - secret scanning produced no evidence (not a pass)"
    fi
    GATE_8_STATUS="SKIP"
  else
    echo "     ❌ BLOCKED - gitleaks reported $GITLEAKS_FINDINGS finding(s)"
    echo "$GITLEAKS_OUTPUT"
    echo ""
    echo "Remediation: remove the secret, or allowlist a false positive in .gitleaks.toml."
    exit 1
  fi
elif [ "$GITLEAKS_EXIT" -eq 1 ]; then
  # #582: gitleaks exits 1 for BOTH "leaks found" and "I could not start" (unreadable
  # config, bad path, IO error). Treating every exit 1 as a finding produced the
  # loudest possible wrong answer: "Secrets detected in staged files", plus
  # instructions to rotate a key, on a repository where nothing had been scanned --
  # because WSL handed a POSIX path to the native binary (#582's own case).
  #
  # #592 established this distinction for exit 0 + FTL. The same test applies here,
  # and the order matters as much: a scanner that could not start must never be
  # reported as having found something, or the gate teaches people to disable it.
  if printf '%s\n' "$GITLEAKS_OUTPUT" | grep -qiE '(^|[[:space:]])(FTL|fatal error)[[:space:]:]|unable to load|cannot find the path'; then
    echo "     ❌ BLOCKED - ENVIRONMENT: gitleaks exited 1 because it could not start, so"
    echo "        NO secret scan took place. This is a tooling problem, not a verdict"
    echo "        about the staged code."
    printf '%s\n' "$GITLEAKS_OUTPUT" | grep -iE 'FTL|fatal|unable|cannot find' | head -3 | sed 's/^/        /'
    echo "   Fix the gitleaks config/invocation above and commit again."
    exit 1
  fi
  # Secrets found — output details
  echo "$GITLEAKS_OUTPUT"
  echo ""
  echo "     ❌ BLOCKED - Secrets detected in staged files."
  echo ""
  echo "Remediation options:"
  echo "  1. Remove the secret and use environment variables instead"
  echo "  2. Add a false positive to .gitleaks.toml allowlist"
  echo "  3. Use git secret or vault for sensitive data"
  echo ""
  echo "See: https://github.com/gitleaks/gitleaks"
  exit 1
else
  # fail-closed (#499): a non-0/1 exit (config error, crash) used to SKIP, which
  # let a broken scanner wave every commit through without any scan.
  echo "     ❌ BLOCKED - gitleaks exited with code $GITLEAKS_EXIT (fail-closed, #499)."
  echo "$GITLEAKS_OUTPUT"
  echo "   Secret scanning could not complete; fix the gitleaks error above and retry."
  exit 1
fi

# ---- detect-secrets（次要防线，基线比对）----
# detect-secrets-hook comes from the project's Python dev extra; it blocks only
# on secrets NOT yet registered in .secrets.baseline, so test-fixture dummy keys
# recorded in the baseline never trip it.
#
# The file list is piped NUL-delimited STRAIGHT into xargs -0 — never through a
# command substitution. `var=$(cmd -z)` strips every NUL byte (bash cannot hold
# NULs in a variable), which concatenated all filenames into one giant
# nonexistent path and would have BLOCKED every commit once a project shipped
# both detect-secrets-hook and .secrets.baseline. The pipeline lives inside an
# if-condition (errexit-exempt); a non-zero hook exit lands in the else branch.
if command -v detect-secrets-hook >/dev/null 2>&1 && [ -f ".secrets.baseline" ]; then
  # #735: normalize path separators BEFORE comparing against the baseline.
  # detect-secrets writes backslash paths on Windows and forward slashes on
  # Linux, and the baseline is committed, so the two forms fight: a Windows scan
  # rewrites ~322 lines, a Linux run rewrites them back, and every commit
  # carries a pure formatting diff. That destroys the only signal the baseline
  # has - "did a NEW secret appear" - because a real new entry no longer stands
  # out from churn. Normalizing HERE (not only in the repair hint) makes the
  # comparison see one canonical form regardless of which platform last touched
  # the file.
  #
  # Two traps had to be handled, both found by RUNNING it rather than reading it:
  #  (1) this script lives at different depths in the source tree
  #      (githooks/adapters/) and in the install (~/.config/xp-gate/adapters/), so
  #      a fixed ../../ silently resolved to nothing in the installed copy;
  #  (2) on Git Bash the resolved path is POSIX-style (/c/Users/...), and handing
  #      it to the native node.exe makes MSYS rewrite it into D:\c\Users\... -
  #      node then dies with MODULE_NOT_FOUND, which `|| true` swallowed. The
  #      gate looked patched and normalised nothing at all.
  # Hence: probe several layouts, then cygpath the winner to a Windows path.
  # Best-effort on purpose - a missing node or unparsable baseline must let the
  # hook speak, never abort the gate silently.
  ds_norm=""
  ds_here="$(dirname "${BASH_SOURCE[0]}")"
  for cand in       "$ds_here/../../scripts/normalize-secrets-baseline.cjs"       "$ds_here/../scripts/normalize-secrets-baseline.cjs"       "$XP_GATE_HOME/scripts/normalize-secrets-baseline.cjs"; do
    if [ -n "$cand" ] && [ -f "$cand" ]; then ds_norm="$cand"; break; fi
  done
  # Normalize a TEMP COPY, never the tracked file.
  #
  # The first version rewrote `.secrets.baseline` in place and did not re-stage
  # it, so the commit still carried the mixed-separator version (#735 relocated
  # rather than resolved) and every gated commit left a tracked file dirty for a
  # reason the user never asked for. Comparing against a normalized copy leaves
  # the working tree untouched and makes the guarantee unconditional: the
  # comparison always sees one canonical form, whether or not the committed
  # baseline is clean.
  DS_BASELINE=".secrets.baseline"
  # Every degradation path below prints WHY, including the two that are not
  # failures: a missing normalizer or a missing node used to fall through in
  # total silence, so the comparison ran on mixed separators and a resulting
  # BLOCK read as "found secrets" with no way to connect it to the real cause.
  # #735 is precisely about that mismatch, so it must never be invisible.
  if [ -z "$ds_norm" ]; then
    echo "     ⚠️  baseline normalizer not found (looked next to the hook, in"
    echo "         ../scripts and \$XP_GATE_HOME/scripts) — comparing with the"
    echo "         committed separators; Windows/Linux baselines may disagree."
  elif ! command -v node >/dev/null 2>&1; then
    echo "     ⚠️  node not found — cannot normalize the detect-secrets baseline;"
    echo "         comparing with the committed separators."
  else
    ds_norm_arg="$ds_norm"
    if command -v cygpath >/dev/null 2>&1; then
      ds_norm_arg="$(cygpath -w "$ds_norm" 2>/dev/null || printf '%s' "$ds_norm")"
    fi
    # The copy lives next to the original, not in $TMPDIR. Two different path
    # dialects consume this one path: node.exe is native and needs a Windows
    # form, while detect-secrets-hook is a Python script that resolves the path
    # itself and REJECTS the Windows form ("Invalid path"). A bare filename in
    # the current directory is the only spelling both accept, and it is also
    # what `git add`/`git status` see, so the file is unmistakably temporary.
    DS_BASELINE=".secrets.baseline.gate8.$$"
    # Register BEFORE creating it. Registering after a successful `cp` leaves a
    # window in which a signal or an errexit abort between the two lines leaves
    # the copy on disk with nothing tracking it — the trap only removes what it
    # knows about. rm -f on a name that was never created is a no-op, so the
    # early registration costs nothing.
    GATE8_TEMP+=("$DS_BASELINE")
    if ! cp .secrets.baseline "$DS_BASELINE" 2>/dev/null; then
      DS_BASELINE=".secrets.baseline"
    fi
    if [ "$DS_BASELINE" != ".secrets.baseline" ]; then
      # NOT `>/dev/null 2>&1 || true`: that swallowed exit 2 (unparsable JSON)
      # and any runtime throw, so the gate reported a clean comparison while the
      # copy had never been normalized — the same "looked patched, did nothing"
      # shape the path probing above exists to fix. A failure is now VISIBLE.
      # `if !` rather than `cmd; rc=$?` because the enclosing hook may run under
      # errexit, where a bare failing assignment would abort before the message
      # could print.
      if ! ds_norm_out="$(node "$ds_norm_arg" "$DS_BASELINE" 2>&1)"; then
        echo "     ⚠️  detect-secrets baseline NOT normalized; comparing with"
        echo "         whatever separators the committed file uses. Reason:"
        printf '%s
' "$ds_norm_out" | sed 's/^/           /'
      fi
    fi
  fi
  # The normalized copy and the hook output are both temp files. The first
  # version of this block removed neither DS_BASELINE (leaked one copy PER
  # gated commit) nor DS_TMP on the early `exit 1` paths. They are registered in
  # the global GATE8_TEMP list, which the EXIT trap installed at the top of this
  # file cleans up — a trap calling a function that reads a FUNCTION-LOCAL
  # variable sees an empty value at exit time, which is exactly how the first
  # fix attempt silently cleaned nothing.
  DS_TMP="$(dirname "$(mktemp -u)")/ds-output.$$"
  GATE8_TEMP+=("$DS_TMP")
  # #616: same scope split as the gitleaks call above. Under `--all` the index is
  # usually empty, so piping `git diff --cached -z` into xargs fed the hook zero
  # files and it reported success without reading anything.
  if [ "${GATE_SCOPE:-diff}" = "all" ]; then
    if git ls-files -z | xargs -0 detect-secrets-hook --baseline "$DS_BASELINE" > "$DS_TMP" 2>&1; then
      echo "     ✅ detect-secrets PASSED - no new secrets beyond baseline (scope: --all)."
    else
      cat "$DS_TMP"
      echo ""
      echo "     ❌ BLOCKED - detect-secrets found secrets not in .secrets.baseline."
      echo "   If these are false positives, mark them in the baseline:"
      echo "     detect-secrets scan --baseline .secrets.baseline && git add .secrets.baseline"
      echo "   (--update does not exist; detect-secrets exits with"
      echo "    \"unrecognized arguments: --update\".)"
      echo "   Then REVIEW the diff: scan --baseline re-scans the WHOLE tree, whereas"
      echo "   this gate only inspects changed files. A whole-tree scan can silently"
      echo "   drop the entries of files it no longer reaches, un-allowlisting a"
      echo "   historical finding. Commit the baseline alone so that stays visible."
      exit 1
    fi
  elif git diff --cached --name-only --diff-filter=ACM -z \
      | xargs -0 detect-secrets-hook --baseline "$DS_BASELINE" > "$DS_TMP" 2>&1; then
    echo "     ✅ detect-secrets PASSED - no new secrets beyond baseline."
  else
    cat "$DS_TMP"
    echo ""
    echo "     ❌ BLOCKED - detect-secrets found secrets not in .secrets.baseline."
    echo "   If these are false positives, mark them in the baseline:"
    echo "     detect-secrets scan --baseline .secrets.baseline && git add .secrets.baseline"
    echo "   (--update does not exist; detect-secrets exits with"
    echo "    \"unrecognized arguments: --update\".)"
    echo "   Then REVIEW the diff: scan --baseline re-scans the WHOLE tree, whereas"
    echo "   this gate only inspects changed files. A whole-tree scan can silently"
    echo "   drop the entries of files it no longer reaches, un-allowlisting a"
    echo "   historical finding. Commit the baseline alone so that stays visible."
    exit 1
  fi
  # Temp cleanup is owned by the gate8_cleanup trap; no rm here.
else
  # #793: this branch used to blame the tool unconditionally. Both "the hook is
  # not installed" and "the baseline file is missing" land here, so a repo with
  # detect-secrets 1.5.52 on PATH was told to run `pip install -e ".[dev]"` --
  # correct-looking advice that changes nothing, while the file actually missing
  # (the committed `.secrets.baseline`) was never named. The two have different
  # remedies and only one of them is an install, so they are split here.
  if command -v detect-secrets-hook >/dev/null 2>&1; then
    echo "     ⚠️  detect-secrets-hook is installed but .secrets.baseline is missing."
    echo "         Generate it once with: detect-secrets scan > .secrets.baseline"
    echo "         (gitleaks still ran.)"
  else
    echo "     ⚠️  detect-secrets-hook unavailable (install: pip install -e \".[dev]\") — gitleaks only."
  fi
fi

record_gate_audit "gate-8" "secret-scanning" "$GATE_8_STATUS" "0" "$GATE_8_START"
