Skip to content

[test] Add a unit-test baseline for the canvas and rules layers - #181

Merged
hsliuustc0106 merged 1 commit into
mainfrom
cursor/canvas-rules-unit-baseline-6d4c
Nov 6, 2026
Merged

hsliuustc0106 merged 1 commit into
mainfrom
cursor/canvas-rules-unit-baseline-6d4c

Conversation

@hsliuustc0106

Copy link
Copy Markdown
Contributor

Summary

Adds a repeatable unit-test baseline for the canvas interaction surface and for src/backend/rules.ts derivation, so later refactors (#174, #175) can fail on regressions. Product behavior is unchanged.

Canvas selection, drag authoring, connection drops, node placement, keyboard actions, and image/video/audio/text generation submission were inline in CanvasWorkspace. Those decisions now live in pure helpers (workspaceInteraction.ts, generationSettings.ts) that the workspace calls. The helpers are what the new tests exercise.

Coverage

  • Selection: flow select-changes merge in place; select-all skips folded stack members.
  • Dragging: click-slop and cancelled gestures author nothing; a real drag is one undo step; a resize keeps its compensating position.
  • Connections: unfinished drops open the creation menu only after leaving the handle, and only on the pane or an unlocked group. New nodes sit on the dropped port, then inside the group.
  • History and shortcuts: undo/redo, reorder, paste, group, import, and arrow nudges map to the existing commands. A nudge is one undo step.
  • Generation submission: service and text requests, context-only inputs, audio run count, voice ids, and missing pinned metadata.
  • Import/export: a placed node, its reference edge, and its prompt survive a .canvas archive round trip.
  • Rules derivation: model labels and lookup, voice ids, music/speech normalization, model-change cleanup, reference rejection, video mode and aspect derivation, submission blockers, and reference budgets (byte dedup, counts, agent images, continuation clips).

New files are picked up by the existing CI step npm test (node --test tests/*.test.ts). No workflow change.

Validation

Run:

  • node --test tests/canvasInteraction.test.ts tests/rulesDerivation.test.ts
  • npm test — 601 passed
  • npx tsc --noEmit
  • npm run check:i18n — 2864 keys, 168 Chinese source lines (legacy model names moved with getNodeGenerationSettings; total unchanged)

Not run:

  • npm run build (Vite production bundle)
  • python -m pytest
  • isolated browser workflows
  • real model or media generation

Intentional gaps

Fixes #172

Open in Web Open in Cursor 

## summary

- Extract canvas selection, drag, connection, shortcut, and
  generation-submission decisions into pure helpers and cover them
  with unit tests.
- Add derivation tests for model identity, voice, audio role,
  reference checks, video mode, blockers, and reference budgets.
- Preserve workspace behavior. The new files run in the existing
  `npm test` CI step.

## validation

- `node --test tests/canvasInteraction.test.ts tests/rulesDerivation.test.ts`
- `npm test` (601 passed)
- `npx tsc --noEmit`
- `npm run check:i18n`

Fixes: #172
Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
@hsliuustc0106
hsliuustc0106 merged commit aba0134 into main Nov 6, 2026
1 check passed
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.

[test] Add a unit-test baseline for the canvas and rules layers

2 participants