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
|
## Key Behavior
|
||||||
|
|
||||||
A stage-owned stable-product inventory supplies the data, destinations, and
|
A stage-owned stable-product inventory supplies the data, destinations, and
|
||||||
manifest provenance for reference materialization. Audio and previous-session
|
manifest provenance for reference materialization. Resume projects source
|
||||||
hydration are handled separately.
|
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.
|
- validates required config/store state and resolves selected vocabulary before audio work.
|
||||||
- prepares references and history without acquiring audio when a validated
|
- 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
|
remediation. Shared code does not make a refactoring a prerequisite or assign
|
||||||
the whole finding to a roadmap.
|
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,
|
planning, prerequisite-history, publication-import, CLI classification,
|
||||||
inspection aggregation, test maintenance, dead-code removal, and associated
|
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
|
an agreed remedy awaiting implementation. **Potentially eliminated** requires verification that the offending
|
||||||
lifecycle is removed. **Coordinate** identifies shared changes, not a commitment
|
lifecycle is removed. **Coordinate** identifies shared changes, not a commitment
|
||||||
that a related feature implements the entire finding. Findings close only after their
|
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
|
### 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)
|
**Disposition / owner.** Coordinate — [reference preparation](../../internal/stage-prepare.md)
|
||||||
supports imported products and reuse. Review the shared stable-product description
|
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
|
## 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`.
|
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) {
|
registerInput := func(kind, path, checksum string) {
|
||||||
inputs = append(inputs, manifest.InputRecord{Kind: kind, Path: path, Checksum: checksum})
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("prepare: %w", err)
|
return nil, fmt.Errorf("prepare: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,41 +12,47 @@ import (
|
|||||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type preparedComparison uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
compareSourceBytes preparedComparison = iota
|
||||||
|
compareNormalizedSnapshot
|
||||||
|
compareDurableCopy
|
||||||
|
)
|
||||||
|
|
||||||
type stablePreparedProduct struct {
|
type stablePreparedProduct struct {
|
||||||
record manifest.InputRecord
|
record manifest.InputRecord
|
||||||
data []byte
|
data []byte
|
||||||
sourcePath string
|
sourcePath string
|
||||||
trackSize bool
|
trackSize bool
|
||||||
label string
|
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) {
|
// stableProductLayout describes the products without loading source content.
|
||||||
campaign, err := config.RenderCampaignDocument(cfg)
|
func stableProductLayout(cfg *config.Config, paths artifacts.SessionPaths, speakers config.ResolvedInputFile) ([]stablePreparedProduct, error) {
|
||||||
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)
|
|
||||||
}
|
|
||||||
source := cfg.SessionSource
|
source := cfg.SessionSource
|
||||||
if strings.TrimSpace(source.Source) == "" {
|
if strings.TrimSpace(source.Source) == "" {
|
||||||
source.Source = "session_config"
|
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{
|
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: "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}, data: session, label: "session.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}, label: "session.yml", comparison: compareNormalizedSnapshot},
|
||||||
{record: manifest.InputRecord{Kind: "pipeline_resolved", Path: filepath.Join(paths.InputsDir, "pipeline.resolved.yml")}, data: pipeline, label: "pipeline.resolved.yml"},
|
{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}, sourcePath: speakersPath, label: "speakers"},
|
{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)}, data: autocorrect, trackSize: true, label: "autocorrection"},
|
{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 }{
|
for _, item := range []struct{ name, source string }{
|
||||||
{"party", artifactpolicy.SourceInputGlossaryParty}, {"campaign", artifactpolicy.SourceInputGlossaryCampaign}, {"setting", artifactpolicy.SourceInputGlossarySetting}, {"spells", artifactpolicy.SourceInputGlossarySpells}, {"combined", artifactpolicy.SourceInputGlossaryCombined},
|
{"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)
|
record.Dependencies = append(record.Dependencies, dep.SourceID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
products = append(products, stablePreparedProduct{record: record, data: glossaries[item.name], trackSize: true, label: desc.ManifestKind})
|
products = append(products, stablePreparedProduct{record: record, label: desc.ManifestKind, trackSize: true, semantic: present(desc.ManifestKind, true), glossaryName: item.name})
|
||||||
}
|
|
||||||
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"
|
|
||||||
}
|
}
|
||||||
for _, item := range []struct {
|
for _, item := range []struct {
|
||||||
source, provenance, label string
|
source, provenance, label string
|
||||||
data []byte
|
semantic *prepareStableInputSelection
|
||||||
}{
|
}{
|
||||||
{artifactpolicy.SourceInputParty, partySource, "canonical party", partyBytes},
|
{artifactpolicy.SourceInputParty, partySource, "canonical party", present("party", partyPresent)},
|
||||||
{artifactpolicy.SourceInputPlayers, "derived_from_party", "canonical players projection", party.Players},
|
{artifactpolicy.SourceInputPlayers, "derived_from_party", "canonical players projection", nil},
|
||||||
} {
|
} {
|
||||||
desc, ok := artifactpolicy.DescribePreparedInputSource(item.source)
|
desc, ok := artifactpolicy.DescribePreparedInputSource(item.source)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("prepared-input descriptor %q is unavailable", item.source)
|
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
|
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 NonResumable(prepareResumeChangedReason), nil
|
||||||
}
|
}
|
||||||
return Resumable(), 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) {
|
func currentPrepareSourceInputs(ctx context.Context, env *Env, m *manifest.Manifest) ([]prepareExpectedInput, error) {
|
||||||
cfg := env.Config
|
cfg := env.Config
|
||||||
expected := make([]prepareExpectedInput, 0, 8)
|
speakers := stableInputSource(cfg.StableInputs.SpeakersFile, cfg.Session.Inputs.SpeakersFile, cfg.SessionPath)
|
||||||
campaign, err := config.RenderCampaignDocument(cfg)
|
speakersPath, err := resolveConfigRelativePath(speakers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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)
|
documents, err := config.ResolveGlossaries(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for _, item := range []struct{ name, source string }{
|
paths := sessionPathsForEnv(env, m.SessionID)
|
||||||
{"party", artifactpolicy.SourceInputGlossaryParty}, {"campaign", artifactpolicy.SourceInputGlossaryCampaign},
|
products, err := describeStablePreparedProducts(cfg, paths, m.SessionID, speakersPath, speakers, documents, false)
|
||||||
{"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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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) {
|
if prepareNeedsAudio(env, m) {
|
||||||
audioInputs, err := currentPrepareAudioSourceInputs(ctx, 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
|
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) {
|
func currentPrepareAudioSourceInputs(ctx context.Context, env *Env, m *manifest.Manifest) ([]prepareExpectedInput, error) {
|
||||||
sessionID := strings.TrimSpace(m.SessionID)
|
sessionID := strings.TrimSpace(m.SessionID)
|
||||||
if sessionID == "" {
|
if sessionID == "" {
|
||||||
@@ -253,16 +204,25 @@ func currentPrepareAudioSourceInputs(ctx context.Context, env *Env, m *manifest.
|
|||||||
return expected, nil
|
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 {
|
if len(expected) == 0 {
|
||||||
return false
|
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))
|
expectedCounts := make(map[string]int, len(managedKinds))
|
||||||
recordCounts := make(map[string]int, len(managedKinds))
|
recordCounts := make(map[string]int, len(managedKinds))
|
||||||
type inputKey struct{ kind, destination string }
|
type inputKey struct{ kind, destination string }
|
||||||
|
|||||||
@@ -18,6 +18,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestPrepareResumeIndexedRecords(t *testing.T) {
|
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
|
const count = 128
|
||||||
inputs := make([]prepareExpectedInput, count)
|
inputs := make([]prepareExpectedInput, count)
|
||||||
records := make([]manifest.InputRecord, count)
|
records := make([]manifest.InputRecord, count)
|
||||||
@@ -44,20 +49,20 @@ func TestPrepareResumeIndexedRecords(t *testing.T) {
|
|||||||
} {
|
} {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
r := tc.mutate(append([]manifest.InputRecord(nil), records...))
|
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)
|
t.Fatalf("match = %t, want %t", got, tc.valid)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
duplicated := append([]prepareExpectedInput(nil), inputs...)
|
duplicated := append([]prepareExpectedInput(nil), inputs...)
|
||||||
duplicated[1] = duplicated[0]
|
duplicated[1] = duplicated[0]
|
||||||
if prepareSourceInputsMatch(artifacts.SessionPaths{}, duplicated, records) {
|
if prepareSourceInputsMatch(artifacts.SessionPaths{}, duplicated, records, managed) {
|
||||||
t.Fatal("record reused")
|
t.Fatal("record reused")
|
||||||
}
|
}
|
||||||
|
|
||||||
remote := prepareExpectedInput{kind: "audio", destinationName: "one.flac", s3Bucket: "archive", s3Key: "audio/one.flac", s3Size: 7, s3ETag: "etag"}
|
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 "}
|
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")
|
t.Fatal("remote identity mismatch")
|
||||||
}
|
}
|
||||||
for _, field := range []string{"source", "bucket", "key", "size", "etag"} {
|
for _, field := range []string{"source", "bucket", "key", "size", "etag"} {
|
||||||
@@ -75,7 +80,7 @@ func TestPrepareResumeIndexedRecords(t *testing.T) {
|
|||||||
case "etag":
|
case "etag":
|
||||||
changed.S3ETag = "other"
|
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")
|
t.Fatal("changed identity accepted")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -87,7 +92,7 @@ func TestPrepareResumeIndexedRecords(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
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")
|
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) {
|
func TestPrepareResumeAcceptsRelocatedEquivalentLocalSource(t *testing.T) {
|
||||||
env, m, _ := prepareResumeLocalFixture(t)
|
env, m, _ := prepareResumeLocalFixture(t)
|
||||||
cfgDir := filepath.Dir(env.Config.CampaignPath)
|
cfgDir := filepath.Dir(env.Config.CampaignPath)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package stage
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/audio"
|
"gitea.maximumdirect.net/eric/narratio/internal/audio"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sort"
|
"sort"
|
||||||
@@ -108,13 +109,17 @@ func buildPrepareSemanticConfig(env *Env) (prepareSemanticConfig, error) {
|
|||||||
if cfg.Party.Canonical == nil {
|
if cfg.Party.Canonical == nil {
|
||||||
return prepareSemanticConfig{}, fmt.Errorf("prepare semantic configuration requires a resolved canonical party")
|
return prepareSemanticConfig{}, fmt.Errorf("prepare semantic configuration requires a resolved canonical party")
|
||||||
}
|
}
|
||||||
|
stableInputs, err := prepareStableInputSemantics(cfg)
|
||||||
|
if err != nil {
|
||||||
|
return prepareSemanticConfig{}, err
|
||||||
|
}
|
||||||
payload := prepareSemanticConfig{
|
payload := prepareSemanticConfig{
|
||||||
CampaignID: strings.TrimSpace(cfg.Session.Campaign),
|
CampaignID: strings.TrimSpace(cfg.Session.Campaign),
|
||||||
SessionID: strings.TrimSpace(cfg.Session.SessionID),
|
SessionID: strings.TrimSpace(cfg.Session.SessionID),
|
||||||
PreviousSession: strings.TrimSpace(cfg.Session.PreviousSessionID),
|
PreviousSession: strings.TrimSpace(cfg.Session.PreviousSessionID),
|
||||||
PlayersSchema: config.PlayersSchemaVersion,
|
PlayersSchema: config.PlayersSchemaVersion,
|
||||||
Audio: prepareAudioSemantics(cfg),
|
Audio: prepareAudioSemantics(cfg),
|
||||||
StableInputs: prepareStableInputSemantics(cfg),
|
StableInputs: stableInputs,
|
||||||
}
|
}
|
||||||
for _, requirement := range requirements {
|
for _, requirement := range requirements {
|
||||||
entry := preparePreviousRequirement{Name: strings.TrimSpace(requirement.Name), Required: requirement.Required}
|
entry := preparePreviousRequirement{Name: strings.TrimSpace(requirement.Name), Required: requirement.Required}
|
||||||
@@ -148,25 +153,18 @@ func prepareAudioSemantics(cfg *config.Config) prepareAudioSelection {
|
|||||||
return selection
|
return selection
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareStableInputSemantics(cfg *config.Config) []prepareStableInputSelection {
|
func prepareStableInputSemantics(cfg *config.Config) ([]prepareStableInputSelection, error) {
|
||||||
stable := cfg.StableInputs
|
products, err := stableProductLayout(cfg, artifacts.SessionPaths{}, cfg.StableInputs.SpeakersFile)
|
||||||
return []prepareStableInputSelection{
|
if err != nil {
|
||||||
prepareStableInput("speakers", stable.SpeakersFile, cfg.Session.Inputs.SpeakersFile),
|
return nil, err
|
||||||
{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, ""),
|
|
||||||
}
|
}
|
||||||
}
|
var result []prepareStableInputSelection
|
||||||
|
for _, product := range products {
|
||||||
func prepareStableInput(kind string, resolved config.ResolvedInputFile, fallback string) prepareStableInputSelection {
|
if product.semantic != nil {
|
||||||
path := resolved.Path
|
result = append(result, *product.semantic)
|
||||||
if strings.TrimSpace(path) == "" {
|
|
||||||
path = fallback
|
|
||||||
}
|
}
|
||||||
// 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 {
|
func cloneFloat64(value *float64) *float64 {
|
||||||
|
|||||||
Reference in New Issue
Block a user