Implement manifest model and local store

This commit is contained in:
2026-05-02 10:51:23 -05:00
parent 4172849f20
commit 6caecb1baa
7 changed files with 652 additions and 28 deletions

View File

@@ -2,14 +2,19 @@ package app
import (
"bytes"
"context"
"os"
"path/filepath"
"strings"
"testing"
"time"
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
)
func TestExecuteValidCommands(t *testing.T) {
pipelinePath, sessionPath := writeValidConfigFiles(t)
manifestPath := writeManifestPathForExecute(t)
cases := []struct {
name string
@@ -18,7 +23,7 @@ func TestExecuteValidCommands(t *testing.T) {
}{
{name: "run", args: []string{"run", "--config", pipelinePath, "--session", sessionPath}, wantOut: "narratio run: configuration loaded and valid"},
{name: "plan", args: []string{"plan", "--config", pipelinePath, "--session", sessionPath}, wantOut: "narratio plan: configuration loaded and valid"},
{name: "status", args: []string{"status"}, wantOut: "narratio status: not yet implemented"},
{name: "status", args: []string{"status", "--manifest", manifestPath}, wantOut: "session_id: 2026-05-03"},
{name: "resume", args: []string{"resume"}, wantOut: "narratio resume: not yet implemented"},
{name: "run-stage", args: []string{"run-stage", "polish"}, wantOut: "narratio run-stage: not yet implemented"},
}
@@ -42,7 +47,7 @@ func TestExecuteValidCommands(t *testing.T) {
}
}
func TestExecuteMissingConfigFlags(t *testing.T) {
func TestExecuteMissingRequiredFlags(t *testing.T) {
cases := []struct {
name string
args []string
@@ -50,6 +55,7 @@ func TestExecuteMissingConfigFlags(t *testing.T) {
}{
{name: "run missing flags", args: []string{"run"}, want: "run: --config and --session are required"},
{name: "plan missing flags", args: []string{"plan"}, want: "plan: --config and --session are required"},
{name: "status missing flags", args: []string{"status"}, want: "status: --manifest is required"},
}
for _, tc := range cases {
@@ -149,3 +155,18 @@ inputs:
return pipelinePath, sessionPath
}
func writeManifestPathForExecute(t *testing.T) string {
t.Helper()
store := &manifest.LocalStore{}
m := manifest.New("2026-05-03", time.Date(2026, 5, 3, 10, 0, 0, 0, time.UTC))
m.MarkStageSucceeded("prepare", time.Date(2026, 5, 3, 10, 1, 0, 0, time.UTC), nil)
path := filepath.Join(t.TempDir(), "manifest.json")
if err := store.Save(context.Background(), path, m); err != nil {
t.Fatalf("save manifest: %v", err)
}
return path
}