Publish and restore prepared glossary documents
This commit is contained in:
@@ -343,7 +343,12 @@ Retain existing per-speaker and per-artifact resume behavior.
|
|||||||
|
|
||||||
## Stage 9. Carry the new prepared inputs through publish and restore
|
## Stage 9. Carry the new prepared inputs through publish and restore
|
||||||
|
|
||||||
Status: Pending
|
Status: Complete
|
||||||
|
|
||||||
|
Publish archives verified prepared glossary bytes using shared descriptors;
|
||||||
|
restore maps committed objects back to their nested canonical paths. Focused
|
||||||
|
publish and restore tests pass, including all four documents, empty roles,
|
||||||
|
changed local bytes, restored manifest evidence, and existing restore guards.
|
||||||
|
|
||||||
Read `stage/publish_sources.go`, prepared publication tests, artifact current
|
Read `stage/publish_sources.go`, prepared publication tests, artifact current
|
||||||
state mapping, and app restore planning/execution tests. Register the four input
|
state mapping, and app restore planning/execution tests. Register the four input
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
"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"
|
||||||
@@ -18,6 +19,7 @@ import (
|
|||||||
func TestPreparedSessionPublishAndRemoteLoad(t *testing.T) {
|
func TestPreparedSessionPublishAndRemoteLoad(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, t.TempDir())
|
pipelinePath, campaignPath, sessionPath := writeValidConfigFiles(t, t.TempDir())
|
||||||
|
mustWriteTestFile(t, filepath.Join(filepath.Dir(campaignPath), "glossary.yml"), "campaign: {entries: [{id: watch, name: Watch, category: organization}]}\n")
|
||||||
fragment := filepath.Join(filepath.Dir(sessionPath), "fragment.yml")
|
fragment := filepath.Join(filepath.Dir(sessionPath), "fragment.yml")
|
||||||
mustWriteTestFile(t, sessionPath, "config:\n imports:\n - path: fragment.yml\nsession_id: 2026-05-03\n")
|
mustWriteTestFile(t, sessionPath, "config:\n imports:\n - path: fragment.yml\nsession_id: 2026-05-03\n")
|
||||||
mustWriteTestFile(t, fragment, "title: Published title\ninputs: {audio_dir: audio}\n")
|
mustWriteTestFile(t, fragment, "title: Published title\ninputs: {audio_dir: audio}\n")
|
||||||
@@ -68,7 +70,7 @@ func TestPreparedSessionPublishAndRemoteLoad(t *testing.T) {
|
|||||||
if got := string(fake.Objects[key].Data); !strings.Contains(got, "Published title") || strings.Contains(got, "imports:") || strings.Contains(got, "speakers_file:") {
|
if got := string(fake.Objects[key].Data); !strings.Contains(got, "Published title") || strings.Contains(got, "imports:") || strings.Contains(got, "speakers_file:") {
|
||||||
t.Fatalf("published session = %q", got)
|
t.Fatalf("published session = %q", got)
|
||||||
}
|
}
|
||||||
for _, name := range []string{"campaign.yml", "party.yml"} {
|
for _, name := range []string{"campaign.yml", "party.yml", "glossaries/party.yml", "glossaries/campaign.yml", "glossaries/setting.yml", "glossaries/spells.yml"} {
|
||||||
key := artifacts.S3RunRelativeDestinationKey(artifacts.S3RunPrefix(prefix, m.RunID), "prepare/inputs/"+name)
|
key := artifacts.S3RunRelativeDestinationKey(artifacts.S3RunPrefix(prefix, m.RunID), "prepare/inputs/"+name)
|
||||||
if data := fake.Objects[key].Data; len(data) == 0 || strings.Contains(string(data), "imports:") {
|
if data := fake.Objects[key].Data; len(data) == 0 || strings.Contains(string(data), "imports:") {
|
||||||
t.Fatalf("published %s = %q", name, data)
|
t.Fatalf("published %s = %q", name, data)
|
||||||
@@ -96,7 +98,8 @@ func TestPreparedSessionPublishAndRemoteLoad(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
want := map[string]bool{"inputs/session.yml": false, "inputs/campaign.yml": false, "inputs/party.yml": false}
|
want := map[string]bool{"inputs/session.yml": false, "inputs/campaign.yml": false, "inputs/party.yml": false,
|
||||||
|
"inputs/glossaries/party.yml": false, "inputs/glossaries/campaign.yml": false, "inputs/glossaries/setting.yml": false, "inputs/glossaries/spells.yml": false}
|
||||||
for _, action := range plan.Actions {
|
for _, action := range plan.Actions {
|
||||||
if _, ok := want[action.LocalRelativePath]; ok {
|
if _, ok := want[action.LocalRelativePath]; ok {
|
||||||
want[action.LocalRelativePath] = true
|
want[action.LocalRelativePath] = true
|
||||||
@@ -108,7 +111,13 @@ func TestPreparedSessionPublishAndRemoteLoad(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
paths := store.SessionPathsFor(m.Campaign, m.SessionID)
|
paths := store.SessionPathsFor(m.Campaign, m.SessionID)
|
||||||
for _, name := range []string{"session.yml", "campaign.yml", "party.yml"} {
|
for _, name := range []string{"session.yml", "campaign.yml", "party.yml", "glossaries/party.yml", "glossaries/campaign.yml", "glossaries/setting.yml", "glossaries/spells.yml"} {
|
||||||
|
if name == "glossaries/campaign.yml" {
|
||||||
|
if err := os.WriteFile(filepath.Join(paths.InputsDir, name), []byte("local change"), 0644); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
if err := os.Remove(filepath.Join(paths.InputsDir, name)); err != nil {
|
if err := os.Remove(filepath.Join(paths.InputsDir, name)); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -121,6 +130,22 @@ func TestPreparedSessionPublishAndRemoteLoad(t *testing.T) {
|
|||||||
if err != nil || string(restored) != string(fake.Objects[key].Data) {
|
if err != nil || string(restored) != string(fake.Objects[key].Data) {
|
||||||
t.Fatalf("restored session = %q, %v", restored, err)
|
t.Fatalf("restored session = %q, %v", restored, err)
|
||||||
}
|
}
|
||||||
|
for _, name := range []string{"party", "campaign", "setting", "spells"} {
|
||||||
|
sourceKey := artifacts.S3RunRelativeDestinationKey(artifacts.S3RunPrefix(prefix, m.RunID), "prepare/inputs/glossaries/"+name+".yml")
|
||||||
|
local, err := os.ReadFile(filepath.Join(paths.InputsDir, "glossaries", name+".yml"))
|
||||||
|
if err != nil || string(local) != string(fake.Objects[sourceKey].Data) {
|
||||||
|
t.Fatalf("restored glossary %s: %v", name, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
restoredManifest, err := (&manifest.LocalStore{}).Load(ctx, paths.ManifestPath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
for _, descriptor := range artifactpolicy.GlossaryInputSources() {
|
||||||
|
if _, err := artifacts.ResolvePreparedInput(paths, restoredManifest, descriptor.SourceID); err != nil {
|
||||||
|
t.Fatalf("restored evidence %s: %v", descriptor.SourceID, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
committedBytes := string(fake.Objects[key].Data)
|
committedBytes := string(fake.Objects[key].Data)
|
||||||
if err := invokeNativeCommandWith(ctx, []string{"session", "init", m.SessionID, "--config", pipelinePath, "--campaign-file", campaignPath, "--remote", "--force", "--title", "Updated title", "--audio-s3-prefix", "replacement/"}, &output, executePlan, deps); err != nil {
|
if err := invokeNativeCommandWith(ctx, []string{"session", "init", m.SessionID, "--config", pipelinePath, "--campaign-file", campaignPath, "--remote", "--force", "--title", "Updated title", "--audio-s3-prefix", "replacement/"}, &output, executePlan, deps); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
"gitea.maximumdirect.net/eric/narratio/internal/adapters/storage"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/pathsafe"
|
"gitea.maximumdirect.net/eric/narratio/internal/pathsafe"
|
||||||
@@ -181,8 +182,11 @@ func restoreLocalRelativePathForCommittedArtifact(sessionPrefix string, artifact
|
|||||||
return config.PathManifestFile, true, nil
|
return config.PathManifestFile, true, nil
|
||||||
}
|
}
|
||||||
if artifact.Type == artifacts.RemoteArtifactTypeRunFile {
|
if artifact.Type == artifacts.RemoteArtifactTypeRunFile {
|
||||||
switch artifact.Source {
|
prepared := map[string]bool{"run:prepare/inputs/session.yml": true, "run:prepare/inputs/campaign.yml": true, "run:prepare/inputs/party.yml": true}
|
||||||
case "run:prepare/inputs/session.yml", "run:prepare/inputs/campaign.yml", "run:prepare/inputs/party.yml":
|
for _, descriptor := range artifactpolicy.GlossaryInputSources() {
|
||||||
|
prepared["run:prepare/inputs/"+descriptor.Filename] = true
|
||||||
|
}
|
||||||
|
if prepared[artifact.Source] {
|
||||||
identity, err := artifacts.ParseImmutableRunObjectKey(sessionPrefix, artifact.DestinationKey)
|
identity, err := artifacts.ParseImmutableRunObjectKey(sessionPrefix, artifact.DestinationKey)
|
||||||
if err != nil || "run:"+identity.RelativePath != artifact.Source {
|
if err != nil || "run:"+identity.RelativePath != artifact.Source {
|
||||||
return "", false, fmt.Errorf("prepared input does not match its run object key")
|
return "", false, fmt.Errorf("prepared input does not match its run object key")
|
||||||
|
|||||||
@@ -223,6 +223,14 @@ var preparedInputSources = map[string]PreparedInputSourceDescriptor{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GlossaryInputSources returns the four shared glossary descriptors in consumer order.
|
||||||
|
func GlossaryInputSources() []PreparedInputSourceDescriptor {
|
||||||
|
return []PreparedInputSourceDescriptor{
|
||||||
|
preparedInputSources[SourceInputGlossaryParty], preparedInputSources[SourceInputGlossaryCampaign],
|
||||||
|
preparedInputSources[SourceInputGlossarySetting], preparedInputSources[SourceInputGlossarySpells],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// DescribePreparedInputSource returns the canonical descriptor for a prepared
|
// DescribePreparedInputSource returns the canonical descriptor for a prepared
|
||||||
// stable input source.
|
// stable input source.
|
||||||
func DescribePreparedInputSource(source string) (PreparedInputSourceDescriptor, bool) {
|
func DescribePreparedInputSource(source string) (PreparedInputSourceDescriptor, bool) {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ func TestPublishPreparedInputsRetainVerifiedBytesAndRejectTampering(t *testing.T
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if len(files) != 3 {
|
if len(files) != 7 {
|
||||||
t.Fatalf("prepared archive files = %d", len(files))
|
t.Fatalf("prepared archive files = %d", len(files))
|
||||||
}
|
}
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
|
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
|
||||||
@@ -29,12 +30,22 @@ type publishUploadFile struct {
|
|||||||
// archive, retaining their manifest checksums for the ordinary upload path.
|
// archive, retaining their manifest checksums for the ordinary upload path.
|
||||||
func collectPublishPreparedInputs(store artifacts.Store, paths artifacts.SessionPaths, runRoot string, records []manifest.InputRecord) ([]publishUploadFile, error) {
|
func collectPublishPreparedInputs(store artifacts.Store, paths artifacts.SessionPaths, runRoot string, records []manifest.InputRecord) ([]publishUploadFile, error) {
|
||||||
filenames := map[string]string{"session_config": "session.yml", "campaign_config": "campaign.yml", "party": "party.yml"}
|
filenames := map[string]string{"session_config": "session.yml", "campaign_config": "campaign.yml", "party": "party.yml"}
|
||||||
|
glossaries := map[string]artifactpolicy.PreparedInputSourceDescriptor{}
|
||||||
|
for _, descriptor := range artifactpolicy.GlossaryInputSources() {
|
||||||
|
filenames[descriptor.ManifestKind] = descriptor.Filename
|
||||||
|
glossaries[descriptor.ManifestKind] = descriptor
|
||||||
|
}
|
||||||
var result []publishUploadFile
|
var result []publishUploadFile
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
name, ok := filenames[record.Kind]
|
name, ok := filenames[record.Kind]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if descriptor, ok := glossaries[record.Kind]; ok {
|
||||||
|
if _, err := artifacts.ResolvePreparedInput(paths, &manifest.Manifest{Inputs: records}, descriptor.SourceID); err != nil {
|
||||||
|
return nil, fmt.Errorf("verify prepared glossary: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
rel, err := pathsafe.SlashRelativeFromRoot(paths.Root, record.Path)
|
rel, err := pathsafe.SlashRelativeFromRoot(paths.Root, record.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user