Skip to content

Jobs backend parity refactor first slice#2527

Merged
rmusser01 merged 16 commits into
devfrom
codex/jobs-backend-parity-first-slice
Jul 4, 2026
Merged

Jobs backend parity refactor first slice#2527
rmusser01 merged 16 commits into
devfrom
codex/jobs-backend-parity-first-slice

Conversation

@rmusser01

@rmusser01 rmusser01 commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds Jobs backend parity design, implementation plan, inventory, and Backlog tracking for the first slice.
  • Refactors Jobs idempotency/completion coverage through shared SQLite/Postgres parity scenarios and adds API/domain mapping contract tests.
  • Introduces typed Jobs settings refresh classification and operation result contract scaffolding to prepare backend extraction without changing runtime behavior.

Test Plan

  • RUN_JOBS=1 python -m pytest tldw_Server_API/tests/Jobs/test_jobs_idempotency_scope_sqlite.py tldw_Server_API/tests/Jobs/test_jobs_idempotency_scope_postgres.py tldw_Server_API/tests/Jobs/test_jobs_completion_idempotent_sqlite.py tldw_Server_API/tests/Jobs/test_jobs_completion_idempotent_postgres.py tldw_Server_API/tests/Jobs/parity/test_sqlite_parity.py tldw_Server_API/tests/Jobs/parity/test_postgres_parity.py tldw_Server_API/tests/Jobs/test_jobs_admin_contract_sqlite.py tldw_Server_API/tests/Chatbooks/test_chatbooks_jobs_adapter.py tldw_Server_API/tests/Jobs/test_jobs_settings.py tldw_Server_API/tests/Jobs/test_jobs_operation_contracts.py -q
  • python -m bandit -q -s B101 -r touched Jobs/Chatbooks test scope
  • git diff --check origin/dev...HEAD

Change summary

Human-authored Change summary required before merge per project policy. Replace this section with the requester-owned explanation of what changed and why these choices were made.


Summary by cubic

Adds a shared Jobs parity harness for SQLite/Postgres and typed settings/operation contracts to lock current API behavior ahead of backend extraction. Ships design/plan/inventory docs and admin API contract tests; no runtime changes.

  • Refactors

    • Added shared parity scenarios: idempotent create scope and original request-id, acquire/complete lifecycle (idempotent completion), stale lease renew no-op, cancel terminal no-op, and events outbox on create/complete.
    • Consolidated legacy tests into helpers; added SQLite/Postgres wrappers; hardened Chatbooks adapter status mappings and isolated it from a real Jobs manager.
    • Added AST-based contract tests to lock JOBS_* env keys, settings classification, and operation enums/fields with invariant checks.
  • New Features

    • Added tldw_Server_API/app/core/Jobs/settings.py with JobsSettings and refresh classification modes.
    • Added tldw_Server_API/app/core/Jobs/operations/contracts.py with OperationOutcome/NoTransitionReason and command/result dataclasses.
    • Added design, plan, and inventory docs defining the first-slice compatibility boundary.

Written for commit a229304. Summary will update on new commits.

Review in cubic

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 00364e6f-6276-4bcf-85f6-161830e63258

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/jobs-backend-parity-first-slice

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements the first slice of the Jobs backend parity refactor, introducing a direct-SQL inventory, shared SQLite/Postgres parity scenarios with wrappers, public API and Chatbooks mapping contract tests, explicit JobsSettings snapshot/refresh semantics, and typed operation contracts. The review feedback highlights several key improvements: using deep copies instead of shallow copies in AdmissionResult and LifecycleResult to ensure nested structures remain immutable; fixing a bug in JobsSettings where None values are converted to the string 'None'; resolving relative paths in tests relative to file to ensure they run reliably from any directory; and explicitly creating the parent directory for the SQLite database path to prevent potential operational errors.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread tldw_Server_API/app/core/Jobs/operations/contracts.py Outdated
Comment thread tldw_Server_API/app/core/Jobs/operations/contracts.py Outdated
Comment thread tldw_Server_API/app/core/Jobs/settings.py
Comment thread tldw_Server_API/tests/Jobs/test_jobs_settings.py
Comment thread tldw_Server_API/tests/Jobs/test_jobs_operation_contracts.py Outdated
Comment thread tldw_Server_API/tests/Jobs/test_jobs_admin_contract_sqlite.py Outdated
@rmusser01 rmusser01 force-pushed the codex/jobs-backend-parity-first-slice branch from 4e2ccc6 to f58fe96 Compare June 26, 2026 06:29
@rmusser01 rmusser01 marked this pull request as ready for review June 26, 2026 06:57
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Jobs backend parity safety net: shared scenarios, contracts, and docs
📝 Documentation 🧪 Tests ✨ Enhancement 🕐 40+ Minutes

Grey Divider

Description

• Document first-slice Jobs backend parity boundaries, plan, and tracking gates before SQL
 extraction.
• Add shared SQLite/Postgres parity scenarios and wrappers; refactor existing idempotency/completion
 tests.
• Lock public contracts (admin list/detail, Chatbooks mapping) and scaffold typed settings/operation
 results.
Diagram

graph TD
  JM["JobManager facade"] --> PS["Parity scenarios"] --> ST["SQLite parity tests"]
  PS --> PT["Postgres parity tests"]
  JM --> ACT["Admin API contract tests"]
  JM --> CAT["Chatbooks adapter tests"]
  JS["JobsSettings contract"] --> JM
  OC["Operation result contracts"] --> JM
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Repository abstraction first (JobsRepository interface)
  • ➕ Clear separation between business logic and persistence early
  • ➕ Encourages consistent behavior across backends by construction
  • ➖ High upfront churn across JobManager methods
  • ➖ Harder to ensure API compatibility without prior parity/contract coverage
  • ➖ More difficult to review incrementally
2. Snapshot-based API compatibility tests
  • ➕ Fast to author and can detect broad response drift
  • ➖ Brittle to harmless ordering/formatting changes
  • ➖ Encourages overfitting to incidental response details
  • ➖ Less helpful for isolating backend semantic differences (leases/idempotency/outbox)
3. Extract backend operations immediately (without parity harness)
  • ➕ Accelerates moving SQL behind the desired boundaries
  • ➖ Higher risk of SQLite/Postgres drift and public contract regressions
  • ➖ Harder to prove unchanged behavior; debugging regressions becomes costlier

Recommendation: Keep the PR’s current strategy: parity/contract safety net first, then incremental extraction behind JobManager. This sequencing minimizes behavioral risk while creating reusable, backend-agnostic scenarios and explicit typed contracts (settings + operation outcomes) that later extraction PRs can plug into with confidence.

Files changed (21) +3456 / -103

Enhancement (3) +378 / -0
__init__.pyCreate Jobs operations package marker +1/-0

Create Jobs operations package marker

• Introduces the operations package namespace intended for backend-specific operation contracts and implementations.

tldw_Server_API/app/core/Jobs/operations/init.py

contracts.pyTyped operation contracts: commands, outcomes, and invariants +178/-0

Typed operation contracts: commands, outcomes, and invariants

• Adds enums for operation outcomes and no-transition/admission rejection reasons, plus frozen dataclasses for CreateJobCommand, AdmissionResult, and LifecycleResult. Enforces invariants in __post_init__ and shallow-copies mutable row/event payloads to keep results stable.

tldw_Server_API/app/core/Jobs/operations/contracts.py

settings.pyJobsSettings: env snapshot/refresh semantics and key classification +199/-0

JobsSettings: env snapshot/refresh semantics and key classification

• Introduces immutable JobsSettings with explicit refresh behavior (preserving construction-time DB config while refreshing other values). Adds key classification (construction-time vs snapshot-refreshable vs operation-time vs unclassified) and domain-aware allowed-queue extras parsing with de-duplication.

tldw_Server_API/app/core/Jobs/settings.py

