Expose native session planning and artifact catalogs
This commit is contained in:
@@ -131,7 +131,7 @@ func (publishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("publish: build runtime artifact catalog: %w", err)
|
||||
}
|
||||
publishRules, err := resolvePublishRules(
|
||||
publishRules, err := PlanPublicationOutputs(
|
||||
runtimeCatalog,
|
||||
env.Config.PublicationOutputs(),
|
||||
env.SelectedArtifactKeys,
|
||||
|
||||
@@ -20,7 +20,8 @@ const (
|
||||
publishOutputUnselected publishOutputStatus = "unselected"
|
||||
)
|
||||
|
||||
type resolvedPublishRule struct {
|
||||
// PublicationAction describes a selected output mapping before remote publication.
|
||||
type PublicationAction struct {
|
||||
Source string
|
||||
Destination string
|
||||
Required bool
|
||||
@@ -52,7 +53,7 @@ type publishOutputPlan struct {
|
||||
func buildPublishOutputPlan(
|
||||
sessionPrefix string,
|
||||
runPrefix string,
|
||||
rules []resolvedPublishRule,
|
||||
rules []PublicationAction,
|
||||
discovered []discoveredPublishOutput,
|
||||
locks []artifacts.RemoteLock,
|
||||
prior *artifacts.RemoteCommitManifest,
|
||||
@@ -135,8 +136,8 @@ func buildPublishOutputPlan(
|
||||
return &publishOutputPlan{Outcomes: outcomes}, nil
|
||||
}
|
||||
|
||||
func normalizeResolvedPublishRules(rules []resolvedPublishRule) ([]resolvedPublishRule, error) {
|
||||
ordered := append([]resolvedPublishRule(nil), rules...)
|
||||
func normalizeResolvedPublishRules(rules []PublicationAction) ([]PublicationAction, error) {
|
||||
ordered := append([]PublicationAction(nil), rules...)
|
||||
sort.Slice(ordered, func(i, j int) bool { return ordered[i].Source < ordered[j].Source })
|
||||
seenSources := make(map[string]struct{}, len(ordered))
|
||||
configuredDestinations := make(map[string]string, len(ordered))
|
||||
@@ -156,7 +157,7 @@ func normalizeResolvedPublishRules(rules []resolvedPublishRule) ([]resolvedPubli
|
||||
return ordered, nil
|
||||
}
|
||||
|
||||
func validateResolvedPublishRule(rule resolvedPublishRule) error {
|
||||
func validateResolvedPublishRule(rule PublicationAction) error {
|
||||
if strings.TrimSpace(rule.Source) != rule.Source || rule.Source == "" {
|
||||
return fmt.Errorf("publish output source %q is not canonical", rule.Source)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func TestBuildPublishOutputPlanModelsEveryOutcome(t *testing.T) {
|
||||
publishPlanLock(t, "narratio.artifact.beta"),
|
||||
publishPlanLock(t, "narratio.artifact.gamma"),
|
||||
}
|
||||
rules := []resolvedPublishRule{
|
||||
rules := []PublicationAction{
|
||||
{Source: "narratio.artifact.gamma", Destination: "artifacts/gamma.md", Required: true, Selected: true},
|
||||
{Source: "narratio.artifact.alpha", Destination: "artifacts/alpha.md", Required: true, Selected: true},
|
||||
{Source: "narratio.artifact.epsilon", Destination: "artifacts/epsilon.md", Required: true, Selected: false},
|
||||
@@ -87,7 +87,7 @@ func TestBuildPublishOutputPlanRejectsAmbiguities(t *testing.T) {
|
||||
available := []discoveredPublishOutput{{Source: "narratio.artifact.alpha", LocalPath: "/workspace/alpha.md"}}
|
||||
tests := []struct {
|
||||
name string
|
||||
rules []resolvedPublishRule
|
||||
rules []PublicationAction
|
||||
discovered []discoveredPublishOutput
|
||||
locks []artifacts.RemoteLock
|
||||
prior *artifacts.RemoteCommitManifest
|
||||
@@ -95,7 +95,7 @@ func TestBuildPublishOutputPlanRejectsAmbiguities(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "duplicate configured source",
|
||||
rules: []resolvedPublishRule{
|
||||
rules: []PublicationAction{
|
||||
{Source: "narratio.artifact.alpha", Destination: "artifacts/a.md", Selected: true},
|
||||
{Source: "narratio.artifact.alpha", Destination: "artifacts/b.md", Selected: true},
|
||||
},
|
||||
@@ -104,7 +104,7 @@ func TestBuildPublishOutputPlanRejectsAmbiguities(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "configured destination collision",
|
||||
rules: []resolvedPublishRule{
|
||||
rules: []PublicationAction{
|
||||
{Source: "narratio.artifact.alpha", Destination: "artifacts/shared.md", Selected: true},
|
||||
{Source: "narratio.artifact.beta", Destination: "artifacts/shared.md", Selected: false},
|
||||
},
|
||||
@@ -113,7 +113,7 @@ func TestBuildPublishOutputPlanRejectsAmbiguities(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "ambiguous discovery",
|
||||
rules: []resolvedPublishRule{{Source: "narratio.artifact.alpha", Destination: "artifacts/a.md", Selected: true}},
|
||||
rules: []PublicationAction{{Source: "narratio.artifact.alpha", Destination: "artifacts/a.md", Selected: true}},
|
||||
discovered: []discoveredPublishOutput{
|
||||
{Source: "narratio.artifact.alpha", LocalPath: "/workspace/a.md"},
|
||||
{Source: "narratio.artifact.alpha", LocalPath: "/workspace/other.md"},
|
||||
@@ -122,7 +122,7 @@ func TestBuildPublishOutputPlanRejectsAmbiguities(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "duplicate prior source",
|
||||
rules: []resolvedPublishRule{{Source: "narratio.artifact.alpha", Destination: "artifacts/a.md", Selected: true}},
|
||||
rules: []PublicationAction{{Source: "narratio.artifact.alpha", Destination: "artifacts/a.md", Selected: true}},
|
||||
locks: []artifacts.RemoteLock{publishPlanLock(t, "narratio.artifact.alpha")},
|
||||
prior: publishPlanCommit(
|
||||
publishPlanDeclaration(sessionPrefix, "20260512T010203Z-11223344", "narratio.artifact.alpha", "artifacts/a.md"),
|
||||
@@ -145,7 +145,7 @@ func TestBuildPublishOutputPlanRejectsInvalidCarryAndEffectiveCollision(t *testi
|
||||
sessionPrefix := artifacts.S3SessionPrefix("dnd", "sample-campaign", "2026-05-03")
|
||||
runPrefix := artifacts.S3RunPrefix(sessionPrefix, "20260519T010203Z-a1b2c3d4")
|
||||
locked := publishPlanLock(t, "narratio.artifact.beta")
|
||||
rules := []resolvedPublishRule{
|
||||
rules := []PublicationAction{
|
||||
{Source: "narratio.artifact.alpha", Destination: "artifacts/shared.md", Required: true, Selected: true},
|
||||
{Source: "narratio.artifact.beta", Destination: "artifacts/new-beta.md", Required: true, Selected: true},
|
||||
}
|
||||
|
||||
@@ -14,12 +14,14 @@ import (
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
)
|
||||
|
||||
func resolvePublishRules(
|
||||
// PlanPublicationOutputs resolves output destinations and analysis selection
|
||||
// without reading payloads, acquiring locks, or predicting publication results.
|
||||
func PlanPublicationOutputs(
|
||||
catalog *artifacts.ArtifactCatalog,
|
||||
rules []config.PublishOutputRule,
|
||||
selectedArtifactKeys []string,
|
||||
) ([]resolvedPublishRule, error) {
|
||||
out := make([]resolvedPublishRule, 0, len(rules))
|
||||
) ([]PublicationAction, error) {
|
||||
out := make([]PublicationAction, 0, len(rules))
|
||||
selectedSet := publishSelectedArtifactSet(selectedArtifactKeys)
|
||||
configuredOutputs := configuredOutputPathMapFromCatalog(catalog)
|
||||
extractionOutputs := extractionOutputSetFromCatalog(catalog)
|
||||
@@ -36,7 +38,7 @@ func resolvePublishRules(
|
||||
_, selected = selectedSet[key]
|
||||
}
|
||||
}
|
||||
out = append(out, resolvedPublishRule{Source: source, Destination: dest, Required: required, Selected: selected})
|
||||
out = append(out, PublicationAction{Source: source, Destination: dest, Required: required, Selected: selected})
|
||||
}
|
||||
return normalizeResolvedPublishRules(out)
|
||||
}
|
||||
@@ -45,7 +47,7 @@ func discoverPublishOutputs(
|
||||
paths artifacts.SessionPaths,
|
||||
m *manifest.Manifest,
|
||||
catalog *artifacts.ArtifactCatalog,
|
||||
rules []resolvedPublishRule,
|
||||
rules []PublicationAction,
|
||||
locks []artifacts.RemoteLock,
|
||||
) ([]discoveredPublishOutput, error) {
|
||||
lockSet := make(map[string]struct{}, len(locks))
|
||||
@@ -74,7 +76,7 @@ func discoverPublishOutputs(
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func readPublishOutputLocks(ctx context.Context, store storage.ObjectStore, sessionPrefix string, rules []resolvedPublishRule) ([]artifacts.RemoteLock, error) {
|
||||
func readPublishOutputLocks(ctx context.Context, store storage.ObjectStore, sessionPrefix string, rules []PublicationAction) ([]artifacts.RemoteLock, error) {
|
||||
locks := make([]artifacts.RemoteLock, 0)
|
||||
for _, rule := range rules {
|
||||
if !rule.Selected {
|
||||
@@ -91,7 +93,7 @@ func readPublishOutputLocks(ctx context.Context, store storage.ObjectStore, sess
|
||||
return locks, nil
|
||||
}
|
||||
|
||||
func publishRulesNeedPriorCommit(rules []resolvedPublishRule, locks []artifacts.RemoteLock) bool {
|
||||
func publishRulesNeedPriorCommit(rules []PublicationAction, locks []artifacts.RemoteLock) bool {
|
||||
locked := make(map[string]struct{}, len(locks))
|
||||
for _, lock := range locks {
|
||||
locked[lock.Source] = struct{}{}
|
||||
|
||||
Reference in New Issue
Block a user