Skip to content

feat(docs): add cmd/docs schema emitter for docs.baseten.co#13

Open
pat-baseten wants to merge 1 commit into
mainfrom
docs-schema-emitter
Open

feat(docs): add cmd/docs schema emitter for docs.baseten.co#13
pat-baseten wants to merge 1 commit into
mainfrom
docs-schema-emitter

Conversation

@pat-baseten

@pat-baseten pat-baseten commented May 25, 2026

Copy link
Copy Markdown

Summary

Adds an internal/cmddocs program that walks the declarative cmd.Root tree and emits a versioned docs.json describing every command, flag, example, output shape, and typed error. The schema in schema.go is the contract between this emitter and docs.baseten.co; SchemaVersion is bumped only on breaking changes.

The emitter lives in internal/cmddocs as package main, so it is not a user-facing baseten subcommand. The docs.baseten.co pipeline pins a baseten-cli ref, runs go run ./internal/cmddocs, and generates the CLI reference from the output — nothing in this repo's release flow runs the emitter or publishes the artifact.

Copilot AI review requested due to automatic review settings May 25, 2026 23:57

Copilot AI 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.

Pull request overview

Adds a dedicated cmd/docs emitter and internal/docs library to generate a stable, versioned docs.json schema describing the Baseten CLI command tree for downstream documentation generation (e.g., docs.baseten.co), and wires it into CI + releases.

Changes:

  • Introduce internal/docs schema + walker to convert cmd.Root into a versioned JSON document, with unit tests and a golden snapshot.
  • Add cmd/docs program to emit docs.json with reproducible timestamps via SOURCE_DATE_EPOCH.
  • Update CI to smoke-test JSON emission, and update goreleaser to attach docs.json to GitHub releases.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/docs/schema.go Defines the versioned JSON schema types for CLI docs emission.
internal/docs/walk.go Implements tree-walking conversion from cmd.Command to the docs schema.
internal/docs/schema_test.go Tests schema stability and JSON marshaling behavior.
internal/docs/walk_test.go Unit tests for walker behavior (paths, flags, output, errors).
internal/docs/golden_test.go Golden snapshot test against the real cmd.Root output.
internal/docs/testdata/docs.golden.json Golden snapshot artifact used to detect drift in emitted schema.
cmd/docs/main.go CLI entrypoint to emit docs.json to stdout or file with reproducible timestamps.
cmd/docs/README.md Documents schema contract, versioning rules, and local usage/testing.
.github/workflows/ci.yml Adds an Ubuntu-only smoke step to emit + parse-check docs.json.
.goreleaser.yaml Generates docs.json during release and attaches it as a release asset.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/docs/schema.go Outdated
Comment on lines +56 to +60
// GroupPri is the rendering priority for the flag's group (lower renders
// earlier). A value of 0 means the source field did not set group-pri; the
// group resolves to the framework default (DefaultFlagGroupPri = 100) at
// render time. Resolved by the walker — consumers should treat 0 as "use the
// framework default".
Comment thread .goreleaser.yaml Outdated
before:
hooks:
- go mod tidy
- sh -c 'go run ./cmd/docs --cli-version={{ .Version }} --out=docs.json'
Comment thread .goreleaser.yaml Outdated
before:
hooks:
- go mod tidy
- sh -c 'go run ./cmd/docs --cli-version={{ .Version }} --out=docs.json'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I do not think goreleaser needs to be running any of the docs stuff

Comment thread internal/cmddocs/main.go

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can this move to internal/cmddocs to be less user facing? Running go run ./internal/cmddocs should be ok (and changing the other things in the package to be package main should be harmless for this kind of tool)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can this package be called cmddocs or docgen or similar? As docs/ it looks like actual docs

Comment thread .github/workflows/ci.yml Outdated
Comment on lines +31 to +35
- name: Emit docs.json (smoke)
if: matrix.os == 'ubuntu-latest'
run: |
go run ./cmd/docs --cli-version=ci --out=/tmp/docs.json
python3 -c "import json,sys; json.load(open('/tmp/docs.json')); print('valid JSON, $(wc -c < /tmp/docs.json) bytes')"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we have unit tests do the equivalent of this (run the code as Go, write to a temp dir, use Go to validate JSON, etc)

Comment thread internal/docs/testdata/docs.golden.json Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you help me understand the purpose of this file? If this is something simply calling the code via a Go test can generate, why put it in the repo instead of generating it during the tests?

Comment thread internal/docs/golden_test.go Outdated
Comment on lines +41 to +43
if string(got) != string(want) {
t.Fatalf("docs.golden.json drift. If intentional, run:\n go test ./internal/docs -run Golden -update\n\nFirst 400 chars of got:\n%s", truncate(string(got), 400))
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am not following this exactly. People have to keep some testdata/ up to date? See other comment on whether this is even needed

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@pat-baseten pat-baseten force-pushed the docs-schema-emitter branch 2 times, most recently from 33cddf3 to ff8d448 Compare June 24, 2026 20:15
Walks the declarative cmd.Root tree and emits a versioned docs.json
describing every command, flag, example, output shape, and typed error.
Consumed by the docs.baseten.co pipeline, which pins a baseten-cli ref,
runs `go run ./internal/cmddocs`, and generates the CLI reference.

The emitter lives in internal/cmddocs (package main) so it is not a
user-facing baseten subcommand. Release flow and goreleaser are untouched:
the docs pipeline is the only caller.
@pat-baseten pat-baseten force-pushed the docs-schema-emitter branch from ff8d448 to 0fd7271 Compare June 24, 2026 20:22

@cretz cretz left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice and self-contained, looks great

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.

4 participants