Skip to content
Merged
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,10 @@ dailybot checkin questions add <followup_uuid> --type text --question "Focus tod
dailybot checkin questions reorder <followup_uuid> <q2> <q1>
```

> **Question types:** `text`, `multiple_choice`, `boolean`, `numeric` (the complete
> catalog). `multiple_choice` needs `--options`; `boolean` auto-generates Yes/No
> (don't pass options). Up to 50 questions per form/check-in.
> **Question types:** `text`, `multiple_choice`, `boolean`, `numeric`; forms also
> take `file` (an image or PDF people attach; never the blocker). `multiple_choice`
> needs `--options`; `boolean` auto-generates Yes/No (don't pass options). Up to 50
> questions per form/check-in.
>
> **Per-question extras** (on `questions add`/`edit`, forms and check-ins):
> `--short-question` (title shown in web & chat reports), `--variation` (repeatable
Expand Down
31 changes: 22 additions & 9 deletions dailybot_cli/commands/authoring_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

# Question types accepted by the server. Anything else is rejected with 400.
VALID_QUESTION_TYPES: tuple[str, ...] = ("text", "multiple_choice", "boolean", "numeric")
# Tables (forms) also take a ``file`` question: people attach images or PDFs.
# Check-ins can't ask for an upload, so the server refuses it there.
FORM_QUESTION_TYPES: tuple[str, ...] = (*VALID_QUESTION_TYPES, "file")
# Server-side ceiling; mirrored here so the CLI fails fast on obviously-too-many.
MAX_QUESTIONS: int = 50
# Report-channel cap (forms + check-ins); server rejects > 3 with too_many_report_channels.
Expand Down Expand Up @@ -202,6 +205,7 @@ def build_question(
short_question: str | None = None,
variations: list[str] | None = None,
logic: dict[str, Any] | None = None,
allowed_types: tuple[str, ...] = VALID_QUESTION_TYPES,
) -> dict[str, Any]:
"""Build a validated question payload (explicit ``question_type``/``question``).

Expand All @@ -211,13 +215,16 @@ def build_question(
``short_question`` (report title), ``variations`` (alternate phrasings), and
``logic`` (conditional branching) are optional per-question extras; callers
pass already-validated values (see ``resolve_question_extras``).
``allowed_types`` is ``VALID_QUESTION_TYPES`` for check-ins and
``FORM_QUESTION_TYPES`` (adds ``file``) for tables.
"""
qtype: str = question_type.strip().lower()
if qtype not in VALID_QUESTION_TYPES:
if qtype not in allowed_types:
raise AuthoringError(
f"Invalid question type '{question_type}'. "
f"Choose from: {', '.join(VALID_QUESTION_TYPES)}."
f"Invalid question type '{question_type}'. Choose from: {', '.join(allowed_types)}."
)
if qtype == "file" and is_blocker:
raise AuthoringError("A file question can't be the blocker question.")
text: str = question.strip()
if not text:
raise AuthoringError("Question text is required.")
Expand Down Expand Up @@ -528,11 +535,14 @@ def resolve_question_extras(
return extras


def parse_questions_file(path: str) -> list[dict[str, Any]]:
def parse_questions_file(
path: str, allowed_types: tuple[str, ...] = VALID_QUESTION_TYPES
) -> list[dict[str, Any]]:
"""Load and validate a JSON array of question objects from ``path``.

Accepts both field conventions (``question_type``/``question`` or
``type``/``label``) and enforces ``MAX_QUESTIONS``.
``type``/``label``) and enforces ``MAX_QUESTIONS``. Tables pass
``FORM_QUESTION_TYPES`` so ``file`` questions are accepted.
"""
try:
raw: str = Path(path).read_text(encoding="utf-8")
Expand Down Expand Up @@ -583,6 +593,7 @@ def parse_questions_file(path: str) -> list[dict[str, Any]]:
options=options,
required=required,
is_blocker=is_blocker,
allowed_types=allowed_types,
**extras,
)
)
Expand Down Expand Up @@ -1019,7 +1030,10 @@ def resolve_form_config(
)


def build_questions_interactively(ai_short_question: bool = False) -> list[dict[str, Any]]:
def build_questions_interactively(
ai_short_question: bool = False,
allowed_types: tuple[str, ...] = VALID_QUESTION_TYPES,
) -> list[dict[str, Any]]:
"""Walk the user through building questions with questionary prompts.

Every question passes through ``build_question``, so the interactive path
Expand All @@ -1036,9 +1050,7 @@ def build_questions_interactively(ai_short_question: bool = False) -> list[dict[

questions: list[dict[str, Any]] = []
while len(questions) < MAX_QUESTIONS:
qtype: str | None = questionary.select(
"Question type:", choices=list(VALID_QUESTION_TYPES)
).ask()
qtype: str | None = questionary.select("Question type:", choices=list(allowed_types)).ask()
if qtype is None:
break
text: str | None = questionary.text("Question text:").ask()
Expand Down Expand Up @@ -1073,6 +1085,7 @@ def build_questions_interactively(ai_short_question: bool = False) -> list[dict[
required=bool(required),
is_blocker=bool(is_blocker),
short_question=short_question,
allowed_types=allowed_types,
)
)
except AuthoringError as exc:
Expand Down
22 changes: 18 additions & 4 deletions dailybot_cli/commands/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
DailyBotClient,
)
from dailybot_cli.commands.authoring_helpers import (
FORM_QUESTION_TYPES,
build_question,
build_question_edit_fields,
build_questions_interactively,
Expand Down Expand Up @@ -1045,9 +1046,11 @@ def form_create(
client = require_auth()
check_report_channels(report_channels)
if interactive:
questions: list[dict[str, Any]] | None = build_questions_interactively(ai_short_question)
questions: list[dict[str, Any]] | None = build_questions_interactively(
ai_short_question, allowed_types=FORM_QUESTION_TYPES
)
elif questions_file:
questions = parse_questions_file(questions_file)
questions = parse_questions_file(questions_file, allowed_types=FORM_QUESTION_TYPES)
else:
questions = None
require_questions(questions, "form")
Expand Down Expand Up @@ -1238,7 +1241,10 @@ def form_questions_list(form_uuid: str, json_mode: bool) -> None:
@form_questions.command("add")
@click.argument("form_uuid")
@click.option(
"--type", "question_type", required=True, help="text/multiple_choice/boolean/numeric."
"--type",
"question_type",
required=True,
help="text/multiple_choice/boolean/numeric/file (file: an image or PDF people attach).",
)
@click.option("--question", required=True, help="The question text.")
@click.option("--options", default=None, help="Comma-separated options (multiple_choice only).")
Expand Down Expand Up @@ -1283,6 +1289,8 @@ def form_questions_add(
--question "Rating?" --options "Excellent,Good,Average,Poor" --ai-short-question
dailybot form questions add <form_uuid> --type boolean --question "Ship it?" \\
--short-question "Ship" --jump-if-equals "No" --jump-to 4
dailybot form questions add <form_uuid> --type file --question "Screenshot" \\
--short-question "Screenshot" --optional
"""
client = require_auth()
require_short_question(extra_flags.get("short_question"), ai_short_question)
Expand All @@ -1293,6 +1301,7 @@ def form_questions_add(
options=parse_options(options),
required=required,
is_blocker=is_blocker,
allowed_types=FORM_QUESTION_TYPES,
**extras,
)
if ai_short_question:
Expand All @@ -1314,7 +1323,12 @@ def form_questions_add(
@click.argument("form_uuid")
@click.argument("question_uuid")
@click.option("--question", default=None, help="New question text.")
@click.option("--type", "question_type", default=None, help="New question type.")
@click.option(
"--type",
"question_type",
default=None,
help="New question type (text/multiple_choice/boolean/numeric/file).",
)
@click.option("--options", default=None, help="New comma-separated options (multiple_choice).")
@click.option("--required/--optional", "required", default=None, help="Toggle required.")
@click.option(
Expand Down
3 changes: 2 additions & 1 deletion dailybot_cli/commands/public_api_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@
"response_date_format_is_invalid": "Invalid date. Use YYYY-MM-DD.",
# Forms & check-ins authoring (create/edit/questions/responses)
"invalid_question_type": (
"Invalid question type. Use one of: text, multiple_choice, boolean, numeric."
"Invalid question type. Use one of: text, multiple_choice, boolean, numeric "
"(forms also take file)."
),
"multiple_choice_requires_options": (
"Multiple-choice questions need at least one option (--options)."
Expand Down
4 changes: 2 additions & 2 deletions docs/API_REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ Creating and configuring forms/check-ins (as opposed to filling them in). All au
| Command | HTTP | Notes |
|---|---|---|
| `form list [--include-archived]` | `GET /v1/forms/` (`?include_archived=true`) | Archived forms hidden by default; flagged in a Status column when shown. |
| `form create -n NAME [--questions-file F] [--interactive] [--report-channel UUID] [config flags]` | `POST /v1/forms/create/` (`name`, `questions?`, `report_channels?`, config all inline) | Question types: `text`, `multiple_choice`, `boolean`, `numeric`; ≤ 50. Config flags below. |
| `form create -n NAME [--questions-file F] [--interactive] [--report-channel UUID] [config flags]` | `POST /v1/forms/create/` (`name`, `questions?`, `report_channels?`, config all inline) | Question types: `text`, `multiple_choice`, `boolean`, `numeric`, `file` (forms only); ≤ 50. Config flags below. |
| `form edit <uuid> [--name] [--report-channel]` | `PATCH /v1/forms/<uuid>/config/` | Thin subset of `form config`. |
| `form config <uuid> [--name] [--report-channel] [config flags]` | `PATCH /v1/forms/<uuid>/config/` | Full form config (partial). Flags below. |

Expand All @@ -269,7 +269,7 @@ Creating and configuring forms/check-ins (as opposed to filling them in). All au

**Report title is required by the CLI.** When authoring a question (`questions add`, or seeding via `create --questions-file`/`--interactive`), a `--short-question` / `"short_question"` is **mandatory** — pass `--ai-short-question` to opt into Dailybot's AI generating it instead (AI titling only runs on intelligence-enabled check-ins). Server-side AI titling is a frontend-oriented convenience; agents/scripts should author explicit report titles. (`questions edit` doesn't require it — partial update.)

**Per-question extras** (on `questions add` + `edit`, both forms and check-ins): `--short-question` (title shown in web & chat reports, ≤512 chars), `--variation` (alternate phrasing rotated per run; repeatable, ≤10), and question logic via `--logic-file <path>` (a JSON `{"rules": {"rules_if": [...], "rules_else": {...}}}` object) or the inline single-jump shortcut `--jump-if-equals VALUE --jump-to N [--else-jump-to M]` (`N`/`M` = target question index, `-1` = end). A **`rules_else` fallback is required** and jump targets are **forward-only** (must be greater than the question's own index, or `-1`); the server owns the question index and rejects backward/out-of-range jumps. Navigation keys (`question_key`/`next_key`/`prev_key`) are computed server-side — never send them. Logic operators (server enforces per type): text — `is_equal_to`, `is_not_equal_to`, `contains`, `not_contains`, `begins_with`, `not_begins_with`, `ends_with`, `not_ends_with`; numeric — `is_equal_to`, `is_not_equal_to`, `lower_than`, `lower_or_equal_than`, `greater_than`, `greater_or_equal_than`; `multiple_choice`/`boolean` — `is_equal_to`, `is_not_equal_to`. Boolean comparison values are JSON `true`/`false` (the CLI coerces `--jump-if-equals true/false`). Actions: `jump_to` (int target), `trigger_checkin` / `trigger_form` (UUID target); connectors: `and`, `or` (`multiple_choice`: `or` only). Empty question text is rejected server-side (`question_label_required`); both check-ins and forms **require at least one question at create time** (`questions_required`) — the CLI fails fast if you create without `--questions-file`/`--interactive`. Question types remain `text`, `multiple_choice`, `boolean`, `numeric` (the complete catalog).
**Per-question extras** (on `questions add` + `edit`, both forms and check-ins): `--short-question` (title shown in web & chat reports, ≤512 chars), `--variation` (alternate phrasing rotated per run; repeatable, ≤10), and question logic via `--logic-file <path>` (a JSON `{"rules": {"rules_if": [...], "rules_else": {...}}}` object) or the inline single-jump shortcut `--jump-if-equals VALUE --jump-to N [--else-jump-to M]` (`N`/`M` = target question index, `-1` = end). A **`rules_else` fallback is required** and jump targets are **forward-only** (must be greater than the question's own index, or `-1`); the server owns the question index and rejects backward/out-of-range jumps. Navigation keys (`question_key`/`next_key`/`prev_key`) are computed server-side — never send them. Logic operators (server enforces per type): text — `is_equal_to`, `is_not_equal_to`, `contains`, `not_contains`, `begins_with`, `not_begins_with`, `ends_with`, `not_ends_with`; numeric — `is_equal_to`, `is_not_equal_to`, `lower_than`, `lower_or_equal_than`, `greater_than`, `greater_or_equal_than`; `multiple_choice`/`boolean` — `is_equal_to`, `is_not_equal_to`. Boolean comparison values are JSON `true`/`false` (the CLI coerces `--jump-if-equals true/false`). Actions: `jump_to` (int target), `trigger_checkin` / `trigger_form` (UUID target); connectors: `and`, `or` (`multiple_choice`: `or` only). Empty question text is rejected server-side (`question_label_required`); both check-ins and forms **require at least one question at create time** (`questions_required`) — the CLI fails fast if you create without `--questions-file`/`--interactive`. Question types: `text`, `multiple_choice`, `boolean`, `numeric`; forms also take `file` (an attachment; optional or required, never the blocker), which the server refuses on check-ins.
| `form questions delete <uuid> <q_uuid>` | `DELETE /v1/forms/<uuid>/questions/<q_uuid>/delete/` | Confirms unless `--yes`. |
| `form questions reorder <uuid> <q_uuid>...` | `PUT /v1/forms/<uuid>/questions/reorder/` | Unknown UUID → 400. |
| `checkin create -n NAME [--time --days --timezone \| --schedule-file] [--user --team] [--questions-file \| --interactive] [--report-channel]` | `POST /v1/checkins/create/` | `days` = ISO weekday ints (0=Sun…6=Sat). **Requires ≥1 participant** — with no `--user`/`--team` an interactive run prompts (default team suggested); non-interactive errors. |
Expand Down
43 changes: 43 additions & 0 deletions tests/authoring_helpers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from dailybot_cli import display
from dailybot_cli.commands.authoring_helpers import (
FORM_QUESTION_TYPES,
MAX_QUESTIONS,
AuthoringError,
build_checkin_config,
Expand Down Expand Up @@ -77,6 +78,48 @@ def test_is_blocker_flag_forwarded(self) -> None:
assert build_question("boolean", "Blocked?", is_blocker=True)["is_blocker"] is True


class TestFileQuestions:
"""Tables (forms) take a ``file`` question; check-ins don't (server refuses it)."""

def test_file_is_a_form_type(self) -> None:
assert "file" in FORM_QUESTION_TYPES

def test_file_question_for_a_form(self) -> None:
result: dict[str, Any] = build_question(
"file", "Screenshot", required=False, allowed_types=FORM_QUESTION_TYPES
)
assert result == {
"question_type": "file",
"question": "Screenshot",
"required": False,
"is_blocker": False,
}

def test_file_rejected_by_default_for_check_ins(self) -> None:
with pytest.raises(AuthoringError, match="Invalid question type 'file'"):
build_question("file", "Screenshot")

def test_file_cannot_be_the_blocker(self) -> None:
with pytest.raises(AuthoringError, match="blocker"):
build_question("file", "Screenshot", is_blocker=True, allowed_types=FORM_QUESTION_TYPES)

def test_file_takes_no_options(self) -> None:
with pytest.raises(AuthoringError):
build_question("file", "Screenshot", options=["a"], allowed_types=FORM_QUESTION_TYPES)

def test_questions_file_accepts_file_for_forms(self, tmp_path: Path) -> None:
path = tmp_path / "q.json"
path.write_text(json.dumps([{"type": "file", "label": "Screenshot", "required": False}]))
questions = parse_questions_file(str(path), allowed_types=FORM_QUESTION_TYPES)
assert questions[0]["question_type"] == "file"

def test_questions_file_rejects_file_for_check_ins(self, tmp_path: Path) -> None:
path = tmp_path / "q.json"
path.write_text(json.dumps([{"type": "file", "label": "Screenshot"}]))
with pytest.raises(AuthoringError, match="Invalid question type 'file'"):
parse_questions_file(str(path))


class TestBuildQuestionEditFields:
def test_empty_when_nothing_provided(self) -> None:
assert build_question_edit_fields(None, None, None, None) == {}
Expand Down
21 changes: 21 additions & 0 deletions tests/checkin_authoring_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,27 @@ def test_add_jump_to_without_value_fails_fast(self, runner: CliRunner) -> None:
assert result.exit_code != 0
assert "--jump-if-equals" in result.output

def test_add_file_is_rejected_for_check_ins(self, runner: CliRunner) -> None:
# File questions are for tables; a check-in can't ask for an upload.
with _auth(), _client() as cls:
result = runner.invoke(
cli,
[
"checkin",
"questions",
"add",
"fu-1",
"--type",
"file",
"--question",
"Screenshot",
"--ai-short-question",
],
)
cls.return_value.add_checkin_question.assert_not_called()
assert result.exit_code != 0
assert "Invalid question type 'file'" in result.output

def test_add_without_short_question_is_rejected(self, runner: CliRunner) -> None:
# A report title is required unless --ai-short-question opts into AI titling.
with _auth(), _client() as cls:
Expand Down
Loading
Loading