2026-05-23 13:56:53 +00:00
|
|
|
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-05-23 13:56:53 +00:00
|
|
|
)
|
|
|
|
|
|
2026-09-02 13:47:20 +00:00
|
|
|
type CurrentCommitPointerMissingError struct {
|
2026-05-23 13:56:53 +00:00
|
|
|
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-05-23 13:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
2026-09-02 13:47:20 +00:00
|
|
|
func (e *CurrentCommitPointerMissingError) Unwrap() error {
|
|
|
|
|
return ErrCurrentCommitPointerMissing
|
2026-05-23 13:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type CurrentState struct {
|
2026-12-02 16:24:33 +00:00
|
|
|
SessionPrefix string
|
|
|
|
|
CurrentPointerKey string
|
|
|
|
|
RunID string
|
|
|
|
|
Commit *RemoteCommitManifest
|
|
|
|
|
Pointer *CurrentCommitPointer
|
2026-05-23 13:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type CurrentStateValidation struct {
|
|
|
|
|
ExpectedCampaign string
|
|
|
|
|
ExpectedSessionID string
|
|
|
|
|
ExpectedRunID string
|
|
|
|
|
}
|
|
|
|
|
|
2026-12-02 15:44:52 +00:00
|
|
|
// 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,
|
2026-05-23 13:56:53 +00:00
|
|
|
) (*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-05-23 13:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
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-05-23 13:56:53 +00:00
|
|
|
}
|
2026-09-02 13:47:20 +00:00
|
|
|
if !pointerExists {
|
|
|
|
|
return nil, &CurrentCommitPointerMissingError{Key: pointerKey}
|
2026-05-23 13:56:53 +00:00
|
|
|
}
|
2026-12-02 15:44:52 +00:00
|
|
|
return loadCommittedInventory(ctx, store, prefix, pointerKey, validation)
|
2026-05-23 13:56:53 +00:00
|
|
|
}
|