# lawref.cases

*module*

Регистрация дел пакета-дела [§168.4](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/24-part-xxiii-cases-snapshots-evaluation.ru.md#1684-пакет-дело-и-операция-ask-decision-0165) (DECISION-0165 [§1.4](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/01-part-i-audit.ru.md#1-что-сохраняется-без-изменений)): секция `[[cases]]`.

Секция — метаданные обнаружения по образцу `[[tests]]` (DECISION-0127): в
нормативную схему манифеста она не входит, оба разбора манифеста её
отбрасывают до валидации. Читают её загрузчик пакета-дела (`lawref.ask`,
`ops::ask` компилятора), выпуск (`apps/registry/package.py`) и ворота
`check_lawcase_discovery`. Здесь — общий читатель и проверка полноты:
осиротевший `.lawcase` в границах пакета, запись без файла, запись без
одноимённой декларации `case`, дубль пары (путь, имя) — отказ `LDC-E1354`,
а не тихий ноль (класс молчаливой потери CLAUDE.md).

## lawref.cases.CASES_CODE

*attribute* · *module attribute*

```python
CASES_CODE = 'LDC-E1354'
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L20-L20)

## lawref.cases.SKIPPED_DIRS

*attribute* · *module attribute*

```python
SKIPPED_DIRS = frozenset({'deps', 'release', 'releases', '.git', '__pycache__', 'target'})
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L25-L25)

## lawref.cases.CasesError

*class*

```python
class CasesError(ValueError)
```

Bases: `ValueError`

Отказ регистрации дел; `code` — канонический код диагностики.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L30-L37)

### lawref.cases.CasesError.code

*attribute* · *class attribute* · *instance attribute*

```python
code = CASES_CODE
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L33-L33)

### lawref.cases.CasesError.message

*attribute* · *instance attribute*

```python
message = message
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L37-L37)

## lawref.cases.RegisteredCase

*class* · *dataclass*

```python
class RegisteredCase
```

Одна строка `[[cases]]`: имя декларации и путь файла внутри пакета.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L40-L48)

### lawref.cases.RegisteredCase.name

*attribute* · *instance attribute*

```python
name: str
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L44-L44)

### lawref.cases.RegisteredCase.path

*attribute* · *instance attribute*

```python
path: str
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L45-L45)

### lawref.cases.RegisteredCase.file

*method*

```python
def file(root: Path) -> Path
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L47-L48)

## lawref.cases.RegistrationChecked

*class* · *dataclass*

```python
class RegistrationChecked
```

Свидетельство шага «регистрация дел пакета полна» (LDC-E1354, [§168.4](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/24-part-xxiii-cases-snapshots-evaluation.ru.md#1684-пакет-дело-и-операция-ask-decision-0165)).

Регистрация — свойство манифеста и дерева пакета, а не дела. Хост,
исполняющий много дел одного открытого пакета (`population-impact`,
DECISION-0255 [§1](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/01-part-i-audit.ru.md#1-что-сохраняется-без-изменений)), проверяет её один раз при открытии стороны и подаёт
свидетельство в `ask.prepare`/`ask.ask`: без него каждая строка читала
манифест и все `.lawcase` пакета заново (O(N²) на пакет из N дел, O(N³) на
прогон; повтор Ф6, 16.09.2026, [§9](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/04-part-iv-project-and-files.ru.md#9-стандартная-структура-проекта)). Одиночный `ask` свидетельства не имеет
и проверяет на прежнем месте — порядок отказов [§168.4](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/24-part-xxiii-cases-snapshots-evaluation.ru.md#1684-пакет-дело-и-операция-ask-decision-0165) не меняется. Образец —
`ask.ResourcesChecked`; у порта регистрация на строке не вызывается вовсе.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L109-L123)

### lawref.cases.RegistrationChecked.entries

*attribute* · *instance attribute*

```python
entries: tuple[RegisteredCase, ...]
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L123-L123)

### lawref.cases.RegistrationChecked.root

*attribute* · *instance attribute*

```python
root: Path
```

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L122-L122)

## lawref.cases.check_package_registration

*function*

```python
def check_package_registration(root: Path) -> RegistrationChecked
```

Регистрация дел пакета: отказ `CasesError`, иначе свидетельство.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L179-L182)

## lawref.cases.check_registration

*function*

```python
def check_registration(root: Path, registered: list[RegisteredCase] | None = None) -> list[RegisteredCase]
```

Полнота регистрации дел пакета: возвращает список записей либо
поднимает `CasesError` с первой найденной потерей.

Проверяются: дубль пары (путь, имя); запись без файла; запись без
одноимённой декларации в файле; файл `.lawcase` в границах пакета, не
названный ни одной записью; декларация `case` файла, не названная ни одной
записью (вторая декларация в файле — тоже дело, и его потеря молчалива).

Имена записей индексируются по пути одним проходом, декларации файла
читаются один раз за вызов (как `law_cli_core::ask::check_registration`):
прежний перебор всех записей на каждый файл стоил O(N²). Порядок и текст
отказов прежние: записи — в порядке манифеста, файлы — в порядке обхода.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L126-L176)

## lawref.cases.declared_case_names

*function*

```python
def declared_case_names(text: str) -> list[str]
```

Имена деклараций `case` в исходнике (поверхностный разбор: одна
декларация на строку заголовка, как пишет форматер [§227](https://github.com/arxohq/law/blob/master/spec/SPEC.ru/30-part-xxix-ux-dx-specification.ru.md#227-stable-formatting-and-comments)).

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L83-L86)

## lawref.cases.discover_lawcases

*function*

```python
def discover_lawcases(root: Path) -> list[Path]
```

Все `.lawcase` в границах пакета: без `deps/`, выпусков и вложенных
пакетов (собственный `law.toml` — другой корень, T102).

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L89-L106)

## lawref.cases.read_cases_section

*function*

```python
def read_cases_section(law_toml_bytes: bytes) -> list[RegisteredCase]
```

`[[cases]]` манифеста в порядке записи; форма каждой строки проверяется.

Секция читается ИЗ СЫРОГО TOML: `parse_manifest` её отбрасывает, и это
намеренно (нормативная схема манифеста не растёт под метаданные обнаружения).

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L51-L80)

## lawref.cases.select_case

*function*

```python
def select_case(registered: list[RegisteredCase], wanted: str | None) -> RegisteredCase
```

Выбор дела по имени; при одном зарегистрированном деле имя необязательно.
Пустой выбор при нескольких делах и неизвестное имя — отказ `LDC-E1354`.

[View source](https://github.com-arxohq/arxo-io/law/blob/2edc2b92ce22b52e03f4081d2769a58229684379/engines/lawref/lawref/cases.py#L185-L201)
