|
1 | 1 | // Telegram User Crabbox Proof tests cover telegram user crabbox proof script behavior. |
| 2 | +import { spawnSync } from "node:child_process"; |
2 | 3 | import fs from "node:fs"; |
3 | 4 | import os from "node:os"; |
4 | 5 | import path from "node:path"; |
@@ -39,6 +40,22 @@ function writeExecutable(pathname: string, content: string): void {
|
39 | 40 | fs.writeFileSync(pathname, content, { mode: 0o755 }); |
40 | 41 | } |
41 | 42 | |
| 43 | +function runProofCli(args: string[]) { |
| 44 | +return spawnSync( |
| 45 | +process.execPath, |
| 46 | +["--import", "tsx", "scripts/e2e/telegram-user-crabbox-proof.ts", ...args], |
| 47 | +{ |
| 48 | +cwd: process.cwd(), |
| 49 | +encoding: "utf8", |
| 50 | +env: { |
| 51 | + ...process.env, |
| 52 | +GIT_CONFIG_NOSYSTEM: "1", |
| 53 | +GIT_TERMINAL_PROMPT: "0", |
| 54 | +}, |
| 55 | +}, |
| 56 | +); |
| 57 | +} |
| 58 | + |
42 | 59 | async function waitFor(predicate: () => boolean, timeoutMs = 5_000): Promise<void> { |
43 | 60 | const started = Date.now(); |
44 | 61 | while (Date.now() - started < timeoutMs) { |
@@ -101,6 +118,20 @@ describe("telegram user Crabbox proof log polling", () => {
|
101 | 118 | ).toBe(4096); |
102 | 119 | }); |
103 | 120 | |
| 121 | +it("rejects loose and out-of-range proof ports before remote setup", () => { |
| 122 | +const looseGatewayPort = runProofCli(["--gateway-port", "1e3", "--dry-run"]); |
| 123 | +expect(looseGatewayPort.status).toBe(1); |
| 124 | +expect(looseGatewayPort.stderr).toContain("--gateway-port must be a positive integer."); |
| 125 | + |
| 126 | +const highGatewayPort = runProofCli(["--gateway-port", "65536", "--dry-run"]); |
| 127 | +expect(highGatewayPort.status).toBe(1); |
| 128 | +expect(highGatewayPort.stderr).toContain("--gateway-port must be a TCP port from 1 to 65535."); |
| 129 | + |
| 130 | +const highMockPort = runProofCli(["--mock-port", "65536", "--dry-run"]); |
| 131 | +expect(highMockPort.status).toBe(1); |
| 132 | +expect(highMockPort.stderr).toContain("--mock-port must be a TCP port from 1 to 65535."); |
| 133 | +}); |
| 134 | + |
104 | 135 | it("reads only the requested log tail", () => { |
105 | 136 | const logPath = path.join(makeTempDir(), "gateway.log"); |
106 | 137 | fs.writeFileSync(logPath, `${"old\n".repeat(2000)}ready\n`, "utf8"); |
|