Skip to content

chore: fix clippy and commit lockfile - #1

Closed
yoiberdev wants to merge 4 commits into
mainfrom
chore/clippy-lockfile
Closed

yoiberdev wants to merge 4 commits into
mainfrom
chore/clippy-lockfile

Conversation

@yoiberdev

@yoiberdev yoiberdev commented Sep 14, 2026 •

Copy link
Copy Markdown
Owner

Base de las PR que vienen detrás: conviene mezclar esta primero. Deja el CI en verde con la stable actual y versiona Cargo.lock. Las siguientes PR de docugraph-mcp parten de aquí.

Problema

  • El CI no pasa con la stable actual. Con rustc/clippy 1.98.1, cargo clippy --all-targets -- -D warnings sale con código 101 por dos lints nuevos: clippy::chunks_exact_to_as_chunks en src/document/attachments.rs:161 y clippy::collapsible_match en src/document/layout.rs:360.
  • Cargo.lock estaba en .gitignore. docugraph es un binario, así que cada build volvía a resolver dependencias: un commit fijo no fijaba rmcp, lopdf, tokio y el resto. La clave de caché del CI (hashFiles('**/Cargo.lock')) tampoco cambiaba nunca.
  • El único test con un PDF real no probaba nada. test_real_pdf_loading_and_extraction buscaba C:/proyectos/chaika-stage/... y, si no existía, hacía return y contaba como pasado. Salvo en una máquina, los verdes no incluían ningún PDF real.

Cambios

Commit Qué hace
refactor: fix clippy lints from Rust 1.98 as_chunks::<2>() en vez de chunks_exact(2) para recorrer la hoja /Names, que igual ignora el elemento suelto del final. Y la comprobación del espacio final se sube a la guarda de los brazos Integer/Real del TJ: si la guarda falla, cae en _ => {}, que es lo mismo que hacía el if interior. Se aplica a los dos brazos para que sigan simétricos. Sin cambio de comportamiento.
chore: track Cargo.lock Quita Cargo.lock del .gitignore y añade el lock resuelto para 2832efa: 182 paquetes, rmcp 3.3.0, lopdf 0.45.0, tokio 1.53.1.
test: gate real PDF test behind env var La ruta se lee de DOCUGRAPH_TEST_PDF y el test lleva #[ignore = "needs a real PDF: set DOCUGRAPH_TEST_PDF and run with --ignored"]. Por defecto sale como ignored en vez de ok. Con --ignored, si falta la variable o el fichero, falla con un mensaje claro. Añade el comando en CONTRIBUTING.md.
ci: run clippy and tests with --locked --locked en clippy y en test. No hay paso de build aparte: clippy es el primero que resuelve dependencias y cargo test compila. Si solo lo llevara test, clippy reescribiría el lock antes y el --locked no detectaría nada.

Nota: as_chunks es estable desde Rust 1.88. El crate no declara rust-version y el CI usa stable, así que no afecta.

Cómo se verificó

En local con rustc/cargo/clippy 1.98.1 y rustfmt 1.9.0, sobre este árbol:

Comando Resultado
cargo fmt --all -- --check exit 0, sin diferencias
cargo clippy --locked --all-targets -- -D warnings exit 0, 0 avisos (Finished dev profile ... in 24.99s)
cargo test --release --locked --test attachments_and_embedded_files_test --test pdf_ingestion_test --test spatial_reading_order_test exit 0: 5 + 4 + 5 pasados, 1 ignorado (test_real_pdf_loading_and_extraction ... ignored, needs a real PDF: set DOCUGRAPH_TEST_PDF and run with --ignored)
cargo test --release --test pdf_ingestion_test -- --ignored --exact test_real_pdf_loading_and_extraction sin la variable exit 101: DOCUGRAPH_TEST_PDF must point to a real PDF with more than 200 pages: NotPresent
Lo mismo con DOCUGRAPH_TEST_PDF apuntando a un PDF digital real de 224 páginas exit 0: Verified real PDF ... with 224 pages and 96 sections
Lo mismo con otro PDF real de 437 páginas exit 0: Verified real PDF ... with 437 pages and 51 sections

Sin cambio de comportamiento, comprobado con PDFs reales. Indexé esos dos PDFs con docugraph index usando el binario release de 2832efa y el de esta rama, cada uno con su DOCUGRAPH_CACHE_DIR. Los JSON salen idénticos byte a byte (385.380 y 642.989 bytes, 224 y 437 páginas). La indexación pasa por parser.rs:277 → layout::extract_page_text_spatial, que es donde está el TJ tocado. La hoja /Names de attachments.rs la cubre test_extract_attachment_from_embedded_files_name_tree. Los PDFs son libros con licencia personal y no se suben al repo.

La suite completa no la pude compilar en local por falta de espacio en el disco temporal (en local ejecuté los tres objetivos afectados). La ejecuta entera el CI de esta PR (run 34894215480): fmt ok, cargo clippy --locked --all-targets -- -D warnings ok y cargo test --all --locked --verbose con 72 pasados, 0 fallidos y 1 ignorado, en 1m18s.

Cifras de antes y después

Antes (main, 2832efa) Después (esta rama)
CI en GitHub falla: los 7 últimos push a main acaban en failure en el paso de clippy y los tests quedan skipped (run 34854899911) pasa (run 34894215480)
cargo clippy --all-targets -- -D warnings (1.98.1) exit 101, 2 errores (attachments.rs:161:30, layout.rs:360:33) exit 0, 0 avisos
cargo fmt --all -- --check limpio limpio
Cargo.lock ignorado: cada build resuelve de nuevo versionado: 182 paquetes, --locked ok en local y en CI
cargo test 73 pasados, 0 ignorados (medido en local en release), pero uno de ellos era un «ok» sin probar nada 72 pasados, 1 ignorado con motivo, 0 fallidos (CI)
Test con PDF real solo se ejecutaba con C:/proyectos/chaika-stage/... DOCUGRAPH_TEST_PDF=... -- --ignored: pasa con PDFs de 224 y 437 páginas y falla claro si falta la variable
Salida de docugraph index con dos PDFs reales referencia idéntica byte a byte

Clippy 0.1.98 flags two new lints that break the CI step
`cargo clippy --all-targets -- -D warnings` on stable:

- chunks_exact_to_as_chunks (attachments.rs): iterate the
  /Names leaf with `as_chunks::<2>()`. The trailing odd element
  is still skipped, as with `chunks_exact(2)`.
- collapsible_match (layout.rs): move the "no trailing space"
  check into the TJ match guards. A failing guard falls through
  to `_ => {}`, which is what the inner `if` did.

No behaviour change. `as_chunks` needs Rust 1.88 or newer.
docugraph ships a binary, so the lockfile belongs in the repo.
Without it every build resolves dependencies again and a fixed
commit does not pin rmcp, lopdf, tokio and the rest.

The lock is the one resolved for 2832efa (182 packages, rmcp
3.3.0, lopdf 0.45.0, tokio 1.53.1) and matches Cargo.toml under
`--locked`.
test_real_pdf_loading_and_extraction read a hardcoded Windows
path and returned early when it was missing, so it reported "ok"
without testing anything on every machine but one.

Read the path from DOCUGRAPH_TEST_PDF instead and mark the test
#[ignore] with a reason, so it shows up as ignored by default.
Run it with `DOCUGRAPH_TEST_PDF=... cargo test -- --ignored`;
a missing variable or file now fails loudly.
Now that Cargo.lock is tracked, fail CI when it is out of date
with Cargo.toml instead of silently rewriting it.

There is no separate build step: clippy is the first step that
resolves dependencies and `cargo test` builds the crate, so both
get --locked. Without it on clippy the lock would be rewritten
before the test step runs.
@yoiberdev

Copy link
Copy Markdown
Owner Author

Se descarta: los arreglos de docugraph los está haciendo el autor en su copia local y estos cambios chocarían con ellos.

@yoiberdev yoiberdev closed this Sep 14, 2026
@yoiberdev
yoiberdev deleted the chore/clippy-lockfile branch September 14, 2026 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant