test(frontend): add unit test coverage for ContextManager and ObservableContextManager#6474
test(frontend): add unit test coverage for ContextManager and ObservableContextManager#6474eugenegujing wants to merge 1 commit into
Conversation
…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.
Automated Reviewer SuggestionsBased on the
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
ContextManagertests for stack semantics (getContext,prevContext,withContextrestoration/return value behavior, nesting, and isolation between separately created managers). - Added
ObservableContextManagertests 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.
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 throughJointGraphWrapper. The module exports theContextManagerandObservableContextManagerclass 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
ContextManagertests cover the context-stack semantics:getContextreturns the current context,prevContextreturns the previous one and throws in the default context,withContextexposes 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
ObservableContextManagertests 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 nestedwithContextcalls, 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
finallyblocks when a nested callable throws, a late subscriber receives no earlier events because the streams are plainSubjects with no replay,prevContextis valid inside the enter subscriber, re-entering the same context value still pushes a new stack frame, andwithContextreturns 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)