Skip to content

refactor: use an LLM to satisfy most detekt issues#428

Merged
nicolasfara merged 5 commits intoreimplementationfrom
refactor/useanllmtosatisfymostdetektissu
Mar 26, 2026
Merged

refactor: use an LLM to satisfy most detekt issues#428
nicolasfara merged 5 commits intoreimplementationfrom
refactor/useanllmtosatisfymostdetektissu

Conversation

@DanySK
Copy link
Copy Markdown
Collaborator

@DanySK DanySK commented Mar 25, 2026

No description provided.

Copilot AI review requested due to automatic review settings March 25, 2026 22:45
@gitguardian
Copy link
Copy Markdown

gitguardian bot commented Mar 25, 2026

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
29200675 Triggered Generic Password 93c341d mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/packet/Connect.kt View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@DanySK DanySK changed the base branch from master to reimplementation March 25, 2026 22:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR performs a major refactor of the codebase: it removes the prior single-module, platform-specific MQTT client implementations and replaces them with a new multi-module architecture (mktt-core for protocol/codec + mktt-client for a coroutine/Flow-based client), along with updated build configuration, dependencies, and tests.

Changes:

  • Split the project into :mktt-core and :mktt-client, updating Gradle settings/build logic and dependency catalog.
  • Introduce MQTT v5 protocol types/packets + encode/decode utilities in mktt-core, and a new Ktor-socket-based client + engine abstraction in mktt-client.
  • Replace the prior end-to-end tests with deterministic codec tests, fake-engine client tests, and Mosquitto (Testcontainers) integration tests.

Reviewed changes

