156 lines
4.5 KiB
Python
156 lines
4.5 KiB
Python
from app.core.rag.contracts.enums import RagLayer
|
|
from app.core.rag.indexing.docs.pipeline import DocsIndexingPipeline
|
|
|
|
|
|
def test_docs_pipeline_builds_docs_layers_from_modern_markdown_structure() -> None:
|
|
pipeline = DocsIndexingPipeline()
|
|
content = """---
|
|
id: api.billing.create_invoice
|
|
type: api_method
|
|
doc_type: api_method
|
|
name: create_invoice
|
|
title: Create Invoice API
|
|
module: billing
|
|
domain: billing
|
|
sub_domain: invoices
|
|
layer: application
|
|
status: draft
|
|
updated_at: 2026-03-23
|
|
tags: [billing, api]
|
|
entities: [Invoice]
|
|
parent: billing_api
|
|
children: []
|
|
related_docs: [api.billing.validate_invoice]
|
|
links:
|
|
called_by:
|
|
- ui.billing.invoice_form
|
|
uses_logic:
|
|
- logic.billing.invoice_validation
|
|
---
|
|
# Create Invoice API
|
|
|
|
## Summary
|
|
|
|
Creates an invoice in billing.
|
|
|
|
## Details
|
|
|
|
### Описание
|
|
|
|
Создает счет на оплату.
|
|
|
|
### Сценарий
|
|
|
|
**Название:**
|
|
Create invoice
|
|
|
|
**Предусловия:**
|
|
- billing service is available
|
|
|
|
**Триггер:**
|
|
- client sends create invoice request
|
|
|
|
**Основной сценарий:**
|
|
1. Validate payload.
|
|
2. Create invoice.
|
|
|
|
**Альтернативный сценарий:**
|
|
1. Reject invalid payload.
|
|
|
|
**Обработка ошибок:**
|
|
1. Return validation error.
|
|
|
|
**Постусловие:**
|
|
- Invoice is created.
|
|
|
|
### Контракт
|
|
|
|
#### Метаданные вызова
|
|
- Method: POST
|
|
- Auth: USER
|
|
- Idempotency: false
|
|
|
|
### Входные параметры
|
|
|
|
| field | type | required | validation |
|
|
| --- | --- | --- | --- |
|
|
| amount | decimal | yes | > 0 |
|
|
|
|
### Выходные параметры
|
|
|
|
| field | type | required |
|
|
| --- | --- | --- |
|
|
| invoice_id | string | yes |
|
|
|
|
### Интеграции
|
|
|
|
#### Billing DB
|
|
- target: db.billing.invoices
|
|
- target_type: db
|
|
- direction: outbound
|
|
- interaction: writes
|
|
- via: invoice repository
|
|
- purpose: persist created invoices
|
|
- details:
|
|
- transaction: required
|
|
- tables:
|
|
- invoices
|
|
- invoice_items
|
|
|
|
### Ошибки
|
|
|
|
| status | error | client action |
|
|
| --- | --- | --- |
|
|
| 400 | invalid_amount | fix request |
|
|
"""
|
|
docs = pipeline.index_file(
|
|
repo_id="acme/proj",
|
|
commit_sha="abc123",
|
|
path="docs/billing/create_invoice.md",
|
|
content=content,
|
|
)
|
|
|
|
layers = {doc.layer for doc in docs}
|
|
assert RagLayer.DOCS_DOC_CHUNKS in layers
|
|
assert RagLayer.DOCS_DOCUMENT_CATALOG in layers
|
|
assert RagLayer.DOCS_FACT_INDEX in layers
|
|
assert RagLayer.DOCS_ENTITY_CATALOG in layers
|
|
assert RagLayer.DOCS_WORKFLOW_INDEX in layers
|
|
assert RagLayer.DOCS_RELATION_GRAPH in layers
|
|
assert RagLayer.DOCS_INTEGRATION_INDEX in layers
|
|
|
|
catalog_doc = next(doc for doc in docs if doc.layer == RagLayer.DOCS_DOCUMENT_CATALOG)
|
|
assert catalog_doc.metadata["document_id"] == "api.billing.create_invoice"
|
|
assert catalog_doc.metadata["module"] == "billing"
|
|
assert catalog_doc.metadata["domain"] == "billing"
|
|
assert catalog_doc.metadata["subdomain"] == "invoices"
|
|
assert catalog_doc.metadata["summary_text"] == "Creates an invoice in billing."
|
|
|
|
fact_texts = [doc.text for doc in docs if doc.layer == RagLayer.DOCS_FACT_INDEX]
|
|
assert any("has_field amount" in text for text in fact_texts)
|
|
assert any("field_required amount:yes" in text for text in fact_texts)
|
|
assert any("returns_error invalid_amount" in text for text in fact_texts)
|
|
|
|
entity_doc = next(doc for doc in docs if doc.layer == RagLayer.DOCS_ENTITY_CATALOG)
|
|
assert entity_doc.metadata["entity_name"] == "Invoice"
|
|
|
|
workflow_doc = next(doc for doc in docs if doc.layer == RagLayer.DOCS_WORKFLOW_INDEX)
|
|
assert workflow_doc.metadata["workflow_name"] == "Create invoice"
|
|
|
|
relation_targets = [doc.metadata["target_id"] for doc in docs if doc.layer == RagLayer.DOCS_RELATION_GRAPH]
|
|
assert "billing_api" in relation_targets
|
|
assert "api.billing.validate_invoice" in relation_targets
|
|
assert "logic.billing.invoice_validation" in relation_targets
|
|
assert "Invoice" in relation_targets
|
|
|
|
chunk_doc = next(doc for doc in docs if doc.layer == RagLayer.DOCS_DOC_CHUNKS)
|
|
assert chunk_doc.metadata["section_path"]
|
|
assert chunk_doc.metadata["artifact_type"] == "DOCS"
|
|
assert chunk_doc.metadata["domain"] == "billing"
|
|
assert chunk_doc.metadata["subdomain"] == "invoices"
|
|
|
|
integration_doc = next(doc for doc in docs if doc.layer == RagLayer.DOCS_INTEGRATION_INDEX)
|
|
assert integration_doc.metadata["target"] == "db.billing.invoices"
|
|
assert integration_doc.metadata["target_type"] == "db"
|
|
assert integration_doc.metadata["details"]["transaction"] == "required"
|