refactor(frontmatter): derive writability facets + predicate from one source - #290
Merged
Conversation
… source isWritable() and writabilityFacets were two hand-written enumerations of the same 'which facets gate writability' fact, tied only by a KEEP-IN-SYNC JSDoc comment. Adding a third writability input to isWritable() without extending writabilityFacets would silently reintroduce the stale aria-description bug PR #279 fixed (the reactive dependency list would stop covering a facet the predicate reads). Both now derive from a single polarity-tagged writabilityInputs table, so the predicate and its reactive dependency list stay in lockstep by construction. A new unit test pins the contract and goes red on polarity drift or a dropped dependency.
…est drive the list Review-cycle findings on the prior commit: - writabilityFacets was widened to a mutable Facet[] by .map(); type it readonly (and freeze the writabilityInputs row fields) so the derived list is as immutable as the old 'as const' tuple, preserving the drift guarantee. - The 'no dead entries' test asserted the same two combinations as the truth table without ever referencing writabilityFacets. Rewrite it to iterate the real list: flipping any one listed facet away from its writable value must break isWritable, so a facet listed but ignored by the predicate now fails.
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
isWritable()andwritabilityFacetsinreveal-state.tswere two independent hand-written enumerations of the same "which facets gate writability" fact, tied together only by a KEEP-IN-SYNC JSDoc comment — no compile-time or test-level enforcement. This mechanizes the sync so the two can no longer drift.Changes
writabilityInputstable ([{ facet, writableWhen }]) as the one source of truth.writabilityFacets(the reactivecompute()dependency list) andisWritable()(the predicate) from that table — adding a writability input is now one row, and both update by construction.test/webview/frontmatter/cm-frontmatter-writability.test.ts: pins theisWritabletruth table, assertswritabilityFacetscovers exactly the gating facets, and verifies no dead dependency entries. Verified non-vacuous (goes red on polarity drift).Related
isWritable()sync (drift guard) — review-cycle finding on PR fix(frontmatter): refresh the collapsed metadata block's aria hint on a read-only flip #279 (MEDIUM/82).aria-descriptionbug PR fix(frontmatter): refresh the collapsed metadata block's aria hint on a read-only flip #279 fixed.Test Plan
pnpm compilegreenpnpm test:unitgreen (4116 tests)