Tests (12) +915 / -103
test_chatbooks_jobs_adapter.pyChatbooks adapter contract tests for status and ID mapping +100/-0

Chatbooks adapter contract tests for status and ID mapping

• Extends tests to lock status mapping behavior (including terminal status preservation) and job-id selection (preferring payload chatbooks_job_id). Adds an autouse fixture to avoid accidental real JobManager usage by default and uses a fake manager for map_jobs assertions.

tldw_Server_API/tests/Chatbooks/test_chatbooks_jobs_adapter.py

__init__.pyCreate parity helpers package marker +1/-0

Create parity helpers package marker

• Adds the parity package for shared backend scenario helpers.

tldw_Server_API/tests/Jobs/parity/init.py

scenarios.pyShared SQLite/Postgres Jobs parity scenarios +211/-0

Shared SQLite/Postgres Jobs parity scenarios

• Defines reusable scenario functions asserting backend-invariant behavior: idempotent create scope, request/trace preservation on idempotent replay, acquire→complete lifecycle, completion idempotency, stale lease renew no-op, cancel terminal no-op, and events outbox creation.

tldw_Server_API/tests/Jobs/parity/scenarios.py

test_postgres_parity.pyPostgres parity wrapper executing shared scenarios +48/-0

Postgres parity wrapper executing shared scenarios

• Adds pg_jobs-marked tests that run the shared parity scenarios against a Postgres-backed JobManager using the existing jobs_pg_dsn fixture.

tldw_Server_API/tests/Jobs/parity/test_postgres_parity.py

test_sqlite_parity.pySQLite parity wrapper executing shared scenarios +48/-0

SQLite parity wrapper executing shared scenarios

• Adds tests that run the shared parity scenarios against SQLite-backed JobManager with migrations applied and relevant env flags set for test behavior (lease enforcement disabled, outbox enabled).

tldw_Server_API/tests/Jobs/parity/test_sqlite_parity.py

test_jobs_admin_contract_sqlite.pyAdmin API field-level contract for list/detail endpoints +109/-0

Admin API field-level contract for list/detail endpoints

• Introduces a minimal FastAPI TestClient contract test verifying required public fields for /api/v1/jobs/list and /api/v1/jobs/{id}. Ensures the test environment forces SQLite (clears JOBS_DB_URL) and validates payload/result/archived invariants.

tldw_Server_API/tests/Jobs/test_jobs_admin_contract_sqlite.py

test_jobs_completion_idempotent_postgres.pyRefactor Postgres completion idempotency to shared scenario +3/-19

Refactor Postgres completion idempotency to shared scenario

• Replaces inline completion idempotency assertions with a call to the shared run_complete_idempotency_scenario helper using a Postgres JobManager factory.

tldw_Server_API/tests/Jobs/test_jobs_completion_idempotent_postgres.py

test_jobs_completion_idempotent_sqlite.pyRefactor SQLite completion idempotency to shared scenario +2/-14

Refactor SQLite completion idempotency to shared scenario

• Replaces inline completion idempotency assertions with a call to the shared run_complete_idempotency_scenario helper, retaining SQLite env setup.

tldw_Server_API/tests/Jobs/test_jobs_completion_idempotent_sqlite.py

test_jobs_idempotency_scope_postgres.pyRefactor Postgres idempotent-create scope tests to shared scenarios +10/-19

Refactor Postgres idempotent-create scope tests to shared scenarios

• Consolidates duplicated Postgres idempotency assertions into shared parity scenarios and adds coverage for preserving the original request_id/trace_id on idempotent replay.

tldw_Server_API/tests/Jobs/test_jobs_idempotency_scope_postgres.py

test_jobs_idempotency_scope_sqlite.pyRefactor SQLite idempotent-create scope tests to shared scenarios +8/-51

Refactor SQLite idempotent-create scope tests to shared scenarios

• Consolidates duplicated SQLite idempotency assertions into shared parity scenarios and returns the db path fixture directly. Adds coverage for preserving the original request_id/trace_id on idempotent replay.

tldw_Server_API/tests/Jobs/test_jobs_idempotency_scope_sqlite.py

test_jobs_operation_contracts.pyContract tests for Jobs operation result dataclasses +177/-0

Contract tests for Jobs operation result dataclasses

• Adds tests that lock the shape and invariants of CreateJobCommand, AdmissionResult, and LifecycleResult, including mutable fact copying. Includes an AST-based guard ensuring operation modules do not import or reference JobManager.

tldw_Server_API/tests/Jobs/test_jobs_operation_contracts.py

test_jobs_settings.pyContract tests for JobsSettings snapshot/refresh and key coverage +198/-0

Contract tests for JobsSettings snapshot/refresh and key coverage

• Adds unit tests ensuring JobsSettings snapshots env at construction, refreshes only refreshable values while preserving construction-time DB config, and de-duplicates domain-aware allowed queue extras. Includes AST-based drift guards that ensure current manager/admin env keys are classified (no UNCLASSIFIED keys).

tldw_Server_API/tests/Jobs/test_jobs_settings.py

Documentation (6) +2163 / -0
JOBS_BACKEND_PARITY_INVENTORY_2026_06_24.mdInventory: first-slice SQL boundaries and domain mappings +42/-0

Inventory: first-slice SQL boundaries and domain mappings

• Adds an inventory defining the first-slice compatibility boundary for Jobs backend parity work. Classifies direct runtime SQL touchpoints (admin, services/workers) and documents domain status/id mapping expectations plus required first-slice gates.

Docs/Design/JOBS_BACKEND_PARITY_INVENTORY_2026_06_24.md

2026-06-24-jobs-backend-parity-refactor-implementation-plan.mdImplementation plan: parity harness + contract gates before extraction +1542/-0

Implementation plan: parity harness + contract gates before extraction

• Introduces a detailed, task-oriented implementation plan describing the first safety-net PR: shared parity scenarios, SQLite/Postgres wrappers, API/domain contract tests, JobsSettings semantics, operation contracts, and verification commands.

Docs/superpowers/plans/2026-06-24-jobs-backend-parity-refactor-implementation-plan.md

2026-06-24-jobs-backend-parity-refactor-design.mdDesign spec: parity-first refactor strategy and boundaries +384/-0

Design spec: parity-first refactor strategy and boundaries

• Adds an approved design spec defining objectives, non-goals, architecture, data flows, error/outcome typing, testing strategy, and rollout plan. Emphasizes preserving public API behavior and reducing backend drift before moving production SQL.

Docs/superpowers/specs/2026-06-24-jobs-backend-parity-refactor-design.md

task-12015 - Design-Jobs-backend-parity-refactor.mdBacklog: track completed design task (TASK-12015) +59/-0

Backlog: track completed design task (TASK-12015)

• Adds task metadata, acceptance criteria, notes, and final summary linking to the Jobs parity refactor design spec.

backlog/tasks/task-12015 - Design-Jobs-backend-parity-refactor.md

task-12016 - Plan-Jobs-backend-parity-refactor-implementation.mdBacklog: track completed planning task (TASK-12016) +53/-0

Backlog: track completed planning task (TASK-12016)

• Adds task metadata and implementation notes for the implementation planning phase, linking to the plan and design spec.

backlog/tasks/task-12016 - Plan-Jobs-backend-parity-refactor-implementation.md

task-12017 - Implement-Jobs-backend-parity-refactor-first-slice.mdBacklog: track first-slice implementation and verification evidence +83/-0

Backlog: track first-slice implementation and verification evidence

• Adds detailed step-by-step implementation notes and verification outputs for the first parity slice (SQLite pass; Postgres skipped when unavailable). Serves as an execution log and handoff artifact.

backlog/tasks/task-12017 - Implement-Jobs-backend-parity-refactor-first-slice.md

@qodo-code-review

qodo-code-review Bot commented Jun 26, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 74 rules

Grey Divider


Action required

1. settings.py missing docstrings ✓ Resolved 📘 Rule violation ✧ Quality
Description
New Jobs-related modules introduce public contracts, settings, and tests but omit required module,
class, and function/method docstrings. This violates PR Compliance ID 224214 and reduces
maintainability and auditability of the Jobs settings/operations contract and test intent.
Code

tldw_Server_API/app/core/Jobs/settings.py[R1-46]

+from __future__ import annotations
+
+import os
+from collections.abc import Mapping
+from dataclasses import dataclass, replace
+from enum import Enum
+
+from tldw_Server_API.app.core.testing import is_truthy
+
+
+class JobsSettingMode(str, Enum):
+    CONSTRUCTION_TIME = "construction_time"
+    SNAPSHOT_REFRESHABLE = "snapshot_refreshable"
+    OPERATION_TIME = "operation_time"
+    UNCLASSIFIED = "unclassified"
+
+
+def _env_value(env: Mapping[str, str], key: str, default: str | None = None) -> str | None:
+    value = env.get(key)
+    if value is None:
+        return default
+    return str(value)
+
+
+def _env_int(env: Mapping[str, str], key: str, default: int) -> int:
+    raw = _env_value(env, key)
+    if raw is None or raw == "":
+        return default
+    return int(raw)
+
+
+def _env_bool(env: Mapping[str, str], key: str, default: bool = False) -> bool:
+    raw = _env_value(env, key)
+    if raw is None:
+        return default
+    return is_truthy(str(raw))
+
+
+def _split_csv(value: str | None) -> tuple[str, ...]:
+    if not value:
+        return ()
+    return tuple(item.strip() for item in value.split(",") if item.strip())
+
+
+@dataclass(frozen=True)
+class JobsSettings:
Evidence
PR Compliance ID 224214 requires docstrings for all new or modified Python modules, classes, and
functions/methods. The cited tldw_Server_API/app/core/Jobs/settings.py begins with imports and
defines JobsSettingMode, helper functions like _env_value, _env_int, _env_bool,
_split_csv, and JobsSettings without any docstring string literals; likewise,
tldw_Server_API/app/core/Jobs/operations/contracts.py defines public enums/dataclasses such as
OperationOutcome, NoTransitionReason, AdmissionRejectionReason, CreateJobCommand,
AdmissionResult, LifecycleResult, and methods including __post_init__, applied, existing,
and rejected without docstrings. The newly added test modules (e.g., parity scenarios and
sqlite/postgres parity tests, plus admin contract tests) also define scenario runners, fixtures,
tests, and helpers without module/function docstring literals, demonstrating noncompliance across
these additions.

Rule 224214: Require docstrings for all modules, classes, and functions
tldw_Server_API/app/core/Jobs/settings.py[1-46]
tldw_Server_API/app/core/Jobs/operations/contracts.py[1-60]
tldw_Server_API/tests/Jobs/parity/scenarios.py[1-12]
tldw_Server_API/tests/Jobs/parity/test_sqlite_parity.py[1-48]
tldw_Server_API/tests/Jobs/parity/test_postgres_parity.py[1-48]
tldw_Server_API/tests/Jobs/test_jobs_admin_contract_sqlite.py[1-36]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Several newly added Jobs modules (core settings/contracts and tests) define public modules, classes/enums/dataclasses, and functions/methods without required docstrings, violating PR Compliance ID 224214.

## Issue Context
Compliance requires docstrings for all Python modules, classes, and functions/methods in new or modified files. The affected areas include the new Jobs settings module (with helpers like `_env_value`, `_env_int`, `_env_bool`, `_split_csv`, and types like `JobsSettingMode`/`JobsSettings`), the Jobs operations contracts module (with `OperationOutcome`, `NoTransitionReason`, `AdmissionRejectionReason`, `CreateJobCommand`, `AdmissionResult`, `LifecycleResult`, and methods such as `__post_init__`, `applied`, `existing`, `rejected`), and newly added test modules where scenario runners, fixtures, tests, and helper functions are missing docstrings.

