fix: preserve existing export documents and assets - #84
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Execute T1-T2 of the 1.0.0 release readiness plan: protect all outputs from silent overwrite and reproduce the confirmed attachment-corruption defect with a persistent fixture.
T1 — Persistent fixture and corruption regression
src/test-support/memory-vault.ts: an in-memory vault whose writes persist across runs, with real mockTFileinstances, text/binary storage, strict create/modify semantics (rejects duplicate creation, wrong-kind modification, aliases binaries), and a metadata cache limited to the fixture's literal wiki links.src/export/ExportIntegrity.test.tsend-to-end test using the real runner, collector, rewriter and writer. Before the fix it failed exactly as planned: after two sequential single-note exports with overwrite disabled,exports/assets/img.pngcontained[2]instead of[1].T2 — Protect all outputs
OutputWriternow takes the overwrite policy in its constructor (defaulttruepreserves existing callers). External writes use the exclusivewxflag when overwrite is disabled; vault writes reject an existing destination and onlycreate—modifyrequires overwrite enabled. Conflicts raise an explicitOutput already existserror.copyBinaryFileroutes throughwriteBinary(single policy implementation) and throwsAttachment source not foundfor missing sources instead of silently skipping.ExportRunnerrelocates a single-file export whenever anything occupies its output root (including an existing empty directory), so earlier exports keep their documents, attachments and links intact.export-report.mdname collisions, late-appearing destinations, explicit overwrite, and missing attachments.Also:
eslint.config.mtsdisablesobsidianmd/no-nodejs-modulesfor test files (tests run under vitest in Node and are never bundled).Validation
npx vitest run src/export/ExportIntegrity.test.ts src/export/OutputWriter.test.ts src/export/ExportRunner.test.ts src/export/ExportPlan.test.ts src/export/LinkRewriter.test.ts— 145/145npm test— 378/378 (baseline 360 + 18 new)npm run lint:obsidian-warnings— exit 0npm run build— exit 0