Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 10 additions & 2 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ name: Pages

# Each release's numbers as one web page to share, https://spin-stack.github.io/spin-machine/:
# the chart, the tables of docs/releases.md and each record, written from docs/releases/*.json by
# spin-machine-dev releases site (docs/cli.md). A merge that changes a record publishes it again;
# nothing else on the page can change without one. Not a required check, so a paths filter is safe.
# spin-machine-dev releases site (docs/cli.md). Beside it, log.html and experiments.html: the log
# and docs/boot-time.md's tables, rendered from docs/log and docs/experiments by spin-machine-dev
# docs site, and committed nowhere else (#709). A merge that changes a record or an entry publishes
# them again; nothing else on the pages can change without one. Not a required check, so a paths
# filter is safe.

on:
push:
branches: [main]
paths:
- "docs/releases/**"
- "docs/log/**"
- "docs/experiments/**"
workflow_dispatch:

permissions:
Expand Down Expand Up @@ -49,6 +54,9 @@ jobs:
- name: Write the site
run: spin-machine-dev releases site --out _site

- name: Write the log and the tables
run: spin-machine-dev docs site --out _site

- name: Configure Pages
uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0

Expand Down
27 changes: 20 additions & 7 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ The second number is a checkpoint restored to the same first login (`task boot:r
A change goes in when it moves one of the two, interleaved against the release, without making
the other worse. A functional change (security, correctness) goes in too. Every other number,
such as the console prompt, a phase, an initcall or a unit's time, is a tool for finding why one
of the two moved, never a target of its own. `docs/log.md` shows what optimising the others cost.
of the two moved, never a target of its own. The log (`docs/log`) shows what optimising the others
cost.

`docs/boot-time.md` says where both stand and what each of their phases costs, and
`docs/measuring.md` says how a number is taken and read. `docs/boot-time.md` also says why the
Expand Down Expand Up @@ -122,11 +123,23 @@ full method. These are its rules.
- Keep experiment outputs, overlays, initrds, firmware and caches apart from release outputs,
and never open the shared base image for writing.
- Remove an experiment once its question is answered. When a change decides something, kept or
rejected, add its row to `docs/boot-time.md`'s tables and its entry, dated and with its run, to
`docs/log.md`.
- **Read before starting.** Read `docs/boot-time.md`'s "Measured and rejected" table and
`docs/log.md`'s rework cycles. An idea already there needs a new reason, not a new run.
`docs/memory-and-disk.md` says what the guest's memory and disk cost.
rejected, add its record to `docs/experiments` and its entry, dated and with its run, to
`docs/log`. Each is a file of its own, so two pull requests in flight never edit the same one
(#709); the pages they make are rendered, never committed.
- **An entry** is `docs/log/<YYYY-MM-DD>-<slug>.md`: YAML front matter (`date`, `order`, the
entry's place among that day's, `area`, `title`, and the `issues`, `prs` and `runs` its text
cites), then the prose. `spin-machine-dev docs log` renders the page, its head
`**MM-DD · area · title.**`.
- **A record** is `docs/experiments/[<issue>-]<slug>.json`, one row of `docs/boot-time.md`'s
tables: `decision` (`carried`, `rejected` or `open`), a rejected one's `section`, `order`
(its place in the table), and the cells its table shows. `spin-machine-dev docs tables`
renders the tables. A record that moves, from open to rejected, changes its `decision`.
- `gates/docs_test.go` refuses an entry or record that lacks a field, names a decision or
section that does not exist, or lists a run, issue or pull request its text does not cite.
- **Read before starting.** Read the "Measured and rejected" records
(`spin-machine-dev docs tables`) and the log's rework cycles (`docs/log/rework.md`). An idea
already there needs a new reason, not a new run. `docs/memory-and-disk.md` says what the
guest's memory and disk cost.
- **Search outside the repository too.** Many people work on KVM, QEMU, the kernel and systemd,
and a boot-time idea has usually been tried, measured or refused somewhere: the projects'
mailing lists, issue trackers and commit history, conference talks (LPC, KVM Forum, All
Expand Down Expand Up @@ -180,7 +193,7 @@ Comments here are longer than usual, on purpose. These rules are what make them
- **A decision, an open question or a follow-up is an issue.** "Left as it is", "not settled",
"not in this change" and "the consumer should change this" each get a GitHub issue in the repo
that owns it (spin-stack/machine or spin-stack/spin), with its evidence and how to settle it.
A comment, a PR body or `docs/log.md` cites the issue and never stands in for it: a comment is
A comment, a PR body or a log entry cites the issue and never stands in for it: a comment is
read only by whoever opens that file, and an issue is where the next person looks for work.
An issue closed because its proposal was decided against carries the label `rejected`, and a
finding that does not apply to this machine (an osv CVE, an upstream bug) carries `not-affected`,
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ slower (7.6 s against 455 ms, lab 44848049631, 2026-11-21), and nothing chooses
| [docs/boot-time.md](docs/boot-time.md) | where the two goal numbers stand, where their time goes, and what was kept, rejected and is open |
| [docs/measuring.md](docs/measuring.md) | how to measure a boot-time change: the steps, the rules a comparison follows, and the pitfalls |
| [docs/releases.md](docs/releases.md) | each release's numbers, measured on the bench |
| [docs/log.md](docs/log.md) | what was tried, when, why, and what it measured |
| [docs/log](docs/log) | what was tried, when, why, and what it measured: one file an entry, `spin-machine-dev docs log` |
| [docs/experiments](docs/experiments) | the rows of boot-time.md's tables, one record each, `spin-machine-dev docs tables` |
| [docs/cli.md](docs/cli.md) | `spin-machine-dev`: building, verifying, measuring, releasing |
| [docs/machine.md](docs/machine.md) | the definition: fixed slots, vmgenid, and the record a checkpoint is held to |
| [docs/migration.md](docs/migration.md) | one VM moved to another host, and why the CPU model decides it |
Expand Down
141 changes: 141 additions & 0 deletions cmd/spin-machine-dev/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// SPDX-License-Identifier: Apache-2.0

package main

import (
"fmt"
"os"
"path/filepath"

"github.com/spf13/cobra"

"github.com/spin-stack/machine/internal/docsrec"
)

// docsCommand renders the pages that the log's entries and the experiments' records add up to.
// The pages are never committed (spin-stack/machine#709).
func docsCommand() *cobra.Command {
c := &cobra.Command{
Use: "docs",
Short: "The log and boot-time.md's tables, rendered from docs/log and docs/experiments",
Long: `The log is one file an entry under docs/log, and the tables of docs/boot-time.md are one record
a row under docs/experiments. A pull request adds files of its own, so two in flight never touch
the same one. log and tables render the pages to stdout or --out; site writes both as web pages,
which pages.yml publishes beside the releases' page. Every verb refuses a file that does not parse.`,
}
c.AddCommand(docsLog(), docsTables(), docsSite())
return c
}

