Reuse prepared product descriptions for resume
This commit is contained in:
@@ -28,8 +28,11 @@ Materialize canonical current-session inputs before processing stages.
|
||||
## Key Behavior
|
||||
|
||||
A stage-owned stable-product inventory supplies the data, destinations, and
|
||||
manifest provenance for reference materialization. Audio and previous-session
|
||||
hydration are handled separately.
|
||||
manifest provenance for reference materialization. Resume projects source
|
||||
identities from the same inventory, using normalized snapshots and a durable-copy
|
||||
check for the pipeline projection. Semantic selection uses its presence-only
|
||||
projection without rendering source content. Audio and previous-session hydration
|
||||
are handled separately.
|
||||
|
||||
- validates required config/store state and resolves selected vocabulary before audio work.
|
||||
- prepares references and history without acquiring audio when a validated
|
||||
|
||||
@@ -41,10 +41,10 @@ their scope. Unless assigned otherwise, a finding remains independent audit
|
||||
remediation. Shared code does not make a refactoring a prerequisite or assign
|
||||
the whole finding to a roadmap.
|
||||
|
||||
Twenty-nine entries are closed by the safety, transfer, audio discovery, S3
|
||||
Thirty entries are closed by the safety, transfer, audio discovery, S3
|
||||
planning, prerequisite-history, publication-import, CLI classification,
|
||||
inspection aggregation, test maintenance, dead-code removal, and associated
|
||||
documentation work; 14 remain open. **Planned** identifies
|
||||
documentation work; 13 remain open. **Planned** identifies
|
||||
an agreed remedy awaiting implementation. **Potentially eliminated** requires verification that the offending
|
||||
lifecycle is removed. **Coordinate** identifies shared changes, not a commitment
|
||||
that a related feature implements the entire finding. Findings close only after their
|
||||
@@ -578,7 +578,11 @@ Related: [CAT-17](#cat-17--p3-centralize-configured-artifact-dependency-queries)
|
||||
|
||||
### CAT-19 — P3: Describe stable prepared products once for materialization and reuse
|
||||
|
||||
Status: Open
|
||||
Status: Closed
|
||||
|
||||
**Closure.** Stable product descriptions drive materialization, resume source
|
||||
matching and semantic presence selection. Preparation, resume, configuration
|
||||
and app tests cover snapshots, relocated inputs, glossaries, and supplied work.
|
||||
|
||||
**Disposition / owner.** Coordinate — [reference preparation](../../internal/stage-prepare.md)
|
||||
supports imported products and reuse. Review the shared stable-product description
|
||||
|
||||
@@ -322,7 +322,7 @@ Validation: `go test ./internal/stage -run 'Test.*Prepar'`.
|
||||
|
||||
## Stage 10: Reuse Stable Descriptions For Resume And Semantics
|
||||
|
||||
CAT IDs: CAT-19, completion. Status: Pending.
|
||||
CAT IDs: CAT-19, completion. Status: Complete.
|
||||
|
||||
Read Stage 9's audit links and `prepare_resume.go`, `semantic_contracts_initial.go`.
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ func prepareInputs(ctx context.Context, env *Env, m *manifest.Manifest, acquireA
|
||||
registerInput := func(kind, path, checksum string) {
|
||||
inputs = append(inputs, manifest.InputRecord{Kind: kind, Path: path, Checksum: checksum})
|
||||
}
|
||||
products, err := describeStablePreparedProducts(env.Config, paths, sessionID, speakersSrc, speakersInput, glossaryDocuments)
|
||||
products, err := describeStablePreparedProducts(env.Config, paths, sessionID, speakersSrc, speakersInput, glossaryDocuments, true)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("prepare: %w", err)
|
||||
}
|
||||
|
||||
@@ -12,41 +12,47 @@ import (
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
)
|
||||
|
||||
type preparedComparison uint8
|
||||
|
||||
const (
|
||||
compareSourceBytes preparedComparison = iota
|
||||
compareNormalizedSnapshot
|
||||
compareDurableCopy
|
||||
)
|
||||
|
||||
type stablePreparedProduct struct {
|
||||
record manifest.InputRecord
|
||||
data []byte
|
||||
sourcePath string
|
||||
trackSize bool
|
||||
label string
|
||||
record manifest.InputRecord
|
||||
data []byte
|
||||
sourcePath string
|
||||
trackSize bool
|
||||
label string
|
||||
comparison preparedComparison
|
||||
compareSource bool
|
||||
semantic *prepareStableInputSelection
|
||||
glossaryName string
|
||||
}
|
||||
|
||||
func describeStablePreparedProducts(cfg *config.Config, paths artifacts.SessionPaths, sessionID string, speakersPath string, speakers config.ResolvedInputFile, glossaries map[string][]byte) ([]stablePreparedProduct, error) {
|
||||
campaign, err := config.RenderCampaignDocument(cfg)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("render campaign.yml: %w", err)
|
||||
}
|
||||
session, err := config.RenderSessionDocument(cfg, sessionID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("render session.yml: %w", err)
|
||||
}
|
||||
pipeline, err := renderResolvedPipeline(cfg.Pipeline)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("render pipeline.resolved.yml: %w", err)
|
||||
}
|
||||
autocorrect, err := config.RenderAutocorrection(cfg.Session.Inputs.Autocorrect)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("render autocorrection: %w", err)
|
||||
}
|
||||
// stableProductLayout describes the products without loading source content.
|
||||
func stableProductLayout(cfg *config.Config, paths artifacts.SessionPaths, speakers config.ResolvedInputFile) ([]stablePreparedProduct, error) {
|
||||
source := cfg.SessionSource
|
||||
if strings.TrimSpace(source.Source) == "" {
|
||||
source.Source = "session_config"
|
||||
}
|
||||
present := func(kind string, value bool) *prepareStableInputSelection {
|
||||
return &prepareStableInputSelection{Kind: kind, Present: value}
|
||||
}
|
||||
partySource := strings.TrimSpace(cfg.Party.Source.Source)
|
||||
if partySource == "" {
|
||||
partySource = "campaign_config"
|
||||
}
|
||||
partyPresent := strings.TrimSpace(cfg.StableInputs.PartyFile.Path) != ""
|
||||
speakersPresent := strings.TrimSpace(cfg.StableInputs.SpeakersFile.Path) != "" || strings.TrimSpace(cfg.Session.Inputs.SpeakersFile) != ""
|
||||
products := []stablePreparedProduct{
|
||||
{record: manifest.InputRecord{Kind: "campaign_config", Path: filepath.Join(paths.InputsDir, "campaign.yml"), Source: "campaign_config"}, data: campaign, label: "campaign.yml"},
|
||||
{record: manifest.InputRecord{Kind: "session_config", Path: filepath.Join(paths.InputsDir, "session.yml"), Source: source.Source, S3Bucket: source.S3Bucket, S3Key: source.S3Key, S3Size: source.S3Size, S3ETag: source.S3ETag}, data: session, label: "session.yml"},
|
||||
{record: manifest.InputRecord{Kind: "pipeline_resolved", Path: filepath.Join(paths.InputsDir, "pipeline.resolved.yml")}, data: pipeline, label: "pipeline.resolved.yml"},
|
||||
{record: manifest.InputRecord{Kind: "speakers", Path: filepath.Join(paths.InputsDir, "speakers.yml"), Source: speakers.Source}, sourcePath: speakersPath, label: "speakers"},
|
||||
{record: manifest.InputRecord{Kind: "autocorrect", Path: filepath.Join(paths.InputsDir, "autocorrect.yml"), Source: config.AutocorrectionSource(cfg)}, data: autocorrect, trackSize: true, label: "autocorrection"},
|
||||
{record: manifest.InputRecord{Kind: "campaign_config", Path: filepath.Join(paths.InputsDir, "campaign.yml"), Source: "campaign_config"}, label: "campaign.yml", comparison: compareNormalizedSnapshot},
|
||||
{record: manifest.InputRecord{Kind: "session_config", Path: filepath.Join(paths.InputsDir, "session.yml"), Source: source.Source, S3Bucket: source.S3Bucket, S3Key: source.S3Key, S3Size: source.S3Size, S3ETag: source.S3ETag}, label: "session.yml", comparison: compareNormalizedSnapshot},
|
||||
{record: manifest.InputRecord{Kind: "pipeline_resolved", Path: filepath.Join(paths.InputsDir, "pipeline.resolved.yml")}, label: "pipeline.resolved.yml", comparison: compareDurableCopy},
|
||||
{record: manifest.InputRecord{Kind: "speakers", Path: filepath.Join(paths.InputsDir, "speakers.yml"), Source: speakers.Source}, label: "speakers", semantic: present("speakers", speakersPresent)},
|
||||
{record: manifest.InputRecord{Kind: "autocorrect", Path: filepath.Join(paths.InputsDir, "autocorrect.yml"), Source: config.AutocorrectionSource(cfg)}, label: "autocorrection", trackSize: true, compareSource: true, semantic: present("autocorrect", true)},
|
||||
}
|
||||
for _, item := range []struct{ name, source string }{
|
||||
{"party", artifactpolicy.SourceInputGlossaryParty}, {"campaign", artifactpolicy.SourceInputGlossaryCampaign}, {"setting", artifactpolicy.SourceInputGlossarySetting}, {"spells", artifactpolicy.SourceInputGlossarySpells}, {"combined", artifactpolicy.SourceInputGlossaryCombined},
|
||||
@@ -61,35 +67,60 @@ func describeStablePreparedProducts(cfg *config.Config, paths artifacts.SessionP
|
||||
record.Dependencies = append(record.Dependencies, dep.SourceID)
|
||||
}
|
||||
}
|
||||
products = append(products, stablePreparedProduct{record: record, data: glossaries[item.name], trackSize: true, label: desc.ManifestKind})
|
||||
}
|
||||
party := cfg.Party
|
||||
if party.Canonical == nil {
|
||||
return nil, fmt.Errorf("canonical party data is required")
|
||||
}
|
||||
partyBytes, err := party.Canonical.YAML()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("render canonical party: %w", err)
|
||||
}
|
||||
if party.Players == nil {
|
||||
return nil, fmt.Errorf("derived players projection is required")
|
||||
}
|
||||
partySource := strings.TrimSpace(party.Source.Source)
|
||||
if partySource == "" {
|
||||
partySource = "campaign_config"
|
||||
products = append(products, stablePreparedProduct{record: record, label: desc.ManifestKind, trackSize: true, semantic: present(desc.ManifestKind, true), glossaryName: item.name})
|
||||
}
|
||||
for _, item := range []struct {
|
||||
source, provenance, label string
|
||||
data []byte
|
||||
semantic *prepareStableInputSelection
|
||||
}{
|
||||
{artifactpolicy.SourceInputParty, partySource, "canonical party", partyBytes},
|
||||
{artifactpolicy.SourceInputPlayers, "derived_from_party", "canonical players projection", party.Players},
|
||||
{artifactpolicy.SourceInputParty, partySource, "canonical party", present("party", partyPresent)},
|
||||
{artifactpolicy.SourceInputPlayers, "derived_from_party", "canonical players projection", nil},
|
||||
} {
|
||||
desc, ok := artifactpolicy.DescribePreparedInputSource(item.source)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("prepared-input descriptor %q is unavailable", item.source)
|
||||
}
|
||||
products = append(products, stablePreparedProduct{record: manifest.InputRecord{Kind: desc.ManifestKind, Path: filepath.Join(paths.InputsDir, desc.Filename), Source: item.provenance}, data: item.data, label: item.label})
|
||||
products = append(products, stablePreparedProduct{record: manifest.InputRecord{Kind: desc.ManifestKind, Path: filepath.Join(paths.InputsDir, desc.Filename), Source: item.provenance}, label: item.label, semantic: item.semantic})
|
||||
}
|
||||
return products, nil
|
||||
}
|
||||
|
||||
func describeStablePreparedProducts(cfg *config.Config, paths artifacts.SessionPaths, sessionID string, speakersPath string, speakers config.ResolvedInputFile, glossaries map[string][]byte, renderPipeline bool) ([]stablePreparedProduct, error) {
|
||||
products, err := stableProductLayout(cfg, paths, speakers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for i := range products {
|
||||
p := &products[i]
|
||||
switch p.record.Kind {
|
||||
case "campaign_config":
|
||||
p.data, err = config.RenderCampaignDocument(cfg)
|
||||
case "session_config":
|
||||
p.data, err = config.RenderSessionDocument(cfg, sessionID)
|
||||
case "pipeline_resolved":
|
||||
if renderPipeline {
|
||||
p.data, err = renderResolvedPipeline(cfg.Pipeline)
|
||||
}
|
||||
case "speakers":
|
||||
p.sourcePath = speakersPath
|
||||
case "autocorrect":
|
||||
p.data, err = config.RenderAutocorrection(cfg.Session.Inputs.Autocorrect)
|
||||
case "party":
|
||||
if cfg.Party.Canonical == nil {
|
||||
return nil, fmt.Errorf("canonical party data is required")
|
||||
}
|
||||
p.data, err = cfg.Party.Canonical.YAML()
|
||||
case "players":
|
||||
if cfg.Party.Players == nil {
|
||||
return nil, fmt.Errorf("derived players projection is required")
|
||||
}
|
||||
p.data = cfg.Party.Players
|
||||
default:
|
||||
p.data = glossaries[p.glossaryName]
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("render %s: %w", p.label, err)
|
||||
}
|
||||
}
|
||||
return products, nil
|
||||
}
|
||||
|
||||
@@ -82,7 +82,11 @@ func (prepareStage) ValidateResume(ctx context.Context, env *Env, m *manifest.Ma
|
||||
}
|
||||
}
|
||||
}
|
||||
if !preparedInputRecordsCurrent(env, paths, records) || !prepareSourceInputsMatch(paths, current, records) {
|
||||
managed, err := prepareManagedKinds(env.Config, paths)
|
||||
if err != nil {
|
||||
return NonResumable(prepareResumeChangedReason), nil
|
||||
}
|
||||
if !preparedInputRecordsCurrent(env, paths, records) || !prepareSourceInputsMatch(paths, current, records, managed) {
|
||||
return NonResumable(prepareResumeChangedReason), nil
|
||||
}
|
||||
return Resumable(), nil
|
||||
@@ -105,72 +109,45 @@ func preparedInputRecordsCurrent(env *Env, paths artifacts.SessionPaths, records
|
||||
|
||||
func currentPrepareSourceInputs(ctx context.Context, env *Env, m *manifest.Manifest) ([]prepareExpectedInput, error) {
|
||||
cfg := env.Config
|
||||
expected := make([]prepareExpectedInput, 0, 8)
|
||||
campaign, err := config.RenderCampaignDocument(cfg)
|
||||
speakers := stableInputSource(cfg.StableInputs.SpeakersFile, cfg.Session.Inputs.SpeakersFile, cfg.SessionPath)
|
||||
speakersPath, err := resolveConfigRelativePath(speakers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
session, err := config.RenderSessionDocument(cfg, m.SessionID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
campaignChecksum, err := prepareConfigSnapshotChecksum(campaign)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sessionChecksum, err := prepareConfigSnapshotChecksum(session)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
expected = append(expected, prepareExpectedInput{kind: "campaign_config", checksum: campaignChecksum, configSnapshot: true}, prepareExpectedInput{kind: "session_config", checksum: sessionChecksum, configSnapshot: true})
|
||||
appendFile := func(kind string, input config.ResolvedInputFile, fallback string) error {
|
||||
resolved := stableInputSource(input, fallback, cfg.SessionPath)
|
||||
sourcePath, err := resolveConfigRelativePath(resolved)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
checksum, err := env.ArtifactStore.Checksum(sourcePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
expected = append(expected, prepareExpectedInput{kind: kind, checksum: checksum})
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := appendFile("speakers", cfg.StableInputs.SpeakersFile, cfg.Session.Inputs.SpeakersFile); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
autocorrect, err := config.RenderAutocorrection(cfg.Session.Inputs.Autocorrect)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
expected = append(expected, prepareExpectedInput{kind: "autocorrect", checksum: checksumPrepareBytes(autocorrect), source: config.AutocorrectionSource(cfg)})
|
||||
documents, err := config.ResolveGlossaries(cfg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, item := range []struct{ name, source string }{
|
||||
{"party", artifactpolicy.SourceInputGlossaryParty}, {"campaign", artifactpolicy.SourceInputGlossaryCampaign},
|
||||
{"setting", artifactpolicy.SourceInputGlossarySetting}, {"spells", artifactpolicy.SourceInputGlossarySpells},
|
||||
{"combined", artifactpolicy.SourceInputGlossaryCombined},
|
||||
} {
|
||||
descriptor, ok := artifactpolicy.DescribePreparedInputSource(item.source)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("glossary descriptor %q unavailable", item.source)
|
||||
}
|
||||
entry := prepareExpectedInput{kind: descriptor.ManifestKind, checksum: checksumPrepareBytes(documents[item.name])}
|
||||
if item.source == artifactpolicy.SourceInputGlossaryCombined {
|
||||
for _, dependency := range artifactpolicy.GlossaryInputSources() {
|
||||
entry.dependencies = append(entry.dependencies, dependency.SourceID)
|
||||
}
|
||||
}
|
||||
expected = append(expected, entry)
|
||||
}
|
||||
partyInputs, err := currentPreparePartySourceInputs(env)
|
||||
paths := sessionPathsForEnv(env, m.SessionID)
|
||||
products, err := describeStablePreparedProducts(cfg, paths, m.SessionID, speakersPath, speakers, documents, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
expected = append(expected, partyInputs...)
|
||||
expected := make([]prepareExpectedInput, 0, len(products))
|
||||
for _, product := range products {
|
||||
if product.comparison == compareDurableCopy {
|
||||
continue
|
||||
}
|
||||
entry := prepareExpectedInput{kind: product.record.Kind, dependencies: product.record.Dependencies}
|
||||
if product.compareSource {
|
||||
entry.source = product.record.Source
|
||||
}
|
||||
switch product.comparison {
|
||||
case compareNormalizedSnapshot:
|
||||
entry.configSnapshot = true
|
||||
entry.checksum, err = prepareConfigSnapshotChecksum(product.data)
|
||||
default:
|
||||
if product.sourcePath != "" {
|
||||
entry.checksum, err = env.ArtifactStore.Checksum(product.sourcePath)
|
||||
} else {
|
||||
entry.checksum = checksumPrepareBytes(product.data)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
expected = append(expected, entry)
|
||||
}
|
||||
|
||||
if prepareNeedsAudio(env, m) {
|
||||
audioInputs, err := currentPrepareAudioSourceInputs(ctx, env, m)
|
||||
@@ -182,32 +159,6 @@ func currentPrepareSourceInputs(ctx context.Context, env *Env, m *manifest.Manif
|
||||
return expected, nil
|
||||
}
|
||||
|
||||
func currentPreparePartySourceInputs(env *Env) ([]prepareExpectedInput, error) {
|
||||
party, ok := artifactpolicy.DescribePreparedInputSource(artifactpolicy.SourceInputParty)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("party prepared-input descriptor is unavailable")
|
||||
}
|
||||
players, ok := artifactpolicy.DescribePreparedInputSource(artifactpolicy.SourceInputPlayers)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("players prepared-input descriptor is unavailable")
|
||||
}
|
||||
if env.Config.Party.Canonical == nil {
|
||||
return nil, fmt.Errorf("canonical party data is unavailable")
|
||||
}
|
||||
partyBytes, err := env.Config.Party.Canonical.YAML()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
playersBytes := env.Config.Party.Players
|
||||
if playersBytes == nil {
|
||||
return nil, fmt.Errorf("derived players projection is unavailable")
|
||||
}
|
||||
return []prepareExpectedInput{
|
||||
{kind: party.ManifestKind, checksum: checksumPrepareBytes(partyBytes)},
|
||||
{kind: players.ManifestKind, checksum: checksumPrepareBytes(playersBytes)},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func currentPrepareAudioSourceInputs(ctx context.Context, env *Env, m *manifest.Manifest) ([]prepareExpectedInput, error) {
|
||||
sessionID := strings.TrimSpace(m.SessionID)
|
||||
if sessionID == "" {
|
||||
@@ -253,16 +204,25 @@ func currentPrepareAudioSourceInputs(ctx context.Context, env *Env, m *manifest.
|
||||
return expected, nil
|
||||
}
|
||||
|
||||
func prepareSourceInputsMatch(paths artifacts.SessionPaths, expected []prepareExpectedInput, records []manifest.InputRecord) bool {
|
||||
func prepareManagedKinds(cfg *config.Config, paths artifacts.SessionPaths) (map[string]struct{}, error) {
|
||||
products, err := stableProductLayout(cfg, paths, cfg.StableInputs.SpeakersFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
kinds := map[string]struct{}{"audio": {}, "glossary": {}}
|
||||
for _, product := range products {
|
||||
if product.comparison != compareDurableCopy {
|
||||
kinds[product.record.Kind] = struct{}{}
|
||||
}
|
||||
}
|
||||
return kinds, nil
|
||||
}
|
||||
|
||||
func prepareSourceInputsMatch(paths artifacts.SessionPaths, expected []prepareExpectedInput, records []manifest.InputRecord, managedKinds map[string]struct{}) bool {
|
||||
if len(expected) == 0 {
|
||||
return false
|
||||
}
|
||||
managedKinds := map[string]struct{}{
|
||||
"campaign_config": {}, "session_config": {},
|
||||
"audio": {}, "speakers": {}, "autocorrect": {}, "glossary": {},
|
||||
"glossary_party": {}, "glossary_campaign": {}, "glossary_setting": {}, "glossary_spells": {}, "glossary_combined": {},
|
||||
"players": {}, "party": {},
|
||||
}
|
||||
|
||||
expectedCounts := make(map[string]int, len(managedKinds))
|
||||
recordCounts := make(map[string]int, len(managedKinds))
|
||||
type inputKey struct{ kind, destination string }
|
||||
|
||||
@@ -18,6 +18,11 @@ import (
|
||||
)
|
||||
|
||||
func TestPrepareResumeIndexedRecords(t *testing.T) {
|
||||
cfg := &config.Config{Session: &config.SessionConfig{}}
|
||||
managed, err := prepareManagedKinds(cfg, artifacts.SessionPaths{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
const count = 128
|
||||
inputs := make([]prepareExpectedInput, count)
|
||||
records := make([]manifest.InputRecord, count)
|
||||
@@ -44,20 +49,20 @@ func TestPrepareResumeIndexedRecords(t *testing.T) {
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
r := tc.mutate(append([]manifest.InputRecord(nil), records...))
|
||||
if got := prepareSourceInputsMatch(artifacts.SessionPaths{}, inputs, r); got != tc.valid {
|
||||
if got := prepareSourceInputsMatch(artifacts.SessionPaths{}, inputs, r, managed); got != tc.valid {
|
||||
t.Fatalf("match = %t, want %t", got, tc.valid)
|
||||
}
|
||||
})
|
||||
}
|
||||
duplicated := append([]prepareExpectedInput(nil), inputs...)
|
||||
duplicated[1] = duplicated[0]
|
||||
if prepareSourceInputsMatch(artifacts.SessionPaths{}, duplicated, records) {
|
||||
if prepareSourceInputsMatch(artifacts.SessionPaths{}, duplicated, records, managed) {
|
||||
t.Fatal("record reused")
|
||||
}
|
||||
|
||||
remote := prepareExpectedInput{kind: "audio", destinationName: "one.flac", s3Bucket: "archive", s3Key: "audio/one.flac", s3Size: 7, s3ETag: "etag"}
|
||||
record := manifest.InputRecord{Kind: "audio", Path: "audio/one.flac", Source: "s3", S3Bucket: " archive ", S3Key: " audio/one.flac ", S3Size: 7, S3ETag: " etag "}
|
||||
if !prepareSourceInputsMatch(artifacts.SessionPaths{}, []prepareExpectedInput{remote}, []manifest.InputRecord{record}) {
|
||||
if !prepareSourceInputsMatch(artifacts.SessionPaths{}, []prepareExpectedInput{remote}, []manifest.InputRecord{record}, managed) {
|
||||
t.Fatal("remote identity mismatch")
|
||||
}
|
||||
for _, field := range []string{"source", "bucket", "key", "size", "etag"} {
|
||||
@@ -75,7 +80,7 @@ func TestPrepareResumeIndexedRecords(t *testing.T) {
|
||||
case "etag":
|
||||
changed.S3ETag = "other"
|
||||
}
|
||||
if prepareSourceInputsMatch(artifacts.SessionPaths{}, []prepareExpectedInput{remote}, []manifest.InputRecord{changed}) {
|
||||
if prepareSourceInputsMatch(artifacts.SessionPaths{}, []prepareExpectedInput{remote}, []manifest.InputRecord{changed}, managed) {
|
||||
t.Fatal("changed identity accepted")
|
||||
}
|
||||
})
|
||||
@@ -87,7 +92,7 @@ func TestPrepareResumeIndexedRecords(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !prepareSourceInputsMatch(artifacts.SessionPaths{}, []prepareExpectedInput{{kind: "session_config", checksum: digest, configSnapshot: true}}, []manifest.InputRecord{{Kind: "session_config", Path: path}}) {
|
||||
if !prepareSourceInputsMatch(artifacts.SessionPaths{}, []prepareExpectedInput{{kind: "session_config", checksum: digest, configSnapshot: true}}, []manifest.InputRecord{{Kind: "session_config", Path: path}}, managed) {
|
||||
t.Fatal("equivalent snapshot rejected")
|
||||
}
|
||||
}
|
||||
@@ -138,6 +143,18 @@ func TestPrepareResumeValidatesCurrentLocalSourcesAndPreparedCopies(t *testing.T
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrepareResumeKeepsPipelineCopyWithoutComparingCurrentPipeline(t *testing.T) {
|
||||
env, m, _ := prepareResumeLocalFixture(t)
|
||||
assertPrepareResume(t, env, m, true)
|
||||
env.Config.Pipeline.WhisperX.Language = "changed-language"
|
||||
assertPrepareResume(t, env, m, true)
|
||||
pipeline := findManifestInput(t, m.Inputs, "pipeline_resolved")
|
||||
if err := os.Remove(pipeline.Path); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertPrepareResume(t, env, m, false)
|
||||
}
|
||||
|
||||
func TestPrepareResumeAcceptsRelocatedEquivalentLocalSource(t *testing.T) {
|
||||
env, m, _ := prepareResumeLocalFixture(t)
|
||||
cfgDir := filepath.Dir(env.Config.CampaignPath)
|
||||
|
||||
@@ -2,6 +2,7 @@ package stage
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/audio"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@@ -108,13 +109,17 @@ func buildPrepareSemanticConfig(env *Env) (prepareSemanticConfig, error) {
|
||||
if cfg.Party.Canonical == nil {
|
||||
return prepareSemanticConfig{}, fmt.Errorf("prepare semantic configuration requires a resolved canonical party")
|
||||
}
|
||||
stableInputs, err := prepareStableInputSemantics(cfg)
|
||||
if err != nil {
|
||||
return prepareSemanticConfig{}, err
|
||||
}
|
||||
payload := prepareSemanticConfig{
|
||||
CampaignID: strings.TrimSpace(cfg.Session.Campaign),
|
||||
SessionID: strings.TrimSpace(cfg.Session.SessionID),
|
||||
PreviousSession: strings.TrimSpace(cfg.Session.PreviousSessionID),
|
||||
PlayersSchema: config.PlayersSchemaVersion,
|
||||
Audio: prepareAudioSemantics(cfg),
|
||||
StableInputs: prepareStableInputSemantics(cfg),
|
||||
StableInputs: stableInputs,
|
||||
}
|
||||
for _, requirement := range requirements {
|
||||
entry := preparePreviousRequirement{Name: strings.TrimSpace(requirement.Name), Required: requirement.Required}
|
||||
@@ -148,25 +153,18 @@ func prepareAudioSemantics(cfg *config.Config) prepareAudioSelection {
|
||||
return selection
|
||||
}
|
||||
|
||||
func prepareStableInputSemantics(cfg *config.Config) []prepareStableInputSelection {
|
||||
stable := cfg.StableInputs
|
||||
return []prepareStableInputSelection{
|
||||
prepareStableInput("speakers", stable.SpeakersFile, cfg.Session.Inputs.SpeakersFile),
|
||||
{Kind: "autocorrect", Present: true},
|
||||
{Kind: "glossary_party", Present: true}, {Kind: "glossary_campaign", Present: true},
|
||||
{Kind: "glossary_setting", Present: true}, {Kind: "glossary_spells", Present: true},
|
||||
{Kind: "glossary_combined", Present: true},
|
||||
prepareStableInput("party", stable.PartyFile, ""),
|
||||
func prepareStableInputSemantics(cfg *config.Config) ([]prepareStableInputSelection, error) {
|
||||
products, err := stableProductLayout(cfg, artifacts.SessionPaths{}, cfg.StableInputs.SpeakersFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func prepareStableInput(kind string, resolved config.ResolvedInputFile, fallback string) prepareStableInputSelection {
|
||||
path := resolved.Path
|
||||
if strings.TrimSpace(path) == "" {
|
||||
path = fallback
|
||||
var result []prepareStableInputSelection
|
||||
for _, product := range products {
|
||||
if product.semantic != nil {
|
||||
result = append(result, *product.semantic)
|
||||
}
|
||||
}
|
||||
// Source ownership remains provenance; resume validates the selected payloads.
|
||||
return prepareStableInputSelection{Kind: kind, Present: strings.TrimSpace(path) != ""}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func cloneFloat64(value *float64) *float64 {
|
||||
|
||||
Reference in New Issue
Block a user