From 9a09e83ec2ad95a8d0ef9baa644ee893cbaaa617 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Leite?= Date: Tue, 29 Sep 2026 19:01:54 -0300 Subject: [PATCH 1/4] Keep RStudio and CRAN-SUBMISSION files out of the build Co-Authored-By: Claude Opus 5.5 --- .Rbuildignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.Rbuildignore b/.Rbuildignore index 28bdb36..15fe9c6 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,3 +10,6 @@ ^DECISIONS\.md$ ^README\.Rmd$ ^CLAUDE\.md$ +^.*\.Rproj$ +^\.Rproj\.user$ +^CRAN-SUBMISSION$ From 0b8dbf9cacd197528b545ca27862b9319de7bc8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Leite?= Date: Tue, 29 Sep 2026 19:01:55 -0300 Subject: [PATCH 2/4] Report an invalid staff status as an error map_status() was passed straight into alepe_fetch_json(), where lazy evaluation ran it inside the fetch layer's error handler. An invalid status therefore surfaced as 'API could not be reached' plus an empty tibble instead of the documented input error. Resolve it first. Co-Authored-By: Claude Opus 5.5 --- DESCRIPTION | 2 +- NEWS.md | 10 ++++++++++ R/people.R | 18 ++++++++---------- tests/testthat/test-endpoints.R | 9 +++++++++ 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ff1fc56..b2ccda3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: alepe Title: Access the Open Data API of the Legislative Assembly of Pernambuco -Version: 0.1.0 +Version: 0.1.0.9000 Authors@R: c( person("André", "Leite", email = "leite@castlab.org", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-4718-9766")), diff --git a/NEWS.md b/NEWS.md index 9f25588..febdaa8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,13 @@ +# alepe (development version) + +* An invalid `status` in `alepe_staff()` / `alepe_positions()` (and + their aliases) is now an error, as documented. It used to be evaluated + inside the fetch layer's error handler and surfaced as a warning that + the API could not be reached, followed by an empty tibble. +* Author metadata: the maintainer's name is spelled André Leite; Marcos + Wasiliew's e-mail address is updated; ORCIDs added for Marcos Wasiliew + and Júlia Nascimento Barreto. + # alepe 0.1.0 * Initial release. diff --git a/R/people.R b/R/people.R index 6bd5970..5ab004a 100644 --- a/R/people.R +++ b/R/people.R @@ -40,11 +40,10 @@ alepe_staff <- function(status = NULL, refresh = FALSE) { cargo_efetivo = "chr", cargo_nivel = "chr", vinculo = "chr", data_admissao = "date" ) - records <- alepe_fetch_json( - "servidores", - vinculo = map_status(status), - refresh = refresh - ) + # Resolved before the fetch: an argument evaluated lazily inside the + # fetch would be caught there and reported as an unreachable API. + vinculo <- map_status(status) + records <- alepe_fetch_json("servidores", vinculo = vinculo, refresh = refresh) out <- records_to_tibble(records, schema) report_rows(out, "staff members") } @@ -62,11 +61,10 @@ alepe_staff <- function(status = NULL, refresh = FALSE) { #' @export alepe_positions <- function(status = NULL, refresh = FALSE) { schema <- c(total = "int", cargo_nivel = "chr") - records <- alepe_fetch_json( - "cargos", - vinculo = map_status(status), - refresh = refresh - ) + # Resolved before the fetch: an argument evaluated lazily inside the + # fetch would be caught there and reported as an unreachable API. + vinculo <- map_status(status) + records <- alepe_fetch_json("cargos", vinculo = vinculo, refresh = refresh) out <- records_to_tibble(records, schema) report_rows(out, "positions") } diff --git a/tests/testthat/test-endpoints.R b/tests/testthat/test-endpoints.R index 3e011ce..f6f703f 100644 --- a/tests/testthat/test-endpoints.R +++ b/tests/testthat/test-endpoints.R @@ -180,3 +180,12 @@ test_that("proposition detail parses one full record", { test_that("detail mode requires year alongside number", { expect_error(alepe_bills(number = 10), class = "alepe_error_input") }) + +test_that("an invalid status is an input error, not a network warning", { + # The mock never touches `...`, as the real fetch layer would only + # evaluate it inside its own error handler. + local_mocked_bindings(alepe_fetch_json = function(...) list()) + + expect_error(alepe_staff(status = "nope"), class = "rlang_error") + expect_error(alepe_positions(status = "nope"), class = "rlang_error") +}) From 54a490c70558f6760cb12b985504d5207d647f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Leite?= Date: Tue, 29 Sep 2026 19:02:02 -0300 Subject: [PATCH 3/4] Add status = "lent" to alepe_staff() The /servidores endpoint accepts vinculo=efetivo-cedido: the Assembly's own permanent staff lent to other bodies. They are published with VINCULO "Efetivo", so only the server-side filter can single them out. /cargos ignores the value and returns every status, so alepe_positions() rejects it instead of pretending to filter (D22). Co-Authored-By: Claude Opus 5.5 --- NEWS.md | 5 +++++ R/people.R | 19 ++++++++++++++----- R/utils.R | 12 ++++++++++-- README.md | 5 +++-- man/alepe_aliases.Rd | 10 +++++++--- man/alepe_positions.Rd | 3 ++- man/alepe_staff.Rd | 10 +++++++--- tests/testthat/test-endpoints.R | 17 ++++++++++++++++- tests/testthat/test-utils.R | 3 +++ 9 files changed, 67 insertions(+), 17 deletions(-) diff --git a/NEWS.md b/NEWS.md index febdaa8..d95f9c9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ # alepe (development version) +* `alepe_staff()` gains `status = "lent"` (API term `"efetivo-cedido"`): + the Assembly's own permanent staff lent to other bodies. The API + publishes them with `vinculo` `"Efetivo"`, so this server-side filter + is the only way to single them out. `alepe_positions()` does not accept + it, because `/cargos` ignores the value and returns every status. * An invalid `status` in `alepe_staff()` / `alepe_positions()` (and their aliases) is now an error, as documented. It used to be evaluated inside the fetch layer's error handler and surfaced as a warning that diff --git a/R/people.R b/R/people.R index 5ab004a..b31e776 100644 --- a/R/people.R +++ b/R/people.R @@ -23,9 +23,13 @@ alepe_representatives <- function(refresh = FALSE) { #' employment status. #' #' @param status Employment status filter. One of `"permanent"`, -#' `"commissioned"`, or `"seconded"` (the original API terms -#' `"efetivo"`, `"comissionado"`, and `"a-disposicao"` are also -#' accepted), or `NULL` (default) for all. +#' `"commissioned"`, `"seconded"` (staff from other bodies placed at +#' the Assembly's disposal), or `"lent"` (the Assembly's own permanent +#' staff lent to other bodies, a subset of `"permanent"`); the original +#' API terms `"efetivo"`, `"comissionado"`, `"a-disposicao"`, and +#' `"efetivo-cedido"` are also accepted. `NULL` (default) for all. +#' Lent staff are published with `vinculo` `"Efetivo"`, so this filter +#' is the only way to tell them apart. #' @inheritParams alepe_representatives #' @returns A tibble with one row per staff member: `nome`, #' `codigo_lotacao`, `nome_lotacao`, `cargo_efetivo`, `cargo_nivel`, @@ -42,7 +46,7 @@ alepe_staff <- function(status = NULL, refresh = FALSE) { ) # Resolved before the fetch: an argument evaluated lazily inside the # fetch would be caught there and reported as an unreachable API. - vinculo <- map_status(status) + vinculo <- map_status(status, lent = TRUE) records <- alepe_fetch_json("servidores", vinculo = vinculo, refresh = refresh) out <- records_to_tibble(records, schema) report_rows(out, "staff members") @@ -53,7 +57,12 @@ alepe_staff <- function(status = NULL, refresh = FALSE) { #' Retrieves the number of staff members per position/level, optionally #' filtered by employment status. #' -#' @inheritParams alepe_staff +#' @param status Employment status filter. One of `"permanent"`, +#' `"commissioned"`, or `"seconded"` (the original API terms +#' `"efetivo"`, `"comissionado"`, and `"a-disposicao"` are also +#' accepted), or `NULL` (default) for all. Unlike [alepe_staff()], +#' `"lent"` is not available: the API ignores it for this endpoint. +#' @inheritParams alepe_representatives #' @returns A tibble with `total` and `cargo_nivel`. Zero rows (with a #' warning) on network failure. #' @examplesIf interactive() diff --git a/R/utils.R b/R/utils.R index 545c39b..8d7d6ee 100644 --- a/R/utils.R +++ b/R/utils.R @@ -232,10 +232,15 @@ decode_numeric_entities <- function(x) { #' #' @param status `NULL` (no filter) or one of `"permanent"`, #' `"commissioned"`, `"seconded"`, `"efetivo"`, `"comissionado"`, -#' `"a-disposicao"`. +#' `"a-disposicao"`; with `lent = TRUE`, also `"lent"` and +#' `"efetivo-cedido"`. +#' @param lent Whether to accept the `efetivo-cedido` value. Only +#' `/servidores` honours it; `/cargos` silently ignores it and returns +#' every status, so it must be rejected there (D22). #' @returns The API value, or `NULL`. #' @noRd -map_status <- function(status, error_call = rlang::caller_env()) { +map_status <- function(status, lent = FALSE, + error_call = rlang::caller_env()) { if (is.null(status)) { return(NULL) } @@ -247,6 +252,9 @@ map_status <- function(status, error_call = rlang::caller_env()) { comissionado = "comissionado", `a-disposicao` = "a-disposicao" ) + if (lent) { + map <- c(map, lent = "efetivo-cedido", `efetivo-cedido` = "efetivo-cedido") + } status <- rlang::arg_match(status, names(map), error_call = error_call) unname(map[[status]]) } diff --git a/README.md b/README.md index 3454608..673bcb0 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,9 @@ alepe_bills(year = 2024) ``` Filter values use an English vocabulary (`"permanent"`, -`"commissioned"`, `"seconded"`), but the original API terms -(`"efetivo"`, `"comissionado"`, `"a-disposicao"`) are accepted as well. +`"commissioned"`, `"seconded"`, `"lent"`), but the original API terms +(`"efetivo"`, `"comissionado"`, `"a-disposicao"`, `"efetivo-cedido"`) +are accepted as well. Column names keep the official Portuguese field names, normalized to snake_case, so results stay traceable to the source. diff --git a/man/alepe_aliases.Rd b/man/alepe_aliases.Rd index 153c642..6acf7bb 100644 --- a/man/alepe_aliases.Rd +++ b/man/alepe_aliases.Rd @@ -51,9 +51,13 @@ alepe_limpar_cache() \item{refresh}{If \code{TRUE}, bypass the local cache.} \item{status}{Employment status filter. One of \code{"permanent"}, -\code{"commissioned"}, or \code{"seconded"} (the original API terms -\code{"efetivo"}, \code{"comissionado"}, and \code{"a-disposicao"} are also -accepted), or \code{NULL} (default) for all.} +\code{"commissioned"}, \code{"seconded"} (staff from other bodies placed at +the Assembly's disposal), or \code{"lent"} (the Assembly's own permanent +staff lent to other bodies, a subset of \code{"permanent"}); the original +API terms \code{"efetivo"}, \code{"comissionado"}, \code{"a-disposicao"}, and +\code{"efetivo-cedido"} are also accepted. \code{NULL} (default) for all. +Lent staff are published with \code{vinculo} \code{"Efetivo"}, so this filter +is the only way to tell them apart.} \item{numero}{Portuguese spelling of \code{number}.} diff --git a/man/alepe_positions.Rd b/man/alepe_positions.Rd index 67c2f73..01be9b9 100644 --- a/man/alepe_positions.Rd +++ b/man/alepe_positions.Rd @@ -10,7 +10,8 @@ alepe_positions(status = NULL, refresh = FALSE) \item{status}{Employment status filter. One of \code{"permanent"}, \code{"commissioned"}, or \code{"seconded"} (the original API terms \code{"efetivo"}, \code{"comissionado"}, and \code{"a-disposicao"} are also -accepted), or \code{NULL} (default) for all.} +accepted), or \code{NULL} (default) for all. Unlike \code{\link[=alepe_staff]{alepe_staff()}}, +\code{"lent"} is not available: the API ignores it for this endpoint.} \item{refresh}{If \code{TRUE}, bypass the local cache.} } diff --git a/man/alepe_staff.Rd b/man/alepe_staff.Rd index 52942a3..4681aff 100644 --- a/man/alepe_staff.Rd +++ b/man/alepe_staff.Rd @@ -8,9 +8,13 @@ alepe_staff(status = NULL, refresh = FALSE) } \arguments{ \item{status}{Employment status filter. One of \code{"permanent"}, -\code{"commissioned"}, or \code{"seconded"} (the original API terms -\code{"efetivo"}, \code{"comissionado"}, and \code{"a-disposicao"} are also -accepted), or \code{NULL} (default) for all.} +\code{"commissioned"}, \code{"seconded"} (staff from other bodies placed at +the Assembly's disposal), or \code{"lent"} (the Assembly's own permanent +staff lent to other bodies, a subset of \code{"permanent"}); the original +API terms \code{"efetivo"}, \code{"comissionado"}, \code{"a-disposicao"}, and +\code{"efetivo-cedido"} are also accepted. \code{NULL} (default) for all. +Lent staff are published with \code{vinculo} \code{"Efetivo"}, so this filter +is the only way to tell them apart.} \item{refresh}{If \code{TRUE}, bypass the local cache.} } diff --git a/tests/testthat/test-endpoints.R b/tests/testthat/test-endpoints.R index f6f703f..94a3360 100644 --- a/tests/testthat/test-endpoints.R +++ b/tests/testthat/test-endpoints.R @@ -181,11 +181,26 @@ test_that("detail mode requires year alongside number", { expect_error(alepe_bills(number = 10), class = "alepe_error_input") }) +test_that("status = 'lent' reaches /servidores but is refused by positions", { + sent <- NULL + local_mocked_bindings(alepe_fetch_json = function(endpoint, ...) { + sent <<- list(...)$vinculo + fixture_json("servidores.json") + }) + + alepe_staff(status = "lent") + expect_equal(sent, "efetivo-cedido") + alepe_servidores(status = "efetivo-cedido") + expect_equal(sent, "efetivo-cedido") + + expect_error(alepe_positions(status = "lent"), class = "rlang_error") +}) + test_that("an invalid status is an input error, not a network warning", { # The mock never touches `...`, as the real fetch layer would only # evaluate it inside its own error handler. local_mocked_bindings(alepe_fetch_json = function(...) list()) expect_error(alepe_staff(status = "nope"), class = "rlang_error") - expect_error(alepe_positions(status = "nope"), class = "rlang_error") + expect_error(alepe_positions(status = "lent"), class = "rlang_error") }) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 4b4ec64..f91e1b7 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -39,6 +39,9 @@ test_that("map_status accepts English and Portuguese vocabularies", { expect_equal(map_status("efetivo"), "efetivo") expect_equal(map_status("seconded"), "a-disposicao") expect_error(map_status("nope"), class = "rlang_error") + expect_equal(map_status("lent", lent = TRUE), "efetivo-cedido") + expect_equal(map_status("efetivo-cedido", lent = TRUE), "efetivo-cedido") + expect_error(map_status("lent"), class = "rlang_error") }) test_that("records_to_tibble builds typed tibbles and handles NULL", { From 3e4aa3c0093a3722645727f817e6887ee2324fca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Leite?= Date: Tue, 29 Sep 2026 19:25:56 -0300 Subject: [PATCH 4/4] Say on the aliases page that only alepe_servidores() takes "lent" Co-Authored-By: Claude Opus 5.5 --- R/aliases.R | 3 +++ man/alepe_aliases.Rd | 11 +++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/R/aliases.R b/R/aliases.R index 7119514..69fd4d2 100644 --- a/R/aliases.R +++ b/R/aliases.R @@ -28,6 +28,9 @@ #' `alepe_servidores(status = "efetivo")` and #' `alepe_staff(status = "permanent")` are the same query. #' +#' @param status Employment status filter, as in [alepe_staff()] and +#' [alepe_positions()]. `"lent"` (`"efetivo-cedido"`) is accepted by +#' `alepe_servidores()` only. #' @inheritParams alepe_staff #' @inheritParams alepe_bills #' @returns The same tibble the corresponding English function returns. diff --git a/man/alepe_aliases.Rd b/man/alepe_aliases.Rd index 6acf7bb..eaf2a91 100644 --- a/man/alepe_aliases.Rd +++ b/man/alepe_aliases.Rd @@ -50,14 +50,9 @@ alepe_limpar_cache() \arguments{ \item{refresh}{If \code{TRUE}, bypass the local cache.} -\item{status}{Employment status filter. One of \code{"permanent"}, -\code{"commissioned"}, \code{"seconded"} (staff from other bodies placed at -the Assembly's disposal), or \code{"lent"} (the Assembly's own permanent -staff lent to other bodies, a subset of \code{"permanent"}); the original -API terms \code{"efetivo"}, \code{"comissionado"}, \code{"a-disposicao"}, and -\code{"efetivo-cedido"} are also accepted. \code{NULL} (default) for all. -Lent staff are published with \code{vinculo} \code{"Efetivo"}, so this filter -is the only way to tell them apart.} +\item{status}{Employment status filter, as in \code{\link[=alepe_staff]{alepe_staff()}} and +\code{\link[=alepe_positions]{alepe_positions()}}. \code{"lent"} (\code{"efetivo-cedido"}) is accepted by +\code{alepe_servidores()} only.} \item{numero}{Portuguese spelling of \code{number}.}