Skip to content

chore(tests): delete 14 source-text tests that no defect can fail - #433

Merged
PathGao merged 1 commit into
masterfrom
chore/drop-tests-that-only-detect-renames
Aug 3, 2026
Merged

chore(tests): delete 14 source-text tests that no defect can fail#433
PathGao merged 1 commit into
masterfrom
chore/drop-tests-that-only-detect-renames

Conversation

@PathGao

@PathGao PathGao commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

What this measures

node --test cannot import a .svelte file, so anything asserted about a component can only be a regex over its source text. 19 files were nominated for deletion on the theory that such a test detects a rename and nothing else. I did not take the list on faith: every file was measured by injecting a real defect into its own stated subject and running the whole suite.

14 are deleted. 5 are kept — each was measured to catch a real defect that nothing else catches. Four assertions from inside the deleted files were salvaged.

Deleted: the file stayed green with a real defect live

Each row is a defect injected into production code, with the whole suite run against it. "Also caught by" is the file that went red instead — where that column is empty, nothing in the suite noticed at all.

Deleted file Defect injected File red? Also caught by
previewScrollSync scroll-sync threshold 5100000 (sync dead) green
previewScrollSync sync ratio hard-coded to 0 green
findCollapsedMatches revealFoldsAround made a no-op green
findCollapsedMatches foldToggleFor always returns null green
toolbarCustomizationWiring reorderEditorToolbarTool made a no-op green
toolbarCustomizationWiring reorderTitlebarToolbarAction made a no-op green
interruptedSessionRestore restore breadcrumb never persisted green sessionRestoreResilience
interruptedSessionRestore explicit exit stops clearing the snapshot red windowStateRestore
taskToggleMemory checkbox toggle writes the wrong line (===>=) green truncatedBufferGuard
taskToggleMemory rendered task boxes stay disabled red renderProtocol
reloadOpenToolbar reload calls canCloseTab and ignores the answer green
reloadOpenToolbar the fmt-bold toolbar action does nothing green
windowsPdfExport await dropped from invoke('export_pdf_windows') green
batchCloseConfirmation Close Others also closes the tab it was invoked on green
frontMatterDisclosure the front-matter tag remove button is inert green
viewerDisposal one of seven isDisposed guards removed green
previewRenderRevision the stale-render guard's || becomes && green
tocEditorJump the ToC jump selects line 1 instead of the heading green
openMultipleFiles only the first selected document is opened red
tabContextMenuIsolation overlay left-click no longer dismisses the menu red
editorOptionWiring* minimap and wordWrap settings ignored green

The rows marked red need the qualifier that decides this PR. In each of them my edit landed on the exact line the file greps, so the file failed because a string moved, not because behaviour changed. That is the same mechanism that turns 2 tests red for renaming revealFoldsAround while 553 stay green for making it a no-op. It is detection of an edit, not of a defect — and svelte-check already refuses an inconsistent rename, which is the only edit of that shape that is ever a bug.

Where the injected defect avoided the greped line (viewerDisposal, previewRenderRevision, batchCloseConfirmation, frontMatterDisclosure, tocEditorJump, reloadOpenToolbar, findCollapsedMatches), the file was green. That is every file in this list.

* editorOptionWiring appears here for context but is kept — see below.

Kept: 5 of the 19, each with a defect only it catches

These were on the list. They should not have been. In each case the file caught something that is not a spelling pin, and nothing else in the suite caught it.

Kept file Defect it caught alone Why it is not a spelling pin
editorOptionWiring one of the two renderWhitespace sites regresses to "trailing" the assertion is count(...) === 2, so it catches creation and updateOptions disagreeing — a class of bug, not a string
printFindHighlight the print rule's background-color: transparent becomes display: none resolves the CSS cascade between styles.css and a :global() rule in FindBar.svelte; no compiler does this
foldLayout styles.css fold wrapper reverts to grid-template-rows: 1fr couples foldLayout.ts (writes --fold-content-height) to styles.css (consumes it) across files
scrollSyncInput a cursor-position listener added to the scroll-sync effect a negative assertion catching newly added code, which no rename can trip
windowTags windowTag dropped from the v2 window snapshot; pinned forced true the only check that the tag survives a serialize/restore round trip

The table's premise for windowTags — "Rust pinned-tag write made a no-op" — reproduces: making save_pinned_tag_at return Ok(()) leaves all 562 JS tests green. But cargo test catches it in three tests (window_runtime::tests), and the JS file's remaining value is the frontend half, which nothing else covers. Deleting it would open a real hole in a data-persistence path.

Salvaged

Four assertions pinned something no compiler can see. They moved rather than died, and each was re-verified by mutation after the move.

From Assertion To Verified by
windowsPdfExport every invoke('…pdf…') name in export.ts is registered in generate_handler! and defined as a #[tauri::command] macosPdfExport renaming export_pdf_windows on the Rust side only → red
toolbarCustomizationWiring 11 interactive labels are translated in every locale; 11 window-organization labels are translated in zh-CN i18nCoverage deleting the zh-CN menu.mergeAllWindows entry → red
findCollapsedMatches FOLD_TRANSITION_MS outlasts the styles.css height transition foldLayout lengthening the CSS transition to 0.6s → red
tabContextMenuIsolation create_transfer_window is async fn windowOrganization dropping async → red

The two i18n tests were the only behavioural code in toolbarCustomizationWiring — they import the dictionary and look keys up in it. i18nCoverage deliberately does not enforce per-locale completeness (19 locales are >100 keys short and failing on that would block every English string), so these keys needed to survive as the named exception: they label icon-only controls where the word carries the whole meaning.

The PDF salvage reads the command names out of export.ts instead of restating them, so a renamed command is checked at its new name rather than quietly passing.

Coverage holes this PR does not close

Deleting these files removes no detection, but it does remove the appearance of it. Four subjects now have no test at all, and each needs an executable one:

  • Preview/editor scroll sync. getScrollSyncPositionFromPixels and getScrollTopForSyncPosition are pure functions of three numbers, currently declared inside MarkdownViewer.svelte and Editor.svelte where nothing can import them. Moving the pair to src/lib/utils/scrollSync.ts would make the whole subject unit-testable, including both defects above.
  • revealFoldsAround / foldToggleFor in FindBar.svelte. These are DOM walks; foldMeasurementBatching.test.ts already drives observeFoldLayout through a recording stand-in for the DOM, and the same technique applies here.
  • exportAsPdf. export.ts is importable and already covered behaviourally for HTML export (exportFoldParity, exportRichContent). The dropped await above would be caught by an equivalent test with a stubbed invoke/save.
  • reloadFromDisk's dirty-buffer guard. documentSession.canCloseTab is covered behaviourally by truncatedBufferGuard; the reload path that calls it is not, because it lives in the component.

Verification

  • npm test 524 pass / 0 fail (was 562); npm run check 0 errors; npm run build clean; cargo test 144 pass.
  • 199 assertions removed with the deleted files; the salvage adds 5 tests back.
  • Every mutation the suite caught before, it still catches. Re-run after deletion: breadcrumb → sessionRestoreResilience; snapshot discard → windowStateRestore; task marker → renderProtocol; fold heights → foldMeasurementBatching; fold styles → foldLayout; window tag → windowTags; whitespace → editorOptionWiring; cursor listener → scrollSyncInput; print highlight → printFindHighlight.
  • The three control mutations all still caught: sanitizer stops forbidding <style>exportSanitize + previewSanitize; lossy-decode save guard inverted → checkedReadMigration + externalChangeReload + pathIdentityCaseFolding + truncatedBufferGuard; checkbox toggle writes the wrong line → truncatedBufferGuard.
  • scripts/sourceTree.ts is untouched — none of the deleted files imported it (its only consumers are previewSanitize, renderPipelineConvention and singleImplementationConvention).
  • package.json: test:settings-scroll is removed (both its files are gone); test:workflows and test:frontmatter drop the deleted entries.

🤖 Generated with Claude Code

@PathGao
PathGao force-pushed the chore/drop-tests-that-only-detect-renames branch from 2b5e7fe to 495336d Compare August 3, 2026 09:11
Measured against injected defects, these 14 files detect that a specific line
was edited and nothing else. Each one stayed green while a real defect in its
own stated subject was live; four of them are the only file that greps the line
they pin, so the catch they do provide is the rename detector #418 rules out,
not coverage.

Four assertions inside them were the exception — they pin something no compiler
can see (a Tauri command name, a locale's own dictionary entry, a CSS duration,
an `async fn` whose absence only deadlocks on Windows). Those move into
surviving files rather than being lost:

  findCollapsedMatches   FOLD_TRANSITION_MS vs the styles.css transition
                         -> foldLayout.test.ts
  toolbarCustomization   two per-locale translation tests (they import and run
                         the dictionary) -> i18nCoverage.test.ts
  windowsPdfExport       invoke() name <-> generate_handler! registration
                         -> macosPdfExport.test.ts
  tabContextMenuIsolation  create_transfer_window must stay `async`
                         -> windowOrganization.test.ts

Five files from the same list are kept: each was measured to catch a real
defect that nothing else catches. See the pull request for the per-file table.

562 -> 524 tests; 199 assertions removed, 5 tests added back by the salvage.
Every mutation the suite caught before it still catches, including the three
controls (sanitizer `<style>`, lossy-decode save guard, checkbox toggle line).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@PathGao
PathGao force-pushed the chore/drop-tests-that-only-detect-renames branch from 495336d to 47b9bd6 Compare August 3, 2026 09:30
@PathGao
PathGao merged commit e196547 into master Aug 3, 2026
4 checks passed
@PathGao
PathGao deleted the chore/drop-tests-that-only-detect-renames branch August 3, 2026 10:04
PathGao added a commit that referenced this pull request Aug 3, 2026
Scroll sync had 23 assertions and no coverage. The defect that set the sync
threshold to a value which disabled sync outright left every one of them green,
because they read Editor.svelte as text; both files were deleted in #433, so the
behaviour is currently untested.

The cause is structural: `node --test` cannot import a `.svelte` file, so the
only thing a test can do to logic living inside one is grep it. The two
functions that decide where the other pane scrolls to are pure arithmetic —
`getScrollSyncPositionFromPixels` and `getScrollTopForSyncPosition` read nothing
but their arguments — so they can simply leave the component, the same move that
produced `documentSession` and `windowSession`.

They were also duplicated. Both functions plus their `clampScrollRatio` helper
existed byte for byte in Editor.svelte and MarkdownViewer.svelte: two private
copies of one formula, invisible to each other and to the compiler. Both call
sites now import `src/lib/utils/scrollSync.ts`, whose body is the moved code
verbatim apart from `export` (md5 of all three blocks, de-indented: 31ab3110).

scripts/scrollSync.test.ts imports and runs it. The cases are stated as a
mapping between two panes with different proportions — the editor spends 20% of
its scroll range on front matter, the preview 10% — because that asymmetry is
the reason the position carries a section instead of a single ratio. 13 injected
defects, 13 caught, including both spellings of "sync does nothing".

540 -> 552 tests.

Co-authored-by: PathGao <gaoyanbo@gaoyanbodeMacBook-Air.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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