Files
narratio/internal/artifacts/current_state.go

68 lines
1.7 KiB
Go
Raw Normal View History

package artifacts
import (
"context"
"errors"
"fmt"
"strings"
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
)
var (
2026-09-02 13:47:20 +00:00
ErrCurrentCommitPointerMissing = errors.New("current commit pointer missing")
)
2026-09-02 13:47:20 +00:00
type CurrentCommitPointerMissingError struct {
Key string
}
2026-09-02 13:47:20 +00:00
func (e *CurrentCommitPointerMissingError) Error() string {
return fmt.Sprintf("%s: %q; republish this session to establish committed remote state", ErrCurrentCommitPointerMissing, e.Key)
}
2026-09-02 13:47:20 +00:00
func (e *CurrentCommitPointerMissingError) Unwrap() error {
return ErrCurrentCommitPointerMissing
}
type CurrentState struct {
SessionPrefix string
CurrentPointerKey string
RunID string
Commit *RemoteCommitManifest
Pointer *CurrentCommitPointer
}
type CurrentStateValidation struct {
ExpectedCampaign string
ExpectedSessionID string
ExpectedRunID string
}
// LoadCurrentInventory reads the selected publication identity and declarations
// without fetching an execution snapshot.
func LoadCurrentInventory(
ctx context.Context,
store storage.ObjectStore,
sessionPrefix string,
validation CurrentStateValidation,
) (*CurrentState, error) {
prefix := strings.TrimSpace(sessionPrefix)
if prefix == "" {
return nil, fmt.Errorf("session prefix is required")
}
2026-08-10 19:47:12 +00:00
if store == nil {
return nil, fmt.Errorf("object store is required")
}
2026-08-10 19:47:12 +00:00
pointerKey := S3CurrentCommitPointerKey(prefix)
pointerExists, err := store.Exists(ctx, pointerKey)
if err != nil {
return nil, fmt.Errorf("check current commit pointer %q: %w", pointerKey, err)
}
2026-09-02 13:47:20 +00:00
if !pointerExists {
return nil, &CurrentCommitPointerMissingError{Key: pointerKey}
}
return loadCommittedInventory(ctx, store, prefix, pointerKey, validation)
}