## Fix Focus Areas
- tldw_Server_API/app/core/Jobs/settings.py[1-60]
- tldw_Server_API/app/core/Jobs/operations/contracts.py[1-170]
- tldw_Server_API/tests/Jobs/parity/scenarios.py[1-30]
- tldw_Server_API/tests/Jobs/parity/test_sqlite_parity.py[1-48]
- tldw_Server_API/tests/Jobs/parity/test_postgres_parity.py[1-48]
- tldw_Server_API/tests/Jobs/test_jobs_admin_contract_sqlite.py[1-40]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Parity tests missing type hints ✓ Resolved 📘 Rule violation ✧ Quality
Description
New parity wrapper tests define fixtures and test functions without parameter/return type
annotations (e.g., sqlite_manager_factory, postgres_manager_factory, and related tests). This
violates the requirement that all function parameters and return values be type-hinted.
Code

tldw_Server_API/tests/Jobs/parity/test_sqlite_parity.py[R17-48]

+@pytest.fixture()
+def sqlite_manager_factory(tmp_path, monkeypatch):
+    db_path = tmp_path / "jobs.db"
+    ensure_jobs_tables(db_path)
+    monkeypatch.setenv("JOBS_DB_PATH", str(db_path))
+    monkeypatch.setenv("JOBS_DISABLE_LEASE_ENFORCEMENT", "true")
+    monkeypatch.setenv("JOBS_EVENTS_OUTBOX", "true")
+    return lambda: JobManager(db_path)
+
+
+def test_sqlite_idempotent_create_scope(sqlite_manager_factory):
+    run_idempotent_create_scope_scenario(sqlite_manager_factory)
+
+
+def test_sqlite_idempotent_create_preserves_request_ids(sqlite_manager_factory):
+    run_idempotent_create_preserves_original_request_ids_scenario(sqlite_manager_factory)
+
+
+def test_sqlite_acquire_complete_lifecycle(sqlite_manager_factory):
+    run_acquire_complete_lifecycle_scenario(sqlite_manager_factory)
+
+
+def test_sqlite_renew_stale_lease_noop(sqlite_manager_factory):
+    run_renew_stale_lease_noop_scenario(sqlite_manager_factory)
+
+
+def test_sqlite_cancel_terminal_noop(sqlite_manager_factory):
+    run_cancel_terminal_noop_scenario(sqlite_manager_factory)
+
+
+def test_sqlite_events_outbox_create_complete(sqlite_manager_factory):
+    run_events_outbox_create_complete_scenario(sqlite_manager_factory)
Evidence
PR Compliance ID 224215 requires every function to have typed parameters and an explicit return
annotation. The cited new test modules include fixture and test function definitions with
unannotated parameters and/or missing -> None return annotations.

Rule 224215: Require type hints on all function parameters and return values
tldw_Server_API/tests/Jobs/parity/test_sqlite_parity.py[17-48]
tldw_Server_API/tests/Jobs/parity/test_postgres_parity.py[19-48]
tldw_Server_API/tests/Jobs/test_jobs_admin_contract_sqlite.py[12-40]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
New test functions/fixtures were added without complete type hints for parameters and return types.

## Issue Context
Compliance requires explicit type hints on all function parameters and return values. For pytest fixtures, consider annotating `monkeypatch` as `pytest.MonkeyPatch`, `tmp_path` as `pathlib.Path`, and fixture returns as `Callable[[], JobManager]`; test functions should return `None`.

## Fix Focus Areas
- tldw_Server_API/tests/Jobs/parity/test_sqlite_parity.py[17-48]
- tldw_Server_API/tests/Jobs/parity/test_postgres_parity.py[19-48]
- tldw_Server_API/tests/Jobs/test_jobs_admin_contract_sqlite.py[12-40]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Jobs tests bypass RUN_JOBS ✓ Resolved 🐞 Bug ☼ Reliability
Description
The new Jobs parity and admin contract tests are missing the jobs marker, so they will still be
collected/executed when RUN_JOBS is unset even though the repo gate only skips tests marked
jobs/pg_jobs/pg_jobs_stress. This can unexpectedly run FastAPI/Jobs DB setup in default CI
runs and increase runtime/flakiness outside the dedicated Jobs workflow.
Code

