Skip to content

Commit e10425d

Browse files
Merge branch 'master' into alexeyk/protocol-v1-1
2 parents 3bad392 + 9352dfa commit e10425d

File tree

21 files changed

+345
-367
lines changed

21 files changed

+345
-367
lines changed

.claude/skills/migrate-groovy-to-java/SKILL.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ When converting Groovy code to Java code, make sure that:
3232
- When translating Spock `Mock(...)` usage, use `libs.bundles.mockito` instead of writing manual recording/stub implementations
3333

3434
TableTest usage
35-
Dependency, if missing add:
36-
- Groovy: testImplementation libs.tabletest
37-
- Kotlin: testImplementation(libs.tabletest)
38-
3935
Import: `import org.tabletest.junit.TableTest;`
4036

4137
JDK 8 rules:

.claude/skills/migrate-junit-source-to-tabletest/SKILL.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ Process (do in this order):
1111
4) Write each modified file once in full using Write (no incremental per-test edits).
1212
5) Run module tests once and verify "BUILD SUCCESSFUL". If failed, inspect JUnit XML report.
1313

14-
Dependency:
15-
- If missing, add:
16-
- Groovy: testImplementation libs.tabletest
17-
- Kotlin: testImplementation(libs.tabletest)
18-
1914
Import: `import org.tabletest.junit.TableTest;`
2015

2116
JDK 8 rules:
@@ -34,6 +29,7 @@ Table formatting rules (mandatory):
3429
- Use '|' as delimiter.
3530
- Align columns with spaces so pipes line up vertically.
3631
- Prefer single quotes for strings requiring quotes (e.g., 'a|b', '[]', '{}', ' ').
32+
- Use value sets (`{a, b, c}`) instead of matrix-style repetition when only one dimension varies across otherwise-identical rows.
3733

3834
Conversions:
3935
A) @CsvSource
@@ -42,7 +38,8 @@ A) @CsvSource
4238
- If delimiter is ',' (default): replace ',' with '|' in rows.
4339

4440
B) @ValueSource
45-
- Convert to @TableTest with header from parameter name.
41+
- Keep single-parameter tests on `@ValueSource` (and `@NullSource` when null cases are needed).
42+
- Otherwise convert to @TableTest with header from parameter name.
4643
- Each value becomes one row.
4744
- Add "scenario" column using common sense for name.
4845

@@ -60,6 +57,11 @@ C) @MethodSource (convert only if values are representable as strings)
6057
- '' = empty string.
6158
- For String params that start with '[' or '{', quote to avoid collection parsing (prefer '[]'/'{}').
6259

60+
D) @TypeConverter
61+
- Use `@TypeConverter` for symbolic constants used by migrated table rows (e.g. `Long.MAX_VALUE`, `DDSpanId.MAX`).
62+
- Prefer explicit one-case-one-return mappings.
63+
- Prefer shared converter utilities (e.g. in `utils/test-utils`) when reuse across modules is likely.
64+
6365
Scenario handling:
6466
- If MethodSource includes a leading description string OR @ParameterizedTest(name=...) uses {0}, convert that to a scenario column and remove that parameter from method signature.
6567

.github/workflows/enforce-groovy-migration.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
types: [opened, edited, ready_for_review, labeled, unlabeled, synchronize]
55
branches:
66
- master
7+
- 'release/v*'
78

89
concurrency:
910
group: ${{ github.workflow }}-${{ github.ref }}

components/json/build.gradle.kts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,3 @@ apply(from = "$rootDir/gradle/java.gradle")
77
jmh {
88
jmhVersion = libs.versions.jmh.get()
99
}
10-
11-
dependencies {
12-
testImplementation(libs.tabletest)
13-
}

components/json/src/test/java/datadog/json/JsonMapperTest.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.junit.jupiter.params.ParameterizedTest;
1818
import org.junit.jupiter.params.provider.Arguments;
1919
import org.junit.jupiter.params.provider.MethodSource;
20+
import org.junit.jupiter.params.provider.NullSource;
21+
import org.junit.jupiter.params.provider.ValueSource;
2022
import org.tabletest.junit.Scenario;
2123
import org.tabletest.junit.TableTest;
2224

@@ -77,28 +79,16 @@ static Stream<Arguments> testMappingToJsonObjectArguments() {
7779
"{\"key1\":null,\"key2\":\"bar\",\"key3\":3,\"key4\":3456789123,\"key5\":3.142,\"key6\":3.141592653589793,\"key7\":true,\"key8\":\"toString\"}"));
7880
}
7981

80-
@TableTest({
81-
"Scenario | Json ",
82-
"null | ",
83-
"null string | 'null'",
84-
"empty string | '' ",
85-
"empty object | '{}' "
86-
})
8782
@ParameterizedTest(name = "test mapping to Map from empty JSON object: {0}")
83+
@NullSource
84+
@ValueSource(strings = {"null", "", "{}"})
8885
void testMappingToMapFromEmptyJsonObject(String json) throws IOException {
8986
Map<String, Object> parsed = JsonMapper.fromJsonToMap(json);
9087
assertEquals(emptyMap(), parsed);
9188
}
9289

93-
// temporary disable spotless, will open issue to fix this.
94-
// spotless:off
95-
@TableTest({
96-
"Scenario | Json ",
97-
"integer | 1 ",
98-
"array | [1, 2]"
99-
})
100-
// spotless:on
10190
@ParameterizedTest(name = "test mapping to Map from non-object JSON: {0}")
91+
@ValueSource(strings = {"1", "[1, 2]"})
10292
void testMappingToMapFromNonObjectJson(String json) {
10393
assertThrows(IOException.class, () -> JsonMapper.fromJsonToMap(json));
10494
}
@@ -138,14 +128,9 @@ void testMappingArrayToJsonArray(String ignoredScenario, String[] input, String
138128
assertArrayEquals(input != null ? input : new String[] {}, parsed);
139129
}
140130

141-
@TableTest({
142-
"Scenario | Json ",
143-
"null | ",
144-
"null string | 'null'",
145-
"empty string | '' ",
146-
"empty array | '[]' "
147-
})
148131
@ParameterizedTest(name = "test mapping to List from empty JSON object: {0}")
132+
@NullSource
133+
@ValueSource(strings = {"null", "", "[]"})
149134
void testMappingToListFromEmptyJsonObject(String json) throws IOException {
150135
List<String> parsed = JsonMapper.fromJsonToList(json);
151136
assertEquals(emptyList(), parsed);

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/symbol/SourceRemapper.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@ static SourceRemapper getSourceRemapper(String sourceFile, SourceMap sourceMap)
1313
JvmLanguage jvmLanguage = JvmLanguage.of(sourceFile);
1414
switch (jvmLanguage) {
1515
case KOTLIN:
16-
StratumExt stratum = sourceMap.getStratum("KotlinDebug");
17-
if (stratum == null) {
18-
throw new IllegalArgumentException("No stratum found for KotlinDebug");
16+
StratumExt stratumMain = sourceMap.getStratum("Kotlin");
17+
if (stratumMain == null) {
18+
stratumMain = sourceMap.getStratum(sourceMap.getDefaultStratumName());
19+
if (stratumMain == null) {
20+
throw new IllegalArgumentException("No default stratum found");
21+
}
1922
}
20-
return new KotlinSourceRemapper(stratum);
23+
StratumExt stratumDebug = sourceMap.getStratum("KotlinDebug");
24+
if (stratumDebug == null) {
25+
throw new IllegalArgumentException("No stratumDebug found for KotlinDebug");
26+
}
27+
return new KotlinSourceRemapper(stratumMain, stratumDebug);
2128
default:
2229
return NOOP_REMAPPER;
2330
}
@@ -33,19 +40,33 @@ public int remapSourceLine(int line) {
3340
}
3441

3542
class KotlinSourceRemapper implements SourceRemapper {
36-
private final StratumExt stratum;
43+
private final StratumExt stratumMain;
44+
private final StratumExt stratumDebug;
3745

38-
public KotlinSourceRemapper(StratumExt stratum) {
39-
this.stratum = stratum;
46+
public KotlinSourceRemapper(StratumExt stratumMain, StratumExt stratumDebug) {
47+
this.stratumMain = stratumMain;
48+
this.stratumDebug = stratumDebug;
4049
}
4150

4251
@Override
4352
public int remapSourceLine(int line) {
44-
Pair<String, Integer> pair = stratum.getInputLine(line);
45-
if (pair == null || pair.getRight() == null) {
46-
return line;
53+
Pair<String, Integer> pairDebug = stratumDebug.getInputLine(line);
54+
if (pairDebug == null || pairDebug.getRight() == null) {
55+
Pair<String, Integer> pairMain = stratumMain.getInputLine(line);
56+
if (pairMain == null || pairMain.getRight() == null) {
57+
return line;
58+
}
59+
String fileId = pairMain.getLeft();
60+
String sourceFileName = stratumMain.getSourceFileName(fileId);
61+
if (sourceFileName == null) {
62+
throw new IllegalArgumentException("Cannot find source filename for fileid=" + fileId);
63+
}
64+
if (sourceFileName.equals("fake.kt")) {
65+
return -1; // no mapping possible
66+
}
67+
return pairMain.getRight();
4768
}
48-
return pair.getRight();
69+
return pairDebug.getRight();
4970
}
5071
}
5172
}

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/symbol/SymbolExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ private static MethodLineInfo extractMethodLineInfo(
506506
if (node.getType() == AbstractInsnNode.LINE) {
507507
LineNumberNode lineNumberNode = (LineNumberNode) node;
508508
int newLine = sourceRemapper.remapSourceLine(lineNumberNode.line);
509-
if (dedupSet.add(newLine)) {
509+
if (newLine > 0 && dedupSet.add(newLine)) {
510510
lineNo.add(newLine);
511511
}
512512
maxLine = Math.max(newLine, maxLine);

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/symbol/SourceRemapperTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ public void noopSourceRemapper() {
2121
@Test
2222
public void kotlinSourceRemapper() {
2323
SourceMap sourceMapMock = mock(SourceMap.class);
24-
StratumExt stratumMock = mock(StratumExt.class);
25-
when(sourceMapMock.getStratum(eq("KotlinDebug"))).thenReturn(stratumMock);
26-
when(stratumMock.getInputLine(eq(42))).thenReturn(Pair.of("", 24));
24+
StratumExt stratumMainMock = mock(StratumExt.class);
25+
StratumExt stratumDebugMock = mock(StratumExt.class);
26+
when(sourceMapMock.getStratum(eq("Kotlin"))).thenReturn(stratumMainMock);
27+
when(sourceMapMock.getStratum(eq("KotlinDebug"))).thenReturn(stratumDebugMock);
28+
when(stratumDebugMock.getInputLine(eq(42))).thenReturn(Pair.of("", 24));
2729
SourceRemapper sourceRemapper = SourceRemapper.getSourceRemapper("foo.kt", sourceMapMock);
2830
assertTrue(sourceRemapper instanceof SourceRemapper.KotlinSourceRemapper);
2931
assertEquals(24, sourceRemapper.remapSourceLine(42));

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/symbol/SymbolExtractionTransformerTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ public void symbolExtraction16() throws IOException, URISyntaxException {
10021002
}
10031003
assertEquals(2, symbolSinkMock.jarScopes.size());
10041004
Scope classScope = symbolSinkMock.jarScopes.get(0).getScopes().get(0);
1005-
assertScope(classScope, ScopeType.CLASS, CLASS_NAME, 6, 17, SOURCE_FILE, 4, 1);
1005+
assertScope(classScope, ScopeType.CLASS, CLASS_NAME, 6, 23, SOURCE_FILE, 5, 1);
10061006
assertLangSpecifics(
10071007
classScope.getLanguageSpecifics(),
10081008
asList("public", "final"),
@@ -1024,12 +1024,15 @@ public void symbolExtraction16() throws IOException, URISyntaxException {
10241024
Scope f2MethodScope = classScope.getScopes().get(2);
10251025
assertScope(f2MethodScope, ScopeType.METHOD, "f2", 10, 17, SOURCE_FILE, 3, 1);
10261026
assertLineRanges(f2MethodScope, "10-10", "12-12", "14-14", "16-17");
1027+
Scope f3MethodScope = classScope.getScopes().get(3);
1028+
assertScope(f3MethodScope, ScopeType.METHOD, "f3", 21, 23, SOURCE_FILE, 1, 1);
1029+
assertLineRanges(f3MethodScope, "21-23");
10271030
assertScope(
1028-
classScope.getScopes().get(3), ScopeType.METHOD, "<clinit>", 0, 0, SOURCE_FILE, 0, 0);
1031+
classScope.getScopes().get(4), ScopeType.METHOD, "<clinit>", 0, 0, SOURCE_FILE, 0, 0);
10291032

10301033
Scope companionClassScope = symbolSinkMock.jarScopes.get(1).getScopes().get(0);
10311034
assertScope(
1032-
companionClassScope, ScopeType.CLASS, CLASS_NAME + "$Companion", 22, 23, SOURCE_FILE, 3, 0);
1035+
companionClassScope, ScopeType.CLASS, CLASS_NAME + "$Companion", 28, 29, SOURCE_FILE, 3, 0);
10331036
assertLangSpecifics(
10341037
classScope.getLanguageSpecifics(),
10351038
asList("public", "final"),
@@ -1047,8 +1050,8 @@ public void symbolExtraction16() throws IOException, URISyntaxException {
10471050
0,
10481051
0);
10491052
Scope mainMethodScope = companionClassScope.getScopes().get(1);
1050-
assertScope(mainMethodScope, ScopeType.METHOD, "main", 22, 23, SOURCE_FILE, 1, 1);
1051-
assertLineRanges(mainMethodScope, "22-23");
1053+
assertScope(mainMethodScope, ScopeType.METHOD, "main", 28, 29, SOURCE_FILE, 1, 1);
1054+
assertLineRanges(mainMethodScope, "28-29");
10521055
}
10531056

10541057
@Test

dd-java-agent/agent-debugger/src/test/resources/CapturedSnapshot301.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ class CapturedSnapshot301 {
1515
return value
1616
}
1717

18+
fun f3(value: Int): Int {
19+
val list = listOf(value, 2, 3)
20+
val max = list.maxOf { it -> it > 0 }
21+
return value
22+
}
23+
1824
companion object {
1925
fun main(arg: String): Int {
2026
val c = CapturedSnapshot301()

0 commit comments

Comments
 (0)