Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.
TypeScript agentic-aiaiai-agentsai-videocompilerdslffmpeggenerative-aillmmarkup-languagemonorepoplugin-systemprogramming-languagetext-to-videotypescriptvideovideo-automationvideo-clonevideo-editingvideo-generation
fix(oauth): preserve literal Windows URLs and tolerate missing openers
kashorin14c0b2bcb44e
diff --git a/packages/cli/src/oauth.ts b/packages/cli/src/oauth.tsindex 092c8e67..5a19c959 100644--- a/packages/cli/src/oauth.ts+++ b/packages/cli/src/oauth.ts@@ -32,6 +32,7 @@ export type AuthorizeBrowserLaunch = {readonly command: string;readonly args: readonly string[];readonly windowsVerbatimArguments: boolean;+ readonly env?: Readonly<Record<string, string>>;};/**@@ -44,11 +45,14 @@ export function authorizeBrowserLaunch(): AuthorizeBrowserLaunch {const platform = options.platform ?? process.platform;if (platform === "win32") {- const quoted = `"${url.replaceAll("\"", "")}"`;+ // Expand one environment value after cmd parses the command. Interpolating the+ // URL into command text would also expand percent sequences inside the URL.+ const serialized = new URL(url).href;return {command: options.comSpec ?? process.env.ComSpec ?? "cmd.exe",- args: ["/d", "/s", "/c", `start "" ${quoted}`],+ args: ["/d", "/s", "/v:off", "/c", 'start "" "%HYPIT_OAUTH_AUTHORIZE_URL%"'],windowsVerbatimArguments: true,+ env: { HYPIT_OAUTH_AUTHORIZE_URL: serialized },};}return {@@ -65,6 +69,7 @@ function openAuthorizeUrl(url: string): void {detached: true,windowsHide: true,windowsVerbatimArguments: launch.windowsVerbatimArguments,+ ...(launch.env === undefined ? {} : { env: { ...process.env, ...launch.env } }),});// A missing opener must not crash the CLI; the URL is already on the progress line.child.once("error", () => undefined);diff --git a/packages/cli/test/oauth.test.ts b/packages/cli/test/oauth.test.tsindex a9452126..4a85b13c 100644--- a/packages/cli/test/oauth.test.ts+++ b/packages/cli/test/oauth.test.ts@@ -2,6 +2,10 @@ import assert from "node:assert/strict";import { once } from "node:events";import { createConnection } from "node:net";import test from "node:test";+import { spawnSync } from "node:child_process";+import { mkdtemp, rm, writeFile } from "node:fs/promises";+import { tmpdir } from "node:os";+import { join } from "node:path";import { decodeOAuth2Credential } from "@hypit/runtime";@@ -82,11 +86,38 @@ test("Windows authorize launch quotes the URL so cmd does not split on query amp});assert.equal(launch.command, "C:\\Windows\\System32\\cmd.exe");assert.equal(launch.windowsVerbatimArguments, true);- assert.deepEqual(launch.args, ["/d", "/s", "/c", `start "" "${url}"`]);+ assert.deepEqual(launch.args, ["/d", "/s", "/v:off", "/c", 'start "" "%HYPIT_OAUTH_AUTHORIZE_URL%"']);+ assert.equal(launch.env?.HYPIT_OAUTH_AUTHORIZE_URL, url);assert.equal(authorizeBrowserLaunch(url, { platform: "darwin" }).command, "open");assert.deepEqual(authorizeBrowserLaunch(url, { platform: "linux" }).args, [url]);});+test("Windows start preserves the entire serialized OAuth URL through cmd", {+ skip: process.platform !== "win32",+}, async () => {+ const directory = await mkdtemp(join(tmpdir(), "hypit oauth "));+ try {+ const receiver = join(directory, "receive.mjs");+ await writeFile(receiver, 'process.stdout.write(JSON.stringify(process.argv.slice(2)));');+ const url = new URL("https://identity.example.test/authorize");+ url.searchParams.set("redirect_uri", "http://127.0.0.1:1234/callback");+ url.searchParams.set("scope", "read write");+ url.searchParams.set("state", "literal%HYPIT_OAUTH_TEST_VALUE%!value&more");+ const serialized = url.href;+ const launch = authorizeBrowserLaunch(serialized);+ // Keep real cmd and start parsing, but receive the argument in Node instead of opening a UI.+ const args = [...launch.args];+ args[args.length - 1] = args.at(-1)!.replace('start "" ', `start "" /b /wait "${process.execPath}" "${receiver}" `);+ const child = spawnSync(launch.command, args, {+ encoding: "utf8", windowsHide: true, windowsVerbatimArguments: launch.windowsVerbatimArguments,+ env: { ...process.env, ...launch.env, HYPIT_OAUTH_TEST_VALUE: "must-not-expand", "3A": "must-not-expand" },+ timeout: 10_000,+ });+ assert.equal(child.status, 0, child.error?.message ?? child.stderr);+ assert.deepEqual(JSON.parse(child.stdout), [serialized]);+ } finally { await rm(directory, { recursive: true, force: true }); }+});+test("OAuth token exchange uses the Endpoint-declared request timeout", async () => {await assert.rejects(async () => await acquireOAuthCredential({ ...acquisition, requestTimeoutMs: 20 }, {@@ -108,3 +139,31 @@ test("OAuth token exchange uses the Endpoint-declared request timeout", async ()/token exchange timed out after 20 ms.*no credential was stored/u,);});++test("a missing browser opener leaves the printed authorization URL usable", async () => {+ const directory = await mkdtemp(join(tmpdir(), "hypit-oauth-no-opener-"));+ try {+ const entry = join(directory, "authorize.mjs");+ await writeFile(entry, `+import { acquireOAuthCredential } from ${JSON.stringify(new URL("../src/oauth.ts", import.meta.url).href)};+const value = await acquireOAuthCredential(${JSON.stringify(acquisition)}, {+ onProgress(message) {+ if (!message.startsWith("Opening sign-in: ")) return;+ const authorize = new URL(message.slice("Opening sign-in: ".length));+ const callback = new URL(authorize.searchParams.get("redirect_uri"));+ callback.searchParams.set("state", authorize.searchParams.get("state"));+ callback.searchParams.set("code", "manual-code");+ setTimeout(() => { void fetch(callback); }, 50);+ },+ fetch: async () => Response.json({access_token: "manual-access"}),+});+process.stdout.write(value);+`);+ const child = spawnSync(process.execPath, ["--import", import.meta.resolve("tsx"), entry], {+ encoding: "utf8", windowsHide: true, timeout: 15_000,+ env: { ...process.env, PATH: "", ComSpec: join(directory, "missing-cmd.exe") },+ });+ assert.equal(child.status, 0, child.error?.message ?? child.stderr);+ assert.equal(decodeOAuth2Credential(child.stdout)?.accessToken, "manual-access");+ } finally { await rm(directory, { recursive: true, force: true }); }+});