diff --git a/scripts/course/course.toml b/scripts/course/course.toml index 06781f85..81eb5192 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 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" [[module.lesson]] order = 2 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 new file mode 100644 index 00000000..161544a8 --- /dev/null +++ b/scripts/scenes/course/03-01-the-station-screen.toml @@ -0,0 +1,443 @@ +# 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. 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.", + "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 = "#queue" +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 = "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." + +[[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." + +[[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." + +[[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 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]] +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_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
" + "" +) +# 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() 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