feat(proton): proof-of-concept migration — longmsg parity test
Migrates a self-contained subset of bridge/proto/longmsg.ts to the new
@snowluma/proton compile-time DSL form and verifies wire-format parity
against the legacy runtime ProtoSchema encoder. End-to-end proof that
the toolchain works in core's vitest pipeline.
What's covered:
- LongMsgUid / LongMsgSettings / SendLongMsgInfo / SendLongMsgReq /
SendLongMsgResp / SendLongMsgRespResult / RecvLongMsgInfo /
RecvLongMsgReq / RecvLongMsgResp / RecvLongMsgRespResult
- The three schemas that pull in PushMsgBody (LongMsgContent /
LongMsgAction / LongMsgResult) stay on the legacy API for now, since
migrating them requires also migrating message.ts and element.ts.
Toolchain changes:
- @snowluma/proton gets a tsup build step. The ./vite subpath now
points at the built dist/index.js so it is loadable as plain Node
ESM from vite.config.ts / vitest.config.ts (the source-only .ts
layout can't be consumed from outside the Vite transform pipeline).
The . (runtime) subpath stays at TS source — it's only ever
imported from user code, which IS Vite-transformed.
- prepare script ensures dist/ exists after pnpm install.
- @snowluma/core depends on @snowluma/proton (workspace:*) and adds
protobufVitePlugin() to its vitest config so test files get
transformed.
Documented divergence:
proton follows proto3 semantics: fields equal to their default value
(0 / false / "" / empty bytes) are NOT emitted on the wire. The legacy
runtime encoder always emits them. Both forms are round-trippable
through a conforming proto3 reader. The parity test pins this
behaviour explicitly.
8/8 parity tests pass.
This commit is contained in:
6 files changed
+199
-2
No files matched your search
@@ -0,0 +1,65 @@
|
||||
// Proton (compile-time) form of the long-message schemas.
|
||||
//
|
||||
// Mirror of the self-contained subset of `bridge/proto/longmsg.ts`. Only the
|
||||
// schemas that DON'T reach into `PushMsgBodySchema` (and thus into element.ts)
|
||||
// are migrated here — `LongMsgContent` / `LongMsgAction` / `LongMsgResult`
|
||||
// stay on the legacy runtime API until message.ts + element.ts get migrated.
|
||||
//
|
||||
// This file is the proof-of-concept target for the @snowluma/proton plugin.
|
||||
// The parity test at `tests/proton-parity.test.ts` asserts that proton's
|
||||
// generated codec produces the exact same wire bytes as `protoEncode`.
|
||||
|
||||
import type { pb, uint_32, bool, bytes } from '@snowluma/proton';
|
||||
|
||||
export interface LongMsgUid {
|
||||
uid?: pb<2, string>;
|
||||
}
|
||||
|
||||
export interface LongMsgSettings {
|
||||
field1?: pb<1, uint_32>;
|
||||
field2?: pb<2, uint_32>;
|
||||
field3?: pb<3, uint_32>;
|
||||
field4?: pb<4, uint_32>;
|
||||
}
|
||||
|
||||
export interface SendLongMsgInfo {
|
||||
type?: pb<1, uint_32>;
|
||||
uid?: pb<2, LongMsgUid>;
|
||||
groupUin?: pb<3, uint_32>;
|
||||
payload?: pb<4, bytes>;
|
||||
}
|
||||
|
||||
export interface SendLongMsgReq {
|
||||
info?: pb<2, SendLongMsgInfo>;
|
||||
settings?: pb<15, LongMsgSettings>;
|
||||
}
|
||||
|
||||
export interface SendLongMsgRespResult {
|
||||
resId?: pb<3, string>;
|
||||
}
|
||||
|
||||
export interface SendLongMsgResp {
|
||||
result?: pb<2, SendLongMsgRespResult>;
|
||||
settings?: pb<15, LongMsgSettings>;
|
||||
}
|
||||
|
||||
export interface RecvLongMsgInfo {
|
||||
uid?: pb<1, LongMsgUid>;
|
||||
resId?: pb<2, string>;
|
||||
acquire?: pb<3, bool>;
|
||||
}
|
||||
|
||||
export interface RecvLongMsgReq {
|
||||
info?: pb<1, RecvLongMsgInfo>;
|
||||
settings?: pb<15, LongMsgSettings>;
|
||||
}
|
||||
|
||||
export interface RecvLongMsgRespResult {
|
||||
resId?: pb<3, string>;
|
||||
payload?: pb<4, bytes>;
|
||||
}
|
||||
|
||||
export interface RecvLongMsgResp {
|
||||
result?: pb<1, RecvLongMsgRespResult>;
|
||||
settings?: pb<15, LongMsgSettings>;
|
||||
}
|
||||
Reference in new issue
Block a user