Copilot reviewed 65 out of 65 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/jvmTest/kotlin/io/github/nicolasfara/MqttClientTestJvm.kt Removes old JVM test suite
src/jvmMain/kotlin/io/github/nicolasfara/utils/JavaKotlinUtils.kt Removes JVM helper utilities
src/jvmMain/kotlin/io/github/nicolasfara/adapter/MqttWillAdapter.kt Removes HiveMQ will adapter
src/jvmMain/kotlin/io/github/nicolasfara/MkttClient.jvm.kt Removes old JVM actual factory
src/jvmMain/kotlin/io/github/nicolasfara/HivemqMkttClient.kt Removes HiveMQ-based client
src/jsMain/kotlin/io/github/nicolasfara/facade/MqttJsFacade.kt Removes MQTT.js externals
src/jsMain/kotlin/io/github/nicolasfara/adapter/MkttJsAdapter.kt Removes MQTT.js config adapter
src/jsMain/kotlin/io/github/nicolasfara/MqttJsClient.kt Removes MQTT.js client impl
src/jsMain/kotlin/io/github/nicolasfara/MkttClient.js.kt Removes old JS actual factory
src/commonTest/kotlin/io/github/nicolasfara/configuration/MqttTestConfiguration.kt Removes old test config
src/commonTest/kotlin/io/github/nicolasfara/MqttClientTest.kt Removes old common tests
src/commonTest/kotlin/io/github/nicolasfara/MqttClientSubscribeTest.kt Removes old subscribe tests
src/commonTest/kotlin/io/github/nicolasfara/MqttClientPublishTest.kt Removes old publish tests
src/commonMain/kotlin/io/github/nicolasfara/MqttWill.kt Removes old will model
src/commonMain/kotlin/io/github/nicolasfara/MqttQoS.kt Removes old QoS enum
src/commonMain/kotlin/io/github/nicolasfara/MqttMessage.kt Removes old message model
src/commonMain/kotlin/io/github/nicolasfara/MqttConnectionState.kt Removes old connection state
src/commonMain/kotlin/io/github/nicolasfara/MqttClientConfiguration.kt Removes old config DSL
src/commonMain/kotlin/io/github/nicolasfara/MkttClient.kt Removes old client API
settings.gradle.kts Adds repo mgmt + includes modules
mktt-core/build.gradle.kts New KMP build for core module
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/util/String.kt MQTT string encoding/decoding utils
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/util/MqttDslMarker.kt DSL marker for builders
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/util/Logger.kt Minimal common logger facade
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/util/Int.kt Variable-byte-int codec utilities
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/util/ByteString.kt MQTT bytestring codec utilities
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/packet/Unsubscribe.kt UNSUBSCRIBE packet + codec
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/packet/Unsuback.kt UNSUBACK packet + helpers
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/packet/Subscribe.kt SUBSCRIBE packet + codec
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/packet/Suback.kt SUBACK packet + helpers
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/packet/Publish.kt PUBLISH packet + codec
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/packet/Pingresp.kt PINGRESP packet
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/packet/Pingreq.kt PINGREQ packet
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/packet/PacketType.kt Packet type enum + decoding
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/packet/PacketIdentifierPacket.kt Marker for packets with IDs
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/packet/Packet.kt Packet I/O over Ktor channels
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/packet/Disconnect.kt DISCONNECT packet + codec
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/packet/Connect.kt CONNECT packet + codec
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/packet/Connack.kt CONNACK packet + codec
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/packet/BasePacket.kt Base packet implementation
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/packet/Auth.kt AUTH packet + codec
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/WillProperties.kt Will properties + DSL builder
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/WillMessage.kt Will message + codec + DSL
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/UserProperties.kt User properties model + DSL
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/TopicFilter.kt Topic filter model + DSL
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/Topic.kt Topic value class + helpers
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/SubscriptionOptions.kt Subscription options model
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/StringPair.kt MQTT string pair model + codec
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/SessionStore.kt Session store interface
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/RetainHandling.kt Retain handling enum
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/QoS.kt New QoS enum
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/Preconditions.kt Malformed/well-formed helpers
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/InFlightPacket.kt In-flight packet tracking types
mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/Exceptions.kt Protocol/client exception types
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/util/StringTest.kt String codec tests
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/util/IntTest.kt Variable int codec tests
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/util/ByteStringTest.kt ByteString codec tests
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/packet/UnsubscribeTest.kt UNSUBSCRIBE round-trip tests
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/packet/UnsubackTest.kt UNSUBACK round-trip tests
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/packet/SubscribeTest.kt SUBSCRIBE round-trip tests
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/packet/SubackTest.kt SUBACK round-trip tests
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/packet/PublishTest.kt PUBLISH tests + invariants
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/packet/PublishResponseTest.kt PUBACK/REC/REL/COMP tests
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/packet/DisconnectTest.kt DISCONNECT tests
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/packet/ConnectTest.kt CONNECT encoding/decoding tests
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/packet/ConnackTest.kt CONNACK tests
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/packet/AuthTest.kt AUTH tests
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/packet/Assertions.kt Shared encode/decode assertion
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/TopicTest.kt Topic parsing helper tests
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/StringPairTest.kt StringPair codec tests
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/SessionExpiryIntervalTest.kt Session expiry interval tests
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/ServerReferenceTest.kt Server reference parsing tests
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/ReceiveMaximumTest.kt ReceiveMaximum invariant test
mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/MaximumPacketSizeTest.kt MaximumPacketSize invariant test
mktt-client/build.gradle.kts New KMP build for client module
mktt-client/src/jvmTest/resources/server.key Adds Mosquitto TLS private key
mktt-client/src/jvmTest/resources/server.crt Adds Mosquitto TLS certificate
mktt-client/src/jvmTest/resources/passwd Adds Mosquitto password file
mktt-client/src/jvmTest/resources/mosquitto.conf Adds Mosquitto config
mktt-client/src/jvmTest/resources/client.key Adds client TLS private key
mktt-client/src/jvmTest/resources/client.crt Adds client TLS certificate
mktt-client/src/jvmTest/resources/ca.crt Adds CA certificate
mktt-client/src/jvmTest/resources/Dockerfile Adds Mosquitto test image
mktt-client/src/jvmTest/kotlin/io/github/nicolasfara/mktt/client/NoTrustManager.kt Test trust manager helper
mktt-client/src/jvmTest/kotlin/io/github/nicolasfara/mktt/client/MqttClientIntegrationTest.kt JVM Mosquitto integration tests
mktt-client/src/jvmTest/kotlin/io/github/nicolasfara/mktt/client/MosquittoContainer.kt Testcontainers Mosquitto wrapper
mktt-client/src/commonTest/kotlin/io/github/nicolasfara/mktt/client/RemoteBrokerIntegrationTest.kt External broker integration test
mktt-client/src/commonTest/kotlin/io/github/nicolasfara/mktt/client/MqttClientTest.kt Fake-engine client behavior tests
mktt-client/src/commonTest/kotlin/io/github/nicolasfara/mktt/client/FakeMqttEngine.kt Fake engine for tests
mktt-client/src/commonMain/kotlin/io/github/nicolasfara/mktt/client/PublishResponse.kt Publish response result types
mktt-client/src/commonMain/kotlin/io/github/nicolasfara/mktt/client/PublishRequest.kt Publish DSL request model
mktt-client/src/commonMain/kotlin/io/github/nicolasfara/mktt/client/MqttEngineFactory.kt Engine factory abstraction
mktt-client/src/commonMain/kotlin/io/github/nicolasfara/mktt/client/MqttEngine.kt Engine interface abstraction
mktt-client/src/commonMain/kotlin/io/github/nicolasfara/mktt/client/MqttClientConfig.kt Client config DSL + immutable config
mktt-client/src/commonMain/kotlin/io/github/nicolasfara/mktt/client/InMemorySessionStore.kt Session store implementation
mktt-client/src/commonMain/kotlin/io/github/nicolasfara/mktt/client/Hashing.kt Shared hash helper
mktt-client/src/commonMain/kotlin/io/github/nicolasfara/mktt/client/DefaultEngineFactory.kt Default engine factory/config
mktt-client/src/commonMain/kotlin/io/github/nicolasfara/mktt/client/DefaultEngine.kt Ktor socket-based engine
mktt-client/src/commonMain/kotlin/io/github/nicolasfara/mktt/client/ConnectionState.kt Client state + message model
gradle/libs.versions.toml Replaces deps (Arrow/HiveMQ → Ktor/kotlinx-io/Testcontainers)
build.gradle.kts Simplifies root build; moves config to subprojects
README.md Updates docs for new modules/APIs
.editorconfig Updates ktlint/IDE formatting settings
Comments suppressed due to low confidence (3)