// readLog is the repository's log.
func readLog() (docsrec.Log, error) {
root, err := repo()
if err != nil {
return docsrec.Log{}, err
}
l, err := docsrec.ReadLog(filepath.Join(root, docsrec.LogDir))
if err != nil {
return docsrec.Log{}, couldNot(err)
}
return l, nil
}

// readRecords is the repository's experiments.
func readRecords() ([]docsrec.Record, error) {
root, err := repo()
if err != nil {
return nil, err
}
records, err := docsrec.ReadRecords(filepath.Join(root, docsrec.ExperimentsDir))
if err != nil {
return nil, couldNot(err)
}
return records, nil
}

// writePage writes text to out, or to stdout when out is empty.
func writePage(c *cobra.Command, out, text string) error {
if out == "" {
_, err := fmt.Fprint(c.OutOrStdout(), text)
return err
}
if err := os.WriteFile(out, []byte(text), 0o644); err != nil { //nolint:gosec // a page to read
return couldNot(fmt.Errorf("writing %s: %w", out, err))
}
return nil
}

func docsLog() *cobra.Command {
var out string
c := &cobra.Command{
Use: "log [--out FILE]",
Short: "The log as one page: docs/log's head, its entries by date under their weeks, and rework.md",
Args: cobra.NoArgs,
RunE: func(c *cobra.Command, _ []string) error {
l, err := readLog()
if err != nil {
return err
}
return writePage(c, out, l.Markdown())
},
}
c.Flags().StringVar(&out, "out", "", "the file to write; stdout when not given")
return c
}

