Skip to content

fix(#1768): remove stale .adoc files before doc generation#1769

Open
fullsend-ai-coder[bot] wants to merge 1 commit into
mainfrom
agent/1768-remove-stale-docs
Open

fix(#1768): remove stale .adoc files before doc generation#1769
fullsend-ai-coder[bot] wants to merge 1 commit into
mainfrom
agent/1768-remove-stale-docs

Conversation

@fullsend-ai-coder

Copy link
Copy Markdown

GenerateAsciidoc() only created/overwrote .adoc files for currently existing packages but never removed files for deleted packages. This caused stale documentation to persist in the repo and published docs.

Add removeAdocFiles() helper that clears all .adoc files from the packages/ directory before regenerating. Since everything in that directory is generated content, this is safe and simpler than a marker-based approach.

Add unit tests covering removal of .adoc files, preservation of non-.adoc files and subdirectories, and graceful handling of nonexistent or empty directories.


Closes #1768

Post-script verification

  • Branch is not main/master (agent/1768-remove-stale-docs)
  • Secret scan passed (gitleaks — 621fc39ae43ed1298a37c971f3483c59c8ef5a60..HEAD)
  • Pre-commit hooks passed (authoritative run on runner)
  • Tests ran inside sandbox

GenerateAsciidoc() only created/overwrote .adoc files for currently
existing packages but never removed files for deleted packages. This
caused stale documentation to persist in the repo and published docs.

Add removeAdocFiles() helper that clears all .adoc files from the
packages/ directory before regenerating. Since everything in that
directory is generated content, this is safe and simpler than a
marker-based approach.

Add unit tests covering removal of .adoc files, preservation of
non-.adoc files and subdirectories, and graceful handling of
nonexistent or empty directories.

Closes #1768
@fullsend-ai-review

fullsend-ai-review Bot commented Jul 8, 2026

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 4:11 PM UTC · Completed 4:21 PM UTC
Commit: 8f05d87 · View workflow run →

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Flag Coverage Δ
unit-tests 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fullsend-ai-review

Copy link
Copy Markdown

Review of PR #1769

Verdict: Approve

Clean, well-scoped fix that precisely implements the approach suggested in #1768. The new removeAdocFiles helper clears all .adoc files from the packages/ directory before GenerateAsciidoc regenerates them, preventing stale documentation from persisting when policy packages are deleted.

What was reviewed

Dimension Result
Correctness ✅ Logic is sound. Error handling is thorough. Tests cover the key behaviors (removal, preservation, edge cases).
Security ✅ No concerns — build-time CLI tool, no untrusted input, tightly-scoped file operations.
Intent & coherence ✅ Matches issue #1768 scope exactly. No scope creep. Approach follows the issue's explicit suggestion.
Style & conventions ✅ Follows existing codebase patterns: Go-convention doc comment, gerund-phrase error wrapping, subtest structure with t.TempDir().
Documentation currency ✅ No docs need updating. The user-facing workflow (make generate-docs → commit) is unchanged.
Cross-repo contracts ✅ No breaking changes. GenerateAsciidoc signature unchanged; only caller is the in-repo docs/main.go CLI.

Findings

[low] os.IsNotExist vs errors.Isdocs/asciidoc/asciidoc.go:370

The function uses os.IsNotExist(err) which works correctly for the unwrapped *os.PathError from os.ReadDir, but the idiomatic Go 1.13+ approach is errors.Is(err, fs.ErrNotExist) since the io/fs package is already imported. The modern form is more robust against future refactors that might wrap the error before this check.

[low] Pre-existing nil-dereference riskdocs/asciidoc/asciidoc.go:379

for _, p := range *d.Packages will panic if d.Packages is nil, which happens when SetAnnotations finds zero packages for a doc category. This is not introduced by this PR and is equally reachable with or without the new cleanup step — it's a pre-existing issue in the same function. In practice the five doc categories (release, pipeline, task, build_task, stepaction) always have at least one package, but a nil guard would be safer.

Neither finding blocks this PR.


Labels: PR fixes a bug in documentation generation tooling

Comment thread docs/asciidoc/asciidoc.go
func removeAdocFiles(dir string) error {
entries, err := os.ReadDir(dir)
if err != nil {
if os.IsNotExist(err) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[low] best-practice

Uses os.IsNotExist(err) instead of the idiomatic errors.Is(err, fs.ErrNotExist). While both work correctly here (os.ReadDir returns an unwrapped *os.PathError), the errors.Is form handles wrapped errors and is the Go 1.13+ convention. The io/fs package is already imported in this file.

Suggested fix: Replace if os.IsNotExist(err) with if errors.Is(err, fs.ErrNotExist) and add "errors" to the import block.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will fullsend the coder notice this suggestion made by fullsend the reviewer, and make the suggested change?

Comment thread docs/asciidoc/asciidoc.go
if !entry.IsDir() && strings.HasSuffix(entry.Name(), ".adoc") {
if err := os.Remove(filepath.Join(dir, entry.Name())); err != nil {
return fmt.Errorf("removing file %q: %w", entry.Name(), err)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[low] nil-dereference

Pre-existing bug (not introduced by this PR): for _, p := range *d.Packages panics when d.Packages is nil, which occurs when SetAnnotations finds zero packages for a doc category. While all five categories currently have packages, adding a nil guard would prevent a crash if a category ever becomes empty.

Suggested fix: Wrap the range loop in if d.Packages != nil { ... }.

@fullsend-ai-review fullsend-ai-review Bot added ready-for-merge All reviewers approved — ready to merge bug Something isn't working tooling labels Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready-for-merge All reviewers approved — ready to merge size: L tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove stale generated documentation when policy packages are deleted

1 participant