tldw_Server_API/tests/Jobs/parity/test_sqlite_parity.py[R1-6]

+from __future__ import annotations
+
+import pytest
+
+from tldw_Server_API.app.core.Jobs.manager import JobManager
+from tldw_Server_API.app.core.Jobs.migrations import ensure_jobs_tables
Evidence
The pytest collection hook only skips tests that have explicit Jobs markers when RUN_JOBS is
unset; the new parity/admin contract tests do not declare those markers, so they will run by
default.

tldw_Server_API/tests/conftest.py[592-616]
tldw_Server_API/tests/Jobs/parity/test_sqlite_parity.py[1-24]
tldw_Server_API/tests/Jobs/test_jobs_admin_contract_sqlite.py[1-25]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The repo uses a collection-time gate to skip Jobs tests unless `RUN_JOBS` is enabled, but it only applies to tests explicitly marked `jobs`/`pg_jobs`/`pg_jobs_stress`. Newly added Jobs parity/admin contract tests are unmarked, so they will still run in default test workflows.

## Issue Context
- The repository-level pytest hook only skips tests with Jobs markers when `RUN_JOBS` is not truthy.
- The new parity/admin contract tests currently have no `pytestmark = pytest.mark.jobs` (or per-test `@pytest.mark.jobs`).

## Fix Focus Areas
- tldw_Server_API/tests/Jobs/parity/test_sqlite_parity.py[1-10]
- tldw_Server_API/tests/Jobs/test_jobs_admin_contract_sqlite.py[1-12]

### Suggested change
Add at module scope:
```python
import pytest
pytestmark = pytest.mark.jobs
```
- Keep `test_postgres_parity.py` as `pg_jobs` (already marked). If you want SQLite parity tests also gated behind RUN_JOBS, marking them `jobs` will align with the gate.
- If the intent is instead for these tests to always run, update/clarify the gate comment and/or CI selection logic accordingly (but the current hook comment asserts default CI should not run Jobs tests).

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Comment thread tldw_Server_API/app/core/Jobs/settings.py
Comment thread tldw_Server_API/tests/Jobs/parity/test_sqlite_parity.py
Comment thread tldw_Server_API/tests/Jobs/parity/test_sqlite_parity.py
@rmusser01 rmusser01 force-pushed the codex/jobs-backend-parity-first-slice branch 2 times, most recently from 855de0c to f960d81 Compare July 4, 2026 00:08
@rmusser01

Copy link
Copy Markdown
Owner Author

Addressed the open review items in 73eb4a1096:

  • Deep-copy nested row/event facts in AdmissionResult and LifecycleResult, with regression coverage.
  • Avoid converting None domain queue values into a literal "None" queue, with regression coverage.
  • Resolve AST guard paths from __file__ and assert scanned files so tests do not silently bypass outside repo root.
  • Create the SQLite admin test DB parent directory explicitly.
  • Add docstrings and complete type hints across the new/modified Jobs settings, operation contract, and parity/admin test files.
  • Existing RUN_JOBS marker fix remains in place.

Local verification: focused Jobs/Chatbooks matrix 46 passed, 9 skipped with Postgres skips due to local Postgres being unreachable; Bandit touched scope clean; git diff --check clean; docstring/type-hint AST scan clean.

@rmusser01 rmusser01 force-pushed the codex/jobs-backend-parity-first-slice branch from 73eb4a1 to a229304 Compare July 4, 2026 01:07
@rmusser01 rmusser01 merged commit 0bb8235 into dev Jul 4, 2026
18 of 19 checks passed
@rmusser01 rmusser01 deleted the codex/jobs-backend-parity-first-slice branch July 4, 2026 01:23
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