func docsTables() *cobra.Command {
var out string
c := &cobra.Command{
Use: "tables [--out FILE]",
Short: "boot-time.md's tables, carried, measured and rejected, and open, from docs/experiments",
Args: cobra.NoArgs,
RunE: func(c *cobra.Command, _ []string) error {
records, err := readRecords()
if err != nil {
return err
}
return writePage(c, out, docsrec.TablesMarkdown(records))
},
}
c.Flags().StringVar(&out, "out", "", "the file to write; stdout when not given")
return c
}

func docsSite() *cobra.Command {
var out string
c := &cobra.Command{
Use: "site --out OUT",
Short: "Write the log and the tables as web pages, OUT/log.html and OUT/experiments.html",
Args: cobra.NoArgs,
RunE: func(c *cobra.Command, _ []string) error {
l, err := readLog()
if err != nil {
return err
}
records, err := readRecords()
if err != nil {
return err
}
if err := os.MkdirAll(out, 0o755); err != nil {
return couldNot(fmt.Errorf("making %s: %w", out, err))
}
for _, p := range []struct{ name, title, markdown string }{
{"log.html", "Log", l.Markdown()},
{"experiments.html", "Experiments", docsrec.TablesMarkdown(records)},
} {
html, err := docsrec.HTML(p.title, p.markdown)
if err != nil {
return couldNot(err)
}
if err := writePage(c, filepath.Join(out, p.name), html); err != nil {
return err
}
}
say(c, "wrote %s/log.html (%d entries) and %s/experiments.html (%d records)", out, len(l.Entries), out, len(records))
return nil
},
}
c.Flags().StringVar(&out, "out", "", "the directory the pages are written in")
_ = c.MarkFlagRequired("out")
return c
}
69 changes: 69 additions & 0 deletions cmd/spin-machine-dev/docs_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: Apache-2.0

package main

import (
"os"
"path/filepath"
"strings"
"testing"
)

// docsCheckout is a repository with a log of one entry and one record.
func docsCheckout(t *testing.T) string {
dir := checkout(t)
put(t, filepath.Join(dir, "docs/log/README.md"), "# Log\n", 0o644)
put(t, filepath.Join(dir, "docs/log/rework.md"), "## 2. Rework cycles\n", 0o644)
put(t, filepath.Join(dir, "docs/log/2026-11-23-an-entry.md"),
"---\ndate: \"2026-11-23\"\norder: 10\narea: lab\ntitle: an entry\n---\nIts prose.\n", 0o644)
put(t, filepath.Join(dir, "docs/experiments/an-idea.json"),
`{"decision": "rejected", "section": "login", "order": 10, "date": "2026-11-23", "change": "An idea", "result": "nothing", "shape": "spin", "source": "-"}`, 0o644)
return dir
}

