package artifacts import ( "context" "errors" "fmt" "strings" "gitea.maximumdirect.net/eric/narratio/internal/adapters/storage" ) var ( ErrCurrentCommitPointerMissing = errors.New("current commit pointer missing") ) type CurrentCommitPointerMissingError struct { Key string } func (e *CurrentCommitPointerMissingError) Error() string { return fmt.Sprintf("%s: %q; republish this session to establish committed remote state", ErrCurrentCommitPointerMissing, e.Key) } 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") } if store == nil { return nil, fmt.Errorf("object store is required") } pointerKey := S3CurrentCommitPointerKey(prefix) pointerExists, err := store.Exists(ctx, pointerKey) if err != nil { return nil, fmt.Errorf("check current commit pointer %q: %w", pointerKey, err) } if !pointerExists { return nil, &CurrentCommitPointerMissingError{Key: pointerKey} } return loadCommittedInventory(ctx, store, prefix, pointerKey, validation) }