MatrixAI / Polykey-CLI

Polykey CLI - Open Source Decentralized Secret Sharing System for Zero Trust Workflows
https://polykey.com
GNU General Public License v3.0
6 stars 3 forks source link

Fix intermittent failure with `scanNode.test.ts` test #189

Closed tegefaulkes closed 4 months ago

tegefaulkes commented 4 months ago

Specification

This test fails randomly with the following.

FAIL tests/vaults/scanNode.test.ts (9.462 s)
  commandScanNode
    ✕ should return the vaults names and ids of the remote vault (8580 ms)
  ● commandScanNode › should return the vaults names and ids of the remote vault
    expect(received).toContain(expected) // indexOf
    Expected substring: "\"Vault1\\tzWzoHThRMYWF33HrkHEymA\\tclone\\nVault2\\tzXdvCXhde8jm7i4mK1TLJqL\\tpull,clone\\n\""
    Received string:    "\"Vault1\\tzWzoHThRMYWF33HrkHEymA \\tclone\\nVault2\\tzXdvCXhde8jm7i4mK1TLJqL\\tpull,clone\\n\""
      177 |         expect(result3.exitCode).toBe(0);
      178 |         expect(result3.stdout).toMatch(/Vault1\t.*\tclone/);
    > 179 |         expect(JSON.stringify(result3.stdout)).toContain(
          |                                                ^
      180 |           JSON.stringify(
      181 |             `Vault1\t${vaultsUtils.encodeVaultId(
      182 |               vault1Id,
      at Object.toContain (tests/vaults/scanNode.test.ts:179:48)

It seems to be entirely an errant space added to the output but it only happens sometimes.

Additional context

Tasks

  1. Find the root cause of the problem
  2. fix the problem
  3. Remove the // Fixme: temperamental problem with formatting the output. Fails sometimes due to an added space comment from scanNode.test.ts.
linear[bot] commented 4 months ago

ENG-327 Fix intermittent failure with `scanNode.test.ts` test

tegefaulkes commented 4 months ago

Seems that the failure is caused by test rigidity, we're expecting a fixed length vaultId, but in some cases the ID is 1 digit shorter. I wonder if it's just a multiformats thing. I'll check.

    Vault1  z6jf5pJ1G8ZEcXusXAxr9eM clone
    Vault2  zdmNxQGKbVfb4NGXgfmxJ1  pull,clone

Yeah, both of these IDs are 16 bytes wide, so multiformats will just create a shorter string for some values.

This means that I just need to make the test less rigid.

CMCDragonkai commented 4 months ago

Base 32 hex should always result in the same length. And the public key is always 32 bytes. Therefore having a different lengths generated is a bug. The test rigidity is required.

tegefaulkes commented 4 months ago

It's not HEX. Do you want to change the format? Right now it's base58btc.

CMCDragonkai commented 4 months ago

No I thought this was about Node IDs, I forgot.