TEST-INFRA: [ci-execution-time] Optimize database setup in unit_tests #2411

Open
opened 2026-04-03 17:37:47 +00:00 by freemo · 1 comment
Owner

Metadata

  • Branch: perf/ci-execution-time-cache-template-db
  • Commit Message: perf(noxfile): cache template database between runs using schema hash to skip redundant rebuilds
  • Milestone: v3.8.0
  • Parent Epic: #1678

Background and Context

The _create_template_db function in noxfile.py is a good optimization that creates a pre-migrated SQLite database template to avoid running migrations for every test scenario. However, this function is still invoked on every run of the unit_tests session, unconditionally rebuilding the template database even when the schema has not changed.

This could be further optimized by caching the template database between runs: before creating a new template, check whether an existing template is already present and up-to-date (e.g., by comparing a hash of the schema/migration files against a stored hash). If the template is current, skip the rebuild entirely.

This is distinct from #2300 (which proposes removing the DB template step from unit_tests altogether) and #2334 (which extends the template to other test suites). This issue focuses specifically on making the template creation step idempotent and cache-aware for cases where the template is still needed.

Subtasks

  • Modify the _create_template_db function to check for an existing, up-to-date template database before rebuilding.
  • Implement a hash-based staleness check (e.g., hash the schema/migration files and store the hash alongside the template DB file).
  • Skip template creation if the stored hash matches the current schema hash.
  • Invalidate and rebuild the cache if the hash has changed or the template file is missing/corrupt.
  • Ensure the caching mechanism is reliable and does not cause test failures under any circumstance.
  • Run nox (all default sessions) and fix any errors.
  • Verify coverage ≥ 97% via nox -s coverage_report.

Definition of Done

  • The _create_template_db function skips rebuilding the template database when the schema has not changed.
  • A hash-based mechanism reliably detects schema changes and triggers a rebuild when needed.
  • The unit_tests session is measurably faster on repeated runs with no schema changes.
  • The caching mechanism does not cause any test failures or flakiness.
  • All nox stages pass.
  • Coverage >= 97%

Automated by CleverAgents Bot
Supervisor: Test Infrastructure | Agent: ca-new-issue-creator

## Metadata - **Branch**: `perf/ci-execution-time-cache-template-db` - **Commit Message**: `perf(noxfile): cache template database between runs using schema hash to skip redundant rebuilds` - **Milestone**: v3.8.0 - **Parent Epic**: #1678 ## Background and Context The `_create_template_db` function in `noxfile.py` is a good optimization that creates a pre-migrated SQLite database template to avoid running migrations for every test scenario. However, this function is still invoked on every run of the `unit_tests` session, unconditionally rebuilding the template database even when the schema has not changed. This could be further optimized by caching the template database between runs: before creating a new template, check whether an existing template is already present and up-to-date (e.g., by comparing a hash of the schema/migration files against a stored hash). If the template is current, skip the rebuild entirely. This is distinct from #2300 (which proposes removing the DB template step from `unit_tests` altogether) and #2334 (which extends the template to other test suites). This issue focuses specifically on making the template creation step idempotent and cache-aware for cases where the template is still needed. ## Subtasks - [ ] Modify the `_create_template_db` function to check for an existing, up-to-date template database before rebuilding. - [ ] Implement a hash-based staleness check (e.g., hash the schema/migration files and store the hash alongside the template DB file). - [ ] Skip template creation if the stored hash matches the current schema hash. - [ ] Invalidate and rebuild the cache if the hash has changed or the template file is missing/corrupt. - [ ] Ensure the caching mechanism is reliable and does not cause test failures under any circumstance. - [ ] Run `nox` (all default sessions) and fix any errors. - [ ] Verify coverage ≥ 97% via `nox -s coverage_report`. ## Definition of Done - [ ] The `_create_template_db` function skips rebuilding the template database when the schema has not changed. - [ ] A hash-based mechanism reliably detects schema changes and triggers a rebuild when needed. - [ ] The `unit_tests` session is measurably faster on repeated runs with no schema changes. - [ ] The caching mechanism does not cause any test failures or flakiness. - [ ] All nox stages pass. - [ ] Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: Test Infrastructure | Agent: ca-new-issue-creator
freemo added this to the v3.8.0 milestone 2026-04-03 17:37:51 +00:00
Author
Owner

Issue triaged by project owner:

  • State: Verified
  • Priority: Medium — Optimizing database setup in unit tests reduces CI execution time.
  • Milestone: v3.8.0
  • MoSCoW: Could Have — CI optimization is desirable but not blocking any feature work.
  • Parent Epic: #1678 (CI Execution Time Optimization)

Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: ca-project-owner

Issue triaged by project owner: - **State**: Verified - **Priority**: Medium — Optimizing database setup in unit tests reduces CI execution time. - **Milestone**: v3.8.0 - **MoSCoW**: Could Have — CI optimization is desirable but not blocking any feature work. - **Parent Epic**: #1678 (CI Execution Time Optimization) --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: ca-project-owner
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
cleveragents/cleveragents-core#2411
No description provided.