release(v4.0.0): Shade GA — V3.x consolidation + audit prep
Some checks failed
Test / test (push) Has been cancelled
Cross-platform vectors / TypeScript vectors (bun) (push) Has been cancelled
Cross-platform vectors / Kotlin vectors (gradle) (push) Has been cancelled
Docker build and publish / docker (push) Has been cancelled
Publish / publish (push) Has been cancelled
Some checks failed
Test / test (push) Has been cancelled
Cross-platform vectors / TypeScript vectors (bun) (push) Has been cancelled
Cross-platform vectors / Kotlin vectors (gradle) (push) Has been cancelled
Docker build and publish / docker (push) Has been cancelled
Publish / publish (push) Has been cancelled
V3.1 → V3.12 consolidated and tagged for the first GA release. Wire format unchanged from 0.4.x — 4.0 peers interoperate with 0.4.x peers byte-for-byte. The version bump is semantic: audit-cycle complete, opt-in surface fully exposed, threat model refreshed for every new surface. Highlights: - All 24 @shade/* packages bumped to 4.0.0 in lockstep. - CHANGELOG 4.0.0 section is the canonical manifest of what landed. - THREAT-MODEL extended (§10 fingerprint gates, §11 WebRTC P2P, §12 Web-Worker boundary) + residual-risks table refreshed. - OpenAPI now covers all 27 routes: prekey, transfer, KT, inbox, bridge, observer, /metrics, /healthz, /ready. - MIGRATION 0.3.x → 4.0 documented + smoke-tested against shade migrate-storage on a real SQLite DB. - docs/audit/REVIEW-BUNDLE.md + SCOPE.md ready for external reviewer. - scripts/soak.ts harness for the GA-stable 2-week soak window. - All V*.md plans archived under docs/archive/ with Status: Done. - Voice/Video carved out into V5.0; 4.0 audit focuses on the frozen non-realtime stack. Tests: TS 1000/1000 + Kotlin 11/11 cross-platform vectors green. Docker: gt.zyon.no/stian/shade-prekey:4.0.0 builds and reports version 4.0.0 on /health. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
193
packages/shade-transport-webrtc/tests/transport.test.ts
Normal file
193
packages/shade-transport-webrtc/tests/transport.test.ts
Normal file
@@ -0,0 +1,193 @@
|
||||
/**
|
||||
* End-to-end test of `WebRtcTransferTransport` against the manager + memory
|
||||
* factory. Exercises the same `ITransferTransport` API the engine calls
|
||||
* (`probe`, `sendChunk`, `fetchResumeState`).
|
||||
*/
|
||||
import { afterEach, describe, expect, it } from 'bun:test';
|
||||
import { MemoryRtcFactory } from '../src/memory-rtc.js';
|
||||
import { MemoryShadeBridge, WebRtcSignalingChannel } from '../src/signaling.js';
|
||||
import { WebRtcConnectionManager } from '../src/manager.js';
|
||||
import {
|
||||
DEFAULT_MAX_DATACHANNEL_MESSAGE,
|
||||
WebRtcTransferTransport,
|
||||
} from '../src/transport.js';
|
||||
import { streamIdBytesToString } from '../src/wire.js';
|
||||
|
||||
afterEach(() => {
|
||||
MemoryRtcFactory.reset();
|
||||
});
|
||||
|
||||
function paired(opts: {
|
||||
bobReceiver: import('../src/connection.js').WebRtcReceiverHooks;
|
||||
}): {
|
||||
alice: WebRtcConnectionManager;
|
||||
bob: WebRtcConnectionManager;
|
||||
aliceTransport: WebRtcTransferTransport;
|
||||
} {
|
||||
const factory = new MemoryRtcFactory();
|
||||
const { a, b } = MemoryShadeBridge.linked('alice', 'bob');
|
||||
const aliceSig = new WebRtcSignalingChannel(a);
|
||||
const bobSig = new WebRtcSignalingChannel(b);
|
||||
const alice = new WebRtcConnectionManager({ factory, signaling: aliceSig });
|
||||
const bob = new WebRtcConnectionManager({
|
||||
factory,
|
||||
signaling: bobSig,
|
||||
receiver: opts.bobReceiver,
|
||||
});
|
||||
const aliceTransport = new WebRtcTransferTransport({ manager: alice });
|
||||
return { alice, bob, aliceTransport };
|
||||
}
|
||||
|
||||
function makeStreamId(): string {
|
||||
const b = new Uint8Array(16);
|
||||
globalThis.crypto.getRandomValues(b);
|
||||
return streamIdBytesToString(b);
|
||||
}
|
||||
|
||||
describe('WebRtcTransferTransport', () => {
|
||||
it('probe opens the peer connection', async () => {
|
||||
const { alice, bob, aliceTransport } = paired({
|
||||
bobReceiver: {
|
||||
async onChunk() {
|
||||
return { lastSeq: 0 };
|
||||
},
|
||||
async onResumeQuery() {
|
||||
return null;
|
||||
},
|
||||
},
|
||||
});
|
||||
await aliceTransport.probe('bob');
|
||||
expect(alice.isConnected('bob')).toBe(true);
|
||||
alice.destroy();
|
||||
bob.destroy();
|
||||
});
|
||||
|
||||
it('sendChunk routes envelope to receiver and returns the ack', async () => {
|
||||
let received: { laneId: number; seq: bigint; bytes: number } | null = null;
|
||||
const { alice, bob, aliceTransport } = paired({
|
||||
bobReceiver: {
|
||||
async onChunk(_from, _streamId, laneId, seq, envelope) {
|
||||
received = { laneId, seq, bytes: envelope.length };
|
||||
return { lastSeq: Number(seq), bytesReceived: envelope.length };
|
||||
},
|
||||
async onResumeQuery() {
|
||||
return null;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const streamId = makeStreamId();
|
||||
const envelope = new Uint8Array(2048);
|
||||
envelope.fill(0x42);
|
||||
const ack = await aliceTransport.sendChunk('bob', streamId, 1, 5n, envelope);
|
||||
expect(ack.lastSeq).toBe(5);
|
||||
expect(ack.bytesReceived).toBe(2048);
|
||||
expect(received).not.toBeNull();
|
||||
expect(received!.laneId).toBe(1);
|
||||
expect(received!.seq).toBe(5n);
|
||||
expect(received!.bytes).toBe(2048);
|
||||
|
||||
alice.destroy();
|
||||
bob.destroy();
|
||||
});
|
||||
|
||||
it('rejects oversized envelopes that would exceed the data channel cap', async () => {
|
||||
const { alice, bob, aliceTransport } = paired({
|
||||
bobReceiver: {
|
||||
async onChunk() {
|
||||
return { lastSeq: 0 };
|
||||
},
|
||||
async onResumeQuery() {
|
||||
return null;
|
||||
},
|
||||
},
|
||||
});
|
||||
const streamId = makeStreamId();
|
||||
const huge = new Uint8Array(DEFAULT_MAX_DATACHANNEL_MESSAGE + 1);
|
||||
await expect(aliceTransport.sendChunk('bob', streamId, 0, 0n, huge)).rejects.toThrow(
|
||||
/frame too large/,
|
||||
);
|
||||
alice.destroy();
|
||||
bob.destroy();
|
||||
});
|
||||
|
||||
it('fetchResumeState returns parsed state when the receiver knows the stream', async () => {
|
||||
const { alice, bob, aliceTransport } = paired({
|
||||
bobReceiver: {
|
||||
async onChunk() {
|
||||
return { lastSeq: 0 };
|
||||
},
|
||||
async onResumeQuery(_from, streamId) {
|
||||
return {
|
||||
streamId,
|
||||
lanes: [
|
||||
{ laneId: 0, lastSeqAcked: 11 },
|
||||
{ laneId: 1, lastSeqAcked: 4 },
|
||||
],
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
const sid = makeStreamId();
|
||||
const state = await aliceTransport.fetchResumeState('bob', sid);
|
||||
expect(state).not.toBeNull();
|
||||
expect(state!.streamId).toBe(sid);
|
||||
expect(state!.lanes[0]!.lastSeqAcked).toBe(11);
|
||||
expect(state!.lanes[1]!.lastSeqAcked).toBe(4);
|
||||
alice.destroy();
|
||||
bob.destroy();
|
||||
});
|
||||
|
||||
it('fetchResumeState returns null when the peer reports not found', async () => {
|
||||
const { alice, bob, aliceTransport } = paired({
|
||||
bobReceiver: {
|
||||
async onChunk() {
|
||||
return { lastSeq: 0 };
|
||||
},
|
||||
async onResumeQuery() {
|
||||
return null;
|
||||
},
|
||||
},
|
||||
});
|
||||
const state = await aliceTransport.fetchResumeState('bob', makeStreamId());
|
||||
expect(state).toBeNull();
|
||||
alice.destroy();
|
||||
bob.destroy();
|
||||
});
|
||||
|
||||
it('multiple in-flight requests interleave correctly via requestId correlation', async () => {
|
||||
let inflight = 0;
|
||||
let maxInflight = 0;
|
||||
const { alice, bob, aliceTransport } = paired({
|
||||
bobReceiver: {
|
||||
async onChunk(_from, _streamId, _laneId, seq) {
|
||||
inflight++;
|
||||
if (inflight > maxInflight) maxInflight = inflight;
|
||||
// Stagger response so request ordering doesn't trivially match
|
||||
// response ordering.
|
||||
await new Promise<void>((resolve) =>
|
||||
setTimeout(resolve, Number(seq % 5n) * 5),
|
||||
);
|
||||
inflight--;
|
||||
return { lastSeq: Number(seq), bytesReceived: 0 };
|
||||
},
|
||||
async onResumeQuery() {
|
||||
return null;
|
||||
},
|
||||
},
|
||||
});
|
||||
const streamId = makeStreamId();
|
||||
const acks = await Promise.all(
|
||||
Array.from({ length: 12 }, (_, i) =>
|
||||
aliceTransport.sendChunk('bob', streamId, i % 4, BigInt(i), new Uint8Array(8)),
|
||||
),
|
||||
);
|
||||
// Each ack matches its request seq (round-trip via requestId).
|
||||
for (let i = 0; i < acks.length; i++) {
|
||||
expect(acks[i]!.lastSeq).toBe(i);
|
||||
}
|
||||
expect(maxInflight).toBeGreaterThan(1);
|
||||
alice.destroy();
|
||||
bob.destroy();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user