diff --git a/src/apps/cli/testdeno/helpers/backgroundCli.ts b/src/apps/cli/testdeno/helpers/backgroundCli.ts index 1269d0f..ef81fea 100644 --- a/src/apps/cli/testdeno/helpers/backgroundCli.ts +++ b/src/apps/cli/testdeno/helpers/backgroundCli.ts @@ -1,4 +1,4 @@ -import { CLI_DIR } from "./cli.ts"; +import { CLI_DIR, TEE_ENABLED, formatTeeCommand, createLineTeeWriter } from "./cli.ts"; import { join } from "@std/path"; const CLI_DIST = join(CLI_DIR, "dist", "index.cjs"); @@ -12,10 +12,9 @@ function decorateArgs(args: string[]): string[] { async function pump( stream: ReadableStream, sink: (text: string) => void, - teeTarget: WritableStream | null + teeTarget: { write: (chunk: Uint8Array) => void; close: () => void } | null ): Promise { const reader = stream.getReader(); - const writer = teeTarget?.getWriter(); const dec = new TextDecoder(); try { while (true) { @@ -23,12 +22,12 @@ async function pump( if (done) break; if (!value) continue; sink(dec.decode(value, { stream: true })); - if (writer) { - await writer.write(value); + if (teeTarget) { + teeTarget.write(value); } } } finally { - if (writer) writer.releaseLock(); + if (teeTarget) teeTarget.close(); reader.releaseLock(); } } @@ -43,19 +42,20 @@ export class BackgroundCliProcess { readonly child: Deno.ChildProcess, readonly args: string[] ) { + const cliArgs = decorateArgs(args); this.#stdoutDone = pump( child.stdout, (text) => { this.#stdout += text; }, - null + TEE_ENABLED ? createLineTeeWriter(child.pid, "stdout", (chunk) => Deno.stdout.writeSync(chunk)) : null ); this.#stderrDone = pump( child.stderr, (text) => { this.#stderr += text; }, - null + TEE_ENABLED ? createLineTeeWriter(child.pid, "stderr", (chunk) => Deno.stderr.writeSync(chunk)) : null ); } @@ -101,12 +101,20 @@ export class BackgroundCliProcess { } export function startCliInBackground(...args: string[]): BackgroundCliProcess { + const cliArgs = decorateArgs(args); const child = new Deno.Command("node", { - args: [CLI_DIST, ...decorateArgs(args)], + args: [CLI_DIST, ...cliArgs], cwd: CLI_DIR, stdin: "null", stdout: "piped", stderr: "piped", }).spawn(); + + if (TEE_ENABLED) { + Deno.stdout.writeSync( + new TextEncoder().encode(`[CLI tee pid=${child.pid}] process(bg): ${formatTeeCommand(cliArgs)}\n`) + ); + } + return new BackgroundCliProcess(child, args); } diff --git a/src/apps/cli/testdeno/helpers/cli.ts b/src/apps/cli/testdeno/helpers/cli.ts index a7e3a42..c393c26 100644 --- a/src/apps/cli/testdeno/helpers/cli.ts +++ b/src/apps/cli/testdeno/helpers/cli.ts @@ -20,7 +20,7 @@ export interface CliResult { code: number; } -const TEE_ENABLED = Deno.env.get("LIVESYNC_TEST_TEE") === "1"; +export const TEE_ENABLED = Deno.env.get("LIVESYNC_TEST_TEE") === "1"; const VERBOSE_ENABLED = Deno.env.get("LIVESYNC_CLI_VERBOSE") === "1"; const DEBUG_ENABLED = Deno.env.get("LIVESYNC_CLI_DEBUG") === "1"; @@ -39,11 +39,11 @@ function concatChunks(chunks: Uint8Array[]): Uint8Array { return out; } -function formatTeeCommand(args: string[]): string { +export function formatTeeCommand(args: string[]): string { return ["node", CLI_DIST, ...args].map((part) => JSON.stringify(part)).join(" "); } -function createLineTeeWriter( +export function createLineTeeWriter( pid: number, streamName: "stdout" | "stderr", writer: (chunk: Uint8Array) => void diff --git a/src/apps/cli/testdeno/helpers/settings.ts b/src/apps/cli/testdeno/helpers/settings.ts index 6f88a03..7f114dd 100644 --- a/src/apps/cli/testdeno/helpers/settings.ts +++ b/src/apps/cli/testdeno/helpers/settings.ts @@ -184,6 +184,7 @@ export async function applyP2pSettings( data.P2P_relays = relays; data.P2P_AutoAcceptingPeers = autoAccept; data.P2P_AutoDenyingPeers = ""; + data.P2P_turnServers = "none"; data.P2P_IsHeadless = true; data.isConfigured = true; await Deno.writeTextFile(settingsFile, JSON.stringify(data, null, 2)); diff --git a/src/lib b/src/lib index 76d9167..808efe1 160000 --- a/src/lib +++ b/src/lib @@ -1 +1 @@ -Subproject commit 76d91674c235c1ccf991a14802c737e82e144ef1 +Subproject commit 808efe19c8e94b32a039463d9bcd407550d335e6