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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
383 changes: 52 additions & 331 deletions AGENTS.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ the release that needed them.
## The log and the experiments

The log is one file an entry under `docs/log`, and the rows of `docs/boot-time.md`'s tables are one
record each under `docs/experiments` (AGENTS.md, "Experiments", says what each holds). A pull
record each under `docs/experiments` (`internal/docsrec` says what each holds). A pull
request adds files of its own, so two in flight do not conflict. The pages they make are rendered,
never committed (#709):

Expand Down
2 changes: 1 addition & 1 deletion docs/measuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ stand, where their time goes, and what was kept, rejected and is open are in
4. Measure it with the rules below. The commands are in `docs/cli.md`, "Measuring".
5. When it is decided, move the record: its `decision` becomes `carried` ("What the machine
carries") when it is kept, or `rejected` ("Measured and rejected") when it is not. Then write
its entry, dated and with its run, as a file of its own in `docs/log` (AGENTS.md says how).
its entry, dated and with its run, as a file of its own in `docs/log` (`internal/docsrec` says what it holds).

## Follow the rules of a measurement

Expand Down
4 changes: 2 additions & 2 deletions gates/docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

// Every log entry and experiment record parses, with its required fields, a decision and section
// that exist, valid dates, and the issues, pull requests and runs its text cites (AGENTS.md,
// "Experiments"). The pages they make are rendered, never committed (#709), so this is where a
// that exist, valid dates, and the issues, pull requests and runs its text cites (internal/docsrec
// says what each holds). The pages they make are rendered, never committed (#709), so this is where a
// broken file is found, not on the site after a merge.
func TestEveryLogEntryAndExperimentRecordParses(t *testing.T) {
l, err := docsrec.ReadLog(filepath.Join(root, docsrec.LogDir))
Expand Down
83 changes: 83 additions & 0 deletions gates/go_rules_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: Apache-2.0

package gates_test

import (
"go/ast"
"go/parser"
"go/token"
"io/fs"
"path/filepath"
"strings"
"testing"
)

// goFiles parses every Go file in the repository, comments kept, and hands each to check.
func goFiles(t *testing.T, check func(path string, fset *token.FileSet, f *ast.File)) {
t.Helper()
n := 0
err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
switch d.Name() {
case "_output", ".git", ".claude", ".cache", "node_modules":
return filepath.SkipDir
}
return nil
}
if !strings.HasSuffix(path, ".go") {
return nil
}
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, path, nil, parser.ParseComments)
if err != nil {
return err
}
n++
check(path, fset, f)
return nil
})
if err != nil {
t.Fatal(err)
}
if n < 200 {
t.Fatalf("read %d Go files: the check reads almost nothing", n)
}
}

func TestEveryGoFileCarriesTheLicence(t *testing.T) {
goFiles(t, func(path string, _ *token.FileSet, f *ast.File) {
if len(f.Comments) == 0 || f.Comments[0].List[0].Text != "// SPDX-License-Identifier: Apache-2.0" {
t.Errorf("%s: does not open with // SPDX-License-Identifier: Apache-2.0", path)
}
})
}

