Skip to content

test: board-frame guards slice fixed character windows #384

Description

@FlyM1ss

dashboard/backend/tests/test_frontend_board_frame.py verifies several call-site
facts by slicing a fixed number of characters forward from an index() hit:

call = _SRC[_SRC.index("createEndpointLabelPlugin({") :][:800]
assert "currentChartView === 'absolute'" in call

Six sites do this — [:800], [:1000], [:400], [:700] (×2), [:900] — and
every assertion inside them is positive (in).

Why the number is unsafe in both directions. The windows are hand-tuned to
land just past the last option of the call they are reading:

  • Too short: add a comment or an option to the call and the target slides out of
    the window. The assertion fails, but the failure says "the tab does not inject
    hoveredDatasetIndex" when the tab plainly does. Loud, but false.
  • Too long: the window runs past the call's closing paren into whatever follows,
    and the assertion can then pass on text from an unrelated function. Silent.

Neither bound is checked, and the file already knows this — one site carries the
comment "it needs the wider window to stay inside the same call site rather than
spilling into whatever follows it."
That is a defended magic number, not a bound.

Fix. The module already solves the equivalent problem for functions:
_extract_function brace-matches by name. Add the paren-matching twin — find
createEndpointLabelPlugin({, walk to its balanced closing paren, and assert
against exactly that call site. Then the window is the call, the six magic
numbers go away, and both failure directions become impossible rather than
improbable.

Found during the whole-branch review of the nof1 board frame work; no current
test is known to be wrong today.


Surfaced by the whole-branch review of #382.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions