Expose native session planning and artifact catalogs
This commit is contained in:
@@ -465,6 +465,17 @@ selection retains its existing analyze/publish consumer and family rules.
|
|||||||
|
|
||||||
## Stage 11: Expose planning and the configured artifact catalog
|
## Stage 11: Expose planning and the configured artifact catalog
|
||||||
|
|
||||||
|
**Completed.** Native session-plan declarations share run selection/checking and
|
||||||
|
one read-only decision builder, including analysis prerequisites/reuse and
|
||||||
|
publication mappings from the same pure publication owner used by execution.
|
||||||
|
Native artifacts-list reports built-in, configured, and extraction sources,
|
||||||
|
producers, dependencies, and selected-party family provenance without requiring
|
||||||
|
a session. Acquisition retains one derived catalog; removed config-artifacts and
|
||||||
|
its custom inspection dependency. Native planning/catalog, existing planning and
|
||||||
|
manifest-cloning, explicit-roster immutability, and bounded composition checks
|
||||||
|
pass. Configuration, stage, and artifact suites, builds, and diff checks pass
|
||||||
|
with Go 1.27.4. Remaining unrelated command conversions stay scheduled below.
|
||||||
|
|
||||||
Read: `internal/app/plan.go`, `analyze_artifacts.go`, old config artifact listing,
|
Read: `internal/app/plan.go`, `analyze_artifacts.go`, old config artifact listing,
|
||||||
and the shared domain products from Stages 4–6.
|
and the shared domain products from Stages 4–6.
|
||||||
|
|
||||||
|
|||||||
79
internal/app/artifact_catalog_command.go
Normal file
79
internal/app/artifact_catalog_command.go
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"sort"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
|
"go.maximumdirect.net/commandkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
type artifactCatalogReport struct {
|
||||||
|
Artifacts []artifactDefinitionReport `json:"artifacts"`
|
||||||
|
}
|
||||||
|
type artifactDefinitionReport struct {
|
||||||
|
Key string `json:"key,omitempty"`
|
||||||
|
Source string `json:"source"`
|
||||||
|
Producer string `json:"producer"`
|
||||||
|
Output string `json:"output,omitempty"`
|
||||||
|
Enabled *bool `json:"enabled,omitempty"`
|
||||||
|
Dependencies []string `json:"dependencies"`
|
||||||
|
Family string `json:"family,omitempty"`
|
||||||
|
CharacterID string `json:"character_id,omitempty"`
|
||||||
|
DefinitionSources []string `json:"definition_sources,omitempty"`
|
||||||
|
FamilySources []string `json:"family_sources,omitempty"`
|
||||||
|
PartySource string `json:"party_source,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func artifactCatalogCommand(deps commandDependencies) commandkit.Command {
|
||||||
|
common := newConfigurationFlags(func(input *configurationSelection) *configurationSelection { return input })
|
||||||
|
return commandkit.NewCommand(commandkit.CommandSpec[configurationSelection]{
|
||||||
|
Name: "list", Summary: "List artifact definitions for the selected pipeline and party.",
|
||||||
|
Flags: []commandkit.Flag[configurationSelection]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.PartyFile, common.SecretsDir},
|
||||||
|
CheckInput: checkConfigurationSelection,
|
||||||
|
Run: func(invocation commandkit.Invocation, input configurationSelection) commandkit.Outcome {
|
||||||
|
report, err := loadArtifactCatalogReport(invocation.Context, input, deps)
|
||||||
|
if report != nil {
|
||||||
|
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
||||||
|
}
|
||||||
|
return operationOutcome(err)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadArtifactCatalogReport(ctx context.Context, input configurationSelection, deps commandDependencies) (report *artifactCatalogReport, err error) {
|
||||||
|
deps = normalizeCommandDependencies(deps)
|
||||||
|
deps.secretsBootstrap = &secretsBootstrap{}
|
||||||
|
acquired := newConfigurationAcquisition(input, deps)
|
||||||
|
defer func() { err = errors.Join(err, acquired.Close()) }()
|
||||||
|
catalog, err := acquired.Catalog(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
configured := artifacts.ConfiguredArtifactDefinitions(catalog.Artifacts)
|
||||||
|
effective, err := artifacts.ResolveEffectiveArtifactSet(configured, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
runtime, err := artifacts.BootstrapRuntimeCatalog(configured, effective, artifacts.ExtractionDefinitionsFromConfig(acquired.pipeline.Notarius))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
report = &artifactCatalogReport{Artifacts: []artifactDefinitionReport{}}
|
||||||
|
for _, spec := range artifacts.RuntimeTranscriptArtifacts() {
|
||||||
|
report.Artifacts = append(report.Artifacts, artifactDefinitionReport{Source: spec.SourceID, Producer: spec.ProducerStage, Output: spec.CanonicalRelPath, Dependencies: []string{}})
|
||||||
|
}
|
||||||
|
if bounds, ok := runtime.Lookup(artifacts.ArtifactBoundsSession); ok {
|
||||||
|
report.Artifacts = append(report.Artifacts, artifactDefinitionReport{Source: bounds.SourceID, Producer: bounds.ProducerStage, Output: bounds.CanonicalRelPath, Dependencies: []string{}})
|
||||||
|
}
|
||||||
|
for _, record := range catalog.Records {
|
||||||
|
report.Artifacts = append(report.Artifacts, artifactDefinitionReport{Key: record.Key, Source: record.SourceID, Producer: "analyze", Output: record.OutputPath, Enabled: &record.Enabled, Dependencies: append([]string{}, record.Dependencies...), Family: record.FamilyKey, CharacterID: record.CharacterID, DefinitionSources: record.DefinitionSources, FamilySources: record.FamilySources, PartySource: record.PartySource})
|
||||||
|
}
|
||||||
|
for _, entry := range runtime.ListExtraction() {
|
||||||
|
enabled := acquired.pipeline.Notarius != nil && acquired.pipeline.Notarius.Enabled
|
||||||
|
report.Artifacts = append(report.Artifacts, artifactDefinitionReport{Key: entry.ExtractionKey, Source: entry.SourceID, Producer: entry.ProducerStage, Enabled: &enabled, Dependencies: []string{}})
|
||||||
|
}
|
||||||
|
sort.Slice(report.Artifacts, func(i, j int) bool { return report.Artifacts[i].Source < report.Artifacts[j].Source })
|
||||||
|
return report, nil
|
||||||
|
}
|
||||||
@@ -18,8 +18,8 @@ func newApplication(deps commandDependencies, executor pipelineExecutor) (*comma
|
|||||||
commandkit.Identity{Name: "narratio", Version: buildinfo.Version},
|
commandkit.Identity{Name: "narratio", Version: buildinfo.Version},
|
||||||
configurationCommand(deps),
|
configurationCommand(deps),
|
||||||
executionCommand("run", "Execute a session pipeline.", false, deps, executor),
|
executionCommand("run", "Execute a session pipeline.", false, deps, executor),
|
||||||
commandkit.Group("artifacts", "Inspect and regenerate configured artifacts.", executionCommand("regenerate", "Rebuild extraction and analysis artifacts.", true, deps, executor)),
|
commandkit.Group("artifacts", "Inspect and regenerate configured artifacts.", artifactCatalogCommand(deps), executionCommand("regenerate", "Rebuild extraction and analysis artifacts.", true, deps, executor)),
|
||||||
commandkit.Group("session", "Manage and inspect sessions."),
|
commandkit.Group("session", "Manage and inspect sessions.", sessionPlanCommand(deps)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,201 +3,105 @@ package app
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"encoding/json"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
|
"go.maximumdirect.net/commandkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
const artifactCatalogHeader = "key\tsource\tdefinitions\tenabled\toutput\tdependencies\tfamily\tcharacter\tfamily_source\tparty_source\n"
|
func catalogReportForTest(t *testing.T, args []string) *artifactCatalogReport {
|
||||||
|
t.Helper()
|
||||||
|
output := nativeInspectionForTest(t, append([]string{"artifacts", "list", "--format", "json"}, args...))
|
||||||
|
var report artifactCatalogReport
|
||||||
|
if err := json.Unmarshal([]byte(output), &report); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
return &report
|
||||||
|
}
|
||||||
|
|
||||||
func TestConfigArtifactsReportsOrdinaryCatalogWithoutCampaign(t *testing.T) {
|
func TestArtifactCatalogCommandWithoutCampaignPreservesDependencies(t *testing.T) {
|
||||||
dir := t.TempDir()
|
dir := t.TempDir()
|
||||||
pipelinePath := filepath.Join(dir, "pipeline.yml")
|
pipeline := filepath.Join(dir, "pipeline.yml")
|
||||||
mustWriteTestFile(t, pipelinePath, `workspace:
|
mustWriteTestFile(t, pipeline, `workspace:
|
||||||
root: `+filepath.Join(dir, "workspace")+`
|
root: `+filepath.Join(dir, "workspace")+`
|
||||||
whisperx:
|
whisperx: {transcribe_url: https://transcription.example.test/transcribe}
|
||||||
transcribe_url: https://transcription.example.com/transcribe
|
|
||||||
scriptorium:
|
scriptorium:
|
||||||
binary: scriptorium
|
|
||||||
artifacts:
|
artifacts:
|
||||||
zeta:
|
zeta: {enabled: false, output_path: artifacts/zeta.md}
|
||||||
enabled: false
|
|
||||||
output_path: artifacts/zeta.md
|
|
||||||
alpha:
|
alpha:
|
||||||
enabled: false
|
enabled: false
|
||||||
output_path: artifacts/alpha.md
|
output_path: artifacts/alpha.md
|
||||||
inputs:
|
inputs:
|
||||||
upstream: {source: narratio.artifact.zeta, required: true}
|
upstream: {source: narratio.artifact.zeta, required: true}
|
||||||
`)
|
`)
|
||||||
|
report := catalogReportForTest(t, []string{"--config", pipeline})
|
||||||
var out bytes.Buffer
|
found := map[string]artifactDefinitionReport{}
|
||||||
if err := ConfigArtifacts(context.Background(), []string{"--config", pipelinePath}, &out); err != nil {
|
for _, entry := range report.Artifacts {
|
||||||
t.Fatalf("ConfigArtifacts() error = %v", err)
|
found[entry.Source] = entry
|
||||||
}
|
}
|
||||||
lines := strings.Split(strings.TrimSuffix(out.String(), "\n"), "\n")
|
alpha := found["narratio.artifact.alpha"]
|
||||||
if len(lines) != 3 || !strings.HasPrefix(lines[1], "alpha\t") || !strings.HasPrefix(lines[2], "zeta\t") {
|
if alpha.Producer != "analyze" || alpha.Enabled == nil || *alpha.Enabled || !reflect.DeepEqual(alpha.Dependencies, []string{"zeta"}) || !reflect.DeepEqual(alpha.DefinitionSources, []string{pipeline}) {
|
||||||
t.Fatalf("catalog order/output = %q", out.String())
|
t.Fatalf("alpha=%#v", alpha)
|
||||||
}
|
}
|
||||||
alpha := strings.Split(lines[1], "\t")
|
if found["narratio.transcript.base"].Producer != "merge" {
|
||||||
if len(alpha) != 10 {
|
t.Fatal("catalog omitted built-in producer")
|
||||||
t.Fatalf("alpha fields = %#v", alpha)
|
|
||||||
}
|
}
|
||||||
if alpha[1] != "narratio.artifact.alpha" || alpha[2] != pipelinePath || alpha[3] != "false" || alpha[4] != "artifacts/alpha.md" || alpha[5] != "zeta" {
|
if _, err := os.Stat(filepath.Join(dir, "workspace")); !os.IsNotExist(err) {
|
||||||
t.Fatalf("alpha record = %#v", alpha)
|
t.Fatalf("listing created workspace: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConfigArtifactsEmptyCatalogWritesOnlyHeader(t *testing.T) {
|
func TestArtifactCatalogCommandUsesExplicitRosterAndNativeConfiguration(t *testing.T) {
|
||||||
dir := t.TempDir()
|
pipeline, _ := writeInspectionFamilyConfig(t)
|
||||||
pipelinePath := filepath.Join(dir, "pipeline.yml")
|
overlay := filepath.Join(filepath.Dir(pipeline), "overlays", "testing.yml")
|
||||||
mustWriteTestFile(t, pipelinePath, "workspace:\n root: "+filepath.Join(dir, "workspace")+"\nwhisperx:\n transcribe_url: https://transcription.example.com/transcribe\n")
|
mustWriteTestFile(t, overlay, "scriptorium:\n artifact_families:\n character_note:\n prompt_id: dnd.character_note.testing\n")
|
||||||
var out bytes.Buffer
|
roster := filepath.Join(t.TempDir(), "selected.yml")
|
||||||
if err := ConfigArtifacts(context.Background(), []string{"--config", pipelinePath}, &out); err != nil {
|
mustWriteTestFile(t, roster, "schema_version: narratio.party.v1\ncharacters:\n synthetic_character:\n player: {name: Synthetic Player}\n character: {name: Synthetic Character, classes: [{name: ranger}]}\n")
|
||||||
|
selected := "testing"
|
||||||
|
loaded, err := config.LoadPipelineWithOptions(pipeline, config.PipelineLoadOptions{Overlay: &selected})
|
||||||
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if out.String() != artifactCatalogHeader {
|
var before, after bytes.Buffer
|
||||||
t.Fatalf("empty catalog = %q, want header only", out.String())
|
if err := loaded.ConfigKitResult().WriteEffective(&before); err != nil {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConfigArtifactsReportsGeneratedFamilyProvenance(t *testing.T) {
|
|
||||||
pipelinePath, campaignPath := writeInspectionFamilyConfig(t)
|
|
||||||
var out bytes.Buffer
|
|
||||||
if err := ConfigArtifacts(context.Background(), []string{"--config", pipelinePath, "--campaign-file", campaignPath}, &out); err != nil {
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
records := catalogRecordsByKey(t, out.String())
|
app, err := newApplication(commandDependencies{loadPipelineConfig: func(string, config.PipelineLoadOptions) (*config.PipelineConfig, error) { return loaded, nil }}, executePlan)
|
||||||
meta := records["character_meta_arannis"]
|
if err != nil {
|
||||||
note := records["character_note_arannis"]
|
|
||||||
partyPath := filepath.Join(filepath.Dir(campaignPath), "party.yml")
|
|
||||||
if len(meta) != 10 || meta[6] != "character_meta" || meta[7] != "arannis" || meta[8] != pipelinePath || meta[9] != partyPath {
|
|
||||||
t.Fatalf("generated meta record = %#v", meta)
|
|
||||||
}
|
|
||||||
if len(note) != 10 || note[5] != "character_meta_arannis" || note[6] != "character_note" {
|
|
||||||
t.Fatalf("generated note record = %#v", note)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConfigArtifactsReportsOverlayFamilyContributors(t *testing.T) {
|
|
||||||
pipelinePath, campaignPath := writeInspectionFamilyConfig(t)
|
|
||||||
overlayPath := filepath.Join(filepath.Dir(pipelinePath), "overlays", "testing.yml")
|
|
||||||
mustWriteTestFile(t, overlayPath, `scriptorium:
|
|
||||||
artifact_families:
|
|
||||||
character_note:
|
|
||||||
prompt_id: dnd.character_note.testing
|
|
||||||
`)
|
|
||||||
|
|
||||||
args := []string{"--config", pipelinePath, "--campaign-file", campaignPath, "--overlay", "testing"}
|
|
||||||
var catalog bytes.Buffer
|
|
||||||
if err := ConfigArtifacts(context.Background(), args, &catalog); err != nil {
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
records := catalogRecordsByKey(t, catalog.String())
|
var out, diagnostic bytes.Buffer
|
||||||
if got := strings.Split(records["character_note_arannis"][2], ","); !reflect.DeepEqual(got, []string{overlayPath, pipelinePath}) {
|
outcome := app.Execute(context.Background(), []string{"artifacts", "list", "--config", pipeline, "--overlay", selected, "--party-file", roster, "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||||
t.Fatalf("generated family definitions = %#v", got)
|
if outcome.Status != 0 {
|
||||||
|
t.Fatalf("status=%d diagnostics=%s", outcome.Status, diagnostic.String())
|
||||||
}
|
}
|
||||||
|
var report artifactCatalogReport
|
||||||
}
|
if err := json.Unmarshal(out.Bytes(), &report); err != nil {
|
||||||
|
|
||||||
func TestConfigArtifactsReportsBaseAndOverlayContributors(t *testing.T) {
|
|
||||||
dir := t.TempDir()
|
|
||||||
pipelinePath := filepath.Join(dir, "pipeline.yml")
|
|
||||||
overlayPath := filepath.Join(dir, "overlays", "testing.yml")
|
|
||||||
mustWriteTestFile(t, pipelinePath, `workspace:
|
|
||||||
root: /srv/narratio
|
|
||||||
whisperx:
|
|
||||||
transcribe_url: https://transcription.example.com/transcribe
|
|
||||||
scriptorium:
|
|
||||||
binary: scriptorium
|
|
||||||
artifacts:
|
|
||||||
notes:
|
|
||||||
enabled: false
|
|
||||||
output_path: artifacts/notes.md
|
|
||||||
`)
|
|
||||||
mustWriteTestFile(t, overlayPath, `scriptorium:
|
|
||||||
artifacts:
|
|
||||||
notes:
|
|
||||||
enabled: true
|
|
||||||
prompt_id: notes
|
|
||||||
overlay_only:
|
|
||||||
enabled: false
|
|
||||||
output_path: artifacts/overlay-only.md
|
|
||||||
`)
|
|
||||||
|
|
||||||
var out bytes.Buffer
|
|
||||||
if err := ConfigArtifacts(context.Background(), []string{"--config", pipelinePath, "--overlay", "testing"}, &out); err != nil {
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
records := catalogRecordsByKey(t, out.String())
|
found := false
|
||||||
if got := strings.Split(records["notes"][2], ","); !reflect.DeepEqual(got, []string{overlayPath, pipelinePath}) {
|
for _, entry := range report.Artifacts {
|
||||||
t.Fatalf("notes definitions = %#v", got)
|
if entry.Family == "character_note" {
|
||||||
}
|
if entry.CharacterID != "synthetic_character" || entry.PartySource != roster || entry.Key != "character_note_synthetic_character" {
|
||||||
if got := records["overlay_only"][2]; got != overlayPath {
|
t.Fatalf("member=%#v", entry)
|
||||||
t.Fatalf("overlay-only definition = %q, want %q", got, overlayPath)
|
}
|
||||||
}
|
if !reflect.DeepEqual(entry.DefinitionSources, []string{overlay, pipeline}) {
|
||||||
}
|
t.Fatalf("definition sources=%v", entry.DefinitionSources)
|
||||||
|
}
|
||||||
func TestConfigArtifactsIdentityDoesNotDependOnDefinitionFilename(t *testing.T) {
|
found = true
|
||||||
inlineDir := t.TempDir()
|
|
||||||
inlinePath := filepath.Join(inlineDir, "pipeline.yml")
|
|
||||||
mustWriteTestFile(t, inlinePath, artifactIdentityPipeline("", "recap"))
|
|
||||||
importDir := t.TempDir()
|
|
||||||
importPath := filepath.Join(importDir, "pipeline.yml")
|
|
||||||
mustWriteTestFile(t, importPath, artifactIdentityPipeline("artifacts.yml", ""))
|
|
||||||
mustWriteTestFile(t, filepath.Join(importDir, "artifacts.yml"), "scriptorium:\n artifacts:\n recap:\n enabled: false\n output_path: artifacts/recap.md\n")
|
|
||||||
|
|
||||||
for _, path := range []string{inlinePath, importPath} {
|
|
||||||
var out bytes.Buffer
|
|
||||||
if err := ConfigArtifacts(context.Background(), []string{"--config", path}, &out); err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if got := catalogRecordsByKey(t, out.String())["recap"][1]; got != "narratio.artifact.recap" {
|
|
||||||
t.Fatalf("source identity for %s = %q", path, got)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if !found {
|
||||||
|
t.Fatal("catalog omitted selected family member")
|
||||||
func TestConfigArtifactsPropagatesWriterErrorsAndEscapesFields(t *testing.T) {
|
|
||||||
dir := t.TempDir()
|
|
||||||
pipelinePath := filepath.Join(dir, "pipeline.yml")
|
|
||||||
mustWriteTestFile(t, pipelinePath, "workspace:\n root: /srv/narratio\nwhisperx:\n transcribe_url: https://transcription.example.com/transcribe\n")
|
|
||||||
want := errors.New("write rejected")
|
|
||||||
err := ConfigArtifacts(context.Background(), []string{"--config", pipelinePath}, rejectingCatalogWriter{err: want})
|
|
||||||
if !errors.Is(err, want) {
|
|
||||||
t.Fatalf("ConfigArtifacts() error = %v, want writer error", err)
|
|
||||||
}
|
}
|
||||||
if got := escapeCatalogField("a\\b\tc\nd\r"); got != `a\\b\tc\nd\r` {
|
if err := loaded.ConfigKitResult().WriteEffective(&after); err != nil {
|
||||||
t.Fatalf("escaped field = %q", got)
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if !bytes.Equal(before.Bytes(), after.Bytes()) {
|
||||||
|
t.Fatal("catalog derivation changed native configuration")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func catalogRecordsByKey(t *testing.T, output string) map[string][]string {
|
|
||||||
t.Helper()
|
|
||||||
lines := strings.Split(strings.TrimSuffix(output, "\n"), "\n")
|
|
||||||
if len(lines) == 0 || lines[0]+"\n" != artifactCatalogHeader {
|
|
||||||
t.Fatalf("catalog header = %q", output)
|
|
||||||
}
|
|
||||||
records := make(map[string][]string, len(lines)-1)
|
|
||||||
for _, line := range lines[1:] {
|
|
||||||
fields := strings.Split(line, "\t")
|
|
||||||
records[fields[0]] = fields
|
|
||||||
}
|
|
||||||
return records
|
|
||||||
}
|
|
||||||
|
|
||||||
func artifactIdentityPipeline(importPath, inlineKey string) string {
|
|
||||||
document := "workspace:\n root: /srv/narratio\nwhisperx:\n transcribe_url: https://transcription.example.com/transcribe\nscriptorium:\n binary: scriptorium\n"
|
|
||||||
if importPath != "" {
|
|
||||||
document = "config:\n imports:\n - path: " + importPath + "\n" + document
|
|
||||||
}
|
|
||||||
if inlineKey != "" {
|
|
||||||
document += " artifacts:\n " + inlineKey + ":\n enabled: false\n output_path: artifacts/recap.md\n"
|
|
||||||
}
|
|
||||||
return document
|
|
||||||
}
|
|
||||||
|
|
||||||
type rejectingCatalogWriter struct{ err error }
|
|
||||||
|
|
||||||
func (w rejectingCatalogWriter) Write([]byte) (int, error) { return 0, w.err }
|
|
||||||
|
|||||||
@@ -1,195 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"errors"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"sort"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
type inspectionFlags struct {
|
|
||||||
pipelinePath string
|
|
||||||
campaignPath string
|
|
||||||
campaignFilePath string
|
|
||||||
overlay singletonStringFlag
|
|
||||||
secretsDir singletonStringFlag
|
|
||||||
}
|
|
||||||
|
|
||||||
type inspectionConfig struct {
|
|
||||||
PipelinePath string
|
|
||||||
Pipeline *config.PipelineConfig
|
|
||||||
CampaignPath string
|
|
||||||
Campaign *config.CampaignConfig
|
|
||||||
Party config.ResolvedParty
|
|
||||||
ArtifactCatalog *config.ArtifactCatalog
|
|
||||||
}
|
|
||||||
|
|
||||||
// ConfigArtifacts validates and reports the effective concrete artifact catalog
|
|
||||||
// without loading session state or runtime collaborators.
|
|
||||||
func ConfigArtifacts(ctx context.Context, args []string, out io.Writer) error {
|
|
||||||
return configArtifactsWithDependencies(ctx, args, out, commandDependencies{})
|
|
||||||
}
|
|
||||||
|
|
||||||
func configArtifactsWithDependencies(_ context.Context, args []string, out io.Writer, deps commandDependencies) error {
|
|
||||||
flags, err := parseInspectionFlags("config artifacts", args, out)
|
|
||||||
if err != nil {
|
|
||||||
if errors.Is(err, flag.ErrHelp) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
resolved, err := resolveInspectionConfigWithDependencies(flags, deps)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("config artifacts: %w", err)
|
|
||||||
}
|
|
||||||
records := resolved.ArtifactCatalog.Records
|
|
||||||
if _, err := fmt.Fprintln(out, "key\tsource\tdefinitions\tenabled\toutput\tdependencies\tfamily\tcharacter\tfamily_source\tparty_source"); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
for _, record := range records {
|
|
||||||
fields := []string{
|
|
||||||
record.Key,
|
|
||||||
record.SourceID,
|
|
||||||
strings.Join(normalizedCatalogPaths(record.DefinitionSources), ","),
|
|
||||||
strconv.FormatBool(record.Enabled),
|
|
||||||
record.OutputPath,
|
|
||||||
strings.Join(record.Dependencies, ","),
|
|
||||||
record.FamilyKey,
|
|
||||||
record.CharacterID,
|
|
||||||
strings.Join(normalizedCatalogPaths(record.FamilySources), ","),
|
|
||||||
config.NormalizedConfigurationPath(record.PartySource),
|
|
||||||
}
|
|
||||||
for index := range fields {
|
|
||||||
fields[index] = escapeCatalogField(fields[index])
|
|
||||||
}
|
|
||||||
if _, err := fmt.Fprintln(out, strings.Join(fields, "\t")); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func normalizedCatalogPaths(paths []string) []string {
|
|
||||||
result := make([]string, len(paths))
|
|
||||||
for index, path := range paths {
|
|
||||||
result[index] = config.NormalizedConfigurationPath(path)
|
|
||||||
}
|
|
||||||
sort.Strings(result)
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
func escapeCatalogField(value string) string {
|
|
||||||
value = strings.ReplaceAll(value, "\\", "\\\\")
|
|
||||||
value = strings.ReplaceAll(value, "\t", "\\t")
|
|
||||||
value = strings.ReplaceAll(value, "\r", "\\r")
|
|
||||||
return strings.ReplaceAll(value, "\n", "\\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseInspectionFlags(command string, args []string, out io.Writer) (inspectionFlags, error) {
|
|
||||||
fs := flag.NewFlagSet(command, flag.ContinueOnError)
|
|
||||||
fs.SetOutput(out)
|
|
||||||
var flags inspectionFlags
|
|
||||||
fs.StringVar(&flags.pipelinePath, "config", "", "path to pipeline.yml (optional; defaults searched)")
|
|
||||||
fs.StringVar(&flags.campaignPath, "campaign", "", "campaign ID")
|
|
||||||
fs.StringVar(&flags.campaignFilePath, "campaign-file", "", "path to campaign.yml")
|
|
||||||
flags.overlay.name = "overlay"
|
|
||||||
fs.Var(&flags.overlay, "overlay", "named pipeline overlay")
|
|
||||||
flags.secretsDir.name = "secrets-dir"
|
|
||||||
fs.Var(&flags.secretsDir, "secrets-dir", "secrets directory (optional; defaults to /usr/local/etc/narratio/secrets)")
|
|
||||||
fs.Usage = func() {
|
|
||||||
fmt.Fprintf(out, "Usage: narratio %s [--config <pipeline.yml>] [--campaign <id> | --campaign-file <campaign.yml>] [--overlay <name>] [--secrets-dir <path>]\n\n", command)
|
|
||||||
fmt.Fprintln(out, "Resolves configuration without a session, workspace, manifest, adapters, or external services.")
|
|
||||||
fmt.Fprintln(out)
|
|
||||||
fmt.Fprintln(out, "Flags:")
|
|
||||||
fs.PrintDefaults()
|
|
||||||
}
|
|
||||||
if err := fs.Parse(args); err != nil {
|
|
||||||
return inspectionFlags{}, fmt.Errorf("%s: invalid flags: %w", command, err)
|
|
||||||
}
|
|
||||||
if fs.NArg() != 0 {
|
|
||||||
return inspectionFlags{}, fmt.Errorf("%s: unexpected positional arguments", command)
|
|
||||||
}
|
|
||||||
if strings.TrimSpace(flags.campaignPath) != "" && strings.TrimSpace(flags.campaignFilePath) != "" {
|
|
||||||
return inspectionFlags{}, fmt.Errorf("%s: --campaign and --campaign-file are mutually exclusive", command)
|
|
||||||
}
|
|
||||||
return flags, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func resolveInspectionConfigWithDependencies(flags inspectionFlags, deps commandDependencies) (*inspectionConfig, error) {
|
|
||||||
pipelinePath, pipeline, err := loadPipelineConfigWithDependencies(flags.pipelinePath, config.PipelineLoadOptions{Overlay: flags.overlay.pointer()}, flags.secretsDir.pointer(), deps)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
needsCampaign := pipelineHasArtifactFamilies(pipeline)
|
|
||||||
hasCampaignSelection := strings.TrimSpace(flags.campaignPath) != "" || strings.TrimSpace(flags.campaignFilePath) != ""
|
|
||||||
if !needsCampaign && !hasCampaignSelection {
|
|
||||||
if err := validateInspectionPipeline(pipelinePath, pipeline); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
catalog, err := config.DeriveArtifactCatalog(pipeline, config.ResolvedParty{})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &inspectionConfig{PipelinePath: pipelinePath, Pipeline: pipeline, ArtifactCatalog: catalog}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
campaignPath, err := resolveCampaignConfigPath(pipeline, flags.campaignPath, flags.campaignFilePath)
|
|
||||||
if err != nil {
|
|
||||||
if needsCampaign {
|
|
||||||
return nil, fmt.Errorf("pipeline.scriptorium.artifact_families requires a campaign: %w", err)
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
campaign, err := config.LoadCampaign(campaignPath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if selectedID := strings.TrimSpace(flags.campaignPath); selectedID != "" && strings.TrimSpace(flags.campaignFilePath) == "" {
|
|
||||||
if got := config.CampaignID(campaign); got != selectedID {
|
|
||||||
return nil, fmt.Errorf("campaign config %q invalid: campaign_id %q does not match selected campaign %q", campaignPath, got, selectedID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
loaded, err := config.LoadPipelineCampaign(pipelinePath, pipeline, campaignPath, campaign)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := validateInspectionPipeline(loaded.PipelinePath, loaded.Pipeline); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := validateInspectionCampaign(loaded.CampaignPath, loaded.Campaign); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &inspectionConfig{
|
|
||||||
PipelinePath: loaded.PipelinePath,
|
|
||||||
Pipeline: loaded.Pipeline,
|
|
||||||
CampaignPath: loaded.CampaignPath,
|
|
||||||
Campaign: loaded.Campaign,
|
|
||||||
Party: loaded.Party,
|
|
||||||
ArtifactCatalog: loaded.ArtifactCatalog,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func pipelineHasArtifactFamilies(pipeline *config.PipelineConfig) bool {
|
|
||||||
return pipeline != nil && pipeline.Scriptorium != nil && len(pipeline.Scriptorium.ArtifactFamilies) != 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateInspectionPipeline(path string, pipeline *config.PipelineConfig) error {
|
|
||||||
if err := config.ValidatePipelineConfig(pipeline); err != nil {
|
|
||||||
return fmt.Errorf("pipeline config %q invalid: %w", path, err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateInspectionCampaign(path string, campaign *config.CampaignConfig) error {
|
|
||||||
if err := config.ValidateCampaignConfig(campaign); err != nil {
|
|
||||||
return fmt.Errorf("campaign config %q invalid: %w", path, err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -147,11 +147,8 @@ func TestNativeBundleInspectionAndExecutionAgree(t *testing.T) {
|
|||||||
t.Fatal("native show omitted authored families")
|
t.Fatal("native show omitted authored families")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var catalog bytes.Buffer
|
catalog := nativeInspectionForTest(t, append([]string{"artifacts", "list", "--format", "json"}, common...))
|
||||||
if err := ConfigArtifacts(context.Background(), common, &catalog); err != nil {
|
if !strings.Contains(catalog, "character_meta_arannis") {
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
if !strings.Contains(catalog.String(), "character_meta_arannis") {
|
|
||||||
t.Fatal("domain catalog omitted concrete family member")
|
t.Fatal("domain catalog omitted concrete family member")
|
||||||
}
|
}
|
||||||
diff := nativeInspectionForTest(t, []string{"config", "diff", "--details", "--against-overlay", "testing", "--secrets-dir", secrets, "--format", "json"})
|
diff := nativeInspectionForTest(t, []string{"config", "diff", "--details", "--against-overlay", "testing", "--secrets-dir", secrets, "--format", "json"})
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ type configurationAcquisition struct {
|
|||||||
session *acquiredSession
|
session *acquiredSession
|
||||||
previousSessionID string
|
previousSessionID string
|
||||||
domain *config.Config
|
domain *config.Config
|
||||||
|
catalog *config.ArtifactCatalog
|
||||||
pipelineOverrides []configkit.Override
|
pipelineOverrides []configkit.Override
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,10 +240,11 @@ func (a *configurationAcquisition) Domain(ctx context.Context) (*config.Config,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
base, err := config.LoadPipelineCampaignWithParty(a.pipelinePath, pipeline, a.campaignPath, campaign, *party)
|
catalog, err := a.Catalog(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
base := config.LoadedPipelineCampaign{PipelinePath: a.pipelinePath, Pipeline: pipeline, CampaignPath: a.campaignPath, Campaign: campaign, Party: *party, ArtifactCatalog: catalog}
|
||||||
cfg, err := config.ResolveLoadedPipelineCampaign(base, a.session.Path, session, a.session.Source)
|
cfg, err := config.ResolveLoadedPipelineCampaign(base, a.session.Path, session, a.session.Source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -259,3 +261,27 @@ func (a *configurationAcquisition) Close() error {
|
|||||||
a.session.cleanup = nil
|
a.session.cleanup = nil
|
||||||
return cleanup()
|
return cleanup()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *configurationAcquisition) Catalog(ctx context.Context) (*config.ArtifactCatalog, error) {
|
||||||
|
pipeline, err := a.Pipeline(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if a.catalog != nil {
|
||||||
|
return a.catalog, nil
|
||||||
|
}
|
||||||
|
var party config.ResolvedParty
|
||||||
|
if a.party != nil || a.selection.PartyFile.Set || a.selection.Campaign.Set || a.selection.CampaignFile.Set || (pipeline.Scriptorium != nil && len(pipeline.Scriptorium.ArtifactFamilies) != 0) {
|
||||||
|
selected, err := a.Party(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
party = *selected
|
||||||
|
}
|
||||||
|
catalog, err := config.DeriveArtifactCatalog(pipeline, party)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
a.catalog = catalog
|
||||||
|
return catalog, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -65,6 +65,18 @@ func checkExecutionInput(input *executionInput) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func executionCommand(name, summary string, regenerate bool, deps commandDependencies, executor pipelineExecutor) commandkit.Command {
|
func executionCommand(name, summary string, regenerate bool, deps commandDependencies, executor pipelineExecutor) commandkit.Command {
|
||||||
|
spec := executionCommandSpec(name, summary, regenerate)
|
||||||
|
spec.Run = func(invocation commandkit.Invocation, input *executionInput) commandkit.Outcome {
|
||||||
|
report, err := executeSelectedPipeline(invocation.Context, input, deps, executor)
|
||||||
|
if report != nil {
|
||||||
|
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
||||||
|
}
|
||||||
|
return operationOutcome(err)
|
||||||
|
}
|
||||||
|
return commandkit.NewCommand(spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func executionCommandSpec(name, summary string, regenerate bool) commandkit.CommandSpec[*executionInput] {
|
||||||
common := newConfigurationFlags(func(input **executionInput) *configurationSelection { return &(*input).Selection })
|
common := newConfigurationFlags(func(input **executionInput) *configurationSelection { return &(*input).Selection })
|
||||||
flags := []commandkit.Flag[*executionInput]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.SessionFile, common.PartyFile, common.SecretsDir,
|
flags := []commandkit.Flag[*executionInput]{common.Config, common.Overlay, common.Campaign, common.CampaignFile, common.SessionFile, common.PartyFile, common.SecretsDir,
|
||||||
commandkit.ValueFlag(commandkit.FlagMeta{Name: "previous-session-id", Usage: "Assert the previous session identity."}, nil, stringValue, func(input **executionInput, value commandkit.Supplied[string]) { (*input).PreviousSession = value }),
|
commandkit.ValueFlag(commandkit.FlagMeta{Name: "previous-session-id", Usage: "Assert the previous session identity."}, nil, stringValue, func(input **executionInput, value commandkit.Supplied[string]) { (*input).PreviousSession = value }),
|
||||||
@@ -78,7 +90,7 @@ func executionCommand(name, summary string, regenerate bool, deps commandDepende
|
|||||||
commandkit.BoolFlag(commandkit.FlagMeta{Name: "force", Usage: "Rerun selected stages."}, false, func(input **executionInput, value commandkit.Supplied[bool]) { (*input).Force = value }),
|
commandkit.BoolFlag(commandkit.FlagMeta{Name: "force", Usage: "Rerun selected stages."}, false, func(input **executionInput, value commandkit.Supplied[bool]) { (*input).Force = value }),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return commandkit.NewCommand(commandkit.CommandSpec[*executionInput]{
|
return commandkit.CommandSpec[*executionInput]{
|
||||||
Name: name, Summary: summary, NewInput: func() *executionInput { return &executionInput{} }, Flags: flags,
|
Name: name, Summary: summary, NewInput: func() *executionInput { return &executionInput{} }, Flags: flags,
|
||||||
Arguments: []commandkit.Argument[*executionInput]{commandkit.ValueArgument(commandkit.ArgumentMeta{Name: "SESSION", Usage: "Session identity."}, true, stringValue, func(input **executionInput, value commandkit.Supplied[string]) { (*input).Selection.Session = value })},
|
Arguments: []commandkit.Argument[*executionInput]{commandkit.ValueArgument(commandkit.ArgumentMeta{Name: "SESSION", Usage: "Session identity."}, true, stringValue, func(input **executionInput, value commandkit.Supplied[string]) { (*input).Selection.Session = value })},
|
||||||
CheckInput: func(input *executionInput) error {
|
CheckInput: func(input *executionInput) error {
|
||||||
@@ -89,14 +101,7 @@ func executionCommand(name, summary string, regenerate bool, deps commandDepende
|
|||||||
}
|
}
|
||||||
return checkExecutionInput(input)
|
return checkExecutionInput(input)
|
||||||
},
|
},
|
||||||
Run: func(invocation commandkit.Invocation, input *executionInput) commandkit.Outcome {
|
}
|
||||||
report, err := executeSelectedPipeline(invocation.Context, input, deps, executor)
|
|
||||||
if report != nil {
|
|
||||||
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
|
||||||
}
|
|
||||||
return operationOutcome(err)
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func executeSelectedPipeline(ctx context.Context, input *executionInput, deps commandDependencies, executor pipelineExecutor) (report *runReport, err error) {
|
func executeSelectedPipeline(ctx context.Context, input *executionInput, deps commandDependencies, executor pipelineExecutor) (report *runReport, err error) {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/stage"
|
"gitea.maximumdirect.net/eric/narratio/internal/stage"
|
||||||
|
"go.maximumdirect.net/commandkit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Plan validates configuration and prints a read-only execution preview.
|
// Plan validates configuration and prints a read-only execution preview.
|
||||||
@@ -48,83 +49,33 @@ func planWithDependencies(ctx context.Context, args []string, out io.Writer, dep
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("plan: %w", err)
|
return fmt.Errorf("plan: %w", err)
|
||||||
}
|
}
|
||||||
m, err := loadManifestIfPresent(ctx, cfg)
|
input := &executionInput{plan: request.Plan, Force: commandkit.Supplied[bool]{Value: request.Force}}
|
||||||
|
report, err := buildSessionPlan(ctx, cfg, input, selectedArtifacts, effective)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("plan: %w", err)
|
return err
|
||||||
}
|
}
|
||||||
if err := validateBoundedPrerequisites(request.Plan, m); err != nil {
|
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||||
return fmt.Errorf("plan: %w", err)
|
|
||||||
}
|
|
||||||
store := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root)
|
|
||||||
paths := store.SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
|
||||||
model, err := cloneManifestForPlan(m, cfg)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("plan: clone session state: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
stages := request.Plan.Stages()
|
|
||||||
stageEnv := &stage.Env{
|
|
||||||
Config: cfg, SelectedArtifactKeys: append([]string(nil), selectedArtifacts...),
|
|
||||||
EffectiveArtifacts: effective, ArtifactStore: store, Force: request.Force,
|
|
||||||
}
|
|
||||||
|
|
||||||
runCount := 0
|
|
||||||
skipCount := 0
|
|
||||||
if _, err := fmt.Fprintf(out, "narratio session plan: read-only workdir at %s; %s\n", paths.Root, effectiveConfigSummary(cfg)); err != nil {
|
if _, err := fmt.Fprintf(out, "narratio session plan: read-only workdir at %s; %s\n", paths.Root, effectiveConfigSummary(cfg)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, selectedStage := range stages {
|
runCount, skipCount := 0, 0
|
||||||
semanticConfig, err := currentStageSemanticConfig(selectedStage, stageEnv)
|
for _, entry := range report.Stages {
|
||||||
if err != nil {
|
if entry.Action == string(stageActionRun) {
|
||||||
return fmt.Errorf("plan: fingerprint semantic configuration for stage %q: %w", selectedStage.Name(), err)
|
|
||||||
}
|
|
||||||
decision := decideStageExecution(recordedStageStatus(model, selectedStage.Name()), request.Force, nil)
|
|
||||||
var validation *stage.ResumeValidation
|
|
||||||
if decision.action == stageActionSkip {
|
|
||||||
checked, validationErr := evaluateStageResume(ctx, selectedStage, stageEnv, model, semanticConfig)
|
|
||||||
if validationErr != nil {
|
|
||||||
return fmt.Errorf("plan: validate resume for stage %q: %w", selectedStage.Name(), validationErr)
|
|
||||||
}
|
|
||||||
validation = checked
|
|
||||||
decision = decideStageExecution(recordedStageStatus(model, selectedStage.Name()), request.Force, checked)
|
|
||||||
}
|
|
||||||
if _, err := applyPreExecutionDecision(model, selectedStage.Name(), decision, time.Now().UTC()); err != nil {
|
|
||||||
return fmt.Errorf("plan: model resume invalidation for stage %q: %w", selectedStage.Name(), err)
|
|
||||||
}
|
|
||||||
if decision.action == stageActionRun && selectedStage.Name() == "analyze" {
|
|
||||||
if validator, ok := selectedStage.(stage.ResumeValidator); ok {
|
|
||||||
checked, validationErr := validator.ValidateResume(ctx, stageEnv, model)
|
|
||||||
if validationErr != nil {
|
|
||||||
return fmt.Errorf("plan: validate resume for stage %q: %w", selectedStage.Name(), validationErr)
|
|
||||||
}
|
|
||||||
checked = checked.Normalized()
|
|
||||||
validation = &checked
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if decision.action == stageActionRun {
|
|
||||||
runCount++
|
runCount++
|
||||||
} else {
|
} else {
|
||||||
skipCount++
|
skipCount++
|
||||||
}
|
}
|
||||||
if _, err := fmt.Fprintf(out, "%s: %s\n", selectedStage.Name(), decision.action); err != nil {
|
if _, err := fmt.Fprintf(out, "%s: %s\n", entry.Name, entry.Action); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if validation != nil && validation.Analyze != nil {
|
if entry.Analysis != nil {
|
||||||
if err := writeAnalyzePlanDetails(out, validation.Analyze); err != nil {
|
if err := writeAnalyzePlanDetails(out, entry.Analysis); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if decision.action == stageActionRun {
|
|
||||||
if err := modelPlannedStageRun(model, selectedStage, cfg, decision, semanticConfig); err != nil {
|
|
||||||
return fmt.Errorf("plan: model stage %q: %w", selectedStage.Name(), err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if _, err := fmt.Fprintf(out, "totals: run=%d skip=%d\n", runCount, skipCount); err != nil {
|
_, err = fmt.Fprintf(out, "totals: run=%d skip=%d\n", runCount, skipCount)
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func cloneManifestForPlan(source *manifest.Manifest, cfg *config.Config) (*manifest.Manifest, error) {
|
func cloneManifestForPlan(source *manifest.Manifest, cfg *config.Config) (*manifest.Manifest, error) {
|
||||||
@@ -175,20 +126,20 @@ func plannedSelfSkipReason(stageName string, cfg *config.Config) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeAnalyzePlanDetails(out io.Writer, summary *stage.AnalyzeResumeSummary) error {
|
func writeAnalyzePlanDetails(out io.Writer, summary *plannedAnalysis) error {
|
||||||
if summary == nil {
|
if summary == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if _, err := fmt.Fprintf(out, " targets: %s\n", planStringList(summary.ExplicitTargets)); err != nil {
|
if _, err := fmt.Fprintf(out, " targets: %s\n", planStringList(summary.Targets)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := fmt.Fprintf(out, " prerequisites: %s\n", planArtifactList(summary.PrerequisiteWork)); err != nil {
|
if _, err := fmt.Fprintf(out, " prerequisites: %s\n", planArtifactList(summary.Prerequisites)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := fmt.Fprintf(out, " execute: %s\n", planArtifactList(summary.ExecutionOrder)); err != nil {
|
if _, err := fmt.Fprintf(out, " execute: %s\n", planArtifactList(summary.Execute)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err := fmt.Fprintf(out, " reuse: %s\n", planArtifactList(summary.ReusedCurrent))
|
_, err := fmt.Fprintf(out, " reuse: %s\n", planArtifactList(summary.Reuse))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +150,7 @@ func planStringList(values []string) string {
|
|||||||
return strings.Join(values, ", ")
|
return strings.Join(values, ", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
func planArtifactList(values []stage.AnalyzeResumeArtifact) string {
|
func planArtifactList(values []plannedArtifact) string {
|
||||||
if len(values) == 0 {
|
if len(values) == 0 {
|
||||||
return "none"
|
return "none"
|
||||||
}
|
}
|
||||||
|
|||||||
180
internal/app/plan_command.go
Normal file
180
internal/app/plan_command.go
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/stage"
|
||||||
|
"go.maximumdirect.net/commandkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
type sessionPlanReport struct {
|
||||||
|
Campaign string `json:"campaign"`
|
||||||
|
SessionID string `json:"session_id"`
|
||||||
|
Stages []plannedStage `json:"stages"`
|
||||||
|
Publication []plannedPublication `json:"publication_actions"`
|
||||||
|
}
|
||||||
|
type plannedStage struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Action string `json:"action"`
|
||||||
|
Reason string `json:"reason"`
|
||||||
|
Analysis *plannedAnalysis `json:"analysis,omitempty"`
|
||||||
|
}
|
||||||
|
type plannedAnalysis struct {
|
||||||
|
Targets []string `json:"targets"`
|
||||||
|
Prerequisites []plannedArtifact `json:"prerequisites"`
|
||||||
|
Execute []plannedArtifact `json:"execute"`
|
||||||
|
Reuse []plannedArtifact `json:"reuse"`
|
||||||
|
}
|
||||||
|
type plannedArtifact struct {
|
||||||
|
Key string `json:"key"`
|
||||||
|
Family string `json:"family,omitempty"`
|
||||||
|
CharacterID string `json:"character_id,omitempty"`
|
||||||
|
Role string `json:"role"`
|
||||||
|
Reason string `json:"reason"`
|
||||||
|
Forced bool `json:"forced"`
|
||||||
|
}
|
||||||
|
type plannedPublication struct {
|
||||||
|
Source string `json:"source"`
|
||||||
|
Destination string `json:"destination"`
|
||||||
|
Required bool `json:"required"`
|
||||||
|
Selected bool `json:"selected"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func analysisPlanReport(summary *stage.AnalyzeResumeSummary) *plannedAnalysis {
|
||||||
|
convert := func(items []stage.AnalyzeResumeArtifact) []plannedArtifact {
|
||||||
|
out := make([]plannedArtifact, 0, len(items))
|
||||||
|
for _, item := range items {
|
||||||
|
out = append(out, plannedArtifact{Key: item.Key, Family: item.Family, CharacterID: item.CharacterID, Role: item.Role, Reason: item.Reason, Forced: item.Forced})
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
return &plannedAnalysis{Targets: append([]string(nil), summary.ExplicitTargets...), Prerequisites: convert(summary.PrerequisiteWork), Execute: convert(summary.ExecutionOrder), Reuse: convert(summary.ReusedCurrent)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func sessionPlanCommand(deps commandDependencies) commandkit.Command {
|
||||||
|
spec := executionCommandSpec("plan", "Preview session work without executing it.", false)
|
||||||
|
spec.Run = func(invocation commandkit.Invocation, input *executionInput) commandkit.Outcome {
|
||||||
|
report, err := planSelectedPipeline(invocation.Context, input, deps)
|
||||||
|
if report != nil {
|
||||||
|
err = errors.Join(err, invocation.Reporter().Report(commandkit.Report{Value: report}))
|
||||||
|
}
|
||||||
|
return operationOutcome(err)
|
||||||
|
}
|
||||||
|
return commandkit.NewCommand(spec)
|
||||||
|
}
|
||||||
|
|
||||||
|
func planSelectedPipeline(ctx context.Context, input *executionInput, deps commandDependencies) (report *sessionPlanReport, err error) {
|
||||||
|
deps = normalizeCommandDependencies(deps)
|
||||||
|
deps.secretsBootstrap = &secretsBootstrap{}
|
||||||
|
acquired := newConfigurationAcquisition(input.Selection, deps)
|
||||||
|
acquired.previousSessionID = input.PreviousSession.Value
|
||||||
|
defer func() { err = errors.Join(err, acquired.Close()) }()
|
||||||
|
cfg, err := acquired.Domain(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := config.Validate(cfg); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selected, err := normalizeArtifactSelection(cfg, input.selectedArtifacts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, &inputError{message: err.Error(), cause: err}
|
||||||
|
}
|
||||||
|
effective, err := resolveEffectiveArtifacts(cfg, selected)
|
||||||
|
if err != nil {
|
||||||
|
return nil, &inputError{message: err.Error(), cause: err}
|
||||||
|
}
|
||||||
|
return buildSessionPlan(ctx, cfg, input, selected, effective)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildSessionPlan(ctx context.Context, cfg *config.Config, input *executionInput, selectedArtifacts []string, effective artifacts.EffectiveArtifactSet) (*sessionPlanReport, error) {
|
||||||
|
m, err := loadManifestIfPresent(ctx, cfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("plan: %w", err)
|
||||||
|
}
|
||||||
|
if err := validateBoundedPrerequisites(input.plan, m); err != nil {
|
||||||
|
return nil, fmt.Errorf("plan: %w", err)
|
||||||
|
}
|
||||||
|
store := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root)
|
||||||
|
model, err := cloneManifestForPlan(m, cfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("plan: clone session state: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
stages := input.plan.Stages()
|
||||||
|
stageEnv := &stage.Env{
|
||||||
|
Config: cfg, SelectedArtifactKeys: append([]string(nil), selectedArtifacts...),
|
||||||
|
EffectiveArtifacts: effective, ArtifactStore: store, Force: input.Force.Value,
|
||||||
|
}
|
||||||
|
|
||||||
|
report := &sessionPlanReport{Campaign: config.CampaignID(cfg.Campaign), SessionID: cfg.Session.SessionID, Stages: []plannedStage{}, Publication: []plannedPublication{}}
|
||||||
|
for _, selectedStage := range stages {
|
||||||
|
semanticConfig, err := currentStageSemanticConfig(selectedStage, stageEnv)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("plan: fingerprint semantic configuration for stage %q: %w", selectedStage.Name(), err)
|
||||||
|
}
|
||||||
|
decision := decideStageExecution(recordedStageStatus(model, selectedStage.Name()), input.Force.Value, nil)
|
||||||
|
var validation *stage.ResumeValidation
|
||||||
|
if decision.action == stageActionSkip {
|
||||||
|
checked, validationErr := evaluateStageResume(ctx, selectedStage, stageEnv, model, semanticConfig)
|
||||||
|
if validationErr != nil {
|
||||||
|
return nil, fmt.Errorf("plan: validate resume for stage %q: %w", selectedStage.Name(), validationErr)
|
||||||
|
}
|
||||||
|
validation = checked
|
||||||
|
decision = decideStageExecution(recordedStageStatus(model, selectedStage.Name()), input.Force.Value, checked)
|
||||||
|
}
|
||||||
|
if _, err := applyPreExecutionDecision(model, selectedStage.Name(), decision, time.Now().UTC()); err != nil {
|
||||||
|
return nil, fmt.Errorf("plan: model resume invalidation for stage %q: %w", selectedStage.Name(), err)
|
||||||
|
}
|
||||||
|
if decision.action == stageActionRun && selectedStage.Name() == "analyze" {
|
||||||
|
if validator, ok := selectedStage.(stage.ResumeValidator); ok {
|
||||||
|
checked, validationErr := validator.ValidateResume(ctx, stageEnv, model)
|
||||||
|
if validationErr != nil {
|
||||||
|
return nil, fmt.Errorf("plan: validate resume for stage %q: %w", selectedStage.Name(), validationErr)
|
||||||
|
}
|
||||||
|
checked = checked.Normalized()
|
||||||
|
validation = &checked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reason := decision.selectedStaleReason
|
||||||
|
if reason == "" {
|
||||||
|
switch {
|
||||||
|
case input.Force.Value:
|
||||||
|
reason = "forced"
|
||||||
|
case decision.action == stageActionSkip:
|
||||||
|
reason = "recorded result is reusable"
|
||||||
|
default:
|
||||||
|
reason = "no reusable successful result"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entry := plannedStage{Name: selectedStage.Name(), Action: string(decision.action), Reason: reason}
|
||||||
|
if validation != nil && validation.Analyze != nil {
|
||||||
|
entry.Analysis = analysisPlanReport(validation.Analyze)
|
||||||
|
}
|
||||||
|
report.Stages = append(report.Stages, entry)
|
||||||
|
if decision.action == stageActionRun {
|
||||||
|
if err := modelPlannedStageRun(model, selectedStage, cfg, decision, semanticConfig); err != nil {
|
||||||
|
return nil, fmt.Errorf("plan: model stage %q: %w", selectedStage.Name(), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if input.plan.Contains("publish") && cfg.Pipeline.Publish != nil && (cfg.Pipeline.Publish.Enabled == nil || *cfg.Pipeline.Publish.Enabled) {
|
||||||
|
catalog, err := buildHelperArtifactCatalog(cfg, model)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
actions, err := stage.PlanPublicationOutputs(catalog, cfg.PublicationOutputs(), selectedArtifacts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, action := range actions {
|
||||||
|
report.Publication = append(report.Publication, plannedPublication{Source: action.Source, Destination: action.Destination, Required: action.Required, Selected: action.Selected})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return report, nil
|
||||||
|
}
|
||||||
70
internal/app/plan_command_test.go
Normal file
70
internal/app/plan_command_test.go
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"os"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
|
"go.maximumdirect.net/commandkit"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSessionPlanCommandReportsWorkWithoutRuntimeState(t *testing.T) {
|
||||||
|
pipeline, campaign, session := writeValidConfigFilesWithScriptoriumArtifacts(t, t.TempDir())
|
||||||
|
cfg, err := config.LoadWithSessionOptions(pipeline, campaign, session, config.SessionLoadOptions{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||||
|
if _, err := os.Stat(paths.Root); !os.IsNotExist(err) {
|
||||||
|
t.Fatalf("fixture session root=%v", err)
|
||||||
|
}
|
||||||
|
app, err := newApplication(commandDependencies{}, func(context.Context, *config.Config, BoundedPlan, RunOptions) (*RunSummary, error) {
|
||||||
|
t.Fatal("planning executed pipeline")
|
||||||
|
return nil, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
var out, diagnostic bytes.Buffer
|
||||||
|
outcome := app.Execute(context.Background(), []string{"session", "plan", "2026-05-03", "--config", pipeline, "--campaign-file", campaign, "--session-file", session, "--force", "--artifacts", "session_recap", "--format", "json"}, commandkit.Streams{Out: &out, Err: &diagnostic})
|
||||||
|
if outcome.Status != 0 {
|
||||||
|
t.Fatalf("status=%d error=%v diagnostics=%s", outcome.Status, outcome.Cause, diagnostic.String())
|
||||||
|
}
|
||||||
|
var report sessionPlanReport
|
||||||
|
if err := json.Unmarshal(out.Bytes(), &report); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if report.SessionID != "2026-05-03" || len(report.Stages) != len(BuildFullPlan()) {
|
||||||
|
t.Fatalf("plan=%#v", report)
|
||||||
|
}
|
||||||
|
foundAnalysis := false
|
||||||
|
for _, entry := range report.Stages {
|
||||||
|
if entry.Action != "run" || entry.Reason != "forced" {
|
||||||
|
t.Fatalf("stage=%#v", entry)
|
||||||
|
}
|
||||||
|
if entry.Name == "analyze" {
|
||||||
|
foundAnalysis = entry.Analysis != nil && len(entry.Analysis.Targets) > 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !foundAnalysis {
|
||||||
|
t.Fatal("plan omitted artifact work")
|
||||||
|
}
|
||||||
|
if len(report.Publication) != len(cfg.PublicationOutputs()) {
|
||||||
|
t.Fatalf("publication actions=%#v", report.Publication)
|
||||||
|
}
|
||||||
|
for _, action := range report.Publication {
|
||||||
|
if action.Destination == "" {
|
||||||
|
t.Fatalf("unresolved publication action=%#v", action)
|
||||||
|
}
|
||||||
|
if action.Source == "narratio.artifact.player_handout" && action.Selected {
|
||||||
|
t.Fatal("plan selected an unrequested publication target")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err := os.Stat(paths.Root); !os.IsNotExist(err) {
|
||||||
|
t.Fatalf("planning created runtime state: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -131,7 +131,7 @@ func (publishStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*S
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("publish: build runtime artifact catalog: %w", err)
|
return nil, fmt.Errorf("publish: build runtime artifact catalog: %w", err)
|
||||||
}
|
}
|
||||||
publishRules, err := resolvePublishRules(
|
publishRules, err := PlanPublicationOutputs(
|
||||||
runtimeCatalog,
|
runtimeCatalog,
|
||||||
env.Config.PublicationOutputs(),
|
env.Config.PublicationOutputs(),
|
||||||
env.SelectedArtifactKeys,
|
env.SelectedArtifactKeys,
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ const (
|
|||||||
publishOutputUnselected publishOutputStatus = "unselected"
|
publishOutputUnselected publishOutputStatus = "unselected"
|
||||||
)
|
)
|
||||||
|
|
||||||
type resolvedPublishRule struct {
|
// PublicationAction describes a selected output mapping before remote publication.
|
||||||
|
type PublicationAction struct {
|
||||||
Source string
|
Source string
|
||||||
Destination string
|
Destination string
|
||||||
Required bool
|
Required bool
|
||||||
@@ -52,7 +53,7 @@ type publishOutputPlan struct {
|
|||||||
func buildPublishOutputPlan(
|
func buildPublishOutputPlan(
|
||||||
sessionPrefix string,
|
sessionPrefix string,
|
||||||
runPrefix string,
|
runPrefix string,
|
||||||
rules []resolvedPublishRule,
|
rules []PublicationAction,
|
||||||
discovered []discoveredPublishOutput,
|
discovered []discoveredPublishOutput,
|
||||||
locks []artifacts.RemoteLock,
|
locks []artifacts.RemoteLock,
|
||||||
prior *artifacts.RemoteCommitManifest,
|
prior *artifacts.RemoteCommitManifest,
|
||||||
@@ -135,8 +136,8 @@ func buildPublishOutputPlan(
|
|||||||
return &publishOutputPlan{Outcomes: outcomes}, nil
|
return &publishOutputPlan{Outcomes: outcomes}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func normalizeResolvedPublishRules(rules []resolvedPublishRule) ([]resolvedPublishRule, error) {
|
func normalizeResolvedPublishRules(rules []PublicationAction) ([]PublicationAction, error) {
|
||||||
ordered := append([]resolvedPublishRule(nil), rules...)
|
ordered := append([]PublicationAction(nil), rules...)
|
||||||
sort.Slice(ordered, func(i, j int) bool { return ordered[i].Source < ordered[j].Source })
|
sort.Slice(ordered, func(i, j int) bool { return ordered[i].Source < ordered[j].Source })
|
||||||
seenSources := make(map[string]struct{}, len(ordered))
|
seenSources := make(map[string]struct{}, len(ordered))
|
||||||
configuredDestinations := make(map[string]string, len(ordered))
|
configuredDestinations := make(map[string]string, len(ordered))
|
||||||
@@ -156,7 +157,7 @@ func normalizeResolvedPublishRules(rules []resolvedPublishRule) ([]resolvedPubli
|
|||||||
return ordered, nil
|
return ordered, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateResolvedPublishRule(rule resolvedPublishRule) error {
|
func validateResolvedPublishRule(rule PublicationAction) error {
|
||||||
if strings.TrimSpace(rule.Source) != rule.Source || rule.Source == "" {
|
if strings.TrimSpace(rule.Source) != rule.Source || rule.Source == "" {
|
||||||
return fmt.Errorf("publish output source %q is not canonical", 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.beta"),
|
||||||
publishPlanLock(t, "narratio.artifact.gamma"),
|
publishPlanLock(t, "narratio.artifact.gamma"),
|
||||||
}
|
}
|
||||||
rules := []resolvedPublishRule{
|
rules := []PublicationAction{
|
||||||
{Source: "narratio.artifact.gamma", Destination: "artifacts/gamma.md", Required: true, Selected: true},
|
{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.alpha", Destination: "artifacts/alpha.md", Required: true, Selected: true},
|
||||||
{Source: "narratio.artifact.epsilon", Destination: "artifacts/epsilon.md", Required: true, Selected: false},
|
{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"}}
|
available := []discoveredPublishOutput{{Source: "narratio.artifact.alpha", LocalPath: "/workspace/alpha.md"}}
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
rules []resolvedPublishRule
|
rules []PublicationAction
|
||||||
discovered []discoveredPublishOutput
|
discovered []discoveredPublishOutput
|
||||||
locks []artifacts.RemoteLock
|
locks []artifacts.RemoteLock
|
||||||
prior *artifacts.RemoteCommitManifest
|
prior *artifacts.RemoteCommitManifest
|
||||||
@@ -95,7 +95,7 @@ func TestBuildPublishOutputPlanRejectsAmbiguities(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "duplicate configured source",
|
name: "duplicate configured source",
|
||||||
rules: []resolvedPublishRule{
|
rules: []PublicationAction{
|
||||||
{Source: "narratio.artifact.alpha", Destination: "artifacts/a.md", Selected: true},
|
{Source: "narratio.artifact.alpha", Destination: "artifacts/a.md", Selected: true},
|
||||||
{Source: "narratio.artifact.alpha", Destination: "artifacts/b.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",
|
name: "configured destination collision",
|
||||||
rules: []resolvedPublishRule{
|
rules: []PublicationAction{
|
||||||
{Source: "narratio.artifact.alpha", Destination: "artifacts/shared.md", Selected: true},
|
{Source: "narratio.artifact.alpha", Destination: "artifacts/shared.md", Selected: true},
|
||||||
{Source: "narratio.artifact.beta", Destination: "artifacts/shared.md", Selected: false},
|
{Source: "narratio.artifact.beta", Destination: "artifacts/shared.md", Selected: false},
|
||||||
},
|
},
|
||||||
@@ -113,7 +113,7 @@ func TestBuildPublishOutputPlanRejectsAmbiguities(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "ambiguous discovery",
|
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{
|
discovered: []discoveredPublishOutput{
|
||||||
{Source: "narratio.artifact.alpha", LocalPath: "/workspace/a.md"},
|
{Source: "narratio.artifact.alpha", LocalPath: "/workspace/a.md"},
|
||||||
{Source: "narratio.artifact.alpha", LocalPath: "/workspace/other.md"},
|
{Source: "narratio.artifact.alpha", LocalPath: "/workspace/other.md"},
|
||||||
@@ -122,7 +122,7 @@ func TestBuildPublishOutputPlanRejectsAmbiguities(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "duplicate prior source",
|
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")},
|
locks: []artifacts.RemoteLock{publishPlanLock(t, "narratio.artifact.alpha")},
|
||||||
prior: publishPlanCommit(
|
prior: publishPlanCommit(
|
||||||
publishPlanDeclaration(sessionPrefix, "20260512T010203Z-11223344", "narratio.artifact.alpha", "artifacts/a.md"),
|
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")
|
sessionPrefix := artifacts.S3SessionPrefix("dnd", "sample-campaign", "2026-05-03")
|
||||||
runPrefix := artifacts.S3RunPrefix(sessionPrefix, "20260519T010203Z-a1b2c3d4")
|
runPrefix := artifacts.S3RunPrefix(sessionPrefix, "20260519T010203Z-a1b2c3d4")
|
||||||
locked := publishPlanLock(t, "narratio.artifact.beta")
|
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.alpha", Destination: "artifacts/shared.md", Required: true, Selected: true},
|
||||||
{Source: "narratio.artifact.beta", Destination: "artifacts/new-beta.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"
|
"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,
|
catalog *artifacts.ArtifactCatalog,
|
||||||
rules []config.PublishOutputRule,
|
rules []config.PublishOutputRule,
|
||||||
selectedArtifactKeys []string,
|
selectedArtifactKeys []string,
|
||||||
) ([]resolvedPublishRule, error) {
|
) ([]PublicationAction, error) {
|
||||||
out := make([]resolvedPublishRule, 0, len(rules))
|
out := make([]PublicationAction, 0, len(rules))
|
||||||
selectedSet := publishSelectedArtifactSet(selectedArtifactKeys)
|
selectedSet := publishSelectedArtifactSet(selectedArtifactKeys)
|
||||||
configuredOutputs := configuredOutputPathMapFromCatalog(catalog)
|
configuredOutputs := configuredOutputPathMapFromCatalog(catalog)
|
||||||
extractionOutputs := extractionOutputSetFromCatalog(catalog)
|
extractionOutputs := extractionOutputSetFromCatalog(catalog)
|
||||||
@@ -36,7 +38,7 @@ func resolvePublishRules(
|
|||||||
_, selected = selectedSet[key]
|
_, 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)
|
return normalizeResolvedPublishRules(out)
|
||||||
}
|
}
|
||||||
@@ -45,7 +47,7 @@ func discoverPublishOutputs(
|
|||||||
paths artifacts.SessionPaths,
|
paths artifacts.SessionPaths,
|
||||||
m *manifest.Manifest,
|
m *manifest.Manifest,
|
||||||
catalog *artifacts.ArtifactCatalog,
|
catalog *artifacts.ArtifactCatalog,
|
||||||
rules []resolvedPublishRule,
|
rules []PublicationAction,
|
||||||
locks []artifacts.RemoteLock,
|
locks []artifacts.RemoteLock,
|
||||||
) ([]discoveredPublishOutput, error) {
|
) ([]discoveredPublishOutput, error) {
|
||||||
lockSet := make(map[string]struct{}, len(locks))
|
lockSet := make(map[string]struct{}, len(locks))
|
||||||
@@ -74,7 +76,7 @@ func discoverPublishOutputs(
|
|||||||
return out, nil
|
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)
|
locks := make([]artifacts.RemoteLock, 0)
|
||||||
for _, rule := range rules {
|
for _, rule := range rules {
|
||||||
if !rule.Selected {
|
if !rule.Selected {
|
||||||
@@ -91,7 +93,7 @@ func readPublishOutputLocks(ctx context.Context, store storage.ObjectStore, sess
|
|||||||
return locks, nil
|
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))
|
locked := make(map[string]struct{}, len(locks))
|
||||||
for _, lock := range locks {
|
for _, lock := range locks {
|
||||||
locked[lock.Source] = struct{}{}
|
locked[lock.Source] = struct{}{}
|
||||||
|
|||||||
Reference in New Issue
Block a user