# madbot_cli.checks

*module*

Check a deposit file against the schemas the instance publishes, before any write.

madbot checks on write the shared parameters and the credentials of a
connection, the settings of a submission and each metadata value. It
publishes the schema of each: `plan` and `apply` check the file against them
first, so that every value madbot would refuse is reported at once, with what
it expects, instead of one by one in the middle of an `apply`.

madbot stays the judge: a format the client cannot check offline, such as an
ORCID or a taxon looked up in a referential, is left to madbot.

Credentials never appear in a message: only their keys and the form the
plugin expects.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L1-1)

## madbot_cli.checks.CLOSEST

*attribute* · *module attribute*

```python
CLOSEST = 3
```

How many close values a message proposes.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L41-41)

## madbot_cli.checks.FORMATS

*attribute* · *module attribute*

```python
FORMATS = {'date': 'a full date, YYYY-MM-DD', 'date-time': 'a date and a time, YYYY-MM-DDThh:mm:ss', 'time': 'a time, hh:mm:ss', 'email': 'an email address'}
```

What a format of JSON Schema asks for, in words.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L47-52)

## madbot_cli.checks.FORMAT_CHECKER

*attribute* · *module attribute*

```python
FORMAT_CHECKER = jsonschema.Draft201909Validator.FORMAT_CHECKER
```

The formats checked offline; madbot checks the others itself.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L66-66)

## madbot_cli.checks.SHOWN_CHOICES

*attribute* · *module attribute*

```python
SHOWN_CHOICES = 5
```

How many allowed values a message lists, at most.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L44-44)

## madbot_cli.checks.TYPES

*attribute* · *module attribute*

```python
TYPES = {'string': 'a text', 'integer': 'a whole number', 'number': 'a number', 'boolean': 'true or false', 'object': 'an object (key: value)', 'array': 'a list', 'null': 'nothing'}
```

What a type of JSON Schema asks for, in words.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L55-63)

## madbot_cli.checks.CheckError

*class*

```python
class CheckError(MadbotError)
```

Bases: `madbot_cli.errors.MadbotError`

The file gives values madbot would refuse.

**Attributes**

- `errors` (`list of str`) — One message per value, each starting with where it is in the file.

**Parameters**

- `errors` (`list of str`) — One message per value.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L70-93)

### madbot_cli.checks.CheckError.errors

*attribute* · *instance attribute*

```python
errors = errors
```

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L89-89)

## madbot_cli.checks.Schemas

*class*

```python
class Schemas
```

The schemas and the fields the instance publishes, read once per command.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L96-145)

### madbot_cli.checks.Schemas.client

*attribute* · *instance attribute*

```python
client = client
```

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L101-101)

### madbot_cli.checks.Schemas.fields

*method*

```python
def fields(source: str) -> dict[str, list[dict]]
```

List the metadata fields of a plugin, by slug.

**Parameters**

- `source` (`str`) — The slug of the plugin.

**Returns**

- (`dict`) — The fields of each slug, as the API returns them.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L125-145)

### madbot_cli.checks.Schemas.schema

*method*

```python
def schema(url: str) -> dict
```

Read a schema, its definitions put in place.

**Parameters**

- `url` (`str`) — Its address, as the API gives it.

**Returns**

- (`dict`) — The schema.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L105-123)

## madbot_cli.checks.check

*function*

```python
def check(client: Client, state: State, manifest: Manifest, environ: Mapping[str, str] | None = None) -> list[str]
```

Check a deposit file against the schemas the instance publishes.

Only what apply would write is checked: a connection madbot holds keeps
its parameters, and the metadata of a submission already sent to its
repository cannot change.

**Parameters**

- `client` (`Client`) — The client.
- `state` (`State`) — What madbot holds.
- `manifest` (`Manifest`) — The deposit file.
- `environ` (`mapping`) (default: `None`) — The environment holding the credentials.

**Returns**

- (`list of str`) — One message per value madbot would refuse; empty when there is none.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L924-965)

