Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# vitals (development version)

* Internal `expect_valid_log()` now styles Pydantic output for readability
(#159 by howardbaik).

* `$eval()` and `$log()` will now write log files to the same default
directory--the one specified when initializing the Task object.
Expand Down
39 changes: 35 additions & 4 deletions tests/testthat/helper-valid_log.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,45 @@ expect_valid_log <- local({
stdout = TRUE,
stderr = TRUE
)

status <- attr(result, "status")

# "inst/test/inspect/logs/2025-03-24T10-39-36-05-00_simple-arithmetic_fQ9mYnqZFhtEuUenPpJgKL.json"
if (length(result) == 1) {
formatted_message <- cli::format_message(c(
"The generated log did not pass the pydantic model:",
glue::glue("{{.field {result[1]}}}")
))
expect(
is.null(status) || status == 0,
formatted_message
)
}

# Make the result more readable by removing redundant elements
# and formatting indices with cli (#159)
result <- result[!grepl("For further information visit", result)]
result_length <- length(result)
field_positions <- seq(2, result_length, by = 2)

for (pos in field_positions) {
result[pos] <- glue::glue("{{.field {result[pos]}}}")
}

result_with_breaks <- result[1]
for (i in seq(2, length(result), by = 2)) {
result_with_breaks <- c(result_with_breaks, "", result[i:(i + 1)])
}

formatted_message <- cli::format_message(c(
"The generated log did not pass the pydantic model:",
"",
result_with_breaks
))

expect(
is.null(status) || status == 0,
paste0(
c("The generated log did not pass the pydantic model: ", result),
collapse = "\n"
)
formatted_message
)
}
})
Loading