modulearn 0.3.0__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. {modulearn-0.3.0 → modulearn-0.4.0}/.github/workflows/ci.yml +3 -0
  2. {modulearn-0.3.0 → modulearn-0.4.0}/.gitignore +1 -0
  3. {modulearn-0.3.0 → modulearn-0.4.0}/CHANGELOG.md +9 -0
  4. {modulearn-0.3.0 → modulearn-0.4.0}/PKG-INFO +3 -1
  5. modulearn-0.4.0/docs/canvas-engine-guide.html +328 -0
  6. modulearn-0.4.0/docs/hyperparameter-sweep-guide.html +269 -0
  7. modulearn-0.4.0/docs/run-comparison-guide.html +217 -0
  8. modulearn-0.4.0/docs/stop-rerun-guide.html +257 -0
  9. {modulearn-0.3.0 → modulearn-0.4.0}/examples/quickstart.py +2 -0
  10. {modulearn-0.3.0 → modulearn-0.4.0}/examples/regression.py +2 -0
  11. {modulearn-0.3.0 → modulearn-0.4.0}/modulearn/__init__.py +1 -1
  12. {modulearn-0.3.0 → modulearn-0.4.0}/modulearn/cli.py +2 -0
  13. {modulearn-0.3.0 → modulearn-0.4.0}/modulearn/demo.py +4 -0
  14. {modulearn-0.3.0 → modulearn-0.4.0}/modulearn/server.py +111 -14
  15. {modulearn-0.3.0 → modulearn-0.4.0}/modulearn/static/graph.html +55 -3
  16. {modulearn-0.3.0 → modulearn-0.4.0}/modulearn/static/graph.js +232 -36
  17. {modulearn-0.3.0 → modulearn-0.4.0}/pyproject.toml +6 -1
  18. modulearn-0.4.0/tests/conftest.py +23 -0
  19. modulearn-0.4.0/tests/test_canvas_engine_e2e.py +71 -0
  20. {modulearn-0.3.0 → modulearn-0.4.0}/tests/test_robustness.py +3 -0
  21. modulearn-0.4.0/tests/test_roundtrip_e2e.py +42 -0
  22. {modulearn-0.3.0 → modulearn-0.4.0}/tests/test_run_errors.py +2 -0
  23. modulearn-0.4.0/tests/test_server_endpoints.py +79 -0
  24. modulearn-0.4.0/tests/test_stop.py +130 -0
  25. modulearn-0.4.0/tests/test_sweep.py +121 -0
  26. {modulearn-0.3.0 → modulearn-0.4.0}/LICENSE +0 -0
  27. {modulearn-0.3.0 → modulearn-0.4.0}/PUBLISHING.md +0 -0
  28. {modulearn-0.3.0 → modulearn-0.4.0}/README.md +0 -0
  29. {modulearn-0.3.0 → modulearn-0.4.0}/docs/changelog-tags-guide.html +0 -0
  30. {modulearn-0.3.0 → modulearn-0.4.0}/docs/ci-badge-guide.html +0 -0
  31. {modulearn-0.3.0 → modulearn-0.4.0}/docs/implementation-guide.html +0 -0
  32. {modulearn-0.3.0 → modulearn-0.4.0}/docs/init-scaffold-guide.html +0 -0
  33. {modulearn-0.3.0 → modulearn-0.4.0}/docs/readme-install-guide.html +0 -0
  34. {modulearn-0.3.0 → modulearn-0.4.0}/docs/registry-api-guide.html +0 -0
  35. {modulearn-0.3.0 → modulearn-0.4.0}/docs/regression-guide.html +0 -0
  36. {modulearn-0.3.0 → modulearn-0.4.0}/docs/reload-guide.html +0 -0
  37. {modulearn-0.3.0 → modulearn-0.4.0}/docs/roadmap.html +0 -0
  38. {modulearn-0.3.0 → modulearn-0.4.0}/docs/run-errors-guide.html +0 -0
  39. {modulearn-0.3.0 → modulearn-0.4.0}/docs/single-source-version-guide.html +0 -0
  40. {modulearn-0.3.0 → modulearn-0.4.0}/docs/type-rules-guide.html +0 -0
  41. {modulearn-0.3.0 → modulearn-0.4.0}/modulearn/__main__.py +0 -0
  42. {modulearn-0.3.0 → modulearn-0.4.0}/modulearn/compiler.py +0 -0
  43. {modulearn-0.3.0 → modulearn-0.4.0}/modulearn/registry.py +0 -0
  44. {modulearn-0.3.0 → modulearn-0.4.0}/modulearn/static/graph-engine.js +0 -0
  45. {modulearn-0.3.0 → modulearn-0.4.0}/tests/test_cli_init.py +0 -0
  46. {modulearn-0.3.0 → modulearn-0.4.0}/tests/test_run_errors_cli.py +0 -0
  47. {modulearn-0.3.0 → modulearn-0.4.0}/tests/test_smoke.py +0 -0
  48. {modulearn-0.3.0 → modulearn-0.4.0}/tests/test_type_rules.py +0 -0
@@ -25,5 +25,8 @@ jobs:
25
25
  - name: Install package with dev extras
26
26
  run: pip install -e ".[dev]"
27
27
 
28
+ - name: Install Playwright browser
29
+ run: python -m playwright install --with-deps chromium
30
+
28
31
  - name: Run tests
29
32
  run: pytest -q
@@ -12,3 +12,4 @@ runs/
12
12
  .DS_Store
13
13
  .idea/
14
14
  .vscode/
15
+ uv.lock
@@ -4,6 +4,15 @@ All notable changes to ModuLearn are documented here.
4
4
  This project follows [Keep a Changelog](https://keepachangelog.com) and
5
5
  [Semantic Versioning](https://semver.org).
6
6
 
7
+ ## [0.4.0] - 2026-07-30
8
+ - Name a run before launching; the name shows in the runs list and comparison legend
9
+ - Compare several past runs' validation curves overlaid on one chart
10
+ - Stop a running job (cooperative cancel) and re-run an edited graph
11
+ - Hyperparameter sweep: fan a wired hyperparameter over a list of values, overlaid as the runs complete
12
+
13
+ ### Fixed
14
+ - Atomic `state.json` writes so polling `/api/runs` can't catch a half-written file
15
+
7
16
  ## [0.3.0] - 2026-07-27
8
17
  - `modulearn init [dir]` scaffolds a runnable starter project. (app.py, README, .gitignore)
9
18
  - `modulearn run --reload` restarts the server on file changes for live development.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: modulearn
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: A visual, Unreal-Blueprints-style node-graph editor for building and launching ML training runs.
5
5
  Project-URL: Homepage, https://github.com/IsaiahKoamalu/modulearn
6
6
  Project-URL: Source, https://github.com/IsaiahKoamalu/modulearn
@@ -20,6 +20,8 @@ Requires-Dist: scikit-learn>=1.7.2
20
20
  Requires-Dist: uvicorn>=0.29
21
21
  Provides-Extra: dev
22
22
  Requires-Dist: build; extra == 'dev'
23
+ Requires-Dist: httpx; extra == 'dev'
24
+ Requires-Dist: pytest-playwright; extra == 'dev'
23
25
  Requires-Dist: pytest>=7; extra == 'dev'
24
26
  Requires-Dist: twine; extra == 'dev'
25
27
  Description-Content-Type: text/markdown
@@ -0,0 +1,328 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>ModuLearn — Implementing: Automate the canvas-engine checks</title>
7
+ <style>
8
+ :root{
9
+ --bg:#14181f; --panel:#1b212b; --panel2:#20262f; --edge:#2a323f;
10
+ --ink:#e6edf3; --muted:#8b98a9; --faint:#5f6b7a; --accent:#a8542f;
11
+ --c:#6fb98f; --err:#f85149; --ok:#3fb950;
12
+ --mono:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
13
+ --sans:ui-sans-serif,system-ui,-apple-system,sans-serif;
14
+ }
15
+ *{box-sizing:border-box} html,body{margin:0}
16
+ body{background:var(--bg); color:var(--ink); font:14.5px/1.6 var(--sans);
17
+ background-image:linear-gradient(rgba(255,255,255,.022) 1px,transparent 1px),
18
+ linear-gradient(90deg,rgba(255,255,255,.022) 1px,transparent 1px);
19
+ background-size:50px 50px; -webkit-font-smoothing:antialiased;}
20
+ .wrap{max-width:860px; margin:0 auto; padding:0 22px}
21
+ code{font:12.5px/1.5 var(--mono); background:#0f131a; border:1px solid var(--edge);
22
+ border-radius:4px; padding:1px 5px; color:#c3ccd8}
23
+ pre{font:12.5px/1.6 var(--mono); background:#0f131a; border:1px solid var(--edge);
24
+ border-radius:8px; padding:13px 15px; overflow-x:auto; color:#c3ccd8; margin:12px 0}
25
+ pre code{background:none; border:none; padding:0}
26
+ a{color:var(--c)}
27
+ header{padding:60px 0 26px}
28
+ .kicker{font:600 11px/1 var(--mono); letter-spacing:.26em; text-transform:uppercase;
29
+ color:var(--muted); display:flex; align-items:center; gap:10px}
30
+ .kicker .dot{width:9px; height:9px; border-radius:50%; background:var(--c);
31
+ box-shadow:0 0 0 4px color-mix(in srgb,var(--c) 18%,transparent)}
32
+ h1{font:600 clamp(30px,5vw,46px)/1.06 var(--sans); letter-spacing:-.02em; margin:16px 0 0}
33
+ h1 code{font-size:.7em; background:#0f131a; padding:2px 9px; vertical-align:3px}
34
+ .lede{margin:16px 0 0; color:#c3ccd8; max-width:62ch} .lede b{color:var(--ink)}
35
+ .goal{margin:22px 0 0; padding:13px 15px; border-left:3px solid var(--c);
36
+ background:#0f131a; border-radius:0 7px 7px 0; font-size:13.5px} .goal b{color:var(--c)}
37
+ .progress{margin:26px 0 0; display:flex; align-items:center; gap:14px}
38
+ .track{flex:1; height:8px; border-radius:5px; background:#0f131a; border:1px solid var(--edge); overflow:hidden}
39
+ .fill{height:100%; width:0; background:var(--c); transition:width .45s cubic-bezier(.2,.7,.2,1)}
40
+ .cnt{font:600 12px/1 var(--mono); color:var(--muted); white-space:nowrap} .cnt b{color:var(--ink); font-size:15px}
41
+ h2{font:600 13px/1 var(--mono); letter-spacing:.13em; text-transform:uppercase; color:var(--muted);
42
+ margin:52px 0 0; padding-bottom:11px; border-bottom:1px solid var(--edge); display:flex; align-items:center; gap:9px}
43
+ h2::before{content:""; width:9px; height:9px; border-radius:50%; background:var(--c)}
44
+ ol.steps{list-style:none; counter-reset:s; padding:0; margin:20px 0 0}
45
+ ol.steps > li{counter-increment:s; position:relative; padding:0 0 22px 52px; border-left:1px dashed var(--edge); margin-left:15px}
46
+ ol.steps > li:last-child{border-left-color:transparent}
47
+ ol.steps > li::before{content:counter(s); position:absolute; left:-15px; top:0; width:30px; height:30px;
48
+ border-radius:50%; background:var(--panel2); border:1px solid var(--edge); color:var(--c);
49
+ font:600 12px/28px var(--mono); text-align:center}
50
+ ol.steps > li.done::before{content:"✓"; background:var(--c); color:#0f131a; border-color:var(--c)}
51
+ .stitle{font:600 15px/1.35 var(--sans); display:flex; align-items:flex-start; gap:10px; margin-top:3px}
52
+ .stitle .chk{flex:none; width:19px; height:19px; margin-top:1px; border-radius:5px; border:1.5px solid var(--edge);
53
+ background:#0f131a; cursor:pointer; position:relative; transition:.12s}
54
+ .stitle .chk:hover{border-color:var(--c)}
55
+ li.done .chk{background:var(--c); border-color:var(--c)}
56
+ li.done .chk::after{content:"✓"; position:absolute; inset:0; display:grid; place-items:center; font-size:11px; color:#0f131a}
57
+ li.done .stitle span{color:var(--muted); text-decoration:line-through; text-decoration-color:var(--faint)}
58
+ .sbody{margin:9px 0 0; color:#c3ccd8; font-size:13.5px} .sbody p{margin:9px 0 0}
59
+ .where{font:600 11px/1 var(--mono); color:var(--faint); margin:2px 0 0; letter-spacing:.04em}
60
+ .note{margin:14px 0 0; padding:11px 13px; border-radius:7px; font-size:13px;
61
+ background:color-mix(in srgb,var(--c) 8%,transparent); border:1px solid color-mix(in srgb,var(--c) 32%,transparent); color:#d7ede0}
62
+ .note b{color:var(--c)}
63
+ .warn{margin:14px 0 0; padding:11px 13px; border-radius:7px; font-size:13px;
64
+ background:rgba(248,81,73,.07); border:1px solid rgba(248,81,73,.32); color:#f3b0ab} .warn b{color:var(--err)}
65
+ .ok{margin:16px 0 0; padding:11px 13px; border-radius:7px; font-size:13px;
66
+ background:rgba(63,185,80,.07); border:1px solid rgba(63,185,80,.3); color:#a6e0ac} .ok b{color:var(--ok)}
67
+ .nav{display:flex; gap:10px; flex-wrap:wrap; margin:22px 0 0}
68
+ .nav a{font:600 12px/1 var(--mono); color:var(--muted); text-decoration:none; border:1px solid var(--edge);
69
+ border-radius:20px; padding:7px 12px} .nav a:hover{border-color:var(--c); color:var(--ink)}
70
+ footer{margin:60px 0; padding-top:20px; border-top:1px solid var(--edge); color:var(--faint); font:12px/1.6 var(--mono)}
71
+ @media (prefers-reduced-motion:reduce){*{transition:none!important}}
72
+ @media (max-width:640px){ ol.steps > li{padding-left:38px} }
73
+ </style>
74
+ </head>
75
+ <body>
76
+ <div class="wrap">
77
+ <header>
78
+ <div class="kicker"><span class="dot"></span>Roadmap · Testing &amp; CI · P2 · L</div>
79
+ <h1>Automate the canvas-engine checks</h1>
80
+ <p class="lede">A build-it-yourself guide. <code>graph-engine.js</code> is the one part of
81
+ ModuLearn with <b>no net at all</b> — it's only ever been poked by hand. This folds the manual
82
+ CDP smoke checks (add / connect / serialize / drag / zoom) into a repeatable headless test on the
83
+ Playwright harness you already built for the round-trip test.</p>
84
+ <div class="goal"><b>Done when:</b> a headless browser test adds a node, drags it, zooms the
85
+ canvas, and connects two ports — each asserted through the engine's own state — and it runs green
86
+ in CI alongside the round-trip test.</div>
87
+ <div class="progress"><div class="track"><div class="fill" id="fill"></div></div>
88
+ <div class="cnt"><b id="dn">0</b> / <span id="tn">0</span> steps</div></div>
89
+ <div class="nav">
90
+ <a href="roadmap.html">← roadmap</a>
91
+ <a href="run-comparison-guide.html">run comparison</a>
92
+ <a href="hyperparameter-sweep-guide.html">sweep</a>
93
+ </div>
94
+ </header>
95
+
96
+ <h2>The core problem: the canvas is pixels, not DOM</h2>
97
+ <p style="margin-top:16px">Every node, port and wire is <em>drawn</em> into a single
98
+ <code>&lt;canvas id="graphcanvas"&gt;</code>. Playwright can't <code>get_by_text("Iris")</code> a
99
+ node — there's nothing in the DOM to select. So you drive the engine two ways:</p>
100
+ <ol style="margin:12px 0 0; padding-left:22px; color:#c3ccd8">
101
+ <li><b>Real mouse events</b> (<code>page.mouse.move/down/up/wheel</code>) at <em>pixel</em>
102
+ coordinates — this is what actually exercises drag, zoom and port-connect in the engine.</li>
103
+ <li><b>A tiny coordinate seam</b> that converts a node/port's <em>graph</em> position into
104
+ viewport pixels, so the test knows where to aim. The transform is
105
+ <code>screen = (graph + ds.offset) · ds.scale</code> (see <code>zoomToFit</code>), plus the
106
+ canvas's own <code>getBoundingClientRect()</code> origin.</li>
107
+ </ol>
108
+ <div class="note"><b>Assert on engine state, not pixels.</b> After a drag you don't diff screenshots —
109
+ you read <code>serialize()</code> (which includes each node's <code>pos</code>) or
110
+ <code>ds.scale</code> and check they changed. Robust, and independent of exact rendering.</div>
111
+
112
+ <h2>Steps</h2>
113
+ <ol class="steps" id="steps">
114
+
115
+ <li data-k="ce1">
116
+ <div class="stitle"><span class="chk"></span><span>Extend the test seam with coordinate helpers</span></div>
117
+ <div class="where">modulearn/static/graph.js — next to the existing <code>window.__ml_*</code> seam, inside the IIFE</div>
118
+ <div class="sbody">
119
+ <p>You already expose <code>__ml_serialize/__ml_rebuild/__ml_clear/__ml_ready</code>. Add a few
120
+ more so a test can add a node and locate node titles / ports in <em>viewport</em> pixels.</p>
121
+ <pre><code>// ---- canvas-engine test seam (headless e2e) ----
122
+ window.__ml_add = (typeId) =&gt; { addNode(typeId); };
123
+ window.__ml_nodeIds = () =&gt; graph._nodes.map((n) =&gt; String(n.id));
124
+ window.__ml_ds = () =&gt; ({ scale: canvas.ds.scale,
125
+ offset: [canvas.ds.offset[0], canvas.ds.offset[1]] });
126
+
127
+ // graph coords -> viewport (client) pixels, for driving page.mouse
128
+ window.__ml_toClient = (gx, gy) =&gt; {
129
+ const r = canvas.canvas.getBoundingClientRect();
130
+ return { x: r.left + (gx + canvas.ds.offset[0]) * canvas.ds.scale,
131
+ y: r.top + (gy + canvas.ds.offset[1]) * canvas.ds.scale };
132
+ };
133
+ // a grabbable point on a node's title bar (title sits above node.pos)
134
+ window.__ml_nodeTitleClient = (id) =&gt; {
135
+ const n = graph.getNodeById(+id); if (!n) return null;
136
+ return window.__ml_toClient(n.pos[0] + 20, n.pos[1] - LiteGraph.NODE_TITLE_HEIGHT / 2);
137
+ };
138
+ // the centre of a port nub: isInput=false for an output slot, true for an input
139
+ window.__ml_portClient = (id, isInput, slot) =&gt; {
140
+ const n = graph.getNodeById(+id); if (!n) return null;
141
+ const p = new Float32Array(2); n.getConnectionPos(isInput, slot, p);
142
+ return window.__ml_toClient(p[0], p[1]);
143
+ };</code></pre>
144
+ <div class="note"><b>Why these are safe to ship.</b> They only <em>read</em> engine state and
145
+ reuse <code>addNode</code> — the same function the palette calls. No behavior changes for real
146
+ users; they're inert unless a test calls them.</div>
147
+ </div>
148
+ </li>
149
+
150
+ <li data-k="ce2">
151
+ <div class="stitle"><span class="chk"></span><span>Add a helpers module for the tests</span></div>
152
+ <div class="where">tests/test_canvas_engine_e2e.py — top of the file</div>
153
+ <div class="sbody">
154
+ <p>Reuse the <code>live_server</code> fixture and <code>page</code> from the round-trip test.
155
+ A couple of small helpers keep the tests readable. Seed graphs with fixed positions via
156
+ <code>__ml_rebuild</code> (not <code>__ml_add</code>, which jitters position) so ports land at
157
+ known spots.</p>
158
+ <pre><code>import pytest
159
+
160
+ pytestmark = pytest.mark.e2e
161
+
162
+ # dataset -> model, NO link yet — the connect test will wire it.
163
+ _TWO_NODES = {
164
+ "nodes": [
165
+ {"id": "1", "type": "dataset.iris", "params": {}, "pos": [120, 200]},
166
+ {"id": "2", "type": "model.mlp",
167
+ "params": {"hidden": [16], "dropout": 0.0}, "pos": [480, 200]},
168
+ ],
169
+ "links": [],
170
+ }
171
+
172
+ def _boot(page, live_server, graph=None):
173
+ page.goto(live_server)
174
+ page.wait_for_function("() =&gt; window.__ml_ready === true", timeout=10000)
175
+ if graph is not None:
176
+ page.evaluate("(g) =&gt; { window.__ml_clear(); window.__ml_rebuild(g); }", graph)
177
+
178
+ def _node(page, node_id):
179
+ nodes = page.evaluate("() =&gt; window.__ml_serialize().nodes")
180
+ return next((n for n in nodes if n["id"] == node_id), None)</code></pre>
181
+ </div>
182
+ </li>
183
+
184
+ <li data-k="ce3">
185
+ <div class="stitle"><span class="chk"></span><span>Test: add a node (palette path)</span></div>
186
+ <div class="where">tests/test_canvas_engine_e2e.py</div>
187
+ <div class="sbody">
188
+ <p><code>__ml_add</code> is exactly what a palette click calls, so this exercises the engine's
189
+ node-creation path and confirms it lands in <code>serialize()</code>.</p>
190
+ <pre><code>def test_add_node(live_server, page):
191
+ _boot(page, live_server)
192
+ page.evaluate("() =&gt; { window.__ml_clear(); window.__ml_add('dataset.iris'); }")
193
+ ids = page.evaluate("() =&gt; window.__ml_nodeIds()")
194
+ assert len(ids) == 1
195
+ assert _node(page, ids[0])["type"] == "dataset.iris"</code></pre>
196
+ </div>
197
+ </li>
198
+
199
+ <li data-k="ce4">
200
+ <div class="stitle"><span class="chk"></span><span>Test: drag moves a node</span></div>
201
+ <div class="where">tests/test_canvas_engine_e2e.py</div>
202
+ <div class="sbody">
203
+ <p>Grab the title bar, drag it, and assert the node's <code>pos</code> in
204
+ <code>serialize()</code> changed. <code>steps=</code> makes the engine see intermediate
205
+ move events (a single jump can be missed).</p>
206
+ <pre><code>def test_drag_moves_node(live_server, page):
207
+ _boot(page, live_server, {"nodes": [_TWO_NODES["nodes"][0]], "links": []})
208
+ nid = page.evaluate("() =&gt; window.__ml_nodeIds()")[0]
209
+ before = _node(page, nid)["pos"]
210
+
211
+ start = page.evaluate("(id) =&gt; window.__ml_nodeTitleClient(id)", nid)
212
+ page.mouse.move(start["x"], start["y"])
213
+ page.mouse.down()
214
+ page.mouse.move(start["x"] + 140, start["y"] + 90, steps=10)
215
+ page.mouse.up()
216
+
217
+ after = _node(page, nid)["pos"]
218
+ assert after != before</code></pre>
219
+ </div>
220
+ </li>
221
+
222
+ <li data-k="ce5">
223
+ <div class="stitle"><span class="chk"></span><span>Test: wheel zooms the canvas</span></div>
224
+ <div class="where">tests/test_canvas_engine_e2e.py</div>
225
+ <div class="sbody">
226
+ <p>Move over the canvas, scroll, and assert <code>ds.scale</code> changed. Zoom is a pure
227
+ engine behavior with no DOM footprint, so the <code>__ml_ds()</code> read is the only way to
228
+ see it.</p>
229
+ <pre><code>def test_wheel_zooms(live_server, page):
230
+ _boot(page, live_server, {"nodes": [_TWO_NODES["nodes"][0]], "links": []})
231
+ before = page.evaluate("() =&gt; window.__ml_ds().scale")
232
+
233
+ box = page.locator("#graphcanvas").bounding_box()
234
+ page.mouse.move(box["x"] + box["width"] / 2, box["y"] + box["height"] / 2)
235
+ page.mouse.wheel(0, -400) # scroll up over the canvas = zoom in
236
+
237
+ after = page.evaluate("() =&gt; window.__ml_ds().scale")
238
+ assert after != before</code></pre>
239
+ <div class="note"><b>If the scale doesn't budge</b>, the wheel handler may require the pointer
240
+ to be <em>over</em> the canvas first (the <code>mouse.move</code> above ensures that), or your
241
+ engine may clamp zoom — try a larger delta or scroll the other direction.</div>
242
+ </div>
243
+ </li>
244
+
245
+ <li data-k="ce6">
246
+ <div class="stitle"><span class="chk"></span><span>Test: drag connects two ports</span></div>
247
+ <div class="where">tests/test_canvas_engine_e2e.py</div>
248
+ <div class="sbody">
249
+ <p>The real payoff: drag from <code>dataset.iris</code>'s output nub (slot 0) to
250
+ <code>model.mlp</code>'s <code>dataset</code> input (slot 0) and assert a link appears in
251
+ <code>serialize()</code>.</p>
252
+ <pre><code>def test_drag_connects_ports(live_server, page):
253
+ _boot(page, live_server, _TWO_NODES)
254
+ assert page.evaluate("() =&gt; window.__ml_serialize().links.length") == 0
255
+
256
+ out = page.evaluate("() =&gt; window.__ml_portClient('1', false, 0)") # dataset output
257
+ inp = page.evaluate("() =&gt; window.__ml_portClient('2', true, 0)") # model 'dataset' input
258
+ page.mouse.move(out["x"], out["y"])
259
+ page.mouse.down()
260
+ page.mouse.move(inp["x"], inp["y"], steps=12) # smooth drag so the engine tracks it
261
+ page.mouse.up()
262
+
263
+ links = page.evaluate("() =&gt; window.__ml_serialize().links")
264
+ assert len(links) == 1
265
+ assert links[0]["from"] == "1" and links[0]["to"] == "2"
266
+ assert links[0]["to_port"] == "dataset"</code></pre>
267
+ <div class="warn"><b>This is the flakiest test — expect to tune it.</b> The engine only forms a
268
+ link if the mouse-up lands inside the input port's hit radius. <code>__ml_portClient</code>
269
+ aims at the exact port centre, which should hit, but if it's intermittent: raise
270
+ <code>steps</code>, add a tiny <code>page.wait_for_timeout(50)</code> before mouse-up, or nudge
271
+ the end point by a pixel or two. If drag-connect stays unreliable in CI, fall back to asserting
272
+ link fidelity through the <a href="#">round-trip test</a> (which already covers serialize/rebuild
273
+ of links) and keep drag-connect as a local-only check.</div>
274
+ </div>
275
+ </li>
276
+
277
+ <li data-k="ce7">
278
+ <div class="stitle"><span class="chk"></span><span>Run it — locally, then confirm CI</span></div>
279
+ <div class="sbody">
280
+ <p>The Playwright browser + the <code>e2e</code> marker are already wired from the round-trip
281
+ work, so there's nothing new in <code>ci.yml</code>.</p>
282
+ <pre><code>pytest tests/test_canvas_engine_e2e.py -q # the four canvas tests
283
+ pytest -q # full suite, e2e included
284
+ pytest -q -m "not e2e" # fast local loop, browser skipped</code></pre>
285
+ <div class="note"><b>Keep e2e opt-outable.</b> Because these are marked <code>e2e</code>, a
286
+ contributor without a browser can still run <code>-m "not e2e"</code>. CI installs chromium and
287
+ runs the full set.</div>
288
+ </div>
289
+ </li>
290
+
291
+ <li data-k="ce8">
292
+ <div class="stitle"><span class="chk"></span><span>Commit + mark shipped</span></div>
293
+ <div class="sbody">
294
+ <pre><code>git add modulearn/static/graph.js tests/test_canvas_engine_e2e.py
295
+ git commit -m "Automate canvas-engine checks: add/drag/zoom/connect in headless Chromium"
296
+ git push
297
+ gh run list --branch main --limit 1 # expect: success</code></pre>
298
+ <p>Then check the <code>{area:"testing", … title:"Automate the canvas-engine checks"}</code>
299
+ card in <code>docs/roadmap.html</code> (shipped state is per-browser). That closes the last
300
+ Testing/CI card.</p>
301
+ </div>
302
+ </li>
303
+ </ol>
304
+
305
+ <h2>Worth knowing</h2>
306
+ <div class="note" style="margin-top:18px"><b>This is the highest-leverage net you'll add.</b> The
307
+ canvas engine is hand-written and, until now, entirely untested — the exact place a refactor could
308
+ silently break wiring. Even this handful of interactions guards the core promise (drop, wire,
309
+ serialize) end to end in a real browser. Screenshot/visual-regression testing is a possible
310
+ follow-up, but asserting <em>engine state</em> is sturdier and won't break on a color tweak.</div>
311
+
312
+ <footer>ModuLearn · docs/canvas-engine-guide.html · companion to
313
+ <a href="roadmap.html">roadmap.html</a> · builds on the Playwright harness from the round-trip test ·
314
+ step state is local to this browser.</footer>
315
+ </div>
316
+ <script>
317
+ const KEY="modulearn.canvas-engine.steps";
318
+ const done=new Set(JSON.parse(localStorage.getItem(KEY)||"[]"));
319
+ const lis=[...document.querySelectorAll("#steps > li")];
320
+ function paint(){lis.forEach(li=>li.classList.toggle("done",done.has(li.dataset.k)));
321
+ document.getElementById("fill").style.width=(100*done.size/lis.length)+"%";
322
+ document.getElementById("dn").textContent=done.size; document.getElementById("tn").textContent=lis.length;}
323
+ lis.forEach(li=>li.querySelector(".chk").addEventListener("click",()=>{const k=li.dataset.k;
324
+ done.has(k)?done.delete(k):done.add(k); localStorage.setItem(KEY,JSON.stringify([...done])); paint();}));
325
+ paint();
326
+ </script>
327
+ </body>
328
+ </html>