diff --git a/packages/desktop/openadapt_desktop/flow_bridge.py b/packages/desktop/openadapt_desktop/flow_bridge.py index 7e15406f68..6f5e0f4b48 100644 --- a/packages/desktop/openadapt_desktop/flow_bridge.py +++ b/packages/desktop/openadapt_desktop/flow_bridge.py @@ -808,8 +808,9 @@ def tutorial( Flow serves its own synthetic clinic app with made-up patients on this computer, records the sample task, builds it, runs it with the record - check on, and (with ``break_it``) runs it again against a backend that - drops the save after the screen says "saved". Nothing here needs an + check on, and (with ``break_it``) runs it again against a save that + keeps the encounter but drops the typed note while the screen says + "saved". Nothing here needs an operating-system permission, an account, or the operator's apps. """ diff --git a/packages/flow/docs/TUTORIAL.md b/packages/flow/docs/TUTORIAL.md index 5455172617..9789e0ed0d 100644 --- a/packages/flow/docs/TUTORIAL.md +++ b/packages/flow/docs/TUTORIAL.md @@ -7,7 +7,7 @@ practice-management fixture served through its real transactional backend. ```bash openadapt-flow demo # both runs, one proof page openadapt-flow tutorial # the whole loop, VERIFIED -openadapt-flow tutorial --break-it # then watch it catch a failed save +openadapt-flow tutorial --break-it # then watch it catch a dropped note openadapt-flow tutorial --guided # perform the demo yourself ``` @@ -16,7 +16,7 @@ openadapt-flow tutorial --guided # perform the demo your `demo` runs `tutorial --break-it` without the stage-by-stage output, then writes one self-contained page, `openadapt-demo/index.html`, and opens it when a display is available (`--no-open` skips that). The page puts the two final -screens side by side, shows the record check under each run (1 note, then 0), +screens side by side, shows the record check under each run (1 typed note, then 0), lists the choices a person gets when the second run stops, and folds the engine's exact terms under "Technical details". When the demo goes as expected, the terminal shows 8 lines. If the first run doesn't end "Done and @@ -74,30 +74,33 @@ shown. ## What `--break-it` does -`--break-it` reruns the **same certified bundle** with the save set to fail: -the server rejects the write, so nothing lands, yet every on-screen check -still passes. The independent read of the system of record refutes the mined -`record_written` contract and the engine **HALTS** at the consequential step -instead of reporting done. The -caught fault's evidence is a clearly-labeled local `run-broken/REPORT.md`; no -shareable receipt is emitted for it, because only `VERIFIED` runs may use the -success rail. +`--break-it` reruns the **same certified bundle** against a partial save +(`?fault=partial`): the app stores the encounter but drops the typed note, +the way real apps do when a field fails a length, encoding or mapping rule +without an error. The form closes and the saved message shows the note, so +every on-screen check passes. Reading the record back shows the encounter with +a blank note, which is what a careful person sees when they reopen it. The +mined `field_equals` contract on the note is refuted and the engine **HALTS** +at the consequential step instead of reporting done. The caught fault's +evidence is a clearly-labeled local `run-broken/REPORT.md`; no shareable +receipt is emitted for it, because only `VERIFIED` runs may use the success +rail. ``` - The screen claimed: every on-screen check passed -- the app painted its success banner + Injected fault: 'partial' -- the app saves the encounter but drops the typed note + On screen: every on-screen check passed, including the saved message (observed on screen: "Encountersaved-") - The verifier found: 1/2 declared effect(s) REFUTED by an independent - read of the system of record, which holds 0 record(s) + The verifier found: 1/2 declared effect(s) REFUTED by reading the record + back: 1 encounter(s), 0 with the note as typed The engine did: HALTED at the consequential step instead of claiming success (transaction: RECONCILIATION_REQUIRED, billable: no) Result: Check the record. A save may have gone through. A person checks the record before anything is retried. ``` -The halted run doesn't retry the write either: delivery is uncertain, so the -transaction ends in `RECONCILIATION_REQUIRED` for a person to settle. That's -why the plain result is "Check the record" and not "Stopped before saving": -the store really is empty, but the engine says nothing was written only when -it can prove that for every declared effect. +The halted run doesn't retry the write either: part of the save landed, so +a resend could create a second encounter. The transaction ends in +`RECONCILIATION_REQUIRED` for a person to settle. That's why the plain +result is "Check the record" and not "Stopped before saving". ## What `--guided` does diff --git a/packages/flow/docs/design/DECOMPOSITION.md b/packages/flow/docs/design/DECOMPOSITION.md index 380f7fb53a..beedf0fb74 100644 --- a/packages/flow/docs/design/DECOMPOSITION.md +++ b/packages/flow/docs/design/DECOMPOSITION.md @@ -612,7 +612,7 @@ The `build_parser` split lowered `__main__.py`: each top-level command's registr | File | Line budget | |---|---:| | `packages/flow/openadapt_flow/runtime/replayer.py` | 15119 | -| `packages/flow/openadapt_flow/__main__.py` | 10395 | +| `packages/flow/openadapt_flow/__main__.py` | 10346 | | `packages/flow/openadapt_flow/qualification/__init__.py` | 4891 | | `packages/flow/openadapt_flow/ir.py` | 6829 | | `packages/desktop/openadapt_desktop/dispatch.py` | 6501 | diff --git a/packages/flow/openadapt_flow/__main__.py b/packages/flow/openadapt_flow/__main__.py index 09cdf083b1..525f77acaa 100644 --- a/packages/flow/openadapt_flow/__main__.py +++ b/packages/flow/openadapt_flow/__main__.py @@ -2095,59 +2095,10 @@ def _cmd_tutorial(args: argparse.Namespace) -> int: def _print_break_it_narrative(broken: "BreakItResult") -> None: - """Tell the caught-fault story from the halted run's own evidence. + """Print the caught-fault story; the body lives in ``break_it_narrative``.""" + from openadapt_flow.break_it_narrative import print_break_it_narrative - Every fact printed here was read back from the broken run's report or the - fault server's ground-truth store by ``run_tutorial``; nothing is scripted. - """ - claim = ( - "every on-screen check passed, including the saved message" - if broken.screen_claimed_success - else "the saved message did not appear" - ) - if broken.screen_claim_text: - claim += f'\n (observed on screen: "{broken.screen_claim_text}")' - print("\n--- break-it: the same certified bundle, with the save set to fail ---") - print(f"\n Injected fault: {broken.fault!r} -- the server rejects the write") - print(f" On screen: {claim}") - print( - " The verifier found: " - f"{broken.effects_refuted}/{broken.effects_required} declared effect(s) " - "REFUTED by an independent\n" - " read of the system of record, which holds " - f"{broken.system_of_record_records} record(s)" - ) - print( - f" The engine did: {broken.execution_outcome} at the consequential " - "step instead of claiming\n" - f" success (transaction: {broken.transaction_outcome}, " - f"billable: {'yes' if broken.transaction_billable else 'no'})" - ) - from openadapt_flow.plain_outcome import plain_result - - plain = plain_result(broken.transaction_outcome, broken.execution_outcome) - print(f" Result: {plain.label}. {plain.meaning}") - print( - "\n The screen looked the same as a good save. The record check found " - "no new note,\n so the engine stopped instead of reporting done." - ) - print(f"\n Engine's own words: {broken.halt_reason}") - print( - "\nCaught-fault evidence (local report, NOT a success receipt):\n" - f" {broken.report_path}" - ) - print( - "\nNo shareable receipt for the halted run: only VERIFIED runs may use " - "the\nsuccess rail. The halt itself is the demonstration." - ) - from openadapt_flow.cli_hints import command - - print( - "\nSee both runs side by side on one page:\n" - f" {command('demo')}\n" - "\nNext: record your own workflow:\n" - f" {command('record --backend web --url https://your-test-app.example --out my-task')}" - ) + print_break_it_narrative(broken) def _demo_progress() -> Optional[Callable[[str], None]]: @@ -2187,7 +2138,7 @@ def _cmd_demo(args: argparse.Namespace) -> int: Composes the unchanged tutorial path (``run_tutorial(..., break_it=True)``): the same record, compile, certify, and Standard-profile run, then the same - bundle against the ``optimistic`` fault. Presentation only: the page and + bundle against the ``partial`` fault. Presentation only: the page and the short summary read each run's ``transaction_outcome`` and artifacts. Exit codes: 0 when the pair showed the difference (the first run ended diff --git a/packages/flow/openadapt_flow/break_it_narrative.py b/packages/flow/openadapt_flow/break_it_narrative.py new file mode 100644 index 0000000000..1c9fc678c1 --- /dev/null +++ b/packages/flow/openadapt_flow/break_it_narrative.py @@ -0,0 +1,79 @@ +"""Print the ``tutorial --break-it`` story from the halted run's own evidence. + +``openadapt-flow tutorial --break-it`` reruns the certified bundle against a +save that drops the typed note. This module prints what that run saw on +screen, what reading the record back found, and what the engine did. +""" + +from __future__ import annotations + +from typing import TYPE_CHECKING + +if TYPE_CHECKING: # pragma: no cover + from openadapt_flow.tutorial import BreakItResult + + +def print_break_it_narrative(broken: BreakItResult) -> None: + """Tell the caught-fault story from the halted run's own evidence. + + Every fact printed here was read back from the broken run's report or the + fault server's ground-truth store by ``run_tutorial``; nothing is scripted. + """ + claim = ( + "every on-screen check passed, including the saved message" + if broken.screen_claimed_success + else "the saved message did not appear" + ) + if broken.screen_claim_text: + claim += f'\n (observed on screen: "{broken.screen_claim_text}")' + print( + "\n--- break-it: the same certified bundle, with a save that drops the note ---" + ) + print( + f"\n Injected fault: {broken.fault!r} -- the app saves the encounter " + "but drops the typed note" + ) + print(f" On screen: {claim}") + print( + " The verifier found: " + f"{broken.effects_refuted}/{broken.effects_required} declared effect(s) " + "REFUTED by reading the record\n" + " back: " + f"{broken.system_of_record_records} encounter(s), " + f"{broken.notes_as_typed} with the note as typed" + ) + print( + f" The engine did: {broken.execution_outcome} at the consequential " + "step instead of claiming\n" + f" success (transaction: {broken.transaction_outcome}, " + f"billable: {'yes' if broken.transaction_billable else 'no'})" + ) + from openadapt_flow.plain_outcome import plain_result + + plain = plain_result(broken.transaction_outcome, broken.execution_outcome) + print(f" Result: {plain.label}. {plain.meaning}") + if broken.system_of_record_records and not broken.notes_as_typed: + found = "the encounter with its note blank" + else: + found = "something other than what was typed" + print( + "\n The screen looked the same as a good save. The record read back held" + f"\n {found}, so the engine stopped instead of reporting done." + ) + print(f"\n Engine's own words: {broken.halt_reason}") + print( + "\nCaught-fault evidence (local report, NOT a success receipt):\n" + f" {broken.report_path}" + ) + print( + "\nNo shareable receipt for the halted run: only VERIFIED runs may use " + "the\nsuccess rail. The halt itself is the demonstration." + ) + from openadapt_flow.cli_hints import command + + print( + "\nSee both runs side by side on one page:\n" + f" {command('demo')}\n" + "\nNext: record your own workflow:\n" + f" {command('record --backend web --url https://your-test-app.example --out my-task')}" + ) diff --git a/packages/flow/openadapt_flow/cli/try_and_measure.py b/packages/flow/openadapt_flow/cli/try_and_measure.py index 7dd271e6ea..4c461f467c 100644 --- a/packages/flow/openadapt_flow/cli/try_and_measure.py +++ b/packages/flow/openadapt_flow/cli/try_and_measure.py @@ -127,10 +127,10 @@ def register_tutorial( dest="break_it", help=( "After the clean VERIFIED run, rerun the SAME certified bundle " - "against a backend that silently rejects the write AFTER the app " - "paints its success banner -- and watch the engine HALT instead of " - "believing the screen. The halted run's evidence lands in " - "/run-broken/REPORT.md" + "against an app whose save keeps the encounter but drops the typed " + "note while still showing it as saved -- and watch the engine HALT " + "when it reopens the record and finds the note blank. The halted " + "run's evidence lands in /run-broken/REPORT.md" ), ) p.set_defaults(func=main._cmd_tutorial) diff --git a/packages/flow/openadapt_flow/demo_proof.py b/packages/flow/openadapt_flow/demo_proof.py index 390d40d0b5..0a3280e065 100644 --- a/packages/flow/openadapt_flow/demo_proof.py +++ b/packages/flow/openadapt_flow/demo_proof.py @@ -1,9 +1,10 @@ """``openadapt-flow demo``: two real runs and one page that shows the difference. The bundled tutorial already proves the product's claim in text. ``--break-it`` -reruns the same checked automation against an app that paints "Encounter saved" -and then drops the write; the engine reads the record, finds nothing, and -stops. The two final screenshots are byte-identical. Only the record check +reruns the same checked automation against an app whose save keeps the +encounter but drops the typed note, while the screen still shows "Encounter +saved" and the note. The engine reads the record back, finds the note blank, +and stops. The two final screenshots are byte-identical. Only the record check tells the runs apart. This module runs that pair and writes one self-contained HTML page that shows @@ -18,7 +19,7 @@ :func:`openadapt_flow.plain_outcome.plain_result`, never from the coarse ``HALTED`` label, so the page never says "nothing was written" for a run the engine left at ``RECONCILIATION_REQUIRED``; -* record counts come from the demo app's own store, read out of band; +* note counts come from the demo app's own store, read out of band; * the screenshots are the retained ``after`` frames of each run's last step, and "identical" is printed only when their SHA-256 digests match; * the person's choices come from the halted run's ``pending_escalation.json``. @@ -157,7 +158,8 @@ class RunEvidence: execution_outcome: str transaction_outcome: Optional[str] plain: PlainResult - #: Rows in the demo app's store after the run, read out of band. + #: Notes in the demo app's store that read exactly as typed, after the + #: run, read out of band. records: int #: True when the app painted its success message at the save step. screen_showed_success: Optional[bool] @@ -175,6 +177,8 @@ class RunEvidence: screen_text: Optional[str] = None #: The engine's own halt reason, verbatim. halt_reason: str = "" + #: All rows in the demo app's store after the run, typed note or not. + rows_in_store: Optional[int] = None @dataclass @@ -405,7 +409,9 @@ def collect_evidence(result: Any, out_dir: Path) -> DemoEvidence: execution_outcome=str(result.execution_outcome), transaction_outcome=result.transaction_outcome, plain=plain_result(result.transaction_outcome, result.execution_outcome), + # A VERIFIED run confirmed the note as typed, so each row counts. records=int(result.system_of_record_records), + rows_in_store=int(result.system_of_record_records), screen_showed_success=clean_screen_ok, final_screenshot=clean_frame, final_screenshot_sha256=_sha256(clean_frame) if clean_frame else None, @@ -423,7 +429,8 @@ def collect_evidence(result: Any, out_dir: Path) -> DemoEvidence: execution_outcome=str(broken.execution_outcome), transaction_outcome=broken.transaction_outcome, plain=plain_result(broken.transaction_outcome, broken.execution_outcome), - records=int(broken.system_of_record_records), + records=int(broken.notes_as_typed), + rows_in_store=int(broken.system_of_record_records), screen_showed_success=bool(broken.screen_claimed_success), final_screenshot=broken_frame, final_screenshot_sha256=_sha256(broken_frame) if broken_frame else None, @@ -456,6 +463,10 @@ def collect_evidence(result: Any, out_dir: Path) -> DemoEvidence: # --------------------------------------------------------------------------- +def _rows(run: RunEvidence) -> int: + return run.records if run.rows_in_store is None else run.rows_in_store + + def _notes(count: int) -> str: return f"{count} note" if count == 1 else f"{count} notes" @@ -475,10 +486,10 @@ def _screen_words(showed: Optional[bool]) -> str: def run_headline(run: RunEvidence) -> str: """The card title for one run. - The "note never reached the record" title needs all three facts: the - transaction outcome is a stop (never done or unchecked), the app painted - its success message, and the record check found nothing. Otherwise the - title is the plain result's own label. + The "record is missing the typed note" title needs all three facts: the + transaction outcome is a stop (never done or unchecked), the app showed + its saved message, and the record check found no note as typed. + Otherwise the title is the plain result's own label. """ if ( @@ -487,7 +498,7 @@ def run_headline(run: RunEvidence) -> str: and run.screen_showed_success and run.records == 0 ): - return "Stopped: the note never reached the record" + return "Stopped: the record is missing the typed note" return run.plain.label @@ -501,10 +512,16 @@ def run_explanation(run: RunEvidence) -> str: "then did it report the run as done." ) if run.records == 0 and plain.key == "check_the_record": - # The record check found nothing, but the engine did not prove that - # no part of the save landed. Say both, and never claim absence. + # The record check found no note as typed, but the engine did not + # prove that no part of the save landed. Say both, and never claim + # absence. + found = ( + "the saved encounter, but not the note that was typed" + if run.rows_in_store + else "no note" + ) return ( - "The record check found no note. OpenAdapt only says nothing was " + f"The record check found {found}. OpenAdapt only says nothing was " "saved when it can prove it, so a person checks the record before " "anything is retried." ) @@ -832,7 +849,7 @@ def _run_card( f'{_icon(tone)}' f"{_e(run.plain.label)}" ) - unit = "note" if run.records == 1 else "notes" + unit = "typed note" if run.records == 1 else "typed notes" screen = _e(_screen_words(run.screen_showed_success)) figure = _frame_figure(run, alt, root) did = _e(what_openadapt_did(run, asked_a_person=asked_a_person)) @@ -935,7 +952,7 @@ def ms(value: Optional[float]) -> str: f"{clean.effects_confirmed}/{clean.effects_required} by an " "independent read of the system of record", ), - ("records in the store", clean.records), + ("records in the store", _rows(clean)), ("model calls", clean.model_calls), ("run time", ms(clean.total_ms)), ("final frame SHA-256", clean.final_screenshot_sha256 or "none"), @@ -949,15 +966,16 @@ def ms(value: Optional[float]) -> str: ("transaction_outcome", broken.transaction_outcome or "not recorded"), ( "injected fault", - f"{evidence.fault!r}: the server rejects the write after the " - "app shows success", + f"{evidence.fault!r}: the save keeps the encounter but drops " + "the typed note, and the app still shows it as saved", ), ( "effects refuted", f"{broken.effects_refuted}/{broken.effects_required} by an " "independent read of the system of record", ), - ("records in the store", broken.records), + ("records in the store", _rows(broken)), + ("notes as typed", broken.records), ("on-screen text (OCR)", broken.screen_text or "none"), ("engine halt reason", broken.halt_reason or "none"), ("model calls", broken.model_calls), @@ -975,7 +993,7 @@ def ms(value: Optional[float]) -> str: reconcile_note = "" if broken.transaction_outcome == "RECONCILIATION_REQUIRED": reconcile_note = ( - f"

The store held {broken.records} rows after the run, and the " + f"

The store held {_rows(broken)} rows after the run, and the " "run still ended RECONCILIATION_REQUIRED, not " "HALTED_BEFORE_EFFECT. The save declared " f"{broken.effects_required} effects, and the record check refuted " diff --git a/packages/flow/openadapt_flow/tutorial.py b/packages/flow/openadapt_flow/tutorial.py index 4a07994b5d..423b8c70c7 100644 --- a/packages/flow/openadapt_flow/tutorial.py +++ b/packages/flow/openadapt_flow/tutorial.py @@ -83,12 +83,13 @@ #: key so the mined contract can assert at-most-once honestly. TUTORIAL_ENTRY_QUERY = "?fault=ok&idempotency=demo#tasks" -#: The fault mode ``--break-it`` injects. ``optimistic`` is the sharpest -#: demonstration of the product's claim: the backend REJECTS the write AFTER -#: the application has already painted its success banner, so every on-screen -#: check passes while nothing landed in the system of record. Only an -#: independent read of that system can catch it -- which is the point. -TUTORIAL_BREAK_FAULT = "optimistic" +#: The fault mode ``--break-it`` injects. ``partial`` is a partial save: the +#: backend stores the encounter but drops the typed note, as real apps do when +#: a field fails a length, encoding or mapping rule without an error. The app +#: shows its usual saved message and the note it just sent. Reopening the +#: record shows the encounter with a blank note -- what a careful person sees +#: when they check their work, and what the record check reads. +TUTORIAL_BREAK_FAULT = "partial" #: The entry query for the ``--break-it`` rerun. Identical to the clean #: query except for the fault mode; the bundle, the policy, the gate, and the @@ -114,19 +115,21 @@ class BreakItResult: execution_outcome: str transaction_outcome: Optional[str] transaction_billable: Optional[bool] - #: The lie, observed: the consequential step's on-screen postconditions - #: all passed (the application painted its success banner) even though the - #: write never landed. + #: The consequential step's on-screen postconditions all passed: the app + #: showed its saved message, so the screen alone looked like a good save. screen_claimed_success: bool - #: The success banner's text as observed on screen at the halt, if any. + #: The saved message's text as observed on screen at the halt, if any. screen_claim_text: Optional[str] effects_required: int effects_refuted: int #: The engine's own explanation of the halt, verbatim from the report. halt_reason: str - #: Rows in the independent system of record after the run (0: the write - #: the screen claimed was never persisted). + #: Rows in the independent system of record after the run. On the + #: partial save the encounter row exists, so this is 1. system_of_record_records: int + #: Of those rows, how many hold the note exactly as it was typed (0: the + #: save kept the encounter and dropped the note). + notes_as_typed: int @dataclass @@ -151,8 +154,8 @@ class TutorialResult: reported_to_metering: bool = False receipt_paths: dict[str, Path] = field(default_factory=dict) #: Present only when the tutorial ran with ``break_it=True``: the same - #: certified bundle, rerun against a backend that lies, and the engine's - #: halt that caught it. + #: certified bundle, rerun against a backend that drops the typed note, + #: and the engine's halt that caught it. break_it: Optional[BreakItResult] = None @@ -512,7 +515,7 @@ def run_tutorial_workflow( entry_url = f"{base_url.rstrip('/')}/{entry_query}" # The independent oracle: it reads the backend store over HTTP, never the - # screen, so an optimistic banner cannot make it confirm anything. + # screen, so a saved message cannot make it confirm anything. verifier = _build_demo_effect_verifier(base_url) gate = evaluate_run_gate( workflow, @@ -578,10 +581,10 @@ def run_tutorial( independent effect verification) -> receipt. With ``break_it=True`` the SAME certified bundle is then rerun against a - backend that injects the :data:`TUTORIAL_BREAK_FAULT` fault -- the server - rejects the write after the application has already painted its success - banner -- and the engine is expected to HALT rather than believe the - screen. The rerun's evidence lands in ``/run-broken`` and on + backend that injects the :data:`TUTORIAL_BREAK_FAULT` fault -- the save + keeps the encounter but drops the typed note, while the app still shows + it as saved -- and the engine is expected to HALT when the record it + reads back has a blank note. The rerun's evidence lands in ``/run-broken`` and on :attr:`TutorialResult.break_it`. If the engine does NOT halt, this function raises: an uncaught injected fault is a product failure, never a tutorial variant. @@ -771,22 +774,21 @@ def _run_break_it( headed: bool, say: Callable[[str], None], ) -> BreakItResult: - """Rerun the certified bundle against a lying backend and prove the halt. + """Rerun the certified bundle against a partial save and prove the halt. - The backend now runs in ``optimistic`` fault mode: it REJECTS the write, - but only after the application has already painted its success banner. - Every on-screen check therefore passes. The engine's independent read of - the system of record is the only thing standing between that screen and a - claimed success -- and the run must end HALTED because of it. + The backend now runs in ``partial`` fault mode: it stores the encounter + but drops the typed note. The app still closes the form and shows its + saved message, so every on-screen check passes. Reading the record back + shows the note is blank, and the run must end HALTED because of it. """ from openadapt_flow.mockmed.fault_server import serve from openadapt_flow.report import render_run_report say("") - say("[break-it] Rerun the SAME certified bundle, but this time the backend") - say(f"[break-it] runs fault mode {TUTORIAL_BREAK_FAULT!r}: it rejects the write,") - say("[break-it] so the save never reaches the record.") + say("[break-it] Rerun the SAME certified bundle, but this time the app") + say(f"[break-it] runs fault mode {TUTORIAL_BREAK_FAULT!r}: it saves the encounter") + say("[break-it] and drops the typed note.") base_url, _db, stop = serve() try: report = run_tutorial_workflow( @@ -797,7 +799,7 @@ def _run_break_it( headed=headed, entry_query=TUTORIAL_BREAK_ENTRY_QUERY, ) - record_count = len(_records(base_url)) + records = _records(base_url) finally: stop() report_path = render_run_report(run_dir) @@ -826,10 +828,15 @@ def _run_break_it( (text for text in report.halt.observed_texts if "saved" in text.lower()), None, ) + typed_note = TUTORIAL_NOTE + params = getattr(workflow, "params", None) + if isinstance(params, dict): + typed_note = str(params.get("note", TUTORIAL_NOTE)) + notes_as_typed = sum(1 for record in records if record.get("note") == typed_note) envelope = report.outcome_envelope say( - f"[break-it] {report.execution_outcome}: the system of record holds " - f"{record_count} record(s); the screen said otherwise." + f"[break-it] {report.execution_outcome}: the record holds " + f"{len(records)} encounter(s), {notes_as_typed} with the note as typed." ) return BreakItResult( run_dir=run_dir, @@ -845,7 +852,8 @@ def _run_break_it( ), effects_refuted=refuted, halt_reason=(report.halt.reason if report.halt is not None else ""), - system_of_record_records=record_count, + system_of_record_records=len(records), + notes_as_typed=notes_as_typed, ) diff --git a/packages/flow/tests/e2e/test_tutorial_break_it_e2e.py b/packages/flow/tests/e2e/test_tutorial_break_it_e2e.py index 7dcba7c8d7..5c316d8cc3 100644 --- a/packages/flow/tests/e2e/test_tutorial_break_it_e2e.py +++ b/packages/flow/tests/e2e/test_tutorial_break_it_e2e.py @@ -2,19 +2,21 @@ The clean free path is pinned by :mod:`test_free_path_e2e` (golden task). This module covers the OTHER half of the tutorial's demonstration: the SAME -certified bundle, rerun against a backend that rejects the write AFTER the -application has painted its success banner (``?fault=optimistic``). Every -on-screen check passes; only the independent read of the system of record can -tell the truth -- and the run must end HALTED because of it. +certified bundle, rerun against a partial save (``?fault=partial``): the app +stores the encounter but drops the typed note, and still closes the form with +its saved message. Every on-screen check passes; reading the record back shows +the note is blank -- and the run must end HALTED because of it. What is asserted, on one real browser run: * the clean half still terminates ``VERIFIED`` with its receipt; * the broken half terminates ``HALTED`` / ``RECONCILIATION_REQUIRED``, not - billable, with the declared ``record_written`` effect REFUTED at - INDEPENDENT_SYSTEM strength while zero rows exist in the store; -* the lie was real: the consequential step's on-screen postconditions all - PASSED on the broken run -- the halt did not come from the screen; + billable, with the declared note effect (``field_equals``) REFUTED at + INDEPENDENT_SYSTEM strength while the store holds the encounter row with a + blank note; +* the screen really looked fine: the consequential step's on-screen + postconditions all PASSED on the broken run -- the halt did not come from + the screen; * the caught fault leaves a clearly-labeled LOCAL report (``run-broken/REPORT.md`` leads with ``HALTED``) and NO shareable receipt, and ``report-run`` still refuses the halted run -- the success rail was not @@ -66,23 +68,25 @@ def test_the_clean_half_still_verifies(break_it_path: TutorialResult) -> None: def test_the_engine_halts_on_the_injected_fault( break_it_path: TutorialResult, ) -> None: - """The aha itself: same bundle, lying backend, HALT -- not success.""" + """The aha itself: same bundle, note dropped on save, HALT -- not success.""" broken = break_it_path.break_it assert broken is not None - assert broken.fault == "optimistic" + assert broken.fault == "partial" assert broken.execution_outcome == "HALTED" assert broken.transaction_outcome == "RECONCILIATION_REQUIRED" assert broken.transaction_billable is not True - # Nothing landed: the write the screen claimed does not exist. - assert broken.system_of_record_records == 0 + # The partial save: the encounter row landed, the typed note did not. + assert broken.system_of_record_records == 1 + assert broken.notes_as_typed == 0 assert broken.effects_refuted >= 1 # The engine's own explanation names the refuted contract, not a guess. - assert "record_written" in broken.halt_reason + assert "field_equals" in broken.halt_reason assert "refuted" in broken.halt_reason + assert "'note'" in broken.halt_reason -def test_the_screen_really_did_lie(break_it_path: TutorialResult) -> None: +def test_the_screen_looked_like_a_good_save(break_it_path: TutorialResult) -> None: """The halt came from the independent verifier, not from the screen. If the on-screen postconditions had failed, the run would have halted for @@ -169,4 +173,4 @@ def test_the_demo_proof_page_reads_this_pair(break_it_path: TutorialResult) -> N ] page = demo_proof.render_demo_page(evidence) assert "identical, pixel for pixel" in page - assert "Stopped: the note never reached the record" in page + assert "Stopped: the record is missing the typed note" in page diff --git a/packages/flow/tests/fixtures/cli_surface.json b/packages/flow/tests/fixtures/cli_surface.json index 9a57a1f79d..cbe879ef53 100644 --- a/packages/flow/tests/fixtures/cli_surface.json +++ b/packages/flow/tests/fixtures/cli_surface.json @@ -287,7 +287,7 @@ "openadapt-flow triage eligibility": "usage: openadapt-flow triage eligibility [-h] --workflow WORKFLOW --artifact ARTIFACT\n --artifact-sha256 ARTIFACT_SHA256 --labels LABELS\n [--verified-runs VERIFIED_RUNS]\n [--target-miss TARGET_MISS] [--delta DELTA]\n [--audit-rate AUDIT_RATE]\n\noptions:\n -h, --help show this help message and exit\n --workflow WORKFLOW Opaque workflow id\n --artifact ARTIFACT Calibration artifact\n --artifact-sha256 ARTIFACT_SHA256\n Pinned digest\n --labels LABELS Label log (JSON lines)\n --verified-runs VERIFIED_RUNS\n --target-miss TARGET_MISS\n --delta DELTA\n --audit-rate AUDIT_RATE\n\nAlso available as: openadapt-flow run --triage eligibility\n", "openadapt-flow triage estimate": "usage: openadapt-flow triage estimate [-h] --labels LABELS\n\noptions:\n -h, --help show this help message and exit\n --labels LABELS\n\nAlso available as: openadapt-flow run --triage estimate\n", "openadapt-flow triage plan": "usage: openadapt-flow triage plan [-h] [--observations OBSERVATIONS] [--run-dir RUN_DIR] --mode\n {each_item,problems_only,not_gated}\n [--policy {off,rule_v0,learned}] [--artifact ARTIFACT]\n [--artifact-sha256 ARTIFACT_SHA256] [--audit-rate AUDIT_RATE]\n --out OUT\n\noptions:\n -h, --help show this help message and exit\n --observations OBSERVATIONS\n SaveObservation JSON lines\n --run-dir RUN_DIR A finished run (repeatable)\n --mode {each_item,problems_only,not_gated}\n The approval mode the runs used. Only problems_only is triaged.\n --policy {off,rule_v0,learned}\n --artifact ARTIFACT Calibration artifact (learned only)\n --artifact-sha256 ARTIFACT_SHA256\n Pinned artifact digest\n --audit-rate AUDIT_RATE\n --out OUT Where to write the plan\n\nAlso available as: openadapt-flow run --triage plan\n", - "openadapt-flow tutorial": "usage: openadapt-flow tutorial [-h] [--out OUT] [--name NAME] [--headed] [--guided]\n [--interactive-record] [--presentation-delay SECONDS]\n [--no-receipt] [--break-it]\n\noptions:\n -h, --help show this help message and exit\n --out OUT Directory for the tutorial's recording, bundle, and run (default:\n tutorials/tutorial- under the current directory)\n --name NAME Workflow name for the compiled bundle (default: local-quickstart)\n --headed Run the browser headed\n --guided Presentation mode: record the demonstration yourself, then watch a visibly\n paced governed replay\n --interactive-record Perform the tutorial demonstration yourself in a headed browser; the\n browser closes after the saved record is observed\n --presentation-delay SECONDS\n Tutorial-only pause before each scripted recording action and replay step\n (0-5 seconds; guided default: 1)\n --no-receipt Skip writing the local receipt (the run and its report are unchanged)\n --break-it After the clean VERIFIED run, rerun the SAME certified bundle against a\n backend that silently rejects the write AFTER the app paints its success\n banner -- and watch the engine HALT instead of believing the screen. The\n halted run's evidence lands in /run-broken/REPORT.md\n\nAlso available as: openadapt-flow demo tutorial\n", + "openadapt-flow tutorial": "usage: openadapt-flow tutorial [-h] [--out OUT] [--name NAME] [--headed] [--guided]\n [--interactive-record] [--presentation-delay SECONDS]\n [--no-receipt] [--break-it]\n\noptions:\n -h, --help show this help message and exit\n --out OUT Directory for the tutorial's recording, bundle, and run (default:\n tutorials/tutorial- under the current directory)\n --name NAME Workflow name for the compiled bundle (default: local-quickstart)\n --headed Run the browser headed\n --guided Presentation mode: record the demonstration yourself, then watch a visibly\n paced governed replay\n --interactive-record Perform the tutorial demonstration yourself in a headed browser; the\n browser closes after the saved record is observed\n --presentation-delay SECONDS\n Tutorial-only pause before each scripted recording action and replay step\n (0-5 seconds; guided default: 1)\n --no-receipt Skip writing the local receipt (the run and its report are unchanged)\n --break-it After the clean VERIFIED run, rerun the SAME certified bundle against an\n app whose save keeps the encounter but drops the typed note while still\n showing it as saved -- and watch the engine HALT when it reopens the\n record and finds the note blank. The halted run's evidence lands in\n /run-broken/REPORT.md\n\nAlso available as: openadapt-flow demo tutorial\n", "openadapt-flow undo": "usage: openadapt-flow undo [-h] {declare,propose,accept,list,approve,run} ...\n\npositional arguments:\n {declare,propose,accept,list,approve,run}\n declare Add a compensating step for one step's effect to a bundle\n propose Find an undo for each saving step, verify it on a declared test copy, and\n write the verified ones as proposals\n accept A person approves a proposed undo once (interactive terminal only)\n list Show the undos a stopped run offers\n approve A person approves one offered undo (interactive terminal only)\n run Run one approved undo once and check it in the system of record\n\noptions:\n -h, --help show this help message and exit\n\nRelated operations (immediately after the task name): rollback\n", "openadapt-flow undo accept": "usage: openadapt-flow undo accept [-h] --undo UNDO_ID bundle\n\npositional arguments:\n bundle Workflow bundle directory\n\noptions:\n -h, --help show this help message and exit\n --undo UNDO_ID Undo id\n", "openadapt-flow undo approve": "usage: openadapt-flow undo approve [-h] --bundle BUNDLE --undo UNDO_ID [--note NOTE] run_dir\n\npositional arguments:\n run_dir The stopped run's directory\n\noptions:\n -h, --help show this help message and exit\n --bundle BUNDLE The run's bundle directory\n --undo UNDO_ID Undo id\n --note NOTE Optional note for the record\n", @@ -27587,7 +27587,7 @@ "choices": null, "default": false, "dest": "break_it", - "help": "After the clean VERIFIED run, rerun the SAME certified bundle against a backend that silently rejects the write AFTER the app paints its success banner -- and watch the engine HALT instead of believing the screen. The halted run's evidence lands in /run-broken/REPORT.md", + "help": "After the clean VERIFIED run, rerun the SAME certified bundle against an app whose save keeps the encounter but drops the typed note while still showing it as saved -- and watch the engine HALT when it reopens the record and finds the note blank. The halted run's evidence lands in /run-broken/REPORT.md", "metavar": null, "nargs": 0, "options": [ diff --git a/packages/flow/tests/test_cli_tutorial_break_it.py b/packages/flow/tests/test_cli_tutorial_break_it.py index 024f07e4e4..213854e5dd 100644 --- a/packages/flow/tests/test_cli_tutorial_break_it.py +++ b/packages/flow/tests/test_cli_tutorial_break_it.py @@ -5,9 +5,9 @@ What is proven here, cheaply and on every unit run: * the flag reaches :func:`openadapt_flow.tutorial.run_tutorial` and its result - drives the printed narrative -- screen claim, refuted verifier read, HALTED - outcome, evidence path, and the no-receipt rule -- from run evidence, not - from a script; + drives the printed narrative -- saved message on screen, the record read back + with its note blank, HALTED outcome, evidence path, and the no-receipt rule -- + from run evidence, not from a script; * the plain tutorial ends with a pointer at ``--break-it`` as the next step; * :func:`openadapt_flow.tutorial._run_break_it` raises loudly when the engine does NOT halt on the injected fault, and extracts the narrative facts from a @@ -67,7 +67,7 @@ def _broken_result(root: Path) -> BreakItResult: return BreakItResult( run_dir=root / "run-broken", report_path=root / "run-broken" / "REPORT.md", - fault="optimistic", + fault="partial", execution_outcome="HALTED", transaction_outcome="RECONCILIATION_REQUIRED", transaction_billable=False, @@ -75,8 +75,9 @@ def _broken_result(root: Path) -> BreakItResult: screen_claim_text="Encounter saved", effects_required=2, effects_refuted=1, - halt_reason="record_written refuted against the rest system of record", - system_of_record_records=0, + halt_reason="field_equals refuted against the rest system of record", + system_of_record_records=1, + notes_as_typed=0, ) @@ -103,11 +104,15 @@ def fake_run_tutorial(work_dir: Path, **kwargs: Any) -> TutorialResult: assert "every on-screen check passed" in out assert '"Encounter saved"' in out assert "1/2 declared effect(s) REFUTED" in out - assert "0 record(s)" in out + assert "1 encounter(s), 0 with the note as typed" in out + assert "the encounter with its note blank" in out + # No language from the retired fault: nothing on screen is called a lie. + assert "rejects the write" not in out + assert "believ" not in out assert "HALTED at the consequential step" in out assert "RECONCILIATION_REQUIRED" in out # The engine's own halt reason is quoted, not paraphrased. - assert "record_written refuted" in out + assert "field_equals refuted" in out # Where the evidence lives, and what may NOT be claimed. assert str(tmp_path / "t" / "run-broken" / "REPORT.md") in out assert "NOT a success receipt" in out @@ -160,7 +165,12 @@ def _wire_break_it_fakes( "serve", lambda: ("http://127.0.0.1:9/", None, lambda: None), ) - monkeypatch.setattr(tutorial_module, "_records", lambda base_url: []) + # The partial save: the encounter row landed, its note did not. + monkeypatch.setattr( + tutorial_module, + "_records", + lambda base_url: [{"id": 1, "patient_id": "P-1001", "note": ""}], + ) monkeypatch.setattr( tutorial_module, "run_tutorial_workflow", lambda **kwargs: report ) @@ -203,7 +213,7 @@ def test_run_break_it_extracts_the_narrative_from_the_halted_report( results=[save_result], halt=SimpleNamespace( observed_texts=["MockMed", "Encountersaved-"], - reason="record_written refuted -- nothing landed", + reason="field_equals refuted -- field 'note' is ''", ), outcome_envelope=SimpleNamespace(required_contracts=SimpleNamespace(effect=2)), ) @@ -217,11 +227,45 @@ def test_run_break_it_extracts_the_narrative_from_the_halted_report( say=lambda message: None, ) assert broken.execution_outcome == "HALTED" - assert broken.fault == "optimistic" + assert broken.fault == "partial" assert broken.screen_claimed_success is True assert broken.screen_claim_text == "Encountersaved-" assert broken.effects_required == 2 assert broken.effects_refuted == 1 - assert broken.system_of_record_records == 0 - assert broken.halt_reason == "record_written refuted -- nothing landed" + assert broken.system_of_record_records == 1 + assert broken.notes_as_typed == 0 + assert broken.halt_reason == "field_equals refuted -- field 'note' is ''" assert broken.report_path == tmp_path / "run-broken" / "REPORT.md" + + +def test_run_break_it_counts_only_notes_stored_as_typed( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + """The note count is read from the store, not assumed from the fault.""" + + report = SimpleNamespace( + execution_outcome="HALTED", + transaction_outcome="RECONCILIATION_REQUIRED", + transaction_billable=False, + results=[], + halt=None, + outcome_envelope=None, + ) + _wire_break_it_fakes(monkeypatch, tmp_path, report) + monkeypatch.setattr( + tutorial_module, + "_records", + lambda base_url: [ + {"id": 1, "note": tutorial_module.TUTORIAL_NOTE}, + {"id": 2, "note": tutorial_module.TUTORIAL_NOTE[:10]}, + ], + ) + broken = _run_break_it( + workflow=_fake_workflow(), + bundle_dir=tmp_path / "bundle", + run_dir=tmp_path / "run-broken", + headed=False, + say=lambda message: None, + ) + assert broken.system_of_record_records == 2 + assert broken.notes_as_typed == 1 diff --git a/packages/flow/tests/test_cli_tutorial_next_steps.py b/packages/flow/tests/test_cli_tutorial_next_steps.py index d19da3b9ad..3ac4dd9f2a 100644 --- a/packages/flow/tests/test_cli_tutorial_next_steps.py +++ b/packages/flow/tests/test_cli_tutorial_next_steps.py @@ -67,7 +67,7 @@ def _broken_result(root: Path) -> BreakItResult: return BreakItResult( run_dir=root / "run-broken", report_path=root / "run-broken" / "REPORT.md", - fault="optimistic", + fault="partial", execution_outcome="HALTED", transaction_outcome="RECONCILIATION_REQUIRED", transaction_billable=False, @@ -75,8 +75,9 @@ def _broken_result(root: Path) -> BreakItResult: screen_claim_text="Encounter saved", effects_required=2, effects_refuted=1, - halt_reason="record_written refuted against the rest system of record", - system_of_record_records=0, + halt_reason="field_equals refuted against the rest system of record", + system_of_record_records=1, + notes_as_typed=0, ) diff --git a/packages/flow/tests/test_demo_proof.py b/packages/flow/tests/test_demo_proof.py index 4a6ee7f03e..4caf235485 100644 --- a/packages/flow/tests/test_demo_proof.py +++ b/packages/flow/tests/test_demo_proof.py @@ -95,7 +95,7 @@ def _write_run( HaltObservation( state_id="step_005", intent="click 'Save Encounter'", - reason="record_written refuted the system of record", + reason="field_equals refuted the system of record", ) if halted else None @@ -109,7 +109,7 @@ def _tutorial_result( root: Path, *, broken_transaction: Optional[str] = "RECONCILIATION_REQUIRED", - broken_records: int = 0, + broken_notes_as_typed: int = 0, identical_frames: bool = True, pending: bool = True, ) -> TutorialResult: @@ -142,7 +142,7 @@ def _tutorial_result( broken = BreakItResult( run_dir=root / "run-broken", report_path=root / "run-broken" / "REPORT.md", - fault="optimistic", + fault="partial", execution_outcome="HALTED", transaction_outcome=broken_transaction, transaction_billable=False, @@ -150,8 +150,9 @@ def _tutorial_result( screen_claim_text="Encountersaved-", effects_required=2, effects_refuted=1, - halt_reason="record_written refuted the system of record", - system_of_record_records=broken_records, + halt_reason="field_equals refuted the system of record", + system_of_record_records=1, + notes_as_typed=broken_notes_as_typed, ) return TutorialResult( recording_dir=root / "recording", @@ -196,7 +197,7 @@ def test_shows_the_difference_from_the_runs_own_evidence( visible = _visible_text(page) assert "Both runs ended on the same saved screen." in visible assert "Done and checked" in visible - assert "Stopped: the note never reached the record" in visible + assert "Stopped: the record is missing the typed note" in visible assert "Check the record" in visible assert "identical, pixel for pixel" in visible # Both final frames are embedded, and each links to the full frame. @@ -232,6 +233,9 @@ def test_reconciliation_never_claims_nothing_was_written( assert "the record check found only one note." in visible assert "only one note was saved" not in visible assert "a person checks the record before anything is retried" in visible + # The partial save left the encounter; the page says so. + assert "found the saved encounter, but not the note that was typed" in visible + assert "0 typed notes found" in re.sub(r"\s+", " ", visible) def test_halted_before_effect_may_say_nothing_was_written( self, tmp_path: Path @@ -262,7 +266,7 @@ def test_identical_is_claimed_only_when_digests_match(self, tmp_path: Path) -> N def test_a_pair_that_did_not_show_the_difference_says_so( self, tmp_path: Path ) -> None: - result = _tutorial_result(tmp_path, broken_records=1) + result = _tutorial_result(tmp_path, broken_notes_as_typed=1) evidence = demo_proof.collect_evidence(result, tmp_path) assert not evidence.showed_the_difference visible = _visible_text(demo_proof.render_demo_page(evidence)) @@ -331,7 +335,7 @@ def test_summary_is_short_and_derived_from_the_plain_results( assert len(lines) <= 7 text = "\n".join(lines) assert "Run 1 Done and checked." in text - assert "Run 2 Stopped: the note never reached the record." in text + assert "Run 2 Stopped: the record is missing the typed note." in text assert "Check the record before anyone runs this again." in text assert "(open it in a browser)" in text assert lines[-1].startswith("Next: openadapt-flow record ") @@ -472,7 +476,9 @@ def test_demo_exit_1_when_the_pair_did_not_show_the_difference( monkeypatch.setattr( tutorial_module, "run_tutorial", - lambda work_dir, **kw: _tutorial_result(Path(work_dir), broken_records=1), + lambda work_dir, **kw: _tutorial_result( + Path(work_dir), broken_notes_as_typed=1 + ), ) assert main(["demo", "--out", str(tmp_path / "p"), "--no-open"]) == 1