Skip to content

Fix flaky strRemovePrefix property test asserting wrong invariant#290

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-flaky-property-test-string-ops
Draft

Fix flaky strRemovePrefix property test asserting wrong invariant#290
Copilot wants to merge 2 commits intomainfrom
copilot/fix-flaky-property-test-string-ops

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 10, 2026

Bug Fix

What was the bug?

The property at tests/stats/string_ops.test.ts:356 asserted an invariant that strRemovePrefix does not satisfy. strRemovePrefix mirrors Python's str.removeprefix() and strips at most one leading occurrence, but the test claimed the result must never start with prefix when str did:

return !(result.startsWith(prefix) && str.startsWith(prefix));

Any input where the prefix repeats at the start (e.g. str = "aa", prefix = "a") is a legitimate counterexample. The reported ["",""] counterexample was two control characters (file separator, \x1c) that render as empty in the console — control characters were a red herring; the underlying invariant was simply wrong. Flakiness depended on whether shrinking happened to land on such inputs for a given seed.

How did you fix it?

Replaced the property with the actual contract of str.removeprefix(): when the prefix is present, exactly one leading occurrence is stripped; otherwise the string is returned unchanged.

fc.property(fc.asciiString(), fc.asciiString({ minLength: 1 }), (str, prefix) => {
  const result = strRemovePrefix(str, prefix);
  return str.startsWith(prefix) ? prefix + result === str : result === str;
}),

The implementation in src/stats/string_ops.ts was already correct and is unchanged.

Testing

Ran bun test tests/stats/string_ops.test.ts repeatedly; all 54 tests pass deterministically.

Co-authored-by: mrjf <180956+mrjf@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix flaky property-based test in string_ops.test.ts with control characters Fix flaky strRemovePrefix property test asserting wrong invariant May 10, 2026
Copilot AI requested a review from mrjf May 10, 2026 13:49
Copilot finished work on behalf of mrjf May 10, 2026 13:49
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.

Flaky property-based test in string_ops.test.ts with control characters

2 participants