mktt-core/src/commonMain/kotlin/io/github/nicolasfara/mktt/core/packet/PacketType.kt:84

  • _root_ide_package_ is not valid Kotlin and will not compile. Replace this with the real exception type (e.g., io.github.nicolasfara.mktt.core.MalformedPacketException) and ensure the proper import/qualification is used.
    mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/util/StringTest.kt:20
  • Typo in comment: "teh" → "the".
    mktt-core/src/commonTest/kotlin/io/github/nicolasfara/mktt/core/packet/ConnectTest.kt:181
  • This test prints to stdout (println(actual)), which can add noise and slow down CI. Please remove the print or replace it with assertions if you intended to verify something about the decoded packet.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"Packets without packet identifier cannot be part of a transaction"
}

return !incomingPackets.add(packetIdentifier)
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

rememberIncomingPacketId returns the opposite of what the SessionStore contract documents. MutableSet.add returns true when the id was NOT present; the current !incomingPackets.add(...) therefore returns false for first-seen packets and true for re-deliveries. Flip the boolean (or rename the method/adjust KDoc) so callers can correctly detect duplicates.

Suggested change
return !incomingPackets.add(packetIdentifier)
return incomingPackets.add(packetIdentifier)

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +35
class RemoteBrokerIntegrationTest {
@Test
fun `connects to public test broker and exchanges a message`() = runTest {
withContext(Dispatchers.Default.limitedParallelism(1)) {
val topicName = "mktt/remote-test/${Random.nextLong().toString(16)}"
val filter = TopicFilter(
Topic(topicName),
)
val subscriber =
MqttClient(TEST_BROKER_HOST, TEST_BROKER_PORT) {
clientId = "mktt-remote-sub-${Random.nextLong().toString(16)}"
}
val publisher =
MqttClient(TEST_BROKER_HOST, TEST_BROKER_PORT) {
clientId = "mktt-remote-pub-${Random.nextLong().toString(16)}"
}
val dispatcher = coroutineContext[ContinuationInterceptor] as CoroutineDispatcher
val topicName = "mktt/remote-test/${Random.nextLong().toString(16)}"
val filter = TopicFilter(
Topic(topicName),
)
val subscriber =
MqttClient(TEST_BROKER_HOST, TEST_BROKER_PORT) {
this.dispatcher = dispatcher
clientId = "mktt-remote-sub-${Random.nextLong().toString(16)}"
}
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

This integration test depends on an external public broker (test.mosquitto.org) and is not guarded by a skip flag, making the build flaky/offline-hostile. Consider moving it to a dedicated integration-test source set, or add an env-based skip (similar to SKIP_INTEGRATION_TEST) so regular CI/unit test runs don’t rely on external network availability.

Copilot uses AI. Check for mistakes.
Comment on lines 38 to 41
/**
* Writes the specified string as an MQTT string, hence writing first the size of the string, then the ZTF-8 encoded
* string.
*
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

KDoc typo: this says "ZTF-8" but should be "UTF-8".

Copilot uses AI. Check for mistakes.
Comment on lines +22 to +28
private fun consoleLog(throwable: Throwable?, message: () -> String) {
// Keep this logger as a no-op while still consuming parameters for static analysis.
throwable?.let(::println)
throwable?.let {
println(message())
throwable.printStackTrace()
}
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

The comment says the logger is a no-op, but it currently prints to stdout/stderr (and only logs when throwable != null). Either make this truly a no-op, or update the implementation to log messages consistently (and adjust the comment accordingly) so behavior matches the intent.

Copilot uses AI. Check for mistakes.
@nicolasfara nicolasfara merged commit 3a0cc5f into reimplementation Mar 26, 2026
10 checks passed
@nicolasfara nicolasfara deleted the refactor/useanllmtosatisfymostdetektissu branch March 26, 2026 11:28
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.

3 participants