Skip to content

fix(patterns): Update containerHasSplit(copyArray, ...) to return copyArray results#3065

Open
gibson042 wants to merge 7 commits intomasterfrom
gh-3064-containerhassplit-hardened-results
Open

fix(patterns): Update containerHasSplit(copyArray, ...) to return copyArray results#3065
gibson042 wants to merge 7 commits intomasterfrom
gh-3064-containerhassplit-hardened-results

Conversation

@gibson042
Copy link
Member

Fixes #3064

Description

  • adds test coverage for containerHasSplit
  • hardens copyArray results from containerHasSplit so they actually have pass style "copyArray"
  • improves typing to avoid attempted mutation of a CopyArray (which is defined to be immutable)
  • refactors some code supporting containerHasSplit

Security Considerations

None known.

Scaling Considerations

n/a

Documentation Considerations

n/a

Testing Considerations

Compatibility Considerations

CopyArrays are already claimed by documentation to be immutable, so this shouldn't affect anything (and doesn't AFAICT).

Upgrade Considerations

I think this fix falls below the level of inclusion in NEWS.md, but could be persuaded out of that position.

Comment on lines +79 to +95
const specimen = harden([1, 'foo', 2, 'bar']);

test('split first match from copyArray', testContainerHasSplit, {
specimen,
pattern: M.string(),
bound: 1n,
expectAccepted: ['bar'],
expectRejected: [2, 'foo', 1],
});

test('split first two matches from copyArray', testContainerHasSplit, {
specimen,
pattern: M.string(),
bound: 2n,
expectAccepted: ['bar', 'foo'],
expectRejected: [2, 1],
});
Copy link
Member Author

@gibson042 gibson042 Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@erights Whether or not this was intentional, we should reconsider the direction for CopyArray scanning. It makes sense for CopySet and CopyBag to start at the end because of their ordering constraints, but I think CopyArray scanning should start at the beginning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. But I won't get to it anytime soon, so putting this in Draft until then. Unless you wanna give it a try?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is ready for review now to hopefully merge soon (and in particular ahead of #3061), and isn't changing that behavior. But since you're amenable to it, I've opened #3067 as a followup.

Copy link
Member

@michaelfig michaelfig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff! Thanks for addressing this (presuming you're heading for CopyArray = ReadonlyArray<Passable>).

Comment on lines +81 to +87
test('split first match from copyArray', testContainerHasSplit, {
specimen,
pattern: M.string(),
bound: 1n,
expectAccepted: ['bar'],
expectRejected: [2, 'foo', 1],
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is bound: 0n a relevant edge case to test?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the function is documented to require a minimum bound of 1n:

* @param {bigint} bound Must be >= 1n

But I have added 1d6b76e for hopefully propagating such documentation to https://docs.endojs.org/variables/_endo_patterns.containerHasSplit.html .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

containerHasSplit(copyArray, …) returns mutable in/out arrays

3 participants