test: pin what a group-signed profile and post do today (group-nostr-profile, Phase 1)

A room-signed kind:0 writes no line, a room-signed kind:1 is a raw-JSON
bubble, and the stored types older builds wrote stay system lines. The
premise the plan rests on is pinned in the signing harness: what a keyed
room signs passes GroupSignedEvent.verifies on every device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5.5 committed 2026-11-21 20:24:21 +02:00
1 parent bdb0b3f0a5
commit b4d0e483b5
2 files changed
+118

No files matched your search

@@ -0,0 +1,87 @@
package mobi.giza.compose.database.model
import androidx.room3.Room
import com.vitorpamplona.quartz.nip01Core.core.Event
import com.vitorpamplona.quartz.nip01Core.core.toHexKey
import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair
import com.vitorpamplona.quartz.nip01Core.metadata.MetadataEvent
import com.vitorpamplona.quartz.nip01Core.signers.NostrSignerSync
import com.vitorpamplona.quartz.nip10Notes.TextNoteEvent
import kotlin.test.AfterTest
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
import kotlin.test.assertTrue
import kotlin.time.Instant
import kotlinx.coroutines.runBlocking
import mobi.giza.compose.database.GizaDatabase
import mobi.giza.compose.database.builder.getRoomDatabase
/**
* What the transcript does with a profile or a post the group signed as itself.
*
* `applyInnerEvent` is reached three ways -- a rumor arriving in the room, a
* signing session completing, a chronicle page -- and these are signed the way a
* completed session's are: by the key whose public half is the room's id.
* docs/group-nostr-profile-and-posts.md.
*/
class GroupStatementApplyJvmTest {
private val database: GizaDatabase = getRoomDatabase(Room.inMemoryDatabaseBuilder<GizaDatabase>())
@AfterTest
fun closeDb() = database.close()
/** The room's own key: its public half is the room's id, as for a derived room. */
private val room = KeyPair()
private val roomId = room.pubKey.toHexKey()
private val member = KeyPair()
private fun signedBy(keyPair: KeyPair, kind: Int, content: String): Event =
NostrSignerSync(keyPair).signNormal(
createdAt = 1_700_000_000,
kind = kind,
tags = emptyArray(),
content = content,
)
private suspend fun apply(event: Event): ChatMessage? = ChatMessage.applyInnerEvent(
database = database,
groupId = roomId,
event = event,
marmotGroupEventId = null,
marmotInnerEventId = null,
senderPublicKey = member.pubKey.toHexKey(),
isUserMessage = false,
createdAt = Instant.fromEpochSeconds(1_700_000_000),
groupSignedEventId = event.id,
)
@Test
fun `a profile the room signed is no line`(): Unit = runBlocking {
val profile = signedBy(room, MetadataEvent.KIND, """{"name":"Translation collective"}""")
assertNull(apply(profile))
}
@Test
fun `a post the room signed is a raw bubble`(): Unit = runBlocking {
val post = signedBy(room, TextNoteEvent.KIND, "We meet on Thursday")
assertEquals("unsupported", apply(post)?.messageType)
}
@Test
fun `a member's own post is a raw bubble`(): Unit = runBlocking {
val post = signedBy(member, TextNoteEvent.KIND, "We meet on Thursday")
assertEquals("unsupported", apply(post)?.messageType)
}
@Test
fun `lines older builds wrote for the group's profile and posts stay system lines`() {
listOf("groupProfileSigned", "groupPostSigned").forEach { type ->
assertTrue(type in ChatMessage.GROUP_IDENTITY_TYPES, type)
}
}
}
@@ -1253,6 +1253,37 @@ class SignedGroupKeyStateTest {
}
}
/**
* The premise docs/group-nostr-profile-and-posts.md rests on: what a keyed room
* signs passes `GroupSignedEvent.verifies`, the one gate every reader of the
* group's profile and posts puts an event through. If this fails, the group has
* no nostr identity a reader would accept, whatever screens sit on top.
*/
@Test
fun `a post the group signs verifies as the room's own statement`() = runBlocking {
val creator = device(members[0], signerIndex = 0)
val other = device(members[1], signerIndex = 1)
val template = TextNoteEvent.build(note = "Sepedi")
val session = FrostSigningManager.proposeSigning(
database = creator.db,
localChatRoom = creator.room,
userPublicKey = creator.publicKey,
kind = template.kind,
tags = template.tags,
content = template.content
)
pump(creator, other)
FrostSigningManager.approve(other.db, other.room, session.id)
pump(creator, other)
listOf(creator, other).forEach { device ->
val post = assertNotNull(device.db.groupSignedEventDao().getById(device.item(session.id).eventId))
assertTrue(post.verifies(), "the room's reader would refuse its own post")
assertEquals(device.room.chatRoom.id, post.chatRoomId)
}
}
@Test
fun `a proposer cannot choose the key the group signs as`() = runBlocking {
val other = device(members[1], signerIndex = 1)