Skip to content

fix(cli): do not pass the github token to generators in preview mode - #17425

Open
fern-api[bot] wants to merge 8 commits into
mainfrom
devin/1786735933-preview-skip-readme-clone
Open

fix(cli): do not pass the github token to generators in preview mode#17425
fern-api[bot] wants to merge 8 commits into
mainfrom
devin/1786735933-preview-skip-readme-clone

Conversation

@fern-api

@fern-api fern-api Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Two related fixes for README/reference generation killing otherwise-successful SDK generation (Auth0, Pylon #22738).

1. CLI, preview-scoped (runLocalGenerationForWorkspace.ts): --preview substitutes env vars as empty strings, so github.token: ${GITHUB_TOKEN} reaches the IR as "". AbstractGeneratorAgent.getRemote only null-checks, so the generator builds a readme remote and does an unauthenticated git clone in the container. getPublishConfig now takes isPreview and omits the token only when it is actually unusable:

const dropTokenForPreview = isPreview === true && !generatorInvocation.raw.github.token;

A preview run with a real token still forwards it (full-fidelity README). When the token is dropped, a logger.warn says README/reference content won't be merged from the existing repo. Non-preview behavior is unchanged — an empty token is still passed through as-is.

2. Generators, non-fatal README/reference (generators/base/src/AbstractGeneratorAgent.ts): this also bites non-preview runs where the token is forwarded but the in-container clone fails on a corporate TLS-interception CA. generateReadme/generateReference previously logged at debug and rethrew, killing generation before any SDK files were copied (.fernignore cleanup then left a PR with only custom files + changelog). They now return string | undefined and never throw:

  • README CLI failure with a remote configured → retry once with remote: undefined (generates the README from scratch instead of merging the repo's existing one), with a logger.warn naming the underlying error.
  • Any other failure → logger.warn (never debug-only) including the underlying reason, and skip emitting that file.

SwiftGeneratorAgent overrides both methods, so it got the same treatment. All call sites (csharp, go-v2, java-v2, php, python-v2, ruby-v2, rust, swift, typescript) skip emitting the file when the content is undefined.

Testing

  • pnpm turbo run test --filter @fern-api/local-workspace-runner — 185 passed. getPublishConfig.preview.test.ts covers empty/absent token in preview → omitted, non-empty token in preview → forwarded, and both token cases outside preview → forwarded unchanged.
  • pnpm compile — full monorepo compile green.

Changelog

  • packages/cli/cli/changes/unreleased/fix-preview-github-token.yml
  • fix-readme-generation-non-fatal.yml under each affected generator's sdk/changes/unreleased/ (csharp, go, java, php, python, ruby-v2, rust, swift, typescript).

@nitpickybot nitpickybot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Review Summary

Small, well-scoped CLI fix: preview runs no longer forward the (empty-substituted) GitHub token into the IR publishing config, avoiding a doomed clone inside the generator container. Logic and threading look correct; only minor robustness/test nits.

  • 🔵 2 suggestion(s)

Comment on lines +7 to +13
const mockContext = {
logger: {
debug: () => undefined,
warn: () => undefined
}
// Test mock: getPublishConfig only touches the logger.
} as unknown as TaskContext;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 suggestion

The logger stub only implements debug/warn. If getPublishConfig ever logs at another level (or calls context.failAndThrow), the test explodes with an unhelpful is not a function. Cheap insurance: stub info/error/log too, or use a Proxy returning no-ops.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — done in 0cedfc0: the stub logger is now a Proxy returning no-ops for every level, so a new log call can't blow the test up with is not a function. Still green: pnpm turbo run test --filter @fern-api/local-workspace-runner (182 passed).

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Docs Generation Benchmark Results

Comparing PR branch against median of 5 nightly run(s) on main (latest: 2026-08-14T04:33:13Z).

Fixture main PR Delta
docs 268.5s (n=5) 261.1s (35 versions) -7.4s (-2.8%)

Docs generation runs fern generate --docs --preview end-to-end against the benchmark fixture with 35 API versions (each version: markdown processing + OpenAPI-to-IR + FDR upload).
Delta is computed against the nightly baseline on main.
Baseline from nightly run(s) on main (latest: 2026-08-14T04:33:13Z). Trigger benchmark-baseline to refresh.
Last updated: 2026-08-14 23:14 UTC

@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

SDK Generation Benchmark Results

Comparing PR branch against median of 5 nightly run(s) on main (latest: 2026-08-14T04:33:13Z).

Full benchmark table (click to expand)
Generator Spec main (generator) main (E2E) PR (generator) Delta
csharp-sdk square 98s (n=5) N/A 90s -8s (-8.2%)
go-sdk square 145s (n=5) 297s (n=5) 132s -13s (-9.0%)
java-sdk square 221s (n=5) 286s (n=5) 204s -17s (-7.7%)
php-sdk square 78s (n=5) N/A 76s -2s (-2.6%)
python-sdk square 152s (n=5) 256s (n=5) 150s -2s (-1.3%)
ruby-sdk-v2 square 110s (n=5) 152s (n=5) 105s -5s (-4.5%)
rust-sdk square 206s (n=5) 212s (n=5) 226s +20s (+9.7%)
swift-sdk square 78s (n=5) 447s (n=5) 75s -3s (-3.8%)
ts-sdk square 185s (n=5) 185s (n=5) 117s -68s (-36.8%)

main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via fern generate). main (E2E): full customer-observable time including build/test scripts (nightly baseline, informational). Delta is computed against generator-only baseline.
⚠️ = generation exited with a non-zero exit code (timing may not reflect a successful run).
Baseline from nightly runs on main (latest: 2026-08-14T04:33:13Z). Trigger benchmark-baseline to refresh.
Last updated: 2026-08-14 23:15 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants