@@ -727,6 +727,68 @@ test_that("combined results are validated and the TSV is repaired on reuse", {
727727 expect_identical(readLines(tsv_path , warn = FALSE ), expected_tsv )
728728})
729729
730+ test_that(" shard schemas accept integer and double numeric columns" , {
731+ artifacts <- list (
732+ list (results = data.frame (df = c(1L , NA_integer_ ), n = c(20 , 30 ))),
733+ list (results = data.frame (df = c(2.5 , NA_real_ ), n = c(40L , 50L )))
734+ )
735+
736+ expect_true(phewasFlow ::: .pf_validate_shard_set(artifacts ))
737+ expect_true(phewasFlow ::: .pf_validate_shard_set(rev(artifacts )))
738+ })
739+
740+ test_that(" shard schemas still reject incompatible types, names, and order" , {
741+ reference <- list (results = data.frame (df = 1L , n = 20L ))
742+ for (value in list (" 1" , TRUE , 1 + 0i , list (1L ))) {
743+ altered <- reference
744+ altered $ results $ df <- value
745+ expect_error(
746+ phewasFlow ::: .pf_validate_shard_set(list (reference , altered )),
747+ " Shard result schemas are inconsistent"
748+ )
749+ }
750+ for (columns in list (" df" , c(" n" , " df" ))) {
751+ altered <- list (results = reference $ results [, columns , drop = FALSE ])
752+ expect_error(
753+ phewasFlow ::: .pf_validate_shard_set(list (reference , altered )),
754+ " Shard result schemas are inconsistent"
755+ )
756+ }
757+ altered <- reference
758+ names(altered $ results )[[1L ]] <- " degrees_of_freedom"
759+ expect_error(
760+ phewasFlow ::: .pf_validate_shard_set(list (reference , altered )),
761+ " Shard result schemas are inconsistent"
762+ )
763+ })
764+
765+ test_that(" mixed integer and double df shards combine without changing values" , {
766+ directory <- withr :: local_tempdir()
767+ fixture <- complete_shard_fixture(directory )
768+ artifacts <- lapply(fixture $ shards , readRDS )
769+
770+ for (double_shard in seq_along(artifacts )) {
771+ for (index in seq_along(artifacts )) {
772+ artifact <- data.table :: copy(artifacts [[index ]])
773+ artifact $ results $ df <- if (index == double_shard ) {
774+ as.double(artifact $ results $ df )
775+ } else {
776+ as.integer(artifact $ results $ df )
777+ }
778+ saveRDS(artifact , fixture $ shards [[index ]], version = 3L )
779+ }
780+
781+ result <- combine_phewas_shards(fixture $ config , overwrite = TRUE )
782+ expect_identical(result $ df , as.double(fixture $ result $ df ))
783+ expect_equal(result , fixture $ result , ignore_attr = TRUE )
784+ expect_equal(read_phewas_bundle(fixture $ output ), result , ignore_attr = TRUE )
785+ expect_equal(
786+ suppressMessages(combine_phewas_shards(fixture $ config )),
787+ result , ignore_attr = TRUE
788+ )
789+ }
790+ })
791+
730792test_that(" readable shard artifacts cannot hide schema or metadata drift" , {
731793 directory <- withr :: local_tempdir()
732794 path <- make_shard_fixture(directory )
0 commit comments