In `BuildIntegrationTestCase`, permit writing utf-8 file contents and ensure all path strings are encoded as latin-1 to keep the test framework consistent with `NativePosixFiles`.

PiperOrigin-RevId: 436564775
diff --git a/src/test/java/com/google/devtools/build/lib/buildtool/util/BuildIntegrationTestCase.java b/src/test/java/com/google/devtools/build/lib/buildtool/util/BuildIntegrationTestCase.java
index 6ea3c4a..071fd93 100644
--- a/src/test/java/com/google/devtools/build/lib/buildtool/util/BuildIntegrationTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/buildtool/util/BuildIntegrationTestCase.java
@@ -14,12 +14,15 @@
 
 package com.google.devtools.build.lib.buildtool.util;
 
+import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.base.Throwables.throwIfUnchecked;
 import static com.google.common.collect.ImmutableSet.toImmutableSet;
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.common.truth.Truth.assertWithMessage;
+import static java.nio.charset.StandardCharsets.ISO_8859_1;
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.fail;
 
@@ -788,7 +791,8 @@
   }
 
   /**
-   * Writes a number of lines of text to a source file using Latin-1 encoding.
+   * Writes a number of lines of text to a source file using {@link
+   * java.nio.charset.StandardCharsets#UTF_8} encoding.
    *
    * @param relativePath the path relative to the workspace root.
    * @param lines the lines of text to write to the file.
@@ -804,7 +808,14 @@
    * Same as {@link #write}, but with an absolute path.
    */
   protected Path writeAbsolute(Path path, String... lines) throws IOException {
-    FileSystemUtils.writeIsoLatin1(path, lines);
+    // Check that the path string encoding matches what is returned by NativePosixFiles. Otherwise,
+    // tests may lose fidelity.
+    String pathStr = path.getPathString();
+    checkArgument(
+        pathStr.equals(new String(pathStr.getBytes(ISO_8859_1), ISO_8859_1)),
+        "Path strings must be encoded as latin-1: %s",
+        path);
+    FileSystemUtils.writeLinesAs(path, UTF_8, lines);
     return path;
   }