Skip to content

Update testable-code report to scan docs monorepo content directories#6

Merged
krollins-mdb merged 5 commits intomainfrom
pages-with-examples
Mar 11, 2026
Merged

Update testable-code report to scan docs monorepo content directories#6
krollins-mdb merged 5 commits intomainfrom
pages-with-examples

Conversation

@krollins-mdb
Copy link
Collaborator

@krollins-mdb krollins-mdb commented Mar 10, 2026

Updates the testable-code report command to take arbitrary docs set directories in the monorepo as input using --for-docs-set. For example, --for-docs-set cloud-docs,golang,node. Also added a URL column to the report that includes the page's production URL for reference and changed the source file path to be relative to the content directory in the monrepo, rather than an absolute path for the machine the command is run on.

Also added a new resolve url command, which maps documentation source files to their production URLs. This logic uses the docs TOC as its source of truth instead of the Snooty Data API.

Image of a cute animal

- Introduced a new `resolve` command with a subcommand `url` to resolve source .txt files to their production URLs.
- Implemented URL resolution logic in `commands/resolve/url/resolver.go`.
- Added tests for URL construction and resolution functionality.
- Updated main command to include the new resolve command.
- Add `--for-docs-set` flag to scan all pages in specified content directories instead of requiring a CSV file
- Add `--current-only` flag to filter to current version pages when scanning docs sets (default: true)
- Add `--base-url` flag for resolving page URLs (default: https://www.mongodb.com/docs)
- Add `DocsSet` field to PageEntry and PageReport to track content directory name
- Add computed fields to PageReport: `TotalUntested` (TotalExamples - TotalTested) and `NeedsToBeTested` (true if TotalTestable > TotalTested)
- Make source paths relative to content directory in CSV output for better readability
- Update command usage to support both CSV mode and docs set scanning mode
- Make CSV file argument optional when using docs set mode
@krollins-mdb krollins-mdb marked this pull request as ready for review March 10, 2026 14:26
Copy link
Collaborator

@cbullinger cbullinger left a comment

Choose a reason for hiding this comment

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

overall, lgtm!


### Resolve Commands

#### `resolve url`
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] why not use hyphen? or are we expecting additional resolve subcommands

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Possibly! I wanted to leave the possibility open. For example, we could have a resolve command for getting the content location of one or more tested code examples.

./audit-cli resolve url content/compass/source/index.txt
# Output: https://www.mongodb.com/docs/compass/

# Use a different base URL (e.g., for staging)
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

// The URL slug is the path component after /docs/ in the production URL.
// For example, "golang" maps to "drivers/go", so the URL would be:
// https://www.mongodb.com/docs/drivers/go/current/
var projectToURLSlug = map[string]string{
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this something that could be extracted for common use?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Certainly! I'm not sure where else it would be useful. Happy to extract it as its own command if it makes sense to do so.

for _, docsSet := range docsSets {
docsSetPath := filepath.Join(contentDir, docsSet)
if _, err := os.Stat(docsSetPath); os.IsNotExist(err) {
return nil, fmt.Errorf("docs set not found: %s", docsSet)
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we want to include the docsSetPath in the error message?

Copy link
Collaborator

Choose a reason for hiding this comment

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

do we want to accumulate errors and continue if docs sets aren't found/are bad, rather than kill the whole run? maybe give an error report

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like both of those ideas. Made a change to how the errors are handled. They'll be printed at the end of a run as a separate report.


**Flags:**

- `--base-url <url>` - Base URL for production documentation (default: `https://www.mongodb.com/docs`)
Copy link
Collaborator

Choose a reason for hiding this comment

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

what about version as a flag?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added one and updated the docs for the report testable-code command. Good idea!

@krollins-mdb krollins-mdb merged commit 80cef9d into main Mar 11, 2026
2 checks passed
@krollins-mdb krollins-mdb deleted the pages-with-examples branch March 11, 2026 23:10
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.

2 participants