|
| 1 | +// Realtime Talk live producer tests cover bounded QA evidence and child status parsing. |
| 2 | +import fs from "node:fs/promises"; |
| 3 | +import os from "node:os"; |
| 4 | +import path from "node:path"; |
| 5 | +import { afterEach, describe, expect, it, vi } from "vitest"; |
| 6 | +import { |
| 7 | + buildRealtimeTalkLiveCommand, |
| 8 | + buildRealtimeTalkLiveEvidence, |
| 9 | + createRealtimeTalkResultParser, |
| 10 | + parseRealtimeTalkLiveOptions, |
| 11 | + runRealtimeTalkLiveProducer, |
| 12 | +} from "./realtime-talk-live.js"; |
| 13 | + |
| 14 | +const tempDirs: string[] = []; |
| 15 | + |
| 16 | +async function makeOptions() { |
| 17 | + const artifactBase = await fs.mkdtemp(path.join(os.tmpdir(), "realtime-talk-live-")); |
| 18 | + tempDirs.push(artifactBase); |
| 19 | + return { |
| 20 | + artifactBase, |
| 21 | + repoRoot: process.cwd(), |
| 22 | + }; |
| 23 | +} |
| 24 | + |
| 25 | +afterEach(async () => { |
| 26 | + vi.restoreAllMocks(); |
| 27 | + await Promise.all(tempDirs.splice(0).map((dir) => fs.rm(dir, { force: true, recursive: true }))); |
| 28 | +}); |
| 29 | + |
| 30 | +describe("realtime Talk live QA producer", () => { |
| 31 | + it("builds the canonical one-cycle OpenAI-only smoke command", () => { |
| 32 | + const command = buildRealtimeTalkLiveCommand({ OPENAI_API_KEY: "test-key" }); |
| 33 | + |
| 34 | + expect(command.args).toEqual([ |
| 35 | + "--import", |
| 36 | + "tsx", |
| 37 | + "scripts/dev/realtime-talk-live-smoke.ts", |
| 38 | + "--openai-only", |
| 39 | + "--openai-audio-cycles", |
| 40 | + "1", |
| 41 | + ]); |
| 42 | + expect(command.env.OPENAI_API_KEY).toBe("test-key"); |
| 43 | + }); |
| 44 | + |
| 45 | + it("parses result prefixes across stream chunks without retaining details", () => { |
| 46 | + const parser = createRealtimeTalkResultParser(); |
| 47 | + parser.append("openai-backend-bridge: o"); |
| 48 | + parser.append("k { model: 'gpt-realtime-2.1' }\n"); |
| 49 | + parser.append( |
| 50 | + "openai-backend-audio-roundtrip: ok {\n transcripts: ['private transcript']\n}\n", |
| 51 | + ); |
| 52 | + parser.append("openai-webrtc-browser: failed { error: 'private provider error' }"); |
| 53 | + |
| 54 | + expect(Object.fromEntries(parser.finish())).toEqual({ |
| 55 | + "openai-backend-bridge": ["ok"], |
| 56 | + "openai-backend-audio-roundtrip": ["ok"], |
| 57 | + "openai-webrtc-browser": ["failed"], |
| 58 | + }); |
| 59 | + }); |
| 60 | + |
| 61 | + it("writes blocked evidence without exposing unrelated or missing credentials", async () => { |
| 62 | + const options = await makeOptions(); |
| 63 | + const runChild = vi.fn(); |
| 64 | + const evidence = await runRealtimeTalkLiveProducer( |
| 65 | + options, |
| 66 | + { OTHER_SECRET: "do-not-record" }, |
| 67 | + { runChild }, |
| 68 | + ); |
| 69 | + |
| 70 | + expect(runChild).not.toHaveBeenCalled(); |
| 71 | + expect(evidence.entries[0]?.result.status).toBe("blocked"); |
| 72 | + const artifacts = JSON.stringify(evidence); |
| 73 | + const log = await fs.readFile( |
| 74 | + path.join(options.artifactBase, "realtime-talk-live.log"), |
| 75 | + "utf8", |
| 76 | + ); |
| 77 | + expect(artifacts).not.toContain("do-not-record"); |
| 78 | + expect(log).toContain("OPENAI_API_KEY is not set"); |
| 79 | + expect(log).not.toContain("do-not-record"); |
| 80 | + }); |
| 81 | + |
| 82 | + it("records only normalized status and byte metadata for a passing smoke", async () => { |
| 83 | + const options = await makeOptions(); |
| 84 | + const apiKey = "sk-private-test-key"; |
| 85 | + const transcript = "private transcript must never persist"; |
| 86 | + const evidence = await runRealtimeTalkLiveProducer( |
| 87 | + options, |
| 88 | + { OPENAI_API_KEY: apiKey }, |
| 89 | + { |
| 90 | + runChild: async ({ onStderr, onStdout }) => { |
| 91 | + onStdout(`openai-backend-bridge: ok { token: '${apiKey}' }\n`); |
| 92 | + onStdout(`openai-backend-audio-roundtrip: ok { transcripts: ['${transcript}'] }\n`); |
| 93 | + onStdout("openai-webrtc-browser: ok { state: 'connected' }\n"); |
| 94 | + onStderr("provider debug output should not persist"); |
| 95 | + return { exitCode: 0, signal: null }; |
| 96 | + }, |
| 97 | + }, |
| 98 | + ); |
| 99 | + |
| 100 | + expect(evidence.entries[0]?.result.status).toBe("pass"); |
| 101 | + const log = await fs.readFile( |
| 102 | + path.join(options.artifactBase, "realtime-talk-live.log"), |
| 103 | + "utf8", |
| 104 | + ); |
| 105 | + expect(log).toContain("audioFormat: pcm16le"); |
| 106 | + expect(log).toContain("audioSampleRateHz: 24000"); |
| 107 | + expect(log).toContain("openai-webrtc-browser=ok"); |
| 108 | + expect(log).toMatch(/statusSha256: [a-f0-9]{64}/u); |
| 109 | + expect(log).not.toContain(apiKey); |
| 110 | + expect(log).not.toContain(transcript); |
| 111 | + expect(log).not.toContain("provider debug output"); |
| 112 | + expect(JSON.stringify(evidence)).not.toContain(apiKey); |
| 113 | + expect(JSON.stringify(evidence)).not.toContain(transcript); |
| 114 | + }); |
| 115 | + |
| 116 | + it("fails clean exits that omit an expected smoke leg", async () => { |
| 117 | + const options = await makeOptions(); |
| 118 | + const evidence = await runRealtimeTalkLiveProducer( |
| 119 | + options, |
| 120 | + { OPENAI_API_KEY: "test-key" }, |
| 121 | + { |
| 122 | + runChild: async ({ onStdout }) => { |
| 123 | + onStdout("openai-backend-bridge: ok {}\n"); |
| 124 | + onStdout("openai-backend-audio-roundtrip: ok {}\n"); |
| 125 | + return { exitCode: 0, signal: null }; |
| 126 | + }, |
| 127 | + }, |
| 128 | + ); |
| 129 | + |
| 130 | + expect(evidence.entries[0]?.result.status).toBe("fail"); |
| 131 | + expect(evidence.entries[0]?.result.failure?.reason).toContain("openai-webrtc-browser=missing"); |
| 132 | + }); |
| 133 | + |
| 134 | + it("reports missing Playwright as blocked harness evidence", async () => { |
| 135 | + const options = await makeOptions(); |
| 136 | + const evidence = await runRealtimeTalkLiveProducer( |
| 137 | + options, |
| 138 | + { OPENAI_API_KEY: "test-key" }, |
| 139 | + { |
| 140 | + runChild: async ({ onStderr }) => { |
| 141 | + onStderr("Executable doesn't exist. Run npx playwright install chromium."); |
| 142 | + return { exitCode: 1, signal: null }; |
| 143 | + }, |
| 144 | + }, |
| 145 | + ); |
| 146 | + |
| 147 | + expect(evidence.entries[0]?.result.status).toBe("blocked"); |
| 148 | + }); |
| 149 | + |
| 150 | + it("keeps an observed smoke failure terminal when the harness is also blocked", async () => { |
| 151 | + const options = await makeOptions(); |
| 152 | + const evidence = await runRealtimeTalkLiveProducer( |
| 153 | + options, |
| 154 | + { OPENAI_API_KEY: "test-key" }, |
| 155 | + { |
| 156 | + runChild: async ({ onStderr, onStdout }) => { |
| 157 | + onStdout("openai-backend-bridge: failed { error: 'provider rejected session' }\n"); |
| 158 | + onStderr("Executable doesn't exist. Run npx playwright install chromium."); |
| 159 | + return { exitCode: 1, signal: null }; |
| 160 | + }, |
| 161 | + }, |
| 162 | + ); |
| 163 | + |
| 164 | + expect(evidence.entries[0]?.result.status).toBe("fail"); |
| 165 | + expect(evidence.entries[0]?.result.failure?.reason).toContain("openai-backend-bridge=failed"); |
| 166 | + }); |
| 167 | + |
| 168 | + it("builds catalog-compatible evidence for the live scenario", async () => { |
| 169 | + const options = await makeOptions(); |
| 170 | + const evidence = buildRealtimeTalkLiveEvidence({ |
| 171 | + env: { OPENCLAW_QA_REF: "test-ref" }, |
| 172 | + options, |
| 173 | + result: { |
| 174 | + details: "proof passed", |
| 175 | + durationMs: 10, |
| 176 | + status: "pass", |
| 177 | + }, |
| 178 | + }); |
| 179 | + |
| 180 | + expect(evidence.entries[0]).toMatchObject({ |
| 181 | + test: { |
| 182 | + id: "openai-realtime-talk-live", |
| 183 | + source: { path: "test/e2e/qa-lab/media/realtime-talk-live.ts" }, |
| 184 | + }, |
| 185 | + result: { |
| 186 | + status: "pass", |
| 187 | + timing: { wallMs: 10 }, |
| 188 | + }, |
| 189 | + }); |
| 190 | + }); |
| 191 | +}); |
| 192 | + |
| 193 | +describe("realtime Talk live QA options", () => { |
| 194 | + it("resolves the artifact directory from the selected repo root", () => { |
| 195 | + expect( |
| 196 | + parseRealtimeTalkLiveOptions([ |
| 197 | + "--repo-root", |
| 198 | + "/tmp/openclaw", |
| 199 | + "--artifact-base", |
| 200 | + ".artifacts/qa-e2e/realtime-talk", |
| 201 | + ]), |
| 202 | + ).toEqual({ |
| 203 | + artifactBase: "/tmp/openclaw/.artifacts/qa-e2e/realtime-talk", |
| 204 | + repoRoot: "/tmp/openclaw", |
| 205 | + }); |
| 206 | + }); |
| 207 | + |
| 208 | + it("requires an artifact base and rejects duplicate options", () => { |
| 209 | + expect(() => parseRealtimeTalkLiveOptions([])).toThrow("--artifact-base is required"); |
| 210 | + expect(() => |
| 211 | + parseRealtimeTalkLiveOptions([ |
| 212 | + "--artifact-base", |
| 213 | + ".artifacts/one", |
| 214 | + "--artifact-base", |
| 215 | + ".artifacts/two", |
| 216 | + ]), |
| 217 | + ).toThrow("--artifact-base was provided more than once"); |
| 218 | + }); |
| 219 | +}); |
0 commit comments