service: artifacts, binhost: Correct chroot/sysroot paths for bundling

We shouldn't be joining or un-prefixing chroot.path; let chroot_lib do
the work.

Notes for CreateChromePackageIndexTest: CreateChromePackageIndex()
actually expects an inside-chroot path in its Sysroot() parameter (I
know, it's unclear how to use this class...), and does chroot_lib
translation on it. The lack of IsInsideChroot mocking meant that the
test would pass anyway, as chroot_lib skips the double-translation. In
other words, I'm fixing the mocking (so the test believes it's outside
the chroot, as the code is intended to run), and then fixing up the
inputs/expectations to match reality.

BUG=b:265885353
TEST=./run_tests

Change-Id: Id384f94db1cec9fb5dd89cd0a75d0ddfa608c120
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/4661949
Commit-Queue: Brian Norris <briannorris@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
Reviewed-by: Greg Edelston <gredelston@google.com>
diff --git a/api/controller/artifacts_unittest.py b/api/controller/artifacts_unittest.py
index 0185548..7520acb 100644
--- a/api/controller/artifacts_unittest.py
+++ b/api/controller/artifacts_unittest.py
@@ -702,9 +702,14 @@
     """BundleSimpleChromeArtifacts tests."""
 
     def setUp(self):
-        self.chroot_dir = os.path.join(self.tempdir, "chroot_dir")
+        self.PatchObject(cros_build_lib, "IsInsideChroot", return_value=False)
+
+        self.chroot = chroot_lib.Chroot(
+            path=self.tempdir / "chroot",
+            out_path=self.tempdir / "out",
+        )
         self.sysroot_path = "/sysroot"
-        self.sysroot_dir = os.path.join(self.chroot_dir, "sysroot")
+        self.sysroot_dir = self.chroot.full_path(self.sysroot_path)
         osutils.SafeMakedirs(self.sysroot_dir)
         self.output_dir = os.path.join(self.tempdir, "output_dir")
         osutils.SafeMakedirs(self.output_dir)
@@ -715,7 +720,7 @@
 
     def _GetRequest(
         self,
-        chroot: Optional[str] = None,
+        chroot: Optional[chroot_lib.Chroot] = None,
         sysroot: Optional[str] = None,
         build_target: Optional[str] = None,
         output_dir: Optional[str] = None,
@@ -730,7 +735,10 @@
         """
         return artifacts_pb2.BundleRequest(
             sysroot={"path": sysroot, "build_target": {"name": build_target}},
-            chroot={"path": chroot},
+            chroot={
+                "path": chroot.path if chroot else None,
+                "out_path": str(chroot.out_path) if chroot else None,
+            },
             output_dir=output_dir,
         )
 
@@ -738,7 +746,7 @@
         """Quick check that a validate only call does not execute any logic."""
         patch = self.PatchObject(artifacts_svc, "BundleSimpleChromeArtifacts")
         request = self._GetRequest(
-            chroot=self.chroot_dir,
+            chroot=self.chroot,
             sysroot=self.sysroot_path,
             build_target="board",
             output_dir=self.output_dir,
@@ -752,7 +760,7 @@
         """Test a mock call does not execute logic, returns mocked value."""
         patch = self.PatchObject(artifacts_svc, "BundleSimpleChromeArtifacts")
         request = self._GetRequest(
-            chroot=self.chroot_dir,
+            chroot=self.chroot,
             sysroot=self.sysroot_path,
             build_target="board",
             output_dir=self.output_dir,
@@ -770,7 +778,7 @@
     def testNoBuildTarget(self):
         """Test no build target fails."""
         request = self._GetRequest(
-            chroot=self.chroot_dir,
+            chroot=self.chroot,
             sysroot=self.sysroot_path,
             output_dir=self.output_dir,
         )
@@ -807,7 +815,7 @@
     def testNoOutputDir(self):
         """Test no output dir fails."""
         request = self._GetRequest(
-            chroot=self.chroot_dir,
+            chroot=self.chroot,
             sysroot=self.sysroot_path,
             build_target="board",
         )
@@ -820,7 +828,7 @@
     def testOutputDirDoesNotExist(self):
         """Test no output dir fails."""
         request = self._GetRequest(
-            chroot=self.chroot_dir,
+            chroot=self.chroot,
             sysroot=self.sysroot_path,
             build_target="board",
             output_dir=self.does_not_exist,
@@ -841,7 +849,7 @@
             return_value=expected_files,
         )
         request = self._GetRequest(
-            chroot=self.chroot_dir,
+            chroot=self.chroot,
             sysroot=self.sysroot_path,
             build_target="board",
             output_dir=self.output_dir,