Fixed a path-duplication bug and added regression coverage
This commit is contained in:
@@ -190,9 +190,7 @@ func discoverRawTranscripts(m *manifest.Manifest, paths artifacts.SessionPaths)
|
||||
if p == "" {
|
||||
continue
|
||||
}
|
||||
if !filepath.IsAbs(p) {
|
||||
p = filepath.Join(paths.Root, p)
|
||||
}
|
||||
p = artifacts.ResolveSessionLocalPathForRead(paths, p)
|
||||
fromManifest = append(fromManifest, filepath.Clean(p))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package stage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -153,9 +154,90 @@ func TestMergeStageFallsBackToRawDirectoryWhenTranscribeOutputsMissing(t *testin
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeStageResolvesWorkspaceQualifiedManifestOutputsWithoutDuplication(t *testing.T) {
|
||||
env, m := setupMergeEnvWithRelativeWorkspaceRoot(t)
|
||||
paths := env.ArtifactStore.SessionPaths(m.SessionID)
|
||||
|
||||
rawPath := filepath.Join(paths.TranscriptsRawDir, "alice.json")
|
||||
writeFile(t, rawPath, `{"segments":[]}`)
|
||||
writeFile(t, filepath.Join(paths.InputsDir, "speakers.yml"), "match: []\n")
|
||||
writeFile(t, filepath.Join(paths.InputsDir, "autocorrect.yml"), "rules: []\n")
|
||||
|
||||
m.MarkStageSucceeded("transcribe", time.Now().UTC(), []manifest.ArtifactRecord{
|
||||
{Kind: "transcript_raw", LocalPath: filepath.Join(env.Config.Pipeline.Workspace.Root, "work", m.SessionID, "transcripts", "raw", "alice.json")},
|
||||
})
|
||||
|
||||
fake := &seriatim.FakeRunner{}
|
||||
env.Seriatim = fake
|
||||
|
||||
if _, err := (mergeStage{}).Run(context.Background(), env, m); err != nil {
|
||||
t.Fatalf("merge.Run() error = %v", err)
|
||||
}
|
||||
if len(fake.Requests) != 1 {
|
||||
t.Fatalf("fake requests = %d, want 1", len(fake.Requests))
|
||||
}
|
||||
got := fake.Requests[0].InputTranscriptPaths
|
||||
if len(got) != 1 {
|
||||
t.Fatalf("input transcript paths = %#v, want len 1", got)
|
||||
}
|
||||
if got[0] != filepath.Clean(rawPath) {
|
||||
t.Fatalf("resolved transcript path = %q, want %q", got[0], filepath.Clean(rawPath))
|
||||
}
|
||||
}
|
||||
|
||||
func TestMergeStageResolvesSessionRelativeManifestOutputs(t *testing.T) {
|
||||
env, m := setupMergeEnv(t)
|
||||
paths := env.ArtifactStore.SessionPaths(m.SessionID)
|
||||
|
||||
rawPath := filepath.Join(paths.TranscriptsRawDir, "alice.json")
|
||||
writeFile(t, rawPath, `{"segments":[]}`)
|
||||
writeFile(t, filepath.Join(paths.InputsDir, "speakers.yml"), "match: []\n")
|
||||
writeFile(t, filepath.Join(paths.InputsDir, "autocorrect.yml"), "rules: []\n")
|
||||
|
||||
m.MarkStageSucceeded("transcribe", time.Now().UTC(), []manifest.ArtifactRecord{
|
||||
{Kind: "transcript_raw", LocalPath: filepath.Join("transcripts", "raw", "alice.json")},
|
||||
})
|
||||
|
||||
fake := &seriatim.FakeRunner{}
|
||||
env.Seriatim = fake
|
||||
|
||||
if _, err := (mergeStage{}).Run(context.Background(), env, m); err != nil {
|
||||
t.Fatalf("merge.Run() error = %v", err)
|
||||
}
|
||||
if len(fake.Requests) != 1 {
|
||||
t.Fatalf("fake requests = %d, want 1", len(fake.Requests))
|
||||
}
|
||||
got := fake.Requests[0].InputTranscriptPaths
|
||||
if len(got) != 1 {
|
||||
t.Fatalf("input transcript paths = %#v, want len 1", got)
|
||||
}
|
||||
if got[0] != filepath.Clean(rawPath) {
|
||||
t.Fatalf("resolved transcript path = %q, want %q", got[0], filepath.Clean(rawPath))
|
||||
}
|
||||
}
|
||||
|
||||
func setupMergeEnv(t *testing.T) (*Env, *manifest.Manifest) {
|
||||
t.Helper()
|
||||
workspace := t.TempDir()
|
||||
return setupMergeEnvWithWorkspace(t, workspace)
|
||||
}
|
||||
|
||||
func setupMergeEnvWithRelativeWorkspaceRoot(t *testing.T) (*Env, *manifest.Manifest) {
|
||||
t.Helper()
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatalf("Getwd() error = %v", err)
|
||||
}
|
||||
workspaceAbs := t.TempDir()
|
||||
workspaceRel, err := filepath.Rel(cwd, workspaceAbs)
|
||||
if err != nil {
|
||||
t.Fatalf("Rel() error = %v", err)
|
||||
}
|
||||
return setupMergeEnvWithWorkspace(t, workspaceRel)
|
||||
}
|
||||
|
||||
func setupMergeEnvWithWorkspace(t *testing.T, workspace string) (*Env, *manifest.Manifest) {
|
||||
t.Helper()
|
||||
cfgDir := t.TempDir()
|
||||
sessionPath := filepath.Join(cfgDir, "session.yml")
|
||||
pipelinePath := filepath.Join(cfgDir, "pipeline.yml")
|
||||
|
||||
Reference in New Issue
Block a user