## madbot_cli.checks.check_connection

*function*

```python
def check_connection(schemas: Schemas, plugins: list[dict], spec: Mapping[str, Any], where: str, planned: Mapping, environ: Mapping[str, str] | None = None) -> list[str]
```

Check the shared parameters and the credentials of a source or a repository.

The shared parameters are checked when the connection is to be created:
one madbot holds has them already. The credentials are checked when
apply would send them.

**Parameters**

- `schemas` (`Schemas`) — The schemas of the instance.
- `plugins` (`list of dict`) — The plugins of the instance.
- `spec` (`mapping`) — ``plugin``, ``shared_params`` and ``credentials_env`` from the file.
- `where` (`str`) — Where it is in the file, such as ``sources.reads``.
- `planned` (`mapping`) — The plan of the connection, with its ``action`` and ``credentials``.
- `environ` (`mapping`) (default: `None`) — The environment holding the credentials.

**Returns**

- (`list of str`) — One message per error.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L680-738)

## madbot_cli.checks.check_metadata

*function*

```python
def check_metadata(schemas: Schemas, plugin: Mapping, metadata: Mapping[str, Any], where: str) -> list[str]
```

Check each metadata value of a submission against the schema of its field.

**Parameters**

- `schemas` (`Schemas`) — The schemas of the instance.
- `plugin` (`mapping`) — The plugin of the repository, whose fields the values fill.
- `metadata` (`mapping`) — The ``metadata`` of the submission in the file.
- `where` (`str`) — The submission, in the messages.

**Returns**

- (`list of str`) — One message per value madbot would find invalid, that YAML read as a date, or given for no field of the repository: madbot would refuse the whole write, and a typo would leave the value unwritten.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L854-918)

## madbot_cli.checks.check_params

*function*

```python
def check_params(known: Mapping[str, Mapping], given: Mapping[str, Any], where: str, plugin: Mapping, *, secret: bool = False) -> list[str]
```

Check the parameters of a connection against those of its plugin.

**Parameters**

- `known` (`mapping`) — The schema of each parameter of the plugin, by key.
- `given` (`mapping`) — The parameters of the file, or the credentials.
- `where` (`str`) — Where they are, in the messages.
- `plugin` (`mapping`) — The plugin.
- `secret` (`bool`) (default: `False`) — True for credentials: no message shows a value.

**Returns**

- (`list of str`) — One message per key unknown, missing or of a value madbot refuses.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L629-677)

## madbot_cli.checks.check_settings

*function*

```python
def check_settings(schemas: Schemas, plugin: Mapping, settings: Mapping[str, Any], where: str) -> list[str]
```

Check the settings of a submission to create against those of its repository.

**Parameters**

- `schemas` (`Schemas`) — The schemas of the instance.
- `plugin` (`mapping`) — The plugin of the repository.
- `settings` (`mapping`) — The settings of the file.
- `where` (`str`) — Where they are in the file.

**Returns**

- (`list of str`) — One message per setting unknown, missing while mandatory, or of a value madbot refuses.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L744-791)

## madbot_cli.checks.check_submission

*function*

```python
def check_submission(schemas: Schemas, state: State, submission: Submission, environ: Mapping[str, str] | None = None) -> list[str]
```

Check the repository, the settings and the metadata of a submission.

**Parameters**

- `schemas` (`Schemas`) — The schemas of the instance.
- `state` (`State`) — What madbot holds.
- `submission` (`Submission`) — The submission.
- `environ` (`mapping`) (default: `None`) — The environment holding the credentials.

**Returns**

- (`list of str`) — One message per error.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L968-1008)

## madbot_cli.checks.check_value

*function*

```python
def check_value(schema: Mapping, value: Any, *, secret: bool = False) -> list[str]
```

Check a value against its schema, as madbot does on write.

**Parameters**

- `schema` (`mapping`) — The JSON Schema, its definitions in place.
- `value` (`Any`) — The value.
- `secret` (`bool`) (default: `False`) — True for credentials: no message shows the value.

**Returns**

- (`list of str`) — What is wrong, empty when the value is valid.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L523-550)

## madbot_cli.checks.closest

*function*

```python
def closest(value: Any, choices: Iterable[Mapping]) -> list[str]
```

Find the allowed values closest to a value, by their text or their title.

**Parameters**

- `value` (`Any`) — The value given.
- `choices` (`iterable of mapping`) — The allowed values, as `madbot_cli.discover.choices_of` gives them.

**Returns**

- (`list of str`) — At most `CLOSEST` values, the closest first.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L168-193)

## madbot_cli.checks.deepest

*function*

```python
def deepest(error: jsonschema.ValidationError) -> jsonschema.ValidationError
```

Follow an error of forms to the error of the form closest to the value.

**Parameters**

- `error` (`ValidationError`) — An error, maybe of ``oneOf`` or ``anyOf``.

**Returns**

- (`ValidationError`) — The error to explain. An error of forms whose forms are only fixed values stays as it is: its message is the list of values.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L381-401)

## madbot_cli.checks.described

*function*

```python
def described(known: Mapping[str, Mapping]) -> str
```

Describe the parameters a plugin expects, with their values.

**Parameters**

- `known` (`mapping`) — The schema of each parameter, by key.

**Returns**

- (`str`) — Such as ``url: one of https://a or https://b; token: a text``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L607-626)

## madbot_cli.checks.expected

*function*

```python
def expected(schema: Mapping) -> str
```

Say in words what a schema accepts.

**Parameters**

- `schema` (`mapping`) — The JSON Schema of a value.

**Returns**

- (`str`) — Such as ``one of a or b``, ``a full date, YYYY-MM-DD``, or ``a text``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L220-255)

## madbot_cli.checks.expected_across

*function*

```python
def expected_across(found: list[tuple[str, Mapping]]) -> str
```

Say in words what a part expects, in each form of the object that has it.

**Parameters**

- `found` (`list of tuple`) — The title of each form that has the part (``form 2`` when it has none), with the schema of the part in it.

**Returns**

- (`str`) — What it expects; the fixed values of the forms together, each once, such as ``one of A or B``; or else what each form expects, by its title, the forms that expect the same said together.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L307-336)

## madbot_cli.checks.explain

*function*

```python
def explain(error: jsonschema.ValidationError, *, secret: bool = False) -> str
```

Say what is wrong with a value and what is expected instead.

**Parameters**

- `error` (`ValidationError`) — The error of the value.
- `secret` (`bool`) (default: `False`) — True for credentials: the message never shows the value.

**Returns**

- (`str`) — The message, starting with the part of the value when it is inside it.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L463-520)

## madbot_cli.checks.key_of

*function*

```python
def key_of(url: str) -> str
```

Return the key a schema address stands for.

**Parameters**

- `url` (`str`) — The address of the schema of a parameter or a setting.

**Returns**

- (`str`) — Its last part, which the API builds from the slug.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L151-165)

## madbot_cli.checks.listed

*function*

```python
def listed(values: Iterable[Any], limit: int = SHOWN_CHOICES) -> str
```

Write values in a sentence, cut when they are many.

**Parameters**

- `values` (`iterable`) — The values.
- `limit` (`int`) (default: `SHOWN_CHOICES`) — How many are written.

**Returns**

- (`str`) — Such as ``a, b or c``, or ``a, b, c… (12 values)``.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L196-217)

## madbot_cli.checks.metadata_values

*function*

```python
def metadata_values(metadata: Mapping[str, Any]) -> Iterable[tuple[str, str, Any]]
```

List the values of the metadata of a submission, with where they are.

**Parameters**

- `metadata` (`mapping`) — The ``metadata`` of a submission in the file.

**Yields**

- (`tuple`) — Where the value is (such as ``metadata.sample.by_alias.s1.r__date``), the slug of its field, and the value without its empty parts. An empty value is left out: apply writes nothing for it.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L797-825)

## madbot_cli.checks.object_parts

