package claude import ( "context" "os" "path/filepath" "strings" "testing" "git.a-wan.net/alan/pipelines/internal/protocol" ) func TestNativeExportReturnsTheSessionJSONL(t *testing.T) { config := t.TempDir() t.Setenv("CLAUDE_CONFIG_DIR", config) id := "0b6f1c2e-1111-4222-8333-444455556666" project := filepath.Join(config, "projects", "-work-a") if err := os.MkdirAll(project, 0o755); err != nil { t.Fatal(err) } body := `{"type":"user","uuid":"u1"}` + "\n" + `{"type":"assistant","uuid":"a1"}` + "\n" if err := os.WriteFile(filepath.Join(project, id+".jsonl"), []byte(body), 0o600); err != nil { t.Fatal(err) } chat := New(context.Background()) defer chat.Close() file, err := chat.NativeExport(context.Background(), id) if err != nil { t.Fatal(err) } if file.Name != id+".jsonl" || file.Mime != "application/x-ndjson" || file.Content != body || file.Format != protocol.ChatExportNative { t.Fatalf("native export = %+v", file) } if _, err := chat.NativeExport(context.Background(), "0b6f1c2e-1111-4222-8333-000000000000"); err == nil || !strings.Contains(err.Error(), "has not written a transcript") { t.Fatalf("missing transcript error = %v", err) } }