Skip to content
Closed
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
8 changes: 7 additions & 1 deletion packages/flow/openadapt_flow/form_tx/pack_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pydantic import BaseModel, ConfigDict, Field

from openadapt_flow.form_tx.codecs import collapse_whitespace
from openadapt_flow.form_tx.presets import load_words
from openadapt_flow.form_tx.surface import (
AmbiguousAnchorError,
match_anchor_in_snapshot,
Expand Down Expand Up @@ -104,6 +105,11 @@
)


#: The default "next screen" button pattern for induction (data:
#: ``presets/words/next_button.json``).
NEXT_BUTTON_PATTERN = "|".join(re.escape(w) for w in load_words("next_button"))


class CanonicalFieldSpec(BaseModel):
"""Canonical domain field or expected output definition for pack induction."""

Expand Down Expand Up @@ -651,7 +657,7 @@ def induce_form_pack(
form_snapshots: Sequence[FormSnapshot],
summary_snapshot: Optional[FormSnapshot] = None,
commit_button_pattern: Optional[str] = None,
next_button_pattern: str = r"next|continue",
next_button_pattern: str = NEXT_BUTTON_PATTERN,
) -> PackInductionReport:
"""Deterministically induce a ``FormPack`` from scrubbed structural snapshots."""
scrubbed_forms = tuple(_scrub_snapshot_values(snap) for snap in form_snapshots)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"schema": "openadapt.form-word-list/v1",
"name": "next_button",
"about": "Words on the button that moves a wizard to its next screen, when the caller gives no pattern. They are matched as a case-insensitive regular expression, joined with |.",
"words": [
"next",
"continue"
]
}
15 changes: 15 additions & 0 deletions packages/flow/tests/test_form_tx_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,16 @@ def _primary_entity_kinds() -> object:
return reconciler._PRIMARY_ENTITY_KINDS


def _next_button_pattern() -> object:
import inspect

return (
inspect.signature(pack_compiler.induce_form_pack)
.parameters["next_button_pattern"]
.default
)


#: word list: (current value, the commit before the move, file, constant)
MOVED_WORDS = {
"primary_entity_kinds": (
Expand All @@ -130,6 +140,11 @@ def _primary_entity_kinds() -> object:
}


def test_the_next_button_default_is_unchanged() -> None:
assert _next_button_pattern() == r"next|continue"
assert pack_compiler.NEXT_BUTTON_PATTERN == r"next|continue"


@pytest.mark.parametrize("words", sorted(MOVED_WORDS))
def test_the_constant_equals_the_old_one(words: str) -> None:
current, sha, source, name = MOVED_WORDS[words]
Expand Down
Loading