Personal Telegram developer console for GitHub

test: wire durable replay namespace into approval flow

davoodmehraban89 committed Oct 3, 2026 at 07:14 UTC bed5597e7f0035135d791268f3820d9941c7c0b5
1 file changed +31 -1
test/approval-flow.test.js
+31 -1
@@ -2,13 +2,43 @@ import test from 'node:test';
2 import assert from 'node:assert/strict';
3 import worker from '../src/index.js';
4
5 +function makeReplayNamespace() {
6 + const used = new Set();
7 + return {
8 + idFromName(name) {
9 + return String(name);
10 + },
11 + get(id) {
12 + return {
13 + async fetch(request) {
14 + const body = await request.json();
15 + const expiresAt = Number(body?.expiresAt);
16 + if (!Number.isFinite(expiresAt)) {
17 + return Response.json({ accepted: false, reason: 'invalid_expiry' }, { status: 400 });
18 + }
19 + if (expiresAt < Date.now()) {
20 + return Response.json({ accepted: false, reason: 'expired' }, { status: 410 });
21 + }
22 + const key = String(id);
23 + if (used.has(key)) {
24 + return Response.json({ accepted: false, reason: 'already_used' }, { status: 409 });
25 + }
26 + used.add(key);
27 + return Response.json({ accepted: true });
28 + }
29 + };
30 + }
31 + };
32 +}
33 +
34 const env = {
35 TELEGRAM_WEBHOOK_SECRET: 'right',
36 OWNER_TELEGRAM_ID: '123',
37 TELEGRAM_BOT_TOKEN: 'telegram-test-token',
38 GITHUB_TOKEN: 'github-test-token',
39 GITHUB_OWNER: 'davoodmehraban89',
11 - APPROVAL_SIGNING_SECRET: 'approval-test-secret'
40 + APPROVAL_SIGNING_SECRET: 'approval-test-secret',
41 + APPROVAL_REPLAY_GUARD: makeReplayNamespace()
42 };
43
44 function webhook(update) {