Skip to content

Commit 9e27ade

Browse files
authored
Merge pull request #1228 from ably/fix/liveobjects-objects-audit-op-handling
[AIT-1142] fix(liveobjects): objects audit conformance; refactor(uts): shared test-infra module
2 parents 74d267f + 960d044 commit 9e27ade

93 files changed

Lines changed: 10277 additions & 5207 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.claude/skills/uts-to-kotlin/SKILL.md‎

Lines changed: 84 additions & 26 deletions
Large diffs are not rendered by default.

‎.claude/skills/uts-to-kotlin/references/objects-mapping.md‎

Lines changed: 256 additions & 35 deletions
Large diffs are not rendered by default.

‎.claude/skills/uts-to-kotlin/scripts/audit_translation.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
UTS_TAG_RE = re.compile(r"@UTS\s+(\S+)")
5757
KOTLIN_ASSERT_RE = re.compile(
5858
r"\b(assertEquals|assertNotEquals|assertNull|assertNotNull|assertTrue|assertFalse|"
59-
r"assertIs|assertIsNot|assertContains|assertFailsWith|assertFails|assertSame|"
59+
r"assertIs|assertIsNot|assertContains|assertContentEquals|assertFailsWith|assertFails|assertSame|"
6060
r"assertNotSame|awaitState|awaitChannelState|pollUntil)\b"
6161
)
6262

