Skip to content

Commit f626613

Browse files
committed
Merge torrust#833: refactor: replace text-to-png with internal render-text-as-image and modernize codebase
f326874 test: add comprehensive test coverage for render-text-as-image and related components (Cameron Garnham) 67e411f refactor: replace text-to-png with internal render-text-as-image and modernize codebase (Cameron Garnham) Pull request description: Replace the external `text-to-png` dependency with a new internal `render-text-as-image` package, modernizes the codebase by migrating from `lazy_static` to `std::sync::LazyLock`, relocates unit tests to a centralized `src/tests/` directory, and bumps the minimum Rust version from 1.72 to 1.80. ## Key Changes ### Dependency Modernization - **Replaced `text-to-png`** with new internal `render-text-as-image` package - Pure-Rust text-to-PNG rendering using `ab_glyph` + `image` crates - Embedded Roboto Mono font (no system dependencies) - Eliminates heavy SVG rendering pipeline (resvg, usvg, fontdb, rustybuzz, etc.) - Reduces transitive dependencies by ~30+ crates - **Replaced `lazy_static`** with `std::sync::LazyLock` (stable since Rust 1.80) - **Updated `io::Error::new(...)`** to `io::Error::other(...)` (stable since Rust 1.74) - **Consolidated `bitflags`** from v1 + v2 to v2 only - **Bumped minimum Rust version** from 1.72 to 1.80 (required for LazyLock) ### New Internal Package: `render-text-as-image` - Self-contained text rendering library for containerized environments - Modular architecture: blend, encode, font, layout, render, types modules - Comprehensive documentation: specification (§SPEC R-1) and ADRs (001–003) - Includes embedded Roboto Mono Regular font (125KB TTF) - Designed for CAPTCHA, image generation, and similar use cases ### Test Architecture Reorganization - **Moved inline `#[cfg(test)]` modules** to centralized `src/tests/` directory - Follows project convention of separating crate-level tests from source - Affected modules: config, cache, mailer, models, services, tracker, utils - Updated `src/lib.rs` to include `mod tests;` for test discovery - Some items widened to `pub(crate)` visibility to support test access ### Workspace Configuration - Converted project to Cargo workspace with three members: - Main `torrust-index` crate - `located-error` package - `render-text-as-image` package - Updated `Cargo.toml` with workspace inheritance for metadata ### Code Quality Improvements - **Fixed recurring typos**: "migth" → "might", "becuase" → "because", "successfull" → "successful", "Ununauthorized" → "Unauthorized" - Updated `.gitignore` to exclude test report files - Updated `cspell.json` and `project-words.txt` with new vocabulary - Expanded `AGENTS.md` with detailed development guidelines ## Benefits - **Reduced dependency tree**: ~30+ transitive crates removed - **Modern Rust idioms**: Uses stable stdlib features (LazyLock, io::Error::other) - **Better test organization**: Clear separation between source and test code - **Self-contained text rendering**: No external system dependencies (FreeType, Fontconfig) - **Improved compile times**: Smaller dependency graph and modular test structure ## Testing Performed - All existing tests continue to pass after migration - New `render-text-as-image` package includes comprehensive unit tests - Crate test structure validated with `cargo test --workspace` ## Breaking Changes - **Minimum Rust version increased from 1.72 to 1.80** - Required for `std::sync::LazyLock` and `io::Error::other()` - Rust 1.80 was released in July 2024 (~1.5 years ago) - No API changes to public interfaces ## Migration Needed - Developers must update to Rust 1.80+ to build the project - New test contributions should follow the centralized `src/tests/` pattern - Text rendering functionality now uses the internal `render-text-as-image` API ## References - `std::sync::LazyLock` stabilization (Rust 1.80, July 2024) - `io::Error::other()` stabilization (Rust 1.74, October 2023) - Specification for render-text-as-image (§SPEC R-1) - ADR 001–003 for dependency, font, and structure decisions ACKs for top commit: da2ce7: ACK f326874 Tree-SHA512: 97db8fa981a5538807611c46b39f118d1aee617eda7ca324b713a3793b17294f0550f9ec8e06d0a6b06657012826d2c60c0eaca9501759918d9953d76d69681b
2 parents 8c32d7b + f326874 commit f626613

74 files changed

Lines changed: 2187 additions & 1490 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/e2e.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Temporary execution of E2E tests using MySQL becuase it's failing
1+
# Temporary execution of E2E tests using MySQL because it's failing
22
# in the `testing.yml` workflows and affects deployments and releases.
33
# See https://github.com/torrust/torrust-index/issues/580
44
name: E2E Testing

.github/workflows/upload_coverage_pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Upload Coverage Report (PR)
22

33
on:
4-
# This workflow is triggered after every successfull execution
4+
# This workflow is triggered after every successful execution
55
# of `Generate Coverage Report` workflow.
66
workflow_run:
77
workflows: ["Generate Coverage Report (PR)"]

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
/output/
88
/storage/
99
/target
10-
/uploads/
10+
/uploads/
11+
**/*report.txt
12+
**/*report.diff

AGENTS.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,56 @@
22

33
## Cargo Commands
44

5-
Prefer using `--workspace --all-targets --all-features` when running `cargo check`, `cargo clippy`, or `cargo test`.
5+
Prefer using `--workspace --all-targets --all-features` when running
6+
`cargo check`, `cargo clippy`, or `cargo test`.
7+
8+
Be mindful to at least do a quick spot-test with `--no-default-features`,
9+
and to try building the docs and running the doc-tests.
10+
11+
When testing, also run the tests in `--release` mode to check that this
12+
works. Run the tests in debug mode with `CARGO_PROFILE_DEV_OPT_LEVEL=3`;
13+
otherwise it is just too slow. You can turn off the optimisation if a bug
14+
is found and you need backtracing.
15+
16+
When working inside a package, prefer running only the `--package` tests,
17+
as the whole-project tests are slow to run. (Occasionally run the whole
18+
suite, for example when finishing up.)
19+
20+
## Running Tests
21+
22+
When running tests, tee to a temp file (`/tmp/...`) and then grep that
23+
file after the tests have completed.
24+
25+
## Test Locations
26+
27+
We use three levels of tests based upon viability. In general, crate tests
28+
are preferred over unit tests. Integration tests should test the public
29+
API, perhaps using `#[doc(hidden)]` helpers when appropriate.
30+
31+
| Level | Visibility | Location |
32+
|-------------|--------------|---------------|
33+
| Unit | `private` | inline |
34+
| Crate | `pub(crate)` | `/src/tests/` |
35+
| Integration | `pub` | `/tests/` |
36+
37+
## Cross-Reference Conventions
38+
39+
Eagerly corrected when spotted in **any** file!
40+
41+
Cross-references use the `§` (section sign) prefix. Every reference
42+
carries a **package qualifier**`T-` for Torrust —
43+
so the target document is never ambiguous.
44+
45+
### General Rules
46+
47+
- Use `§§` for ranges: e.g. `§§ALGO M-12.2–12.5`.
48+
- Bare `§N` (no label) is acceptable **within** a document that already
49+
establishes context (e.g. inside `algorithm.md` itself), but in source
50+
code and cross-package references always use the fully qualified
51+
`§BOOK PACKAGE_PREFIX-N` form.
52+
53+
## Replacing a File
54+
55+
1. Read the file.
56+
2. Using the CLI, `rm` the file.
57+
3. Recreate the file.

0 commit comments

Comments
 (0)