|
|
|
|
@@ -3,6 +3,7 @@ package stage
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"slices"
|
|
|
|
|
@@ -14,8 +15,10 @@ import (
|
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/artifactpolicy"
|
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/domaininput"
|
|
|
|
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
|
|
|
|
configkit "go.maximumdirect.net/configkit"
|
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type polishRunnerFunc func(context.Context, audita.PolishRequest) (audita.PolishResult, error)
|
|
|
|
|
@@ -82,6 +85,43 @@ func TestPolishStagePolishesMergedTranscriptAndRecordsMetadata(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestPolishUsesEverySharedGlossaryEnvelopeUnchanged(t *testing.T) {
|
|
|
|
|
env, m := setupPolishEnv(t)
|
|
|
|
|
paths := sessionPathsForEnv(env, m.SessionID)
|
|
|
|
|
root := filepath.Join(paths.Root, "scratch", "probe")
|
|
|
|
|
request, evidence, err := BuildPolishRequest(paths, m, "", filepath.Join(root, "output.json"), filepath.Join(root, "logs"), filepath.Join(root, "debug"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
process, sameEvidence, err := BuildPolishRequest(paths, m, filepath.Join(paths.TranscriptsDir, "base.json"), filepath.Join(root, "processed.json"), filepath.Join(root, "process-logs"), filepath.Join(root, "process-debug"))
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if !slices.Equal(request.GlossaryFiles, process.GlossaryFiles) || evidence != sameEvidence || len(request.GlossaryFiles) != 4 {
|
|
|
|
|
t.Fatalf("preflight/process inputs = %#v / %#v", request.GlossaryFiles, process.GlossaryFiles)
|
|
|
|
|
}
|
|
|
|
|
for index, descriptor := range artifactpolicy.GlossaryInputSources() {
|
|
|
|
|
data, err := os.ReadFile(request.GlossaryFiles[index])
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
var document map[string]any
|
|
|
|
|
if err := yaml.Unmarshal(data, &document); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if err := domaininput.ValidateGlossary(document); err != nil {
|
|
|
|
|
t.Fatalf("%s: %v", descriptor.SourceID, err)
|
|
|
|
|
}
|
|
|
|
|
collection := strings.TrimPrefix(descriptor.SourceID, "narratio.input.glossary.")
|
|
|
|
|
collections := document["collections"].(map[string]any)
|
|
|
|
|
value := collections[collection].(map[string]any)
|
|
|
|
|
entries, ok := value["entries"].([]any)
|
|
|
|
|
if !ok || len(entries) != 0 || value["instruction"] != "synthetic extension data" {
|
|
|
|
|
t.Fatalf("shared collection = %#v", value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestPolishStageRejectsIncidentalMergedTranscriptPath(t *testing.T) {
|
|
|
|
|
env, m := setupPolishEnv(t)
|
|
|
|
|
paths := sessionPathsForEnv(env, m.SessionID)
|
|
|
|
|
@@ -172,11 +212,12 @@ func TestPolishStageDoesNotPromoteTranscriptAfterAdapterFailure(t *testing.T) {
|
|
|
|
|
writeFile(t, mergedPath, `{"segments":[]}`)
|
|
|
|
|
setCurrentBuiltInEvidence(t, m, "merge", artifacts.TranscriptOutputKindBase, artifacts.ArtifactTranscriptBase, mergedPath)
|
|
|
|
|
failure := errors.New("audita exited after output")
|
|
|
|
|
var runOutput string
|
|
|
|
|
var runOutput, reportPath string
|
|
|
|
|
env.Audita = polishRunnerFunc(func(_ context.Context, req audita.PolishRequest) (audita.PolishResult, error) {
|
|
|
|
|
runOutput = req.OutputProcessedPath
|
|
|
|
|
writeFile(t, runOutput, `{"segments":[]}`)
|
|
|
|
|
writeFile(t, filepath.Join(filepath.Dir(runOutput), "errors.yml"), "status: failed\n")
|
|
|
|
|
reportPath = filepath.Join(req.ReportDir, "errors.yml")
|
|
|
|
|
writeFile(t, reportPath, "status: failed\n")
|
|
|
|
|
return audita.PolishResult{ProcessedTranscriptPath: runOutput}, failure
|
|
|
|
|
})
|
|
|
|
|
_, err := (polishStage{}).Run(context.Background(), env, m)
|
|
|
|
|
@@ -186,7 +227,7 @@ func TestPolishStageDoesNotPromoteTranscriptAfterAdapterFailure(t *testing.T) {
|
|
|
|
|
if _, err := os.Stat(filepath.Join(paths.TranscriptsDir, "polished.json")); !errors.Is(err, os.ErrNotExist) {
|
|
|
|
|
t.Fatalf("failed output was promoted: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if _, err := os.Stat(filepath.Join(filepath.Dir(runOutput), "errors.yml")); err != nil {
|
|
|
|
|
if _, err := os.Stat(reportPath); err != nil {
|
|
|
|
|
t.Fatalf("run-local diagnostic missing: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -305,7 +346,8 @@ func setupPolishEnv(t *testing.T) (*Env, *manifest.Manifest) {
|
|
|
|
|
paths := sessionPathsForEnv(env, m.SessionID)
|
|
|
|
|
for _, desc := range artifactpolicy.GlossaryInputSources() {
|
|
|
|
|
path := filepath.Join(paths.InputsDir, desc.Filename)
|
|
|
|
|
writeFile(t, path, "synthetic: {entries: []}\n")
|
|
|
|
|
collection := strings.TrimPrefix(desc.SourceID, "narratio.input.glossary.")
|
|
|
|
|
writeFile(t, path, fmt.Sprintf("schema_version: maximumdirect.glossary.v1\ncollections:\n %s:\n instruction: synthetic extension data\n entries: []\n", collection))
|
|
|
|
|
checksum, err := store.Checksum(path)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
@@ -333,7 +375,7 @@ func TestPolishResumeRequiresMatchingPreparedGlossaries(t *testing.T) {
|
|
|
|
|
t.Fatalf("reuse: %+v %v", state, err)
|
|
|
|
|
}
|
|
|
|
|
file := filepath.Join(paths.InputsDir, "glossaries", "campaign.yml")
|
|
|
|
|
writeFile(t, file, "campaign: {entries: [{id: a, name: A, category: place}]}\n")
|
|
|
|
|
writeFile(t, file, "schema_version: maximumdirect.glossary.v1\ncollections:\n campaign: {entries: [{id: a, name: A, category: place}]}\n")
|
|
|
|
|
state, err = (polishStage{}).ValidateResume(context.Background(), env, m)
|
|
|
|
|
if err != nil || state.Resumable {
|
|
|
|
|
t.Fatalf("changed: %+v %v", state, err)
|
|
|
|
|
|