Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions dokimi/tests/data/cli_emits_unwrapped.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright (C) 2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

# Ratchet for the --json envelope wrap (tests/test_cli_emits_ratchet.py, issue #94 F2).
#
# One leaf per row, as its command words: `eval personas discover`. A leaf listed here has no
# `emits_cli_output` default on its parser yet (cli_output.v1 is not guaranteed for its --json).
# The list only shrinks: a row for a leaf that is now wrapped, or no longer a leaf, fails the test,
# which names the row to delete. A leaf that is not listed must be wrapped, so a new command
# opts in with `set_defaults(emits_cli_output=True, cli_kind=...)` or adds no row to pass.
answers generate
arms matrix-run
arms plugin-delta
arms run
baseline compare
baseline list
baseline save
benchmark batch
benchmark preflight
benchmark run
catalog intents
catalog list
catalog novelty
catalog provenance
catalog repair-receipt
catalog routing
catalog routing-compare
catalog show
catalog trigger-probe
dashboard generate
data export
data import docling
data schema list
data schema show
docs check
docs compare
eval headroom
eval import
eval judge agreement
eval judge validate
eval judge wording
eval leak
eval native-import
eval personas validate
eval questions analyze
eval questions generate
eval questions refine
eval questions review
eval redteam
eval score checklist
eval score grounding
eval score pairwise
eval score panel
eval score pointwise
eval score ragas
eval score reference
eval tasks generate
eval tasks list
eval triggers generate
evaluate
explore run
repo hits sheet
repo reach
repo run
repo security
repo skill-reach
report eval
report generate
report model-compare
report opportunities
report summary
runs export
skill check
skill novelty analyze
skill novelty atoms
skill novelty ground
skill novelty items
skill novelty probe
skill novelty retest
skill novelty view
skill sensitivity
skill shorten
subjects evidence
subjects run
tasks harnesses
tasks run
71 changes: 71 additions & 0 deletions dokimi/tests/test_cli_emits_ratchet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright (C) 2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

"""Every CLI leaf is wrapped by the --json envelope, or listed as not yet (issue #94 F2).

A leaf is wrapped when its parser sets ``emits_cli_output`` (``set_defaults``); the envelope of a
--json run of it is then cli_output.v1 on every exit. ``tests/data/cli_emits_unwrapped.txt`` lists
the leaves that are not wrapped today. The list only shrinks: a new unlisted unwrapped leaf fails,
and a listed leaf that is now wrapped (or gone) fails until its row is deleted.
"""

from __future__ import annotations

import argparse
from pathlib import Path

from dokimi import cli

ALLOWLIST = Path(__file__).parent / "data" / "cli_emits_unwrapped.txt"


def _leaves(parser: argparse.ArgumentParser, prefix: tuple[str, ...] = ()):
"""Every leaf parser under ``parser`` as (path, parser); an alias is the same parser twice."""
sub = next((a for a in parser._actions if isinstance(a, argparse._SubParsersAction)), None)
if sub is None:
yield prefix, parser
return
seen: set[int] = set()
for name, child in sub.choices.items():
if id(child) in seen:
continue
seen.add(id(child))
yield from _leaves(child, (*prefix, name))


def _wrapped_and_not() -> tuple[set[str], set[str]]:
wrapped, unwrapped = set(), set()
for path, parser in _leaves(cli.build_parser()):
(wrapped if parser.get_default("emits_cli_output") else unwrapped).add(" ".join(path))
return wrapped, unwrapped


def _listed() -> list[str]:
rows = (line.split("#", 1)[0].strip() for line in ALLOWLIST.read_text(encoding="utf-8").splitlines())
return [row for row in rows if row]


def test_every_leaf_is_wrapped_or_listed_as_not_yet():
_, unwrapped = _wrapped_and_not()
new = sorted(unwrapped - set(_listed()))
assert not new, (
"these leaves have no emits_cli_output default and are not in tests/data/cli_emits_unwrapped.txt:\n "
+ "\n ".join(new)
+ "\nWrap each with set_defaults(emits_cli_output=True, cli_kind=...) and no row is needed."
)


def test_a_listed_leaf_is_still_unwrapped():
wrapped, unwrapped = _wrapped_and_not()
listed = _listed()
now_wrapped = sorted(row for row in listed if row in wrapped)
gone = sorted(row for row in listed if row not in wrapped and row not in unwrapped)
assert not (now_wrapped or gone), (
"delete these rows from tests/data/cli_emits_unwrapped.txt (wrapped now, or no such leaf):\n "
+ "\n ".join([*now_wrapped, *gone])
)


def test_the_list_has_no_duplicate_rows():
listed = _listed()
assert sorted({row for row in listed if listed.count(row) > 1}) == []
Loading