Skip to content

Test with a published model (Cohen & Huston Stroop) and fix what it found - #186

Draft
gidili wants to merge 16 commits into
feature/mac-one-clickfrom
stroop-model-testing
Draft

gidili wants to merge 16 commits into
feature/mac-one-clickfrom
stroop-model-testing

Conversation

@gidili

@gidili gidili commented Dec 5, 2026

Copy link
Copy Markdown
Member

Stacked on #183 (the one-click macOS app): it reuses that PR's packaged app and Playwright setup, and its base should change to develop once #183 merges.

What it does

Tests the viewer with a real published model, Cohen & Huston's (1994) Stroop model from PsyNeuLink's model library, and with models built from scratch. Then it fixes what those tests found. All of these bugs were already in develop.

Fixed

Loading and drawing

  • Models with spaces or dashes in their names crashed on load; the Stroop model is one. The viewer looked up names that PsyNeuLink had converted ("COLORS HIDDEN" is stored as "COLORS_HIDDEN"). This also fixes auto-named ProcessingMechanism-0 layers being dropped.
  • Recurrent links (a layer to itself) were drawn as NaN. They're now loops.
  • Opening any recurrent layer's properties crashed the window.

What the viewer shows

  • The properties panel showed blanks or pnl.undefined() for many values the script set, such as integration_rate, hetero and function=pnl.Logistic(x_0=4.0). It now shows the values from the live PsyNeuLink objects.
  • Hovering over a link shows its weights.

Running and saving

  • Run rebuilt the whole script from the diagram, which drops weights and functions, so it ran a different model, or failed (Stroop).
    • With no changes in the app, Run now runs the script itself.
    • With changed values, only those arguments are written into the script, and comments and formatting stay.
    • Stroop results match plain PsyNeuLink exactly.
  • Run, Update Model and Save could leave the .py empty if anything failed partway. Writes are now atomic.
  • Save As wrote over the open file instead of the chosen one. It now writes the chosen file, as a copy of the script.
  • Structural changes (adding layers, links or ports) still need the whole script regenerated, so the app now asks before doing that to a hand-written script.
  • Run results work for models with several input layers or vector outputs. The composition is found by its name.

Building from scratch

  • Only 4 of the sidebar's 24 layer types could be built and saved. All 12 types it now offers work.
    • The generator now quotes text values, writes numbers correctly, and skips port arguments for the types that reject them.
    • The loader no longer loops forever on an undefined name ("maximum recursion depth exceeded").
  • Sidebar:

Tests

  • e2e/published-models.spec.ts (Stroop):
    • every layer and link is drawn;
    • the panel shows the script's values;
    • hovering a link shows its weights;
    • runs, plain and with a value changed in the app, match plain PsyNeuLink run with the app's bundled Python;
    • Update Model and Save As change only what they should;
    • the rewrite question appears for structural changes.
  • e2e/build-a-model.spec.ts: builds a composition and linked layers from the sidebar, saves, checks the saved script in plain PsyNeuLink, runs it, and builds every offered layer type.
  • src/server/tests: 23 Python tests for the script editor, the code generator, the loader and Save As. They pass on PsyNeuLink 0.15.3 and 0.21.1, and macos-app.yml runs them with the bundled Python.
  • Jest: 11 tests. The ProcessingMechanism-0 test, skipped until now, is enabled.
  • Tested locally (Apple Silicon, packaged app): all of the above pass, and the full e2e suite passed twice in a row.

Not done yet

🤖 Generated with Claude Code

gidili and others added 12 commits December 5, 2026 14:05
Update Model, Save and Run used to open the model's .py for writing (emptying it) before the
new code was ready, so a failure or a quit in between lost the user's script (seen: 0 bytes).
The code is now generated first, written to a temporary file next to the model, and swapped in
whole. If generation fails, the file is untouched and the previously loaded model is restored.
The error now reads clearly instead of "can only concatenate str (not ParsingError)".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
…t links

- PsyNeuLink stores "COLORS HIDDEN" as "COLORS_HIDDEN" in its summaries (and
  "ProcessingMechanism-0" as "ProcessingMechanism_0"). Some lookups didn't convert the name,
  so a model with such names crashed on load (Cohen & Huston's Stroop model) or lost nodes.
  summaryKey() follows PsyNeuLink's own rule and is used for every lookup. The skipped unit
  test for ProcessingMechanism-0 now passes.
- A link whose port can't be found is skipped with a warning instead of stopping the load.
- A link from a layer to itself (a recurrent projection) had no direction and was drawn as
  NaN; it's now a loop on the layer's right side.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
- The properties panel read values from PsyNeuLink's json_summary, which leaves many out or
  elsewhere: a recurrent layer showed no integration_rate or hetero and pnl.undefined() as its
  function. The backend now sends the values the script set, read from the live objects
  (Parameter._user_specified, same in PsyNeuLink 0.15.3 and 0.21.1), and the panel uses them.
- Hovering a link shows its weights. Links inside a composition are under its box, so the
  hover looks through it (document.elementsFromPoint) and clicking is unchanged; links drawn on
  top of each other (both directions between two layers) are all shown.
- Opening any recurrent layer's properties crashed the window: a summary object reached a text
  field. Such values now show as empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
Run regenerated the whole script from the app's own copy of the model, which leaves out what
the app can't represent (weights, functions, the script's variables), so it ran a different
model, or failed (Cohen & Huston's Stroop model).
- Unchanged in the app: Run rebuilds the model from its script and runs it. The file isn't
  touched, and every run starts fresh.
- Parameters changed in the app: Run and Update Model write just those arguments into the
  script (scriptEditor.py, using Python's ast positions; comments and formatting stay), then
  rebuild. The file is only written if the edited script builds.
- Structural changes (and models not loaded from a file) still regenerate the script.
- Results: the composition is found by its name, as the app lists it; each output unit gets
  its own series named after its layer; inputs given per layer work; logs are collected per
  layer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
- e2e/published-models.spec.ts: Cohen & Huston's (1994) Stroop model from PsyNeuLink's model
  library, in the packaged app: all layers and links drawn, the script's values in the panel,
  link weights on hover, and runs (unchanged, then with a value changed in the app) whose
  results match plain PsyNeuLink running the same file with the app's bundled Python. Also
  checks the file is untouched by a plain run and changed by one line otherwise.
- src/server/tests: unit tests for writing changes into a script. CI runs them with the
  bundled Python right after building it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
- Removed ModulatoryMechanism_Base, CompositionInterfaceMechanism and
  DefaultProcessingMechanism_Base: PsyNeuLink's docs say never to construct them directly (the
  last one isn't even exported, so generated code always failed). Scripts containing them still
  display.
- Greyed out, with "(not available yet)" in the tooltip: the learning and control mechanisms,
  which only work once wired to what they learn from or control (the viewer can't set that up
  yet; see #185), and KohonenMechanism, which PsyNeuLink itself can't construct (0.15.3 and
  0.21.1: its __init__ passes params=params without a params argument).
- Each icon carries data-node-type, so tests can find a type by name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
…fers

Building a model from scratch and saving it worked for 4 of the sidebar's 24 types; now all 12
types it offers work (the saved script runs in plain PsyNeuLink).
- Plain text values from PsyNeuLink (a recurrent layer's matrix, "HollowMatrix") were written
  unquoted, as an undefined name. They're written as strings now; numbers no longer crash
  generation.
- Loading a script with an undefined name retried that line forever ("maximum recursion depth
  exceeded", also the error Cohen & Huston's Stroop model got). It now stops with a clear
  NameError naming the variable and the line.
- No port arguments for ObjectiveMechanism, ComparatorMechanism, PredictionErrorMechanism, DDM
  and ContrastiveHebbianMechanism, which reject them; ContrastiveHebbianMechanism gets the
  input, hidden and target sizes PsyNeuLink requires (1 unless set in the app).
- Function fields other than 'function' (integrator_function, termination_measure, ...) showed
  the node's first function and were generated with it (LCAMechanism got
  integrator_function=pnl.Logistic()). They're left empty now, so PsyNeuLink's defaults apply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
Structural changes (layers, links or ports added or removed) can't be written into a script
one argument at a time yet, so Run and Update Model regenerate the whole script from the
diagram, losing what it doesn't show (weights, comments, the script's variables). The app now
asks first, and Cancel leaves the file untouched.
The backend tells the app whether the loaded file is hand-written (its content differs from
what the app last generated), so models built in the app are never asked about.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
…stion

- e2e/build-a-model.spec.ts: drag a composition and layers from the sidebar, link them, save
  with Update Model, run. The saved script runs in plain PsyNeuLink, runs in the app match
  plain PsyNeuLink, and every layer type the sidebar offers can be built and saved.
- e2e/published-models.spec.ts: adding a layer to the Stroop model asks before rewriting its
  script, and Cancel keeps the file.
- src/server/tests/test_code_generator.py: values, port arguments, required sizes, every
  offered type, and the undefined-name error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
With a file open, Save As ignored the chosen path: it wrote a version regenerated from the
diagram over the open file (losing comments, pathways, weights) and never created the new
file, while reporting "Model saved successfully".
- It now always writes the chosen file, and the app works on that file from then on (the main
  process watches it instead of the original).
- With a script open, the copy is that script with any values changed in the app written in,
  so nothing is lost. It's generated from the diagram only for structural changes (or with no
  script open), and for a hand-written script the app asks first ("Save a generated copy?").
- Tests: src/server/tests/test_save_as.py, and a Save As step in the published model e2e test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
…nvas

On CI's smaller screens the fixed drop points of the "every layer type" test fell outside the
composition's canvas, onto the dialog around it, and the drag timed out (both architectures).
The drops now go on a grid sized to the canvas. Checked with the app window shrunk to 1024x700:
the old version fails the same way, this one passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
With no model open, the right panel showed "No instances to display yet." in the default 16px
font, with no margin (its no-instance class had no styles). It now has the same "Model
Hierarchy" heading and padding as with a model, and a muted hint in the panel's text size:
"No model yet. Open one with File > Open model, or drag a layer onto the canvas."

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
gidili and others added 4 commits December 5, 2026 17:46
A composition's name chip, with the icon that opens the composition, is drawn 1.75rem (28px)
above its box. Loaded models put the box at the very top of the canvas (the backend shifted
compositions to the right, not down), so the chip sat mostly behind the app's header and its
icon couldn't be clicked; the canvas can't be scrolled to reach it. Every loaded model was
affected. The backend now also shifts the layout down by 60px, so the chip is fully visible.

Tests: the published model test checks the chip is below the header, and opens the composition
with a real click on its icon (it had to send the click event directly before).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
The layer-type menu listed types in the code's enum order, with the greyed-out ones mixed in.
It now lists the types that can be added first, then the ones not available yet, each grouped
by PsyNeuLink family (from psyneulink's package layout): Processing, Transfer, Integrator,
Objective, then Learning and Control. The menu can't show headings, so each tooltip names the
group, e.g. "Integrator · DDM" or "Control · Gating Mechanism (not available yet)".

Test: build-a-model checks every available type comes before every unavailable one, and the
group in the tooltip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
Generated code used each component's name as its Python variable, so names that aren't valid
variables ("WORDS HIDDEN", "ProcessingMechanism-0", "2nd layer") made the script fail, and some
valid ones were wrong: a Python keyword, pnl/np (overwriting the module the script uses), or two
names converting to the same variable (one component silently replacing the other). Names in
name='...' weren't escaped either.

- Regenerating a loaded script keeps the script's own variables (colors_hidden_layer, not one
  made from "COLORS HIDDEN").
- Otherwise the name is converted the way PsyNeuLink does, avoiding keywords and pnl, np and
  psyneulink, with a suffix when a variable is already taken.
- The variable is used everywhere the code refers to the component (add_node, add_projection,
  link senders and receivers, ports, logging); names are written with Python quoting.

Tests: names with spaces, dashes, a leading digit, a keyword, pnl/np and a quote; names that
convert to the same variable; and keeping a script's own variables.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
- appdmg failed twice on CI's Intel runners while unmounting its temporary image
  ("hdiutil: detach failed - No such file or directory"). build_app.sh now tries up to 3 times,
  detaching any leftover volume and removing the partial .dmg in between.
- With the new sidebar order, a hovered layer-type icon's tooltip sat where the build-a-model
  test dropped a layer, and caught the drop. The drops now land further right, away from the
  menu. Passes with the default window and with it shrunk to 1024x700.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
gidili added a commit that referenced this pull request Dec 5, 2026
Brings in #186's latest changes, including the appdmg retry for CI's Intel runners.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01M7yBhRTy54udAfmgtfbNjQ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant