Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First digit dropped from path?! #4339

Closed
hsommerlandreason opened this issue Oct 20, 2023 · 3 comments
Closed

First digit dropped from path?! #4339

hsommerlandreason opened this issue Oct 20, 2023 · 3 comments

Comments

@hsommerlandreason
Copy link

🐛 Bug Report

I have come across a hyperstrange bug.
When I try to replay a test with a path fast-check complains that it is a malformed path but it reports the path with the first digit dropped.

To Reproduce

I run the tests and it complains about:

  ● Cleanup (with seed=481321175)

    Property failed after 41 tests
    { seed: 481321175, path: "40:1:0:2:2:2:2:2:4:4:4:4:4:4:4:6:6:6:7:6:7:8:7:9:9:9:9:9:9:9:9:9:9:9:9:9:10:10:10:10:10:10:10
:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10
:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10", endOnFailure: true }
    Counterexample: [{"pairs":[["b","0.0.0"],["a","0.0.0"],["b","0.0.00"],["ba","0.0.0"],["a","0.0.0f0"]],"isIgnored":false
,"gen":[["b","0.0.00"]]}]
    Shrunk 113 time(s)
    Got error: expect(sinon.spy).toBeCalledWith()

I say gosh darnit and change the test to:

const _path = "40:1:0:2:2:2:2:2:4:4:4:4:4:4:4:6:6:6:7:6:7:8:7:9:9:9:9:9:9:9:9:9:9:9:9:9:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10"

test.prop({
  pairs: fc.uniqueArray(
    fc.tuple(
      fc
        .stringOf(fc.constantFrom('a', 'b', '.'), { minLength: 1 })
        .filter((s) => s !== '__proto__' && s.trim() !== ''),
      fc.stringMatching(/^([0-9])\.([0-9]+)\.([0-9]+)(?:([dabf])([0-9]+))?$/)
    ),
    { minLength: 2, comparator: deepEqual }
  ),
  isIgnored: fc.boolean(),
  gen: fc.gen(),
}, {path: _path})('Cleanup', async ({ pairs, isIgnored, gen }) => { .... }

I then run:

grandmother@...<fix/device-chaos>$ npx jest --seed=481321175 testyfile.spec.ts 
  ● Cleanup (with seed=481321175)

    Unable to replay, got wrong path=0:1:0:2:2:2:2:2:4:4:4:4:4:4:4:6:6:6:7:6:7:8:7:9:9:9:9:9:9:9:9:9:9:9:9:9:10:10:10:10:10
:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10
:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10:10

      at pathWalk (../node_modules/fast-check/lib/check/runner/utils/PathWalker.js:17:19)
      at applyPath (../node_modules/fast-check/lib/check/runner/Runner.js:50:38)
      at check (../node_modules/fast-check/lib/check/runner/Runner.js:68:11)
      at Object.assert (../node_modules/fast-check/lib/check/runner/Runner.js:77:17)
      at Object.<anonymous> (../node_modules/@fast-check/jest/lib/internals/TestWithPropRunnerBuilder.js:43:18)

Now this is the odd part: got wrong path=0:1:0......
The path I provided begins with 40:1:0......
Where did the 4 go?🤷‍♂️

Your environment

Packages / Softwares Version(s)
fast-check 3.13.1
node v18.16.0 (reproducable in node 20 as well)
TypeScript 4.9.5
@dubzzz
Copy link
Owner

dubzzz commented Oct 20, 2023

I can repro! Thanks a lot for the report, I'll investigate it!

@dubzzz
Copy link
Owner

dubzzz commented Oct 20, 2023

Seems to be a display issue of the path. But the path seems to be well interpreted.

By any luck, do you perform side effects on pairs?

I think I got the problem: gen!

Well I should update the documentation, but for now it's not possible to replay gen properly given the fact that replaying it would require to re-run everything. In other words, when replaying with something implying gen you should limit the path to its first element only, 40 in your case.

So far I have no way to replay it. But I must definitely make it clearer in the doc and ideally in the reported errors by just stopping at 40.


Workaround:

const _path = "40";

On my side I'll log myself the following todos:

  • Explicitly tell in the doc that gen does not support replay with deep path
  • Find a way to trim the path at report time or tell the user to do so when there is a gen somewhere
  • Better report path error and do not replace first element by 0 in the reported error
  • Support replay on gen with deep paths (hardly feasible but logging it just in case)

I'll open the specific issues later.

dubzzz added a commit that referenced this issue Oct 21, 2023
Related to #4339

Following that PR, the path will start being properly reported whenever it cannot be really leveraged for the replay.
dubzzz added a commit that referenced this issue Oct 21, 2023
Related to #4339

Following that PR, the path will start being properly reported whenever it cannot be really leveraged for the replay.
dubzzz added a commit that referenced this issue Oct 22, 2023
@dubzzz
Copy link
Owner

dubzzz commented Oct 25, 2023

Closing the issue for now.

The bug itself was about the path being wrongly reported. For now support for replays on gen is out-of-scope. I filled an issue to track the need but no short term plan to prioritize it given the huge impacts it may have on the API of arbitraries.

@dubzzz dubzzz closed this as completed Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants