[embedder] More workflow improvements.

- Support --goma and --no-prebuilt-dart-sdk in engine build
  scripts. This enables testing Dart SDK changes with the embedder.
- Use ninja and autoninja from $PATH instead of $DEPOT_TOOLS.
  This matches how other repos' workflow works, so it saves an extra
  step for devs that already have ninja and autoninja on their PATH.
- Enforce environment requirements at the beginning of each script,
  giving more clear error messages when they're not met.
- Add scripts to locally test the workflows, making it safer to
  do larger changes to the scripts.

Tested: Ran new workflow test scripts.
Change-Id: I6b17d89754688f86dc709f19e10b0429aca07ff4
diff --git a/README.md b/README.md
index 23b9deb..30d3b82 100644
--- a/README.md
+++ b/README.md
@@ -84,9 +84,13 @@
 2. Set `$ENGINE_DIR` to the `src` folder of your Flutter Engine checkout location,
    for example `~/engine/src`.
 
-3. `$DEPOT_TOOLS` should be set to your
-    [`depot_tools`](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up)
-    location, for example `~/depot_tools`.
+3. You will need to install 
+   [`depot_tools`](https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up)
+   and add it to your `PATH`.
+
+   ```sh
+   export PATH=$HOME/depot_tools:$PATH
+   ```
 
 4. For `sync_engine_artifacts_to_revision.sh`, you will need to `git stash` or `git commit` any local
    changes to the Flutter Engine. This is not necesssary for `build_and_copy_engine_artifacts.sh`.
diff --git a/hooks/post-checkout b/hooks/post-checkout
index 62367ae..c7e1fdf 100755
--- a/hooks/post-checkout
+++ b/hooks/post-checkout
@@ -4,7 +4,7 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/echo_helpers.sh || exit $?
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/helpers.sh || exit $?
 
 # Check if sdk-integration has changed.
 # If it has, the SDK version has changed for the
diff --git a/hooks/pre-commit b/hooks/pre-commit
index fcc899c..b1668eb 100755
--- a/hooks/pre-commit
+++ b/hooks/pre-commit
@@ -4,7 +4,7 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/echo_helpers.sh || exit $?
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/helpers.sh || exit $?
 
 echo-info "Formatting C++ code using clang-format..."
 clang_format="${FUCHSIA_EMBEDDER_DIR}"/bazel-flutter-embedder/external/fuchsia_clang/bin/clang-format
diff --git a/scripts/README.md b/scripts/README.md
new file mode 100644
index 0000000..1d4700b
--- /dev/null
+++ b/scripts/README.md
@@ -0,0 +1,35 @@
+# Workflow scripts
+
+This folder contains several scripts for handling common workflows
+in the embedder directory.
+
+Each script in `//scripts` should be runnable following instructions
+documented at the top of the script. Helper variables and functions should
+go under `//scripts/lib/` instead.
+
+## Testing changes
+
+**Because some of these workflows involve mutating the state of this
+repository and other repositories like the Flutter Engine repository,
+we recommend backing up your local changes first before running these tests.**
+
+To locally verify that common workflows are still working
+correctly after changes to the scripts, run:
+
+```sh
+$FUCHSIA_EMBEDDER_DIR/scripts/tests/run_all.sh
+```
+
+This will run all scripts called `tests/*_test.sh`, testing various workflows and
+failing at the first error.
+
+You can also run local tests for a specific workflow script by running the corresponding
+`*_test.sh` script. For example:
+
+```sh
+$FUCHSIA_EMBEDDER_DIR/scripts/tests/bootstrap_test.sh
+```
+
+Because these workflow tests make frequent calls to the internet, they do not run on CQ.
+If you're interested in running workflow tests on CQ, see https://fxrev.dev/735770
+for a WIP prototype of testing the workflows using Bazel.
\ No newline at end of file
diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh
index 5238ce3..b29d5b5 100755
--- a/scripts/bootstrap.sh
+++ b/scripts/bootstrap.sh
@@ -8,20 +8,11 @@
 #
 # Usage:
 #   bootstrap.sh
-#
-# Requirements:
-#   1. $FUCHSIA_EMBEDDER_DIR is set to your flutter-embedder.git checkout.
 
 set -e # Fail on any error.
-source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/echo_helpers.sh || exit $?
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/helpers.sh || exit $?
 
-if [[ -z $FUCHSIA_EMBEDDER_DIR ]]
-then
-  echo-error '$FUCHSIA_EMBEDDER_DIR must be set to your flutter-embedder folder before running this script.'
-  echo-error 'Add this line to your shell profile:'
-  echo-error "export FUCHSIA_EMBEDDER_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && cd .. && pwd)"
-  exit 1
-fi
+ensure-embedder-dir
 
 # bootstrap_bazel.sh fails quietly if run outside the Bazel workspace.
 pushd $FUCHSIA_EMBEDDER_DIR
diff --git a/scripts/build_and_copy_engine_artifacts.sh b/scripts/build_and_copy_engine_artifacts.sh
index 1157a54..1247d1d 100755
--- a/scripts/build_and_copy_engine_artifacts.sh
+++ b/scripts/build_and_copy_engine_artifacts.sh
@@ -10,18 +10,45 @@
 # Usage:
 #   build_and_copy_engine_artifacts.sh
 #
-# Requirements:
-#   1. $ENGINE_DIR is set to the src/ directory of your flutter/engine checkout.
-#   2. $FUCHSIA_EMBEDDER_DIR is set to your flutter-embedder.git checkout.
-#   3. $DEPOT_TOOLS is set to your depot_tools directory.
+# Arguments:
+#   --goma: Uses goma to accelerate the Flutter Engine build.
+#           For Googlers only, sorry. :(
+#
+# All other arguments are forwarded to Flutter Engine's GN.
 
 set -e # Fail on any error.
-source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/echo_helpers.sh || exit $?
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/helpers.sh || exit $?
+
+ensure-engine-dir
+ensure-ninja
+
+# Parse arguments.
+goma=0
+goma_flags=""
+ninja_cmd="ninja"
+extra_gn_args=()
+while [[ $# -gt 0 ]]; do
+  case $1 in
+    --goma)
+      goma=1
+      goma_flags="--goma"
+      ninja_cmd="autoninja"
+      shift # past argument
+      ;;
+    *)
+      extra_gn_args+=("$1") # forward argument
+      shift # past argument
+      ;;
+  esac
+done
+
+all_gn_args="--fuchsia --embedder-for-target --unopt ${goma_flags} ${extra_gn_args[@]}"
 
 echo-info "Building the debug Flutter Engine embedding for Fuchsia (libflutter_engine.so)..."
-"${ENGINE_DIR}"/flutter/tools/gn --fuchsia --embedder-for-target --unopt
+echo-info "... GN args: ${all_gn_args}"
+"${ENGINE_DIR}"/flutter/tools/gn ${all_gn_args}
 debug_out_dir="${ENGINE_DIR}"/out/fuchsia_debug_unopt_x64
-"${DEPOT_TOOLS}"/ninja -C "${debug_out_dir}"
+${ninja_cmd} -C "${debug_out_dir}"
 
 echo-info "Copying debug Flutter Engine artifacts to ${FUCHSIA_EMBEDDER_DIR}/src/embedder/engine/debug_x64..."
 cp "${debug_out_dir}"/libflutter_engine.so "${FUCHSIA_EMBEDDER_DIR}"/src/embedder/engine/debug_x64/libflutter_engine.so
diff --git a/scripts/build_and_run_example.sh b/scripts/build_and_run_example.sh
index 82a3e86..b060068 100755
--- a/scripts/build_and_run_example.sh
+++ b/scripts/build_and_run_example.sh
@@ -7,14 +7,15 @@
 #   build_and_run_example.sh <name_of_dir_in_examples>
 #
 # Requirements:
-#   1. $FUCHSIA_EMBEDDER_DIR is set to your flutter-embedder.git checkout directory.
-#   2. You are currently running Workstation (`ffx emu start --headless workstation_eng.qemu-x64`).
-#   3. The example folder must contain a package target named `<example>_pkg`.
+#   1. You are currently running Workstation (`ffx emu start --headless workstation_eng.qemu-x64`).
+#   2. The example folder must contain a fuchsia_package target named `<example>_pkg`.
 #
 # TODO(akbiggs): Port this workflow to Bazel.
 
 set -e # Fail on any error.
-source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/echo_helpers.sh || exit $?
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/helpers.sh || exit $?
+
+ensure-embedder-dir
 
 far_debug_dir=/tmp/"${app_name}"_far_contents
 far_tool="${FUCHSIA_EMBEDDER_DIR}"/bazel-flutter-embedder/external/fuchsia_sdk/tools/x64/far
diff --git a/scripts/install_hooks.sh b/scripts/install_hooks.sh
index 4be27c8..7de0d3f 100755
--- a/scripts/install_hooks.sh
+++ b/scripts/install_hooks.sh
@@ -8,16 +8,18 @@
 #
 # Usage:
 #   install_hooks.sh
-#
-# Requirements:
-#   1. $FUCHSIA_EMBEDDER_DIR is set to your flutter-embedder.git checkout.
+
+set -e # Fail on any error.
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/helpers.sh || exit $?
+
+ensure-embedder-dir
 
 # Ensure the hooks were marked executable before copying them over,
 # or git will fail to execute them.
 chmod +x $FUCHSIA_EMBEDDER_DIR/hooks/*
 
 # Install dependency for the hooks.
-cp $FUCHSIA_EMBEDDER_DIR/scripts/lib/echo_helpers.sh $FUCHSIA_EMBEDDER_DIR/.git/hooks/echo_helpers.sh
+cp $FUCHSIA_EMBEDDER_DIR/scripts/lib/helpers.sh $FUCHSIA_EMBEDDER_DIR/.git/hooks/helpers.sh
 
 # Install the post-checkout hook for checkout, merge and rebase.
 cp $FUCHSIA_EMBEDDER_DIR/hooks/post-checkout $FUCHSIA_EMBEDDER_DIR/.git/hooks/post-checkout
diff --git a/scripts/lib/echo_helpers.sh b/scripts/lib/echo_helpers.sh
deleted file mode 100644
index 49df823..0000000
--- a/scripts/lib/echo_helpers.sh
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/bash
-#
-# Copyright 2022 The Fuchsia Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-# Returns true if colors are supported.
-function is-stderr-tty {
-  [[ -t 2 ]]
-}
-
-# echo-info prints a line to stderr with a green INFO: prefix.
-function echo-info {
-  if is-stderr-tty; then
-    echo -e >&2 "\033[1;32mINFO:\033[0m $*"
-  else
-    echo -e >&2 "INFO: $*"
-  fi
-}
-
-# echo-warning prints a line to stderr with a yellow WARNING: prefix.
-function echo-warning {
-  if is-stderr-tty; then
-    echo -e >&2 "\033[1;33mWARNING:\033[0m $*"
-  else
-    echo -e >&2 "WARNING: $*"
-  fi
-}
-
-# echo-error prints a line to stderr with a red ERROR: prefix.
-function echo-error {
-  if is-stderr-tty; then
-    echo -e >&2 "\033[1;31mERROR:\033[0m $*"
-  else
-    echo -e >&2 "ERROR: $*"
-  fi
-}
diff --git a/scripts/lib/helpers.sh b/scripts/lib/helpers.sh
new file mode 100644
index 0000000..54a4890
--- /dev/null
+++ b/scripts/lib/helpers.sh
@@ -0,0 +1,62 @@
+#!/bin/bash
+#
+# Copyright 2022 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# Returns true if colors are supported.
+function is-stderr-tty {
+  [[ -t 2 ]]
+}
+
+# echo-info prints a line to stderr with a green INFO: prefix.
+function echo-info {
+  if is-stderr-tty; then
+    echo -e >&2 "\033[1;32mINFO:\033[0m $*"
+  else
+    echo -e >&2 "INFO: $*"
+  fi
+}
+
+# echo-warning prints a line to stderr with a yellow WARNING: prefix.
+function echo-warning {
+  if is-stderr-tty; then
+    echo -e >&2 "\033[1;33mWARNING:\033[0m $*"
+  else
+    echo -e >&2 "WARNING: $*"
+  fi
+}
+
+# echo-error prints a line to stderr with a red ERROR: prefix.
+function echo-error {
+  if is-stderr-tty; then
+    echo -e >&2 "\033[1;31mERROR:\033[0m $*"
+  else
+    echo -e >&2 "ERROR: $*"
+  fi
+}
+
+function ensure-embedder-dir {
+  if [[ -z "${FUCHSIA_EMBEDDER_DIR}" ]]; then
+    echo-error '$FUCHSIA_EMBEDDER_DIR must be set to your flutter-embedder folder before running this script.'
+    echo-error 'Add this line to your shell profile:'
+    echo-error "export FUCHSIA_EMBEDDER_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && cd .. && pwd)"
+    exit 1
+  fi
+}
+
+function ensure-engine-dir {
+  if [[ -z "${ENGINE_DIR}" ]]; then
+    echo-error '$ENGINE_DIR must be set to the src/ folder of your Flutter Engine checkout before running this script.'
+    echo-error 'For example if your Flutter Engine checkout is $HOME/engine, add this line to your shell profile:'
+    echo-error 'export ENGINE_DIR=$HOME/engine/src'
+    exit 1
+  fi
+}
+
+function ensure-ninja {
+  if ! [ -x "$(command -v ninja)" ]; then
+    echo-error '`ninja` is not in your $PATH. Do you have depot_tools installed and in your $PATH? https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up'
+    exit 1
+  fi
+}
diff --git a/scripts/sync_engine_artifacts_to_revision.sh b/scripts/sync_engine_artifacts_to_revision.sh
index c1a63c8..a4e1f80 100755
--- a/scripts/sync_engine_artifacts_to_revision.sh
+++ b/scripts/sync_engine_artifacts_to_revision.sh
@@ -12,13 +12,17 @@
 #   sync_engine_artifacts_to_commit.sh <engine_commit>
 #
 # Requirements:
-#   1. $ENGINE_DIR is set to the src/ directory of your flutter/engine checkout.
-#   2. $FUCHSIA_EMBEDDER_DIR is set to your flutter-embedder.git checkout.
-#   3. $DEPOT_TOOLS is set to your depot_tools directory.
-#   4. You don't have any uncommited changes to your Engine code.
+#   1. You don't have any uncommited changes to your Engine code.
+#
+# Arguments:
+#   The first argument is the Flutter Engine commit to sync to.
+#   All other arguments are forwarded to build_and_copy_engine_artifacts.sh.
 
 set -e # Fail on any error.
-source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/echo_helpers.sh || exit $?
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/helpers.sh || exit $?
+
+ensure-embedder-dir
+ensure-engine-dir
 
 engine_revision=$1
 
@@ -82,7 +86,8 @@
 
 # Build and copy over the artifacts we need and update our
 # revision.
-"${FUCHSIA_EMBEDDER_DIR}"/scripts/build_and_copy_engine_artifacts.sh
+shift # so "$@" doesn't include the engine revision
+"${FUCHSIA_EMBEDDER_DIR}"/scripts/build_and_copy_engine_artifacts.sh "$@"
 echo "${engine_revision}" > "${FUCHSIA_EMBEDDER_DIR}"/src/embedder/engine/engine_revision
 
 echo-info "Done! Engine artifacts updated to ${engine_revision}."
diff --git a/scripts/tests/bootstrap_test.sh b/scripts/tests/bootstrap_test.sh
new file mode 100755
index 0000000..f5e400b
--- /dev/null
+++ b/scripts/tests/bootstrap_test.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+#
+# Copyright 2022 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# Runs local tests for scripts/bootstrap.sh. Not runnable on CQ.
+#
+# Usage:
+#   $FUCHSIA_EMBEDDER_DIR/scripts/tests/bootstrap_test.sh
+
+set -e # Fail on any error.
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../lib/helpers.sh || exit $?
+
+echo-info 'Testing bootstrap.sh from $FUCHSIA_EMBEDDER_DIR ...'
+pushd $FUCHSIA_EMBEDDER_DIR
+$FUCHSIA_EMBEDDER_DIR/scripts/bootstrap.sh
+popd  # $FUCHSIA_EMBEDDER_DIR
+
+echo-info 'Testing bootstrap.sh from $HOME ...'
+pushd $HOME
+$FUCHSIA_EMBEDDER_DIR/scripts/bootstrap.sh
+popd  # $HOME 
\ No newline at end of file
diff --git a/scripts/tests/build_and_copy_engine_artifacts_test.sh b/scripts/tests/build_and_copy_engine_artifacts_test.sh
new file mode 100755
index 0000000..7c4d77f
--- /dev/null
+++ b/scripts/tests/build_and_copy_engine_artifacts_test.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+#
+# Copyright 2022 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# Runs local tests for scripts/build_and_copy_engine_artifacts.sh. Not runnable on CQ.
+#
+# Usage:
+#   $FUCHSIA_EMBEDDER_DIR/scripts/tests/build_and_copy_engine_artifacts_test.sh
+
+set -e # Fail on any error.
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../lib/helpers.sh || exit $?
+
+pushd $FUCHSIA_EMBEDDER_DIR
+
+echo-info 'Testing build_and_copy_engine_artifacts.sh from $FUCHSIA_EMBEDDER_DIR ...'
+$FUCHSIA_EMBEDDER_DIR/scripts/build_and_copy_engine_artifacts.sh
+
+echo-info 'Testing build_and_copy_engine_artifacts.sh --goma ...'
+$FUCHSIA_EMBEDDER_DIR/scripts/build_and_copy_engine_artifacts.sh --goma
+
+echo-info 'Testing build_and_copy_engine_artifacts.sh --no-prebuilt-dart-sdk ...'
+$FUCHSIA_EMBEDDER_DIR/scripts/build_and_copy_engine_artifacts.sh --no-prebuilt-dart-sdk
+
+popd  # $FUCHSIA_EMBEDDER_DIR
+
+echo-info 'Testing build_and_copy_engine_artifacts.sh from $HOME ...'
+pushd $HOME
+$FUCHSIA_EMBEDDER_DIR/scripts/build_and_copy_engine_artifacts.sh
+popd  # $HOME 
+ 
\ No newline at end of file
diff --git a/scripts/tests/install_hooks_test.sh b/scripts/tests/install_hooks_test.sh
new file mode 100755
index 0000000..9c45a52
--- /dev/null
+++ b/scripts/tests/install_hooks_test.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+#
+# Copyright 2022 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# Runs local tests for scripts/install_hooks.sh. Not runnable on CQ.
+#
+# Usage:
+#   $FUCHSIA_EMBEDDER_DIR/scripts/tests/install_hooks_test.sh
+
+set -e # Fail on any error.
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../lib/helpers.sh || exit $?
+
+echo-info 'Testing install_hooks.sh from $FUCHSIA_EMBEDDER_DIR ...'
+pushd $FUCHSIA_EMBEDDER_DIR
+$FUCHSIA_EMBEDDER_DIR/scripts/install_hooks.sh
+popd  # $FUCHSIA_EMBEDDER_DIR
+
+echo-info 'Testing install_hooks.sh from $HOME ...'
+pushd $HOME
+$FUCHSIA_EMBEDDER_DIR/scripts/install_hooks.sh
+popd  # $HOME 
\ No newline at end of file
diff --git a/scripts/tests/run_all.sh b/scripts/tests/run_all.sh
new file mode 100755
index 0000000..9eac438
--- /dev/null
+++ b/scripts/tests/run_all.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+#
+# Copyright 2022 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# Runs local tests for all workflow scripts. Not runnable on CQ.
+#
+# Usage:
+#   $FUCHSIA_EMBEDDER_DIR/scripts/tests/run_all.sh
+
+set -e # Fail on any error.
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../lib/helpers.sh || exit $?
+
+for test in ${FUCHSIA_EMBEDDER_DIR}/scripts/tests/*_test.sh
+do
+  echo-info "Running $test ..."
+  $test
+done
\ No newline at end of file
diff --git a/scripts/tests/sync_engine_artifacts_to_revision_test.sh b/scripts/tests/sync_engine_artifacts_to_revision_test.sh
new file mode 100755
index 0000000..87f1837
--- /dev/null
+++ b/scripts/tests/sync_engine_artifacts_to_revision_test.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+#
+# Copyright 2022 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# Runs local tests for scripts/sync_engine_artifacts_to_revision.sh. Not runnable on CQ.
+#
+# Usage:
+#   $FUCHSIA_EMBEDDER_DIR/scripts/tests/sync_engine_artifacts_to_revision_test.sh
+
+set -e # Fail on any error.
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../lib/helpers.sh || exit $?
+
+pushd $FUCHSIA_EMBEDDER_DIR
+
+current_flutter_engine_revision=$(cat $FUCHSIA_EMBEDDER_DIR/third_party/dart-pkg/internal/flutter/flutter/bin/internal/engine.version)
+
+echo-info 'Testing sync_engine_artifacts_to_revision.sh from $FUCHSIA_EMBEDDER_DIR ...'
+$FUCHSIA_EMBEDDER_DIR/scripts/sync_engine_artifacts_to_revision.sh $current_flutter_engine_revision
+
+echo-info 'Testing sync_engine_artifacts_to_revision.sh --goma ...'
+$FUCHSIA_EMBEDDER_DIR/scripts/sync_engine_artifacts_to_revision.sh $current_flutter_engine_revision --goma
+
+echo-info 'Testing sync_engine_artifacts_to_revision.sh --no-prebuilt-dart-sdk ...'
+$FUCHSIA_EMBEDDER_DIR/scripts/sync_engine_artifacts_to_revision.sh $current_flutter_engine_revision --no-prebuilt-dart-sdk
+
+popd  # $FUCHSIA_EMBEDDER_DIR
+
+echo-info 'Testing sync_engine_artifacts_to_revision.sh from $HOME ...'
+pushd $HOME
+$FUCHSIA_EMBEDDER_DIR/scripts/sync_engine_artifacts_to_revision.sh $current_flutter_engine_revision
+popd  # $HOME 
\ No newline at end of file
diff --git a/scripts/tests/update_fuchsia_sdk_test.sh b/scripts/tests/update_fuchsia_sdk_test.sh
new file mode 100755
index 0000000..ca49d4c
--- /dev/null
+++ b/scripts/tests/update_fuchsia_sdk_test.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+#
+# Copyright 2022 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# Runs local tests for scripts/update_fuchsia_sdk.sh. Not runnable on CQ.
+#
+# Usage:
+#   $FUCHSIA_EMBEDDER_DIR/scripts/tests/update_fuchsia_sdk_test.sh
+
+set -e # Fail on any error.
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/../lib/helpers.sh || exit $?
+
+echo-info 'Testing update_fuchsia_sdk.sh --no-version-bump --cleanup from $FUCHSIA_EMBEDDER_DIR ...'
+pushd $FUCHSIA_EMBEDDER_DIR
+$FUCHSIA_EMBEDDER_DIR/scripts/update_fuchsia_sdk.sh --no-version-bump --cleanup
+popd  # $FUCHSIA_EMBEDDER_DIR
+
+echo-info 'Testing update_fuchsia_sdk.sh --no-version-bump --cleanup from $HOME ...'
+pushd $HOME
+$FUCHSIA_EMBEDDER_DIR/scripts/update_fuchsia_sdk.sh --no-version-bump --cleanup
+popd  # $HOME 
\ No newline at end of file
diff --git a/scripts/update_dependencies.sh b/scripts/update_dependencies.sh
index ce62e1f..5da453d 100755
--- a/scripts/update_dependencies.sh
+++ b/scripts/update_dependencies.sh
@@ -11,15 +11,14 @@
 # Usage:
 #   update_dependencies.sh
 #
-# Requirements:
-#   1. $FUCHSIA_EMBEDDER_DIR is set to your flutter-embedder.git checkout.
-#
 # Arguments:
 #   --cleanup: Removes old product bundles and shuts down old emulators.
 #              Default: false
 
 set -e # Fail on any error.
-source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/echo_helpers.sh || exit $?
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/helpers.sh || exit $?
+
+ensure-embedder-dir
 
 # Parse arguments.
 cleanup_args=
diff --git a/scripts/update_fuchsia_sdk.sh b/scripts/update_fuchsia_sdk.sh
index be43bf7..26e20ef 100755
--- a/scripts/update_fuchsia_sdk.sh
+++ b/scripts/update_fuchsia_sdk.sh
@@ -10,9 +10,6 @@
 # Usage:
 #   update_fuchsia_sdk.sh
 #
-# Requirements:
-#   1. $FUCHSIA_EMBEDDER_DIR is set to your flutter-embedder.git checkout.
-#
 # Arguments:
 #    --cleanup: Removes old product bundles and shuts down old emulators.
 #               Default: false
@@ -21,7 +18,9 @@
 #                       Default: false
 
 set -e # Fail on any error.
-source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/echo_helpers.sh || exit $?
+source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/helpers.sh || exit $?
+
+ensure-embedder-dir
 
 # Parse arguments.
 cleanup=0