From 74d9cbe05aa62dd6d2039eb176c24363134fafa1 Mon Sep 17 00:00:00 2001 From: scottkalw Date: Sat, 14 Nov 2026 20:53:20 -0600 Subject: [PATCH 01/12] 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 02/12] 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 03/12] 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 04/12] 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 05/12] 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 06/12] 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 07/12] 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 08/12] 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. From 9025420dda907977d45f42a9805722f0fc50c132 Mon Sep 17 00:00:00 2001 From: scottkalw Date: Sat, 14 Nov 2026 22:58:35 -0600 Subject: [PATCH 09/12] Course draft 2: class 2.1, the station screen, scene and tests Co-Authored-By: Claude Opus 5.5 Signed-off-by: scottkalw --- scripts/course/course.toml | 6 + .../course/03-01-the-station-screen.toml | 437 ++++++++++++++++++ ...ion_screen_and_books_only_released_work.py | 287 ++++++++++++ 3 files changed, 730 insertions(+) create mode 100644 scripts/scenes/course/03-01-the-station-screen.toml create mode 100644 tests/test_class_2_1_reads_one_machine_on_its_station_screen_and_books_only_released_work.py diff --git a/scripts/course/course.toml b/scripts/course/course.toml index 06781f85..c8eb1b19 100644 --- a/scripts/course/course.toml +++ b/scripts/course/course.toml @@ -138,6 +138,12 @@ label = "2.1" slug = "the-station-screen" title = "The station screen — one machine at arm's length" one_line = "State, queue, booking output, issuing material, a quality check, what maintenance is owed." +outcomes = [ + "Read one machine on its station screen: its state, its queue of released work, and what maintenance is owed.", + "Book good and scrap against the order at the head of the queue, issue a lot to it, and record a quality reading against its specification.", + "Say why only released work can be booked at a station, and why a typed count is the operator's word and not the counter's.", +] +scene = "scripts/scenes/course/03-01-the-station-screen.toml" [[module.lesson]] order = 2 diff --git a/scripts/scenes/course/03-01-the-station-screen.toml b/scripts/scenes/course/03-01-the-station-screen.toml new file mode 100644 index 00000000..cb4ae06d --- /dev/null +++ b/scripts/scenes/course/03-01-the-station-screen.toml @@ -0,0 +1,437 @@ +# Class 2.1 of the course, *The station screen — one machine at arm's length*: +# what an operator standing at one machine reads and does on its screen. +# +# It starts from the operator at the press with a tablet (a card of words, no +# drawing), names the four words of the class (station, book, issue, queue), +# and reads the station screen of the fork mould, FORK1_Mold, top to bottom, +# one action per card: its state, its queue, 500 good and 3 scrap booked +# against the order at the head of the queue, two kilos of the line's resin lot +# issued to it, one length reading recorded and judged in spec, and what +# maintenance is owed. Then what it refuses: an order that is planned, not +# released, is not on the screen to book against; and what it does not refuse: +# a Good figure the machine's own counter contradicts is taken as typed. +# Filmed on a scratch cutlery plant, every screen as the product draws it. + +name = "the-station-screen" +title = "The station screen — one machine at arm's length" +lesson = "2.1" +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 +# Booking, issuing and recording a reading are writes, and they are the story. +allow_writes = true +what_is_written = "which is how the class books output, issues material and records a quality reading: Book, Issue and Record are real `POST`s to the take's own scratch plant, made with the station screen'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, had booked its first forks, so that the mould's queue has a running order with a count on it when the class arrives.", + "The simulated floor was told `MES_OPS_FINISH_ORDERS=false`, so its simulated supervisor neither finishes WO-FORK1-0001 nor releases the next fork order, WO-FORK1-0002, while the camera rolls: the class needs WO-FORK1-0002 to stay planned for its refusal. The switch belongs to the simulated floor; the MES is configured as anybody installs it.", + "The lot issued is LOT-PP-FORK1-001, the pack's polypropylene lot for the fork line. Two kilos is about what 500 forks weigh: the pack's fork weighs 3.6 to 4.2 grams.", + "The reading recorded is 165.1 mm on length_mm, inside the pack's UT-FORK limits of 164 to 166 mm. It is the first reading on this scratch plant, so no control chart rule can fire on it.", + "The cutlery pack carries no maintenance plan, so the maintenance card says nothing is owed. That is the product's answer for this plant, filmed as drawn.", + "The second booking, 5,000 good, is typed to show that the station does not check a typed figure against the mould's own counter. It is a write to a scratch plant that is thrown away when the take ends.", + "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 machine, a tablet or a person.", +] + +honesty = [ + "the mould's counter books every shot by itself on this plant; the 500 good and 3 scrap typed in the class are added on top of what it counted, not instead of it", + "the station does not refuse a Good figure the machine's own counter contradicts: 5,000 typed against a mould whose whole count, counter and typed, was short of 5,000 is taken as typed, and nothing on the screen says the two disagree; the class shows that rather than a refusal the product does not make", + "the refusal to book against an order not released to this machine is drawn as an absence: the Against list holds only the machine's own released queue, so the planned order WO-FORK1-0002 is not offered; the class does not call the API behind the screen, which books to any order named with an explicit step, on whatever machine that step is", + "the simulated floor was told not to finish or release orders itself (MES_OPS_FINISH_ORDERS=false), so WO-FORK1-0002 stays planned while the camera rolls; on a plant left to itself the simulated supervisor would release it when WO-FORK1-0001 is done", + "the Lot list at the station offers every available lot on the plant, paper plates among them, not only the resin this machine takes; the class picks the fork line's resin lot from it", + "the maintenance card is empty because the cutlery pack has no maintenance plan, not because the machine was just serviced", + "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 = 900 + +# A running order with a count on it at the head of the mould's queue. +[[plant.roll_when_order]] +code = "WO-FORK1-0001" +booked = 100 + +# ----------------------------------------------------------------- the hook + +[[step]] +do = "slide" +name = "the-operator-at-the-press" +title = "An operator at the press, a tablet in hand" +lines = [ + "One machine: the fork mould", + "What is it doing? What is next?", + "What did I make? What did I put in?", + "Is it good? What is owed to it?", +] +hold = 1.5 + +[[step]] +do = "say" +line = "An operator stands at one press for a whole shift, a tablet in hand. Not the plant, not the line: this one machine." + +[[step]] +do = "say" +line = "Through the shift they ask the same few things. What is it doing, and what is next for it?" + +[[step]] +do = "say" +line = "What did I make, what did I put in, is it good, and is anything owed to the machine? One screen answers all of them." + +[[step]] +do = "mark" +name = "the-operator-at-the-press" + +# ----------------------------------------------------------------- the idea + +[[step]] +part = "idea" +do = "slide" +name = "four-words" +title = "Four words" +lines = [ + "Station: one machine's screen, for the person standing at it", + "Queue: the released work this machine has next, in order", + "Book: write down how many good and how many scrap, against an order", + "Issue: write down which lot of material went into that order", +] +hold = 1.5 + +[[step]] +do = "say" +line = "Four words. A station is one machine's screen, made for the person standing at it, not for the office." + +[[step]] +do = "say" +line = "The queue is the work released to this machine, in the order it should run. Only released work is in it." + +[[step]] +do = "say" +line = "To book is to write down how many good and how many scrap, always against an order and its step." + +[[step]] +do = "say" +line = "To issue is to write down which lot of material went into that order, so it can be traced later." + +[[step]] +do = "mark" +name = "four-words" + +# ------------------------------------------------------------ on the screen + +[[step]] +part = "screen" +do = "goto" +url = "/dashboard/station?m=FORK1_Mold" +settle = 3 + +[[step]] +do = "wait_for" +selector = "#queue" +text = "WO-FORK1-0001" + +[[step]] +do = "say" +line = "The station screen of the fork mould, FORK1_Mold. The machine is chosen at the top; the operator starts the shift here." + +[[step]] +do = "say" +line = "First card, its state: running, and since when. Going down asks why, which is the next class." + +[[step]] +do = "mark" +name = "its-state" + +[[step]] +do = "say" +line = "Second card, its queue: the order it is running, WO-FORK1-0001, step 10, Mold, and how many good of how many ordered." + +[[step]] +do = "say" +line = "That count moves by itself: the mould's own counter books every shot it makes." + +[[step]] +do = "mark" +name = "its-queue" + +[[step]] +do = "wait_for" +selector = "#book-order" +text = "WO-FORK1-0001" +scroll_to = "#book" +scroll_block = "start" +scroll_offset = 300 + +[[step]] +do = "say" +line = "Third card, book output. Against: the order at the head of the queue, step 10. The operator counts a box." + +[[step]] +do = "choose" +selector = "#book-order" +value = "WO-FORK1-0001" + +[[step]] +do = "fill" +selector = "#book-good" +text = "500" + +[[step]] +do = "fill" +selector = "#book-scrap" +text = "3" + +[[step]] +do = "say" +line = "Five hundred good, three scrap. Book." + +[[step]] +do = "click" +selector = "#book-submit" + +[[step]] +do = "wait_for" +selector = "#toast" +text = "Booked 500 good, 3 scrap." + +[[step]] +do = "say" +line = "Booked, against WO-FORK1-0001 step 10, under the name of the person signed in. The queue's count is up by five hundred." + +[[step]] +do = "mark" +name = "booked-500-good-3-scrap" + +[[step]] +do = "say" +line = "Fourth card, issue material. It issues to the order running here, WO-FORK1-0001." + +[[step]] +do = "choose" +selector = "#issue-lot" +value = "LOT-PP-FORK1-001" + +[[step]] +do = "fill" +selector = "#issue-qty" +text = "2" + +[[step]] +do = "say" +line = "The lot is the fork line's polypropylene resin, LOT-PP-FORK1-001. Two kilos: about what five hundred forks weigh. Issue." + +[[step]] +do = "click" +selector = "#issue-submit" + +[[step]] +do = "wait_for" +js = "[...document.querySelectorAll('#issue-lot option')].some(o => o.value === 'LOT-PP-FORK1-001' && o.textContent.includes('4,485.5'))" + +[[step]] +do = "say" +line = "Issued. The lot is two kilos lighter, and the order now says which resin went into it." + +[[step]] +do = "mark" +name = "issued-two-kilos-of-resin" + +[[step]] +do = "wait_for" +selector = "#q-spec" +text = "Spec 164 to 166 mm." +scroll_to = "#quality" +scroll_block = "start" +scroll_offset = 300 + +[[step]] +do = "say" +line = "Fifth card, quality, on what this machine is running: forks, UT-FORK. Only characteristics with a specification are offered." + +[[step]] +do = "choose" +selector = "#q-char" +value = "length_mm" + +[[step]] +do = "say" +line = "Length: the specification is 164 to 166 millimetres. The operator puts a fork on the gauge." + +[[step]] +do = "fill" +selector = "#q-value" +text = "165.1" + +[[step]] +do = "click" +selector = "#q-submit" + +[[step]] +do = "wait_for" +js = "(document.querySelector('#q-recent').innerText || '').includes('165.1') && (document.querySelector('#q-recent').innerText || '').includes('in spec')" + +[[step]] +do = "say" +line = "165.1 millimetres: in spec. It is in the recent results, with the time and who measured it." + +[[step]] +do = "mark" +name = "a-reading-in-spec" + +[[step]] +do = "wait_for" +selector = "#maint" +text = "Nothing owed on this machine." +scroll_to = "#maint" +scroll_block = "start" +scroll_offset = 320 + +[[step]] +do = "say" +line = "Last card, maintenance on this machine. Here, nothing is owed: this plant has no maintenance plan set up." + +[[step]] +do = "say" +line = "Where a plan is set up, the jobs due on this machine are listed here, and the operator can start and complete them." + +[[step]] +do = "mark" +name = "what-maintenance-is-owed" + +# -------------------------------------------------------------- it refuses + +[[step]] +part = "refuses" +do = "goto" +url = "/dashboard/orders?q=WO-FORK1-0002" +settle = 2 + +[[step]] +do = "click" +selector = "#order-list tbody tr:has-text(\"WO-FORK1-0002\")" + +[[step]] +do = "wait_for" +js = "document.querySelector('#detail-code').innerText === 'WO-FORK1-0002' && document.querySelector('#d-status').innerText === 'planned'" +scroll_to = "#detail-panel" +scroll_block = "start" +scroll_offset = 220 + +[[step]] +do = "say" +line = "Now what it refuses. This is the next fork order, WO-FORK1-0002. Its first step is on the same mould, but it is only planned." +hold = 1.0 + +[[step]] +do = "mark" +name = "the-next-order-is-planned" + +[[step]] +do = "goto" +url = "/dashboard/station?m=FORK1_Mold" +settle = 3 + +[[step]] +do = "wait_for" +js = "[...document.querySelectorAll('#book-order option')].map(o => o.value).join() === 'WO-FORK1-0001'" +scroll_to = "#book" +scroll_block = "start" +scroll_offset = 300 + +[[step]] +do = "say" +line = "Back at the mould, the Against list holds one order: WO-FORK1-0001. The planned order is not there to book against." + +[[step]] +do = "say" +line = "Nor is any order of another line. An operator can only book to work released to this machine." + +[[step]] +do = "mark" +name = "only-released-work-to-book-against" + +# The claim the next caption makes, checked on the take: the mould's count, +# its counter's shots and the 500 typed, is still short of what is typed next. +[[step]] +do = "wait_for" +js = "Number(((document.querySelector('#queue').innerText.match(/Mold\\D+([0-9,]+) of/) || [])[1] || 'NaN').replace(/,/g, '')) < 5000" + +[[step]] +do = "say" +line = "And what it does not refuse. Type five thousand good: more forks than this mould has made since the plant started." + +[[step]] +do = "fill" +selector = "#book-good" +text = "5000" + +[[step]] +do = "click" +selector = "#book-submit" + +[[step]] +do = "wait_for" +selector = "#toast" +text = "Booked 5,000 good, 0 scrap." + +[[step]] +do = "say" +line = "Booked. The station took the figure as typed. Nothing on the screen says the counter disagrees." +hold = 1.0 + +[[step]] +do = "mark" +name = "a-figure-the-counter-contradicts-is-taken" + +[[step]] +do = "wait_for" +selector = "#queue" +text = "WO-FORK1-0001" +scroll_to = "#queue" +scroll_block = "start" +scroll_offset = 300 + +[[step]] +do = "say" +line = "The queue now says the mould has made thousands more than its counter saw. A typed booking is added to the count; it is not checked against it." + +[[step]] +do = "say" +line = "So a typed figure is the operator's word. The audit trail says who typed it, and the counter's own shots stay counted beside it." + +[[step]] +do = "mark" +name = "the-queue-takes-the-typed-figure" + +# ------------------------------------------------------------ you now know + +[[step]] +part = "know" +do = "slide" +name = "you-now-know" +title = "You now know how to" +lines = [ + "Read one machine on its station screen: its state, its queue of released work, and what maintenance is owed.", + "Book good and scrap against the order at the head of the queue, issue a lot to it, and record a quality reading against its specification.", + "Say why only released work can be booked at a station, and why a typed count is the operator's word and not the counter's.", +] + +[[step]] +do = "say" +line = "That is the station screen: one machine, read top to bottom, and the work done at it written down. 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_2_1_reads_one_machine_on_its_station_screen_and_books_only_released_work.py b/tests/test_class_2_1_reads_one_machine_on_its_station_screen_and_books_only_released_work.py new file mode 100644 index 00000000..22ae62af --- /dev/null +++ b/tests/test_class_2_1_reads_one_machine_on_its_station_screen_and_books_only_released_work.py @@ -0,0 +1,287 @@ +"""Class 2.1 reads one machine on its station screen and books only released work, on a scratch cutlery plant. + +*The station screen — one machine at arm's length* is the first class of the +floor: the operator at the press (a card of words), the four words of the +class (station, queue, book, issue), and the fork mould's station screen read +card by card - its state, its queue, 500 good and 3 scrap booked against the +order at the head of the queue, a lot of the line's resin issued to it, one +length reading recorded in spec, and what maintenance is owed. Then what it +refuses (a planned order is not offered to book against) and what it does +not (a Good figure the machine's counter contradicts is taken as typed, and +the scene says so rather than inventing a refusal). 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 parse_qs, urlparse + +import pytest + +from fsmes import modules + +REPO = Path(__file__).resolve().parents[1] +RUNNER = REPO / "scripts" / "record-scene.py" +SCENE = REPO / "scripts" / "scenes" / "course" / "03-01-the-station-screen.toml" +PACK = REPO / "labs" / "cutlery" / "masterdata" +MACHINE = "FORK1_Mold" + +# 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_2_1", 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 steps_of(scene: dict, part: str) -> list[dict]: + return [step for step in scene["step"] if step["part"] == part] + + +def typed_into(scene: dict, part: str, selector: str) -> list[str]: + return [step["text"] for step in steps_of(scene, part) if step["do"] == "fill" and step["selector"] == selector] + + +def chosen_in(scene: dict, part: str, selector: str) -> list[str]: + return [step["value"] for step in steps_of(scene, part) if step["do"] == "choose" and step["selector"] == selector] + + +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_2_1_named_by_its_label_that_runs_four_to_six_minutes(runner, scene): + assert scene["lesson"] == "2.1" 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_station_screen_folder_of_the_floor(runner, scene): + course = runner.load_course(REPO / "scripts" / "course" / "course.toml") + _, lesson = runner.find_lesson(course, scene["lesson"]) + + assert lesson["path"] == "03-the-floor/01-the-station-screen" + 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_words_about_one_machine_short_enough_for_the_teaser(runner, scene): + hook = steps_of(scene, "hook") + + assert hook[0]["do"] == "slide" and hook[0]["name"] == "the-operator-at-the-press" + assert not [step for step in hook if step["do"] in ("goto", "click", "fill", "choose")] + assert runner.planned_seconds(dict(scene, step=hook)) - scene["gif_skip_seconds"] <= 30 + + +def test_the_idea_card_names_station_queue_book_and_issue(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"]] == ["Station", "Queue", "Book", "Issue"] + + +def test_the_screen_is_the_fork_moulds_station_and_its_machine_is_the_first_step_of_the_fork_line(scene): + first = min(fork_routing()["operations"], key=lambda op: op["seq"])["equipment"] + stations = [urlparse(step["url"]) for step in scene["step"] if step["do"] == "goto" and "/station" in step["url"]] + + assert first == MACHINE + assert stations and all(parse_qs(url.query)["m"] == [MACHINE] for url in stations) + + +def test_it_reads_the_cards_top_to_bottom_state_queue_book_issue_quality_maintenance(scene): + marks = [step["name"] for step in steps_of(scene, "screen") if step["do"] == "mark"] + + assert marks == [ + "its-state", + "its-queue", + "booked-500-good-3-scrap", + "issued-two-kilos-of-resin", + "a-reading-in-spec", + "what-maintenance-is-owed", + ] + + +def test_it_books_500_good_and_3_scrap_against_the_released_order_at_the_head_of_the_queue(scene): + order = next(o for o in pack("work_orders") if o["code"] == "WO-FORK1-0001") + + assert order["release"] and order["line"] == "FORK1LINE" + assert chosen_in(scene, "screen", "#book-order") == [order["code"]] + assert typed_into(scene, "screen", "#book-good") == ["500"] + assert typed_into(scene, "screen", "#book-scrap") == ["3"] + assert scene["plant"]["roll_when_order"] == [{**scene["plant"]["roll_when_order"][0], "code": order["code"]}] + + +def test_the_lot_issued_is_the_fork_lines_resin_and_about_what_500_forks_weigh(scene): + (lot,) = chosen_in(scene, "screen", "#issue-lot") + (kilos,) = typed_into(scene, "screen", "#issue-qty") + lots = {entry["code"]: entry for entry in pack("lots")} + order = next(o for o in pack("work_orders") if o["code"] == "WO-FORK1-0001") + weight = next(s for s in pack("quality_specs") if s["material"] == "UT-FORK" and s["characteristic"] == "weight_g") + + assert lot in lots and lots[lot]["material"] == "RAW-PP" and lot == order["issue"]["lot"] + assert 500 * weight["min"] / 1000 <= float(kilos) <= 500 * weight["max"] / 1000 + # What the take waits for after Issue is that lot, lighter by what was typed. + left = lots[lot]["quantity"] - order["issue"]["quantity"] - float(kilos) + assert any(f"{left:,.1f}" in step.get("js", "") for step in steps_of(scene, "screen")) + + +def test_the_reading_recorded_is_inside_the_packs_length_limits_for_forks(scene): + (characteristic,) = chosen_in(scene, "screen", "#q-char") + (value,) = typed_into(scene, "screen", "#q-value") + spec = next( + s for s in pack("quality_specs") if s["material"] == "UT-FORK" and s["characteristic"] == characteristic + ) + + assert spec["min"] < float(value) < spec["max"] + assert any(f"Spec {spec['min']:g} to {spec['max']:g} mm." == step.get("text") for step in scene["step"]) + + +def test_what_it_refuses_is_a_planned_order_which_the_against_list_does_not_offer(scene): + refuses = steps_of(scene, "refuses") + planned = next(o for o in pack("work_orders") if o["code"] == "WO-FORK1-0002") + said = " ".join(step["line"] for step in refuses if step["do"] == "say") + + assert not planned["release"] and planned["line"] == "FORK1LINE" + assert "'planned'" in next(step["js"] for step in refuses if "WO-FORK1-0002" in step.get("js", "")) + # Back at the mould, the list is checked to hold the released order alone. + assert any("#book-order option" in step.get("js", "") for step in refuses) + assert "not there to book against" in said + # The floor is told not to release it while the camera rolls. + assert scene["plant"]["env"] == {"MES_OPS_FINISH_ORDERS": "false"} + + +def test_a_figure_the_counter_contradicts_is_filmed_as_taken_and_owned_up_to_not_refused(scene): + refuses = steps_of(scene, "refuses") + (typed,) = typed_into(scene, "refuses", "#book-good") + honesty = " ".join(scene["honesty"]) + said = " ".join(step["line"] for step in refuses if step["do"] == "say") + + # The take checks the mould's count is short of the figure before typing it. + fill = next(i for i, step in enumerate(refuses) if step["do"] == "fill") + assert any(f"< {typed}" in step.get("js", "") for step in refuses[:fill]) + assert "took the figure as typed" in said + assert "does not refuse a Good figure the machine's own counter contradicts" in honesty + + +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_counter_the_absent_order_the_floor_switch_the_lot_list_and_the_replay_are_owned_up_to(scene): + honesty = " ".join(scene["honesty"]).lower() + + assert "added on top" in honesty + assert "wo-fork1-0002" in honesty + assert "mes_ops_finish_orders=false" in honesty + assert "paper plates" in honesty + assert "no maintenance plan" 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 5581b98c8f87e136ae0584b5a5f570b6ae81160f Mon Sep 17 00:00:00 2001 From: scottkalw Date: Sat, 14 Nov 2026 23:04:33 -0600 Subject: [PATCH 10/12] Class 2.1 scene: outcomes that fit the card, captions held for their words Co-Authored-By: Claude Opus 5.5 Signed-off-by: scottkalw --- scripts/course/course.toml | 4 ++-- scripts/scenes/course/03-01-the-station-screen.toml | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/scripts/course/course.toml b/scripts/course/course.toml index c8eb1b19..81eb5192 100644 --- a/scripts/course/course.toml +++ b/scripts/course/course.toml @@ -140,8 +140,8 @@ title = "The station screen — one machine at arm's length" one_line = "State, queue, booking output, issuing material, a quality check, what maintenance is owed." outcomes = [ "Read one machine on its station screen: its state, its queue of released work, and what maintenance is owed.", - "Book good and scrap against the order at the head of the queue, issue a lot to it, and record a quality reading against its specification.", - "Say why only released work can be booked at a station, and why a typed count is the operator's word and not the counter's.", + "Book good and scrap against the order at the head of its queue, issue a lot, and record a quality reading.", + "Say why only released work can be booked at a station, and why a typed count is the operator's word.", ] scene = "scripts/scenes/course/03-01-the-station-screen.toml" diff --git a/scripts/scenes/course/03-01-the-station-screen.toml b/scripts/scenes/course/03-01-the-station-screen.toml index cb4ae06d..969689dd 100644 --- a/scripts/scenes/course/03-01-the-station-screen.toml +++ b/scripts/scenes/course/03-01-the-station-screen.toml @@ -328,7 +328,6 @@ scroll_offset = 220 [[step]] do = "say" line = "Now what it refuses. This is the next fork order, WO-FORK1-0002. Its first step is on the same mould, but it is only planned." -hold = 1.0 [[step]] do = "mark" @@ -385,7 +384,6 @@ text = "Booked 5,000 good, 0 scrap." [[step]] do = "say" line = "Booked. The station took the figure as typed. Nothing on the screen says the counter disagrees." -hold = 1.0 [[step]] do = "mark" @@ -420,8 +418,8 @@ name = "you-now-know" title = "You now know how to" lines = [ "Read one machine on its station screen: its state, its queue of released work, and what maintenance is owed.", - "Book good and scrap against the order at the head of the queue, issue a lot to it, and record a quality reading against its specification.", - "Say why only released work can be booked at a station, and why a typed count is the operator's word and not the counter's.", + "Book good and scrap against the order at the head of its queue, issue a lot, and record a quality reading.", + "Say why only released work can be booked at a station, and why a typed count is the operator's word.", ] [[step]] From 89684342e720e42ca4244344eb81f02878e62b5f Mon Sep 17 00:00:00 2001 From: scottkalw Date: Sat, 14 Nov 2026 23:13:50 -0600 Subject: [PATCH 11/12] Recorder lifts a row at the foot of a short page clear of the caption bar A scroll_to at the foot of a short page could not reach its offset, and take 2 of class 2.1 left "Nothing owed on this machine" under the caption bar. The recorder now adds room below the page, as clear_of_caption does, and lifts the row clear, never above the offset the scene asked for. Class 2.1's book beat scrolls to the queue so the count it names is in frame, and a note that called 165.1 the plant's first reading is corrected: the simulated floor records readings too. Co-Authored-By: Claude Opus 5.5 Signed-off-by: scottkalw --- scripts/record-scene.py | 23 ++++++ .../course/03-01-the-station-screen.toml | 4 +- ..._lifts_the_row_clear_of_the_caption_bar.py | 74 +++++++++++++++++++ 3 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 tests/test_a_scene_scrolled_to_the_foot_of_a_short_page_lifts_the_row_clear_of_the_caption_bar.py diff --git a/scripts/record-scene.py b/scripts/record-scene.py index 1301ae02..e9e6b1bb 100644 --- a/scripts/record-scene.py +++ b/scripts/record-scene.py @@ -809,6 +809,29 @@ def scroll_to(self, selector: str, block: str, offset: int, text: str | None = N }""", [selector, block, offset, text], ) + # A row at the very foot of a short page cannot reach its offset, and + # can be left under the caption bar: the station screen's "Nothing owed + # on this machine" in the second take of class 2.1. Room is added below + # the page, as `clear_of_caption` adds it, and the row is lifted clear, + # but never higher than the offset the scene asked for, so a row that + # reached its offset, or a panel taller than the window, stays put. + self.page.evaluate( + """([selector, offset, text, bar]) => { + const nodes = [...document.querySelectorAll(selector)]; + const node = text ? nodes.find((n) => (n.innerText || '').includes(text)) : nodes[0]; + const box = node.getBoundingClientRect(); + const lift = Math.min(box.bottom - (window.innerHeight - bar), box.top - offset); + if (lift <= 0) return; + if (!document.getElementById('fs-scene-room')) { + const room = document.createElement('div'); + room.id = 'fs-scene-room'; + room.style.height = (2 * bar) + 'px'; + document.body.appendChild(room); + } + window.scrollBy(0, lift); + }""", + [selector, offset, text, CAPTION_HEIGHT * 2], + ) self.page.wait_for_timeout(int(SCROLL_SECONDS * 1000)) to_y = self.page.evaluate("() => Math.round(window.scrollY)") # Page pixels, the window's scroll: a box that scrolls inside the page diff --git a/scripts/scenes/course/03-01-the-station-screen.toml b/scripts/scenes/course/03-01-the-station-screen.toml index 969689dd..61bd50d7 100644 --- a/scripts/scenes/course/03-01-the-station-screen.toml +++ b/scripts/scenes/course/03-01-the-station-screen.toml @@ -32,7 +32,7 @@ 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, had booked its first forks, so that the mould's queue has a running order with a count on it when the class arrives.", "The simulated floor was told `MES_OPS_FINISH_ORDERS=false`, so its simulated supervisor neither finishes WO-FORK1-0001 nor releases the next fork order, WO-FORK1-0002, while the camera rolls: the class needs WO-FORK1-0002 to stay planned for its refusal. The switch belongs to the simulated floor; the MES is configured as anybody installs it.", "The lot issued is LOT-PP-FORK1-001, the pack's polypropylene lot for the fork line. Two kilos is about what 500 forks weigh: the pack's fork weighs 3.6 to 4.2 grams.", - "The reading recorded is 165.1 mm on length_mm, inside the pack's UT-FORK limits of 164 to 166 mm. It is the first reading on this scratch plant, so no control chart rule can fire on it.", + "The reading recorded is 165.1 mm on length_mm, inside the pack's UT-FORK limits of 164 to 166 mm. The simulated floor records length readings too, so the recent results show its readings beside ADMIN's.", "The cutlery pack carries no maintenance plan, so the maintenance card says nothing is owed. That is the product's answer for this plant, filmed as drawn.", "The second booking, 5,000 good, is typed to show that the station does not check a typed figure against the mould's own counter. It is a write to a scratch plant that is thrown away when the take ends.", "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.", @@ -166,7 +166,7 @@ name = "its-queue" do = "wait_for" selector = "#book-order" text = "WO-FORK1-0001" -scroll_to = "#book" +scroll_to = "#queue" scroll_block = "start" scroll_offset = 300 diff --git a/tests/test_a_scene_scrolled_to_the_foot_of_a_short_page_lifts_the_row_clear_of_the_caption_bar.py b/tests/test_a_scene_scrolled_to_the_foot_of_a_short_page_lifts_the_row_clear_of_the_caption_bar.py new file mode 100644 index 00000000..0d734dce --- /dev/null +++ b/tests/test_a_scene_scrolled_to_the_foot_of_a_short_page_lifts_the_row_clear_of_the_caption_bar.py @@ -0,0 +1,74 @@ +"""A row a scene scrolls to at the foot of a short page is lifted clear of the caption bar, and no higher than asked. + +A `scroll_to` puts its row `offset` pixels from the top of the window, as near +as the page can. At the foot of a short page it cannot, and the second take of +class 2.1 left the station screen's "Nothing owed on this machine" under the +caption bar for that reason. The recorder now adds room below the page and +lifts the row clear, but only as far as the offset the scene asked for, so a +row that reached its offset, or a panel taller than the window, is where it +always was. This drives the runner's own stage in Chromium; 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} +# A maintenance list that is the last thing on a page a little taller than the window. +SHORT = ( + "
the cards above
" + "
  • Nothing owed on this machine.
" +) +# A panel taller than the window, with plenty of page below it. +TALL = ( + "
above
" + "
the order
" +) + + +@pytest.fixture(scope="module") +def runner(): + spec = importlib.util.spec_from_file_location("record_scene_scroll_room", RUNNER) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def test_the_last_row_of_a_short_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(SHORT) + clear = VIEWPORT["height"] - runner.CAPTION_HEIGHT * 2 + + runner.BrowserStage(page, tmp_path, 0.0).scroll_to("#maint", "start", 320) + + box = page.locator("#maint").bounding_box() + assert box["y"] + box["height"] <= clear, box + assert box["y"] >= 320 - 1, box + browser.close() + + +def test_a_panel_taller_than_the_window_stays_at_the_offset_it_was_scrolled_to(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(TALL) + + runner.BrowserStage(page, tmp_path, 0.0).scroll_to("#detail-panel", "start", 220) + + assert round(page.locator("#detail-panel").bounding_box()["y"]) == 220 + assert page.evaluate("document.getElementById('fs-scene-room')") is None + browser.close() From 65416119f82649556169d31e0f63348af3c07271 Mon Sep 17 00:00:00 2001 From: scottkalw Date: Sat, 14 Nov 2026 23:20:44 -0600 Subject: [PATCH 12/12] Class 2.1: back to the queue after the booking, so the count it names is in frame Clicking Book centres the button clear of the caption bar, which took the queue out of frame in take 3 while the caption said its count rose. Co-Authored-By: Claude Opus 5.5 Signed-off-by: scottkalw --- scripts/scenes/course/03-01-the-station-screen.toml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/scenes/course/03-01-the-station-screen.toml b/scripts/scenes/course/03-01-the-station-screen.toml index 61bd50d7..161544a8 100644 --- a/scripts/scenes/course/03-01-the-station-screen.toml +++ b/scripts/scenes/course/03-01-the-station-screen.toml @@ -202,6 +202,14 @@ do = "wait_for" selector = "#toast" text = "Booked 500 good, 3 scrap." +[[step]] +do = "wait_for" +selector = "#queue" +text = "WO-FORK1-0001" +scroll_to = "#queue" +scroll_block = "start" +scroll_offset = 300 + [[step]] do = "say" line = "Booked, against WO-FORK1-0001 step 10, under the name of the person signed in. The queue's count is up by five hundred."