fix(core): make hard delete owner-only in ScopedStack#75
Merged
Conversation
Closes the item-1 carve-out from #59: ScopedStack.delete() forwarded opts straight to the adapter, so the write bit and delete-own/delete-any grants could reach { hard: true } and permanently destroy a record and its version history. Hard delete now requires being the stack owner; everyone else is limited to (recoverable) soft delete. The remaining #59 work items (undelete API, association versioning, the full recoverability trust-model writeup) are tracked separately in #60 and #61 and are out of scope here.
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
Closes the first, unblocked work item from #59.
ScopedStack.delete()calledrequireDeletable()(checks the record-levelwritebit or adelete-own/delete-anygrant) and then forwardedoptsstraight to the adapter — so awrite: trueholder, or adelete-anygrant holder, could pass{ hard: true }and permanently destroy the record and its version history. There was no test exercising this path.Per #59's stated trust model — "anything a write-holder does, the owner can undo" — hard delete has no undo, so it doesn't belong behind any delegated-access mechanism. This PR makes hard delete owner-only:
ScopedStack.delete()now throwsStackPermissionErrorwhen a non-owner passes{ hard: true }, regardless of whether they'd otherwise be authorized to delete (write bit or grant).asEntity()/ScopedStackwrapper (plainStackis unscoped and trusted-by-definition per Single-writer storage model: durability fixes for adapter-local + spec/README guidance on multi-app topology #45).Out of scope (tracked separately)
#59 has other work items — an undelete API, versioned/audited association changes, and the full "recoverability trust model" spec writeup — that are genuine prerequisites tracked as their own open issues (#60, #61) and don't exist in code yet. This PR only lands the carve-out that #59 itself flags as having no dependencies.
Test plan
delete-anygrant holder cannot hard-deletepnpm --filter @haverstack/core test— 192 tests passingpnpm --filter @haverstack/core typecheck— cleanpnpm --filter @haverstack/core lint— cleanprettier --checkon changed files — cleanRefs #59, #60, #61, #45
Generated by Claude Code