Author SHA1 Message Date
terminarandClaude Opus 5.5 c1c0b8a116 solutions: load a catalog without a disk (LoadFSWith, LoadBigPictureFS); skip *.conflict.md
LoadFSWith reads the Big Picture from its own fs.FS, so a catalog can be
embedded -- the web wizard runs the engine in the browser as WebAssembly.
The knowledge index leaves out wiki-sync conflict copies (*.conflict.md).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 16:20:21 +01:00
terminarandClaude Opus 5.5 c8a219a84b solutions: exit 3 is "interrupted", "not found" moves to 7
The family convention (docs/program-conventions.md) gives 3 to a
command stopped by SIGINT/SIGTERM (owner decision 2026-12-01 to unify).
A cancelled context now exits 3; yetano-solutions also stops on SIGTERM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 13:21:10 +01:00
7 changed files with 94 additions and 13 deletions

No files matched your search

+13 -4
View File
@@ -2,7 +2,9 @@ package catalog
import (
"fmt"
"io/fs"
"os"
"path"
"path/filepath"
"sort"
"strings"
@@ -15,7 +17,8 @@ import (
// here they are decoded leniently and only the fields the guide uses are
// kept.
type BigPicture struct {
Dir string `json:"-"`
Dir string `json:"-"`
fsys fs.FS
Title string `json:"title"`
WebPath string `json:"webPath"` // "map/"
Topics map[string]*BPTopic `json:"topics"`
@@ -89,8 +92,14 @@ type BPInterface struct {
// LoadBigPicture reads dir/manifest.yaml and the files it names.
func LoadBigPicture(dir string) (*BigPicture, error) {
return LoadBigPictureFS(os.DirFS(dir), dir)
}
// LoadBigPictureFS reads manifest.yaml and the files it names from fsys
// (an embedded copy, e.g. in the browser); dir only names it in messages.
func LoadBigPictureFS(fsys fs.FS, dir string) (*BigPicture, error) {
bp := &BigPicture{
Dir: dir, WebPath: "map/",
Dir: dir, fsys: fsys, WebPath: "map/",
Topics: map[string]*BPTopic{}, Stories: map[string]*BPStory{},
Products: map[string]*BPProduct{}, Interfaces: map[string]BPInterface{},
}
@@ -157,7 +166,7 @@ func (bp *BigPicture) read(name string, v any) error {
if name == "" {
return fmt.Errorf("big picture: manifest names no file")
}
b, err := os.ReadFile(filepath.Join(bp.Dir, name))
b, err := fs.ReadFile(bp.fsys, path.Clean(filepath.ToSlash(name)))
if err != nil {
return fmt.Errorf("big picture: %w", err)
}
@@ -172,7 +181,7 @@ func (bp *BigPicture) read(name string, v any) error {
}
func (bp *BigPicture) readDir(sub string, fn func(string) error) error {
ents, err := os.ReadDir(filepath.Join(bp.Dir, sub))
ents, err := fs.ReadDir(bp.fsys, path.Clean(filepath.ToSlash(sub)))
if err != nil {
return fmt.Errorf("big picture: %w", err)
}
+17 -1
View File
@@ -156,6 +156,14 @@ func Load(root string) (*Catalog, error) {
// LoadFS reads a catalog from fsys (root is only used for messages and
// to find the Big Picture relative to it, when fsys is a directory).
func LoadFS(fsys fs.FS, root string) (*Catalog, error) {
return LoadFSWith(fsys, root, nil)
}
// LoadFSWith is LoadFS with the Big Picture read from bigPicture instead
// of the directory catalog.yaml names -- for a catalog without a disk
// (embedded in a program, or in the browser as WebAssembly). nil: as
// LoadFS.
func LoadFSWith(fsys fs.FS, root string, bigPicture fs.FS) (*Catalog, error) {
c := &Catalog{
Root: root,
Capabilities: map[string]*Capability{},
@@ -206,7 +214,15 @@ func LoadFS(fsys fs.FS, root string) (*Catalog, error) {
if !sawRoot {
c.add("error", "catalog.yaml", 0, "", "no-root", "no Catalog manifest (catalog.yaml) found")
}
if c.Spec.BigPicture != "" {
if c.Spec.BigPicture != "" && bigPicture != nil {
bp, err := LoadBigPictureFS(bigPicture, c.Spec.BigPicture)
if err != nil {
c.add("error", "catalog.yaml", 0, "", "bigpicture", err.Error())
} else {
c.BigPicture = bp
c.Files = append(c.Files, bp.Files...)
}
} else if c.Spec.BigPicture != "" {
bpDir := c.Spec.BigPicture
if !filepath.IsAbs(bpDir) {
bpDir = filepath.Join(root, bpDir)
+27
View File
@@ -0,0 +1,27 @@
package catalog
import (
"os"
"reflect"
"testing"
)
// A catalog without a disk (embedded, or in the browser) loads the Big
// Picture from its own fs.FS and gives the same catalog as from disk.
func TestLoadFSWith(t *testing.T) {
disk, err := Load("../engine/testdata/cat")
if err != nil {
t.Fatal(err)
}
// "/nonexistent" as root: nothing may be read from disk
emb, err := LoadFSWith(os.DirFS("../engine/testdata/cat"), "/nonexistent", os.DirFS("../engine/testdata/bp"))
if err != nil {
t.Fatal(err)
}
if emb.BigPicture == nil || len(emb.BigPicture.Products) == 0 {
t.Fatal("no Big Picture")
}
if !reflect.DeepEqual(SortedIDs(disk.BigPicture.Products), SortedIDs(emb.BigPicture.Products)) || disk.Hash() != emb.Hash() {
t.Fatalf("embedded catalog differs: %v / %v", disk.Hash(), emb.Hash())
}
}
+13 -6
View File
@@ -23,13 +23,17 @@ import (
"yetano.dev/yetano/core/solutions/store"
)
// Exit codes, the same as yet's (yet/internal/cliutil).
// Exit codes, the same as yet's (yet/internal/cliutil). 0-3 are the
// family-wide ones (docs/program-conventions.md in the meta-repo); 3 is
// "interrupted" there, so "not found" is 7 (owner decision 2026-12-01,
// it was 3 up to solutions/v0.1.0).
const (
ExitOK = 0
ExitError = 1
ExitUsage = 2
ExitNotFound = 3
ExitConflict = 4
ExitOK = 0
ExitError = 1
ExitUsage = 2
ExitInterrupted = 3 // stopped by SIGINT/SIGTERM (the context was cancelled)
ExitConflict = 4
ExitNotFound = 7
)
// Env is what the embedding program provides.
@@ -103,6 +107,9 @@ func Run(ctx context.Context, args []string, env Env) int {
code = ee.code
}
switch {
case ctx.Err() != nil:
// whatever failed, it failed because we were told to stop
code = ExitInterrupted
case errors.Is(err, engine.ErrNotFound), errors.Is(err, store.ErrNotFound):
code = ExitNotFound
case errors.Is(err, engine.ErrModified):
+19
View File
@@ -147,3 +147,22 @@ func TestInteractiveWizard(t *testing.T) {
t.Error("export did not write the configuration")
}
}
// Ctrl-C: a cancelled context is exit 3, the family-wide "interrupted"
// (docs/program-conventions.md); "not found" moved to 7 for it.
func TestInterrupted(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
var out, errb bytes.Buffer
code := Run(ctx, []string{"solution", "show", "nope"}, Env{
Stdin: strings.NewReader(""), Stdout: &out, Stderr: &errb,
Program: "yetano-solutions", StoreDir: t.TempDir(), Catalogs: []string{"../engine/testdata/cat"},
Getenv: func(string) string { return "" },
})
if code != ExitInterrupted || ExitInterrupted != 3 || ExitNotFound != 7 {
t.Fatalf("cancelled: exit %d (%s)", code, errb.String())
}
if r := run(t, t.TempDir(), "solution", "show", "nope"); r.code != 7 {
t.Fatalf("not found: exit %d", r.code)
}
}
+2 -1
View File
@@ -10,6 +10,7 @@ import (
"context"
"os"
"os/signal"
"syscall"
"yetano.dev/yetano/core"
"yetano.dev/yetano/core/paths"
@@ -19,7 +20,7 @@ import (
var version = "dev"
func main() {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
// instances, sessions and presets are user data: core/paths' data
// directory (nothing is created until something is saved)
+3 -1
View File
@@ -224,7 +224,9 @@ func (ix *Index) manuals() {
if d.IsDir() && strings.HasPrefix(d.Name(), ".") {
return fs.SkipDir
}
if !d.IsDir() && strings.HasSuffix(p, ".md") {
// *.conflict.md: a wiki-sync conflict copy (meta-repo
// AGENTS.md), never documentation of its own
if !d.IsDir() && strings.HasSuffix(p, ".md") && !strings.HasSuffix(p, ".conflict.md") {
files = append(files, rel)
}
return nil