fix(#248 F1): remove dead intentional-clear escape hatch from empty-guard

Round-1 review F1 (maintainer decision: variant A). The store-side
empty-guard's `context?.intentionalClear === true` branch was dead:
`intentionalClear` is never set in production (connection context is
{user, actor, aiChatId}); it appeared only in the guard and a hand-injected
spec, so the guard already blocked empty-over-non-empty unconditionally.

- persistence.extension.ts: drop the dead branch; the guard now simply
  skips empty-over-non-empty, full stop. Reference issue #251 (real
  intentional-clear UX) in the comment where the branch was.
- persistence-store.spec.ts: remove the misleading "persists an intentional
  clear" escape-hatch test (false coverage — green only because the flag was
  injected by hand). Real guard tests (empty-over-empty allowed,
  empty-over-non-empty blocked, etc.) kept.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
claude code agent 227
2026-06-28 23:45:45 +03:00
parent 78953cf775
commit 78cc019492
2 changed files with 12 additions and 33 deletions

View File

@@ -210,8 +210,8 @@ describe('PersistenceExtension.onStoreDocument — Approach-A boundary snapshot'
// but not the STORE path, so an empty doc (a client/agent glitch, a bad
// merge, an emptying transclusion) was written straight over the page and the
// content was wiped silently. The store-side empty-guard now skips the write
// when the incoming doc is empty and the stored page is non-empty, unless an
// explicit intentional-clear signal is present.
// when the incoming doc is empty and the stored page is non-empty. A real
// intentional-clear UX is tracked separately in issue #251.
it('does NOT overwrite non-empty content with a momentarily-empty live doc (persist-6)', async () => {
const emptyDoc = { type: 'doc', content: [{ type: 'paragraph' }] };
const document = ydocFor(emptyDoc);
@@ -229,29 +229,6 @@ describe('PersistenceExtension.onStoreDocument — Approach-A boundary snapshot'
expect(historyQueue.add).not.toHaveBeenCalled();
});
// persist-6 — a legitimate clear is NOT broken: with the explicit
// intentional-clear signal, emptying a non-empty page still persists.
it('persists an intentional clear of a non-empty page (persist-6 escape hatch)', async () => {
const emptyDoc = { type: 'doc', content: [{ type: 'paragraph' }] };
const document = ydocFor(emptyDoc);
pageRepo.findById.mockResolvedValue({
...persistedHumanPage('IGNORED'),
content: doc('IMPORTANT RICH CONTENT'),
});
await ext.onStoreDocument({
documentName: `page.${PAGE_ID}`,
document,
context: {
user: { id: USER_ID, name: 'Alice' },
actor: 'user',
intentionalClear: true,
},
} as any);
expect(pageRepo.updatePage).toHaveBeenCalledTimes(1);
});
// persist-6 — a brand-new / already-empty page is unaffected: an empty store
// over empty stored content is not blocked (it short-circuits as unchanged).
it('does not block an empty store over an already-empty page (persist-6)', async () => {