*function*

```python
def object_parts(schema: Mapping) -> list[dict]
```

List the parts of an object a metadata field holds, to write it with its keys.

A field of several forms, all objects (such as an instrument of one form
per platform), gives every key of its forms; a part that differs from a
form to another says what each form expects.

**Parameters**

- `schema` (`mapping`) — The JSON Schema of the field.

**Returns**

- (`list of dict`) — Each part with its ``key``, whether every form ``required`` it, and what it ``expected``, in words. Empty when the field is not an object, or may be something else than an object (such as a date).

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L258-304)

## madbot_cli.checks.parameters

*function*

```python
def parameters(schemas: Schemas, urls: Iterable[str]) -> dict[str, dict]
```

Read the schemas of the parameters of a plugin, by key.

madbot checks ``{key: value}`` against the schema of each key. A schema
holding several keys is split, one object schema per key.

**Parameters**

- `schemas` (`Schemas`) — The schemas of the instance.
- `urls` (`iterable of str`) — The addresses of the schemas, as the plugin gives them.

**Returns**

- (`dict`) — The schema of each parameter by its key: an object holding that key, required when its schema requires it.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L573-604)

## madbot_cli.checks.plugin_hint

*function*

```python
def plugin_hint(plugin: Mapping) -> str
```

Name the discovery command that describes a plugin.

**Parameters**

- `plugin` (`mapping`) — The plugin, as the API returns it.

**Returns**

- (`str`) — Such as ``see `madbot-cli plugins ena```.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L556-570)

## madbot_cli.checks.require

*function*

```python
def require(client: Client, state: State, manifest: Manifest, environ: Mapping[str, str] | None = None) -> None
```

Stop when the file gives values madbot would refuse.

**Parameters**

- `client` (`Client`) — The client.
- `state` (`State`) — What madbot holds.
- `manifest` (`Manifest`) — The deposit file.
- `environ` (`mapping`) (default: `None`) — The environment holding the credentials.

**Raises**

- `CheckError` — With every value madbot would refuse.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L1011-1038)

## madbot_cli.checks.unnamed_form

*function*

```python
def unnamed_form(error: jsonschema.ValidationError, *, secret: bool = False) -> str | None
```

Say which part of an object names its form, when the value names none.

The forms of a field are told apart by a fixed part, such as
``library_layout`` set to ``single`` or ``paired``. A value naming no
form fails every form; the error of the first one alone, ``'single'
was expected``, would hide the others.

**Parameters**

- `error` (`ValidationError`) — An error, maybe of ``oneOf`` or ``anyOf``.
- `secret` (`bool`) (default: `False`) — True for credentials: the message never shows the value.

**Returns**

- (`str or None`) — Such as ``library_layout: 'PAIRED' names no form; one of 'single' or 'paired'``; None when the error is of another kind.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L404-460)

## madbot_cli.checks.unquoted_date

*function*

```python
def unquoted_date(value: Any) -> datetime.date | None
```

Find a date YAML read from an unquoted value, such as ``2026-11-02``.

**Parameters**

- `value` (`Any`) — A metadata value of the file.

**Returns**

- (`datetime.date or None`) — The first date or date and time found in the value, or None.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L828-851)

## madbot_cli.checks.variant_of

*function*

```python
def variant_of(schema: Mapping, value: Any) -> Mapping
```

Choose the form of a schema a value names by its fixed parts.

An instrument ``{platform: X, model: …}`` is checked against the form of
platform X, so that the message is about its model, not about every form.

**Parameters**

- `schema` (`mapping`) — A JSON Schema, with ``oneOf`` or ``anyOf`` forms or without.
- `value` (`Any`) — The value.

**Returns**

- (`mapping`) — The form named, merged with the rest of the schema; the schema itself when the value names no single form.

[View source](https://gitlab.com/ifb-elixirfr/madbot/madbot/-/blob/c7108faae5e7dd06591be53c8d5bd5e75d880ebe/cli/madbot_cli/checks.py#L339-378)
