An inbound forward is shown as one rather than as the sender's own words. Both flag shapes accepted, like ctl: org.json's optBoolean does not coerce a number, so an engine reading one shape would silently miss every forward the other two send. ⚠️ The subtle one: Content.text returns raw bytes with no envelope at all when there is no id, reply or link to carry. A forward that was not counted in that condition would lose its flag and arrive looking like the sender's own composition — so is part of the test for whether an envelope is needed, not just a field inside it. Codec only. Originating a forward needs the transcript work in #10. Refs paulhitt/flamenet-messenger-ios#28 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
97 lines
3.6 KiB
Kotlin
97 lines
3.6 KiB
Kotlin
package io.flamenet.e2e
|
|
|
|
import kotlin.test.Test
|
|
import kotlin.test.assertEquals
|
|
import kotlin.test.assertFalse
|
|
import kotlin.test.assertNull
|
|
import kotlin.test.assertTrue
|
|
import org.json.JSONObject
|
|
|
|
/**
|
|
* Passing a message on without passing on where it came from (§6.16).
|
|
*
|
|
* ⚠️ **The codec half.** The Android app cannot forward yet — that needs the
|
|
* transcript work in #10 — but it must already understand an envelope the
|
|
* iPhone app sends, so a forwarded message arrives as a message and not as
|
|
* something the reader is told nothing about.
|
|
*/
|
|
class ForwardWithoutProvenanceTest {
|
|
|
|
@Test
|
|
fun `a forwarded message is marked as forwarded`() {
|
|
val content = Content.parse(Content.text("meet at 6", forwarded = true))
|
|
assertTrue(content.isForwarded)
|
|
assertEquals("meet at 6", content.text)
|
|
}
|
|
|
|
@Test
|
|
fun `an ordinary message is not marked forwarded`() {
|
|
assertFalse(Content.parse(Content.text("meet at 6")).isForwarded)
|
|
}
|
|
|
|
/**
|
|
* 🔴 The whole point: the envelope says THAT it was forwarded and nothing
|
|
* about who wrote it or what it answered.
|
|
*/
|
|
@Test
|
|
fun `the envelope carries no author and no reply chain`() {
|
|
val wire = Content.text("meet at 6", forwarded = true)
|
|
assertFalse(wire.contains("author"), "the envelope carries an author: $wire")
|
|
assertFalse(wire.contains("\"re\""), "the envelope carries a reply chain: $wire")
|
|
assertNull(Content.parse(wire).about)
|
|
}
|
|
|
|
/**
|
|
* ⚠️ `1`, not `true` — §6.10's shape. `org.json`'s optBoolean does not
|
|
* coerce a number, so an engine that read only one shape would silently
|
|
* miss every forward the other two engines send.
|
|
*/
|
|
@Test
|
|
fun `both flag shapes are accepted`() {
|
|
val asNumber = Content.text("hi", forwarded = true)
|
|
assertTrue(asNumber.contains("\"fwd\":1"), "wrote the wrong shape: $asNumber")
|
|
assertTrue(Content.parse(asNumber).isForwarded)
|
|
|
|
val asBool = asNumber.replace("\"fwd\":1", "\"fwd\":true")
|
|
assertTrue(Content.parse(asBool).isForwarded,
|
|
"an engine writing `true` would have its forwards read as ordinary messages")
|
|
}
|
|
|
|
/** ⚠️ A forward is still a message: it renders, unlike control traffic. */
|
|
@Test
|
|
fun `a forwarded message is still renderable`() {
|
|
assertTrue(Content.parse(Content.text("meet at 6", forwarded = true)).isRenderable)
|
|
}
|
|
|
|
/** The flag rides an attachment too — a forwarded photo is still a forward. */
|
|
@Test
|
|
fun `a forwarded attachment keeps the flag`() {
|
|
val ref = Attachment.Ref(
|
|
kind = Attachment.IMAGE, id = "a".repeat(64),
|
|
key = ByteArray(32) { 1 }, digest = ByteArray(32) { 2 },
|
|
bytes = 1024, mime = "image/jpeg", width = 100, height = 100,
|
|
duration = 0.0, expires = 0.0,
|
|
)
|
|
val content = Content.parse(
|
|
Content.attachment(ref, caption = "look", forwarded = true))
|
|
assertTrue(content.isForwarded)
|
|
assertEquals("look", content.text)
|
|
}
|
|
|
|
/** ⚠️ `fnc` first, like every other envelope. */
|
|
@Test
|
|
fun `the envelope starts with the marker`() {
|
|
assertTrue(Content.text("hi", forwarded = true).startsWith("{\"fnc\":1,"))
|
|
}
|
|
|
|
/**
|
|
* A missing flag is not a forward — the ordinary case, and the one that
|
|
* every message sent before today takes.
|
|
*/
|
|
@Test
|
|
fun `an envelope with no flag is not a forward`() {
|
|
val json = JSONObject("""{"fnc":1,"kind":"text","caption":"hi"}""")
|
|
assertFalse(Content.parse(json.toString()).isForwarded)
|
|
}
|
|
}
|