diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 067a660..f75e4c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 - with: { go-version: '1.26.9' } + with: { go-version: '1.26.10' } - name: gofmt run: test -z "$(gofmt -l .)" || (gofmt -l . && exit 1) - name: vet @@ -65,7 +65,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 - with: { go-version: '1.26.9' } + with: { go-version: '1.26.10' } - name: golangci-lint uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0 with: @@ -84,7 +84,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 - with: { go-version: '1.26.9' } + with: { go-version: '1.26.10' } - name: fuzz untrusted-input parsers (negative control — normal input passes) run: | set -euo pipefail @@ -259,7 +259,7 @@ jobs: echo "negative control rejected as required — the schema gate catches malformed manifests" - name: set up Go uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 - with: { go-version: '1.26.9' } + with: { go-version: '1.26.10' } - name: leak gate + offline validator on the packaged artifact # The Go suite validates the manifest offline AND runs the leak gate over # the packaged skill payload (declared skills resolve to shareable, no diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 2ec80b3..38807f6 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -22,7 +22,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 - with: { go-version: '1.26.9' } + with: { go-version: '1.26.10' } - name: Initialize CodeQL uses: github/codeql-action/init@1c5b675653bb5c22dbe9b12b556ec555138e09fd # v4.38.1 with: diff --git a/.github/workflows/govulncheck.yml b/.github/workflows/govulncheck.yml index bc44303..5c47024 100644 --- a/.github/workflows/govulncheck.yml +++ b/.github/workflows/govulncheck.yml @@ -16,7 +16,7 @@ jobs: steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 - with: { go-version: '1.26.9' } + with: { go-version: '1.26.10' } - name: govulncheck run: | go install golang.org/x/vuln/cmd/govulncheck@latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 07138dd..cd4c409 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: { fetch-depth: 0 } - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 - with: { go-version: '1.26.9' } + with: { go-version: '1.26.10' } # Refuse to publish a tag whose version has no real changelog entry. This # runs BEFORE goreleaser, so an empty release fails the build rather than # publishing and being reported after the fact. The gate asserts a dated, diff --git a/CHANGELOG.md b/CHANGELOG.md index ac28f83..ef5f099 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,8 +26,19 @@ tagged release, goreleaser generates the release notes from the commit log reference that cannot be loaded is a hard error naming the path (plain `validate` without `--templates` never consults the key). (#182) +### Changed + +- `index build` now links a subdirectory entry to the child's index file + (`* [Wine](wine/index.md)`) instead of the bare directory (`wine/`), so a + reader that can only open files can follow it. An index written by an older + build reads as stale under `index check` once; the next `index build` + rewrites its links and keeps hand-written subdirectory descriptions. + ### Fixed +- `node touch` and every other `modified` refresh no longer turn an empty null + frontmatter key (`? `) into an empty-string key the node never had. + - `validate` now enforces OKF v0.2 §9 on every reserved `log.md` at any depth: each `## ` date heading must be a valid ISO-8601 `YYYY-MM-DD` (rejecting impossible dates like `2025-13-45` and non-dates like `last Tuesday`), @@ -51,6 +62,8 @@ tagged release, goreleaser generates the release notes from the commit log - The Go toolchain was bumped from 1.26.6 to 1.26.9 to pick up patched standard-library fixes for seven disclosed vulnerabilities (GO-2026-6603, -6607, -6608, -6611, -6612, -6613, -6617), clearing `govulncheck` in CI. +- The Go toolchain was bumped from 1.26.9 to 1.26.10 for the `crypto/x509` + fix (GO-2026-6809), reached through the atomic writer's temp-file naming. ## [0.4.0] - 2026-08-19 diff --git a/docs/guides/index-and-freshness.md b/docs/guides/index-and-freshness.md index 96762ca..9121d96 100644 --- a/docs/guides/index-and-freshness.md +++ b/docs/guides/index-and-freshness.md @@ -8,6 +8,14 @@ concepts or subdirectories, enumerating only that directory's own contents with index carries frontmatter (the §12 `okf_version` marker); every nested index carries none. +A subdirectory entry links to the child's own index file, as in +`* [Wine](wine/index.md) - description`, not to the bare directory, so a reader that can only open files +(an agent's read tool, a plain Markdown viewer) can follow it. §8 leaves the +relative URL open; its `subdir/` example is one spelling, not a rule. An index +written by an older build with `wine/` links reads as stale under `index check` +until the next `index build`, which rewrites the links and keeps every +hand-written subdirectory description. + - `okfctl index build [dir]` regenerates the reserved `index.md` files from the current bundle. Orphaned indexes left in a now-empty directory are pruned. - `okfctl index check [dir]` verifies every directory's `index.md` is current; diff --git a/go.mod b/go.mod index d52125b..2f38766 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/cwest/okfctl -go 1.26.9 +go 1.26.10 require ( github.com/spf13/cobra v1.10.2 diff --git a/internal/fsutil/confine.go b/internal/fsutil/confine.go index 535e83f..8d0b3a1 100644 --- a/internal/fsutil/confine.go +++ b/internal/fsutil/confine.go @@ -69,7 +69,7 @@ func ResolveInRoot(root, rel string) (string, error) { if filepath.VolumeName(native) != "" { return "", fmt.Errorf("%w: %s", ErrEscapesRoot, rel) } - native = strings.TrimLeft(native, string(filepath.Separator)+"/") + native = strings.TrimLeftFunc(native, func(r rune) bool { return r == '/' || r == filepath.Separator }) clean := filepath.Clean(native) if clean == "." || native == "" { return "", fmt.Errorf("%w: %q names the bundle root", ErrInvalidPath, rel) @@ -103,7 +103,7 @@ func ResolveInRoot(root, rel string) (string, error) { } realExisting, err := filepath.EvalSymlinks(existing) if err != nil { - return "", fmt.Errorf("%w: %s (%v)", ErrEscapesRoot, rel, err) + return "", fmt.Errorf("%w: %s (%w)", ErrEscapesRoot, rel, err) } if !within(realRoot, realExisting) { return "", fmt.Errorf("%w: %s resolves through a symlink to %s", ErrEscapesRoot, rel, realExisting) @@ -122,7 +122,7 @@ func ResolveInRoot(root, rel string) (string, error) { cur = filepath.Join(cur, part) fi, err := os.Lstat(cur) if err != nil { - return "", fmt.Errorf("%w: %s (%v)", ErrEscapesRoot, rel, err) + return "", fmt.Errorf("%w: %s (%w)", ErrEscapesRoot, rel, err) } if fi.Mode()&(os.ModeSymlink|os.ModeIrregular) == 0 { continue diff --git a/internal/okf/frontmatter_edit.go b/internal/okf/frontmatter_edit.go index 878e60f..ae4a4aa 100644 --- a/internal/okf/frontmatter_edit.go +++ b/internal/okf/frontmatter_edit.go @@ -60,6 +60,13 @@ func TouchModifiedFile(abs string, at time.Time) error { return fsutil.WriteFileAtomic(abs, out.Bytes(), 0o644) //nolint:gosec // G306: shareable bundle content file } + // Refuse a block the frontmatter parser rejects. Decoding into a yaml.Node + // skips the map-level checks (a duplicate key, for one), so without this the + // refresh would rewrite an invalid block instead of leaving it byte-identical. + if _, _, err := ParseFrontmatter(raw); err != nil { + return fmt.Errorf("parse frontmatter of %s: %w", abs, err) + } + var doc yaml.Node if err := yaml.Unmarshal(yamlBlock, &doc); err != nil { return fmt.Errorf("parse frontmatter of %s: %w", abs, err) @@ -69,6 +76,7 @@ func TouchModifiedFile(abs string, at time.Time) error { return fmt.Errorf("frontmatter of %s is not a mapping", abs) } setScalar(root, "modified", stamp) + keepEmptyNullKeysNull(root) var fmBuf bytes.Buffer enc := yaml.NewEncoder(&fmBuf) @@ -104,6 +112,26 @@ func frontmatterMapping(doc *yaml.Node) *yaml.Node { return doc } +// keepEmptyNullKeysNull rewrites every mapping key that is an empty plain null +// (an explicit `? ` key) as `~`, recursively. yaml.v3 encodes that empty plain +// scalar as an empty quoted STRING, so a refresh would otherwise invent a key +// the node never had. `~` is the same null, spelled so it survives the encoder. +// A key that is already a quoted empty string is real data and is left alone. +func keepEmptyNullKeysNull(n *yaml.Node) { + for _, c := range n.Content { + keepEmptyNullKeysNull(c) + } + if n.Kind != yaml.MappingNode { + return + } + for i := 0; i+1 < len(n.Content); i += 2 { + k := n.Content[i] + if k.Kind == yaml.ScalarNode && k.Value == "" && k.Style == 0 && k.ShortTag() == "!!null" { + k.Value = "~" + } + } +} + // setScalar updates the scalar value of key in a mapping node in place, // preserving key order; if the key is absent it is appended, keeping the // original keys ahead of it. diff --git a/internal/okf/frontmatter_edit_test.go b/internal/okf/frontmatter_edit_test.go index 64e091f..3da152f 100644 --- a/internal/okf/frontmatter_edit_test.go +++ b/internal/okf/frontmatter_edit_test.go @@ -99,6 +99,46 @@ func TestTouchModifiedFileAddsMissingModified(t *testing.T) { } } +// A null key written as an empty explicit key (`? `) must stay null across a +// refresh. yaml.v3 re-encodes that empty plain scalar as an empty quoted STRING +// key, which a parser then reads as a key the node never had (the +// FuzzTouchModifiedRoundTrip failure `touch added keys: [] -> [ modified]`, +// where the blank is the empty key). The negative +// control: a key that really is the empty string keeps its quotes. +func TestTouchModifiedFileKeepsEmptyNullKeyNull(t *testing.T) { + at := time.Date(2026, 7, 26, 0, 0, 0, 0, time.UTC) + cases := []struct { + name, src string + wantKeys int // keys a parser sees after the touch + }{ + {"null key stays null", "---\n? \n---\n", 1}, + {"nested null key stays null", "---\na:\n ? \n---\n", 2}, + {"empty string key stays a key", "---\n'': x\n---\n", 2}, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + abs := filepath.Join(t.TempDir(), "n.md") + if err := os.WriteFile(abs, []byte(c.src), 0o644); err != nil { + t.Fatal(err) + } + if err := TouchModifiedFile(abs, at); err != nil { + t.Fatalf("TouchModifiedFile: %v", err) + } + got := readAll(t, abs) + fm, _, err := ParseFrontmatter([]byte(got)) + if err != nil { + t.Fatalf("touched frontmatter does not parse: %v\n%q", err, got) + } + if len(fm) != c.wantKeys { + t.Fatalf("got %d keys %q, want %d:\n%q", len(fm), sortedKeys(fm), c.wantKeys, got) + } + if c.name == "nested null key stays null" && strings.Contains(got, "''") { + t.Fatalf("nested null key re-encoded as an empty string:\n%q", got) + } + }) + } +} + // The separator blank line between the frontmatter fence and the body must // survive a refresh byte-for-byte. The corpus writes `---\n\n# Heading`; a // refresh that collapses that to `---\n# Heading` is a prose change the drift diff --git a/internal/okf/tagfold.go b/internal/okf/tagfold.go index 12aa59c..b88be48 100644 --- a/internal/okf/tagfold.go +++ b/internal/okf/tagfold.go @@ -79,7 +79,7 @@ func tagPluralCandidates(w string) []string { case strings.HasSuffix(w, "es"): j := n - 3 // the letter before "es" var out []string - if j > 0 && !(w[j] == 's' && w[j-1] == 's') { + if j > 0 && (w[j] != 's' || w[j-1] != 's') { out = append(out, w[:n-1]) } return append(out, w[:n-2]) diff --git a/internal/okf/writepath_fuzz_test.go b/internal/okf/writepath_fuzz_test.go index 803e1be..c434fd4 100644 --- a/internal/okf/writepath_fuzz_test.go +++ b/internal/okf/writepath_fuzz_test.go @@ -113,6 +113,8 @@ func FuzzTouchModifiedRoundTrip(f *testing.F) { "---\r\ntype: Reference\r\n---\r\n\r\nCRLF body\r\n", "---\ntitle: |\n line\n ---\n injected: true\n---\n", "---\n- a list\n---\n", + "---\n? \n---\n", // an empty null key: re-encoded as '' it became a new key + "---\nype: 0\nype:\n---\n", // a duplicate key: the parser rejects it, so touch must too "", } for _, s := range seeds {