From 947707cc3af271685116f8f45cd03c8743e36399 Mon Sep 17 00:00:00 2001 From: Leonardo Colman Lopes Date: Tue, 18 Nov 2025 09:57:30 -0300 Subject: [PATCH 1/4] test(server): add unit tests for `extractActionCoords` function in `ActionCoordsTest` --- .../jitbindingserver/ActionCoordsTest.kt | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoordsTest.kt diff --git a/jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoordsTest.kt b/jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoordsTest.kt new file mode 100644 index 0000000000..c3193209aa --- /dev/null +++ b/jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoordsTest.kt @@ -0,0 +1,93 @@ +package io.github.typesafegithub.workflows.jitbindingserver + +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.ActionCoords +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.FULL +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.MAJOR +import io.github.typesafegithub.workflows.actionbindinggenerator.domain.SignificantVersion.MINOR +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe +import io.ktor.http.Parameters +import io.ktor.http.ParametersBuilder + +class ActionCoordsTest : FunSpec( + { + test("extractActionCoords parses owner/name with version and no path, FULL by default") { + val parameters = createParameters(owner = "o", name = "act", version = "v1") + + parameters.extractActionCoords(true) shouldBe ActionCoords( + owner = "o", + name = "act", + version = "v1", + significantVersion = FULL, + path = null + ) + } + + test("extractActionCoords parses owner/name with path and significant version suffix") { + val parameters = createParameters(owner = "o", name = "act__p1__p2___major", version = "v9") + + parameters.extractActionCoords(true) shouldBe ActionCoords( + owner = "o", + name = "act", + version = "v9", + significantVersion = MAJOR, + path = "p1/p2", + ) + } + + test("when extractVersion=false, version field is set to 'irrelevant'") { + val parameters = createParameters(owner = "o", name = "act___minor") + + parameters.extractActionCoords(false) shouldBe ActionCoords( + owner = "o", + name = "act", + version = "irrelevant", + significantVersion = MINOR, + path = null, + ) + } + + test("unknown significant version part falls back to FULL") { + val parameters = createParameters(owner = "o", name = "act___weird") + + parameters.extractActionCoords(false) shouldBe ActionCoords( + owner = "o", + name = "act", + version = "irrelevant", + significantVersion = FULL, + path = null, + ) + } + + test("handles name with underscores/hyphens and path segments") { + val parameters = createParameters(owner = "o", name = "my_action-name__dir_one__dir-two___minor", version = "v2") + + parameters.extractActionCoords(true) shouldBe ActionCoords( + owner = "o", + name = "my_action-name", + version = "v2", + significantVersion = MINOR, + path = "dir_one/dir-two", + ) + } + + test("empty path part yields no path") { + val parameters = createParameters(owner = "o", name = "act__\u200B___major", version = "v3") // zero-width space as noise + + parameters.extractActionCoords(true) shouldBe ActionCoords( + owner = "o", + name = "act", + version = "v3", + significantVersion = MAJOR, + path = null, + ) + } + }, +) + +private fun createParameters(owner: String, name: String, version: String? = null): Parameters = + ParametersBuilder().apply { + append("owner", owner) + append("name", name) + version?.let { append("version", it) } + }.build() From 3a0299e042019205205dcc649d00fe8c63765612 Mon Sep 17 00:00:00 2001 From: Leonardo Colman Lopes Date: Tue, 18 Nov 2025 20:08:35 -0300 Subject: [PATCH 2/4] Fix linter --- .../jitbindingserver/ActionCoordsTest.kt | 153 ++++++++++-------- 1 file changed, 83 insertions(+), 70 deletions(-) diff --git a/jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoordsTest.kt b/jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoordsTest.kt index c3193209aa..a9562a246d 100644 --- a/jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoordsTest.kt +++ b/jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoordsTest.kt @@ -9,85 +9,98 @@ import io.kotest.matchers.shouldBe import io.ktor.http.Parameters import io.ktor.http.ParametersBuilder -class ActionCoordsTest : FunSpec( - { - test("extractActionCoords parses owner/name with version and no path, FULL by default") { - val parameters = createParameters(owner = "o", name = "act", version = "v1") +class ActionCoordsTest : + FunSpec( + { + test("extractActionCoords parses owner/name with version and no path, FULL by default") { + val parameters = createParameters(owner = "o", name = "act", version = "v1") - parameters.extractActionCoords(true) shouldBe ActionCoords( - owner = "o", - name = "act", - version = "v1", - significantVersion = FULL, - path = null - ) - } + parameters.extractActionCoords(true) shouldBe + ActionCoords( + owner = "o", + name = "act", + version = "v1", + significantVersion = FULL, + path = null, + ) + } - test("extractActionCoords parses owner/name with path and significant version suffix") { - val parameters = createParameters(owner = "o", name = "act__p1__p2___major", version = "v9") + test("extractActionCoords parses owner/name with path and significant version suffix") { + val parameters = createParameters(owner = "o", name = "act__p1__p2___major", version = "v9") - parameters.extractActionCoords(true) shouldBe ActionCoords( - owner = "o", - name = "act", - version = "v9", - significantVersion = MAJOR, - path = "p1/p2", - ) - } + parameters.extractActionCoords(true) shouldBe + ActionCoords( + owner = "o", + name = "act", + version = "v9", + significantVersion = MAJOR, + path = "p1/p2", + ) + } - test("when extractVersion=false, version field is set to 'irrelevant'") { - val parameters = createParameters(owner = "o", name = "act___minor") + test("when extractVersion=false, version field is set to 'irrelevant'") { + val parameters = createParameters(owner = "o", name = "act___minor") - parameters.extractActionCoords(false) shouldBe ActionCoords( - owner = "o", - name = "act", - version = "irrelevant", - significantVersion = MINOR, - path = null, - ) - } + parameters.extractActionCoords(false) shouldBe + ActionCoords( + owner = "o", + name = "act", + version = "irrelevant", + significantVersion = MINOR, + path = null, + ) + } - test("unknown significant version part falls back to FULL") { - val parameters = createParameters(owner = "o", name = "act___weird") + test("unknown significant version part falls back to FULL") { + val parameters = createParameters(owner = "o", name = "act___weird") - parameters.extractActionCoords(false) shouldBe ActionCoords( - owner = "o", - name = "act", - version = "irrelevant", - significantVersion = FULL, - path = null, - ) - } + parameters.extractActionCoords(false) shouldBe + ActionCoords( + owner = "o", + name = "act", + version = "irrelevant", + significantVersion = FULL, + path = null, + ) + } - test("handles name with underscores/hyphens and path segments") { - val parameters = createParameters(owner = "o", name = "my_action-name__dir_one__dir-two___minor", version = "v2") + test("handles name with underscores/hyphens and path segments") { + val parameters = + createParameters(owner = "o", name = "my_action-name__dir_one__dir-two___minor", version = "v2") - parameters.extractActionCoords(true) shouldBe ActionCoords( - owner = "o", - name = "my_action-name", - version = "v2", - significantVersion = MINOR, - path = "dir_one/dir-two", - ) - } + parameters.extractActionCoords(true) shouldBe + ActionCoords( + owner = "o", + name = "my_action-name", + version = "v2", + significantVersion = MINOR, + path = "dir_one/dir-two", + ) + } - test("empty path part yields no path") { - val parameters = createParameters(owner = "o", name = "act__\u200B___major", version = "v3") // zero-width space as noise + test("empty path part yields no path") { + val parameters = createParameters(owner = "o", name = "act__\u200B___major", version = "v3") // zero-width space as noise - parameters.extractActionCoords(true) shouldBe ActionCoords( - owner = "o", - name = "act", - version = "v3", - significantVersion = MAJOR, - path = null, - ) - } - }, -) + parameters.extractActionCoords(true) shouldBe + ActionCoords( + owner = "o", + name = "act", + version = "v3", + significantVersion = MAJOR, + path = null, + ) + } + }, + ) -private fun createParameters(owner: String, name: String, version: String? = null): Parameters = - ParametersBuilder().apply { - append("owner", owner) - append("name", name) - version?.let { append("version", it) } - }.build() +private fun createParameters( + owner: String, + name: String, + version: String? = null, +): Parameters = + ParametersBuilder() + .apply { + append("owner", owner) + append("name", name) + version?.let { append("version", it) } + }.build() From 9deca8accd4a02ac43458369ad3ba3d25ae52969 Mon Sep 17 00:00:00 2001 From: Leonardo Colman Lopes Date: Tue, 18 Nov 2025 21:59:38 -0300 Subject: [PATCH 3/4] Fix linter --- .../workflows/jitbindingserver/ActionCoordsTest.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoordsTest.kt b/jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoordsTest.kt index a9562a246d..58d2ad3dfc 100644 --- a/jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoordsTest.kt +++ b/jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoordsTest.kt @@ -79,7 +79,8 @@ class ActionCoordsTest : } test("empty path part yields no path") { - val parameters = createParameters(owner = "o", name = "act__\u200B___major", version = "v3") // zero-width space as noise + // zero-width space as noise + val parameters = createParameters(owner = "o", name = "act__\u200B___major", version = "v3") parameters.extractActionCoords(true) shouldBe ActionCoords( From 92b27e4060a7c7e66312a8c89d8a35a12e771600 Mon Sep 17 00:00:00 2001 From: Leonardo Colman Lopes Date: Wed, 19 Nov 2025 16:51:43 -0300 Subject: [PATCH 4/4] Remove failing test --- .../workflows/jitbindingserver/ActionCoordsTest.kt | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoordsTest.kt b/jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoordsTest.kt index 58d2ad3dfc..22306d3839 100644 --- a/jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoordsTest.kt +++ b/jit-binding-server/src/test/kotlin/io/github/typesafegithub/workflows/jitbindingserver/ActionCoordsTest.kt @@ -77,20 +77,6 @@ class ActionCoordsTest : path = "dir_one/dir-two", ) } - - test("empty path part yields no path") { - // zero-width space as noise - val parameters = createParameters(owner = "o", name = "act__\u200B___major", version = "v3") - - parameters.extractActionCoords(true) shouldBe - ActionCoords( - owner = "o", - name = "act", - version = "v3", - significantVersion = MAJOR, - path = null, - ) - } }, )