Skip to content

Provide unique IDs for all node info objects#1696

Open
Vampire wants to merge 2 commits intomasterfrom
unique-node-ids
Open

Provide unique IDs for all node info objects#1696
Vampire wants to merge 2 commits intomasterfrom
unique-node-ids

Conversation

@Vampire
Copy link
Member

@Vampire Vampire commented Jun 10, 2023

Summary by CodeRabbit

  • New Features
    • Test specifications, features, and iterations now receive stable, globally unique identifiers for improved tracking and reporting.
    • Iterations are identified relative to their parent feature (e.g., feature[id][index]) to distinguish parameterized runs.
    • Test nodes expose readable IDs for tooling and reporting, enabling clearer traceability across inheritance and repeated executions.

@Vampire
Copy link
Member Author

Vampire commented Jun 10, 2023

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codecov
Copy link

codecov bot commented Jun 10, 2023

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.17%. Comparing base (9c6342c) to head (e84a5c6).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1696   +/-   ##
=========================================
  Coverage     82.16%   82.17%           
- Complexity     4822     4825    +3     
=========================================
  Files           472      472           
  Lines         15036    15043    +7     
  Branches       1905     1905           
=========================================
+ Hits          12355    12362    +7     
  Misses         1989     1989           
  Partials        692      692           
Files with missing lines Coverage Δ
...va/org/spockframework/runtime/SpecInfoBuilder.java 99.27% <100.00%> (+0.01%) ⬆️
...rg/spockframework/runtime/model/IterationInfo.java 95.45% <100.00%> (+0.21%) ⬆️
...ava/org/spockframework/runtime/model/NodeInfo.java 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Vampire Vampire force-pushed the unique-node-ids branch 3 times, most recently from 595c6da to 3cacaf6 Compare August 21, 2023 16:15
@leonard84
Copy link
Member

What is the use-case? And shouldn't we have something that is stable across invocations, otherwise it's use is severely limited.

@Vampire
Copy link
Member Author

Vampire commented Aug 21, 2023

What is the use-case?

Well, everytime you need a unique ID during the test.
One use-case where I needed it is for example to put it as thread context map entry to log messages, so that you can identify log messages belonging to an iteration and test logging behavior in a multi-threaded SUT.

And shouldn't we have something that is stable across invocations, otherwise it's use is severely limited.

Well, the intended use by me was during one test run to relate things, without needing to build a unique ID yourself.
And for spec info, feature info and iteration info, it actually is stable across invocations, just not for "other" nodes.
Others being data provider info, field info, method info and parameter info.

Not sure whether we need stable unique ids for those. :-/

@Vampire
Copy link
Member Author

Vampire commented Aug 22, 2023

Also, that they are stable across invocations for spec, feature, and iteration info is mainly a side-effect. The goal was to have something descriptive that can the also easily be readable for example in the log output where I intend to use it. :-D

@Vampire Vampire force-pushed the unique-node-ids branch 2 times, most recently from 82329d4 to 9e20670 Compare September 16, 2023 10:37
@Vampire Vampire force-pushed the unique-node-ids branch 2 times, most recently from 0a54c3f to 53f0557 Compare September 18, 2023 23:41
@Vampire Vampire force-pushed the unique-node-ids branch 3 times, most recently from 5c9ac8c to 02aff00 Compare October 14, 2023 11:36
@Vampire Vampire force-pushed the unique-node-ids branch 3 times, most recently from 6e21a45 to b3d7dbb Compare November 7, 2023 00:29
@Vampire Vampire force-pushed the unique-node-ids branch 4 times, most recently from 2caee62 to 6c400f0 Compare November 13, 2023 00:50
@Vampire Vampire force-pushed the unique-node-ids branch 4 times, most recently from 0422e2b to d6e3be7 Compare November 30, 2023 13:08
@Vampire Vampire force-pushed the unique-node-ids branch 3 times, most recently from 937bf52 to 60bf169 Compare May 16, 2024 10:24
@Vampire Vampire force-pushed the unique-node-ids branch from 60bf169 to 9bffe3b Compare May 22, 2024 14:43
@Vampire Vampire force-pushed the unique-node-ids branch 2 times, most recently from 3b8d246 to b322fb9 Compare August 8, 2024 09:17
@Vampire Vampire force-pushed the unique-node-ids branch 2 times, most recently from ad0c185 to 92d0a32 Compare January 22, 2025 19:01
@Vampire Vampire force-pushed the unique-node-ids branch 4 times, most recently from 3080aad to 06b7338 Compare February 28, 2025 14:36
@Vampire Vampire force-pushed the unique-node-ids branch 3 times, most recently from 00a4141 to 307e4dc Compare April 27, 2025 23:22
@Vampire Vampire force-pushed the unique-node-ids branch from 307e4dc to 888f6ee Compare May 19, 2025 14:03
@Vampire Vampire force-pushed the unique-node-ids branch 3 times, most recently from a01553f to f410524 Compare June 5, 2025 14:46
@Vampire Vampire force-pushed the unique-node-ids branch 2 times, most recently from 968bbe9 to c434efe Compare October 20, 2025 17:03
@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a63c91f1-c832-4fc3-b781-acb0c2b818c7

