Skip to content

test: make every integration test target compile and pass - #12

Merged
CodingAnarchy merged 1 commit into
masterfrom
fix/test-targets
Oct 8, 2026
Merged

CodingAnarchy merged 1 commit into
masterfrom
fix/test-targets

Conversation

@CodingAnarchy

Copy link
Copy Markdown
Owner

Part of #7 (test-targets workstream).

What

Every root tests/*.rs target and hammerwork-web/tests/integration_tests.rs now compiles under --all-features --all-targets, is clippy-clean, and passes against PostgreSQL 16 and MySQL 8 with --include-ignored. Only files under tests/ and hammerwork-web/tests/ are touched.

Changes

  • Compile fixes: missing imports (DatabaseQueue trait, Job, json!, Arc, Mutex, Duration, Uuid, JobPriority, ResultStorage, ...), feature-gated so default, postgres, mysql and --all-features builds are all warning-free. API drift: ArchivalStats::bytes_purged, WebSocketConfig::message_buffer_size/max_message_size.
  • Conventions: DB tests that weren't #[ignore] now are (jobrow_query_tests, result_storage_tests). DB-free tests moved out of DB-gated modules so they run under plain cargo test.
  • tests/test_utils.rs:
    • Reads DATABASE_URL / MYSQL_DATABASE_URL with the documented defaults.
    • unique_queue() gives each test its own queue name.
    • serial() is a per-binary lock for tests that archive or purge across all queues.
    • lazy_postgres_pool() serves tests that need a Pool but no database.
    • skip_known_bug() gates the tests marked as known bugs.
  • Isolation: the test databases are shared and never reset. Tests used to dequeue each other's leftover jobs from shared queue names like test_queue; they now use unique names. Fixed sleeps that let tests pass without doing anything are replaced with polling for completion.
  • Compile-only tests made real: three archiver config/pool tests built futures that never ran (one asserted ptr::eq on two different values). They now run against a lazily connected pool.
  • Wrong expectations corrected: the compression ratio is documented as original/compressed, so compressed data gives a ratio > 1. ArchivedJob::status is the status the job had before it was archived. A 1-minute archival policy must not archive a job that just completed. The web test for an invalid DB URL now asserts that start() fails, which is where the URL is validated.
  • Removed:
    • tests/result_storage_debug.rs: a scratch file. Its one unique case (the stored result survives complete_job) moved into result_storage_tests for both backends.
    • Two jobarchiver_pool_tests that duplicated or were subsets of comprehensive_archive_tests.
    • comprehensive_archive_tests::test_jobarchiver_public_pool_patterns, which duplicated test_jobarchiver_with_public_pool_field.
    • An unused web test helper module that referenced SQLite.

Known library bugs (tests ignored, not fixed here)

These tests are #[ignore = "bug: ..., see #7"]. CI runs --include-ignored, so they also return early unless HAMMERWORK_TEST_KNOWN_BUGS=1 is set. To reproduce: HAMMERWORK_TEST_KNOWN_BUGS=1 cargo test --all-features --test <file> -- --include-ignored.

  1. archive_jobs doesn't move or mark the job. It copies the row to hammerwork_jobs_archive but leaves it in hammerwork_jobs with its old status, only setting archived_at (src/queue/postgres.rs:2277, src/queue/mysql.rs:2106). get_job afterwards returns Completed, not Archived. docs/archiving.md says archived jobs leave the main table.
  2. restore_archived_job fails with a duplicate key. Because of bug 1, the re-insert via enqueue_with_tx (postgres.rs:2413, mysql.rs:2244) hits 23505 hammerwork_jobs_pkey.
  3. list_archived_jobs always reports ArchivalReason::Automatic. The reason is stored with Display (Manual) but parsed with serde_json::from_str, which expects "Manual" in quotes, so parsing falls back to Automatic (postgres.rs:2507, mysql.rs:2324).
  4. MySQL get_archival_stats fails to decode. SUM() returns DECIMAL, which is decoded as i64 (mysql.rs:2372).
  5. JobArchiver::archive_jobs_with_progress / _with_events archive a single batch. They call archive_jobs once, which truncates to policy.batch_size (postgres.rs:2191), so 25 jobs with batch size 10 archive 10. The docs say they handle batch processing for large datasets.
  6. Postgres get_batch_status fails to decode the status column. impl Type<Postgres> for BatchStatus (src/batch.rs:62) has no compatible(), so the VARCHAR column fails (postgres.rs:1085). MySQL is fine.
  7. WebDashboard::start() panics with CORS disabled. It panics with "missing scheme" from warp::cors().allow_origin("none") (hammerwork-web/src/server.rs, CORS setup in start).
  8. The dashboard rejects MySQL URLs when both postgres and mysql features are enabled (hammerwork-web/src/server.rs, create_job_queue_with_type).

Verification (local, PostgreSQL 16 and MySQL 8)

  • cargo fmt --all --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings: nothing in tests/ or hammerwork-web/tests/. The remaining findings are in cargo-hammerwork src and tests.
  • Same commands as the CI integration jobs, run for the hammerwork and hammerwork-web test targets:
    • Postgres: cargo test --all-features --test '*' -- --include-ignored --skip mysql passes.
    • MySQL: cargo test --all-features --test '*' -- --include-ignored mysql, with both URLs pointing at MySQL, passes.
  • Plain cargo test --workspace --all-features --test '*' with no database passes.

Within a binary, tests can run in parallel: tests that touch every queue take test_utils::serial().

Outside this PR's scope: cargo-hammerwork/tests/sql_query_tests.rs has 3 Postgres failures and clippy errors.

🤖 Generated with Claude Code

Fix the root `tests/` targets and `hammerwork-web/tests` so they build
under `--all-features --all-targets` and pass against PostgreSQL 16 and
MySQL 8, including ignored DB tests.

- Add missing imports (DatabaseQueue trait, Job, json!, Arc, Mutex,
  Duration, Uuid, ...) with feature gating that keeps every feature
  combination warning-free; update to current APIs (ArchivalStats
  bytes_purged, WebSocketConfig message_buffer_size/max_message_size).
- Mark DB tests that lacked it `#[ignore]` (jobrow_query_tests,
  result_storage_tests) and move DB-free tests out of DB modules.
- test_utils: env-var URLs with documented defaults, unique queue names,
  a per-binary serial lock for tests that archive/purge across queues,
  a lazily connected pool for tests that need a pool but no database,
  and a known-bug guard.
- Use unique queue names so tests don't dequeue each other's leftovers
  in shared databases; poll for completion instead of fixed sleeps.
- Turn never-executed "compile-only" archiver tests into real tests.
- Correct wrong expectations (compression ratio is original/compressed,
  ArchivedJob::status is the pre-archive status, a 1-minute policy must
  not archive a just-completed job); strengthen weak ones.
- Remove tests/result_storage_debug.rs (scratch file; its one unique
  case moved into result_storage_tests) and two duplicate archiver tests.
- Tests exposing library bugs are `#[ignore = "bug: ..., see #7"]` and
  skip unless HAMMERWORK_TEST_KNOWN_BUGS is set, since CI runs ignored
  tests.

Refs #7

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@CodingAnarchy

Copy link
Copy Markdown
Owner Author

CI verification: every target in this PR's scope passes on both PostgreSQL 16 and MySQL 8. The remaining red jobs are owned elsewhere:

@CodingAnarchy
CodingAnarchy merged commit 14159b9 into master Oct 8, 2026
1 of 6 checks passed
CodingAnarchy added a commit that referenced this pull request Oct 8, 2026
Archive (PostgreSQL and MySQL):
- archive_jobs selects candidates with FOR UPDATE SKIP LOCKED and moves
  each row (insert into hammerwork_jobs_archive + delete from
  hammerwork_jobs) in one transaction
- get_job falls back to the archive table and returns JobStatus::Archived
- restore_archived_job moves the row back atomically and returns
  JobNotFound when the id is not archived
- archival_reason is stored and parsed via ArchivalReason::as_str /
  parse_from_db (plain and legacy JSON-quoted forms)
- MySQL get_archival_stats casts SUM() to SIGNED
- JobArchiver progress/events loop over batches until none remain

Batch:
- BatchStatus/JobStatus implement compatible() so Postgres VARCHAR
  columns decode
- get_batch_status tallies progress from the batch's jobs (including
  archived ones) instead of the never-updated stored counters

Un-gates the known-bug tests from #12 and adds regression tests.

Part of #14.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CodingAnarchy added a commit that referenced this pull request Oct 8, 2026
* fix: move archived jobs atomically and report live batch progress

Archive (PostgreSQL and MySQL):
- archive_jobs selects candidates with FOR UPDATE SKIP LOCKED and moves
  each row (insert into hammerwork_jobs_archive + delete from
  hammerwork_jobs) in one transaction
- get_job falls back to the archive table and returns JobStatus::Archived
- restore_archived_job moves the row back atomically and returns
  JobNotFound when the id is not archived
- archival_reason is stored and parsed via ArchivalReason::as_str /
  parse_from_db (plain and legacy JSON-quoted forms)
- MySQL get_archival_stats casts SUM() to SIGNED
- JobArchiver progress/events loop over batches until none remain

Batch:
- BatchStatus/JobStatus implement compatible() so Postgres VARCHAR
  columns decode
- get_batch_status tallies progress from the batch's jobs (including
  archived ones) instead of the never-updated stored counters

Un-gates the known-bug tests from #12 and adds regression tests.

Part of #14.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(web): start without CORS, pick backend from URL scheme

- With CORS disabled no CORS filter is installed (warp panicked on
  allow_origin("none"))
- The server is generic over DatabaseQueue and chooses PostgreSQL or
  MySQL from the database URL, so MySQL URLs work with both features
- The connection pool honours pool_size
- Building without a database feature fails with one clear
  compile_error!

Part of #14.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(cli): use UUID[] depends_on and typed job list filters on Postgres

- spawn queries use `depends_on @> ARRAY[parent.id]` (the column is
  UUID[] since migration 012, not JSONB); spawn/workflow decode the
  arrays as UUID[]
- job list binds parameters, maps status names to the stored values and
  priority names to the integer column, and decodes priority as i32
- sql_query_tests mirror the fixed queries; drop always-true
  `len() >= 0` asserts flagged by clippy

Part of #14.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: changelog for #14 fixes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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