#7671 fences graph workspaces in cmd/bd: command admission, the store factories and the other CLI paths refuse one, and #7722 extends that fence to a .beads holding the graph-preview-format marker whatever its metadata says. But the public library opens (beads.OpenBestAvailable, OpenBestAvailableWith, OpenFromConfig, OpenGated) and the Dolt store's metadata-driven constructors (NewFromConfig, NewFromConfigWithOptions, NewFromConfigWithCLIOptions) still opened either kind of graph workspace as an Issue store and ran Issue schema migrations into the graph database (or, with no metadata beside the marker, created an Issue database inside the graph workspace). - Move the typed refusal into internal/configfile (UnsupportedWorkspaceFormatError with BeadsDir, GraphMode and FormatMarker; CheckWorkspaceFormat; GraphFormatMarkerFile; HasGraphFormatMarker) with byte-identical text and hints for both the graph_mode and the marker refusal, and move cmd/bd's discovery pre-checks there as LoadAndCheckWorkspaceFormat and CheckDiscoveredWorkspaceFormat (LoadForDiscovery, which never migrates a legacy config.json; unreadable metadata beside the marker is refused as the marker's format). cmd/bd's checkWorkspaceFormat, loadAndCheckWorkspaceFormat, hasGraphFormatMarker and checkDiscoveredWorkspaceFormat become thin delegates, so the CLI keeps its behaviour (exit 16 with the same hints) and every caller of them is unchanged; bootstrap's ancestor walk builds the configfile type. - Every public metadata-driven open runs CheckDiscoveredWorkspaceFormat as its first statement: before OpenGated takes its gates and before OpenBestAvailableWith's Load can migrate config.json. A refused open leaves the workspace byte-identical. The type is exported as beads.UnsupportedWorkspaceFormatError. - The Dolt constructors run CheckDiscoveredWorkspaceFormat before configfile.Load, so a graph workspace marked only by a legacy config.json, or by the marker beside stripped, missing or unparseable metadata, is refused before Load can migrate it into metadata.json (and drop graph_* keys this build does not know). requireDoltBackend re-checks the loaded config as a backstop, so they also refuse before resolving a server or writing a port file or Dolt root. Tests: configfile unit tests for both refusals (exact marker text and hint, graph_mode winning over the marker, unparseable metadata with and without the marker); the public opens and the three Dolt constructors against graph_mode workspaces and against marker-only, stripped (metadata.json and legacy config.json), server, explicit dependency and unparseable-metadata marker workspaces, each refused with the typed error and the workspace left unchanged. Agent-Signature: claude-code-claude-opus-5-5-unknown-reasoning on behalf of Julian Knutsen Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
77 lines
3.4 KiB
Go
77 lines
3.4 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/steveyegge/beads/internal/configfile"
|
|
)
|
|
|
|
// ExitUnsupportedWorkspaceFormat is the exit code for a command refused
|
|
// because its workspace declares a format this bd build cannot open: a
|
|
// metadata.json graph_mode other than "dependency", or a graph workspace
|
|
// format marker (configfile.GraphFormatMarkerFile). Stable so a wrapper can
|
|
// tell "this workspace needs a different bd build" apart from a generic
|
|
// failure (1) without grepping stderr.
|
|
//
|
|
// 16 because 13, 14 and 15 are taken (ExitGuardMismatch, ExitMigrationFrozen,
|
|
// ExitHomeDirRefused). Like ExitHomeDirRefused, it is not part of protocol v0
|
|
// §E3, which freezes 10/11/12/130.
|
|
const ExitUnsupportedWorkspaceFormat = 16
|
|
|
|
// checkWorkspaceFormat refuses metadata whose graph_mode marker names any
|
|
// model but the default, and a beadsDir holding the graph format marker file,
|
|
// with a *configfile.UnsupportedWorkspaceFormatError. It is
|
|
// configfile.CheckWorkspaceFormat, the check the public beads package and the
|
|
// Dolt store's metadata-driven opens apply too, so the CLI and a library
|
|
// caller refuse the same workspaces with the same error.
|
|
func checkWorkspaceFormat(cfg *configfile.Config, beadsDir string) error {
|
|
return configfile.CheckWorkspaceFormat(cfg, beadsDir)
|
|
}
|
|
|
|
// loadAndCheckWorkspaceFormat reads beadsDir's discovery metadata without
|
|
// migrating it and refuses a workspace in a format this build cannot open,
|
|
// including unreadable metadata beside the graph format marker. It is
|
|
// configfile.LoadAndCheckWorkspaceFormat.
|
|
func loadAndCheckWorkspaceFormat(beadsDir string) (*configfile.Config, error) {
|
|
return configfile.LoadAndCheckWorkspaceFormat(beadsDir)
|
|
}
|
|
|
|
// hasGraphFormatMarker reports whether anything exists at beadsDir's graph
|
|
// format marker path (configfile.HasGraphFormatMarker).
|
|
func hasGraphFormatMarker(beadsDir string) bool {
|
|
return configfile.HasGraphFormatMarker(beadsDir)
|
|
}
|
|
|
|
// checkDiscoveredWorkspaceFormat runs checkWorkspaceFormat on beadsDir's
|
|
// metadata as LoadForDiscovery reads it, which never rewrites the workspace.
|
|
// A path that opens or initializes a workspace without passing through command
|
|
// admission runs it first: configfile.Load would otherwise migrate a legacy
|
|
// config.json into metadata.json before the format check could refuse it.
|
|
// Metadata that does not load is left to the caller's own load to report,
|
|
// unless the graph format marker sits beside it (loadAndCheckWorkspaceFormat).
|
|
// It is configfile.CheckDiscoveredWorkspaceFormat, the pre-check the public
|
|
// beads package's opens run too.
|
|
func checkDiscoveredWorkspaceFormat(beadsDir string) error {
|
|
return configfile.CheckDiscoveredWorkspaceFormat(beadsDir)
|
|
}
|
|
|
|
func isUnsupportedWorkspaceFormat(err error) bool {
|
|
var formatErr *configfile.UnsupportedWorkspaceFormatError
|
|
return errors.As(err, &formatErr)
|
|
}
|
|
|
|
// handleWorkspaceGuardError renders a workspace admission refusal from
|
|
// guardLegacyUpgradeWorkspace. An unsupported workspace format gets a hint and
|
|
// ExitUnsupportedWorkspaceFormat; every other refusal keeps HandleError's
|
|
// rendering and exit 1.
|
|
func handleWorkspaceGuardError(err error) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
var formatErr *configfile.UnsupportedWorkspaceFormatError
|
|
if !errors.As(err, &formatErr) {
|
|
return HandleError("%v", err)
|
|
}
|
|
_ = HandleErrorWithHint(formatErr.Error(), formatErr.Hint())
|
|
return &exitError{Code: ExitUnsupportedWorkspaceFormat}
|
|
}
|