docs(agents): a bead never carries production instance detail
Beads sync to a Dolt remote, so anything written into one is published. Two beads filed earlier today named an operator host, its internal address and its filesystem paths -- the tracker was treated as a private store, which it is not. The rule is stated where the tracker is described, next to the existing one about .beads/ never reaching a commit, because it is the same class: the tracker is not a private store. Host-specific facts belong in the operator's memos instance, which a bead may point at.
This commit is contained in:
1 parent
052e350bf1
commit
a65eae2458
20 files changed
+1121
-545
No files matched your search
+90
-15
@@ -34,6 +34,7 @@ import (
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
@@ -410,8 +411,93 @@ func resolveLinks(relative, body string, urls map[string]string, slugs map[strin
|
||||
|
||||
// readPages reads the source of every page either set carries, keyed by its path
|
||||
// relative to docs/.
|
||||
func readPages(sourceDir string) (map[string]string, error) {
|
||||
//
|
||||
// The page list comes from the commit, not from the working tree: see
|
||||
// sourcePages for why that distinction is the whole of this function's contract.
|
||||
func readPages(repoRoot, sourceDir string) (map[string]string, error) {
|
||||
relativePaths, err := sourcePages(repoRoot, sourceDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bodies := map[string]string{}
|
||||
for _, relative := range relativePaths {
|
||||
if !published(relative) {
|
||||
continue
|
||||
}
|
||||
body, err := os.ReadFile(filepath.Join(sourceDir, relative))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read %s: %w", relative, err)
|
||||
}
|
||||
bodies[relative] = string(body)
|
||||
}
|
||||
if len(bodies) == 0 {
|
||||
return nil, fmt.Errorf("no published pages under %s", docsDir)
|
||||
}
|
||||
return bodies, nil
|
||||
}
|
||||
|
||||
// sourcePages lists the published candidate pages, relative to docs/, choosing
|
||||
// git over a directory walk whenever git can answer.
|
||||
//
|
||||
// The artifacts are committed beside their sources, so each one must be derived
|
||||
// from the files the commit carries. A walk also sees an UNTRACKED page -- one no
|
||||
// commit holds -- and then reported the artifact as stale, which sent the reader
|
||||
// to regenerate an artifact that was already correct and would have committed a
|
||||
// page belonging to no commit. That happened twice in one session, once to a
|
||||
// migration branch and once to an unrelated writer staging a new PRD.
|
||||
//
|
||||
// The index counts as well as HEAD, deliberately: a page staged for this commit
|
||||
// is about to be carried by it, so the artifact must include it and check must
|
||||
// fail until it does. Only a file in neither tree is ignored -- and that is
|
||||
// exactly the working-tree scratch this exists to exclude.
|
||||
//
|
||||
// Outside a git work tree there is no commit to disagree with, so the walk is
|
||||
// the best answer available and is used unchanged, with a line saying so rather
|
||||
// than a silence that reads as the stronger guarantee.
|
||||
func sourcePages(repoRoot, sourceDir string) ([]string, error) {
|
||||
pages, err := trackedPages(repoRoot, sourceDir)
|
||||
if err == nil {
|
||||
return pages, nil
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "docsite: %v; falling back to a directory walk, which cannot tell an untracked page from a committed one\n", err)
|
||||
return walkedPages(sourceDir)
|
||||
}
|
||||
|
||||
// trackedPages asks git for the .md files under docs/ that the index or HEAD
|
||||
// carries.
|
||||
func trackedPages(repoRoot, sourceDir string) ([]string, error) {
|
||||
rel, err := filepath.Rel(repoRoot, sourceDir)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("locate %s under %s: %w", docsDir, repoRoot, err)
|
||||
}
|
||||
rel = filepath.ToSlash(rel)
|
||||
// -z because a path may contain anything but NUL; --cached so a page staged
|
||||
// for this commit counts.
|
||||
out, err := exec.Command("git", "-C", repoRoot, "ls-files", "--cached", "-z", "--", rel).Output()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("git ls-files %s: %w", rel, err)
|
||||
}
|
||||
var pages []string
|
||||
for _, entry := range strings.Split(string(out), "\x00") {
|
||||
if entry == "" {
|
||||
continue
|
||||
}
|
||||
relative := strings.TrimPrefix(entry, rel+"/")
|
||||
if relative == entry || !strings.HasSuffix(relative, ".md") {
|
||||
continue
|
||||
}
|
||||
pages = append(pages, relative)
|
||||
}
|
||||
if len(pages) == 0 {
|
||||
return nil, fmt.Errorf("git ls-files %s listed no Markdown", rel)
|
||||
}
|
||||
return pages, nil
|
||||
}
|
||||
|
||||
// walkedPages is the gitless enumeration: every .md under the tree, tracked or
|
||||
// not.
|
||||
func walkedPages(sourceDir string) ([]string, error) {
|
||||
var pages []string
|
||||
err := filepath.WalkDir(sourceDir, func(filename string, entry fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -423,24 +509,13 @@ func readPages(sourceDir string) (map[string]string, error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
relative = filepath.ToSlash(relative)
|
||||
if !published(relative) {
|
||||
return nil
|
||||
}
|
||||
body, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return fmt.Errorf("read %s: %w", relative, err)
|
||||
}
|
||||
bodies[relative] = string(body)
|
||||
pages = append(pages, filepath.ToSlash(relative))
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("walk %s: %w", docsDir, err)
|
||||
}
|
||||
if len(bodies) == 0 {
|
||||
return nil, fmt.Errorf("no published pages under %s", docsDir)
|
||||
}
|
||||
return bodies, nil
|
||||
return pages, nil
|
||||
}
|
||||
|
||||
// setDocument pairs one set with the artifact generated for it.
|
||||
@@ -455,7 +530,7 @@ type setDocument struct {
|
||||
// link that crosses between them resolves to the base its target is served under.
|
||||
func load(repoRoot string) ([]setDocument, error) {
|
||||
sourceDir := filepath.Join(repoRoot, docsDir)
|
||||
bodies, err := readPages(sourceDir)
|
||||
bodies, err := readPages(repoRoot, sourceDir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -216,6 +217,59 @@ func TestCheckFailsOnAStaleArtifactAndLeavesTheTreeAlone(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestUntrackedPagesDoNotReachTheArtifact pins why the artifact is derived from
|
||||
// the commit rather than from the working tree. docs:artifact:check runs in the
|
||||
// gate and reads the sources from disk, so an untracked page under docs/ made
|
||||
// the committed artifact look stale. The gate then demanded a regeneration that
|
||||
// was already correct, and that regeneration would have committed a page no
|
||||
// commit carries. It cost two sessions in one day: a migration branch, and an
|
||||
// unrelated writer adding a PRD.
|
||||
func TestUntrackedPagesDoNotReachTheArtifact(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
writeFile(t, filepath.Join(root, "docs", "index.md"), "# Archie\n\nHello.\n")
|
||||
writeFile(t, filepath.Join(root, "docs", "architecture", "policy.md"), "# Policy\n\nRules.\n")
|
||||
gitIn(t, root, "init", "--quiet")
|
||||
gitIn(t, root, "add", "docs/index.md", "docs/architecture/policy.md")
|
||||
|
||||
if err := write(root); err != nil {
|
||||
t.Fatalf("write: %v", err)
|
||||
}
|
||||
|
||||
// Untracked: no commit carries it, so the committed artifact is not required
|
||||
// to contain it and check must not claim the artifact is stale.
|
||||
writeFile(t, filepath.Join(root, "docs", "prds", "scratch.md"), "# Scratch\n\nNot committed.\n")
|
||||
if err := check(root); err != nil {
|
||||
t.Fatalf("check with an untracked page = %v, want it to pass", err)
|
||||
}
|
||||
|
||||
// Staged: this commit is about to carry it, so the artifact must too.
|
||||
gitIn(t, root, "add", "docs/prds/scratch.md")
|
||||
if err := check(root); err == nil {
|
||||
t.Fatal("check with a staged page = nil, want a failure: the artifact does not carry it")
|
||||
}
|
||||
if err := write(root); err != nil {
|
||||
t.Fatalf("write: %v", err)
|
||||
}
|
||||
if err := check(root); err != nil {
|
||||
t.Fatalf("check after regenerating for the staged page = %v, want it to pass", err)
|
||||
}
|
||||
}
|
||||
|
||||
// gitIn runs one git command in dir, failing loudly rather than skipping: task
|
||||
// check already requires git for proto:lint, so a test that quietly passed
|
||||
// without it would be asserting nothing.
|
||||
func gitIn(t *testing.T, dir string, args ...string) {
|
||||
t.Helper()
|
||||
cmd := exec.Command("git", append([]string{"-C", dir}, args...)...)
|
||||
cmd.Env = append(os.Environ(),
|
||||
"GIT_AUTHOR_NAME=docsite", "GIT_AUTHOR_EMAIL=docsite@example.invalid",
|
||||
"GIT_COMMITTER_NAME=docsite", "GIT_COMMITTER_EMAIL=docsite@example.invalid",
|
||||
)
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
t.Fatalf("git %s: %v\n%s", strings.Join(args, " "), err, out)
|
||||
}
|
||||
}
|
||||
|
||||
func writeFile(t *testing.T, path, content string) {
|
||||
t.Helper()
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
|
||||
Reference in new issue
Block a user