‎.claude/skills/uts-to-kotlin/scripts/resolve_uts.py‎

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
directory (a directory directly under .../specification/uts/), it:
66
77
- validates the path and the module's tier structure,
8-
- reads uts-package-mapping.json (next to this script's skill dir),
9-
- resolves, per tier, the target output directory and Kotlin package, and
8+
- reads uts-package-mapping.json (next to this script's skill dir), where each
9+
tier value is ONE repo-root-relative path (never machine-absolute),
10+
- resolves, per tier, the target output directory, Kotlin package (the path
11+
after 'src/test/kotlin/'), and owning Gradle module (from the path's first
12+
segment), and
1013
- lists the candidate spec files with their derived Kotlin class names.
1114
1215
Doing this in code (rather than asking the model to eyeball regexes, join
@@ -31,6 +34,10 @@
3134
SKILL_DIR = Path(__file__).resolve().parent.parent
3235
MAPPING = SKILL_DIR / "uts-package-mapping.json"
3336
TIERS = ("unit", "integration", "proxy")
37+
# Owning Gradle module, keyed by a target dir's first path segment. The `lib` -> `:java`
38+
# pair is the load-bearing non-obvious mapping (the `:java` module's build file wires
39+
# `../lib/src/...` srcDirs).
40+
MODULE_BY_PREFIX = {"lib": ":java", "liveobjects": ":liveobjects", "uts": ":uts"}
3441

3542

3643
def fail(code, message):
@@ -88,7 +95,9 @@ def main():
8895
"--create",
8996
metavar="NAME",
9097
help="add a mapping for this source module using NAME as the ably-java "
91-
"module base name, then resolve",
98+
"module base name, then resolve. Scaffolds full lib/-rooted (:java) paths "
99+
"only — a module whose tiers live in another Gradle module (like objects "
100+
"-> :liveobjects) still needs a hand-edit afterwards.",
92101
)
93102
args = ap.parse_args()
94103

@@ -114,7 +123,6 @@ def main():
114123
fail("MAPPING_NOT_FOUND", f"mapping file not found at {MAPPING}")
115124
data = json.loads(MAPPING.read_text(encoding="utf-8"))
116125
packages = data.setdefault("packages", {})
117-
test_root = data.get("testRoot", "")
118126

119127
if args.create:
120128
target = args.create
@@ -123,10 +131,14 @@ def main():
123131
f"--create target {target!r} must be a simple module base name "
124132
f"(letters/digits/underscore, e.g. 'liveobjects') so it forms a "
125133
f"valid path and Kotlin package.")
134+
# Full repo-root-relative paths using the realtime/`lib` (:java) template.
135+
# A module whose tiers live in another Gradle module (like objects ->
136+
# :liveobjects) still needs a hand-edit — --create only scaffolds :java-hosted modules.
137+
base = "lib/src/test/kotlin/io/ably/lib/uts"
126138
new_entry = {
127-
"unit": f"unit/{target}",
128-
"integration": f"integration/standard/{target}",
129-
"proxy": f"integration/proxy/{target}",
139+
"unit": f"{base}/unit/{target}",
140+
"integration": f"{base}/integration/standard/{target}",
141+
"proxy": f"{base}/integration/proxy/{target}",
130142
}
131143
# preserve a hand-maintained "notes" pointer when re-creating an existing entry
132144
notes = packages.get(source_module, {}).get("notes")
@@ -162,20 +174,25 @@ def main():
162174

163175
tiers_out = {}
164176
for tier in TIERS:
165-
target_dir = f"{test_root}/{entry[tier]}" if (mapped and tier in entry) else None
177+
# A tier value is ONE repo-root-relative path (never machine-absolute); the
178+
# owning module comes from its first path segment (MODULE_BY_PREFIX).
179+
target_dir = entry.get(tier) if mapped else None
180+
module = (
181+
MODULE_BY_PREFIX.get(target_dir.split("/", 1)[0]) if target_dir else None
182+
)
166183
tiers_out[tier] = {
167184
"present": src[tier].is_dir(),
168185
"sourceDir": str(src[tier]),
169186
"targetDir": target_dir,
170187
"package": package_for(target_dir) if target_dir else None,
188+
"module": module,
171189
"specs": [{"file": str(p), "className": class_name(p)} for p in specs[tier]],
172190
}
173191

174192
print(json.dumps({
175193
"ok": True,
176194
"sourceModule": source_module,
177195
"mapped": mapped,
178-
"testRoot": test_root,
179196
"translationNotes": translation_notes,
180197
"tiers": tiers_out,
181198
}, indent=2))
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
{
2-
"_comment": "Maps each UTS spec module (a dir under specification/uts/) to its target test packages. Output dir = testRoot + '/' + tier entry; Kotlin package = that path after 'src/test/kotlin/' with '/' -> '.'. An optional 'notes' field points (relative to this skill dir) to a per-module ably-js -> ably-java translation reference, read before translating that module. Used by the uts-to-kotlin skill.",
3-
"testRoot": "uts/src/test/kotlin/io/ably/lib/uts",
2+
"_comment": "Maps each UTS spec module (a dir under specification/uts/) to its target test directory per tier. Each tier value is ONE repo-root-relative path (never machine-absolute); the Kotlin package is the path after 'src/test/kotlin/' with '/' -> '.'; the owning Gradle module is the path's first segment (lib/ -> :java, liveobjects/ -> :liveobjects, uts/ -> :uts). Every tier path MUST keep a module segment after the tier (e.g. 'unit/realtime', never bare 'unit') so a derived package can never collide with a :uts smoke package (io.ably.lib.uts.unit / .integration.standard / .integration.proxy) — an invariant currently held only by construction. An optional 'notes' field points (relative to this skill dir) to a per-module ably-js -> ably-java translation reference, read before translating that module. Used by the uts-to-kotlin skill (scripts/resolve_uts.py).",
43
"packages": {
54
"realtime": {
6-
"unit": "unit/realtime",
7-
"integration": "integration/standard/realtime",
8-
"proxy": "integration/proxy/realtime"
5+
"unit": "lib/src/test/kotlin/io/ably/lib/uts/unit/realtime",
6+
"integration": "lib/src/test/kotlin/io/ably/lib/uts/integration/standard/realtime",
7+
"proxy": "lib/src/test/kotlin/io/ably/lib/uts/integration/proxy/realtime"
98
},
109
"objects": {
11-
"unit": "unit/liveobjects",
12-
"integration": "integration/standard/liveobjects",
13-
"proxy": "integration/proxy/liveobjects",
10+
"unit": "liveobjects/src/test/kotlin/io/ably/lib/liveobjects/uts/unit",
11+
"integration": "liveobjects/src/test/kotlin/io/ably/lib/liveobjects/uts/integration",
12+
"proxy": "liveobjects/src/test/kotlin/io/ably/lib/liveobjects/uts/proxy",
1413
"notes": "references/objects-mapping.md"
1514
},
1615
"rest": {
17-
"unit": "unit/rest",
18-
"integration": "integration/standard/rest",
19-
"proxy": "integration/proxy/rest"
16+
"unit": "lib/src/test/kotlin/io/ably/lib/uts/unit/rest",
17+
"integration": "lib/src/test/kotlin/io/ably/lib/uts/integration/standard/rest",
18+
"proxy": "lib/src/test/kotlin/io/ably/lib/uts/integration/proxy/rest"
2019
}
2120
}
2221
}

‎.github/workflows/check.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ jobs:
2323
distribution: 'temurin'
2424
- name: Set up Gradle
2525
uses: gradle/actions/setup-gradle@d9c87d481d55275bb5441eef3fe0e46805f9ef70 # v3
26-
- run: ./gradlew checkWithCodenarc checkstyleMain checkstyleTest runUnitTests runLiveObjectsUnitTests :uts:runUtsUnitTests
26+
- run: ./gradlew checkWithCodenarc checkstyleMain checkstyleTest runUnitTests runLiveObjectsUnitTests :java:runUtsUnitTests :uts:runUtsUnitTests

‎.github/workflows/integration-test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,4 @@ jobs:
143143
- name: Set up Gradle
144144
uses: gradle/actions/setup-gradle@d9c87d481d55275bb5441eef3fe0e46805f9ef70 # v3
145145

146-
- run: ./gradlew :uts:runUtsIntegrationTests
146+
- run: ./gradlew :java:runUtsIntegrationTests :uts:runUtsIntegrationTests

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ realtimeClient.connection.on(ConnectionEvent.connected, connectionStateChange ->
107107

108108
[Ably Live Objects](https://ably.com/docs/liveobjects) provide realtime, collaborative data structures that automatically synchronize state across all connected clients. Build interactive applications with shared data that updates instantly across devices.
109109

110+
For a comprehensive guide, check the [Ably Live Objects documentation](https://ably.com/docs/liveobjects), starting with the [Java quickstart](https://ably.com/docs/liveobjects/quickstart/java).
111+
110112
### Install Live Objects
111113

112114
Add the following dependency to your `build.gradle` file:

‎gradle/libs.versions.toml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[versions]
22
agp = "8.6.1"
33
junit = "4.13.2"
4+
junit-jupiter = "5.10.1" # matches what kotlin-test-junit5:2.1.10 transitively pins (verified)
45
gson = "2.9.0"
56
msgpack = "0.9.11"
67
java-websocket = "1.5.3"
@@ -40,6 +41,10 @@ java-websocket = { group = "org.java-websocket", name = "Java-WebSocket", versio
4041
navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigation-compose" }
4142
vcdiff-core = { group = "com.davidehrmann.vcdiff", name = "vcdiff-core", version.ref = "vcdiff" }
4243
junit = { group = "junit", name = "junit", version.ref = "junit" }
44+
junit-bom = { group = "org.junit", name = "junit-bom", version.ref = "junit-jupiter" }
45+
junit-jupiter = { group = "org.junit.jupiter", name = "junit-jupiter" }
46+
junit-jupiter-params = { group = "org.junit.jupiter", name = "junit-jupiter-params" }
47+
junit-vintage-engine = { group = "org.junit.vintage", name = "junit-vintage-engine" }
4348
hamcrest-all = { group = "org.hamcrest", name = "hamcrest-all", version.ref = "hamcrest" }
4449
nanohttpd = { group = "org.nanohttpd", name = "nanohttpd", version.ref = "nanohttpd" }
4550
nanohttpd-nanolets = { group = "org.nanohttpd", name = "nanohttpd-nanolets", version.ref = "nanohttpd" }

‎java/build.gradle.kts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
2+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
23

34
plugins {
45
alias(libs.plugins.build.config)
56
alias(libs.plugins.maven.publish)
67
alias(libs.plugins.test.retry)
78
checkstyle
89
`java-library`
10+
alias(libs.plugins.kotlin.jvm)
911
}
1012

1113
java {
@@ -28,6 +30,9 @@ dependencies {
2830
runtimeOnly(project(":network-client-default"))
2931
}
3032
testImplementation(libs.bundles.tests)
33+
34+
// Brings in the shared UTS test toolkit (JUnit 5 + kotlin.test + coroutines) transitively via :uts api.
35+
testImplementation(project(":uts"))
3136
}
3237

3338
buildConfig {
@@ -47,9 +52,16 @@ sourceSets {
4752
java {
4853
srcDirs("src/test/java", "../lib/src/test/java")
4954
}
55+
kotlin {
56+
srcDirs("src/test/kotlin", "../lib/src/test/kotlin")
57+
}
5058
}
5159
}
5260

61+
kotlin {
62+
compilerOptions { jvmTarget.set(JvmTarget.JVM_1_8) } // match sourceCompatibility 1.8
63+
}
64+
5365
tasks.checkstyleMain.configure {
5466
exclude("io/ably/lib/BuildConfig.java")
5567
}
@@ -103,9 +115,43 @@ as it only contains the REST and Realtime suites.
103115
tasks.register<Test>("runUnitTests") {
104116
filter {
105117
excludeTestsMatching("io.ably.lib.test.*")
118+
excludeTestsMatching("io.ably.lib.uts.*") // UTS Jupiter suites run via runUts* tasks only
106119
}
107120
jvmArgs("--add-opens", "java.base/java.time=ALL-UNNAMED")
108121
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
109122
beforeTest(closureOf<TestDescriptor> { logger.lifecycle("-> $this") })
110123
outputs.upToDateWhen { false }
111124
}
125+
126+
tasks.register<Test>("runUtsUnitTests") {
127+
useJUnitPlatform()
128+
filter {
129+
includeTestsMatching("io.ably.lib.uts.unit.*")
130+
}
131+
jvmArgs("--add-opens", "java.base/java.time=ALL-UNNAMED")
132+
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
133+
beforeTest(closureOf<TestDescriptor> { logger.lifecycle("-> $this") })
134+
outputs.upToDateWhen { false }
135+
}
136+
137+
tasks.register<Test>("runUtsIntegrationTests") {
138+
useJUnitPlatform()
139+
filter {
140+
includeTestsMatching("io.ably.lib.uts.integration.*")
141+
}
142+
jvmArgs("--add-opens", "java.base/java.time=ALL-UNNAMED")
143+
jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED")
144+
beforeTest(closureOf<TestDescriptor> { logger.lifecycle("-> $this") })
145+
outputs.upToDateWhen { false }
146+
147+
// Gradle does not forward -D system properties to the forked test JVM, so propagate the
148+
// local uts-proxy override explicitly (invariant I6; AuthReauthTest launches the proxy).
149+
// Accepts either `-Duts.proxy.localPath=...` on the Gradle invocation or the
150+
// `UTS_PROXY_LOCAL_PATH` environment variable. See ProxyManager.
151+
systemProperty(
152+
"uts.proxy.localPath",
153+
providers.systemProperty("uts.proxy.localPath")
154+
.orElse(providers.environmentVariable("UTS_PROXY_LOCAL_PATH"))
155+
.getOrElse(""),
156+
)
157+
}

0 commit comments

Comments
 (0)