Skip to content

test: run the code instead of reading it - #1032

Merged
PathGao merged 113 commits into
masterfrom
tests-run-the-code
Oct 26, 2026
Merged

PathGao merged 113 commits into
masterfrom
tests-run-the-code

Conversation

@PathGao

@PathGao PathGao commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #1030. Most cases in the *.checks.* files read source as text: they sliced function bodies out of components, cut code out of .svelte files and evaluated it, or matched a line's spelling. This rewrites them as tests that run the code.

Logic a test could not reach is moved out of the components into modules the components call (41 new files under src/lib: the viewer's window exit, external change, view mode, viewer command table, preview links and copy; the editor's actions, key handlers, clipboard, mount sequence, document readings and jumps; the settings panes as row data; and similar). Each move is the old code plus its call site, with no intended behavior change. A few Rust functions became pure or generic over Runtime so they can be unit tested, with the tauri test feature as a dev-dependency only.

Every rewritten test was checked by putting the old bug back (or breaking the guarded behavior) and watching it fail for that reason. Small components without Monaco are now mounted under jsdom for their markup wiring; AGENTS.md is updated to say so and to stop asking for source-shape assertions. The checks files keep 177 cases: Tauri command/event names, config and i18n keys, and single-implementation conventions, which a follow-up moves to generated bindings and lint rules.

Order-dependent tests (pre-existing in the external change reload spec) are fixed; vitest --sequence.shuffle and node --test --test-random-seed pass on 10 seeds each.

These 18 checks are deleted with no replacement, because they need MarkdownViewer.svelte or Editor.svelte mounted, or real CSS layout:

  • "saveContent is the choke point auto-save and the close dialogs share" (documents.checks.test.ts): the viewer's auto-save timer writes through saveSilently, so a file that decoded with losses is never auto-saved over itself.
  • "the conflict bar offers Compare beside the two answers" (documents.checks.test.ts): when the file changes on disk, the bar shows Compare next to Keep mine and Reload, so you can look before you pick the answer that cannot be undone.
  • "the viewer hands over an article rather than its own preview" (export.checks.test.ts): PDF export prints a dedicated <article id="print-root">, not the live preview with its folds and theme.
  • "the preview scroll and the outline are wired to the view mode" (layout.checks.test.ts): scrolling the preview moves the outline highlight.
  • "the outline's toggle drops the editor toolbar's offset once it is over the outline" (layout.checks.test.ts): when the outline is open, its toggle button doesn't sit on the outline's first entry.
  • "every renderer line reaching the editor goes through the shift" (navigation.checks.test.ts): clicking an outline heading in a file with front matter opens the editor on the right line.
  • "inline code in a heading scales with the heading" (preview.checks.test.ts): code inside a ## heading is sized relative to the heading, not stuck at the code font size.
  • "the setting still governs code everywhere else" (preview.checks.test.ts): the Code Font Size setting still sizes code outside headings.
  • "the document-level copy handler is attached" (preview.checks.test.ts): ⌘C and Edit ▸ Copy in the preview go through the app's copy handler (plain text plus text/html, no WebArchive).
  • "release notes can be selected even though the app disables selection" (release.checks.test.ts): you can select and copy text in the update dialog's release notes (Makes the release note section better #532).
  • "an inactive row is dimmed rather than hidden" (settings.checks.test.ts): a setting that has no effect right now (for example Wrap Column with wrapping off) is greyed out, not removed.
  • "the auto-save debounce still reads the one switch" (settings.checks.test.ts): the auto-save timer only runs when Auto-save is on.
  • "the panel's groups are visibly separated, not run together" (shortcuts.checks.test.ts): the Shortcuts pane draws a themed line and space between groups.
  • "the viewer wires the editor's oncommand to runViewerCommand" (shortcuts.checks.test.ts): ⌘O and ⌘T typed inside the editor do the same thing as in the preview.
  • "the preview holds one document host per tab, not one for all of them" (tabs.checks.test.ts): switching tabs doesn't rebuild the whole preview or lose your reading position.
  • "startup restore reads content from disk, not from the snapshot" (windows.checks.test.ts): on launch, restored tabs read their text from disk.
  • "the scope line is drawn on the strip, in a channel the active tab does not use" (windows.tagEditor.checks.test.ts): a window tag's coloured line runs along the bottom of the tab strip and can't be mistaken for the active-tab marker.
  • "the status bar keeps its items on one line" / "the status bar clips what does not fit rather than growing" (editor.checks.test.ts): the status bar stays one line and clips instead of wrapping or growing, so a selection in a narrow window does not end the drag (Shift + Alt + LMB drag in the editor takes into account the window size #762).

Verified: node --test, vitest (normal and shuffled), svelte-check, cargo fmt/clippy/test, npm audit all green. Not clicked through in a built app.

Merge the ~200 per-fix test files into a few files per feature area.
Source-reading cases move to <feature>.checks.* files, separate from
behavior tests. No assertion changed: the same 1752 test names pass.
…Handlers.ts

test: run the editing keys against the extracted handlers instead of cutting them out of Editor.svelte
…nt-matter scroll end out of Editor.svelte

test: run them instead of reading Editor.svelte
…Bar.svelte

Move the window-tag editor, menu flags and window dismissal out of
TitleBar.svelte into stores/titleBarPopovers.svelte.ts, and the Home
menu export gate into canExportTab. Rewrite the tag-editor, export-gate
and context-menu-dismiss checks as behaviour specs and delete
scripts/windowTagEditor.ts.
…them directly

The close handler, quit, update settle, last-tab close, merge and pinned
group open move out of MarkdownViewer.svelte unchanged, as does the
set_window_meta report. Source-reading checks for them are replaced by
behavior tests; checks that lifted these functions now run the module.
…ns.ts

Editor.svelte and MarkdownViewer.svelte call createdEditorOptions,
updatedEditorOptions and editorReadOnly, so the option tests run the
functions instead of lifting the literal out of the component.
test: check every theme name the editor asks for against what defineAppThemes
and the VS Code theme loader actually define.
…calizedActions.svelte.ts

test: drive it with a real effect in editor.localizedActions.spec.ts instead of matching Editor.svelte
# Conflicts:
#	scripts/shortcuts.checks.test.ts
Settings.svelte walks SETTINGS_PANES (src/lib/utils/settingsPanes.ts) and its open effect lives in settingsOpen.svelte.ts. The pane checks that read the component now run on the data in settings.spec.ts.
Delete the AST walk over Settings.svelte, the inactive-row opacity check
(component CSS) and the viewer's auto-save debounce wiring check.
… engine, could observe

The viewer and editor wiring and the component CSS rules they pinned are
listed in the PR body.
# Conflicts:
#	scripts/editor.checks.spec.ts
AGENTS.md no longer asks for source-shape assertions. It says tests run
the code, logic a test cannot reach moves into a module, which components
may be mounted, and that the checks files hold only contract and
convention checks until bindings and lint rules replace them.
- documents.load: the #692 reload test replaced the invoke handler for
  good; reset() now restores the disk-backed one.
- settings.themeLoad: the Monaco mock is cached after its first import;
  the first-load test re-registers it, resets modules and holds the import.
- export: the KaTeX/highlight memo is module-level; each export run
  resets it.
refreshesPreviewCache, showsHomeScreen and tocAutoCollapses take getters for
the value the old short-circuit did not read, so their effects do not
subscribe to it. patchHost runs readTab and patchPreview inside untrack, as
the viewer did. saveImageAs reads the UI language after the Save dialog.
Sticky Headings now comes from editorOptionsFromSettings only, so the
moved creation options no longer set it a second time, and the 'option a
setting can change' test covers it instead of skipping it.
The Windows test binary failed to load (STATUS_ENTRYPOINT_NOT_FOUND):
tauri's test feature pulls in Common Controls v6 entry points and a test
binary carries no manifest declaring them. The three tests that need the
mock runtime, and the feature itself, now apply to macOS and Linux only.
@PathGao
PathGao merged commit 6310d52 into master Oct 26, 2026
4 of 5 checks passed
@PathGao
PathGao deleted the tests-run-the-code branch October 26, 2026 12:27
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