func TestDocsRendersTheLogAndTheTables(t *testing.T) {
dir := docsCheckout(t)
stdout, stderr, status := verb(t, "docs", "log")
if status != 0 || !strings.Contains(stdout, "### Week 12: 2026-11-21 to 11-27\n\n**11-23 · lab · an entry.** Its prose.\n") {
t.Errorf("docs log: %d, %s%s", status, stdout, stderr)
}
out := filepath.Join(t.TempDir(), "tables.md")
if _, stderr, status := verb(t, "docs", "tables", "--out", out); status != 0 {
t.Fatalf("docs tables: %d, %s", status, stderr)
}
if got := read(t, out); !strings.Contains(got, "### The login\n\n| Idea | Result | Shape | Source | Date |\n|---|---|---|---|---|\n| An idea | nothing | spin | - | 11-23 |\n") {
t.Errorf("docs tables wrote:\n%s", got)
}
site := filepath.Join(t.TempDir(), "site")
if _, stderr, status := verb(t, "docs", "site", "--out", site); status != 0 {
t.Fatalf("docs site: %d, %s", status, stderr)
}
if log := read(t, filepath.Join(site, "log.html")); !strings.Contains(log, "<strong>11-23 · lab · an entry.</strong> Its prose.") {
t.Errorf("log.html:\n%s", log)
}
if exp := read(t, filepath.Join(site, "experiments.html")); !strings.Contains(exp, "<td>An idea</td>") {
t.Errorf("experiments.html:\n%s", exp)
}
if err := os.Remove(filepath.Join(dir, "docs/log/rework.md")); err != nil {
t.Fatal(err)
}
if _, stderr, status := verb(t, "docs", "log"); status != 2 || !strings.Contains(stderr, "rework.md") {
t.Errorf("docs log without rework.md: %d, %s", status, stderr)
}
if _, stderr, status := verb(t, "docs", "site", "--out", site); status != 2 || !strings.Contains(stderr, "rework.md") {
t.Errorf("docs site without rework.md: %d, %s", status, stderr)
}
}

func TestDocsRefusesARecordThatDoesNotParse(t *testing.T) {
dir := docsCheckout(t)
put(t, filepath.Join(dir, "docs/experiments/kept.json"), `{"decision": "kept"}`, 0o644)
for _, args := range [][]string{{"docs", "tables"}, {"docs", "site", "--out", t.TempDir()}} {
if _, stderr, status := verb(t, args...); status != 2 || !strings.Contains(stderr, `kept.json: decision "kept"`) {
t.Errorf("%v: %d, %s", args, status, stderr)
}
}
if _, stderr, status := verb(t, "docs", "tables", "--out", filepath.Join(dir, "none", "t.md")); status != 2 {
t.Errorf("docs tables to a directory that is not there: %d, %s", status, stderr)
}
}
2 changes: 1 addition & 1 deletion cmd/spin-machine-dev/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func root() *cobra.Command {
shellCmd(), vsockCmd("/dev/vhost-vsock"), menuconfigCmd(), cleanCmd(),
outdatedCmd(), bumpCmd(), refreshCmd(),
releaseCmd(),
releasesCommand(),
releasesCommand(), docsCommand(),
osvCmd(), cvesCmd(),
patchedCmd(),
failedCmd(),
Expand Down
2 changes: 1 addition & 1 deletion cmd/spin-machine-dev/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func openRegression(ctx context.Context, c *cobra.Command, r lab.Record, worse [
body := r.Release + "'s " + strings.Join(worse, "; ") + " against " + r.Against.Release + ", " + where + ". " +
"Each interval is wholly above 0: slower, beyond noise. That is a regression by docs/releasing.md, " +
"\"Withdrawing a release\".\n\n" +
"At 20 boots a side about 1 in 40 such flags of a number is noise, and a cost docs/log.md records as accepted " +
"At 20 boots a side about 1 in 40 such flags of a number is noise, and a cost the log (docs/log) records as accepted " +
"(a correctness change) is no regression. Decide which, and either close this saying why, or withdraw the release:\n\n" +
"```\ngh workflow run withdraw.yml -R " + repo + " -f tag=" + r.Release + " -f reason=\"...\" -f issue=THIS\n```\n\n" +
"A measurement again, if the flag may be noise: `gh workflow run report.yml -R " + repo + " -f versions=" + r.Release + "`.\n\n" +
Expand Down
Loading