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
Copy Markdown
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.
    • Feature IDs are derived from their parent spec to preserve traceability between spec and feature.
    • Iterations receive deterministic, index-based identifiers to distinguish parameterized runs.
    • Test nodes expose readable IDs (initially generated) and can be overridden for tooling and reporting.

@Vampire
Copy link
Copy Markdown
Member Author

Vampire commented Jun 10, 2023

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

@codecov
Copy link
Copy Markdown

codecov bot commented Jun 10, 2023

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.24%. Comparing base (8d380cc) to head (0f36696).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1696      +/-   ##
============================================
+ Coverage     82.16%   82.24%   +0.08%     
- Complexity     4822     4829       +7     
============================================
  Files           472      472              
  Lines         15036    15043       +7     
  Branches       1905     1905              
============================================
+ Hits          12354    12372      +18     
+ Misses         1989     1983       -6     
+ Partials        693      688       -5     
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%> (ø)

... and 3 files with indirect coverage changes

🚀 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 2 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
Copy Markdown

coderabbitai bot commented Mar 13, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 370d190c-2e7c-467b-8d4a-6588151f339b

📥 Commits

Reviewing files that changed from the base of the PR and between 71a030d and 0f36696.

📒 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
🚧 Files skipped from review as they are similar to previous changes (3)
  • spock-core/src/main/java/org/spockframework/runtime/model/IterationInfo.java
  • spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java
  • spock-core/src/main/java/org/spockframework/runtime/SpecInfoBuilder.java

📝 Walkthrough

Walkthrough

Assigns hierarchical unique IDs: NodeInfo gains a UUID-default uniqueId; SpecInfo uniqueId is set to the spec class name in the builder; FeatureInfo uniqueIds are set to specUniqueId.methodName; IterationInfo uniqueIds are set to featureUniqueId[index].

Changes

Cohort / File(s) Summary
Core Model: NodeInfo
spock-core/src/main/java/org/spockframework/runtime/model/NodeInfo.java
Added private uniqueId initialized to a random UUID, public String getUniqueId() with Javadoc, and public void setUniqueId(String); added java.util.UUID import.
Builder: SpecInfo unique assignment
spock-core/src/main/java/org/spockframework/runtime/SpecInfoBuilder.java
Sets SpecInfo uniqueId to the spec class name early in buildSpec() 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
Constructor now sets iteration node uniqueId to 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(clazz)
    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 root to twig,
UUID hums where nodes are big.
Classes first, then methods named,
Iterations bracketed, neatly framed,
Hopping tests, all tidy and sprig.

🚥 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 and concisely captures the main objective of the pull request—adding unique ID functionality to node info objects across the framework.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch unique-node-ids

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
Copy Markdown

@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
Copy Markdown

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.

@testlens-app

This comment has been minimized.

@testlens-app
Copy link
Copy Markdown

testlens-app bot commented Mar 21, 2026

🔎 No tests executed 🔎

🏷️ Commit: 0f36696
▶️ Tests: 0 executed
⚪️ Checks: 61/61 completed


Learn more about TestLens at testlens.app.

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