Skip to content

test(frontend): add unit test coverage for ContextManager and ObservableContextManager#6474

Open
eugenegujing wants to merge 1 commit into
apache:mainfrom
eugenegujing:test/context-manager-spec
Open

test(frontend): add unit test coverage for ContextManager and ObservableContextManager#6474
eugenegujing wants to merge 1 commit into
apache:mainfrom
eugenegujing:test/context-manager-spec

Conversation

@eugenegujing

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

This PR adds unit test coverage for frontend/src/app/common/util/context.ts, which previously had no spec and was only exercised implicitly through JointGraphWrapper. The module exports the ContextManager and ObservableContextManager class factories that back the workflow editor's context-stack behavior, and this PR locks that behavior down with explicit assertions without changing any production code.

The ContextManager tests cover the context-stack semantics: getContext returns the current context, prevContext returns the previous one and throws in the default context, withContext exposes the entered and previous contexts to its callable and restores the previous context afterwards, the callable's return value is forwarded, the context is still restored (and the error re-thrown) when the callable throws, nested calls restore each level, and separately created managers keep isolated stacks.

The ObservableContextManager tests cover the enter, exit, and change-context streams: each emits the correct [exiting, entering] tuple, events fire after the stack has been updated, and ordering is correct across nested withContext calls, including the case where the callable throws.

Edge cases are covered as well: object-reference contexts are preserved by identity through the stack and in the emitted tuples, both levels unwind via their finally blocks when a nested callable throws, a late subscriber receives no earlier events because the streams are plain Subjects with no replay, prevContext is valid inside the enter subscriber, re-entering the same context value still pushes a new stack frame, and withContext returns falsy callable results unchanged.

Any related issues, documentation, discussions?

Closes #6442

How was this PR tested?

All 23 tests pass via ng test --include='src/app/common/util/context.spec.ts', and no production code is modified.

Was this PR authored or co-authored using generative AI tooling?

Co-authored using Claude Code(Fable 5)

…bleContextManager

Add a spec for frontend/src/app/common/util/context.ts, which previously had no test and was only exercised implicitly through JointGraphWrapper.

The tests cover the context-stack semantics (getContext, prevContext, and withContext restoring the previous context even when the callable throws) and the enter, exit, and change-context streams of ObservableContextManager, asserting the correct [exiting, entering] tuples and event ordering across nested and sequential calls.

They also cover edge cases: object-reference contexts preserved by identity, both levels unwinding on a nested throw, no replay for late subscribers, prevContext inside the enter subscriber, re-entering the same context value, and falsy callable return values.

No production code is modified.
@github-actions github-actions Bot added the frontend Changes related to the frontend GUI label Jul 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • No candidates found from git blame history.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.18%. Comparing base (aa0bc44) to head (288fff9).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #6474   +/-   ##
=========================================
  Coverage     70.17%   70.18%           
  Complexity     3388     3388           
=========================================
  Files          1142     1142           
  Lines         44844    44844           
  Branches       4949     4949           
=========================================
+ Hits          31471    31474    +3     
+ Misses        11739    11735    -4     
- Partials       1634     1635    +1     
Flag Coverage Δ *Carryforward flag
access-control-service 70.00% <ø> (ø) Carriedforward from aa0bc44
agent-service 76.76% <ø> (ø) Carriedforward from aa0bc44
amber 66.67% <ø> (ø) Carriedforward from aa0bc44
computing-unit-managing-service 9.97% <ø> (ø) Carriedforward from aa0bc44
config-service 52.30% <ø> (ø) Carriedforward from aa0bc44
file-service 65.63% <ø> (ø) Carriedforward from aa0bc44
frontend 68.93% <ø> (+0.02%) ⬆️
notebook-migration-service 78.94% <ø> (ø) Carriedforward from aa0bc44
pyamber 91.19% <ø> (ø) Carriedforward from aa0bc44
workflow-compiling-service 55.14% <ø> (ø) Carriedforward from aa0bc44

*This pull request uses carry forward flags. 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:
  • 📦 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

This PR adds a new unit test suite for frontend/src/app/common/util/context.ts, specifically covering the ContextManager and ObservableContextManager class factories that implement the workflow editor’s context-stack and related RxJS event streams.

Changes:

  • Added ContextManager tests for stack semantics (getContext, prevContext, withContext restoration/return value behavior, nesting, and isolation between separately created managers).
  • Added ObservableContextManager tests validating enter/exit/change stream emissions (payloads, ordering, stack-update timing, exception unwinding, and late-subscriber non-replay behavior).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

frontend Changes related to the frontend GUI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add unit test coverage for ContextManager and ObservableContextManager

3 participants