Skip to content

CLUE-622: Fix flaky test--Keep Copy to Workspace disabled until the workspace document loads - #2987

Merged
kswenson merged 2 commits into
masterfrom
CLUE-622-copy-to-workspace-disabled-state
Sep 2, 2026
Merged

CLUE-622: Fix flaky test--Keep Copy to Workspace disabled until the workspace document loads#2987
kswenson merged 2 commits into
masterfrom
CLUE-622-copy-to-workspace-disabled-state

Conversation

@kswenson

Copy link
Copy Markdown
Member

What this fixes

Copy to Workspace could silently do nothing. With tiles selected in a Problems tab, clicking the button before the workspace document finished loading copied nothing — no error, no feedback, the click simply discarded. The window is short, so people rarely notice: they click again and it works. The Cypress regression suite clicks the instant the button looks actionable and hit the window often enough that the resulting failure was written off as flake.

After this change the button reports its true state. It stays disabled while there is nothing to copy into, and becomes enabled as soon as there is — so the click either works or is visibly unavailable.

Three defects, stacked

Each one hid the next, which is why this took a while to pin down:

  1. persistentUI.problemWorkspace.primaryDocumentKey is undefined for a window after load — no workspace document is registered to copy into yet.
  2. isButtonDisabled compared document?.key === primaryDocumentKey. A section toolbar has no document of its own, so while the key was also undefined this was undefined === undefined, and Copy to Workspace flipped to disabled. ToolbarButtonComponent.handleClick returns early when disabled, so the click was dropped silently.
  3. With that corrected the click reached handleCopyToWorkspace, which guards on primaryDocument?.content and returned without copying — silently again.

Why the test could not see it

The spec guarded the click with:

canvas.getCopyToWorkspaceButton().should('not.have.attr', 'disabled');

Toolbar buttons report their state via aria-disabled and never render a bare disabled attribute, so this assertion passed instantly regardless of the button's real state. Cypress never waited, and clicked straight into the window.

This check has been vacuous since it was added in April 2025 — the element was a <div> then, with no disabled attribute either. It is not fallout from the later accessibility work that made these buttons real <button> elements.

Changes

  • src/components/toolbar.tsx — require a primary document key before treating a document as the primary document, and keep Copy to Workspace disabled until a loaded primary document exists.
  • cypress/e2e/functional/document_tests/tiles_copy_test_spec.js — assert aria-disabled, so Cypress waits for the button to become actionable.
  • src/components/toolbar.test.tsx — unit tests pinning button state across three cases: no primary key, key set but not yet loaded, and loaded.

Verification

Check Result
Cypress spec loop, retries=0 4 of 6 runs failed before; 7 of 7 passed after
Full jest suite 3978 passed, 0 failures
npm run check:types, eslint clean

Both production changes are pinned: reverting the fix makes two of the new unit tests fail. The failure signature Found '22', expected '32' was confirmed to be exactly the no-copy state by removing the click entirely and getting the same count.

For the reviewer

This makes Copy to Workspace correctly disabled during a window on load where it previously appeared enabled. That is the intended behavior, but it is a visible change to button state, so it deserves an eye.

Jira: CLUE-622

🤖 Generated with Claude Code

https://claude.ai/code/session_01462X5PX8pREGYLLy9fSr6m

Clicking Copy to Workspace copied nothing when the primary workspace
document had not finished loading. The click was discarded silently, with
no error and no feedback.

Three defects stacked, each hiding the next:

- primaryDocumentKey is undefined for a window after load, so there is no
  workspace document registered to copy into.
- isButtonDisabled compared `document?.key === primaryDocumentKey`. A
  section toolbar has no document of its own, so while the key was also
  undefined the comparison was undefined === undefined and the button
  flipped to disabled; handleClick then dropped the click.
- Once the click got through, handleCopyToWorkspace returned without
  copying because primaryDocument had no content.