// A library returns its error; cmd/ decides what a failure means.
func TestNoLibraryPanicsOrExits(t *testing.T) {
goFiles(t, func(path string, fset *token.FileSet, f *ast.File) {
if f.Name.Name == "main" || strings.HasSuffix(path, "_test.go") {
return
}
ast.Inspect(f, func(n ast.Node) bool {
call, ok := n.(*ast.CallExpr)
if !ok {
return true
}
switch fn := call.Fun.(type) {
case *ast.Ident:
if fn.Name == "panic" {
t.Errorf("%s: panics; return the error", fset.Position(call.Pos()))
}
case *ast.SelectorExpr:
if pkg, ok := fn.X.(*ast.Ident); ok && (pkg.Name == "os" && fn.Sel.Name == "Exit" ||
pkg.Name == "log" && strings.HasPrefix(fn.Sel.Name, "Fatal")) {
t.Errorf("%s: %s.%s outside package main; return the error", fset.Position(call.Pos()), pkg.Name, fn.Sel.Name)
}
}
return true
})
})
}
15 changes: 15 additions & 0 deletions machine/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,9 @@ func TestValidateRefuses(t *testing.T) {
{"a descriptor set holding stdin", func(s *Spec) { s.FDSets = []FDSet{{ID: 1, FDs: []FD{{Num: 0}}}} }},
{"a monitor given a path and a descriptor", func(s *Spec) { s.Monitors = []Monitor{{Socket: "/qmp", FD: 3}} }},
{"a monitor given neither", func(s *Spec) { s.Monitors = []Monitor{{Socket: "/qmp"}, {}} }},
{"a monitor's socket path longer than sun_path holds", func(s *Spec) { s.Monitors = []Monitor{{Socket: "/" + strings.Repeat("a", 107)}} }},
{"a console's socket path longer than sun_path holds", func(s *Spec) { s.Console = "unix:/" + strings.Repeat("a", 107) + ",server=on,wait=off" }},
{"a multiplexed console's socket path longer than sun_path holds", func(s *Spec) { s.Console = "mon:unix:/" + strings.Repeat("a", 107) + ",server=on" }},
{"a monitor on stderr", func(s *Spec) { s.Monitors = []Monitor{{FD: 2}} }},
// A value from a fixed set is refused, not escaped: an escaped "qcow2,,x" is
// still not a format, and an unescaped one is a second option.
Expand Down Expand Up @@ -701,6 +704,18 @@ func TestValidateRefuses(t *testing.T) {
if err := s.validate(); err != nil {
t.Fatalf("a console by path does not validate: %v", err)
}

// The longest socket path sun_path holds, and a file console has no such limit.
s = spec(t)
s.Monitors = []Monitor{{Socket: "/" + strings.Repeat("a", 106)}}
s.Console = "unix:/" + strings.Repeat("a", 106) + ",server=on,wait=off"
if err := s.validate(); err != nil {
t.Fatalf("a 107-byte socket path does not validate: %v", err)
}
s.Console = "file:/" + strings.Repeat("a", 200)
if err := s.validate(); err != nil {
t.Fatalf("a long file console does not validate: %v", err)
}
s = spec(t)
s.FDSets = []FDSet{{ID: 1, FDs: []FD{{Num: 10}}}}
s.ConsoleFDSet = 1
Expand Down
6 changes: 6 additions & 0 deletions machine/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,12 @@ func (h *handover) monitors(s *Spec) (*net.UnixConn, error) {
if m.Socket == "" {
continue
}
// Here and not only in validate, which Start runs once the sockets are bound: Go's
// refusal of too long a path is a bare "invalid argument".
if err := socketFits(m.Socket); err != nil {
h.removeSockets()
return nil, err
}
f, err := listen(m.Socket)
if err != nil {
h.removeSockets()
Expand Down
10 changes: 10 additions & 0 deletions machine/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -912,3 +912,13 @@ func TestAMissingPasstFailsTheStart(t *testing.T) {
t.Fatalf("Start with no passt = %v, want an error naming it", err)
}
}

// Start binds a monitor's socket before anything else reads the Spec, so too long a path is
// refused there, by name, and not as bind's "invalid argument".
func TestStartRefusesASocketPathSunPathCannotHold(t *testing.T) {
long := "/" + strings.Repeat("a", 107)
_, err := startFake(t, t.Context(), "", Spec{Monitors: []Monitor{{Socket: long}}}, StartOptions{})
if err == nil || !strings.Contains(err.Error(), long) || strings.Contains(err.Error(), "invalid argument") {
t.Fatalf("Start with a 108-byte socket path: %v", err)
}
}
18 changes: 18 additions & 0 deletions machine/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ func (m Monitor) validate() error {
case m.FD != 0 && m.FD < 3:
return fmt.Errorf("a monitor descriptor of %d is stdin, stdout or stderr", m.FD)
}
return socketFits(m.Socket)
}

// maxSocketPath is the longest path a Unix socket is bound or reached at: sun_path is 108 bytes,
// the NUL that ends the path among them. Too long a path was refused only once QEMU ran, and a
// probe then read the guest as never answering, not the path (hit more than once, last in
// boot:restore-first, 2026-11-19).
const maxSocketPath = 107

func socketFits(path string) error {
if len(path) > maxSocketPath {
return fmt.Errorf("socket %s is %d bytes, and a Unix socket's path holds %d", path, len(path), maxSocketPath)
}
return nil
}

Expand Down Expand Up @@ -466,6 +479,11 @@ func (s Spec) validate() error {
switch {
case s.ConsoleFDSet != 0 && s.Console != "":
return errors.New("a console given both as a chardev and as a descriptor set")
case strings.HasPrefix(strings.TrimPrefix(s.Console, "mon:"), "unix:"):
path, _, _ := strings.Cut(strings.TrimPrefix(strings.TrimPrefix(s.Console, "mon:"), "unix:"), ",")
if err := socketFits(path); err != nil {
return fmt.Errorf("console: %w", err)
}
case s.ConsoleFDSet != 0 && !sets[s.ConsoleFDSet]:
return fmt.Errorf("the console is descriptor set %d, which Spec.FDSets does not have", s.ConsoleFDSet)
case s.KVMFDSet != 0 && s.Accel != "" && s.Accel != "kvm":
Expand Down