mattcasters opened a new pull request, #7872:
URL: https://github.com/apache/hop/pull/7872

   ## Summary
   
   Implements [issue #7719](https://github.com/apache/hop/issues/7719): when a 
pipeline unit test is selected in Hop GUI, its **Parameters & Variables** are 
applied to `HopGuiPipelineGraph.variables` so design-time actions use the same 
sample values as execution.
   
   Also hardens related unit-test / metadata create UX found while testing this 
feature.
   
   ### Unit test variables on the pipeline graph (#7719)
   
   When a unit test is **selected**, its `variableValues` are applied to the 
open pipeline graph variable space. That space is already used by:
   
   - Show input/output fields
   - Pipeline check
   - Transform dialogs / Get fields
   - Run configuration population (after the sticky-value fix below)
   
   Lifecycle:
   
   | Event | Behavior |
   |--------|----------|
   | Select unit test | Apply vars; set `__UnitTest_Run__` / 
`__UnitTest_Name__` on the graph |
   | Switch unit test | Clear previous applied keys, apply the new test |
   | Edit / save active test | Re-apply |
   | Detach / delete active / close pipeline | Clear applied keys |
   
   Helper: `UnitTestGraphVariables` tracks applied keys in the graph `stateMap` 
for clean switch/detach.
   
   This complements #7245 (unit test vars in the **run dialog**). Execution 
already applied vars in `ChangePipelineMetaPriorToExecutionExtensionPoint`; 
design-time did not.
   
   ### Switching unit tests and execution config
   
   Two issues made “test A vs test B with the same variable name” feel broken:
   
   1. Graph variables needed a reliable select/apply path (active graph lookup, 
flags on select, avoid combo re-entry).
   2. `PipelineExecutionConfiguration.getUsedVariables()` preferred **previous 
run dialog** values over the live graph variable space, so after running test A 
(`UNIT_TEST_VAR=value1`), switching to test B still sticky-filled `value1` into 
the next config.
   
   Fix: prefer live graph/project variables when present; still fall back to 
the previous dialog map for vars not in the live space. On run config build, 
reload the active unit test from metadata and re-apply graph vars so in-memory 
copies cannot go stale.
   
   ### Metadata create no longer “renames” an existing unit test
   
   Creating a unit test pre-fills a default name (`<pipeline> UNIT`). 
`MetadataEditor` treated that as `originalName`, so changing the name was a 
**rename**: save new name + **delete** the old name — often a real existing 
unit test.
   
   - `MetadataEditor.markAsNew()` on all create paths: suggested names are not 
a persisted identity
   - Create save rejects names that already exist (no silent overwrite)
   - After successful create/rename, `originalName` is set to the saved name
   - Default unit test names are unique (`… UNIT`, `… UNIT 2`, …)
   - Dropped a duplicate `HopGuiMetadataObjectCreated` fire after dialog save 
(editor save already fires it)
   
   ### Exclusive auto-open per pipeline
   
   Multiple unit tests for one pipeline could all have **Auto open** enabled; 
open then picked an arbitrary first match.
   
   On create OK / metadata save of a test with auto-open enabled, other unit 
tests for the **same pipeline** have auto-open cleared and saved 
(`UnitTestAutoOpening`).
   
   ## Reviewer notes
   
   ### Design choices
   
   - Overlay unit-test variables on the **graph** variable space (per-tab copy 
of Hop GUI vars), not project/global config.
   - On detach/switch, keys applied by the unit test are removed 
(`setVariable(key, null)`). If a unit test overwrote a project var that was 
already on the graph, the previous project value is **not** restored (accepted 
trade-off for a minimal fix).
   - Exclusive auto-open uses the same pipeline path matching as the unit-test 
combo list (`matchesPipelineFilename`).
   
   ### Main files
   
   | Area | Files |
   |------|--------|
   | Graph var overlay | `UnitTestGraphVariables`, `TestingGuiPlugin`, 
close/delete/changed XPs |
   | Run config sticky vars | `PipelineExecutionConfiguration`, 
`HopGuiUnitTestVariablesExtensionPoint` |
   | Metadata create safety | `MetadataEditor`, `MetadataManager` |
   | Unique default names | `HopGuiUnitTestCreateBeforeDialog` |
   | Exclusive auto-open | `UnitTestAutoOpening`, `HopGuiUnitTestChanged` |
   
   ### Tests
   
   - `UnitTestGraphVariablesTest` — apply / clear / switch same key
   - `UnitTestAutoOpeningTest` — exclusive auto-open
   - `HopGuiUnitTestCreateBeforeDialogTest` — default name base
   - Existing `HopGuiUnitTestVariablesExtensionPointTest` still green
   
   ```bash
   ./mvnw -pl plugins/misc/testing,engine -am test \
     
-Dtest=UnitTestGraphVariablesTest,UnitTestAutoOpeningTest,HopGuiUnitTestCreateBeforeDialogTest,HopGuiUnitTestVariablesExtensionPointTest
 \
     -Dsurefire.failIfNoSpecifiedTests=false
   ```
   
   ### Manual smoke (recommended)
   
   1. Pipeline with `${UNIT_TEST_VAR}` (e.g. Get Variables).
   2. Two unit tests for that pipeline: `UNIT_TEST_VAR=value1` / `value2`.
   3. Select each test → design-time resolve / run dialog / golden run match 
the active test.
   4. Create a second unit test with default name when `… UNIT` exists → gets 
`… UNIT 2`; renaming does not delete the first.
   5. Enable Auto open on one test → others for that pipeline lose Auto open on 
save.
   
   ## Related
   
   - Fixes #7719
   - Follow-up / related to #7245 (run dialog unit test variables)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to