The cypress regression test could not see any of this. It guarded the
click with should('not.have.attr', 'disabled'), but toolbar buttons report
their state via aria-disabled and never render a bare disabled attribute,
so the assertion passed instantly and the click landed inside the window.
That check has been vacuous since it was added in April 2025, when the
element was still a div.

Require a primary document key before treating a document as the primary
document, and disable Copy to Workspace until a loaded primary document
exists to copy into. Assert aria-disabled in the spec so cypress waits for
the button to become actionable, and add unit tests covering no key, key
set but not yet loaded, and loaded.

CLUE-622

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01462X5PX8pREGYLLy9fSr6m
@kswenson kswenson changed the title Keep Copy to Workspace disabled until the workspace document loads CLUE-622: Keep Copy to Workspace disabled until the workspace document loads Aug 28, 2026
@kswenson
kswenson requested a balanced review from Copilot August 28, 2026 03:02
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.32%. Comparing base (4941cfd) to head (728bb45).
⚠️ Report is 17 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2987   +/-   ##
=======================================
  Coverage   86.31%   86.32%           
=======================================
  Files         994      994           
  Lines       56836    56840    +4     
  Branches    15056    15059    +3     
=======================================
+ Hits        49059    49065    +6     
+ Misses       7757     7755    -2     
  Partials       20       20           
Flag Coverage Δ
cypress ?
cypress-regression 71.18% <100.00%> (+<0.01%) ⬆️
cypress-smoke 41.17% <100.00%> (+<0.01%) ⬆️
jest 57.70% <80.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Keeps Copy to Workspace disabled until its destination document is loaded, preventing silently discarded copy actions.

Changes:

  • Corrects toolbar disabled-state logic for section toolbars and unloaded workspaces.
  • Adds unit coverage for primary-document lifecycle states.
  • Fixes Cypress to assert the actual aria-disabled state.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/components/toolbar.tsx Gates copying on a loaded primary document.
src/components/toolbar.test.tsx Tests toolbar states before and after document loading.
cypress/e2e/functional/document_tests/tiles_copy_test_spec.js Waits for the accessible enabled state before clicking.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@cypress

cypress Bot commented Aug 28, 2026

Copy link
Copy Markdown

collaborative-learning    Run #20204

Run Properties:  status check passed Passed #20204  •  git commit 728bb45839: docs: note that the section toolbar test config is synthetic
Project collaborative-learning
Branch Review CLUE-622-copy-to-workspace-disabled-state
Run status status check passed Passed #20204
Run duration 03m 41s
Commit git commit 728bb45839: docs: note that the section toolbar test config is synthetic
Committer Kirk Swenson
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 4
View all changes introduced in this branch ↗︎

@kswenson
kswenson requested a review from scytacki August 28, 2026 03:21
@kswenson kswenson changed the title CLUE-622: Keep Copy to Workspace disabled until the workspace document loads CLUE-622: Fix flaky test--Keep Copy to Workspace disabled until the workspace document loads Aug 28, 2026
@emcelroy
emcelroy self-requested a review September 1, 2026 20:20
@kswenson
kswenson removed the request for review from scytacki September 1, 2026 20:21

@emcelroy emcelroy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good 👍 A review generated with Claude only raised a few nits. Only one seemed at all worth mentioning, and even that is probably OK to ignore if you want. See below.

renderSectionToolbar builds copyConfig by hand (toolbar.test.tsx:175-181) including an edit button and passes it directly, bypassing myResourcesToolbar() and its filter. That's fine as a unit test of isButtonDisabled, and it does pin the guard. But the test name at line 240 could lead a later reader to believe section toolbars show an Edit button. A one-line comment noting the config is synthetic, and that production section toolbars filter Edit out, would prevent that.

Production section toolbars filter Edit out; the test includes it because it is
the only button that pins the primary-document-key requirement on its own.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JYg4b9bnjmAUkr4LrVaNNT
@kswenson
kswenson merged commit 8df31a0 into master Sep 2, 2026
27 checks passed
@kswenson
kswenson deleted the CLUE-622-copy-to-workspace-disabled-state branch September 2, 2026 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants