buildapi: Implement ArtifactsService/FetchMetadata

The logic for finding metadata files previously lived at
src/platform/dev/copy_metadata.sh. This CL moves that logic to the build
API.

Note that we don't actually consider whether the files exist; we just
return the raw paths. We might decide later that it would be useful to
only return paths that actually exist.

For now we only have test metadata files, because that's what we used in
the aforementioned copy_metadata.sh. It is expected that build metadata
files will be added to this implementation.

Opportunitistically, I've also added a bit of go/inclusive-language
cleanup for "sanity check".

BUG=b:188705539
TEST=Run build_api CLI with new endpoint; inspect output.
inspect output.
TEST=./run_tests api/controller/artifacts_service_unittest.py
lib/sysroot_lib_unittest.py service/test_unittest.py

Change-Id: Id11d863de3d0cd299a664a350888543e5a360158
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/3089480
Tested-by: Greg Edelston <gredelston@google.com>
Auto-Submit: Greg Edelston <gredelston@google.com>
Commit-Queue: Greg Edelston <gredelston@google.com>
Reviewed-by: Alex Klein <saklein@chromium.org>
diff --git a/api/controller/artifacts.py b/api/controller/artifacts.py
index 7649ef1..c6ae2a4 100644
--- a/api/controller/artifacts.py
+++ b/api/controller/artifacts.py
@@ -23,6 +23,7 @@
 from chromite.lib import cros_build_lib
 from chromite.lib import sysroot_lib
 from chromite.service import artifacts
+from chromite.service import test
 
 
 class RegisteredGet(NamedTuple):
@@ -366,6 +367,37 @@
   pass
 
 
+def _FetchMetadataResponse(_input_proto, output_proto, _config):
+  """Populate the output_proto with sample data."""
+  for fp in ('/metadata/foo.txt', '/metadata/bar.jsonproto'):
+    output_proto.filepaths.add(path=common_pb2.Path(
+        path=fp, location=common_pb2.Path.OUTSIDE))
+  return controller.RETURN_CODE_SUCCESS
+
+
+@faux.success(_FetchMetadataResponse)
+@faux.empty_error
+@validate.exists('chroot.path')
+@validate.require('sysroot.path')
+@validate.validation_complete
+def FetchMetadata(input_proto, output_proto, _config):
+  """FetchMetadata returns the paths to all build/test metadata files.
+
+  This implements ArtifactsService.FetchMetadata.
+
+  Args:
+    input_proto (FetchMetadataRequest): The input proto.
+    output_proto (FetchMetadataResponse): The output proto.
+    config (api_config.ApiConfig): The API call config.
+  """
+  chroot = controller_util.ParseChroot(input_proto.chroot)
+  sysroot = controller_util.ParseSysroot(input_proto.sysroot)
+  for path in test.FindAllMetadataFiles(chroot, sysroot):
+    output_proto.filepaths.add(
+        path=common_pb2.Path(path=path, location=common_pb2.Path.OUTSIDE))
+  return controller.RETURN_CODE_SUCCESS
+
+
 def _BundleFirmwareResponse(input_proto, output_proto, _config):
   """Add test firmware image files to a successful response."""
   output_proto.artifacts.add().path = os.path.join(