📥 Commits

Reviewing files that changed from the base of the PR and between 25912aa and e84a5c6.

📒 Files selected for processing (1)
  • spock-core/src/main/java/org/spockframework/runtime/model/IterationInfo.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • spock-core/src/main/java/org/spockframework/runtime/model/IterationInfo.java

📝 Walkthrough

Walkthrough

Adds hierarchical unique identifiers across the node model: SpecInfo gets a spec-level ID (class name), FeatureInfo IDs are formed as specId.methodName, IterationInfo IDs as featureId[index], and NodeInfo gains a UUID-based uniqueId with accessors.

Changes

Cohort / File(s) Summary
Core Model: NodeInfo
spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java
Added private uniqueId (UUID default), Javadoc, public String getUniqueId() and protected void setUniqueId(String); added java.util.UUID import.
Spec/Feature setters
spock-core/src/main/java/org/spockframework/runtime/SpecInfo.java, spock-core/src/main/java/org/spockframework/runtime/model/FeatureInfo.java
Added void setUniqueId(String) methods to allow external assignment/propagation of unique IDs.
Builder initialization
spock-core/src/main/java/org/spockframework/runtime/SpecInfoBuilder.java
Sets SpecInfo uniqueId (class name) during spec build and assigns each FeatureInfo a uniqueId formatted as specUniqueId.methodName when creating features.
Iteration IDs
spock-core/src/main/java/org/spockframework/runtime/model/IterationInfo.java
Iteration constructor now sets uniqueId as String.format(Locale.ROOT, "%s[%d]", feature.getUniqueId(), iterationIndex) producing featureId[index].

Sequence Diagram(s)

sequenceDiagram
    participant Builder as SpecInfoBuilder
    participant Spec as SpecInfo
    participant Feature as FeatureInfo
    participant Iteration as IterationInfo

    Builder->>Spec: buildSpec(class)
    Spec->>Spec: setUniqueId(className)
    Builder->>Feature: createFeature(method)
    Feature->>Feature: setUniqueId(specUniqueId + "." + methodName)
    Feature->>Iteration: createIteration(index)
    Iteration->>Iteration: setUniqueId(featureUniqueId + "[" + index + "]")
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I stitched IDs from class to test and thread,
A spec, some features, and indices in bed.
UUIDs hum, method names gleam,
Iterations hop into the scheme. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding unique identifiers to NodeInfo and its subclasses (SpecInfo, FeatureInfo, IterationInfo).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch unique-node-ids
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@spock-core/src/main/java/org/spockframework/runtime/model/IterationInfo.java`:
- Around line 33-35: The iteration ID is being built with locale-sensitive
String.format in the IterationInfo constructor
(setUniqueId(String.format("%s[%d]", ...))), which can produce locale-specific
digits; change this to a locale-independent construction—either use simple
String concatenation (feature.getUniqueId() + "[" + iterationIndex + "]") or
call String.format(Locale.ROOT, "%s[%d]", feature.getUniqueId(),
iterationIndex)—so setUniqueId always receives a stable, locale-neutral
identifier.

In `@spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java`:
- Around line 38-52: The public mutator setUniqueId on NodeInfo exposes and
allows replacing the node's uniqueId (and setting null/duplicates); remove or
restrict that mutator and enforce one-time, non-null assignment instead: either
make setUniqueId non-public (protected or package-private) or eliminate it and
assign uniqueId during construction, and if you keep an assignment method ensure
it throws on null or if uniqueId is already set (idempotent write-protection).
Update references to getUniqueId, setUniqueId and the uniqueId field accordingly
so only internal/runtime code can set the ID and callers cannot overwrite it.
- Around line 23-31: NodeInfo currently eagerly allocates a UUID in the field
declaration and exposes a public setUniqueId, causing wasted allocations
(IterationInfo immediately replaces it) and allowing external mutation; change
uniqueId to not be eagerly generated (e.g. initialize to null and lazily create
on first getUniqueId OR require subclasses to supply a semantic id via
constructor), replace the public setUniqueId with a non-public API (make it
private/protected or remove it) and, if desired, implement a cheap per-execution
id generator (static AtomicLong counter) that subclasses or getUniqueId can use
to produce lightweight unique values; update NodeInfo.getUniqueId/setters and
constructors of SpecInfo, FeatureInfo, IterationInfo accordingly to ensure
immutability of the identifier.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d290a688-11d0-4184-abc2-413afcc836e3

📥 Commits

Reviewing files that changed from the base of the PR and between 9c6342c and 612a600.

📒 Files selected for processing (3)
  • spock-core/src/main/java/org/spockframework/runtime/SpecInfoBuilder.java
  • spock-core/src/main/java/org/spockframework/runtime/model/IterationInfo.java
  • spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java

Comment on lines +23 to +31
import java.util.UUID;

/**
* Base class for runtime information about an element in a Spock specification.
*
* @author Peter Niederwieser
*/
public abstract class NodeInfo<P extends NodeInfo, R extends AnnotatedElement> {
private String uniqueId = UUID.randomUUID().toString();
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, locate and examine NodeInfo.java
find . -type f -name "NodeInfo.java" | head -20

Repository: spockframework/spock

Length of output: 137


🏁 Script executed:

# Check the full content of NodeInfo.java
if [ -f "spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java" ]; then
  cat -n "spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java"
else
  # Search for the file
  find . -name "NodeInfo.java" -type f
fi

Repository: spockframework/spock

Length of output: 3665


🏁 Script executed:

# Also check SpecInfoBuilder.java to see if it assigns semantic IDs
find . -type f -name "SpecInfoBuilder.java" | head -5

Repository: spockframework/spock

Length of output: 138


🏁 Script executed:

# Check IterationInfo.java
find . -type f -name "IterationInfo.java" | head -5

Repository: spockframework/spock

Length of output: 142


🏁 Script executed:

# Examine SpecInfoBuilder.java to find semantic ID assignments
cat -n "spock-core/src/main/java/org/spockframework/runtime/SpecInfoBuilder.java"

Repository: spockframework/spock

Length of output: 10958


🏁 Script executed:

# Examine IterationInfo.java 
cat -n "spock-core/src/main/java/org/spockframework/runtime/model/IterationInfo.java"

Repository: spockframework/spock

Length of output: 5336


🏁 Script executed:

# Search for setUniqueId calls to verify overwriting of uniqueId
rg "setUniqueId" -n --context 3

Repository: spockframework/spock

Length of output: 3267


Avoid eagerly generating a UUID in the base type.

SpecInfo, FeatureInfo, and IterationInfo each overwrite the default UUID with semantic IDs. On the per-iteration path, this causes unnecessary UUID allocation overhead—each IterationInfo constructor immediately discards the generated UUID. A per-execution counter would satisfy the documented uniqueness requirement without the allocation cost.

Additionally, the public setUniqueId() setter (lines 50–52) weakens the API contract by allowing arbitrary mutation of what should be an immutable identifier.

💡 One possible simplification
-import java.util.UUID;
+import java.util.concurrent.atomic.AtomicLong;
 
 public abstract class NodeInfo<P extends NodeInfo, R extends AnnotatedElement> {
-  private String uniqueId = UUID.randomUUID().toString();
+  private static final AtomicLong NEXT_ID = new AtomicLong();
+  private String uniqueId = "node-" + NEXT_ID.incrementAndGet();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java`
around lines 23 - 31, NodeInfo currently eagerly allocates a UUID in the field
declaration and exposes a public setUniqueId, causing wasted allocations
(IterationInfo immediately replaces it) and allowing external mutation; change
uniqueId to not be eagerly generated (e.g. initialize to null and lazily create
on first getUniqueId OR require subclasses to supply a semantic id via
constructor), replace the public setUniqueId with a non-public API (make it
private/protected or remove it) and, if desired, implement a cheap per-execution
id generator (static AtomicLong counter) that subclasses or getUniqueId can use
to produce lightweight unique values; update NodeInfo.getUniqueId/setters and
constructors of SpecInfo, FeatureInfo, IterationInfo accordingly to ensure
immutability of the identifier.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants