Skip to content

Several related booleans represent richer state #5

Open

Description

@cblanquera

Timing: Follow-up after trial/3 merges into main; defer implementation until then.

Review baseline: Local trial/3 at a094418baf6388e3eeca23821df481a7f0a8751c. This branch is not yet on the remote. Source locations below refer to that snapshot and should be rechecked after merge.

Problem

account_keys accepts separate object, array, added, and removed booleans. Valid combinations depend on caller knowledge, while the signature permits contradictory combinations. No incorrect current call was established; this is a maintainability and invariant-expression concern.

Evidence

  • crates/lib/src/data/mutation.rs:190-198: call assembled from several state flags.
  • crates/lib/src/data/mutation.rs:231-288: branching over four booleans and container-transition state.

Acceptance criteria

  • Express meaningful container shape and mutation outcome through enums or another representation that makes invalid combinations difficult to construct.
  • Preserve accounting, overflow/error precedence, atomic mutation guarantees, and dense/sparse conversion behavior.
  • Verify representative insert/remove/no-change and object/array transition cases.
  • Keep genuinely independent capability flags as booleans; do not mechanically replace every collection of flags.

Code examples and suggested direction

Possible private state model:

#[derive(Clone, Copy, Debug)]
enum ContainerBefore {
    Missing,
    Object,
    Array,
}

#[derive(Clone, Copy, Debug)]
enum MembershipChange {
    Unchanged,
    Added,
    Removed,
}

Then replace the boolean bundle with meaningful inputs:

fn account_keys(
    before: ContainerBefore,
    membership: MembershipChange,
    final_length: usize,
    step: &Step,
    change: &mut Change,
) -> Result<()> {
    // Port the existing accounting rules through an exhaustive match.
    // The body must be implemented from the current decision table.
}

The signature is a design sketch, not complete compilable replacement code. Scalar traversal must still fail before accounting.

Activity

  1. cblanquera commented on Oct 26, 2026

    @cblanquera
    MemberAuthor

    Suggested investigation and fix notes

    Deferred until trial/3 is merged into main. Recheck the merged source and tests first. The snippets are examples/proposals, not an approved patch or a change to frozen contracts.

    1. Derive a decision table from Preparation::inspect before replacing flags: existing object/array/missing intermediate; membership added/removed/unchanged; final object/array; leaf versus ancestor; root versus nested container.
    2. Confirm what Unchanged means: membership can be unchanged even when a payload is replaced. Preserve separate payload accounting.
    3. Construct the enums where facts become known and pass them into account_keys. Avoid an enum-to-booleans-to-enum round trip or new validation that changes existing error precedence.
    4. Port rules one transition at a time. In particular, dense object→array removes numeric-key bytes; array→sparse object adds retained numeric-key bytes; missing removal must not create containers.
    5. Retain read-only planning followed by commit. Overflow/limit errors must leave both tree and cached totals unchanged.

    Observable regression example:

    use stackpress_lib::{Nest, Result};
    
    fn sparse_transition() -> Result<()> {
        let mut data = Nest::new();
        data.set_path("items.0", "a")?;
        data.set_path("items.1", "b")?;
        assert!(data.path("items").unwrap().as_array().is_some());
        data.remove_path("items.0")?;
        assert!(data.path("items.0").is_none());
        assert_eq!(data.path_as::<String>("items.1")?, Some("b".into()));
        Ok(())
    }

    Add boundary/accounting cases to existing data_contracts; run cargo test -p stackpress-lib --test data_contracts --locked. Independent capability booleans elsewhere are outside this focused refactor.

    Implementation workflow: After the merge, follow .agents/workflows/rust-programming.md: prove the affected behavior, complete the three test-verified review rounds, and record relevant formatting/lints/docs, feature/platform scope, and applicable development coverage. Preserve unrelated changes.

  2. cblanquera commented on Oct 26, 2026

    @cblanquera
    MemberAuthor

    Fixed on trial/3 in 644795f (merged as 64a5b70, task 00010 lane 1; not yet on main, so leaving open).

    • Mutation accounting now uses private container-shape and membership-change enums instead of four related booleans; checked-arithmetic order, atomic mutation plans and dense/sparse behavior are unchanged (existing budget-oracle tests rerun throughout).

    Coordinator-verified: fmt, Clippy -D warnings, Rustdoc -D warnings, cargo +1.96.0 check, 454 workspace tests, 856 doctests pass; lib production coverage 93.64%.

  3. added a commit that references this issue on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions