Skip to content

Commit dd66659

Browse files
committed
refactor: clarify sync queue boundary
1 parent 7cf3347 commit dd66659

6 files changed

Lines changed: 44 additions & 47 deletions

File tree

src/codealmanac/cli/dispatch/sync.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from codealmanac.core.errors import ValidationFailed
1010
from codealmanac.services.sources.models import TranscriptApp
1111
from codealmanac.workflows.sync.requests import (
12-
RunSyncRequest,
13-
RunSyncStatusRequest,
12+
SyncRequest,
13+
SyncStatusRequest,
1414
)
1515

1616

@@ -19,7 +19,7 @@ def dispatch_sync(args: argparse.Namespace, app: CodeAlmanac) -> int:
1919
return dispatch_sync_status(args, app)
2020
cli_config = load_cli_config(app, args.wiki)
2121
result = app.workflows.sync.run(
22-
RunSyncRequest(
22+
SyncRequest(
2323
repository_name=args.wiki,
2424
apps=parse_sync_apps(args.source_apps),
2525
harness=resolve_harness(args.using, cli_config),
@@ -32,7 +32,7 @@ def dispatch_sync(args: argparse.Namespace, app: CodeAlmanac) -> int:
3232

3333
def dispatch_sync_status(args: argparse.Namespace, app: CodeAlmanac) -> int:
3434
result = app.workflows.sync.status(
35-
RunSyncStatusRequest(
35+
SyncStatusRequest(
3636
repository_name=args.wiki,
3737
apps=parse_sync_apps(args.source_apps),
3838
)

src/codealmanac/workflows/sync/execution.py renamed to src/codealmanac/workflows/sync/queue.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
SyncStarted,
1212
SyncWorkItem,
1313
)
14-
from codealmanac.workflows.sync.requests import RunSyncRequest
14+
from codealmanac.workflows.sync.requests import SyncRequest
1515
from codealmanac.workflows.sync.store import SyncStateStore
1616
from codealmanac.workflows.sync.summary import (
1717
skipped_transcript,
1818
started_repository,
1919
)
2020

2121

22-
class SyncRunExecutor:
22+
class SyncIngestQueue:
2323
def __init__(
2424
self,
2525
queue: RunQueue,
@@ -30,10 +30,10 @@ def __init__(
3030

3131
def run(
3232
self,
33-
request: RunSyncRequest,
33+
request: SyncRequest,
3434
evaluation: SyncEvaluation,
3535
now: datetime,
36-
) -> "SyncRunExecutionResult":
36+
) -> "SyncQueueResult":
3737
started: list[SyncStarted] = []
3838
skipped = list(evaluation.summary.skipped)
3939
worker_cwd = None
@@ -66,19 +66,19 @@ def run(
6666
for candidate in item.transcripts
6767
)
6868
self.state_store.record_completed(now)
69-
return SyncRunExecutionResult(
69+
return SyncQueueResult(
7070
started=tuple(started),
7171
skipped=tuple(skipped),
7272
)
7373

7474

75-
class SyncRunExecutionResult(CodeAlmanacModel):
75+
class SyncQueueResult(CodeAlmanacModel):
7676
started: tuple[SyncStarted, ...]
7777
skipped: tuple[SyncSkipped, ...]
7878

7979

8080
def sync_ingest_request(
81-
request: RunSyncRequest,
81+
request: SyncRequest,
8282
item: SyncWorkItem,
8383
) -> IngestRequest:
8484
return IngestRequest(

src/codealmanac/workflows/sync/requests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ def positive_interval(cls, value: timedelta) -> timedelta:
3535
return value
3636

3737

38-
class RunSyncStatusRequest(SyncSelectionRequest):
38+
class SyncStatusRequest(SyncSelectionRequest):
3939
pass
4040

4141

42-
class RunSyncRequest(SyncSelectionRequest):
42+
class SyncRequest(SyncSelectionRequest):
4343
harness: HarnessKind
4444
auto_commit: bool = True

src/codealmanac/workflows/sync/service.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
from codealmanac.services.sources.service import SourcesService
55
from codealmanac.workflows.run_queue.service import RunQueue
66
from codealmanac.workflows.sync.evaluation import SyncEvaluator
7-
from codealmanac.workflows.sync.execution import SyncRunExecutor
87
from codealmanac.workflows.sync.models import (
98
SyncEvaluation,
109
SyncMode,
1110
SyncSummary,
1211
)
12+
from codealmanac.workflows.sync.queue import SyncIngestQueue
1313
from codealmanac.workflows.sync.requests import (
14-
RunSyncRequest,
15-
RunSyncStatusRequest,
14+
SyncRequest,
1615
SyncSelectionRequest,
16+
SyncStatusRequest,
1717
)
1818
from codealmanac.workflows.sync.store import SyncStateStore
1919

@@ -31,15 +31,15 @@ def __init__(
3131
sources=sources,
3232
state_store=state_store,
3333
)
34-
self.executor = SyncRunExecutor(
34+
self.executor = SyncIngestQueue(
3535
queue=queue,
3636
state_store=state_store,
3737
)
3838

39-
def status(self, request: RunSyncStatusRequest) -> SyncSummary:
39+
def status(self, request: SyncStatusRequest) -> SyncSummary:
4040
return self.evaluate(request, SyncMode.STATUS).summary
4141

42-
def run(self, request: RunSyncRequest) -> SyncSummary:
42+
def run(self, request: SyncRequest) -> SyncSummary:
4343
now = request.now or datetime.now(UTC)
4444
evaluation = self.evaluate(request, SyncMode.SYNC, now=now)
4545
effects = self.executor.run(request, evaluation, now)

tests/test_architecture.py

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ def test_cli_dispatch_edge_is_split_by_command_domain():
831831
assert "dispatch_lifecycle(args, app)" in dispatch_root
832832
assert "dispatch_wiki(args, app)" in dispatch_root
833833
assert "dispatch_admin(args, app)" in dispatch_root
834-
assert "RunIngestRequest" not in dispatch_root
834+
assert "IngestRequest" not in dispatch_root
835835
assert "SearchPagesRequest" not in dispatch_root
836836
assert "AutomationStatusRequest" not in dispatch_root
837837
assert "DoctorRequest" not in dispatch_root
@@ -972,23 +972,23 @@ def test_cli_lifecycle_dispatch_stays_split_by_command_family():
972972
lifecycle = (dispatch_path / "lifecycle.py").read_text(encoding="utf-8")
973973
module_expectations = {
974974
"build.py": ("InitializeRepositoryRequest", "def dispatch_build("),
975-
"operations.py": ("RunIngestRequest", "def dispatch_ingest("),
976-
"sync.py": ("RunSyncRequest", "def dispatch_sync("),
975+
"operations.py": ("IngestRequest", "def dispatch_ingest("),
976+
"sync.py": ("SyncRequest", "def dispatch_sync("),
977977
"worker.py": ("DrainRunQueueRequest", "def dispatch_run_worker("),
978978
}
979979
forbidden_lifecycle_fragments = (
980980
"InitializeRepositoryRequest",
981-
"RunIngestRequest",
981+
"IngestRequest",
982982
"RunGardenRequest",
983-
"RunSyncRequest",
984-
"RunSyncStatusRequest",
983+
"SyncRequest",
984+
"SyncStatusRequest",
985985
"DrainRunQueueRequest",
986986
"TranscriptApp",
987987
"ValidationFailed",
988988
"load_cli_config",
989989
"resolve_harness",
990990
"parse_sync_apps",
991-
"sync_execution",
991+
"sync_queue",
992992
"render_",
993993
)
994994
oversized = []
@@ -1651,13 +1651,13 @@ def test_sync_workflow_policy_stays_out_of_service_orchestration():
16511651
)
16521652

16531653

1654-
def test_sync_execution_effects_stay_out_of_service_orchestration():
1654+
def test_sync_queue_effects_stay_out_of_service_orchestration():
16551655
sync_root = SRC_ROOT / "workflows/sync"
16561656
service_text = (sync_root / "service.py").read_text(encoding="utf-8")
16571657
evaluation_text = (sync_root / "evaluation.py").read_text(encoding="utf-8")
1658-
execution_text = (sync_root / "execution.py").read_text(encoding="utf-8")
1658+
queue_text = (sync_root / "queue.py").read_text(encoding="utf-8")
16591659
forbidden_service_fragments = (
1660-
"RunIngestRequest",
1660+
"IngestRequest",
16611661
"StartedIngestRequest",
16621662
"FinishRunRequest",
16631663
"RunStatus.FAILED",
@@ -1671,7 +1671,7 @@ def test_sync_execution_effects_stay_out_of_service_orchestration():
16711671
"run_started(",
16721672
)
16731673
forbidden_evaluation_fragments = (
1674-
"RunIngestRequest",
1674+
"IngestRequest",
16751675
"StartedIngestRequest",
16761676
"FinishRunRequest",
16771677
"RunStatus.FAILED",
@@ -1680,7 +1680,7 @@ def test_sync_execution_effects_stay_out_of_service_orchestration():
16801680
"run_started(",
16811681
)
16821682

1683-
assert (sync_root / "execution.py").is_file()
1683+
assert (sync_root / "queue.py").is_file()
16841684
assert len(service_text.splitlines()) <= 120
16851685
assert [
16861686
fragment
@@ -1692,14 +1692,11 @@ def test_sync_execution_effects_stay_out_of_service_orchestration():
16921692
for fragment in forbidden_evaluation_fragments
16931693
if fragment in evaluation_text
16941694
] == []
1695-
assert "class SyncRunExecutor" in execution_text
1696-
assert "RunIngestRequest" in execution_text
1697-
assert "StartedIngestRequest" in execution_text
1698-
assert "FinishRunRequest" in execution_text
1699-
assert "pending_entry(" in execution_text
1700-
assert "absorbed_entry(" in execution_text
1701-
assert "queue_ingest(" in execution_text
1702-
assert "spawn_worker(" in execution_text
1695+
assert "class SyncIngestQueue" in queue_text
1696+
assert "IngestRequest" in queue_text
1697+
assert "queue_ingest(" in queue_text
1698+
assert "spawn_worker(" in queue_text
1699+
assert "record_completed(" in queue_text
17031700

17041701

17051702
def test_viewer_jobs_surface_stays_read_only():

tests/test_sync_workflow.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
from pathlib import Path
44

55
from codealmanac.app import create_app
6-
from codealmanac.settings import AppConfig
76
from codealmanac.services.harnesses.models import HarnessKind
87
from codealmanac.services.repositories.requests import InitializeRepositoryRequest
98
from codealmanac.services.runs.models import RunKind, RunWorkerSpawnResult
109
from codealmanac.services.runs.requests import ReadRunSpecRequest, SpawnRunWorkerRequest
1110
from codealmanac.services.sources.models import TranscriptApp, TranscriptCandidate
1211
from codealmanac.services.sources.requests import DiscoverTranscriptsRequest
12+
from codealmanac.settings import AppConfig
1313
from codealmanac.workflows.sync.models import SyncMode
14-
from codealmanac.workflows.sync.requests import RunSyncRequest, RunSyncStatusRequest
14+
from codealmanac.workflows.sync.requests import SyncRequest, SyncStatusRequest
1515

1616

1717
class FakeTranscriptDiscoveryAdapter:
@@ -63,7 +63,7 @@ def test_sync_status_groups_active_transcripts_by_repository(
6363
app.workflows.build.initialize(InitializeRepositoryRequest(path=repo))
6464

6565
summary = app.workflows.sync.status(
66-
RunSyncStatusRequest(
66+
SyncStatusRequest(
6767
cwd=repo,
6868
apps=(TranscriptApp.CODEX,),
6969
now=current_time(),
@@ -93,7 +93,7 @@ def test_sync_uses_exact_registered_cwd_without_root_hopping(
9393
app.workflows.build.initialize(InitializeRepositoryRequest(path=repo))
9494

9595
summary = app.workflows.sync.status(
96-
RunSyncStatusRequest(
96+
SyncStatusRequest(
9797
cwd=repo,
9898
apps=(TranscriptApp.CODEX,),
9999
now=current_time(),
@@ -130,7 +130,7 @@ def test_sync_run_queues_one_ingest_run_per_repository_and_records_scan_time(
130130
app.workflows.build.initialize(InitializeRepositoryRequest(path=repo))
131131

132132
summary = app.workflows.sync.run(
133-
RunSyncRequest(
133+
SyncRequest(
134134
cwd=repo,
135135
apps=(TranscriptApp.CODEX,),
136136
harness=HarnessKind.CODEX,
@@ -163,7 +163,7 @@ def test_sync_run_queues_one_ingest_run_per_repository_and_records_scan_time(
163163
assert sync_completed_at(database_path) == current_time().isoformat()
164164

165165
next_status = app.workflows.sync.status(
166-
RunSyncStatusRequest(
166+
SyncStatusRequest(
167167
cwd=repo,
168168
apps=(TranscriptApp.CODEX,),
169169
now=current_time() + timedelta(minutes=1),
@@ -189,7 +189,7 @@ def test_sync_advances_scan_time_even_when_queueing_fails(
189189
app.workflows.build.initialize(InitializeRepositoryRequest(path=repo))
190190

191191
summary = app.workflows.sync.run(
192-
RunSyncRequest(
192+
SyncRequest(
193193
cwd=repo,
194194
apps=(TranscriptApp.CODEX,),
195195
harness=HarnessKind.CODEX,
@@ -224,7 +224,7 @@ def test_sync_uses_last_completed_time_before_interval_fallback(
224224
write_sync_completed_at(database_path, previous)
225225

226226
summary = app.workflows.sync.status(
227-
RunSyncStatusRequest(
227+
SyncStatusRequest(
228228
cwd=repo,
229229
apps=(TranscriptApp.CODEX,),
230230
now=current_time(),

0 commit comments

Comments
 (0)