88 KiB
V2 Phase 2 Backend Route Boundary Refactor
Date: 2026-06-28
Goal
Phase 2 starts the backend modularization work. The first slices extract route boundaries from the two FastAPI entrypoints. They keep current API paths, response models, and runtime behavior unchanged.
The route boundary pattern has now been verified. The follow-up slices have started splitting the AI Platform SQLAlchemy persistence logic behind the stable public AiPlatformRepository protocol.
The current focus is back on the Contract API, following the optimization plan order: split contracts.py models and repository boundaries before continuing with Contract API business routers.
Completed
Contract API
Added route module:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/api/system.py
Moved these routes out of main.py:
GET /health
GET /api/v1/health
GET /api/v1/metrics/health
GET /api/v1/metrics/latency
GET /api/v1/metrics/errors
GET /api/v1/permissions/roles
POST /api/v1/permissions/check
GET /api/v1/runtime/config-check
GET /api/v1/runtime/schema-check
main.py now registers these routes through:
register_system_routes(app, settings=resolved_settings, repository=repository)
Added route module:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/api/support.py
Moved these support routes out of main.py:
GET /api/v1/contracts/export
GET /api/v1/obligations
POST /api/v1/contracts/{contract_id}/obligations
POST /api/v1/obligations/{obligation_id}/complete
GET /api/v1/contracts/{contract_id}/signature-evidence
POST /api/v1/contracts/{contract_id}/signature-evidence
POST /api/v1/contracts/{contract_id}/archive
GET /api/v1/contracts/{contract_id}/archive-evidence
GET /api/v1/notifications
PATCH /api/v1/notifications/{notification_id}/read
POST /api/v1/notifications/mark-all-read
GET /api/v1/approval-rules
POST /api/v1/approval-rules
PATCH /api/v1/approval-rules/{rule_id}
DELETE /api/v1/approval-rules/{rule_id}
main.py now registers these routes through:
register_support_routes(app, settings=resolved_settings, repository=repository)
The support route registration intentionally happens before /api/v1/contracts/{contract_id} so /api/v1/contracts/export stays a static route instead of being captured as a contract id.
Added route module:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/api/files_search_backup.py
Moved these file/search/backup routes out of main.py:
POST /api/v1/backup
GET /api/v1/backup
GET /api/v1/backup/{backup_id}
POST /api/v1/backup/{backup_id}/validate
POST /api/v1/restore
GET /api/v1/search
GET /api/v1/files
POST /api/v1/files
POST /api/v1/files/batch-download
GET /api/v1/files/{file_id}
GET /api/v1/files/{file_id}/preview
GET /api/v1/files/{file_id}/download
main.py now registers these routes through:
register_files_search_backup_routes(app, settings=resolved_settings, repository=repository)
The route module registers /api/v1/files/batch-download before /api/v1/files/{file_id} so the static batch download endpoint is not captured as a file id.
Added route module:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/api/review.py
Moved these review routes out of main.py:
POST /api/v1/contracts/{contract_id}/review
GET /api/v1/contracts/{contract_id}/review-tasks
POST /api/v1/contracts/{contract_id}/review-tasks/{review_task_id}/run
POST /api/v1/review-worker/run-once
main.py now registers these routes through:
register_review_routes(app, settings=resolved_settings, repository=repository)
review-rules routes remain in main.py for now because they belong to legal asset management, not the review task runtime route group.
Added route module:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/api/templates.py
Moved these template routes out of main.py:
GET /api/v1/templates
GET /api/v1/templates/tree
GET /api/v1/templates/{template_id}
GET /api/v1/templates/{template_id}/edit-draft
PATCH /api/v1/templates/{template_id}/edit-draft
GET /api/v1/templates/{template_id}/diff
POST /api/v1/templates/{template_id}/validate
GET /api/v1/templates/{template_id}/history
POST /api/v1/templates/{template_id}/publish
POST /api/v1/templates/{template_id}/offline
POST /api/v1/templates/{template_id}/rollback
POST /api/v1/templates/{template_id}/draft
main.py now registers these routes through:
register_template_routes(app, settings=resolved_settings, repository=repository)
/api/v1/templates/{template_id}/legal-assets moved with the legal asset route group described below.
Added route module:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/api/legal_assets.py
Moved these legal asset and legal fulltext routes out of main.py:
GET /api/v1/standard-clauses
GET /api/v1/standard-clauses/{clause_id}
GET /api/v1/standard-clauses/{clause_id}/edit-draft
PATCH /api/v1/standard-clauses/{clause_id}/edit-draft
GET /api/v1/standard-clauses/{clause_id}/diff
POST /api/v1/standard-clauses/{clause_id}/validate
GET /api/v1/standard-clauses/{clause_id}/history
POST /api/v1/standard-clauses/{clause_id}/publish
POST /api/v1/standard-clauses/{clause_id}/offline
POST /api/v1/standard-clauses/{clause_id}/rollback
GET /api/v1/review-rules
GET /api/v1/review-rules/{rule_id}
GET /api/v1/review-rules/{rule_id}/edit-draft
PATCH /api/v1/review-rules/{rule_id}/edit-draft
GET /api/v1/review-rules/{rule_id}/diff
POST /api/v1/review-rules/{rule_id}/validate
GET /api/v1/review-rules/{rule_id}/history
POST /api/v1/review-rules/{rule_id}/publish
POST /api/v1/review-rules/{rule_id}/offline
POST /api/v1/review-rules/{rule_id}/rollback
GET /api/v1/templates/{template_id}/legal-assets
GET /api/v1/legal-articles
GET /api/v1/legal-articles/{article_id}
GET /api/v1/legal-change-impacts
POST /api/v1/legal-change-impacts/scan
GET /api/v1/legal-change-impacts/{event_id}
main.py now registers these routes through:
register_legal_asset_routes(app, settings=resolved_settings, repository=repository)
The route module registers /api/v1/legal-change-impacts/scan before /api/v1/legal-change-impacts/{event_id} so the static scan endpoint is not captured as an event id.
Added route module:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/api/contracts_core.py
Moved these remaining contract core, workspace, approval, version, audit, and legal QA proxy routes out of main.py:
GET /api/v1/workspace
GET /api/v1/contracts
POST /api/v1/contracts
GET /api/v1/contracts/dashboard
GET /api/v1/contracts/{contract_id}
PATCH /api/v1/contracts/{contract_id}
POST /api/v1/contracts/{contract_id}/clause-repairs
POST /api/v1/contracts/{contract_id}/download-events
GET /api/v1/contracts/{contract_id}/audit-integrity
POST /api/v1/contracts/{contract_id}/approval/submit
POST /api/v1/contracts/{contract_id}/approval/resubmit
POST /api/v1/contracts/{contract_id}/approval/decision
GET /api/v1/contracts/{contract_id}/versions
GET /api/v1/contracts/{contract_id}/versions/{version_id}
POST /api/v1/legal/qa
main.py now registers these routes through:
register_contract_core_routes(app, settings=resolved_settings, repository=repository)
main.py keeps application creation, middleware, repository wiring, and route-module registration only. Static route order is still protected: /api/v1/contracts/export from the support router and /api/v1/contracts/dashboard from the core router register before /api/v1/contracts/{contract_id}.
Extracted seed/demo data loaders from contracts.py into:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/seed_data.py
This module now owns:
default approval rule seed data construction
demo contract seed data construction
demo obligation seed data construction
SQLAlchemy default seed orchestration through ContractSeedDataLoader
contracts.py keeps compatibility wrappers for existing callers:
build_default_approval_rules
build_demo_contracts
build_demo_obligations
SqlAlchemyContractRepository.seed_defaults() now delegates to ContractSeedDataLoader. Seed data content, public function names, and repository startup behavior are unchanged.
Extracted schema/domain models and pure domain helpers from contracts.py into:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/domain.py
This module now owns:
contract/workspace/support/permission DTOs
ContractStatus / UserRole / Permission and related Literal types
permission matrix and permission helper functions
contract permission projection helpers
workspace summary helpers
lifecycle-stage and status-normalization helpers
contracts.py imports and re-exports these names so existing callers can continue using yuqei_contract_api.contracts as the public compatibility surface. ContractRepository, repository implementations, persistence orchestration, and workflow errors remain in contracts.py.
Extracted SQLAlchemy persistence models from:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/contracts.py
into:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/persistence/models.py
The following public imports remain compatible through yuqei_contract_api.contracts re-exports:
Base
ContractModel
ApprovalTimelineModel
ContractAuditEventModel
ContractFileModel
ReviewTaskModel
ContractSearchDocumentModel
TemplateLifecycleEventModel
LegalAssetLifecycleEventModel
TemplateEditDraftModel
LegalAssetEditDraftModel
LegalChangeImpactScanModel
Extracted the first SQLAlchemy repository submodule from SqlAlchemyContractRepository:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/persistence/legal_change_impacts.py
This module now owns persistence for legal change impact scan history:
record_legal_change_impact_scan
list_legal_change_impact_scans
get_legal_change_impact_scan
SqlAlchemyContractRepository keeps the public repository methods and delegates to this persistence module after resolving the current tenant.
Extracted unified search persistence from SqlAlchemyContractRepository:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/persistence/search.py
This module now owns:
SearchResult / SearchResultPage / SearchQueryResult
search document id/upsert helpers
contract/file/review-task search document sync
search document rebuild/ensure
SQLite keyword search path
PostgreSQL full-text search path
search scoring, grouping, pagination helpers
yuqei_contract_api.contracts still re-exports the search DTOs and helper names so existing imports remain compatible.
Extracted the first file repository persistence slice from SqlAlchemyContractRepository:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/persistence/files.py
This module now owns:
ContractFileItem / FileCreateRequest / FilePage / FilePreview / FileDownload / BatchDownload DTOs
file list/detail/preview persistence
stored file read guard
file content encode/decode helpers
file preview/download response builders
file type and decoded size helpers
SqlAlchemyContractRepository kept file upload/download side effects during the first file persistence slice:
upload updates contract next_action / timeline / audit / search sync
download appends file_downloaded audit event / search sync
Those timeline/audit/search-sync side effects have now moved into the contract audit/status persistence support described below.
Extracted the first review task runtime persistence slice from SqlAlchemyContractRepository:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/persistence/review_tasks.py
This module now owns:
ReviewSourceDocument / ReviewTask / ReviewTaskRequest / ReviewTaskRunRequest / ReviewWorkerRunRequest / ReviewWorkerRun DTOs
review task model conversion
review task request builder
review task listing
review source document loading
claim queued review task as running
queue failed review task back to queued
complete review task as succeeded
fail review task with persisted error details
SqlAlchemyContractRepository now delegates review task queue/complete/fail state mutation to this module. The outer repository still coordinates review-specific contract field updates through callbacks:
start_review updates contract review status
queue_review_task handles retry-specific contract state
complete_review_task enriches risks and updates next actions
fail_review_task preserves failure details on the review task
Timeline append, audit append/hash-chain, and contract search-sync side effects from those callbacks now delegate to the audit/status persistence support.
Extracted contract audit/status persistence support from SqlAlchemyContractRepository:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/persistence/audit.py
This module now owns:
ContractAuditEvent / ContractAuditEventType DTOs
audit event model conversion
audit event hash-chain construction and verification
audit event list and record persistence
contract workflow status transition persistence
timeline event append helpers
combined timeline + audit + search-sync side-effect helper
UTC datetime normalization for stable hash verification across SQLite/PostgreSQL datetime behavior
SqlAlchemyContractRepository now delegates these SQLAlchemy paths to the audit/status persistence support:
record_audit_event
list_audit_events
verify_audit_integrity
_transition_contract
contract update audit append/search sync
clause repair audit append/search sync
file upload timeline/audit/search sync
file download audit/search sync
review start/requeue/complete/fail timeline/audit/search sync
The public import surface remains compatible through yuqei_contract_api.contracts for existing callers/tests that import audit DTOs and hash helper names.
Extracted contract create/update/version persistence from SqlAlchemyContractRepository:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/persistence/contract_core.py
This module now owns:
ContractVersion / ContractVersionPage DTOs
ContractCreateData / ContractTimelineData persistence input objects
SQLAlchemy contract row creation
contract_created audit event initialization
contract search document upsert during creation
contract field update persistence
contract_updated audit append/search sync through ContractAuditRepository
current-version list/detail persistence
SqlAlchemyContractRepository now delegates these SQLAlchemy paths to ContractCoreRepository:
create_contract
update_contract
list_versions
get_version
seed_defaults contract row insertion
The outer repository still builds domain-facing ContractDetail objects, applies tenant context, and coordinates template drafting / review / approval business flows.
Extracted template lifecycle/edit-draft persistence from SqlAlchemyContractRepository:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/persistence/templates.py
This module now owns:
template lifecycle event model conversion
template lifecycle event insert/list/load helpers
template lifecycle event grouped loading for template lists and trees
template edit draft get/upsert persistence
template edit draft model conversion
UTC datetime normalization for SQLite/PostgreSQL stability
SqlAlchemyContractRepository now delegates these SQLAlchemy paths to ContractTemplatePersistence:
list template lifecycle events
load template lifecycle events for single templates and template collections
insert template lifecycle event
get template edit draft
upsert template edit draft
The outer repository still owns template business rules:
publish/offline/rollback decisions
published snapshot application
edit draft construction
diff calculation
publish validation
template rendering for drafting
Extracted legal asset lifecycle/edit-draft persistence from SqlAlchemyContractRepository:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/persistence/legal_assets.py
This module now owns:
standard clause / review rule lifecycle event model conversion
legal asset lifecycle event insert/list/load helpers
legal asset lifecycle grouped loading for clause and rule lists
legal asset edit draft get/upsert persistence
legal asset edit draft model conversion
UTC datetime normalization for SQLite/PostgreSQL stability
SqlAlchemyContractRepository now delegates these SQLAlchemy paths to ContractLegalAssetPersistence:
list legal asset lifecycle events
load legal asset lifecycle events for single assets and asset collections
insert legal asset lifecycle event
get legal asset edit draft
upsert legal asset edit draft
The outer repository still owns legal asset business rules:
publish/offline/rollback decisions
published snapshot application
edit draft construction
diff calculation
publish validation
review-rule recommendation effects through published/offline lifecycle state
Extracted notification / approval-rule / obligation / signature / archive support persistence from SqlAlchemyContractRepository:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/persistence/support.py
This module now owns:
notification list/create/read/mark-all persistence
approval rule list/create/update/delete/enabled-rule/default-seed persistence
obligation list/create/complete/demo-seed persistence
signature evidence list/create persistence
archive evidence list/create persistence
archived contract export persistence
support DTO model conversion helpers
support document hash and UTC datetime helpers
The support tables were added to SQLAlchemy models, Alembic migrations, and runtime schema-check:
notifications
approval_rules
obligation_tasks
signature_evidence
archive_evidence
SqlAlchemyContractRepository now delegates these SQLAlchemy paths to ContractSupportRepository:
list_notifications
mark_notification_read
mark_all_notifications_read
create_notification
list_approval_rules
create_approval_rule
update_approval_rule
delete_approval_rule
check_approval_required
list_obligations
create_obligation
complete_obligation
list_signature_evidence
create_signature_evidence
list_archive_evidence
export_contracts
The outer repository still coordinates business transitions:
workflow transition notification creation
approval-driven signature evidence creation
archive workflow status transition and archive evidence creation
tenant context resolution
During validation, /api/v1/contracts/export was found to be captured by /api/v1/contracts/{contract_id} because the static route was registered after the dynamic route. The static /contracts/dashboard and /contracts/export routes now register before /contracts/{contract_id}. API paths and response models are unchanged.
AI Platform API
Added route module:
yuqei-ai-platform/services/ai-platform-api/src/yuqei_ai_platform_api/api/system.py
Moved these routes out of main.py:
GET /health
GET /api/v1/health
GET /api/v1/runtime/schema-check
GET /api/v1/runtime/worker-health
GET /api/v1/runtime/worker-runs
POST /api/v1/runtime/worker-runs/run-once
POST /api/v1/runtime/worker-heartbeats
GET /api/v1/runtime/object-storage/check
GET /api/v1/runtime/ocr-provider
PUT /api/v1/runtime/ocr-provider
GET /api/v1/runtime/ocr-provider/check
main.py now registers these routes through:
register_system_routes(
app,
settings=resolved_settings,
store=store,
object_storage=object_storage,
)
Added route modules:
yuqei-ai-platform/services/ai-platform-api/src/yuqei_ai_platform_api/api/model_configs.py
yuqei-ai-platform/services/ai-platform-api/src/yuqei_ai_platform_api/api/prompts.py
yuqei-ai-platform/services/ai-platform-api/src/yuqei_ai_platform_api/api/knowledge.py
yuqei-ai-platform/services/ai-platform-api/src/yuqei_ai_platform_api/api/quality.py
yuqei-ai-platform/services/ai-platform-api/src/yuqei_ai_platform_api/api/audit.py
yuqei-ai-platform/services/ai-platform-api/src/yuqei_ai_platform_api/api/legal.py
Moved these routes out of main.py:
GET /api/v1/model-configs
POST /api/v1/model-configs
GET /api/v1/model-configs/changes
GET /api/v1/prompt-templates
POST /api/v1/prompt-templates
GET /api/v1/prompt-templates/changes
POST /api/v1/prompt-templates/{name}/publish
POST /api/v1/prompt-templates/{name}/rollback
POST /api/v1/knowledge-bases/{knowledge_base_id}/documents
GET /api/v1/knowledge-ingestion-jobs
POST /api/v1/knowledge-ingestion-jobs/{job_id}/retry
POST /api/v1/knowledge-documents
POST /api/v1/knowledge-documents/reindex
POST /api/v1/knowledge-import-batches
GET /api/v1/knowledge-import-batches
GET /api/v1/knowledge-import-batches/{batch_id}
GET /api/v1/knowledge-import-batches/{batch_id}/documents
GET /api/v1/knowledge-import-batches/{batch_id}/chunks
POST /api/v1/knowledge-import-batches/{batch_id}/reindex
GET /api/v1/knowledge-documents/{document_id}/chunks
GET /api/v1/knowledge-documents/search
GET /api/v1/knowledge-chunks/search
GET /api/v1/knowledge-chunks/search/explain
GET /api/v1/quality-rules/default
PUT /api/v1/quality-rules/default
GET /api/v1/quality/golden-samples
POST /api/v1/quality/golden-samples/evaluate
GET /api/v1/audit/ai-runs
GET /api/v1/audit/ai-runs/{run_id}
GET /api/v1/audit/quality-dashboard
GET /api/v1/audit/quality-improvement-actions
POST /api/v1/audit/quality-improvement-actions
GET /api/v1/audit/quality-improvement-actions/{action_id}
GET /api/v1/audit/quality-improvement-actions/{action_id}/executions
PATCH /api/v1/audit/quality-improvement-actions/{action_id}
PATCH /api/v1/audit/ai-runs/{run_id}/quality-labels/{label_code}
POST /api/v1/legal/qa
POST /api/v1/legal/contract-review
main.py now registers these routes through:
register_model_config_routes(app, settings=resolved_settings, store=store)
register_prompt_routes(app, settings=resolved_settings, store=store)
register_quality_routes(app, settings=resolved_settings, store=store)
register_knowledge_routes(
app,
settings=resolved_settings,
store=store,
object_storage=object_storage,
)
register_audit_routes(app, settings=resolved_settings, store=store)
register_legal_routes(
app,
settings=resolved_settings,
store=store,
provider_adapter=provider_adapter,
)
AI Run Audit Summary Compatibility
While running the full backend tests, the slim /api/v1/audit/ai-runs list response was found to be missing two lightweight compatibility fields:
retrieved_source_count
has_rag_explain
These fields were restored on AiRunAuditSummary for both in-memory and SQLAlchemy repositories. The list response still excludes the heavy retrieved_sources and rag_explain payloads; callers can fetch those from GET /api/v1/audit/ai-runs/{run_id}.
SQLAlchemy Default Seed Guard
While re-running health tests, an empty SQLAlchemy database with database_auto_create=false was found to fail during repository startup because default seed logic queried missing tables before /api/v1/runtime/schema-check could report the schema problem.
SqlAlchemyAiPlatformRepository.seed_defaults() now checks that the seed tables exist before inserting defaults:
ai_provider_configs
prompt_templates
knowledge_documents
If those tables are missing, startup continues and schema-check remains responsible for reporting the missing core tables.
AI Platform Repository Persistence Split
Added persistence package:
yuqei-ai-platform/services/ai-platform-api/src/yuqei_ai_platform_api/persistence/
Completed SQLAlchemy subrepositories:
persistence/provider_configs.py
persistence/prompts.py
persistence/knowledge.py
persistence/audit.py
persistence/quality.py
persistence/worker_runtime.py
repository.py now delegates SQLAlchemy provider config operations through:
SqlAlchemyProviderConfigRepository
and Prompt lifecycle operations through:
SqlAlchemyPromptTemplateRepository
and knowledge/RAG operations through:
SqlAlchemyKnowledgeRepository
and AI run audit operations through:
SqlAlchemyAuditRepository
and quality rule/dashboard/improvement-action operations through:
SqlAlchemyQualityRepository
and worker runtime/OCR provider operations through:
SqlAlchemyWorkerRuntimeRepository
The public repository import surface remains compatible. Existing callers can still import these schemas from yuqei_ai_platform_api.repository:
ProviderConfigCreate
ProviderConfig
ProviderConfigUpsertRequest
ProviderConfigChange
PromptTemplateCreate
PromptTemplate
PromptTemplatePublishRequest
PromptTemplateRollbackRequest
PromptTemplateChange
KnowledgeDocumentCreate
KnowledgeDocument
KnowledgeImportBatchCreate
KnowledgeImportBatch
KnowledgeImportBatchDetail
KnowledgeChunk
KnowledgeSearchResult
KnowledgeSearchExplain
KnowledgeReindexRequest
KnowledgeReindexResult
KnowledgeReindexExecution
KnowledgeIngestionJobCreate
KnowledgeIngestionJob
KnowledgeDocumentUploadResult
RetrievalSource
AiQualityLabel
AiQualityLabelReviewUpdate
AiRunAudit
AiRunAuditSummary
AiQualityRuleConfigCreate
AiQualityRuleConfig
AiQualityDailyMetric
AiQualityPendingLabel
AiQualityAttributionItem
AiQualityAttribution
AiQualityImprovementActionCreate
AiQualityImprovementActionUpdate
AiQualityImprovementAction
AiQualityImprovementLabelEffect
AiQualityImprovementTraceImpact
AiQualityImprovementExecutionBundle
AiQualityDashboardSummary
AiQualityDashboard
OcrProviderConfigCreate
OcrProviderConfig
OcrProviderRuntimeConfig
WorkerHeartbeatCreate
WorkerHeartbeat
WorkerRuntimeHealth
WorkerRunExecutionCreate
WorkerRunExecution
Prompt lifecycle behavior remains unchanged:
draft upsert
publish
rollback
published template lookup
change history filtering
default prompt seeding
Knowledge/RAG behavior remains unchanged:
document import and chunking
batch detail and counts
ingestion job queue/acquire/complete/retry
keyword/vector/hybrid search
PostgreSQL search_vector and pgvector probes
RAG explain output
reindex execution records
default knowledge seeding
The outer SqlAlchemyAiPlatformRepository keeps a compatibility delegation bridge so existing tests and callers that monkeypatch _session_factory or private search-vector hooks continue to affect the delegated knowledge repository.
AI run audit behavior remains unchanged:
audit run insert
audit run detail lookup
slim audit run list summaries
retrieved source count and RAG explain presence summary fields
quality label review updates
Quality behavior remains unchanged:
quality rule config upsert/default lookup
quality dashboard metrics and pending labels
improvement action list/detail/materialization
improvement action execution bundle
improvement action create/update validation
linked prompt/knowledge action inference
baseline and post-change effect calculation
Worker runtime behavior remains unchanged:
OCR provider config lookup/upsert and secret masking
worker heartbeat record/list
worker runtime health queue/staleness status
worker run execution create/list
Verification
Passed:
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_health.py yuqei-ai-platform\services\ai-platform-api\tests\test_health.py -q
Result:
14 passed
Passed:
python -m pytest yuqei-ai-platform\services\ai-platform-api\tests\test_health.py -q
Result:
5 passed
Passed:
python -m pytest yuqei-ai-platform\services\ai-platform-api\tests\test_platform_data.py -q
Result:
37 passed
Passed:
python -m pytest yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
exit code 0
Passed:
python -m pytest yuqei-ai-platform\services\ai-platform-api\tests\test_provider_flow.py yuqei-ai-platform\services\ai-platform-api\tests\test_object_storage.py -q
Result:
5 passed
Passed:
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
exit code 0
Passed:
python -m compileall yuqei-contract-platform\services\contract-api\src\yuqei_contract_api yuqei-ai-platform\services\ai-platform-api\src\yuqei_ai_platform_api
Passed after Prompt persistence split:
python -m compileall yuqei-ai-platform\services\ai-platform-api\src\yuqei_ai_platform_api
Passed after Prompt persistence split:
python -m pytest yuqei-ai-platform\services\ai-platform-api\tests\test_platform_data.py::test_prompt_template_can_be_hot_updated_and_listed yuqei-ai-platform\services\ai-platform-api\tests\test_platform_data.py::test_prompt_template_can_be_published_and_rolled_back yuqei-ai-platform\services\ai-platform-api\tests\test_platform_data.py::test_sqlalchemy_repository_persists_platform_data -q
Result:
3 passed
Passed after Prompt persistence split:
python -m pytest yuqei-ai-platform\services\ai-platform-api\tests\test_platform_data.py::test_quality_improvement_action_executions_collect_config_prompt_and_reindex_records yuqei-ai-platform\services\ai-platform-api\tests\test_platform_data.py::test_quality_improvement_action_links_prompt_and_knowledge_changes -q
Result:
2 passed
Passed after Prompt persistence split:
python -m pytest yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
exit code 0
Passed after Prompt persistence split:
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
exit code 0
Passed after Knowledge/RAG persistence split:
python -m py_compile yuqei-ai-platform\services\ai-platform-api\src\yuqei_ai_platform_api\persistence\knowledge.py yuqei-ai-platform\services\ai-platform-api\src\yuqei_ai_platform_api\repository.py
Passed after Knowledge/RAG persistence split:
python -m pytest yuqei-ai-platform\services\ai-platform-api\tests\test_platform_data.py -k "knowledge or reindex or ingestion or search" -q
Result:
17 passed
Passed after Knowledge/RAG persistence split:
python -m pytest yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
52 passed
Passed after Knowledge/RAG persistence split:
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
100% passed
Passed after AI run audit persistence split:
python -m py_compile yuqei-ai-platform\services\ai-platform-api\src\yuqei_ai_platform_api\persistence\audit.py yuqei-ai-platform\services\ai-platform-api\src\yuqei_ai_platform_api\repository.py
Passed after AI run audit persistence split:
python -m pytest yuqei-ai-platform\services\ai-platform-api\tests\test_platform_data.py -k "audit or quality or ai_run or label" -q
Result:
14 passed
Passed after AI run audit persistence split:
python -m pytest yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
52 passed
Passed after AI run audit persistence split:
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
100% passed
Passed after Quality persistence split:
python -m py_compile yuqei-ai-platform\services\ai-platform-api\src\yuqei_ai_platform_api\persistence\quality.py yuqei-ai-platform\services\ai-platform-api\src\yuqei_ai_platform_api\repository.py
Passed after Quality persistence split:
python -m pytest yuqei-ai-platform\services\ai-platform-api\tests\test_platform_data.py -k "quality or improvement or dashboard or label" -q
Result:
10 passed
Passed after Quality persistence split:
python -m pytest yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
52 passed
Passed after Quality persistence split:
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
100% passed
Passed after Worker runtime persistence split:
python -m py_compile yuqei-ai-platform\services\ai-platform-api\src\yuqei_ai_platform_api\persistence\worker_runtime.py yuqei-ai-platform\services\ai-platform-api\src\yuqei_ai_platform_api\repository.py
Passed after Worker runtime persistence split:
python -m pytest yuqei-ai-platform\services\ai-platform-api\tests\test_platform_data.py -k "worker or runtime or ocr" -q
Result:
3 passed
Passed after Worker runtime persistence split:
python -m pytest yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
52 passed
Passed after Worker runtime persistence split:
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
100% passed
Current Status
Phase 2 route boundary extraction has started. AI Platform route slices and SQLAlchemy persistence subrepositories are complete. Contract API system routes, support business routes, file/search/backup routes, review routes, template routes, legal assets/fulltext routes, contracts core/workspace routes, SQLAlchemy model extraction, schema/domain model extraction, seed/demo data loader extraction, workflow helper extraction, in-memory repository extraction, SQLAlchemy review task orchestration cleanup, SQLAlchemy lifecycle orchestration cleanup, SQLAlchemy search orchestration cleanup, SQLAlchemy repository wiring cleanup, SQLAlchemy transition orchestration cleanup, contracts.py public import/export surface audit, explicit compatibility export inventory, API route import migration, test import migration first slice, and the planned repository persistence slices through support persistence are complete.
Still pending:
- Split Contract API business routers from
main.py:- contracts core/workspace - done
- files/search/backup - done
- review - done
- templates - done
- legal assets / legal fulltext - done
- notifications/approval rules/obligations/signature/archive - done
- Split
contracts.pyinto clearer domains:- schemas/domain models - done
- SQLAlchemy persistence models - done
- repository submodules - started
- legal change impact scan history - done
- unified search persistence - done
- file repository persistence first slice - done
- review task runtime first slice - done
- review task queue/complete/fail transitions - done
- contract audit/status/timeline/search-sync support - done
- contract create/update/version persistence - done
- template lifecycle/edit-draft persistence - done
- legal asset lifecycle/edit-draft persistence - done
- notification/approval-rule/obligation/signature/archive support - done
- seed/demo data loaders - done
- contract workflow helpers/orchestration functions - done
- in-memory repository extraction - done
- SQLAlchemy review task orchestration cleanup - done
- SQLAlchemy template/legal-asset lifecycle orchestration cleanup - done
- SQLAlchemy search orchestration cleanup - done
- SQLAlchemy repository construction/support wiring cleanup - done
- SQLAlchemy transition orchestration cleanup - done
contracts.pypublic import/export surface audit - donecontracts.pyexplicit compatibility export inventory - done- route modules import migration first slice - done
- route modules import migration review/files-search-backup slice - done
- route modules import migration support slice - done
- route modules import migration contracts-core slice - done
- test import migration permission/audit slice - done
- Split AI Platform
repository.pyinto subrepositories:- provider configs - done
- prompt lifecycle - done
- knowledge/RAG - done
- AI run audit - done
- quality - done
- worker runtime - done
Next Recommended Slice
Continue with Phase 2 by choosing the next repository/orchestration cleanup slice:
- Continue internal import migration outside the API route layer, focusing on remaining tests that still import from
contracts.py. - Keep API paths, response shapes, route order, and current
yuqei_contract_api.contractspublic names stable. - Run Contract API tests, compatibility import checks, and full backend tests after each slice.
The recommended next slice is to migrate the remaining low-risk test imports in test_contract_workflow.py and test_tenant_isolation.py, keeping contracts.py plus its __all__ stable for external compatibility.
Contract API Model Extraction Validation
Passed after Contract API SQLAlchemy model extraction:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\persistence\models.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Contract API Search Persistence Validation
Passed after extracting unified search persistence:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\persistence\search.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py -k "search or file or review" -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Contract API File Persistence Validation
Passed after extracting file DTO/helper/query/preview persistence:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\persistence\files.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\main.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_upload_file_and_start_review_closes_review_entry_flow yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_file_repository_detail_preview_download_and_audit yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_unified_search_returns_contract_file_and_review_task yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_worker_uses_uploaded_source_file_text_and_persists_ai_sources -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Contract API Review Task Persistence Validation
Passed after extracting review task DTO/helper/list/source/claim persistence:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\persistence\review_tasks.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\review_worker.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\main.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_upload_file_and_start_review_closes_review_entry_flow yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_worker_calls_ai_platform_and_persists_result yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_worker_uses_uploaded_source_file_text_and_persists_ai_sources yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_worker_does_not_fallback_to_contract_body_when_source_file_is_unreadable -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Passed after extracting review task queue/complete/fail status transitions while keeping timeline/audit/search side effects in the outer repository callbacks:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\persistence\review_tasks.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_worker_calls_ai_platform_and_persists_result yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_worker_uses_uploaded_source_file_text_and_persists_ai_sources yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_worker_does_not_fallback_to_contract_body_when_source_file_is_unreadable yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_failed_review_task_can_be_requeued -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Passed after extracting contract audit/status/timeline/search-sync persistence support:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\persistence\audit.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_audit_integrity.py yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_submit_reject_resubmit_and_approve_workflow yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_create_and_update_contract_draft_persists_to_repository yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_file_repository_detail_preview_download_and_audit -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Passed after extracting contract create/update/version persistence:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\persistence\contract_core.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_create_and_update_contract_draft_persists_to_repository yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_file_repository_detail_preview_download_and_audit yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_submit_reject_resubmit_and_approve_workflow yuqei-contract-platform\services\contract-api\tests\test_audit_integrity.py -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Passed after extracting template lifecycle/edit-draft persistence:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\persistence\templates.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_template_library_can_create_contract_draft yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_template_type_tree_groups_v1_templates_and_filters yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_template_lifecycle_publish_offline_rollback_and_history yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_template_rollback_can_restore_default_published_state yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_template_edit_diff_validation_and_publish_snapshot_for_drafting -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Passed after extracting legal asset lifecycle/edit-draft persistence:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\persistence\legal_assets.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_legal_asset_lifecycle_events_update_clause_and_rule_state yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_legal_asset_edit_diff_validation_and_publish_snapshot yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_template_legal_assets_returns_related_clauses_and_rules yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_legal_change_impact_scan_finds_templates_clauses_rules_and_contracts -q
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_rule_published_snapshot_controls_recommendation_hit_and_order yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_offline_review_rule_is_excluded_from_clause_recommendations -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Passed after extracting notification / approval-rule / obligation / signature / archive support persistence:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\persistence\models.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\persistence\support.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\main.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\schema_check.py yuqei-contract-platform\services\contract-api\migrations\versions\20260628_0018_add_contract_support_tables.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_contract_support_operations_persist_with_sqlalchemy_repository -q
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_workspace_returns_pending_tasks_from_contract_state yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_workspace_filters_tasks_by_role yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_submit_reject_resubmit_and_approve_workflow -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
Result:
passed
Contract API Support Router Validation
Passed after extracting support business routes from main.py:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\main.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\api\support.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_contract_support_operations_persist_with_sqlalchemy_repository -q
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_workspace_returns_pending_tasks_from_contract_state yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_workspace_filters_tasks_by_role yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_submit_reject_resubmit_and_approve_workflow -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
Route order check:
/api/v1/contracts/export registers before /api/v1/contracts/{contract_id}
Result:
passed
Contract API Files/Search/Backup Router Validation
Passed after extracting file/search/backup business routes from main.py:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\main.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\api\files_search_backup.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_backup.py yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_upload_file_and_start_review_closes_review_entry_flow yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_file_repository_detail_preview_download_and_audit yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_unified_search_returns_contract_file_and_review_task -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
Route order check:
/api/v1/files/batch-download registers before /api/v1/files/{file_id}
Result:
passed
Contract API Review Router Validation
Passed after extracting review task and review-worker routes from main.py:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\main.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\api\review.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_upload_file_and_start_review_closes_review_entry_flow yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_worker_calls_ai_platform_and_persists_result yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_worker_uses_uploaded_source_file_text_and_persists_ai_sources yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_worker_does_not_fallback_to_contract_body_when_source_file_is_unreadable yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_failed_review_task_can_be_requeued -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
Result:
passed
Contract API Template Router Validation
Passed after extracting template routes from main.py:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\main.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\api\templates.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_template_library_can_create_contract_draft yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_template_type_tree_groups_v1_templates_and_filters yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_v1_template_assets_have_complete_clause_and_rule_bindings yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_template_lifecycle_publish_offline_rollback_and_history yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_template_rollback_can_restore_default_published_state yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_template_edit_diff_validation_and_publish_snapshot_for_drafting -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
Route order check:
/api/v1/templates/tree registers before /api/v1/templates/{template_id}
Result:
passed
Contract API Legal Assets/Fulltext Router Validation
Passed after extracting legal asset and legal fulltext routes from main.py:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\main.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\api\legal_assets.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_v1_clause_and_review_rule_assets_are_queryable yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_legal_asset_lifecycle_events_update_clause_and_rule_state yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_legal_asset_edit_diff_validation_and_publish_snapshot yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_template_legal_assets_returns_related_clauses_and_rules yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_rule_published_snapshot_controls_recommendation_hit_and_order yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_offline_review_rule_is_excluded_from_clause_recommendations yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_legal_change_impact_scan_finds_templates_clauses_rules_and_contracts yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_legal_change_impact_scan_is_persisted_to_history yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_legal_change_impact_scan_uses_published_clause_snapshot -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Route order check:
/api/v1/legal-change-impacts/scan registers before /api/v1/legal-change-impacts/{event_id}
Result:
passed
Contract API Contracts Core/Workspace Router Validation
Passed after extracting the remaining contract core, workspace, approval, version, audit integrity, clause repair, download event, and legal QA proxy routes from main.py:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\main.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\api\contracts_core.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_workspace_returns_pending_tasks_from_contract_state yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_workspace_filters_tasks_by_role yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_contract_detail_permissions_follow_role yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_contract_detail_returns_404_for_missing_contract yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_create_and_update_contract_draft_persists_to_repository yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_contract_versions_endpoint_returns_current_persisted_body yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_submit_reject_resubmit_and_approve_workflow yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_record_contract_download_event yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_approval_decision_requires_pending_status yuqei-contract-platform\services\contract-api\tests\test_audit_integrity.py::test_audit_integrity_verification yuqei-contract-platform\services\contract-api\tests\test_legal_qa_proxy.py::test_contract_api_exposes_legal_qa_proxy -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Route order check:
/api/v1/contracts/export registers before /api/v1/contracts/{contract_id}
/api/v1/contracts/dashboard registers before /api/v1/contracts/{contract_id}
Result:
passed
Contract API Seed/Demo Loader Validation
Passed after extracting default approval rule, demo contract, demo obligation, and SQLAlchemy default seed orchestration from contracts.py into seed_data.py:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\seed_data.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_workspace_returns_pending_tasks_from_contract_state yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_contract_support_operations_persist_with_sqlalchemy_repository yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_contract_list_and_detail_expose_next_action yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_sqlalchemy_repository_persists_contracts_and_approval_timeline yuqei-contract-platform\services\contract-api\tests\test_tenant_isolation.py::test_default_tenant_fallback yuqei-contract-platform\services\contract-api\tests\test_health.py::test_health_endpoint_returns_contract_api_status -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Compatibility check:
contracts.py still exposes build_default_approval_rules, build_demo_contracts, and build_demo_obligations as wrappers.
SqlAlchemyContractRepository.seed_defaults delegates to ContractSeedDataLoader.
Result:
passed
Contract API Schema/Domain Extraction Validation
Passed after extracting contract DTOs, Literal domain types, permission matrix helpers, workspace helpers, lifecycle helpers, and status normalization from contracts.py into domain.py:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\domain.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -c "from yuqei_contract_api.contracts import ContractDetail, ContractCreateRequest, ApprovalRule, WorkspaceSummary, Permission, UserRole, has_permission, get_permissions, normalize_role, build_workspace_summary, compute_lifecycle_stage, lifecycle_stage_from_status, normalize_contract_status"
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_permissions.py yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_workspace_returns_pending_tasks_from_contract_state yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_workspace_filters_tasks_by_role yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_contract_detail_permissions_follow_role yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_contract_list_and_detail_expose_next_action yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_contract_list_supports_status_and_keyword_filters yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_legacy_returned_status_is_normalized_to_rejected yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_submit_reject_resubmit_and_approve_workflow yuqei-contract-platform\services\contract-api\tests\test_health.py::test_health_endpoint_returns_contract_api_status -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Compatibility check:
Existing imports from yuqei_contract_api.contracts continue to resolve for DTOs, Literal types, permission helpers, workspace helpers, lifecycle helpers, and status normalization.
Result:
passed
Contract API Workflow Helper Extraction Validation
Passed after extracting contract workflow/orchestration helper functions from contracts.py into:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/workflow_helpers.py
Moved helper groups:
approval rule matching
review risk -> review rule / standard clause recommendation helpers
clause repair body/risk-item helpers
contract draft builders and template draft mappers
timeline/audit event builders
contract/file/review search-result mappers
SQLAlchemy contract model -> DTO mappers
Compatibility check:
contracts.py imports and re-exports the moved helper names so existing callers can keep importing them from yuqei_contract_api.contracts.
ensure_allowed_transition remains in contracts.py because it depends on ContractWorkflowError.
template/legal-asset lifecycle helpers remain in contracts.py for a separate focused slice.
Validation:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\workflow_helpers.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_create_and_update_contract_draft_persists_to_repository yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_template_library_can_create_contract_draft yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_clause_repair_can_append_recommended_clause_to_contract_body yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_rule_published_snapshot_controls_recommendation_hit_and_order yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_file_repository_detail_preview_download_and_audit yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_submit_reject_resubmit_and_approve_workflow -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Contract API In-Memory Repository Extraction Validation
Passed after extracting the test/demo in-memory repository from contracts.py into:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/in_memory_repository.py
Boundary support modules added:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/repository_base.py
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/lifecycle_helpers.py
Moved responsibilities:
InMemoryContractRepository test/demo state and behavior
ContractRepository protocol and ContractWorkflowError base types
template lifecycle/edit-draft/diff/validation pure helpers
legal asset lifecycle/edit-draft/diff/validation pure helpers
Compatibility check:
yuqei_contract_api.contracts still re-exports InMemoryContractRepository, ContractRepository, ContractWorkflowError, and lifecycle helper names.
SQLAlchemyContractRepository remains in contracts.py.
create_notification_for_transition moved to workflow_helpers.py and is still imported by contracts.py for SQLAlchemy workflow transitions.
Validation:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\repository_base.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\lifecycle_helpers.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\in_memory_repository.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\workflow_helpers.py
python -c "from yuqei_contract_api.contracts import InMemoryContractRepository, ContractRepository, ContractWorkflowError, SqlAlchemyContractRepository; from yuqei_contract_api.in_memory_repository import InMemoryContractRepository as Direct; assert InMemoryContractRepository is Direct"
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_template_library_can_create_contract_draft yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_v1_clause_and_review_rule_assets_are_queryable yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_legal_asset_lifecycle_events_update_clause_and_rule_state yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_clause_repair_can_append_recommended_clause_to_contract_body yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_submit_reject_resubmit_and_approve_workflow -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Contract API SQLAlchemy Review Orchestration Validation
Passed after extracting SQLAlchemy review task side-effect orchestration from SqlAlchemyContractRepository into:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/sqlalchemy_review_orchestration.py
Moved helper group:
review task requeue -> contract next-action/timeline/audit side effects
review task complete -> contract next-action/timeline/audit side effects
review task fail -> timeline/audit side effects
Compatibility check:
SqlAlchemyContractRepository still exposes the same review task methods.
The repository keeps the callback method names and delegates their bodies to sqlalchemy_review_orchestration.py.
Review task persistence APIs and route behavior are unchanged.
Validation:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\sqlalchemy_review_orchestration.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_worker_uses_uploaded_source_file_text_and_persists_ai_sources yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_upload_file_and_start_review_closes_review_entry_flow yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_unified_search_returns_contract_file_and_review_task yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_clause_repair_can_append_recommended_clause_to_contract_body -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Contract API SQLAlchemy Lifecycle Orchestration Validation
Passed after extracting SQLAlchemy template/legal-asset lifecycle orchestration from SqlAlchemyContractRepository into:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/sqlalchemy_lifecycle_orchestration.py
Moved helper group:
template lifecycle snapshot composition
template body selection from latest published snapshot
template lifecycle event insertion and loading
legal asset published snapshot + lifecycle state composition
legal asset lifecycle event insertion and loading
Compatibility check:
SqlAlchemyContractRepository still exposes the same template and legal asset repository methods.
The repository keeps the private helper names and delegates their bodies to SqlAlchemyLifecycleOrchestration.
Template/standard-clause/review-rule route behavior and response models are unchanged.
Validation:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\sqlalchemy_lifecycle_orchestration.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py -k "template or legal_asset or review_rule or clause" -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Contract API SQLAlchemy Search Orchestration Validation
Passed after extracting SQLAlchemy search delegation wrappers from SqlAlchemyContractRepository into:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/sqlalchemy_search_orchestration.py
Moved helper group:
search document id delegation
contract/file/review search-document upsert callbacks
contract search-document sync/rebuild/ensure delegation
SQLite/PostgreSQL search query delegation
Compatibility check:
SqlAlchemyContractRepository keeps the private callback method names used by audit, contract core, files, and review task persistence.
Search implementation remains in persistence/search.py.
Unified search route behavior and response models are unchanged.
Validation:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\sqlalchemy_search_orchestration.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_unified_search_returns_contract_file_and_review_task yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_upload_file_and_start_review_closes_review_entry_flow yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_review_worker_uses_uploaded_source_file_text_and_persists_ai_sources yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_create_and_update_contract_draft_persists_to_repository -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Contract API SQLAlchemy Repository Wiring Validation
Passed after extracting SqlAlchemyContractRepository.__init__ component wiring into:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/sqlalchemy_repository_wiring.py
Moved helper group:
engine/session factory construction
search/audit/contract-core persistence collaborator construction
template/legal-asset lifecycle/search orchestration collaborator construction
support/file/review-task persistence collaborator construction
file storage directory setup
Compatibility check:
SqlAlchemyContractRepository keeps the same constructor signature.
Attribute names used by existing repository methods are unchanged.
Base.metadata.create_all and seed_defaults remain controlled by SqlAlchemyContractRepository.__init__.
build_engine_kwargs and ensure_sqlite_parent_dir remain exported from contracts.py for schema-check compatibility.
Validation:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\sqlalchemy_repository_wiring.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -c "from yuqei_contract_api.contracts import SqlAlchemyContractRepository; r=SqlAlchemyContractRepository('sqlite://', auto_create=True, seed_demo_data=False); assert r.engine is not None; assert r._session_factory is not None; assert r._support is not None"
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_sqlalchemy_repository_persists_contracts_and_approval_timeline yuqei-contract-platform\services\contract-api\tests\test_tenant_isolation.py::test_default_tenant_fallback yuqei-contract-platform\services\contract-api\tests\test_health.py::test_health_endpoint_returns_contract_api_status -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Contract API SQLAlchemy Transition Orchestration Validation
Passed after extracting _transition_contract status-transition orchestration from SqlAlchemyContractRepository into:
yuqei-contract-platform/services/contract-api/src/yuqei_contract_api/sqlalchemy_transition_orchestration.py
Moved helper group:
approval/rejection/resubmission/archive workflow status transition lookup
ContractAuditRepository.transition_contract_in_session delegation
workflow ValueError to ContractWorkflowError translation
post-commit notification creation for transition events
tenant-scoped contract lookup
Compatibility check:
SqlAlchemyContractRepository keeps the same public workflow methods.
The private _transition_contract method remains as a thin delegate for existing internal call sites.
Approval timeline, audit hash-chain, archive transition, and notification behavior are unchanged.
API routes and response models are unchanged.
Validation:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\sqlalchemy_transition_orchestration.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_submit_reject_resubmit_and_approve_workflow yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_approval_decision_requires_pending_status yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_sqlalchemy_repository_persists_contracts_and_approval_timeline yuqei-contract-platform\services\contract-api\tests\test_audit_integrity.py::test_audit_integrity_verification -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Contract API Public Import/Export Surface Audit Validation
Passed after auditing the yuqei_contract_api.contracts facade import surface and removing only confirmed private unused imports:
unused standard-library / third-party leftovers from contracts.py
private legal-change helper reimports already owned by persistence/legal_change_impacts.py
private search-time helper reimport already owned by persistence/search.py
private legal-asset scoring helper reimports already owned by workflow_helpers.py
Compatibility check:
The remaining apparently-unused imports are kept because they serve active facade imports from API routes, tests, migrations, seed data, review worker, schema check, or support persistence.
Current local imports from yuqei_contract_api.contracts were enumerated and 89 imported names were verified to still exist.
ContractRepository, ContractWorkflowError, repository implementations, DTOs, SQLAlchemy models, Base, and schema-check helpers remain available from yuqei_contract_api.contracts.
Validation:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
$env:PYTHONPATH='D:\yuqei-project\ai-contract-platform\yuqei-contract-platform\services\contract-api\src'; python -c "from yuqei_contract_api.contracts import ContractDetail, ContractCreateRequest, ApprovalRule, WorkspaceSummary, Permission, UserRole, has_permission, get_permissions, normalize_role, build_workspace_summary, compute_lifecycle_stage, lifecycle_stage_from_status, normalize_contract_status, ContractRepository, ContractWorkflowError, InMemoryContractRepository, SqlAlchemyContractRepository, Base, ContractModel, build_engine_kwargs, ensure_sqlite_parent_dir"
$env:PYTHONPATH='D:\yuqei-project\ai-contract-platform\yuqei-contract-platform\services\contract-api\src'; python - <compatibility-import-check-script>
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Contract API Explicit Compatibility Export Inventory Validation
Passed after adding an explicit __all__ compatibility inventory to yuqei_contract_api.contracts:
contracts.py now documents the facade names retained for compatibility.
The inventory includes Contract API DTOs, template/legal asset DTOs, persistence models/repositories, repository implementations, workflow helpers, seed helpers, tenant context helpers, and schema-check helpers.
Implementation-only standard library and SQLAlchemy query helpers are not listed as public facade exports.
Compatibility check:
__all__ contains 261 names.
All __all__ names resolve on the module.
Current local imports from yuqei_contract_api.contracts still cover 89 imported names and all are included in __all__.
from yuqei_contract_api.contracts import * succeeds and exposes every listed name.
Validation:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
$env:PYTHONPATH='D:\yuqei-project\ai-contract-platform\yuqei-contract-platform\services\contract-api\src'; python -c "from yuqei_contract_api.contracts import ContractDetail, ContractCreateRequest, ApprovalRule, WorkspaceSummary, Permission, UserRole, has_permission, get_permissions, normalize_role, build_workspace_summary, compute_lifecycle_stage, lifecycle_stage_from_status, normalize_contract_status, ContractRepository, ContractWorkflowError, InMemoryContractRepository, SqlAlchemyContractRepository, Base, ContractModel, build_engine_kwargs, ensure_sqlite_parent_dir"
$env:PYTHONPATH='D:\yuqei-project\ai-contract-platform\yuqei-contract-platform\services\contract-api\src'; python - <__all__-compatibility-check-script>
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Contract API Route Import Migration First Slice Validation
Passed after moving the first low-risk internal route group away from the yuqei_contract_api.contracts facade import path:
api/system.py now imports system DTOs from domain.py and ContractRepository from repository_base.py.
api/templates.py now imports template DTOs/errors from contract_templates.py, ContractDetail from domain.py, and repository types/errors from repository_base.py.
api/legal_assets.py now imports TemplateNotFoundError from contract_templates.py and repository types/errors from repository_base.py.
contracts.py remains a stable compatibility facade with the same __all__ inventory.
Compatibility check:
Current local imports from yuqei_contract_api.contracts dropped from 89 names to 67 names.
All remaining local imports from yuqei_contract_api.contracts are still included in __all__.
API paths, response models, route order, and facade exports are unchanged.
Validation:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\api\system.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\api\templates.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\api\legal_assets.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_health.py yuqei-contract-platform\services\contract-api\tests\test_permissions.py yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py -k "template or legal_asset or review_rule or legal_change or health or permission" -q
$env:PYTHONPATH='D:\yuqei-project\ai-contract-platform\yuqei-contract-platform\services\contract-api\src'; python - <__all__-compatibility-check-script>
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Contract API Route Import Migration Review/Files Slice Validation
Passed after moving the next low-risk route group away from the yuqei_contract_api.contracts facade import path:
api/review.py now imports review task DTOs from persistence/review_tasks.py and repository types/errors from repository_base.py.
api/files_search_backup.py now imports backup DTOs from domain.py, file DTOs from persistence/files.py, search DTOs from persistence/search.py, and repository types/errors from repository_base.py.
contracts.py remains a stable compatibility facade with the same __all__ inventory.
Compatibility check:
Current local imports from yuqei_contract_api.contracts dropped from 67 names to 49 names.
All remaining local imports from yuqei_contract_api.contracts are still included in __all__.
Remaining route modules using the facade are api/support.py and api/contracts_core.py.
API paths, response models, route order, and facade exports are unchanged.
Validation:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\api\review.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\api\files_search_backup.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py -k "review or file or search or backup" yuqei-contract-platform\services\contract-api\tests\test_backup.py -q
$env:PYTHONPATH='D:\yuqei-project\ai-contract-platform\yuqei-contract-platform\services\contract-api\src'; python - <__all__-compatibility-check-script>
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Contract API Route Import Migration Support Slice Validation
Passed after moving api/support.py away from the yuqei_contract_api.contracts facade import path:
api/support.py now imports notification, approval-rule, obligation, signature, archive, export, and ContractDetail DTOs from domain.py.
api/support.py now imports ContractRepository and ContractWorkflowError from repository_base.py.
contracts.py remains a stable compatibility facade with the same __all__ inventory.
Compatibility check:
Current local imports from yuqei_contract_api.contracts dropped from 49 names to 42 names.
All remaining local imports from yuqei_contract_api.contracts are still included in __all__.
The only remaining API route module using the facade is api/contracts_core.py.
API paths, response models, route order, and facade exports are unchanged.
Validation:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\api\support.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py -k "support or obligation or notification or approval_rule or signature or archive or export" yuqei-contract-platform\services\contract-api\tests\test_permissions.py -q
$env:PYTHONPATH='D:\yuqei-project\ai-contract-platform\yuqei-contract-platform\services\contract-api\src'; python - <__all__-compatibility-check-script>
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Contract API Route Import Migration Contracts Core Slice Validation
Passed after moving the final API route module away from the yuqei_contract_api.contracts facade import path:
api/contracts_core.py now imports contract/workspace DTOs and normalize_role from domain.py.
api/contracts_core.py now imports ContractAuditEvent from persistence/audit.py.
api/contracts_core.py now imports ContractVersion and ContractVersionPage from persistence/contract_core.py.
api/contracts_core.py now imports ContractRepository and ContractWorkflowError from repository_base.py.
contracts.py remains a stable compatibility facade with the same __all__ inventory.
Compatibility check:
Current local imports from yuqei_contract_api.contracts dropped from 42 names to 29 names.
All remaining local imports from yuqei_contract_api.contracts are still included in __all__.
No API route modules import from yuqei_contract_api.contracts anymore.
API paths, response models, route order, and facade exports are unchanged.
Validation:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\api\contracts_core.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py yuqei-contract-platform\services\contract-api\tests\test_audit_integrity.py yuqei-contract-platform\services\contract-api\tests\test_legal_qa_proxy.py -q
$env:PYTHONPATH='D:\yuqei-project\ai-contract-platform\yuqei-contract-platform\services\contract-api\src'; python - <__all__-compatibility-check-script>
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Contract API Test Import Migration Permission/Audit Slice Validation
Passed after moving the first low-risk test group away from the yuqei_contract_api.contracts facade import path:
test_permissions.py now imports permission helpers and role/permission types from domain.py.
test_audit_integrity.py now imports ContractAuditEvent and compute_audit_event_hash from persistence/audit.py.
contracts.py remains a stable compatibility facade with the same __all__ inventory.
Compatibility check:
Current local imports from yuqei_contract_api.contracts dropped from 29 names to 22 names.
All remaining local imports from yuqei_contract_api.contracts are still included in __all__.
Remaining test facade imports are test_contract_workflow.py and test_tenant_isolation.py.
API paths, response models, route order, and facade exports are unchanged.
Validation:
python -m py_compile yuqei-contract-platform\services\contract-api\tests\test_permissions.py yuqei-contract-platform\services\contract-api\tests\test_audit_integrity.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_permissions.py yuqei-contract-platform\services\contract-api\tests\test_audit_integrity.py -q
$env:PYTHONPATH='D:\yuqei-project\ai-contract-platform\yuqei-contract-platform\services\contract-api\src'; python - <__all__-compatibility-check-script>
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed
Contract API Legal Change Persistence Validation
Passed after extracting legal change impact scan history persistence:
python -m py_compile yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\persistence\legal_change_impacts.py yuqei-contract-platform\services\contract-api\src\yuqei_contract_api\contracts.py
python -m pytest yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_legal_change_impact_scan_finds_templates_clauses_rules_and_contracts yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_legal_change_impact_scan_is_persisted_to_history yuqei-contract-platform\services\contract-api\tests\test_contract_workflow.py::test_legal_change_impact_scan_uses_published_clause_snapshot -q
python -m pytest yuqei-contract-platform\services\contract-api\tests -q
python -m pytest yuqei-contract-platform\services\contract-api\tests yuqei-ai-platform\services\ai-platform-api\tests -q
Result:
passed