ййй
This commit is contained in:
@@ -2,40 +2,78 @@ from app.modules.rag.contracts.enums import RagLayer
|
||||
from app.modules.rag.indexing.docs.pipeline import DocsIndexingPipeline
|
||||
|
||||
|
||||
def test_docs_pipeline_builds_catalog_facts_sections_and_policy() -> None:
|
||||
def test_docs_pipeline_builds_new_d0_to_d5_layers() -> None:
|
||||
pipeline = DocsIndexingPipeline()
|
||||
content = """---
|
||||
id: api.billing.create_invoice
|
||||
type: policy
|
||||
domain: billing
|
||||
type: api_method
|
||||
name: create_invoice
|
||||
title: Create Invoice API
|
||||
module: billing
|
||||
layer: application
|
||||
status: draft
|
||||
updated_at: 2026-03-23
|
||||
tags: [billing, api]
|
||||
entities: [Invoice]
|
||||
parent: billing_api
|
||||
children: []
|
||||
links:
|
||||
calls_api:
|
||||
- api.billing.validate_invoice
|
||||
tags: [billing]
|
||||
status: active
|
||||
- type: related_api
|
||||
target: api.billing.validate_invoice
|
||||
---
|
||||
# Create Invoice
|
||||
|
||||
## Spec Summary
|
||||
# Summary
|
||||
|
||||
Creates an invoice in billing.
|
||||
|
||||
## Request Contract
|
||||
# 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.
|
||||
|
||||
## Контракт
|
||||
|
||||
### Входные параметры
|
||||
|
||||
| field | type | required | validation |
|
||||
| --- | --- | --- | --- |
|
||||
| amount | decimal | yes | > 0 |
|
||||
|
||||
## Error Matrix
|
||||
### Выходные параметры
|
||||
|
||||
| field | type | required |
|
||||
| --- | --- | --- |
|
||||
| invoice_id | string | yes |
|
||||
|
||||
## Ошибки
|
||||
|
||||
| status | error | client action |
|
||||
| --- | --- | --- |
|
||||
| 400 | invalid_amount | fix request |
|
||||
|
||||
## Rules
|
||||
|
||||
- metric: billing.invoice.created
|
||||
- rule: amount must be positive
|
||||
"""
|
||||
docs = pipeline.index_file(
|
||||
repo_id="acme/proj",
|
||||
@@ -45,19 +83,31 @@ Creates an invoice in billing.
|
||||
)
|
||||
|
||||
layers = {doc.layer for doc in docs}
|
||||
assert RagLayer.DOCS_MODULE_CATALOG in layers
|
||||
assert RagLayer.DOCS_DOC_CHUNKS in layers
|
||||
assert RagLayer.DOCS_DOCUMENT_CATALOG in layers
|
||||
assert RagLayer.DOCS_FACT_INDEX in layers
|
||||
assert RagLayer.DOCS_SECTION_INDEX in layers
|
||||
assert RagLayer.DOCS_POLICY_INDEX in layers
|
||||
assert RagLayer.DOCS_ENTITY_CATALOG in layers
|
||||
assert RagLayer.DOCS_WORKFLOW_INDEX in layers
|
||||
assert RagLayer.DOCS_RELATION_GRAPH in layers
|
||||
|
||||
module_doc = next(doc for doc in docs if doc.layer == RagLayer.DOCS_MODULE_CATALOG)
|
||||
assert module_doc.metadata["module_id"] == "api.billing.create_invoice"
|
||||
assert module_doc.metadata["type"] == "policy"
|
||||
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"
|
||||
|
||||
fact_texts = [doc.text for doc in docs if doc.layer == RagLayer.DOCS_FACT_INDEX]
|
||||
assert any("calls_api" in text for text in fact_texts)
|
||||
assert any("has_field" in text for text in fact_texts)
|
||||
assert any("returns_error" in text for text in fact_texts)
|
||||
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)
|
||||
|
||||
section_doc = next(doc for doc in docs if doc.layer == RagLayer.DOCS_SECTION_INDEX)
|
||||
assert section_doc.metadata["section_path"]
|
||||
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
|
||||
|
||||
chunk_doc = next(doc for doc in docs if doc.layer == RagLayer.DOCS_DOC_CHUNKS)
|
||||
assert chunk_doc.metadata["section_path"]
|
||||
|
||||
Reference in New Issue
Block a user