From 74d9cbe05aa62dd6d2039eb176c24363134fafa1 Mon Sep 17 00:00:00 2001 From: scottkalw Date: Sat, 14 Nov 2026 20:53:20 -0600 Subject: [PATCH 1/8] Course draft 2: class 1.3, routings, filmed The first class of the core. A fork's road told as a word card, then the three words (operation, sequence, routing) and the recipe of steps, not of ingredients. Then the plant's routings in Admin. RT-PALLET is typed into the form, and each step's cost center is read from its machine's line. The two things the form refuses close it out. Filmed on a scratch cutlery plant on loopback at ten times. The recorder learns to fill in a form: `fill` types into a field one key at a time, and `choose` picks an option from a list. It scrolls a control clear of the caption bar before it touches it. It also lifts the product's toast above that bar, which otherwise covers it. course.toml gains 1.3's outcomes and its scene, and nothing else. Co-Authored-By: Claude Opus 5.5 Signed-off-by: scottkalw --- scripts/course/course.toml | 6 + scripts/record-scene.py | 88 +++- scripts/scenes/course/02-03-routings.toml | 439 ++++++++++++++++++ ...e_into_a_form_and_choose_from_its_lists.py | 86 ++++ ...ng_whose_steps_bring_their_cost_centers.py | 226 +++++++++ 5 files changed, 838 insertions(+), 7 deletions(-) create mode 100644 scripts/scenes/course/02-03-routings.toml create mode 100644 tests/test_a_scene_can_type_into_a_form_and_choose_from_its_lists.py create mode 100644 tests/test_class_1_3_defines_a_routing_whose_steps_bring_their_cost_centers.py diff --git a/scripts/course/course.toml b/scripts/course/course.toml index 85e75ad7..c43ea0b4 100644 --- a/scripts/course/course.toml +++ b/scripts/course/course.toml @@ -105,6 +105,12 @@ label = "1.3" slug = "routings" title = "Routings — the path a material takes" one_line = "The ordered operations that make a material, each on a named machine." +outcomes = [ + "Say what a routing is: operations in sequence, each on a named machine, for one material.", + "Read a plant's routings in Admin, and the cost center each step bills to, read from its machine's line.", + "Define a routing in the form, and say the two things it refuses: no operation, and a code in use.", +] +scene = "scripts/scenes/course/02-03-routings.toml" [[module.lesson]] order = 4 diff --git a/scripts/record-scene.py b/scripts/record-scene.py index 726f03e9..23854350 100644 --- a/scripts/record-scene.py +++ b/scripts/record-scene.py @@ -4,8 +4,8 @@ python scripts/record-scene.py --base http://127.0.0.1:8110 --out /tmp/take python scripts/record-scene.py --course # course.json and the tree's README only -A scene file is a list of steps — `goto`, `click`, `wait_for`, `say`, `hold`, -`mark`, `slide` — against a plant that is already running. This file drives a browser +A scene file is a list of steps — `goto`, `click`, `fill`, `choose`, +`wait_for`, `say`, `hold`, `mark`, `slide` — against a plant that is already running. This file drives a browser through them, burns the overlay into the picture, and writes, into one folder: * `.gif`, the published loop, under the budget the scene states and @@ -70,7 +70,8 @@ narrator is drawn there afterwards, and nothing a viewer must read may sit under it. The take is checked for that as it is filmed. It also hides the floating Assistant and Design buttons, which are the product's and sit in that -corner. +corner, and lifts the product's toast above the caption bar, which would +otherwise cover it. It is a developer tool. It is not in the wheel, not in CI, and not asked to run on Windows. It needs `ffmpeg`, and a Python with Playwright and its @@ -102,14 +103,18 @@ HERE = Path(__file__).resolve().parent REPO = HERE.parent -# The seven words a step can be. An eighth is a newer scene file than this +# The nine words a step can be. A tenth is a newer scene file than this # script, and guessing what it meant is how a recording comes out missing the -# thing it was made to show. -VERBS = ("goto", "click", "wait_for", "say", "hold", "mark", "slide") +# thing it was made to show. `fill` types into a field, a key at a time so the +# viewer sees it typed, and `choose` picks an option of a ``) and the option's `value`") if verb == "say": if not step.get("line"): raise SystemExit(f"{where}: a `say` needs a `line` — it is the sentence on screen") @@ -391,6 +406,8 @@ def planned_seconds(scene: dict) -> float: total += SCROLL_SECONDS if step["do"] == "goto": total += float(step["settle"]) + elif step["do"] == "fill": + total += len(step["text"]) * TYPE_DELAY_SECONDS + SMALL_STEP_SECONDS elif step["do"] == "say": total += float(step["hold"]) elif step["do"] == "hold": @@ -426,6 +443,10 @@ def play(scene: dict, stage) -> None: stage.goto(step["url"], float(step["settle"])) elif verb == "click": stage.click(step["selector"]) + elif verb == "fill": + stage.fill(step["selector"], step["text"]) + elif verb == "choose": + stage.choose(step["selector"], step["value"]) elif verb == "wait_for": stage.wait_for(step, float(step["timeout"])) elif verb == "say": @@ -483,6 +504,10 @@ def overlay_script(badge: str, captions: bool = True) -> str: "padding:0 18px!important;border-radius:8px!important;white-space:nowrap!important;" "box-shadow:0 2px 10px rgba(0,0,0,.5)!important}" ".assist-launch,.design-launch{display:none!important}" + # The product's message after a save sits 22 px off the bottom, under + # the caption bar; it is lifted above the bar's two lines, where the + # viewer can read it, and is otherwise drawn as the product draws it. + f".toast{{bottom:{TOAST_LIFT}px!important}}" ) return f""" (() => {{ @@ -603,6 +628,7 @@ def click(self, selector: str) -> None: # above. When the clicked thing is gone after the click (a button that # takes itself away, a link that leaves the page) the press is all # there is, and the mark says so. + self.clear_of_caption(selector) heard = len(self.presses) # The same element `page.click` will press: the first that matches. clicked = self.page.locator(selector).first.element_handle() @@ -623,6 +649,52 @@ def click(self, selector: str) -> None: print(f" at {mark['x']},{mark['y']} press {mark.get('press')}" + (f" ({mark['settled']})" if "settled" in mark else ""), flush=True) + def fill(self, selector: str, text: str) -> None: + # Emptied first, then typed a key at a time, so the frames show the + # words arriving rather than a field that was blank and then full. + self.clear_of_caption(selector) + field = self.page.locator(selector).first + field.fill("") + if text: + field.press_sequentially(text, delay=int(TYPE_DELAY_SECONDS * 1000)) + self.note(f"fill {selector}: {text!r}", "fill", text=text) + self.page.wait_for_timeout(int(SMALL_STEP_SECONDS * 1000)) + + def choose(self, selector: str, value: str) -> None: + # The option is picked, not the list opened: an open ``. Neither writes; the click on +the form's button does, and that still needs `allow_writes`. The product's +message after a save is lifted above the caption bar, which otherwise covers +it. No plant and no browser here. +""" + +from __future__ import annotations + +import importlib.util +from pathlib import Path + +import pytest + +REPO = Path(__file__).resolve().parents[1] +RUNNER = REPO / "scripts" / "record-scene.py" + + +@pytest.fixture(scope="module") +def runner(): + spec = importlib.util.spec_from_file_location("record_scene_fill_choose", RUNNER) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def write_scene(tmp_path: Path, steps: str) -> Path: + path = tmp_path / "scene.toml" + path.write_text('name = "form"\nbase = "http://127.0.0.1:8040"\n' + steps, encoding="utf-8") + return path + + +def test_fill_and_choose_are_words_a_step_can_be(runner): + assert "fill" in runner.VERBS and "choose" in runner.VERBS + + +def test_the_stage_is_handed_the_field_and_its_text_and_the_list_and_its_option(runner, tmp_path): + scene = runner.load_scene(write_scene(tmp_path, ''' +[[step]] +do = "fill" +selector = "#code" +text = "RT-PALLET" + +[[step]] +do = "choose" +selector = "#material" +value = "PALLET" +''')) + handed = [] + + class Stage: + def fill(self, selector, text): + handed.append(("fill", selector, text)) + + def choose(self, selector, value): + handed.append(("choose", selector, value)) + + runner.play(scene, Stage()) + + assert handed == [("fill", "#code", "RT-PALLET"), ("choose", "#material", "PALLET")] + + +def test_a_fill_without_its_text_or_a_choose_without_its_option_is_refused_before_filming(runner, tmp_path): + with pytest.raises(SystemExit, match="needs a `selector` and the `text`"): + runner.load_scene(write_scene(tmp_path, '[[step]]\ndo = "fill"\nselector = "#code"\n')) + with pytest.raises(SystemExit, match="the option's `value`"): + runner.load_scene(write_scene(tmp_path, '[[step]]\ndo = "choose"\nselector = "#material"\n')) + + +def test_typing_takes_time_in_the_plan_by_the_length_of_what_is_typed(runner, tmp_path): + short = runner.load_scene(write_scene(tmp_path, '[[step]]\ndo = "fill"\nselector = "#a"\ntext = "RT"\n')) + long = runner.load_scene(write_scene(tmp_path, '[[step]]\ndo = "fill"\nselector = "#a"\ntext = "RT-PALLET-LINE-ONE"\n')) + + assert runner.planned_seconds(long) - runner.planned_seconds(short) == pytest.approx( + 16 * runner.TYPE_DELAY_SECONDS) + + +def test_the_products_message_after_a_save_is_drawn_above_the_caption_bar(runner): + overlay = runner.overlay_script("badge") + + assert f".toast{{bottom:{runner.TOAST_LIFT}px!important}}" in overlay + # Above two lines of caption: 18 px padding, two lines of 25 px at 1.3, the border. + assert runner.TOAST_LIFT > 18 * 2 + 2 * 25 * 1.3 + 2 diff --git a/tests/test_class_1_3_defines_a_routing_whose_steps_bring_their_cost_centers.py b/tests/test_class_1_3_defines_a_routing_whose_steps_bring_their_cost_centers.py new file mode 100644 index 00000000..09735bf2 --- /dev/null +++ b/tests/test_class_1_3_defines_a_routing_whose_steps_bring_their_cost_centers.py @@ -0,0 +1,226 @@ +"""Class 1.3 defines a routing whose steps bring their machines' cost centers, on a scratch cutlery plant. + +*Routings — the path a material takes* is the first class of the core: a +fork's road in words, the three words a routing is made of, the plant's +routings table, a new pallet routing typed into the Admin form with each +step's cost center read from its machine's line, and the two things the form +refuses. This file holds the scene file to what the outline asks of it. No +plant and no browser: the scene is loaded and walked the way the recorder +walks it. +""" + +from __future__ import annotations + +import importlib.util +import json +import re +from pathlib import Path +from urllib.parse import urlparse + +import pytest + +from fsmes import modules + +REPO = Path(__file__).resolve().parents[1] +RUNNER = REPO / "scripts" / "record-scene.py" +SCENE = REPO / "scripts" / "scenes" / "course" / "02-03-routings.toml" +PACK = REPO / "labs" / "cutlery" / "masterdata" + +# The lab fleet, the public demo and the stock demo ports: a class is never +# filmed on a plant somebody else is looking at. +NOT_OURS = {8090, 8110, 8120, 8140, 9030, 5433, 5434, 4944, 4945} + +# What no caption, card or note may carry: a calendar date, a year, a month's +# name. The class is about any plant on any day. +A_DATE = re.compile( + r"\b(19|20)\d\d\b|\b\d{1,2}/\d{1,2}/\d{2,4}\b|" + r"\b(January|February|March|April|May|June|July|August|September|October|November|December)\b" +) + + +@pytest.fixture(scope="module") +def runner(): + """`scripts/record-scene.py`, imported by path because of the hyphen.""" + spec = importlib.util.spec_from_file_location("record_scene_class_1_3", RUNNER) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +@pytest.fixture(scope="module") +def scene(runner): + return runner.load_scene(SCENE) + + +def pack(kind: str) -> list[dict]: + return json.loads((PACK / f"{kind}.json").read_text(encoding="utf-8")) + + +def everything_written(scene: dict) -> list[str]: + """Every sentence a viewer or a reader of the folder will see.""" + written = [scene["title"], scene["what_is_written"], *scene["notes"], *scene["honesty"]] + for step in scene["step"]: + if step["do"] == "say": + written.append(step["line"]) + if step["do"] == "slide": + written += [step["title"], *step["lines"]] + if step["do"] == "fill": + written.append(step["text"]) + return written + + +def typed(scene: dict, part: str) -> list[str]: + return [step["text"] for step in scene["step"] if step["part"] == part and step["do"] == "fill"] + + +def chosen(scene: dict, part: str) -> list[str]: + return [step["value"] for step in scene["step"] if step["part"] == part and step["do"] == "choose"] + + +def test_the_scene_is_a_full_take_of_class_1_3_named_by_its_label_that_runs_four_to_six_minutes(runner, scene): + assert scene["lesson"] == "1.3" and scene["take_is"] == "lesson" + assert (scene["width"], scene["height"]) == (1280, 720) + planned = runner.planned_seconds(scene) + # Page loads and waits add to the plan; the finished take is measured. + assert 240 <= planned <= scene["budget_seconds"] <= 360, planned + print(f"planned {planned} s against a {scene['budget_seconds']} s budget") + + +def test_it_films_into_the_routings_folder_of_the_core(runner, scene): + course = runner.load_course(REPO / "scripts" / "course" / "course.toml") + _, lesson = runner.find_lesson(course, scene["lesson"]) + + assert lesson["path"] == "02-the-core/03-routings" + assert lesson["scene"] == SCENE.relative_to(REPO).as_posix() + + +def test_the_scene_walks_the_five_parts_in_order(runner, scene): + order = [] + for step in scene["step"]: + if not order or order[-1] != step["part"]: + order.append(step["part"]) + + assert order == list(runner.PARTS) + + +def test_the_hook_is_a_card_of_a_forks_road_then_its_line_and_is_short_enough_for_the_teaser(runner, scene): + hook = [step for step in scene["step"] if step["part"] == "hook"] + + assert hook[0]["do"] == "slide" and hook[0]["name"] == "a-forks-road" + machines = [op["equipment"] for op in next(r for r in pack("routings") if r["code"] == "RT-FORK1")["operations"]] + assert [line.rsplit(" ", 1)[-1] for line in hook[0]["lines"] if "_" in line] == machines + assert [step["url"] for step in hook if step["do"] == "goto"] == ["/dashboard?line=FORK1LINE"] + assert runner.planned_seconds(dict(scene, step=hook)) - scene["gif_skip_seconds"] <= 30 + + +def test_the_idea_cards_name_operation_sequence_and_routing_and_the_recipe_of_steps(scene): + cards = {step["name"]: step for step in scene["step"] if step["do"] == "slide" and step["part"] == "idea"} + + assert [line.split(":")[0] for line in cards["three-words"]["lines"]] == ["Operation", "Sequence", "Routing"] + assert cards["steps-not-ingredients"]["title"] == "The recipe of steps, not of ingredients" + + +def test_the_routing_typed_in_is_not_in_the_pack_and_every_code_in_it_is_the_plants_own(scene): + codes = {r["code"] for r in pack("routings")} + materials = {m["code"] for m in pack("materials")} + machines = {e["code"]: e for e in pack("equipment")} + screen_typed, screen_chosen = typed(scene, "screen"), chosen(scene, "screen") + + assert "RT-PALLET" in screen_typed and "RT-PALLET" not in codes + assert screen_chosen == ["PALLET", "PAL1_Palletizer", "PAL1_StretchWrap"] + assert screen_chosen[0] in materials + assert all(code in machines for code in screen_chosen[1:]) + # The cost center the class says filled itself is the machines' line's, and + # neither machine carries one of its own. + assert {machines[machines[code]["parent"]]["cost_center"] for code in screen_chosen[1:]} == {"CC-PAL01"} + assert not any(machines[code].get("cost_center") for code in screen_chosen[1:]) + assert "CC-PAL01" not in screen_typed + + +def test_the_routing_is_created_by_the_forms_own_button_and_seen_in_the_table_afterwards(scene): + screen = [step for step in scene["step"] if step["part"] == "screen"] + create = next(i for i, step in enumerate(screen) if step["do"] == "click" and "routing-create" in step["selector"]) + + assert screen[create + 1]["do"] == "wait_for" and "RT-PALLET created" in screen[create + 1]["text"] + assert any(step["do"] == "wait_for" and step.get("text") == "RT-PALLET" for step in screen[create:]) + + +def test_what_it_refuses_is_a_routing_with_no_operation_and_a_code_already_used(scene): + refuses = [step for step in scene["step"] if step["part"] == "refuses"] + waits = [step["text"] for step in refuses if step["do"] == "wait_for"] + said = " ".join(step["line"] for step in refuses if step["do"] == "say") + + assert waits == ["A routing needs at least one operation.", "already exists"] + assert sum(1 for step in refuses if step["do"] == "click") == 2 + assert "machine that does not exist" in said and "list with no blank" in said + + +def test_the_you_now_know_card_says_the_classs_own_outcomes_word_for_word(runner, scene): + course = runner.load_course(REPO / "scripts" / "course" / "course.toml") + _, lesson = runner.find_lesson(course, scene["lesson"]) + know = [step for step in scene["step"] if step["part"] == "know" and step["do"] == "slide"] + + assert len(lesson["outcomes"]) == 3 + assert len(know) == 1 and know[0]["lines"] == lesson["outcomes"] + + +def test_every_page_it_visits_is_a_screen_the_app_serves(scene): + served = [page.path for module in modules.REGISTRY for page in module.pages] + patterns = [re.compile("^" + re.sub(r"\{[^}]+\}", "[^/]+", path) + "$") for path in served] + visited = {urlparse(step["url"]).path for step in scene["step"] if step["do"] == "goto"} + + unserved = sorted(path for path in visited if not any(p.match(path) for p in patterns)) + assert unserved == [], f"{len(unserved)} of {len(visited)} pages are not served: {unserved}" + + +def test_every_frame_carries_the_pre_alpha_simulated_plant_badge(scene): + assert scene["badge"] == "pre-alpha · simulated plant · v{version}" + + +def test_no_caption_card_note_or_typed_word_carries_a_date(scene): + dated = [line for line in everything_written(scene) if A_DATE.search(line)] + + assert dated == [], f"{len(dated)} lines carry a date: {dated}" + + +def test_it_is_filmed_on_a_scratch_cutlery_plant_on_loopback_and_never_on_one_somebody_else_runs(runner, scene): + base = urlparse(scene["base"]) + + assert scene["plant"]["pack"] == "labs/cutlery" + assert base.hostname == "127.0.0.1" + assert base.port not in NOT_OURS + # It writes, so it must be refused anywhere but loopback. + assert scene["allow_writes"] + runner.refuse_to_write_off_this_box(scene) + with pytest.raises(SystemExit): + runner.refuse_to_write_off_this_box(dict(scene, base="http://100.64.0.1:8040")) + + +def test_the_existing_pallet_routing_the_lists_and_the_replay_are_owned_up_to(scene): + honesty = " ".join(scene["honesty"]).lower() + + assert "rt-pal1" in honesty + assert "no blank" in honesty + assert "ten times" in honesty + + +def test_admin_is_opened_at_its_routings_and_no_screen_of_people_is_filmed(scene): + urls = [step["url"] for step in scene["step"] if step["do"] == "goto"] + + assert not [url for url in urls if "people" in url] + assert [url for url in urls if "/admin" in url] == ["/dashboard/admin#routings"] + + +def test_the_recorder_plays_every_step_of_it(runner, scene): + handed: list[str] = [] + + class Stage: + def __getattr__(self, verb): + return lambda *args: handed.append(verb) + + runner.play(scene, Stage()) + + for verb in ("goto", "click", "fill", "choose"): + assert handed.count(verb) == sum(1 for step in scene["step"] if step["do"] == verb), verb + assert handed.count("scroll_to") == sum(1 for step in scene["step"] if step.get("scroll_to")) + assert handed.count("slide") == 4 and "terminal" not in handed From 8671f89fabb2d4c5e1ec23723908f2cf7da12337 Mon Sep 17 00:00:00 2001 From: scottkalw Date: Sat, 14 Nov 2026 20:54:49 -0600 Subject: [PATCH 2/8] Class 1.3 tests: keep the typing test inside the line length Co-Authored-By: Claude Opus 5.5 Signed-off-by: scottkalw --- ...a_scene_can_type_into_a_form_and_choose_from_its_lists.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_a_scene_can_type_into_a_form_and_choose_from_its_lists.py b/tests/test_a_scene_can_type_into_a_form_and_choose_from_its_lists.py index 4a8f8cd3..be1b6480 100644 --- a/tests/test_a_scene_can_type_into_a_form_and_choose_from_its_lists.py +++ b/tests/test_a_scene_can_type_into_a_form_and_choose_from_its_lists.py @@ -71,8 +71,9 @@ def test_a_fill_without_its_text_or_a_choose_without_its_option_is_refused_befor def test_typing_takes_time_in_the_plan_by_the_length_of_what_is_typed(runner, tmp_path): - short = runner.load_scene(write_scene(tmp_path, '[[step]]\ndo = "fill"\nselector = "#a"\ntext = "RT"\n')) - long = runner.load_scene(write_scene(tmp_path, '[[step]]\ndo = "fill"\nselector = "#a"\ntext = "RT-PALLET-LINE-ONE"\n')) + fill = '[[step]]\ndo = "fill"\nselector = "#a"\ntext = "{}"\n' + short = runner.load_scene(write_scene(tmp_path, fill.format("RT"))) + long = runner.load_scene(write_scene(tmp_path, fill.format("RT-PALLET-LINE-ONE"))) assert runner.planned_seconds(long) - runner.planned_seconds(short) == pytest.approx( 16 * runner.TYPE_DELAY_SECONDS) From 26434723c5dccd1b4aa3ba8387a247c5160bb1ed Mon Sep 17 00:00:00 2001 From: scottkalw Date: Sat, 14 Nov 2026 21:18:21 -0600 Subject: [PATCH 3/8] Course draft 2: class 1.4, a work order's day, scene and tests The fourth class of draft 2: a new fork order typed into the Orders page and released, found in the mould's queue on its station screen, the plant's own fork order read step by step (its count the last step's), and what an order refuses: it does not finish itself at its quantity (decision 0029), so a person finishes its steps and the confirmation is in the outbox. 1.4's outcomes and scene in course.toml; the draft-1 scene stays on disk untouched. Co-Authored-By: Claude Opus 5.5 Signed-off-by: scottkalw --- scripts/course/course.toml | 7 +- .../course/02-04-a-work-orders-day.toml | 407 ++++++++++++++++++ ...and_a_person_not_its_count_finishes_one.py | 269 ++++++++++++ 3 files changed, 682 insertions(+), 1 deletion(-) create mode 100644 scripts/scenes/course/02-04-a-work-orders-day.toml create mode 100644 tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py diff --git a/scripts/course/course.toml b/scripts/course/course.toml index c43ea0b4..06781f85 100644 --- a/scripts/course/course.toml +++ b/scripts/course/course.toml @@ -118,7 +118,12 @@ label = "1.4" slug = "a-work-orders-day" title = "Work orders — make this many of that, this way" one_line = "Released to the floor, station to station; its good count is the last step's, not the sum." -scene = "scripts/scenes/04-work-orders-and-routings.toml" +outcomes = [ + "Say what a work order is: this many of a material, made along its routing, from release to finish.", + "Create and release an order on the Orders page, and find it in the first machine's queue on its station screen.", + "Read an order's count as its last step's, and say why it stays open past its number until a person finishes it.", +] +scene = "scripts/scenes/course/02-04-a-work-orders-day.toml" # ------------------------------------------------------------------ tier 2 [[module]] diff --git a/scripts/scenes/course/02-04-a-work-orders-day.toml b/scripts/scenes/course/02-04-a-work-orders-day.toml new file mode 100644 index 00000000..3f445366 --- /dev/null +++ b/scripts/scenes/course/02-04-a-work-orders-day.toml @@ -0,0 +1,407 @@ +# Class 1.4 of the course, *Work orders — make this many of that, this way*: +# an order is released to the floor, runs station to station, and is finished +# by a person, not by its count. +# +# It starts from the card a bin carries on a floor, names the four words of an +# order's life (order, release, dispatch, finish), types a new order for forks +# into the Orders page and releases it, finds it in the mould's queue on its +# station screen, and reads the plant's own fork order step by step, its good +# count the last step's. Then what an order refuses: it has passed its number +# and is still open, because reaching the quantity is not being finished +# (decision 0029). A person finishes it, and the confirmation for the office is +# in the outbox. Filmed on a scratch cutlery plant, every screen as the product +# draws it. + +name = "a-work-orders-day" +title = "Work orders — make this many of that, this way" +lesson = "1.4" +take_is = "lesson" +part = "hook" +base = "http://127.0.0.1:8040" +badge = "pre-alpha · simulated plant · v{version}" +# Four to six minutes, as the outline says this class runs. +budget_seconds = 360 +gif_skip_seconds = 2.0 +width = 1280 +height = 720 +# Creating, releasing and finishing an order are writes, and they are the story. +allow_writes = true +what_is_written = "which is how the class creates and releases its order and finishes the plant's: Create, Release and each Finish step are real `POST`s to the take's own scratch plant, made with the product's own buttons, and its audit trail names the person signed in as having made them." + +notes = [ + "The plant was started from the cutlery pack at ten times wall clock. The camera waited, off camera, until the pack's own released fork order, WO-FORK1-0001 for 2,778 forks, had booked 2,400 of them, so that by the time the class reaches it the line has run past its number on camera's side of the cut.", + "The simulated floor was told `MES_OPS_FINISH_ORDERS=false`. Its simulated shift supervisor otherwise finishes an order soon after the line has made its number and releases the next one himself: he would have finished, off camera, the very order this class shows a person finishing. The switch belongs to the simulated floor (it is the one `fsmes lab` uses for its over-run experiment); the MES is configured as anybody installs it.", + "The order typed in is WO-FORK1-0100 for 11,000 forks of UT-FORK, a code the pack does not have, outside the planner's own sequence (it continues WO-FORK1-0003, 0004, ...). 11,000 is about one eight-hour shift of the fork line, which the pack rates at a little over twenty-three forks a minute; the pack's own orders are for two hours, 2,778. The form has no routing or line to choose: the order's steps are copied from the material's first routing, RT-FORK1, which is the fork line's.", + "The order is created with the form's Release box unticked, so that release is its own press on camera, the Release button, rather than a side effect of Create.", + "The finish beat is filmed on the plant's own WO-FORK1-0001, which was released when the plant started and was far along when the camera rolled; the order typed in the class would take hours at this speed. The person finishes its three steps one by one with the orders page's Finish step button.", + "The outbox is opened right after the order completes, so that its confirmation is among the newest twenty messages the panel draws; the rest are the machines' state changes, which are most of what a plant sends.", + "At any speed but 1x every 2D page carries the product's REPLAY 10× banner across its top. It is filmed as the product draws it.", + "The opening beat is a plain card with words on it. There is no artwork of a card, a bin, a machine or a person.", +] + +honesty = [ + "the order typed in is not the one finished: finishing is filmed on the plant's own fork order, WO-FORK1-0001, released when the plant started and far along when the camera rolled, because an order for a shift does not run out in a five-minute class", + "the form chooses no routing: a new order takes its material's first routing, and for forks that is RT-FORK1, the fork line's; the class says the steps were copied from the fork line's routing, not that the planner picked a line", + "the simulated floor was told not to finish orders itself (MES_OPS_FINISH_ORDERS=false), so the order on camera stays open past its number until the person on camera finishes it; on a plant left to itself the simulated supervisor would have closed it", + "the outbox panel draws the newest twenty messages, most of them machine state changes; the confirmation is in view only because the class opens the panel seconds after the order completes; the card already open about that panel stands", + "the plant is a scratch plant a few minutes old, replaying at ten times wall clock, which is the banner across the top of the 2D pages", +] + +[plant] +pack = "labs/cutlery" +speed = 10 +env = { MES_OPS_FINISH_ORDERS = "false" } +roll_when_timeout_seconds = 1800 + +# Short of its 2,778, so the count passes the number while the class is on it. +[[plant.roll_when_order]] +code = "WO-FORK1-0001" +booked = 2400 + +# ----------------------------------------------------------------- the hook + +[[step]] +do = "slide" +name = "the-card-on-the-bin" +title = "The card clipped to a bin" +lines = [ + "Make: forks, UT-FORK", + "How many: 2,778", + "This way: Mold, then Degate, then Mark", + "Done when somebody signs it off", +] +hold = 1.5 + +[[step]] +do = "say" +line = "On a floor, a bin of work carries a card. It says what to make, how many, and which way." + +[[step]] +do = "say" +line = "Every station the bin passes reads the card. At the end, somebody signs it off. That card is a work order." + +[[step]] +do = "mark" +name = "the-card-on-the-bin" + +# ----------------------------------------------------------------- the idea + +[[step]] +part = "idea" +do = "slide" +name = "four-words" +title = "Four words" +lines = [ + "Order: make this many of that material, this way (its routing)", + "Release: the order may now go to the floor", + "Dispatch: each machine's queue shows the work it has next", + "Finish: a person says a step, and then the order, is done", +] +hold = 1.5 + +[[step]] +do = "say" +line = "Four words. An order says make this many of that material, this way. This way is its routing, the road from the last class." + +[[step]] +do = "say" +line = "Release means the order may now go to the floor. Until then it is a plan, and no machine works on it." + +[[step]] +do = "say" +line = "Dispatch is each machine's queue: the work it has next, in order. And finish is a person saying a step is done, and then the order." + +[[step]] +do = "mark" +name = "four-words" + +# ------------------------------------------------------------ on the screen + +[[step]] +part = "screen" +do = "goto" +url = "/dashboard/orders" +settle = 2 + +[[step]] +do = "wait_for" +js = "document.querySelector('#new-order-form').classList.contains('hidden') && document.querySelectorAll('#order-list tbody tr').length > 0" + +[[step]] +do = "say" +line = "This is the Orders page. Every order on the plant, its status, what was ordered and what has been booked." + +[[step]] +do = "mark" +name = "the-orders-page" + +[[step]] +do = "say" +line = "A planner makes a new one. New order: a code, the material, and how many." + +[[step]] +do = "click" +selector = "#new-order" + +[[step]] +do = "fill" +selector = "#no-code" +text = "WO-FORK1-0100" + +[[step]] +do = "choose" +selector = "#no-material" +value = "UT-FORK" + +[[step]] +do = "fill" +selector = "#no-qty" +text = "11000" + +[[step]] +do = "say" +line = "Forks, UT-FORK. Eleven thousand: about one shift of the fork line, at some twenty-three forks a minute." + +[[step]] +do = "click" +selector = "#no-release" + +[[step]] +do = "say" +line = "We leave release unticked, so the order is only planned for now. Create." + +[[step]] +do = "mark" +name = "the-new-order-form" + +[[step]] +do = "click" +selector = "#no-create" + +[[step]] +do = "wait_for" +js = "document.querySelector('#detail-code').innerText === 'WO-FORK1-0100' && document.querySelector('#d-status').innerText === 'planned' && document.querySelectorAll('#ops tbody tr').length === 3" +scroll_to = "#detail-panel" +scroll_block = "start" +scroll_offset = 220 + +[[step]] +do = "say" +line = "Planned. Its steps were copied from the fork line's routing: Mold, Degate, Mark, each on its machine." + +[[step]] +do = "mark" +name = "planned-with-its-steps" + +[[step]] +do = "say" +line = "Now release it to the floor." + +[[step]] +do = "click" +selector = "#order-actions button:has-text(\"Release\")" + +[[step]] +do = "wait_for" +selector = "#d-status" +text = "released" + +[[step]] +do = "say" +line = "Released. Nothing has been made against it yet. Where does it show up? At the first machine of its road." + +[[step]] +do = "mark" +name = "released" + +[[step]] +do = "goto" +url = "/dashboard/station?m=FORK1_Mold" +settle = 3 + +[[step]] +do = "wait_for" +selector = "#queue" +text = "WO-FORK1-0100" +scroll_to = "#queue" +scroll_block = "start" +scroll_offset = 260 + +[[step]] +do = "say" +line = "The station screen of the fork mould, FORK1_Mold. Its queue: the order it is running now, and ours behind it, nothing made yet." + +[[step]] +do = "say" +line = "That is dispatch. The operator does not hunt for paper: the machine's screen says what is next." + +[[step]] +do = "mark" +name = "in-the-moulds-queue" + +[[step]] +do = "goto" +url = "/dashboard/orders?q=WO-FORK1-0001" +settle = 2 + +[[step]] +do = "click" +selector = "#order-list tbody tr:has-text(\"WO-FORK1-0001\")" + +[[step]] +do = "wait_for" +js = "document.querySelector('#detail-code').innerText === 'WO-FORK1-0001' && document.querySelector('#d-status').innerText === 'running' && document.querySelectorAll('#ops tbody tr').length === 3" +scroll_to = "#detail-panel" +scroll_block = "start" +scroll_offset = 220 + +[[step]] +do = "say" +line = "The order in front of ours, WO-FORK1-0001, for 2,778 forks, released when the plant started. It is running." + +[[step]] +do = "mark" +name = "the-running-order" + +[[step]] +do = "wait_for" +selector = "#ops tbody" +text = "Mark" +scroll_to = "#ops" +scroll_block = "start" +scroll_offset = 230 + +[[step]] +do = "say" +line = "Each step books what its own machine counted. Mold has made the most, then Degate, then Mark, the last." + +[[step]] +do = "say" +line = "The order's booked count is the last step's, not the sum. A fork moulded but not yet marked is not a finished fork." + +[[step]] +do = "mark" +name = "each-step-its-own-count" + +# -------------------------------------------------------------- it refuses + +[[step]] +part = "refuses" +do = "wait_for" +js = "Number((document.querySelector('#d-good').innerText || '').replace(/[^0-9.]/g, '')) > Number((document.querySelector('#d-qty').innerText || '').replace(/[^0-9.]/g, ''))" +timeout = 240 +scroll_to = "#detail-panel" +scroll_block = "start" +scroll_offset = 220 + +[[step]] +do = "say" +line = "Now what it refuses. The order has booked past its 2,778, the over-run says by how many, and it is still running." +hold = 1.0 + +[[step]] +do = "mark" +name = "past-its-number-still-open" + +[[step]] +do = "say" +line = "An order does not finish itself when the count is reached. A line that has made its number is often still running." + +[[step]] +do = "say" +line = "So every fork it makes past the number is booked to this order, and the over-run is the true one. A person closes it." + +[[step]] +do = "say" +line = "Here that person finishes each step. Mold first." + +[[step]] +do = "click" +selector = "#ops tbody tr:has-text(\"Mold\") button:has-text(\"Finish step\")" + +[[step]] +do = "wait_for" +js = "[...document.querySelectorAll('#ops tbody tr')].some(r => r.innerText.includes('Mold') && r.innerText.toLowerCase().includes('done'))" + +[[step]] +do = "say" +line = "Mold is done. The mould's next fork books to the order behind it in its queue, ours." + +[[step]] +do = "click" +selector = "#ops tbody tr:has-text(\"Degate\") button:has-text(\"Finish step\")" + +[[step]] +do = "wait_for" +js = "[...document.querySelectorAll('#ops tbody tr')].some(r => r.innerText.includes('Degate') && r.innerText.toLowerCase().includes('done'))" + +[[step]] +do = "click" +selector = "#ops tbody tr:has-text(\"Mark\") button:has-text(\"Finish step\")" + +[[step]] +do = "wait_for" +selector = "#d-status" +text = "completed" +scroll_to = "#detail-panel" +scroll_block = "start" +scroll_offset = 220 + +[[step]] +do = "say" +line = "Degate, then Mark. With its last step done, the order is completed, at the count it really made." + +[[step]] +do = "mark" +name = "finished-by-a-person" + +[[step]] +do = "goto" +url = "/dashboard/ops" +settle = 1 + +[[step]] +do = "wait_for" +selector = "#erp-table tbody" +text = "WO-FORK1-0001" +timeout = 15 +scroll_to = "#erp-table tr" +scroll_text = "WO-FORK1-0001" +scroll_offset = 300 + +[[step]] +do = "say" +line = "And the news goes up. In the outbox, a confirmation for the office, beside the machines' state changes: WO-FORK1-0001, waiting to be sent." + +[[step]] +do = "mark" +name = "the-confirmation-in-the-outbox" + +[[step]] +do = "say" +line = "It was written when a person finished the order, not when the count passed the number. So the office hears the number the line really made." + +# ------------------------------------------------------------ you now know + +[[step]] +part = "know" +do = "slide" +name = "you-now-know" +title = "You now know how to" +lines = [ + "Say what a work order is: this many of a material, made along its routing, from release to finish.", + "Create and release an order on the Orders page, and find it in the first machine's queue on its station screen.", + "Read an order's count as its last step's, and say why it stays open past its number until a person finishes it.", +] + +[[step]] +do = "say" +line = "That is a work order's day: planned, released, dispatched, counted step by step, and finished by a person. You now know how to do three things." + +[[step]] +do = "mark" +name = "you-now-know" + +[[step]] +do = "hold" +seconds = 3 diff --git a/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py b/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py new file mode 100644 index 00000000..166e0caa --- /dev/null +++ b/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py @@ -0,0 +1,269 @@ +"""Class 1.4 releases a work order to the floor and a person, not its count, finishes one, on a scratch cutlery plant. + +*Work orders — make this many of that, this way* is the second class of the +core: the card a bin carries, the four words of an order's life (order, +release, dispatch, finish), a new fork order typed into the Orders page and +released, the same order in the mould's queue on its station screen, the +plant's own fork order read step by step with its count the last step's, and +the thing an order refuses: it does not finish itself at its quantity +(decision 0029), so a person finishes it and the confirmation goes to the +outbox. This file holds the scene file to what the outline asks of it. No +plant and no browser: the scene is loaded and walked the way the recorder +walks it. +""" + +from __future__ import annotations + +import importlib.util +import json +import re +from pathlib import Path +from urllib.parse import urlparse + +import pytest + +from fsmes import modules + +REPO = Path(__file__).resolve().parents[1] +RUNNER = REPO / "scripts" / "record-scene.py" +SCENE = REPO / "scripts" / "scenes" / "course" / "02-04-a-work-orders-day.toml" +PACK = REPO / "labs" / "cutlery" / "masterdata" + +# The lab fleet, the public demo and the stock demo ports: a class is never +# filmed on a plant somebody else is looking at. +NOT_OURS = {8090, 8110, 8120, 8140, 9030, 5433, 5434, 4944, 4945} + +# What no caption, card or note may carry: a calendar date, a year, a month's +# name. The class is about any plant on any day. +A_DATE = re.compile( + r"\b(19|20)\d\d\b|\b\d{1,2}/\d{1,2}/\d{2,4}\b|" + r"\b(January|February|March|April|May|June|July|August|September|October|November|December)\b" +) + + +@pytest.fixture(scope="module") +def runner(): + """`scripts/record-scene.py`, imported by path because of the hyphen.""" + spec = importlib.util.spec_from_file_location("record_scene_class_1_4", RUNNER) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +@pytest.fixture(scope="module") +def scene(runner): + return runner.load_scene(SCENE) + + +def pack(kind: str) -> list[dict]: + return json.loads((PACK / f"{kind}.json").read_text(encoding="utf-8")) + + +def everything_written(scene: dict) -> list[str]: + """Every sentence a viewer or a reader of the folder will see.""" + written = [scene["title"], scene["what_is_written"], *scene["notes"], *scene["honesty"]] + for step in scene["step"]: + if step["do"] == "say": + written.append(step["line"]) + if step["do"] == "slide": + written += [step["title"], *step["lines"]] + if step["do"] == "fill": + written.append(step["text"]) + return written + + +def typed(scene: dict, part: str) -> list[str]: + return [step["text"] for step in scene["step"] if step["part"] == part and step["do"] == "fill"] + + +def chosen(scene: dict, part: str) -> list[str]: + return [step["value"] for step in scene["step"] if step["part"] == part and step["do"] == "choose"] + + + + +def steps_of(scene: dict, part: str) -> list[dict]: + return [step for step in scene["step"] if step["part"] == part] + + +def fork_routing() -> dict: + return next(r for r in pack("routings") if r["code"] == "RT-FORK1") + + +def test_the_scene_is_a_full_take_of_class_1_4_named_by_its_label_that_runs_four_to_six_minutes(runner, scene): + assert scene["lesson"] == "1.4" and scene["take_is"] == "lesson" + assert (scene["width"], scene["height"]) == (1280, 720) + planned = runner.planned_seconds(scene) + # Page loads and waits add to the plan; the finished take is measured. + assert 240 <= planned <= scene["budget_seconds"] <= 360, planned + print(f"planned {planned} s against a {scene['budget_seconds']} s budget") + + +def test_it_films_into_the_work_orders_folder_of_the_core_and_leaves_the_draft_one_scene_alone(runner, scene): + course = runner.load_course(REPO / "scripts" / "course" / "course.toml") + _, lesson = runner.find_lesson(course, scene["lesson"]) + + assert lesson["path"] == "02-the-core/04-a-work-orders-day" + assert lesson["scene"] == SCENE.relative_to(REPO).as_posix() + # The draft-1 teaser's scene stays on disk, filming into its own folder. + old = runner.load_scene(REPO / "scripts" / "scenes" / "04-work-orders-and-routings.toml") + assert old["take_is"] == "teaser" + + +def test_the_scene_walks_the_five_parts_in_order(runner, scene): + order = [] + for step in scene["step"]: + if not order or order[-1] != step["part"]: + order.append(step["part"]) + + assert order == list(runner.PARTS) + + +def test_the_hook_is_a_card_of_what_a_bin_carries_in_the_fork_lines_steps_short_enough_for_the_teaser(runner, scene): + hook = steps_of(scene, "hook") + order = next(o for o in pack("work_orders") if o["code"] == "WO-FORK1-0001") + + assert hook[0]["do"] == "slide" and hook[0]["name"] == "the-card-on-the-bin" + card = " ".join(hook[0]["lines"]) + assert all(op["name"] in card for op in fork_routing()["operations"]) + assert f"{order['quantity']:,}" in card and order["material"] in card + assert not [step for step in hook if step["do"] == "goto"] + assert runner.planned_seconds(dict(scene, step=hook)) - scene["gif_skip_seconds"] <= 30 + + +def test_the_idea_card_names_order_release_dispatch_and_finish(scene): + cards = [step for step in steps_of(scene, "idea") if step["do"] == "slide"] + + assert len(cards) == 1 + assert [line.split(":")[0] for line in cards[0]["lines"]] == ["Order", "Release", "Dispatch", "Finish"] + + +def test_the_order_typed_in_is_not_in_the_pack_is_for_the_plants_forks_and_is_about_a_shift_of_the_line(scene): + screen_typed, screen_chosen = typed(scene, "screen"), chosen(scene, "screen") + code, quantity = screen_typed + orders = {o["code"]: o for o in pack("work_orders")} + materials = {m["code"] for m in pack("materials")} + + assert code.startswith("WO-FORK1-") and code not in orders + assert screen_chosen == ["UT-FORK"] and "UT-FORK" in materials + # The pack's own orders are two hours of the line; a shift is eight. + shift = orders["WO-FORK1-0001"]["quantity"] * 4 + assert abs(int(quantity) - shift) / shift < 0.05, (quantity, shift) + + +def test_the_order_is_created_planned_and_released_by_its_own_button(scene): + screen = steps_of(scene, "screen") + clicks = [step["selector"] for step in screen if step["do"] == "click"] + create = next(i for i, step in enumerate(screen) if step["do"] == "click" and step["selector"] == "#no-create") + release = next(i for i, step in enumerate(screen) if step["do"] == "click" and "Release" in step["selector"]) + + # The form's Release box is unticked before Create, so release is a press of its own. + assert clicks.index("#no-release") < clicks.index("#no-create") + assert "'planned'" in screen[create + 1]["js"] + assert screen[release + 1] == {**screen[release + 1], "selector": "#d-status", "text": "released"} + + +def test_the_released_order_is_found_in_the_queue_of_the_first_machine_on_its_routing(scene): + screen = steps_of(scene, "screen") + first = min(fork_routing()["operations"], key=lambda op: op["seq"])["equipment"] + code = typed(scene, "screen")[0] + station = next(i for i, step in enumerate(screen) if step["do"] == "goto" and "/station" in step["url"]) + + assert screen[station]["url"] == f"/dashboard/station?m={first}" + assert screen[station + 1]["selector"] == "#queue" and screen[station + 1]["text"] == code + + +def test_the_order_finished_is_the_packs_own_fork_order_and_the_floor_is_told_not_to_finish_it(scene): + order = next(o for o in pack("work_orders") if o["code"] == "WO-FORK1-0001") + (wanted,) = scene["plant"]["roll_when_order"] + + assert order["release"] and order["material"] == fork_routing()["material"] + assert wanted["code"] == order["code"] and 0 < wanted["booked"] < order["quantity"] + assert scene["plant"]["env"] == {"MES_OPS_FINISH_ORDERS": "false"} + + +def test_what_it_refuses_is_finishing_at_the_count_so_a_person_finishes_every_step_and_the_outbox_has_it(scene): + refuses = steps_of(scene, "refuses") + said = " ".join(step["line"] for step in refuses if step["do"] == "say") + finished = [step["selector"] for step in refuses if step["do"] == "click"] + + # It opens on the count past the ordered quantity with the order still open. + assert refuses[0]["do"] == "wait_for" and "#d-good" in refuses[0]["js"] and "#d-qty" in refuses[0]["js"] + assert "does not finish itself" in said and "A person closes it" in said + assert finished == [f'#ops tbody tr:has-text("{op["name"]}") button:has-text("Finish step")' + for op in sorted(fork_routing()["operations"], key=lambda op: op["seq"])] + waits = [step for step in refuses if step["do"] == "wait_for"] + assert {"selector": "#d-status", "text": "completed"}.items() <= waits[-2].items() + assert waits[-1]["selector"] == "#erp-table tbody" and waits[-1]["text"] == "WO-FORK1-0001" + + +def test_the_you_now_know_card_says_the_classs_own_outcomes_word_for_word(runner, scene): + course = runner.load_course(REPO / "scripts" / "course" / "course.toml") + _, lesson = runner.find_lesson(course, scene["lesson"]) + know = [step for step in steps_of(scene, "know") if step["do"] == "slide"] + + assert len(lesson["outcomes"]) == 3 + assert len(know) == 1 and know[0]["lines"] == lesson["outcomes"] + + +def test_every_page_it_visits_is_a_screen_the_app_serves(scene): + served = [page.path for module in modules.REGISTRY for page in module.pages] + patterns = [re.compile("^" + re.sub(r"\{[^}]+\}", "[^/]+", path) + "$") for path in served] + visited = {urlparse(step["url"]).path for step in scene["step"] if step["do"] == "goto"} + + unserved = sorted(path for path in visited if not any(p.match(path) for p in patterns)) + assert unserved == [], f"{len(unserved)} of {len(visited)} pages are not served: {unserved}" + + +def test_every_frame_carries_the_pre_alpha_simulated_plant_badge(scene): + assert scene["badge"] == "pre-alpha · simulated plant · v{version}" + + +def test_no_caption_card_note_or_typed_word_carries_a_date(scene): + dated = [line for line in everything_written(scene) if A_DATE.search(line)] + + assert dated == [], f"{len(dated)} lines carry a date: {dated}" + + +def test_it_is_filmed_on_a_scratch_cutlery_plant_on_loopback_and_never_on_one_somebody_else_runs(runner, scene): + base = urlparse(scene["base"]) + + assert scene["plant"]["pack"] == "labs/cutlery" + assert base.hostname == "127.0.0.1" + assert base.port not in NOT_OURS + # It writes, so it must be refused anywhere but loopback. + assert scene["allow_writes"] + runner.refuse_to_write_off_this_box(scene) + with pytest.raises(SystemExit): + runner.refuse_to_write_off_this_box(dict(scene, base="http://100.64.0.1:8040")) + + +def test_the_borrowed_order_the_floor_switch_the_outbox_and_the_replay_are_owned_up_to(scene): + honesty = " ".join(scene["honesty"]).lower() + + assert "wo-fork1-0001" in honesty + assert "mes_ops_finish_orders=false" in honesty + assert "newest twenty" in honesty + assert "first routing" in honesty + assert "ten times" in honesty + + +def test_no_screen_of_people_is_filmed_and_admin_is_not_opened(scene): + urls = [step["url"] for step in scene["step"] if step["do"] == "goto"] + + assert not [url for url in urls if "people" in url or "/admin" in url] + + +def test_the_recorder_plays_every_step_of_it(runner, scene): + handed: list[str] = [] + + class Stage: + def __getattr__(self, verb): + return lambda *args: handed.append(verb) + + runner.play(scene, Stage()) + + for verb in ("goto", "click", "fill", "choose"): + assert handed.count(verb) == sum(1 for step in scene["step"] if step["do"] == verb), verb + assert handed.count("scroll_to") == sum(1 for step in scene["step"] if step.get("scroll_to")) + assert handed.count("slide") == 3 and "terminal" not in handed From 89c3f71d99f32018a02d3541b0e8adc8b86a6704 Mon Sep 17 00:00:00 2001 From: scottkalw Date: Sat, 14 Nov 2026 21:31:16 -0600 Subject: [PATCH 4/8] Recorder: bring a button named by its words clear of the caption bar The move out from under the caption bar before a click looked the selector up with document.querySelector, which refuses Playwright's :has-text. Class 1.4's first take stopped on its Release button for that reason. It now finds the thing with Playwright's own locator, as the click does, and leaves a selector that matches nothing yet to the step. Co-Authored-By: Claude Opus 5.5 Signed-off-by: scottkalw --- scripts/record-scene.py | 16 +++-- ...d_by_its_words_clear_of_the_caption_bar.py | 69 +++++++++++++++++++ 2 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 tests/test_a_scene_brings_a_button_named_by_its_words_clear_of_the_caption_bar.py diff --git a/scripts/record-scene.py b/scripts/record-scene.py index 23854350..1301ae02 100644 --- a/scripts/record-scene.py +++ b/scripts/record-scene.py @@ -677,11 +677,17 @@ def clear_of_caption(self, selector: str) -> None: pressed. When the thing is under the bar, room is added once below the page's last row and the thing is put in the middle of the window. A thing already clear is left where it is, so no other take moves. + + The thing is found the way the click will find it, by Playwright's + own locator: a scene's selector may say `:has-text("Release")`, which + `document.querySelector` refuses as no selector at all (the first take + of class 1.4 stopped on its Release button for that reason). """ - self.page.evaluate( - """([selector, bar]) => { - const node = document.querySelector(selector); - if (!node) return; + found = self.page.locator(selector) + if not found.count(): + return + found.first.evaluate( + """(node, bar) => { const box = node.getBoundingClientRect(); if (box.bottom <= window.innerHeight - bar) return; if (!document.getElementById('fs-scene-room')) { @@ -692,7 +698,7 @@ def clear_of_caption(self, selector: str) -> None: } node.scrollIntoView({ block: 'center', behavior: 'instant' }); }""", - [selector, CAPTION_HEIGHT * 2], + CAPTION_HEIGHT * 2, ) def wait_for(self, step: dict, timeout: float) -> None: diff --git a/tests/test_a_scene_brings_a_button_named_by_its_words_clear_of_the_caption_bar.py b/tests/test_a_scene_brings_a_button_named_by_its_words_clear_of_the_caption_bar.py new file mode 100644 index 00000000..96334697 --- /dev/null +++ b/tests/test_a_scene_brings_a_button_named_by_its_words_clear_of_the_caption_bar.py @@ -0,0 +1,69 @@ +"""A button a scene names by its words is brought out from under the caption bar before it is pressed. + +Before a click, fill or choose the recorder moves the thing out from under +the caption bar (class 1.3's "Add operation"). Scenes name buttons by their +words, `#order-actions button:has-text("Release")`, which only Playwright's +own locator reads: the first take of class 1.4 stopped on its Release button +because the move looked the selector up with `document.querySelector`. This +drives the runner's own stage in Chromium against a page of that shape; no +plant is needed. +""" + +from __future__ import annotations + +import importlib.util +from pathlib import Path + +import pytest + +pytestmark = [pytest.mark.slow, pytest.mark.browser] + +REPO = Path(__file__).resolve().parents[1] +RUNNER = REPO / "scripts" / "record-scene.py" + +VIEWPORT = {"width": 800, "height": 600} +# The Release button at the very foot of a page too short to scroll it higher. +PAGE = ( + "
the order
" + "
" +) + + +@pytest.fixture(scope="module") +def runner(): + spec = importlib.util.spec_from_file_location("record_scene_clear_of_caption", RUNNER) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def test_a_button_named_with_has_text_at_the_foot_of_a_page_ends_up_above_the_caption_bar(runner, tmp_path): + from playwright.sync_api import sync_playwright + + with sync_playwright() as pw: + browser = pw.chromium.launch() + page = browser.new_page(viewport=VIEWPORT) + page.set_content(PAGE) + button = page.locator('#order-actions button:has-text("Release")') + clear = VIEWPORT["height"] - runner.CAPTION_HEIGHT * 2 + assert button.bounding_box()["y"] + button.bounding_box()["height"] > clear + + runner.BrowserStage(page, tmp_path, 0.0).clear_of_caption('#order-actions button:has-text("Release")') + + box = button.bounding_box() + assert box["y"] + box["height"] <= clear + browser.close() + + +def test_a_selector_that_matches_nothing_yet_is_left_for_the_step_itself_to_wait_on(runner, tmp_path): + from playwright.sync_api import sync_playwright + + with sync_playwright() as pw: + browser = pw.chromium.launch() + page = browser.new_page(viewport=VIEWPORT) + page.set_content(PAGE) + + runner.BrowserStage(page, tmp_path, 0.0).clear_of_caption('#order-actions button:has-text("Close")') + + assert page.evaluate("document.getElementById('fs-scene-room')") is None + browser.close() From d0f8306eb842003f054b524e5f5d27829f229f12 Mon Sep 17 00:00:00 2001 From: scottkalw Date: Sat, 14 Nov 2026 21:46:18 -0600 Subject: [PATCH 5/8] Class 1.4 scene: wait for the outbox row before scrolling to it; two more captions Co-Authored-By: Claude Opus 5.5 Signed-off-by: scottkalw --- .../scenes/course/02-04-a-work-orders-day.toml | 15 +++++++++++++++ ...der_and_a_person_not_its_count_finishes_one.py | 8 ++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/scripts/scenes/course/02-04-a-work-orders-day.toml b/scripts/scenes/course/02-04-a-work-orders-day.toml index 3f445366..d084fc45 100644 --- a/scripts/scenes/course/02-04-a-work-orders-day.toml +++ b/scripts/scenes/course/02-04-a-work-orders-day.toml @@ -235,6 +235,10 @@ line = "The station screen of the fork mould, FORK1_Mold. Its queue: the order i do = "say" line = "That is dispatch. The operator does not hunt for paper: the machine's screen says what is next." +[[step]] +do = "say" +line = "Each line of the queue says how many good of how many ordered. The next machine, the degating press, gets our order the same way." + [[step]] do = "mark" name = "in-the-moulds-queue" @@ -355,16 +359,27 @@ line = "Degate, then Mark. With its last step done, the order is completed, at t do = "mark" name = "finished-by-a-person" +[[step]] +do = "say" +line = "Look at the over-run beside the ordered number. It is every fork made past 2,778, still attached to the order that made them." + [[step]] do = "goto" url = "/dashboard/ops" settle = 1 +# A step scrolls before it waits, so the row is waited for first and scrolled +# to by a second wait that finds it already there. [[step]] do = "wait_for" selector = "#erp-table tbody" text = "WO-FORK1-0001" timeout = 15 + +[[step]] +do = "wait_for" +selector = "#erp-table tbody" +text = "WO-FORK1-0001" scroll_to = "#erp-table tr" scroll_text = "WO-FORK1-0001" scroll_offset = 300 diff --git a/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py b/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py index 166e0caa..88d6647d 100644 --- a/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py +++ b/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py @@ -193,8 +193,12 @@ def test_what_it_refuses_is_finishing_at_the_count_so_a_person_finishes_every_st assert finished == [f'#ops tbody tr:has-text("{op["name"]}") button:has-text("Finish step")' for op in sorted(fork_routing()["operations"], key=lambda op: op["seq"])] waits = [step for step in refuses if step["do"] == "wait_for"] - assert {"selector": "#d-status", "text": "completed"}.items() <= waits[-2].items() - assert waits[-1]["selector"] == "#erp-table tbody" and waits[-1]["text"] == "WO-FORK1-0001" + assert {"selector": "#d-status", "text": "completed"}.items() <= waits[-3].items() + # The outbox row is waited for, then scrolled to: a step scrolls before it waits. + assert [(w["selector"], w["text"], bool(w.get("scroll_to"))) for w in waits[-2:]] == [ + ("#erp-table tbody", "WO-FORK1-0001", False), + ("#erp-table tbody", "WO-FORK1-0001", True), + ] def test_the_you_now_know_card_says_the_classs_own_outcomes_word_for_word(runner, scene): From d04115d4ccdb463f97c9ad8d4a32a3acfaa901f4 Mon Sep 17 00:00:00 2001 From: scottkalw Date: Sat, 14 Nov 2026 22:02:01 -0600 Subject: [PATCH 6/8] Class 1.4 scene: open the outbox the moment the order completes Co-Authored-By: Claude Opus 5.5 Signed-off-by: scottkalw --- .../course/02-04-a-work-orders-day.toml | 47 ++++++++++++++----- ...and_a_person_not_its_count_finishes_one.py | 14 ++++-- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/scripts/scenes/course/02-04-a-work-orders-day.toml b/scripts/scenes/course/02-04-a-work-orders-day.toml index d084fc45..f44115a2 100644 --- a/scripts/scenes/course/02-04-a-work-orders-day.toml +++ b/scripts/scenes/course/02-04-a-work-orders-day.toml @@ -353,23 +353,22 @@ scroll_offset = 220 [[step]] do = "say" -line = "Degate, then Mark. With its last step done, the order is completed, at the count it really made." +line = "Degate, then Mark. Completed." [[step]] do = "mark" name = "finished-by-a-person" -[[step]] -do = "say" -line = "Look at the over-run beside the ordered number. It is every fork made past 2,778, still attached to the order that made them." - +# The outbox draws its newest twenty messages and the machines send about two +# state changes a second, so it is opened at once, before anything is said +# about the order: twenty seconds later the confirmation has scrolled off the +# panel (the third take). A step scrolls before it waits, so the row is waited +# for first and scrolled to by a second wait that finds it already there. [[step]] do = "goto" url = "/dashboard/ops" -settle = 1 +settle = 0.5 -# A step scrolls before it waits, so the row is waited for first and scrolled -# to by a second wait that finds it already there. [[step]] do = "wait_for" selector = "#erp-table tbody" @@ -384,18 +383,42 @@ scroll_to = "#erp-table tr" scroll_text = "WO-FORK1-0001" scroll_offset = 300 -[[step]] -do = "say" -line = "And the news goes up. In the outbox, a confirmation for the office, beside the machines' state changes: WO-FORK1-0001, waiting to be sent." - [[step]] do = "mark" name = "the-confirmation-in-the-outbox" +[[step]] +do = "say" +line = "And the news goes up. In the outbox, a confirmation for the office, among the machines' state changes: WO-FORK1-0001, waiting to be sent." + [[step]] do = "say" line = "It was written when a person finished the order, not when the count passed the number. So the office hears the number the line really made." +[[step]] +do = "goto" +url = "/dashboard/orders?q=WO-FORK1-0001" +settle = 2 + +[[step]] +do = "click" +selector = "#order-list tbody tr:has-text(\"WO-FORK1-0001\")" + +[[step]] +do = "wait_for" +js = "document.querySelector('#detail-code').innerText === 'WO-FORK1-0001' && document.querySelector('#d-status').innerText === 'completed'" +scroll_to = "#detail-panel" +scroll_block = "start" +scroll_offset = 220 + +[[step]] +do = "say" +line = "Back on the order: completed. The over-run beside the ordered number is every fork made past 2,778, still on the order that made them." + +[[step]] +do = "mark" +name = "completed-with-its-over-run" + # ------------------------------------------------------------ you now know [[step]] diff --git a/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py b/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py index 88d6647d..9f952342 100644 --- a/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py +++ b/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py @@ -185,20 +185,24 @@ def test_the_order_finished_is_the_packs_own_fork_order_and_the_floor_is_told_no def test_what_it_refuses_is_finishing_at_the_count_so_a_person_finishes_every_step_and_the_outbox_has_it(scene): refuses = steps_of(scene, "refuses") said = " ".join(step["line"] for step in refuses if step["do"] == "say") - finished = [step["selector"] for step in refuses if step["do"] == "click"] + finished = [step["selector"] for step in refuses if step["do"] == "click" and "Finish step" in step["selector"]] # It opens on the count past the ordered quantity with the order still open. assert refuses[0]["do"] == "wait_for" and "#d-good" in refuses[0]["js"] and "#d-qty" in refuses[0]["js"] assert "does not finish itself" in said and "A person closes it" in said assert finished == [f'#ops tbody tr:has-text("{op["name"]}") button:has-text("Finish step")' for op in sorted(fork_routing()["operations"], key=lambda op: op["seq"])] - waits = [step for step in refuses if step["do"] == "wait_for"] - assert {"selector": "#d-status", "text": "completed"}.items() <= waits[-3].items() - # The outbox row is waited for, then scrolled to: a step scrolls before it waits. - assert [(w["selector"], w["text"], bool(w.get("scroll_to"))) for w in waits[-2:]] == [ + # The outbox is opened right after the last step is finished, before the + # confirmation scrolls off its newest twenty; the row is waited for, then + # scrolled to, because a step scrolls before it waits. + outbox = next(i for i, step in enumerate(refuses) if step["do"] == "goto" and step["url"] == "/dashboard/ops") + assert finished[-1] in [step.get("selector") for step in refuses[outbox - 4 : outbox]] + assert [(w["selector"], w["text"], bool(w.get("scroll_to"))) for w in refuses[outbox + 1 : outbox + 3]] == [ ("#erp-table tbody", "WO-FORK1-0001", False), ("#erp-table tbody", "WO-FORK1-0001", True), ] + # And the order is seen completed afterwards, its over-run beside it. + assert any("'completed'" in step.get("js", "") for step in refuses[outbox:]) def test_the_you_now_know_card_says_the_classs_own_outcomes_word_for_word(runner, scene): From e362453802c798995f64056b6e42f1a707475337 Mon Sep 17 00:00:00 2001 From: scottkalw Date: Sat, 14 Nov 2026 22:20:23 -0600 Subject: [PATCH 7/8] Class 1.4 scene: one more hook caption, so the teaser runs near thirty seconds The teaser is cut from the hook; at two captions it came out 17.6 s. Co-Authored-By: Claude Opus 5.5 Signed-off-by: scottkalw --- scripts/scenes/course/02-04-a-work-orders-day.toml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/scenes/course/02-04-a-work-orders-day.toml b/scripts/scenes/course/02-04-a-work-orders-day.toml index f44115a2..e94ef3e9 100644 --- a/scripts/scenes/course/02-04-a-work-orders-day.toml +++ b/scripts/scenes/course/02-04-a-work-orders-day.toml @@ -78,7 +78,11 @@ line = "On a floor, a bin of work carries a card. It says what to make, how many [[step]] do = "say" -line = "Every station the bin passes reads the card. At the end, somebody signs it off. That card is a work order." +line = "Every station the bin passes reads the card, and writes down beside its own step how many good it made." + +[[step]] +do = "say" +line = "The card never counts itself done. At the end, somebody signs it off. That card is a work order." [[step]] do = "mark" From d054aa56ad7d5a3a4a3e60b6a735802939bd8db3 Mon Sep 17 00:00:00 2001 From: scottkalw Date: Sat, 14 Nov 2026 22:47:53 -0600 Subject: [PATCH 8/8] Class 1.4 tests: formatted Co-Authored-By: Claude Opus 5.5 Signed-off-by: scottkalw --- ...es_an_order_and_a_person_not_its_count_finishes_one.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py b/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py index 9f952342..ff5c763d 100644 --- a/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py +++ b/tests/test_class_1_4_releases_an_order_and_a_person_not_its_count_finishes_one.py @@ -80,8 +80,6 @@ def chosen(scene: dict, part: str) -> list[str]: return [step["value"] for step in scene["step"] if step["part"] == part and step["do"] == "choose"] - - def steps_of(scene: dict, part: str) -> list[dict]: return [step for step in scene["step"] if step["part"] == part] @@ -190,8 +188,10 @@ def test_what_it_refuses_is_finishing_at_the_count_so_a_person_finishes_every_st # It opens on the count past the ordered quantity with the order still open. assert refuses[0]["do"] == "wait_for" and "#d-good" in refuses[0]["js"] and "#d-qty" in refuses[0]["js"] assert "does not finish itself" in said and "A person closes it" in said - assert finished == [f'#ops tbody tr:has-text("{op["name"]}") button:has-text("Finish step")' - for op in sorted(fork_routing()["operations"], key=lambda op: op["seq"])] + assert finished == [ + f'#ops tbody tr:has-text("{op["name"]}") button:has-text("Finish step")' + for op in sorted(fork_routing()["operations"], key=lambda op: op["seq"]) + ] # The outbox is opened right after the last step is finished, before the # confirmation scrolls off its newest twenty; the row is waited for, then # scrolled to, because a step scrolls before it waits.