Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
applyRestore: whole-snapshot removal keys on effective keepLive, not class (#722)
nyblnetbc074b8ebd3c
diff --git a/kernel/src/docfields.ts b/kernel/src/docfields.tsindex 2ff362ab..7300fe92 100644--- a/kernel/src/docfields.ts+++ b/kernel/src/docfields.ts@@ -95,10 +95,13 @@ export interface RestoreRules {* removed. A PROJECTION snapshot — one that legitimately omits fields it still* has — MUST pass FALSE: forget it and those fields are REMOVED, so its failure* is data loss, not exposure. Under FALSE an absent field keeps the live- * value. A HISTORY field- * keeps live when absent either way, and the identity/mode/capability floor is- * unchanged. Only 'recover' is affected — 'back' already drops an absent- * field. (maintainer ruling 2026-10-15: whole is the default.) */+ * value. This keys on the EFFECTIVE keepLive, not the class: a history field an+ * app OVERRODE to 'follows' (e.g. comments) is treated as content, so a deleted+ * comment stays deleted. A history field left at its default 'live' keep+ * (revisions, signatures) keeps live when absent either way, and the+ * identity/mode/capability floor is unchanged. Only 'recover' is affected —+ * 'back' already drops an absent field. (maintainer ruling 2026-10-15: whole is+ * the default.) */readonly wholeSnapshot?: boolean}@@ -107,8 +110,9 @@ export interface RestoreRules {* - a 'follows' field takes `incoming` ('back': absent means dropped; 'recover':* absent means dropped too for a WHOLE snapshot — the default, since a* recovery snapshot is contentOnly(doc) and an absent field was deleted — but- * absent keeps live for a PROJECTION (wholeSnapshot:false) and for a HISTORY- * field either way);+ * absent keeps live for a PROJECTION (wholeSnapshot:false). This covers a+ * history field OVERRIDDEN to 'follows' (e.g. comments): it restores like+ * content, so a deleted one stays deleted on a whole snapshot;* - a 'live' field keeps the live value, EXCEPT a 'live' history field on* 'recover', which uses its recover hook, or (no hook) follows incoming when* present and keeps live when absent.@@ -148,10 +152,14 @@ export function applyRestore<T extends object>(if (kl === 'follows') {if (I[k] !== undefined) out[k] = I[k]// On 'recover', an absent follows-field keeps live ONLY for a PROJECTION- // snapshot (wholeSnapshot:false) or a HISTORY field. In a WHOLE snapshot- // (the default), an absent content or unknown field means the user DELETED- // it, so it stays removed — not resurrected.- else if (direction === 'recover' && L[k] !== undefined && (!whole || cls === 'history')) out[k] = L[k]+ // snapshot (wholeSnapshot:false). This keys on the EFFECTIVE keepLive, not+ // the class: a field reaches here because it behaves like content for+ // restore — content, unknown, AND a history field an app OVERRODE to+ // 'follows' (e.g. comments). In a WHOLE snapshot (the default) its absence+ // means the user DELETED it, so it stays removed — not resurrected. (A+ // history field left at its default 'live' keep is handled below, where+ // absent keeps live either way.)+ else if (direction === 'recover' && L[k] !== undefined && !whole) out[k] = L[k]continue}// 'live'diff --git a/scripts/test-restore.ts b/scripts/test-restore.tsindex b41072f5..1b07341a 100644--- a/scripts/test-restore.ts+++ b/scripts/test-restore.ts@@ -87,19 +87,22 @@ H('recover (crash): the newer snapshot wins content AND history; identity stillok((r.comments as Rec)?.t1 === 'incoming', 'comments follow the snapshot on recover')}-H('recover of a WHOLE snapshot (the default): a deleted content/unknown field stays removed')+H('recover of a WHOLE snapshot (the default): a deleted field stays removed — by EFFECTIVE keepLive, not class'){// Every app's recovery snapshot is contentOnly(doc) — the WHOLE document minus// capability — so an absent field means the user DELETED it before the crash.- // wholeSnapshot defaults true, so a 'follows' content or unknown field absent- // from the snapshot is REMOVED, not resurrected. A HISTORY field still keeps- // live. (Regression #701 introduced; maintainer ruling 2026-10-15.)+ // wholeSnapshot defaults true. Removal keys on EFFECTIVE keepLive, not class:+ // an effective-'follows' field (content, unknown, AND a history field OVERRIDDEN+ // to 'follows' like comments) absent → REMOVED; a history field at its default+ // 'live' keep (revisions) absent → kept live. (comments is the case security+ // required: a deleted comment/redaction must not resurrect and ride the next+ // shared copy. Regression first introduced in #701, partly fixed in #716.)const inc = incoming(); delete inc.body; delete inc.mystery; delete inc.revisions; delete inc.commentsconst r = applyRestore(live(), inc, 'recover', RULES) as Recok(!('body' in r), 'a CONTENT field the user deleted stays removed (not brought back)')ok(!('mystery' in r), 'an UNKNOWN field absent from the whole snapshot is removed too')- ok(eq(r.revisions, live().revisions), 'but a HISTORY field absent keeps the live value (trail/revisions rule unchanged)')- ok((r.comments as Rec)?.t1 === 'live', 'and a history-class follows field (comments) absent keeps live')+ ok(!('comments' in r), 'an OVERRIDDEN history field (comments, keepLive follows) deleted stays removed')+ ok(eq(r.revisions, live().revisions), 'but a DEFAULT-live history field (revisions) absent keeps the live value')}H('recover of a PROJECTION snapshot (wholeSnapshot:false): absent keeps live')@@ -107,10 +110,11 @@ H('recover of a PROJECTION snapshot (wholeSnapshot:false): absent keeps live')// An incoming that legitimately omits fields it still has — a projection — must// not have those fields removed. The caller opts out of the whole-doc default.const PROJ: RestoreRules = { ...RULES, wholeSnapshot: false }- const inc = incoming(); delete inc.body; delete inc.mystery; delete inc.revisions+ const inc = incoming(); delete inc.body; delete inc.mystery; delete inc.revisions; delete inc.commentsconst r = applyRestore(live(), inc, 'recover', PROJ) as Recok(r.body === 'live body', 'a content field absent from a PROJECTION keeps live (never wiped)')ok(r.mystery === 'live-x', 'an unknown field absent from a projection keeps live')+ ok((r.comments as Rec)?.t1 === 'live', 'an overridden-to-follows history field (comments) absent from a projection keeps live')ok(eq(r.revisions, live().revisions), 'and history keeps live either way')}