Copilot commented on code in PR #49996:
URL: https://github.com/apache/arrow/pull/49996#discussion_r3510139233


##########
r/R/arrow-package.R:
##########
@@ -183,19 +190,35 @@ configure_tzdb <- function() {
     tryCatch(
       {
         tzdb::tzdb_initialize()
-        set_timezone_database(tzdb::tzdb_path("text"))
+        tz_path <- tzdb::tzdb_path("text")
+        packageStartupMessage("[configure_tzdb] tzdb path: ", tz_path)
+        packageStartupMessage("[configure_tzdb] path exists: ", 
dir.exists(tz_path))
+        if (dir.exists(tz_path)) {
+          tz_files <- list.files(tz_path, recursive = TRUE)

Review Comment:
   `configure_tzdb()` now emits several debug-style `packageStartupMessage()` 
lines and does a recursive `list.files()` over the tzdb directory at package 
load. This is user-visible noise and can be expensive (especially in 
constrained Wasm environments). Consider reverting to the previous behavior (no 
success-path logging / no directory enumeration).



##########
r/R/arrow-package.R:
##########
@@ -183,19 +190,35 @@ configure_tzdb <- function() {
     tryCatch(
       {
         tzdb::tzdb_initialize()
-        set_timezone_database(tzdb::tzdb_path("text"))
+        tz_path <- tzdb::tzdb_path("text")
+        packageStartupMessage("[configure_tzdb] tzdb path: ", tz_path)
+        packageStartupMessage("[configure_tzdb] path exists: ", 
dir.exists(tz_path))
+        if (dir.exists(tz_path)) {
+          tz_files <- list.files(tz_path, recursive = TRUE)
+          packageStartupMessage(
+            "[configure_tzdb] tzdb contents (",
+            length(tz_files),
+            " files): ",
+            paste(head(tz_files, 10), collapse = ", "),
+            if (length(tz_files) > 10) "..."
+          )
+        }
+        set_timezone_database(tz_path)
+        packageStartupMessage("[configure_tzdb] successfully configured 
timezone database")
       },
       error = function(e) {
         packageStartupMessage(
-          "The tzdb package was available but failed to initialize: ",
-          e,
+          "[configure_tzdb] tzdb package available but failed to initialize: ",
+          conditionMessage(e)
+        )

Review Comment:
   The startup message in the tzdb initialization error path was changed to a 
debug-style prefix ("[configure_tzdb] …"). This becomes part of Arrow's 
user-facing attach/load output; consider keeping the message user-oriented 
while still using `conditionMessage(e)`.



##########
r/R/arrow-package.R:
##########
@@ -183,19 +190,35 @@ configure_tzdb <- function() {
     tryCatch(
       {
         tzdb::tzdb_initialize()
-        set_timezone_database(tzdb::tzdb_path("text"))
+        tz_path <- tzdb::tzdb_path("text")
+        packageStartupMessage("[configure_tzdb] tzdb path: ", tz_path)
+        packageStartupMessage("[configure_tzdb] path exists: ", 
dir.exists(tz_path))
+        if (dir.exists(tz_path)) {
+          tz_files <- list.files(tz_path, recursive = TRUE)
+          packageStartupMessage(
+            "[configure_tzdb] tzdb contents (",
+            length(tz_files),
+            " files): ",
+            paste(head(tz_files, 10), collapse = ", "),
+            if (length(tz_files) > 10) "..."
+          )
+        }
+        set_timezone_database(tz_path)
+        packageStartupMessage("[configure_tzdb] successfully configured 
timezone database")
       },
       error = function(e) {
         packageStartupMessage(
-          "The tzdb package was available but failed to initialize: ",
-          e,
+          "[configure_tzdb] tzdb package available but failed to initialize: ",
+          conditionMessage(e)
+        )
+        packageStartupMessage(
           "Timezones will not be available to Arrow compute functions."
         )
       }
     )
   } else {
     packageStartupMessage(
-      "The tzdb package is not installed. ",
+      "[configure_tzdb] tzdb package is NOT installed. ",
       "Timezones will not be available to Arrow compute functions. ",
       "If you get errors when using Arrow on datetimes, try running ",
       "`install.packages('tzdb')` and trying again."

Review Comment:
   The tzdb-missing startup message was changed to a debug-style prefix and 
uppercase emphasis ("[configure_tzdb] … NOT installed"). This is user-facing 
output during package load; consider keeping the previous wording to avoid 
noisy/diagnostic formatting.



##########
r/tests/testthat/test-dataset-dplyr.R:
##########
@@ -119,6 +120,7 @@ test_that("filter() on date32 columns", {
   )
 
   skip_if_not_available("re2")
+  skip_on_emscripten()

Review Comment:
   As written, `skip_on_emscripten()` occurs after the first assertion, so on 
Emscripten the test will still do file I/O and run expectations before being 
marked skipped (and the test's first part won't be counted). If only the 
timestamp-scalar portion is unsupported, conditionally run just that 
expectation instead of skipping the whole test at that point.



##########
ci/scripts/r_wasm_test.cjs:
##########
@@ -0,0 +1,165 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+// Smoke-test the arrow R package under webR, then run the testthat suite.
+// Called by r_wasm_test.sh. Requires env vars:
+//   ARROW_WASM_REPO_DIR - local CRAN-like repo with the arrow .tgz
+//   ARROW_R_TESTS_DIR   - path to tests/testthat in the source tree
+
+const { WebR } = require("webr");
+const http = require("http");
+const fs = require("fs");
+const path = require("path");
+
+const repoDir = process.env.ARROW_WASM_REPO_DIR;
+if (!repoDir) {
+  console.error("ERROR: ARROW_WASM_REPO_DIR not set");
+  process.exit(1);
+}
+
+const testsDir = process.env.ARROW_R_TESTS_DIR;
+if (!testsDir) {
+  console.error("ERROR: ARROW_R_TESTS_DIR not set");
+  process.exit(1);
+}
+
+function listFilesRecursive(dir) {
+  const results = [];
+  for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
+    const full = path.join(dir, entry.name);
+    if (entry.isDirectory()) {
+      results.push(...listFilesRecursive(full));
+    } else {
+      results.push(full);
+    }
+  }
+  return results;
+}
+
+async function main() {
+  // Serve the repo over HTTP (webR can't access the host filesystem directly)
+  const server = http.createServer((req, res) => {
+    const filePath = path.join(repoDir, decodeURIComponent(req.url));
+    if (!filePath.startsWith(path.resolve(repoDir))) {
+      res.writeHead(403);
+      res.end();
+      return;
+    }
+    fs.readFile(filePath, (err, data) => {

Review Comment:
   The HTTP file server path check can be bypassed with `..` segments because 
`filePath` is built with `path.join()` and then compared using `startsWith()` 
without normalizing. Use `path.resolve()` (and compare against a resolved repo 
root with a trailing separator) to prevent path traversal outside `repoDir`.



##########
r/tests/testthat/test-dplyr-arrange.R:
##########
@@ -238,6 +238,7 @@ test_that("Can use across() within arrange()", {
       collect(),
     example_data
   )
+  skip_on_emscripten()

Review Comment:
   `skip_on_emscripten()` aborts the entire test when reached; placed mid-test 
it will mark the whole test as skipped (and prevents reporting the first 
`compare_dplyr_binding()` result) while still doing work before skipping. If 
only the second assertion is unsupported on Emscripten, gate just that block 
with a conditional instead of calling `skip_*`.



##########
ci/scripts/r_wasm_test.sh:
##########
@@ -0,0 +1,80 @@
+#!/usr/bin/env bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Test the arrow R package built for WebAssembly.
+#
+# This script is intended to run inside the ghcr.io/r-universe-org/build-wasm
+# Docker container after rwasm::build() has produced a .tgz binary. It:
+#   1. Sets up a CRAN-like repo structure from the built .tgz
+#   2. Installs the npm webr package (Node.js webR runtime)
+#   3. Boots webR, installs arrow from the local repo, and verifies:
+#      - The package can be installed and loaded
+#      - Multithreading is disabled (arrow.use_threads == FALSE)
+#      - The testthat test suite runs
+#
+# Tests that require threading are automatically skipped via
+# skip_if_not(CanRunWithCapturedR()) since CanRunWithCapturedR() returns
+# FALSE under Emscripten.
+#
+# Usage:
+#   r_wasm_test.sh <path-to-arrow-r-dir>
+#
+# Example:
+#   r_wasm_test.sh /work
+#
+# The arrow .tgz file(s) should already exist in <path-to-arrow-r-dir>.
+
+set -euxo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+arrow_r_dir="${1:-.}"
+
+# Set up a fake CRAN-like repo so we can install the package
+tgz_file=$(ls "${arrow_r_dir}"/arrow_*.tgz 2>/dev/null | head -1)
+if [ -z "${tgz_file}" ]; then
+  echo "ERROR: No arrow_*.tgz found in ${arrow_r_dir}" >&2
+  exit 1
+fi

Review Comment:
   With `set -euo pipefail`, the `ls … | head -1` pipeline will cause the 
script to exit immediately when no `arrow_*.tgz` exists (due to `pipefail`), so 
the custom error message below never runs. Guard the pipeline (or avoid `ls`) 
so the explicit check can execute.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to