a78b1542da
* feat: pullfrog auth codex + fresh-branch Add `pullfrog auth codex` standalone command for minting Codex (ChatGPT) subscription credentials and saving them as the `CODEX_AUTH_JSON` Pullfrog secret. Codex device-auth runs in a subprocess with an isolated `CODEX_HOME` (temp dir) so the user's `~/.codex/auth.json` is never touched. The spawned `codex login --device-auth` output is captured line-by-line, ANSI-stripped, and re-rendered with a `$ codex login --device-auth` header above dimmed sub-output on the @clack/prompts rail so the user visually understands they're seeing a sub-process. Companion `pnpm fresh-branch` script: from inside `.worktrees/<name>`, creates a schema-only Neon branch named `dev/<git-branch>`, patches the worktree's `.env` (DATABASE_URL, DATABASE_URL_UNPOOLED, NEON_DEV_BRANCH), then runs `prisma migrate reset --force` so migrations apply cleanly against a data-free copy. Refuses to run from the primary checkout or on protected branch names. Other: - bump CLI/account/repo secret value limit 4096 -> 49152 chars (matches GitHub Actions' 48KB cap; auth.json is ~4-5KB) - extract shared CLI helpers (gh/pullfrog API, secret save) into `action/commands/_shared.ts` * fix(auth): address PR review + add CodexAuthCallout, default account scope Review fixes: - handle 'error' event from `codex` spawn (ENOENT) so missing PATH bails with an actionable "install codex CLI" message instead of an unhandled Node error - escalate SIGTERM -> SIGKILL after 5s grace when killing a stuck codex child so the CLI can't get pinned indefinitely - stop the spinner with a red "failed" glyph in the catch path before clearing activeSpin, mirroring `bail` (no orphan spinner above errors) - enforce 48 KB secret value cap by *bytes* (Buffer.byteLength) not UTF-16 code units, across all 3 secret routes; matches GH Actions' byte-based limit - preserve existing blank lines + comments when fresh-branch rewrites worktree .env (no more cosmetic reformat on every run) Scope: - default to `account` scope on org-owned repos too — never silently prompt for repo scope. Pullfrog has no per-GitHub-user secret store, so account is right for both user and org owners; `--scope repo` is the explicit opt-in for repo-only. UI: - new CodexAuthCallout (sibling to ClaudeCodeOAuthCallout); surfaces `pullfrog auth codex` for ChatGPT subscribers when an OpenAI provider model is selected. wired into AgentSettings.tsx (model-costs surface) and OnboardingCard.tsx (first-time setup). no paste button — the CLI handles minting + saving end-to-end. * auth/codex: rename to neon-fresh-branch, address PR review - rename `pnpm fresh-branch` → `pnpm neon-fresh-branch` (and the script file) to disambiguate from git branches. - `--scope` help text now explains the default (account) and when to pass `repo`. - move `_shared.ts` import up with the rest in `action/commands/auth.ts` and push the `stripAnsi` helper below the import block. - `sanitizeBranchName` no longer slices: slicing after trim could reintroduce a trailing `-`/`/`. callers slice the raw input first, then sanitize. - DRY the `start` branch of the codex progress callback (single header path, optional retry log). - thread a `timedOut` flag from `runDeviceAuth` → `ProgressEvent.exit` so the retry prompt can say "device authorization timed out — retry?" instead of the generic "no auth.json was written" line when the per-attempt timeout fires. - drop the redundant `mkdirSync` after `mkdtempSync` in `codexAuth.ts`. * untrack .scratch/ (committed screenshot fixture by mistake) * auth codex: prompt for scope on orgs (mirrors init) * revert worktree.ts: out of scope for this PR * anneal: trim _shared.ts dead exports, collapse CodexSpawnError, inline packageBin * codex auth: wire end-to-end runtime consumer CODEX_AUTH_JSON is now actually usable: the action runtime materializes it as OpenCode's auth.json at the runner's real $HOME/.local/share/opencode, OpenCode routes openai requests through the ChatGPT subscription via the embedded CodexAuthPlugin, and a GitHub Actions post: hook detects any refresh-chain rotation during the run and PUTs it back to Pullfrog via a new JWT-authenticated PUT /api/runtime/secret endpoint. Key decisions: - Write to the real $HOME (not the per-run tmpdir-redirected HOME) so the file lives outside OpenCode's `/tmp/*` permission allow zone — its existing deny-default protects it without any new permission rule. - Materialization gated on agent === opencode (Codex auth is OpenAI-only, Claude never sees the file). - Defense-in-depth on Claude: deny Read/Grep/Edit/Glob + sandbox.denyRead for ~/.local/share/opencode/auth.json in managedSettings (covers Bash file-reading commands too per Claude Code permissions docs). - New `provider.managedCredentials` field on the provider config — CLI-only credentials authored via `pullfrog auth <provider>`. Counted for hasAnyKey/log-redaction but never surfaced as a paste option in init. CODEX_AUTH_JSON is the first member; OPENAI_API_KEY stays in envVars. - Eager refresh on `pullfrog auth codex`: one OAuth round-trip before setPullfrogSecret so Pullfrog's copy is the freshest in the chain (avoids the user's laptop refreshing first and stranding our copy). - Post-hook approach for write-back so it survives cancellation, timeouts, and unhandled errors in the main step. State is ferried via core.saveState since apiToken is run-scoped and not in env. - Server-side write-back endpoint is allowlist-gated to CODEX_AUTH_JSON only — never a generic secret-write surface. Looks up the secret at repo scope first, falls back to account scope. 404s on create (refresh-only, never auto-provision). * codex auth: documentation + wiki cross-links * debug: log dbSecrets keys + CODEX_AUTH_JSON presence (temporary) * debug: surface install path + parse failure preview * remove debug log lines (E2E verified) * hide CodexAuthCallout until opencode-ai bump (1.1.56's allowed-models set excludes gpt-5.5)
86 lines
3.1 KiB
TypeScript
86 lines
3.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { detectCodexRefresh } from "./codexHome.ts";
|
|
|
|
// installCodexAuth touches the filesystem (mkdir + writeFile) — leaving it
|
|
// untested here per AGENTS.md guidance ("be highly dubious of any test that
|
|
// relies on mocks"). The conversion math is what we actually want to
|
|
// protect; the disk write is one writeFileSync call.
|
|
|
|
describe("detectCodexRefresh", () => {
|
|
const original = "rt_original_chain";
|
|
|
|
it("returns Codex-shape JSON when openai.refresh advanced", () => {
|
|
const authFileContent = JSON.stringify({
|
|
openai: {
|
|
type: "oauth",
|
|
refresh: "rt_new_chain",
|
|
access: "at_new",
|
|
expires: 9_999_999_999_999,
|
|
accountId: "acc_123",
|
|
},
|
|
});
|
|
const result = detectCodexRefresh({ authFileContent, originalRefresh: original });
|
|
expect(result).not.toBeNull();
|
|
const parsed = JSON.parse(result ?? "{}");
|
|
expect(parsed.auth_mode).toBe("chatgpt");
|
|
expect(parsed.tokens.refresh_token).toBe("rt_new_chain");
|
|
expect(parsed.tokens.access_token).toBe("at_new");
|
|
expect(parsed.tokens.account_id).toBe("acc_123");
|
|
expect(typeof parsed.last_refresh).toBe("string");
|
|
});
|
|
|
|
it("omits account_id when accountId is absent from OpenCode shape", () => {
|
|
const authFileContent = JSON.stringify({
|
|
openai: {
|
|
type: "oauth",
|
|
refresh: "rt_new",
|
|
access: "at_new",
|
|
expires: 0,
|
|
},
|
|
});
|
|
const result = detectCodexRefresh({ authFileContent, originalRefresh: original });
|
|
const parsed = JSON.parse(result ?? "{}");
|
|
expect("account_id" in parsed.tokens).toBe(false);
|
|
});
|
|
|
|
it("returns null when refresh token unchanged (no rotation happened)", () => {
|
|
const authFileContent = JSON.stringify({
|
|
openai: { type: "oauth", refresh: original, access: "at_same", expires: 0 },
|
|
});
|
|
expect(detectCodexRefresh({ authFileContent, originalRefresh: original })).toBeNull();
|
|
});
|
|
|
|
it("returns null when openai entry is missing", () => {
|
|
const authFileContent = JSON.stringify({
|
|
anthropic: { type: "oauth", refresh: "rt_other", access: "at_other", expires: 0 },
|
|
});
|
|
expect(detectCodexRefresh({ authFileContent, originalRefresh: original })).toBeNull();
|
|
});
|
|
|
|
it("returns null when openai is api-key type (no refresh chain)", () => {
|
|
const authFileContent = JSON.stringify({
|
|
openai: { type: "api", key: "sk-something" },
|
|
});
|
|
expect(detectCodexRefresh({ authFileContent, originalRefresh: original })).toBeNull();
|
|
});
|
|
|
|
it("returns null for malformed JSON", () => {
|
|
expect(
|
|
detectCodexRefresh({ authFileContent: "{not json", originalRefresh: original })
|
|
).toBeNull();
|
|
});
|
|
|
|
it("returns null for non-object content", () => {
|
|
expect(
|
|
detectCodexRefresh({ authFileContent: '"a string"', originalRefresh: original })
|
|
).toBeNull();
|
|
});
|
|
|
|
it("returns null when refresh field is missing", () => {
|
|
const authFileContent = JSON.stringify({
|
|
openai: { type: "oauth", access: "at_new", expires: 0 },
|
|
});
|
|
expect(detectCodexRefresh({ authFileContent, originalRefresh: original })).toBeNull();
|
|
});
|
|
});
|