mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-10-05 19:28:25 +00:00
refactor: extract duplicated string literals flagged by Sonar
StreamCommands read the "stream-id" flag name in four places and MarmotBenchmarks repeated the "wss://bench.invalid" relay URL three times. Each is now a private const in its file.
This commit is contained in:
@@ -52,6 +52,8 @@ import kotlinx.coroutines.withTimeoutOrNull
|
||||
* kind:9.
|
||||
*/
|
||||
object StreamCommands {
|
||||
private const val STREAM_ID_FLAG = "stream-id"
|
||||
|
||||
val USAGE: String =
|
||||
"""
|
||||
|amy marmot stream — agent text stream previews over QUIC
|
||||
@@ -105,7 +107,7 @@ object StreamCommands {
|
||||
val positional = args.positional
|
||||
if (positional.isEmpty()) return Output.error("bad_args", "stream start GID [--stream-id HEX] [--broker URI]…")
|
||||
|
||||
val streamId = args.flag("stream-id") ?: MlsCryptoProvider.randomBytes(32).toHexKey()
|
||||
val streamId = args.flag(STREAM_ID_FLAG) ?: MlsCryptoProvider.randomBytes(32).toHexKey()
|
||||
if (streamId.length != 64) return Output.error("bad_args", "--stream-id must be 32 bytes of hex")
|
||||
// Repeatable in the spec, comma-separated here: `Args` keeps one
|
||||
// value per flag and a receiver tries them in the order given.
|
||||
@@ -149,7 +151,7 @@ object StreamCommands {
|
||||
): Int {
|
||||
val args = Args(rest)
|
||||
val positional = args.positional
|
||||
val streamId = args.flag("stream-id")
|
||||
val streamId = args.flag(STREAM_ID_FLAG)
|
||||
val startEventId = args.flag("start-event-id")
|
||||
val broker = args.flag("broker")
|
||||
// The two delivery modes are alternatives, not a fallback chain: one
|
||||
@@ -265,7 +267,7 @@ object StreamCommands {
|
||||
ctx.syncIncoming()
|
||||
if (!ctx.marmot.isMember(gid)) return Output.error("not_member", "not a member of group $gid")
|
||||
|
||||
val wanted = args.flag("stream-id")
|
||||
val wanted = args.flag(STREAM_ID_FLAG)
|
||||
val anchor =
|
||||
findStart(ctx, gid, wanted)
|
||||
?: return Output.error("no_stream", "no kind:1200 stream start in group $gid")
|
||||
@@ -363,7 +365,7 @@ object StreamCommands {
|
||||
): Int {
|
||||
val args = Args(rest)
|
||||
val positional = args.positional
|
||||
val streamId = args.flag("stream-id")
|
||||
val streamId = args.flag(STREAM_ID_FLAG)
|
||||
val transcriptHash = args.flag("transcript-hash")
|
||||
val chunkCount = args.flag("chunk-count")?.toLongOrNull()
|
||||
if (positional.size < 2 || streamId == null || transcriptHash == null || chunkCount == null) {
|
||||
|
||||
@@ -87,7 +87,7 @@ fun benchCreateGroup(invitees: Int): BenchResult =
|
||||
runBlocking {
|
||||
alice.manager.createCurrentProfileGroup(
|
||||
nostrGroupId = groupId,
|
||||
relays = listOf("wss://bench.invalid"),
|
||||
relays = listOf(BENCH_RELAY),
|
||||
profile = GroupProfileV1("bench", ""),
|
||||
)
|
||||
if (kps.isNotEmpty()) alice.manager.addMembers(groupId, kps, emptyList())
|
||||
@@ -104,7 +104,7 @@ fun benchCreateGroup(invitees: Int): BenchResult =
|
||||
private suspend fun groupWithMembers(members: Int): Triple<Client, List<Client>, HexKey> {
|
||||
val alice = Client("alice")
|
||||
val groupId = newGroupId()
|
||||
alice.manager.createCurrentProfileGroup(groupId, listOf("wss://bench.invalid"), GroupProfileV1("bench", ""))
|
||||
alice.manager.createCurrentProfileGroup(groupId, listOf(BENCH_RELAY), GroupProfileV1("bench", ""))
|
||||
val invitees = (0 until members).map { Client("member-$it") }
|
||||
if (invitees.isNotEmpty()) {
|
||||
val kps = invitees.map { it.manager.generateKeyPackageEvent(relays = emptyList()) }
|
||||
@@ -163,7 +163,7 @@ fun benchJoinWelcome(): BenchResult =
|
||||
val alice = Client("alice")
|
||||
val bob = Client("bob")
|
||||
val groupId = newGroupId()
|
||||
alice.manager.createCurrentProfileGroup(groupId, listOf("wss://bench.invalid"), GroupProfileV1("bench", ""))
|
||||
alice.manager.createCurrentProfileGroup(groupId, listOf(BENCH_RELAY), GroupProfileV1("bench", ""))
|
||||
val kp = bob.manager.generateKeyPackageEvent(relays = emptyList())
|
||||
val (_, welcome) = alice.manager.addMember(groupId, kp, emptyList())
|
||||
bob to welcome!!.giftWrapEvent
|
||||
@@ -226,6 +226,8 @@ fun benchIngestAppMessage(members: Int): BenchResult =
|
||||
runBlocking { bob.manager.ingest(event as GroupEvent) }
|
||||
}
|
||||
|
||||
private const val BENCH_RELAY = "wss://bench.invalid"
|
||||
|
||||
private const val PAYLOAD = "marmot benchmark payload — the same 64-ish byte body both sides send"
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user