Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

refactor(web): remove community event versions (#520)

Gener3d2b4e5f0d1d
diff --git a/src/shared/src/community-ws-bundle.ts b/src/shared/src/community-ws-bundle.ts
index 2a8a8d97e..07478e773 100644
--- a/src/shared/src/community-ws-bundle.ts
+++ b/src/shared/src/community-ws-bundle.ts
@@ -1,10 +1,8 @@
import {
- COMMUNITY_BROWSER_EVENT_CONTRACT_VERSION,
COMMUNITY_BROWSER_EVENT_MAX_BYTES,
decodeCommunityBrowserEvent,
encodeCommunityBrowserEvent,
utf8ByteLength,
- type CommunityBrowserEventEnvelopeV1,
type CommunityWsEvent,
} from "./community-ws-events"
import { MESSAGE_DELIVERY_MAX_EVENTS_PER_USER } from "./community-message-delivery"
@@ -29,12 +27,12 @@ export type CommunityBrowserEventBatch = {
type: typeof COMMUNITY_BROWSER_EVENT_BATCH_TYPE
operationId: CommunityDeliveryOperationId
operationDigest: CommunityDeliveryDigest
- events: CommunityBrowserEventEnvelopeV1[]
+ events: CommunityWsEvent[]
}
export type PreparedCommunityDeliveryEvents = {
events: CommunityWsEvent[]
- envelopes: CommunityBrowserEventEnvelopeV1[]
+ envelopes: CommunityWsEvent[]
bodies: string[]
digest: CommunityDeliveryDigest
}
@@ -192,7 +190,7 @@ export async function prepareCommunityDeliveryEvents(
return { ok: false, reason: "invalid-event-count" }
}
const events: CommunityWsEvent[] = []
- const envelopes: CommunityBrowserEventEnvelopeV1[] = []
+ const envelopes: CommunityWsEvent[] = []
const bodies: string[] = []
for (let eventIndex = 0; eventIndex < values.length; eventIndex += 1) {
const decoded = decodeCommunityBrowserEvent(values[eventIndex])
@@ -322,14 +320,14 @@ export function decodeCommunityBrowserEventBatch(
return { ok: false, reason: "invalid-event-count" }
}
const events: CommunityWsEvent[] = []
- const envelopes: CommunityBrowserEventEnvelopeV1[] = []
+ const envelopes: CommunityWsEvent[] = []
for (let eventIndex = 0; eventIndex < value.events.length; eventIndex += 1) {
const child = decodeCommunityBrowserEvent(value.events[eventIndex])
- if (!child.ok || child.sourceVersion !== COMMUNITY_BROWSER_EVENT_CONTRACT_VERSION) {
+ if (!child.ok) {
return { ok: false, reason: "invalid-child", eventIndex }
}
events.push(child.event)
- envelopes.push(value.events[eventIndex] as CommunityBrowserEventEnvelopeV1)
+ envelopes.push(child.event)
}
return {
ok: true,
diff --git a/src/shared/src/community-ws-events.ts b/src/shared/src/community-ws-events.ts
index 3a5222d01..1e4464232 100644
--- a/src/shared/src/community-ws-events.ts
+++ b/src/shared/src/community-ws-events.ts
@@ -609,16 +609,11 @@ void exactCommunityEventTypes
const COMMUNITY_EVENT_TYPES: ReadonlySet<string> = new Set(Object.values(WS_EVENTS))
-export const COMMUNITY_BROWSER_EVENT_CONTRACT_VERSION = 1 as const
export const COMMUNITY_BROWSER_EVENT_MAX_BYTES = 65_536
export const COMMUNITY_USER_TARGET_MAX_BYTES = 128
export const COMMUNITY_USER_TARGET_PATH_PREFIX = "u:"
export const COMMUNITY_BULK_BODY_MAX_BYTES = 837_347
-export type CommunityBrowserEventEnvelopeV1 = CommunityWsEvent & {
- contractVersion: typeof COMMUNITY_BROWSER_EVENT_CONTRACT_VERSION
-}
-
export type CommunityBrowserEventFailureReason =
| "oversized"
| "invalid-json"
@@ -626,7 +621,6 @@ export type CommunityBrowserEventFailureReason =
| "missing-type"
| "wrong-family"
| "unknown-community-type"
- | "unsupported-version"
| "invalid-payload"
| "invalid-target"
| "too-many-targets"
@@ -634,18 +628,17 @@ export type CommunityBrowserEventFailureReason =
| "duplicate-auth-ok"
export type CommunityBrowserEventDecodeResult =
- | { ok: true; event: CommunityWsEvent; sourceVersion: 0 | 1 }
+ | { ok: true; event: CommunityWsEvent }
| {
ok: false
reason: CommunityBrowserEventFailureReason
type: CommunityWsEvent["type"] | "unknown"
- contractVersion?: number
}
export type CommunityBrowserEventEncodeResult =
| {
ok: true
- event: CommunityBrowserEventEnvelopeV1
+ event: CommunityWsEvent
body: string
byteLength: number
}
@@ -713,39 +706,16 @@ export function decodeCommunityBrowserEvent(value: unknown): CommunityBrowserEve
return { ok: false, reason: "unknown-community-type", type: "unknown" }
}
- const hasVersion = Object.prototype.hasOwnProperty.call(value, "contractVersion")
- const rawVersion = value.contractVersion
- if (hasVersion && rawVersion !== COMMUNITY_BROWSER_EVENT_CONTRACT_VERSION) {
- return {
- ok: false,
- reason: "unsupported-version",
- type: value.type,
- ...(typeof rawVersion === "number" && Number.isSafeInteger(rawVersion)
- ? { contractVersion: rawVersion }
- : {}),
- }
- }
-
- const eventValue = hasVersion
- ? Object.fromEntries(Object.entries(value).filter(([key]) => key !== "contractVersion"))
- : value
- const parsed = CommunityWsEventSchema.safeParse(eventValue)
+ const parsed = CommunityWsEventSchema.safeParse(value)
if (!parsed.success) return { ok: false, reason: "invalid-payload", type: value.type }
- return {
- ok: true,
- event: parsed.data,
- sourceVersion: hasVersion ? 1 : 0,
- }
+ return { ok: true, event: parsed.data }
}
export function encodeCommunityBrowserEvent(value: unknown): CommunityBrowserEventEncodeResult {
const parsed = CommunityWsEventSchema.safeParse(value)
const type = isRecord(value) && isCommunityEventType(value.type) ? value.type : "unknown"
if (!parsed.success) return { ok: false, reason: "invalid-payload", type }
- const event = {
- ...parsed.data,
- contractVersion: COMMUNITY_BROWSER_EVENT_CONTRACT_VERSION,
- } satisfies CommunityBrowserEventEnvelopeV1
+ const event = parsed.data
const body = JSON.stringify(event)
const byteLength = utf8ByteLength(body)
if (byteLength > COMMUNITY_BROWSER_EVENT_MAX_BYTES) {
diff --git a/src/shared/src/index.ts b/src/shared/src/index.ts
index 512b811e9..567571281 100644
--- a/src/shared/src/index.ts
+++ b/src/shared/src/index.ts
@@ -583,7 +583,6 @@ export type {
CommunityMachineRemoved,
CommunityBotAuditEvent,
CommunityWsEvent,
- CommunityBrowserEventEnvelopeV1,
CommunityBrowserEventFailureReason,
CommunityBrowserEventDecodeResult,
CommunityBrowserEventEncodeResult,
@@ -591,7 +590,6 @@ export type {
export {
CommunityWsEventSchema,
FriendApprovalPayloadSchema,
- COMMUNITY_BROWSER_EVENT_CONTRACT_VERSION,
COMMUNITY_BROWSER_EVENT_MAX_BYTES,
COMMUNITY_USER_TARGET_MAX_BYTES,
COMMUNITY_USER_TARGET_PATH_PREFIX,
diff --git a/src/shared/test/community-ws-bundle.contract.test.ts b/src/shared/test/community-ws-bundle.contract.test.ts
index 7a4d6a569..45d019a83 100644
--- a/src/shared/test/community-ws-bundle.contract.test.ts
+++ b/src/shared/test/community-ws-bundle.contract.test.ts
@@ -207,7 +207,7 @@ describe("community WS batch transport contract", () => {
})).toMatchObject({ ok: false, reason: "invalid-operation-digest" })
expect(decodeCommunityBrowserEventBatch({
...encoded.batch,
- events: [{ ...encoded.batch.events[0], contractVersion: undefined }],
+ events: [{ ...encoded.batch.events[0], contractVersion: 1 }],
})).toMatchObject({ ok: false, reason: "invalid-child", eventIndex: 0 })
expect(decodeCommunityBrowserEventBatch(encoded.batch, COMMUNITY_BROWSER_EVENT_BATCH_MAX_BYTES + 1)).toEqual({
ok: false,
diff --git a/src/shared/test/community-ws-events.contract.test.ts b/src/shared/test/community-ws-events.contract.test.ts
index f20c2f357..6f5b5918b 100644
--- a/src/shared/test/community-ws-events.contract.test.ts
+++ b/src/shared/test/community-ws-events.contract.test.ts
@@ -71,20 +71,16 @@ describe("Community browser event runtime contract", () => {
expect(Object.keys(requiredFixturePaths).sort()).toEqual(names)
})
- it("decodes all legacy and v1 fixtures and emits flat v1", () => {
+ it("decodes and canonically encodes all 41 current event fixtures", () => {
for (const fixture of fixtures) {
- const legacy = decodeCommunityBrowserEvent(fixture)
- expect(legacy).toEqual({ ok: true, event: fixture, sourceVersion: 0 })
+ expect(decodeCommunityBrowserEvent(fixture)).toEqual({ ok: true, event: fixture })
const encoded = encodeCommunityBrowserEvent(fixture)
expect(encoded.ok).toBe(true)
if (!encoded.ok) continue
- expect(encoded.event.type).toBe(fixture.type)
- expect(encoded.event.contractVersion).toBe(1)
- expect(decodeCommunityBrowserEvent(encoded.event)).toEqual({
- ok: true,
- event: fixture,
- sourceVersion: 1,
- })
+ expect(encoded.event).toEqual(fixture)
+ expect(encoded.event).not.toHaveProperty("contractVersion")
+ expect(JSON.parse(encoded.body)).toEqual(fixture)
+ expect(decodeCommunityBrowserEvent(encoded.event)).toEqual({ ok: true, event: fixture })
}
})
@@ -99,16 +95,18 @@ describe("Community browser event runtime contract", () => {
}
})
- it("fails closed for family, version, shape, and strict-key errors", () => {
+ it("fails closed for family, removed-version, shape, and strict-key errors", () => {
expect(decodeCommunityBrowserEvent(null)).toMatchObject({ reason: "non-object" })
expect(decodeCommunityBrowserEvent([])).toMatchObject({ reason: "non-object" })
expect(decodeCommunityBrowserEvent({})).toMatchObject({ reason: "missing-type" })
expect(decodeCommunityBrowserEvent({ type: "task.messages" })).toMatchObject({ reason: "wrong-family" })
expect(decodeCommunityBrowserEvent({ type: "community:future" })).toMatchObject({ reason: "unknown-community-type" })
- expect(decodeCommunityBrowserEvent({ ...fixtures[0], contractVersion: 2 })).toMatchObject({
- reason: "unsupported-version",
- contractVersion: 2,
- })
+ expect(decodeCommunityBrowserEvent({ ...fixtures[0], contractVersion: 1 }))
+ .toMatchObject({ reason: "invalid-payload" })
+ expect(encodeCommunityBrowserEvent({ ...fixtures[0], contractVersion: 1 }))
+ .toMatchObject({ ok: false, reason: "invalid-payload" })
+ expect(decodeCommunityBrowserEvent({ ...fixtures[0], contractVersion: 2 }))
+ .toMatchObject({ reason: "invalid-payload" })
expect(decodeCommunityBrowserEvent({ ...fixtures[0], extra: true })).toMatchObject({ reason: "invalid-payload" })
const nestedExtra = clone(communityWsEventFixtures["community:message.create"]) as CommunityMessageCreate & {
message: CommunityMessageCreate["message"] & { extra: boolean }
diff --git a/src/web/src/hooks/community/community-ws/bundle-events.test.ts b/src/web/src/hooks/community/community-ws/bundle-events.test.ts
index 837896918..455b60773 100644
--- a/src/web/src/hooks/community/community-ws/bundle-events.test.ts
+++ b/src/web/src/hooks/community/community-ws/bundle-events.test.ts
@@ -133,7 +133,7 @@ describe("useCommunityWs — operation bundles", () => {
const frame = await batchFor("message-malformed", mentionEvents)
capturedOnMessage!({
...frame,
- events: [...frame.events, { type: "community:future", contractVersion: 1 }],
+ events: [{ ...frame.events[0], contractVersion: 1 }, ...frame.events.slice(1)],
})
const { useCommunityWsStore } = await import("@/stores/community/ws")
@@ -153,10 +153,7 @@ describe("useCommunityWs — operation bundles", () => {
type: COMMUNITY_BROWSER_EVENT_BATCH_TYPE,
extra: true,
})
- capturedOnMessage!({
- type: "community:message.create",
- contractVersion: 2,
- })
+ capturedOnMessage!({ ...message, contractVersion: 1 })
expect(warn).toHaveBeenCalledWith(
"[ws] frame dropped",
@@ -168,7 +165,7 @@ describe("useCommunityWs — operation bundles", () => {
)
expect(warn).toHaveBeenCalledWith(
"[ws] frame dropped",
- expect.objectContaining({ type: "community:message.create", contractVersion: 2 }),
+ expect.objectContaining({ reason: "invalid-payload", type: "community:message.create" }),
)
})
diff --git a/src/web/src/hooks/community/use-community-ws.ts b/src/web/src/hooks/community/use-community-ws.ts
index cd6f1703d..499d2aa52 100644
--- a/src/web/src/hooks/community/use-community-ws.ts
+++ b/src/web/src/hooks/community/use-community-ws.ts
@@ -252,10 +252,6 @@ export function useCommunityWs(options?: UseCommunityWsOptions): void {
const metadata = {
reason: decoded.reason,
type: isCommunityEventType(msg.type) ? msg.type : "unknown",
- ...(typeof msg.contractVersion === "number"
- && Number.isSafeInteger(msg.contractVersion)
- ? { contractVersion: msg.contractVersion }
- : {}),
} as const
console.warn("[ws] frame dropped", {
event: "community_ws_frame_dropped",
diff --git a/src/web/src/lib/analytics.test.ts b/src/web/src/lib/analytics.test.ts
index a1b46c55c..fef530d10 100644
--- a/src/web/src/lib/analytics.test.ts
+++ b/src/web/src/lib/analytics.test.ts
@@ -249,14 +249,12 @@ describe("analytics utility", () => {
trackCommunityWsFrameDropped({
reason: "oversized",
type: "community:message.create",
- contractVersion: 1,
byteCount: 65_537,
})
expect(mockSendGTMEvent).toHaveBeenCalledWith({
event: "community_ws_frame_dropped",
reason: "oversized",
type: "community:message.create",
- contractVersion: 1,
byteCount: 65_537,
})
})
diff --git a/src/web/src/lib/analytics.ts b/src/web/src/lib/analytics.ts
index 3cc8a8cc8..1cfc7772d 100644
--- a/src/web/src/lib/analytics.ts
+++ b/src/web/src/lib/analytics.ts
@@ -154,7 +154,6 @@ export type CommunityWsFrameDropReason =
| "missing-type"
| "wrong-family"
| "unknown-community-type"
- | "unsupported-version"
| "invalid-payload"
| "invalid-target"
| "too-many-targets"
@@ -187,14 +186,12 @@ function sendCommunityWsGTMEvent(payload: Record<string, unknown>) {
export function trackCommunityWsFrameDropped(params: {
reason: CommunityWsFrameDropReason
type: string
- contractVersion?: number
byteCount?: number
}) {
sendCommunityWsGTMEvent({
event: "community_ws_frame_dropped",
reason: params.reason,
type: params.type,
- ...(params.contractVersion === undefined ? {} : { contractVersion: params.contractVersion }),
...(params.byteCount === undefined ? {} : { byteCount: params.byteCount }),
});
}
diff --git a/src/web/src/lib/broadcast.test.ts b/src/web/src/lib/broadcast.test.ts
index b3332a600..c2e5b3627 100644
--- a/src/web/src/lib/broadcast.test.ts
+++ b/src/web/src/lib/broadcast.test.ts
@@ -265,10 +265,7 @@ describe("broadcastToUser", () => {
expect(String(bindingFetch.mock.calls[0]?.[0])).toBe(
`http://internal/broadcast/community/user/u:${encodeURIComponent(target)}`,
)
- expect(JSON.parse(String(bindingFetch.mock.calls[0]?.[1]?.body))).toEqual({
- ...communityEvent,
- contractVersion: 1,
- })
+ expect(JSON.parse(String(bindingFetch.mock.calls[0]?.[1]?.body))).toEqual(communityEvent)
},
)
@@ -290,6 +287,10 @@ describe("broadcastToUser", () => {
type: "community:future",
payload: "private",
} as any)).rejects.toThrow("invalid community event")
+ await expect(broadcastToUser("u1", {
+ ...communityEvent,
+ contractVersion: 1,
+ } as any)).rejects.toThrow("invalid community event: invalid-payload")
expect(bindingFetch).not.toHaveBeenCalled()
})
diff --git a/src/web/src/lib/use-user-ws.ts b/src/web/src/lib/use-user-ws.ts
index f38020baa..c6c791ac1 100644
--- a/src/web/src/lib/use-user-ws.ts
+++ b/src/web/src/lib/use-user-ws.ts
@@ -68,14 +68,9 @@ function reportDroppedFrame(
) {
const rawType = value?.type
const type = isCommunityEventType(rawType) ? rawType : "unknown"
- const rawVersion = value?.contractVersion
- const contractVersion = typeof rawVersion === "number" && Number.isSafeInteger(rawVersion)
- ? rawVersion
- : undefined
const metadata = {
reason,
type,
- ...(contractVersion === undefined ? {} : { contractVersion }),
...(byteCount === undefined ? {} : { byteCount }),
}
console.warn("[ws] frame dropped", { event: "community_ws_frame_dropped", ...metadata })
diff --git a/src/web/src/test/e2e-ui/24-composer-overflow.spec.ts b/src/web/src/test/e2e-ui/24-composer-overflow.spec.ts
index 71ca90522..c4b9aacfa 100644
--- a/src/web/src/test/e2e-ui/24-composer-overflow.spec.ts
+++ b/src/web/src/test/e2e-ui/24-composer-overflow.spec.ts
@@ -210,6 +210,7 @@ test.describe.serial("community composer text containment", () => {
let longMemberId: string
let longMemberDiscriminator: string
let secondaryServerName: string
+ let secondaryChannelSearchToken: string
let secondaryChannelName: string
let secondaryChannelId: string
@@ -226,7 +227,9 @@ test.describe.serial("community composer text containment", () => {
longMemberDiscriminator = longMember.discriminator
secondaryServerName = `secondary-${"s".repeat(90)}`
- secondaryChannelName = `channel-${"c".repeat(92)}`
+ secondaryChannelSearchToken = `overflow-ref-${Date.now()}`
+ await seedChannel("alice", serverId, `${secondaryChannelSearchToken}-anchor`)
+ secondaryChannelName = `${secondaryChannelSearchToken}-${"c".repeat(72)}`
const secondaryServerId = await seedServer("alice", secondaryServerName)
secondaryChannelId = await seedChannel(
"alice",
@@ -342,7 +345,7 @@ test.describe.serial("community composer text containment", () => {
await ignoreNextDevToolsPointerCapture(page)
const editable = composerEditable(page)
await editable.click()
- await editable.pressSequentially("/")
+ await editable.pressSequentially(`/${secondaryChannelSearchToken}`)
const option = page.getByTestId(tid.channelRefOption(secondaryChannelId))
await expect(option).toHaveAttribute(
"title",
diff --git a/src/web/src/test/e2e-ui/_fixtures/community-ws-proxy.ts b/src/web/src/test/e2e-ui/_fixtures/community-ws-proxy.ts
index 4eea5903a..95c1ca7a2 100644
--- a/src/web/src/test/e2e-ui/_fixtures/community-ws-proxy.ts
+++ b/src/web/src/test/e2e-ui/_fixtures/community-ws-proxy.ts
@@ -2,7 +2,6 @@ import type { BrowserContext, WebSocketRoute } from "@playwright/test"
export type CapturedCommunityFrame = {
type: string
- contractVersion?: number
operationId?: string
operationDigest?: string
events?: CapturedCommunityFrame[]
diff --git a/src/ws-do/src/community-browser-event-ingress.test.ts b/src/ws-do/src/community-browser-event-ingress.test.ts
index d3eadf95c..17d32908b 100644
--- a/src/ws-do/src/community-browser-event-ingress.test.ts
+++ b/src/ws-do/src/community-browser-event-ingress.test.ts
@@ -69,18 +69,15 @@ function worstEscapingTarget(index: number) {
}
describe("community browser event ingress", () => {
- it("normalizes all 41 legacy and v1 fixtures", () => {
+ it("normalizes all 41 current fixtures without a version field", () => {
const fixtures = Object.values(communityWsEventFixtures)
expect(fixtures).toHaveLength(41)
for (const fixture of fixtures) {
- const legacy = normalizeCommunityBrowserEvent(fixture)
- expect(legacy).toMatchObject({ ok: true, sourceVersion: 0 })
- if (!legacy.ok) continue
- expect(legacy.envelope.contractVersion).toBe(1)
- expect(normalizeCommunityBrowserEvent(legacy.envelope)).toMatchObject({
- ok: true,
- sourceVersion: 1,
- })
+ const normalized = normalizeCommunityBrowserEvent(fixture)
+ expect(normalized).toMatchObject({ ok: true, event: fixture, envelope: fixture })
+ if (!normalized.ok) continue
+ expect(normalized.envelope).not.toHaveProperty("contractVersion")
+ expect(JSON.parse(normalized.body)).toEqual(fixture)
}
})
@@ -94,8 +91,8 @@ describe("community browser event ingress", () => {
expect(normalizeCommunityBrowserEvent({ type: "community:future" })).toMatchObject({ reason: "unknown-community-type" })
expect(normalizeCommunityBrowserEvent({
...communityWsEventFixtures["community:presence.update"],
- contractVersion: 2,
- })).toMatchObject({ reason: "unsupported-version" })
+ contractVersion: 1,
+ })).toMatchObject({ reason: "invalid-payload" })
})
it("rejects malformed UTF-8, malformed JSON, lying lengths, and streamed overflow", async () => {
@@ -177,7 +174,8 @@ describe("community browser event ingress", () => {
{ ...body, operationId: "message:short" },
{ ...body, operationDigest: "A".repeat(64) },
{ ...body, operationDigest: "0".repeat(64) },
- { ...body, events: [...body.events, { type: "community:future", contractVersion: 1 }] },
+ { ...body, events: [{ ...body.events[0], contractVersion: 1 }, ...body.events.slice(1)] },
+ { ...body, events: [...body.events, { type: "community:future" }] },
{ ...body, extra: true },
]) {
await expect(readCommunityBrowserEventBundleRequest(requestFromBytes(JSON.stringify(invalid))))
diff --git a/src/ws-do/src/community-browser-event-ingress.ts b/src/ws-do/src/community-browser-event-ingress.ts
index 633fa5d6d..6a55ab03b 100644
--- a/src/ws-do/src/community-browser-event-ingress.ts
+++ b/src/ws-do/src/community-browser-event-ingress.ts
@@ -10,7 +10,6 @@ import {
isValidCommunityUserTarget,
prepareCommunityDeliveryEvents,
type CommunityBrowserEventFailureReason,
- type CommunityBrowserEventEnvelopeV1,
type CommunityDeliveryOperationId,
type CommunityDeliveryDigest,
type PreparedCommunityDeliveryEvents,
@@ -21,17 +20,15 @@ export type CommunityBrowserEventIngressFailure = {
ok: false
reason: CommunityBrowserEventFailureReason
type: CommunityWsEvent["type"] | "unknown"
- contractVersion?: number
byteCount?: number
}
type CommunityBrowserEventIngressSuccess = {
ok: true
event: CommunityWsEvent
- envelope: CommunityBrowserEventEnvelopeV1
+ envelope: CommunityWsEvent
body: string
byteCount: number
- sourceVersion: 0 | 1
}
export type CommunityBrowserEventIngressResult =
@@ -115,7 +112,6 @@ export function normalizeCommunityBrowserEvent(
envelope: encoded.event,
body: encoded.body,
byteCount: encoded.byteLength,
- sourceVersion: decoded.sourceVersion,
}
}
@@ -224,7 +220,6 @@ export function logCommunityBrowserEventRejected(
route,
reason: failure.reason,
type: failure.type,
- ...(failure.contractVersion === undefined ? {} : { contractVersion: failure.contractVersion }),
...(failure.byteCount === undefined ? {} : { byteCount: failure.byteCount }),
...(targetCount === undefined ? {} : { targetCount }),
})
diff --git a/src/ws-do/src/routes/audit-broadcast.test.ts b/src/ws-do/src/routes/audit-broadcast.test.ts
index fe1ddb688..cafd04aea 100644
--- a/src/ws-do/src/routes/audit-broadcast.test.ts
+++ b/src/ws-do/src/routes/audit-broadcast.test.ts
@@ -84,7 +84,7 @@ describe("ws-do router", () => {
expect(body.kind).toBe("wake_trigger")
expect(body.createdAt).toBe(payload.createdAt)
expect(body.payload).toEqual(payload.payload)
- expect(body.contractVersion).toBe(1)
+ expect(body).not.toHaveProperty("contractVersion")
})
it("400s on invalid JSON", async () => {
diff --git a/src/ws-do/src/routes/broadcast.test.ts b/src/ws-do/src/routes/broadcast.test.ts
index 023f6481e..ea2d74fe9 100644
--- a/src/ws-do/src/routes/broadcast.test.ts
+++ b/src/ws-do/src/routes/broadcast.test.ts
@@ -39,7 +39,6 @@ const communityPresenceEvent = {
type: "community:presence.update",
userId: "presence-user",
online: true,
- contractVersion: 1,
}
function maximumAuditEnvelope() {
@@ -185,7 +184,8 @@ describe("ws-do router", () => {
)
it.each([
- ["unknown event", { type: "community:unknown", contractVersion: 1 }],
+ ["unknown event", { type: "community:unknown" }],
+ ["removed version field", { ...communityPresenceEvent, contractVersion: 1 }],
["extra event field", { ...communityPresenceEvent, secret: "nope" }],
])("rejects a %s before Durable Object access", async (_label, event) => {
const res = await handler.fetch(new Request(
@@ -197,12 +197,11 @@ describe("ws-do router", () => {
expect(doMock.stubFetch).not.toHaveBeenCalled()
})
- it("normalizes a legacy event to v1 before Durable Object access", async () => {
+ it("canonicalizes a current event before Durable Object access", async () => {
doMock.stubFetch.mockResolvedValue(Response.json({ sent: 1 }))
- const { contractVersion: _, ...legacy } = communityPresenceEvent
const res = await handler.fetch(new Request(
"http://localhost/broadcast/community/user/u:user-1",
- { method: "POST", body: JSON.stringify(legacy) },
+ { method: "POST", body: JSON.stringify(communityPresenceEvent) },
), env as any)
expect(res.status).toBe(200)
diff --git a/src/ws-do/src/ws-durable/machine-frames.test.ts b/src/ws-do/src/ws-durable/machine-frames.test.ts
index 1b4f1ce71..a1c717c79 100644
--- a/src/ws-do/src/ws-durable/machine-frames.test.ts
+++ b/src/ws-do/src/ws-durable/machine-frames.test.ts
@@ -351,8 +351,8 @@ describe("WebSocketDurableObject", () => {
const parsed = bodies.map((b) => JSON.parse(b)).filter((b) => b.type === "community:status.update")
expect(parsed).toEqual(
expect.arrayContaining([
- { contractVersion: 1, type: "community:status.update", userId: "bot_1", statusEmoji: "💤", statusText: "Idle" },
- { contractVersion: 1, type: "community:status.update", userId: "bot_2", statusEmoji: "💤", statusText: "Idle" },
+ { type: "community:status.update", userId: "bot_1", statusEmoji: "💤", statusText: "Idle" },
+ { type: "community:status.update", userId: "bot_2", statusEmoji: "💤", statusText: "Idle" },
])
)
})
diff --git a/src/ws-do/src/ws-durable/machine-restart.test.ts b/src/ws-do/src/ws-durable/machine-restart.test.ts
index 2fbb96987..0f27f0f7f 100644
--- a/src/ws-do/src/ws-durable/machine-restart.test.ts
+++ b/src/ws-do/src/ws-durable/machine-restart.test.ts
@@ -151,7 +151,6 @@ describe("WebSocketDurableObject", () => {
expect(call).toBeDefined()
const body = JSON.parse(await (call!).clone().text()) as Record<string, unknown>
expect(body).toEqual({
- contractVersion: 1,
type: "community:bot.audit_event",
botId: "bot_1",
id: "bae_reset",
diff --git a/src/ws-do/src/ws-durable/machine-telemetry.test.ts b/src/ws-do/src/ws-durable/machine-telemetry.test.ts
index d38bcc844..79ca63fdd 100644
--- a/src/ws-do/src/ws-durable/machine-telemetry.test.ts
+++ b/src/ws-do/src/ws-durable/machine-telemetry.test.ts
@@ -100,7 +100,6 @@ describe("WebSocketDurableObject", () => {
statusText: string
}
expect(body).toEqual({
- contractVersion: 1,
type: "community:status.update",
userId: "bot_1",
statusEmoji: "⚡",
@@ -337,7 +336,6 @@ describe("WebSocketDurableObject", () => {
// Bot path carries name/discriminator from the binding (getBotBindingWithOwner's
// existing join) so the client renders the bot's name without a roster lookup.
expect(body).toEqual({
- contractVersion: 1,
type: "community:typing.start",
userId: "bot_1",
channelId: "dm_1",
@@ -457,7 +455,6 @@ describe("WebSocketDurableObject", () => {
channelId: string
}
expect(body).toEqual({
- contractVersion: 1,
type: "community:typing.stop",
userId: "bot_1",
channelId: "dm_1",
@@ -536,7 +533,6 @@ describe("WebSocketDurableObject", () => {
createdAt: string
}
expect(body).toEqual({
- contractVersion: 1,
type: "community:bot.audit_event",
botId: "bot_1",
id: "bae_abc",
diff --git a/src/ws-do/src/ws-durable/presence-typing.test.ts b/src/ws-do/src/ws-durable/presence-typing.test.ts
index cc20448af..dbabf7de7 100644
--- a/src/ws-do/src/ws-durable/presence-typing.test.ts
+++ b/src/ws-do/src/ws-durable/presence-typing.test.ts
@@ -403,7 +403,7 @@ describe("WebSocketDurableObject", () => {
await (durable as unknown as PresenceInternals).sendPresenceSnapshot(ws as any, "user-1")
expect(ws.send).toHaveBeenCalledWith(
- JSON.stringify({ type: "community:presence.update", userId: "friend-c", online: true, contractVersion: 1 }),
+ JSON.stringify({ type: "community:presence.update", userId: "friend-c", online: true }),
)
})
@@ -442,7 +442,7 @@ describe("WebSocketDurableObject", () => {
expect(ws.send).toHaveBeenCalledWith(JSON.stringify({ type: "auth.ok" }))
expect(ws.send).toHaveBeenCalledWith(
- JSON.stringify({ type: "community:presence.update", userId: "online", online: true, contractVersion: 1 }),
+ JSON.stringify({ type: "community:presence.update", userId: "online", online: true }),
)
expect(ws.send).toHaveBeenCalledTimes(2)
})
@@ -502,7 +502,7 @@ describe("WebSocketDurableObject", () => {
expect(requests.filter((r) => r.body.includes('"userId":"bot-1"') && r.body.includes('"online":true'))).toHaveLength(1)
expect(requests.filter((r) => r.body.includes('"userId":"bot-2"') && r.body.includes('"online":true'))).toHaveLength(1)
expect(requests.every((request) => request.url === "http://internal/community-broadcast")).toBe(true)
- expect(requests.every((request) => JSON.parse(request.body).contractVersion === 1)).toBe(true)
+ expect(requests.every((request) => !("contractVersion" in JSON.parse(request.body)))).toBe(true)
})
it("broadcasts online: false for every bound bot on a machine-offline transition", async () => {
@@ -875,7 +875,6 @@ describe("WebSocketDurableObject", () => {
type: "community:typing.start",
channelId: "chan-1",
userId: "sender-1",
- contractVersion: 1,
})
})
diff --git a/src/ws-do/src/ws-durable/user-auth.test.ts b/src/ws-do/src/ws-durable/user-auth.test.ts
index 0b0ee920e..18bcd3f7d 100644
--- a/src/ws-do/src/ws-durable/user-auth.test.ts
+++ b/src/ws-do/src/ws-durable/user-auth.test.ts
@@ -71,7 +71,6 @@ describe("WebSocketDurableObject", () => {
userId: "user-42",
statusEmoji: null,
statusText: "ready",
- contractVersion: 1,
}
it("delivers a validated self-event to the authenticated target socket", async () => {
@@ -91,7 +90,7 @@ describe("WebSocketDurableObject", () => {
expect(ws.send).toHaveBeenCalledWith(JSON.stringify(event))
})
- it("normalizes legacy and rejects invalid or oversized frames before socket delivery", async () => {
+ it("rejects removed-version, invalid, and oversized frames before socket delivery", async () => {
const { durable, ctx } = createDO()
const ws = createMockWebSocket()
ws.serializeAttachment({ type: "user", userId: "user-42", authenticated: true })
@@ -104,10 +103,8 @@ describe("WebSocketDurableObject", () => {
expect((await durable.fetch(request(JSON.stringify({
...event,
- contractVersion: undefined,
- })))).status).toBe(200)
- expect(ws.send).toHaveBeenCalledWith(JSON.stringify(event))
- ws.send.mockClear()
+ contractVersion: 1,
+ })))).status).toBe(400)
expect((await durable.fetch(request(JSON.stringify({
...event,
extra: true,
@@ -131,14 +128,12 @@ describe("WebSocketDurableObject", () => {
type: "chat",
createdAt: "2026-08-18T00:00:00.000Z",
},
- contractVersion: 1,
},
{
type: "community:unread.bump",
userId: "user-42",
channelId: "ch-1",
isMention: false,
- contractVersion: 1,
},
{
type: "community:mention.create",
@@ -146,7 +141,6 @@ describe("WebSocketDurableObject", () => {
messageId: "m-1",
channelId: "ch-1",
authorName: "Alice",
- contractVersion: 1,
},
]
@@ -236,7 +230,7 @@ describe("WebSocketDurableObject", () => {
body: JSON.stringify({
operationId: await deriveCommunityDeliveryOperationId("m-1"),
operationDigest: prepared.prepared.digest,
- events: [...prepared.prepared.envelopes, { type: "community:unknown", contractVersion: 1 }],
+ events: [...prepared.prepared.envelopes, { type: "community:unknown" }],
}),
}))
@@ -771,7 +765,6 @@ describe("WebSocketDurableObject", () => {
type: "community:presence.update",
userId: "victim",
online: false,
- contractVersion: 1,
})
})
@@ -1093,7 +1086,6 @@ describe("WebSocketDurableObject", () => {
type: "community:presence.update",
userId: "user-1",
online: false,
- contractVersion: 1,
})
})