Use native prepared previews and correct diagnostic references
This commit is contained in:
@@ -128,6 +128,8 @@ Check: `go test ./internal/adapters/scriptorium` when preview fixtures permit.
|
||||
|
||||
## Stage 3: Migrate prepared preview and diagnostic references
|
||||
|
||||
**Status: Complete.**
|
||||
|
||||
**Purpose:** Preserve optional render-debug behavior through the native prepared
|
||||
request command.
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ func (n *NoopRunner) RunArtifact(ctx context.Context, req RunArtifactRequest) (A
|
||||
}
|
||||
return ArtifactResult{
|
||||
OutputPath: req.OutputPath,
|
||||
StdoutLogPath: req.StdoutLogPath,
|
||||
StderrLogPath: req.StderrLogPath,
|
||||
GeneratedConfigPath: req.GeneratedConfigPath,
|
||||
CommandMode: CommandModeRun,
|
||||
@@ -41,7 +40,6 @@ func (n *NoopRunner) RenderArtifact(ctx context.Context, req RenderArtifactReque
|
||||
}
|
||||
return ArtifactResult{
|
||||
OutputPath: req.OutputPath,
|
||||
StdoutLogPath: req.StdoutLogPath,
|
||||
StderrLogPath: req.StderrLogPath,
|
||||
GeneratedConfigPath: req.GeneratedConfigPath,
|
||||
CommandMode: CommandModeRender,
|
||||
@@ -78,9 +76,6 @@ func (f *FakeRunner) RunArtifact(ctx context.Context, req RunArtifactRequest) (A
|
||||
if res.OutputPath == "" {
|
||||
res.OutputPath = req.OutputPath
|
||||
}
|
||||
if res.StdoutLogPath == "" {
|
||||
res.StdoutLogPath = req.StdoutLogPath
|
||||
}
|
||||
if res.StderrLogPath == "" {
|
||||
res.StderrLogPath = req.StderrLogPath
|
||||
}
|
||||
@@ -119,9 +114,6 @@ func (f *FakeRunner) RenderArtifact(ctx context.Context, req RenderArtifactReque
|
||||
if res.OutputPath == "" {
|
||||
res.OutputPath = req.OutputPath
|
||||
}
|
||||
if res.StdoutLogPath == "" {
|
||||
res.StdoutLogPath = req.StdoutLogPath
|
||||
}
|
||||
if res.StderrLogPath == "" {
|
||||
res.StderrLogPath = req.StderrLogPath
|
||||
}
|
||||
@@ -161,11 +153,6 @@ func materializeRunPlaceholders(req RunArtifactRequest) error {
|
||||
return fmt.Errorf("write generated config %q: %w", req.GeneratedConfigPath, err)
|
||||
}
|
||||
}
|
||||
if req.StdoutLogPath != "" {
|
||||
if err := fileops.WriteFileAtomic(req.StdoutLogPath, []byte("scriptorium noop/fake run stdout placeholder\n"), fileops.WorkspaceFileMode); err != nil {
|
||||
return fmt.Errorf("write stdout log %q: %w", req.StdoutLogPath, err)
|
||||
}
|
||||
}
|
||||
if req.StderrLogPath != "" {
|
||||
if err := fileops.WriteFileAtomic(req.StderrLogPath, []byte("scriptorium noop/fake run stderr placeholder\n"), fileops.WorkspaceFileMode); err != nil {
|
||||
return fmt.Errorf("write stderr log %q: %w", req.StderrLogPath, err)
|
||||
@@ -176,7 +163,7 @@ func materializeRunPlaceholders(req RunArtifactRequest) error {
|
||||
|
||||
func materializeRenderPlaceholders(req RenderArtifactRequest) error {
|
||||
if req.OutputPath != "" {
|
||||
if err := fileops.WriteFileAtomic(req.OutputPath, []byte("{\"schema\":\"scriptorium.render.v1\",\"placeholder\":true}\n"), fileops.WorkspaceFileMode); err != nil {
|
||||
if err := fileops.WriteFileAtomic(req.OutputPath, []byte("{\"placeholder\":true}\n"), fileops.WorkspaceFileMode); err != nil {
|
||||
return fmt.Errorf("write render output %q: %w", req.OutputPath, err)
|
||||
}
|
||||
}
|
||||
@@ -192,11 +179,6 @@ func materializeRenderPlaceholders(req RenderArtifactRequest) error {
|
||||
return fmt.Errorf("write generated config %q: %w", req.GeneratedConfigPath, err)
|
||||
}
|
||||
}
|
||||
if req.StdoutLogPath != "" {
|
||||
if err := fileops.WriteFileAtomic(req.StdoutLogPath, []byte("scriptorium noop/fake render stdout placeholder\n"), fileops.WorkspaceFileMode); err != nil {
|
||||
return fmt.Errorf("write stdout log %q: %w", req.StdoutLogPath, err)
|
||||
}
|
||||
}
|
||||
if req.StderrLogPath != "" {
|
||||
if err := fileops.WriteFileAtomic(req.StderrLogPath, []byte("scriptorium noop/fake render stderr placeholder\n"), fileops.WorkspaceFileMode); err != nil {
|
||||
return fmt.Errorf("write stderr log %q: %w", req.StderrLogPath, err)
|
||||
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
const (
|
||||
// CommandModeRun is the Scriptorium CLI mode for production generation.
|
||||
CommandModeRun = "run"
|
||||
// CommandModeRender is the Scriptorium CLI mode for debug/test rendering.
|
||||
CommandModeRender = "render"
|
||||
// CommandModeRender identifies the prepared request inspection command.
|
||||
CommandModeRender = "promptkit show prepared"
|
||||
)
|
||||
|
||||
// Runner is the adapter boundary for Scriptorium artifact invocations.
|
||||
|
||||
@@ -2,6 +2,7 @@ package scriptorium
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -121,7 +122,7 @@ func (r *SubprocessRunner) RunArtifact(ctx context.Context, req RunArtifactReque
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// RenderArtifact executes `scriptorium render` with JSON output.
|
||||
// RenderArtifact captures the native prepared request as JSON.
|
||||
func (r *SubprocessRunner) RenderArtifact(ctx context.Context, req RenderArtifactRequest) (ArtifactResult, error) {
|
||||
if r == nil {
|
||||
return ArtifactResult{}, fmt.Errorf("scriptorium subprocess runner is nil")
|
||||
@@ -158,6 +159,10 @@ func (r *SubprocessRunner) RenderArtifact(ctx context.Context, req RenderArtifac
|
||||
}
|
||||
}
|
||||
|
||||
output, err := openResultFile(req.OutputPath)
|
||||
if err != nil {
|
||||
return ArtifactResult{}, fmt.Errorf("open scriptorium preview %q: %w", req.OutputPath, err)
|
||||
}
|
||||
runRes, runErr := subprocess.Run(ctx, subprocess.RunRequest{
|
||||
Executable: req.Binary,
|
||||
Args: args,
|
||||
@@ -166,13 +171,17 @@ func (r *SubprocessRunner) RenderArtifact(ctx context.Context, req RenderArtifac
|
||||
EnvOverrides: envOverrides,
|
||||
SensitiveEnvNames: sensitiveNames,
|
||||
DiagnosticOwner: "scriptorium",
|
||||
StdoutLogPath: req.StdoutLogPath,
|
||||
StdoutResult: output,
|
||||
StdoutResultLimit: MaxOutputFileBytes,
|
||||
StderrLogPath: req.StderrLogPath,
|
||||
})
|
||||
if closeErr := output.Close(); closeErr != nil {
|
||||
runErr = errors.Join(runErr, fmt.Errorf("close scriptorium preview %q: %w", req.OutputPath, closeErr))
|
||||
}
|
||||
|
||||
result := ArtifactResult{
|
||||
OutputPath: req.OutputPath,
|
||||
StdoutLogPath: req.StdoutLogPath,
|
||||
StdoutLogPath: runRes.StdoutLogPath,
|
||||
StderrLogPath: req.StderrLogPath,
|
||||
GeneratedConfigPath: req.GeneratedConfigPath,
|
||||
ExitCode: runRes.ExitCode,
|
||||
@@ -196,6 +205,13 @@ func (r *SubprocessRunner) RenderArtifact(ctx context.Context, req RenderArtifac
|
||||
if err := validateNonEmptyOutput(req.OutputPath); err != nil {
|
||||
return result, fmt.Errorf("validate scriptorium render output %q: %w", req.OutputPath, err)
|
||||
}
|
||||
data, err := fileops.ReadFileBounded(req.OutputPath, MaxOutputFileBytes)
|
||||
if err != nil {
|
||||
return result, fmt.Errorf("read scriptorium render output %q: %w", req.OutputPath, err)
|
||||
}
|
||||
if !json.Valid(data) {
|
||||
return result, fmt.Errorf("validate scriptorium render output %q: invalid JSON", req.OutputPath)
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -281,7 +297,7 @@ func openResultFile(path string) (*os.File, error) {
|
||||
}
|
||||
|
||||
func buildRenderArgs(req RenderArtifactRequest) []string {
|
||||
args := []string{"render", "--prompt", strings.TrimSpace(req.PromptID)}
|
||||
args := []string{"promptkit", "show", "prepared", strings.TrimSpace(req.PromptID)}
|
||||
if cfgPath := strings.TrimSpace(req.ConfigPath); cfgPath != "" {
|
||||
args = append(args, "--config", cfgPath)
|
||||
}
|
||||
@@ -289,14 +305,12 @@ func buildRenderArgs(req RenderArtifactRequest) []string {
|
||||
args = append(args, "--profile", profileID)
|
||||
}
|
||||
for _, kv := range sortedKeyValues(req.InputPaths) {
|
||||
args = append(args, "--input", kv)
|
||||
args = append(args, "--input-file", kv)
|
||||
}
|
||||
for _, kv := range sortedKeyValues(req.Vars) {
|
||||
args = append(args, "--var", kv)
|
||||
}
|
||||
args = append(args, "--timeout", req.Timeout.String())
|
||||
args = append(args, "--format", "json")
|
||||
args = append(args, "--out", req.OutputPath)
|
||||
return args
|
||||
}
|
||||
|
||||
@@ -351,9 +365,7 @@ func writeInvocationConfig(path string, payload invocationPayload) error {
|
||||
"render_format": payload.RenderFormat,
|
||||
"render_prompt_logged": payload.RenderPromptStore,
|
||||
}
|
||||
if payload.Mode == CommandModeRun {
|
||||
data["stdout_destination"] = payload.OutputPath
|
||||
}
|
||||
data["stdout_destination"] = payload.OutputPath
|
||||
return writeGeneratedYAML(path, data)
|
||||
}
|
||||
|
||||
|
||||
@@ -182,6 +182,20 @@ func TestSubprocessRunnerRunExitCodeFourReturnsValidationFailureAndPreservesOutp
|
||||
assertFileNonEmpty(t, req.OutputPath)
|
||||
}
|
||||
|
||||
func TestSubprocessRunnerRenderRejectsInvalidOrFailedPreview(t *testing.T) {
|
||||
for _, mode := range []string{"render_invalid", "render_failure"} {
|
||||
t.Run(mode, func(t *testing.T) {
|
||||
t.Setenv("GO_WANT_SCRIPTORIUM_HELPER", "1")
|
||||
t.Setenv("SCRIPTORIUM_HELPER_MODE", mode)
|
||||
dir := t.TempDir()
|
||||
req := RenderArtifactRequest{Binary: writeScriptoriumHelperWrapper(t), PromptID: "example", OutputPath: filepath.Join(dir, "preview.json"), StderrLogPath: filepath.Join(dir, "stderr.log"), Timeout: 2 * time.Second}
|
||||
if _, err := NewSubprocessRunner().RenderArtifact(context.Background(), req); err == nil {
|
||||
t.Fatal("expected preview error")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubprocessRunnerRunExitCodeTwoIsNotContentValidation(t *testing.T) {
|
||||
t.Setenv("GO_WANT_SCRIPTORIUM_HELPER", "1")
|
||||
t.Setenv("SCRIPTORIUM_HELPER_MODE", "fail_exit2_with_output")
|
||||
@@ -224,8 +238,11 @@ func TestSubprocessRunnerRenderSuccess(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
req := RenderArtifactRequest{
|
||||
Binary: wrapper,
|
||||
ConfigPath: "/config.yml",
|
||||
PromptID: "dnd.session_recap",
|
||||
ProfileID: "local-quality",
|
||||
InputPaths: map[string]string{"transcript": filepath.Join(dir, "polished.json")},
|
||||
Vars: map[string]string{"session_id": "test,session=value"},
|
||||
OutputPath: filepath.Join(dir, "artifacts", "session_recap.render.json"),
|
||||
StdoutLogPath: filepath.Join(dir, "logs", "scriptorium.render.stdout.log"),
|
||||
StderrLogPath: filepath.Join(dir, "logs", "scriptorium.render.stderr.log"),
|
||||
@@ -245,15 +262,21 @@ func TestSubprocessRunnerRenderSuccess(t *testing.T) {
|
||||
t.Fatalf("ExitCode = %d, want 0", res.ExitCode)
|
||||
}
|
||||
assertFileNonEmpty(t, req.OutputPath)
|
||||
if res.StdoutLogPath != "" {
|
||||
t.Fatalf("stdout log = %q", res.StdoutLogPath)
|
||||
}
|
||||
data, err := os.ReadFile(req.OutputPath)
|
||||
if err != nil || string(data) != "{\"prepared\":true}\n" {
|
||||
t.Fatalf("prepared output = %q, %v", data, err)
|
||||
}
|
||||
|
||||
rec := readScriptoriumHelperRecord(t, recordPath)
|
||||
wantArgs := []string{
|
||||
"render",
|
||||
"--prompt", "dnd.session_recap",
|
||||
"--input", "transcript=" + req.InputPaths["transcript"],
|
||||
"--timeout", "2s",
|
||||
"promptkit", "show", "prepared", "dnd.session_recap",
|
||||
"--config", "/config.yml", "--profile", "local-quality",
|
||||
"--input-file", "transcript=" + req.InputPaths["transcript"],
|
||||
"--var", "session_id=test,session=value",
|
||||
"--format", "json",
|
||||
"--out", req.OutputPath,
|
||||
}
|
||||
if strings.Join(rec.Args, "\n") != strings.Join(wantArgs, "\n") {
|
||||
t.Fatalf("args = %#v, want %#v", rec.Args, wantArgs)
|
||||
@@ -279,7 +302,6 @@ func TestScriptoriumSubprocessHelper(t *testing.T) {
|
||||
}
|
||||
cliArgs := args[start:]
|
||||
|
||||
outputPath := flagValue(cliArgs, "--out")
|
||||
recordPath := os.Getenv("SCRIPTORIUM_HELPER_RECORD_PATH")
|
||||
if strings.TrimSpace(recordPath) != "" {
|
||||
rec := scriptoriumHelperRecord{
|
||||
@@ -315,10 +337,15 @@ func TestScriptoriumSubprocessHelper(t *testing.T) {
|
||||
_, _ = os.Stderr.WriteString("scriptorium helper validation failure\n")
|
||||
os.Exit(4)
|
||||
case "render_success":
|
||||
writeScriptoriumHelperFile(outputPath, "{\"rendered\":true}\n")
|
||||
_, _ = os.Stdout.WriteString("scriptorium helper render stdout\n")
|
||||
_, _ = os.Stdout.WriteString("{\"prepared\":true}\n")
|
||||
_, _ = os.Stderr.WriteString("scriptorium helper render stderr\n")
|
||||
os.Exit(0)
|
||||
case "render_invalid":
|
||||
_, _ = os.Stdout.WriteString("{broken")
|
||||
os.Exit(0)
|
||||
case "render_failure":
|
||||
_, _ = os.Stderr.WriteString("preview failed")
|
||||
os.Exit(1)
|
||||
default:
|
||||
_, _ = os.Stderr.WriteString(fmt.Sprintf("unknown helper mode %q\n", mode))
|
||||
os.Exit(2)
|
||||
@@ -371,15 +398,6 @@ func mustParseScriptoriumDuration(t *testing.T, v string) time.Duration {
|
||||
return d
|
||||
}
|
||||
|
||||
func flagValue(args []string, name string) string {
|
||||
for i := 0; i < len(args)-1; i++ {
|
||||
if args[i] == name {
|
||||
return args[i+1]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func writeScriptoriumFile(t *testing.T, path, contents string) {
|
||||
t.Helper()
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||
@@ -390,14 +408,6 @@ func writeScriptoriumFile(t *testing.T, path, contents string) {
|
||||
}
|
||||
}
|
||||
|
||||
func writeScriptoriumHelperFile(path, contents string) {
|
||||
if strings.TrimSpace(path) == "" {
|
||||
return
|
||||
}
|
||||
_ = os.MkdirAll(filepath.Dir(path), 0o755)
|
||||
_ = os.WriteFile(path, []byte(contents), 0o644)
|
||||
}
|
||||
|
||||
func assertFileNonEmpty(t *testing.T, path string) {
|
||||
t.Helper()
|
||||
info, err := os.Stat(path)
|
||||
|
||||
@@ -23,12 +23,10 @@ type analyzeArtifactPreparation struct {
|
||||
timeout time.Duration
|
||||
canonicalOutputPath string
|
||||
runOutputPath string
|
||||
stdoutLogPath string
|
||||
stderrLogPath string
|
||||
generatedConfigPath string
|
||||
renderEnabled bool
|
||||
renderOutputPath string
|
||||
renderStdoutPath string
|
||||
renderStderrPath string
|
||||
renderConfigPath string
|
||||
metadata map[string]any
|
||||
@@ -119,19 +117,15 @@ func prepareAnalyzeArtifact(
|
||||
return nil, fmt.Errorf("analyze: resolve run-local output path for artifact %q: %w", artifactName, err)
|
||||
}
|
||||
|
||||
stdoutLogPath := filepath.Join(paths.LogsDir, "scriptorium."+artifactName+".stdout.log")
|
||||
stderrLogPath := filepath.Join(paths.LogsDir, "scriptorium."+artifactName+".stderr.log")
|
||||
generatedConfigPath := filepath.Join(paths.ConfigDir, "scriptorium."+artifactName+".generated.yml")
|
||||
renderOutputPath := filepath.Join(paths.ArtifactsDir, artifactName+".render.json")
|
||||
renderStdoutPath := filepath.Join(paths.LogsDir, "scriptorium."+artifactName+".render.stdout.log")
|
||||
renderStderrPath := filepath.Join(paths.LogsDir, "scriptorium."+artifactName+".render.stderr.log")
|
||||
renderConfigPath := filepath.Join(paths.ConfigDir, "scriptorium."+artifactName+".render.generated.yml")
|
||||
if runLayout.Enabled {
|
||||
stdoutLogPath = filepath.Join(runLayout.LogsDir, "scriptorium."+artifactName+".stdout.log")
|
||||
stderrLogPath = filepath.Join(runLayout.LogsDir, "scriptorium."+artifactName+".stderr.log")
|
||||
generatedConfigPath = filepath.Join(runLayout.ConfigDir, "scriptorium."+artifactName+".generated.yml")
|
||||
renderOutputPath = filepath.Join(runLayout.ReportsDir, artifactName+".render.json")
|
||||
renderStdoutPath = filepath.Join(runLayout.LogsDir, "scriptorium."+artifactName+".render.stdout.log")
|
||||
renderStderrPath = filepath.Join(runLayout.LogsDir, "scriptorium."+artifactName+".render.stderr.log")
|
||||
renderConfigPath = filepath.Join(runLayout.ConfigDir, "scriptorium."+artifactName+".render.generated.yml")
|
||||
}
|
||||
@@ -151,12 +145,10 @@ func prepareAnalyzeArtifact(
|
||||
timeout: timeout,
|
||||
canonicalOutputPath: canonicalOutputPath,
|
||||
runOutputPath: runOutputPath,
|
||||
stdoutLogPath: stdoutLogPath,
|
||||
stderrLogPath: stderrLogPath,
|
||||
generatedConfigPath: generatedConfigPath,
|
||||
renderEnabled: renderEnabled,
|
||||
renderOutputPath: renderOutputPath,
|
||||
renderStdoutPath: renderStdoutPath,
|
||||
renderStderrPath: renderStderrPath,
|
||||
renderConfigPath: renderConfigPath,
|
||||
reusedArtifacts: reusedArtifacts,
|
||||
@@ -203,7 +195,6 @@ func invokeAnalyzeRender(
|
||||
InputPaths: prepared.inputPaths,
|
||||
Vars: prepared.vars,
|
||||
OutputPath: prepared.renderOutputPath,
|
||||
StdoutLogPath: prepared.renderStdoutPath,
|
||||
StderrLogPath: prepared.renderStderrPath,
|
||||
GeneratedConfigPath: prepared.renderConfigPath,
|
||||
Timeout: prepared.timeout,
|
||||
@@ -226,10 +217,9 @@ func invokeAnalyzeRender(
|
||||
return fmt.Errorf("analyze: render diagnostics %q invalid json: %w", outputPath, err)
|
||||
}
|
||||
|
||||
prepared.logs = append(prepared.logs, prepared.renderStdoutPath, prepared.renderStderrPath)
|
||||
prepared.logs = append(prepared.logs, prepared.renderStderrPath)
|
||||
prepared.generatedConfigs = append(prepared.generatedConfigs, prepared.renderConfigPath)
|
||||
prepared.metadata["render_output_path"] = outputPath
|
||||
prepared.metadata["render_stdout_log_path"] = prepared.renderStdoutPath
|
||||
prepared.metadata["render_stderr_log_path"] = prepared.renderStderrPath
|
||||
prepared.metadata["render_generated_config_path"] = prepared.renderConfigPath
|
||||
prepared.metadata["render_adapter_exit_code"] = res.ExitCode
|
||||
@@ -239,7 +229,6 @@ func invokeAnalyzeRender(
|
||||
prepared.metadata["render_adapter_profile_id"] = res.ProfileID
|
||||
prepared.metadata["render_adapter_output_path"] = res.OutputPath
|
||||
prepared.metadata["render_adapter_generated_config"] = res.GeneratedConfigPath
|
||||
prepared.metadata["render_adapter_stdout_log_path"] = res.StdoutLogPath
|
||||
prepared.metadata["render_adapter_stderr_log_path"] = res.StderrLogPath
|
||||
if res.Metadata != nil {
|
||||
prepared.metadata["render_adapter_metadata"] = res.Metadata
|
||||
@@ -261,7 +250,6 @@ func invokeAnalyzeArtifact(
|
||||
InputPaths: prepared.inputPaths,
|
||||
Vars: prepared.vars,
|
||||
OutputPath: prepared.runOutputPath,
|
||||
StdoutLogPath: prepared.stdoutLogPath,
|
||||
StderrLogPath: prepared.stderrLogPath,
|
||||
GeneratedConfigPath: prepared.generatedConfigPath,
|
||||
Timeout: prepared.timeout,
|
||||
@@ -271,12 +259,11 @@ func invokeAnalyzeArtifact(
|
||||
if err != nil {
|
||||
if res.ValidationFailed {
|
||||
return invocation, fmt.Errorf(
|
||||
"analyze: scriptorium validation failed (artifact=%q, prompt_id=%q, output_path=%q, exit_code=%d, stdout_log=%q, stderr_log=%q): %w",
|
||||
"analyze: scriptorium validation failed (artifact=%q, prompt_id=%q, output_path=%q, exit_code=%d, stderr_log=%q): %w",
|
||||
prepared.name,
|
||||
req.PromptID,
|
||||
req.OutputPath,
|
||||
res.ExitCode,
|
||||
coalesceString(res.StdoutLogPath, req.StdoutLogPath),
|
||||
coalesceString(res.StderrLogPath, req.StderrLogPath),
|
||||
err,
|
||||
)
|
||||
@@ -350,13 +337,12 @@ func buildAnalyzeArtifactExecutionResult(
|
||||
materialized analyzeArtifactMaterialization,
|
||||
) *analyzeArtifactExecutionResult {
|
||||
res := invocation.result
|
||||
prepared.logs = append(prepared.logs, prepared.stdoutLogPath, prepared.stderrLogPath)
|
||||
prepared.logs = append(prepared.logs, prepared.stderrLogPath)
|
||||
prepared.generatedConfigs = append(prepared.generatedConfigs, prepared.generatedConfigPath)
|
||||
prepared.metadata["run_output_path"] = materialized.runOutputPath
|
||||
prepared.metadata["path"] = prepared.canonicalOutputPath
|
||||
prepared.metadata["output_path"] = prepared.canonicalOutputPath
|
||||
prepared.metadata["generated_config_path"] = prepared.generatedConfigPath
|
||||
prepared.metadata["stdout_log_path"] = prepared.stdoutLogPath
|
||||
prepared.metadata["stderr_log_path"] = prepared.stderrLogPath
|
||||
prepared.metadata["adapter_exit_code"] = res.ExitCode
|
||||
prepared.metadata["adapter_duration_ms"] = res.Duration.Milliseconds()
|
||||
@@ -366,7 +352,6 @@ func buildAnalyzeArtifactExecutionResult(
|
||||
prepared.metadata["adapter_validation_failed"] = res.ValidationFailed
|
||||
prepared.metadata["adapter_output_path"] = res.OutputPath
|
||||
prepared.metadata["adapter_generated_config"] = res.GeneratedConfigPath
|
||||
prepared.metadata["adapter_stdout_log_path"] = res.StdoutLogPath
|
||||
prepared.metadata["adapter_stderr_log_path"] = res.StderrLogPath
|
||||
prepared.metadata["provenance"] = artifacts.ArtifactProvenanceGeneratedCurrentAnalyzeRun
|
||||
if res.Metadata != nil {
|
||||
|
||||
@@ -49,7 +49,7 @@ func TestAnalyzeGeneratesSessionRecapFromTrimmedTranscript(t *testing.T) {
|
||||
if req.OutputPath != filepath.Join(runRoot, "outputs", "artifacts", "session_recap.md") {
|
||||
t.Fatalf("output path = %q, want run-local output", req.OutputPath)
|
||||
}
|
||||
if req.StdoutLogPath != filepath.Join(runRoot, "logs", "scriptorium.session_recap.stdout.log") {
|
||||
if req.StdoutLogPath != "" {
|
||||
t.Fatalf("stdout log path = %q", req.StdoutLogPath)
|
||||
}
|
||||
if req.StderrLogPath != filepath.Join(runRoot, "logs", "scriptorium.session_recap.stderr.log") {
|
||||
@@ -68,8 +68,8 @@ func TestAnalyzeGeneratesSessionRecapFromTrimmedTranscript(t *testing.T) {
|
||||
if m.Stages["analyze"].AnalyzeArtifacts["session_recap"].Status != manifest.AnalyzeArtifactCurrent {
|
||||
t.Fatalf("analyze state = %#v, want current session_recap", m.Stages["analyze"].AnalyzeArtifacts)
|
||||
}
|
||||
if len(result.Logs) != 2 {
|
||||
t.Fatalf("logs = %#v, want stdout+stderr logs", result.Logs)
|
||||
if len(result.Logs) != 1 || result.Logs[0] != req.StderrLogPath {
|
||||
t.Fatalf("logs = %#v, want stderr log", result.Logs)
|
||||
}
|
||||
if len(result.GeneratedConfigs) != 1 {
|
||||
t.Fatalf("generated configs = %#v, want one path", result.GeneratedConfigs)
|
||||
@@ -192,12 +192,17 @@ func TestAnalyzeRenderOutputPathIsRecorded(t *testing.T) {
|
||||
if result.Metadata["render_output_path"] != filepath.Join(runRoot, "reports", "session_recap.render.json") {
|
||||
t.Fatalf("render_output_path = %#v, want session_recap.render.json path", result.Metadata["render_output_path"])
|
||||
}
|
||||
if len(result.Logs) != 4 {
|
||||
t.Fatalf("logs = %#v, want render+run stdout/stderr logs", result.Logs)
|
||||
if len(result.Logs) != 2 || result.Logs[0] != fake.RenderRequests[0].StderrLogPath || result.Logs[1] != fake.RunRequests[0].StderrLogPath {
|
||||
t.Fatalf("logs = %#v, want render and run stderr logs", result.Logs)
|
||||
}
|
||||
if len(result.GeneratedConfigs) != 2 {
|
||||
t.Fatalf("generated configs = %#v, want render+run generated configs", result.GeneratedConfigs)
|
||||
}
|
||||
for _, key := range []string{"stdout_log_path", "adapter_stdout_log_path", "render_stdout_log_path", "render_adapter_stdout_log_path"} {
|
||||
if _, ok := result.Metadata[key]; ok {
|
||||
t.Fatalf("unexpected stdout diagnostic %q", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAnalyzeRenderFailurePreventsRun(t *testing.T) {
|
||||
@@ -348,14 +353,12 @@ func (r *orderedScriptoriumRunner) RenderArtifact(_ context.Context, req scripto
|
||||
body = `{"rendered":true}`
|
||||
}
|
||||
writeAnalyzeFileNoTest(req.OutputPath, body)
|
||||
writeAnalyzeFileNoTest(req.StdoutLogPath, "render stdout\n")
|
||||
writeAnalyzeFileNoTest(req.StderrLogPath, "render stderr\n")
|
||||
if req.GeneratedConfigPath != "" {
|
||||
writeAnalyzeFileNoTest(req.GeneratedConfigPath, "schema: scriptorium.generated.v1\n")
|
||||
}
|
||||
return scriptorium.ArtifactResult{
|
||||
OutputPath: req.OutputPath,
|
||||
StdoutLogPath: req.StdoutLogPath,
|
||||
StderrLogPath: req.StderrLogPath,
|
||||
GeneratedConfigPath: req.GeneratedConfigPath,
|
||||
CommandMode: scriptorium.CommandModeRender,
|
||||
@@ -374,14 +377,12 @@ func (r *orderedScriptoriumRunner) RunArtifact(_ context.Context, req scriptoriu
|
||||
body = "session recap\n"
|
||||
}
|
||||
writeAnalyzeFileNoTest(req.OutputPath, body)
|
||||
writeAnalyzeFileNoTest(req.StdoutLogPath, "run stdout\n")
|
||||
writeAnalyzeFileNoTest(req.StderrLogPath, "run stderr\n")
|
||||
if req.GeneratedConfigPath != "" {
|
||||
writeAnalyzeFileNoTest(req.GeneratedConfigPath, "schema: scriptorium.generated.v1\n")
|
||||
}
|
||||
return scriptorium.ArtifactResult{
|
||||
OutputPath: req.OutputPath,
|
||||
StdoutLogPath: req.StdoutLogPath,
|
||||
StderrLogPath: req.StderrLogPath,
|
||||
GeneratedConfigPath: req.GeneratedConfigPath,
|
||||
CommandMode: scriptorium.CommandModeRun,
|
||||
@@ -1417,8 +1418,8 @@ func TestAnalyzeRecordsRefsAndMetadata(t *testing.T) {
|
||||
if !ok || record.Output == nil || record.Output.LocalPath != "artifacts/session_recap.md" {
|
||||
t.Fatalf("analyze output record = %#v, want session recap evidence", record)
|
||||
}
|
||||
if len(result.Logs) != 2 {
|
||||
t.Fatalf("logs = %#v, want two logs", result.Logs)
|
||||
if len(result.Logs) != 1 {
|
||||
t.Fatalf("logs = %#v, want stderr log", result.Logs)
|
||||
}
|
||||
if len(result.GeneratedConfigs) != 1 {
|
||||
t.Fatalf("generated configs = %#v, want one", result.GeneratedConfigs)
|
||||
|
||||
@@ -122,11 +122,9 @@ func (trimStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*Stag
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("trim: resolve run-local bounds output path: %w", err)
|
||||
}
|
||||
boundsStdoutLogPath := filepath.Join(paths.LogsDir, "scriptorium.bounds.stdout.log")
|
||||
boundsStderrLogPath := filepath.Join(paths.LogsDir, "scriptorium.bounds.stderr.log")
|
||||
boundsGeneratedConfigPath := filepath.Join(paths.ConfigDir, "scriptorium.bounds.generated.yml")
|
||||
if runLayout.Enabled {
|
||||
boundsStdoutLogPath = filepath.Join(runLayout.LogsDir, "scriptorium.bounds.stdout.log")
|
||||
boundsStderrLogPath = filepath.Join(runLayout.LogsDir, "scriptorium.bounds.stderr.log")
|
||||
boundsGeneratedConfigPath = filepath.Join(runLayout.ConfigDir, "scriptorium.bounds.generated.yml")
|
||||
}
|
||||
@@ -159,11 +157,9 @@ func (trimStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*Stag
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("trim: resolve run-local bounds render output path: %w", err)
|
||||
}
|
||||
renderStdoutLogPath := filepath.Join(paths.LogsDir, "scriptorium.bounds.render.stdout.log")
|
||||
renderStderrLogPath := filepath.Join(paths.LogsDir, "scriptorium.bounds.render.stderr.log")
|
||||
renderGeneratedConfigPath := filepath.Join(paths.ConfigDir, "scriptorium.bounds.render.generated.yml")
|
||||
if runLayout.Enabled {
|
||||
renderStdoutLogPath = filepath.Join(runLayout.LogsDir, "scriptorium.bounds.render.stdout.log")
|
||||
renderStderrLogPath = filepath.Join(runLayout.LogsDir, "scriptorium.bounds.render.stderr.log")
|
||||
renderGeneratedConfigPath = filepath.Join(runLayout.ConfigDir, "scriptorium.bounds.render.generated.yml")
|
||||
}
|
||||
@@ -177,7 +173,6 @@ func (trimStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*Stag
|
||||
InputPaths: inputPaths,
|
||||
Vars: vars,
|
||||
OutputPath: renderOutputPath,
|
||||
StdoutLogPath: renderStdoutLogPath,
|
||||
StderrLogPath: renderStderrLogPath,
|
||||
GeneratedConfigPath: renderGeneratedConfigPath,
|
||||
Timeout: boundsTimeout,
|
||||
@@ -200,10 +195,9 @@ func (trimStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*Stag
|
||||
return nil, fmt.Errorf("trim: bounds render diagnostics %q invalid json: %w", finalRenderOutputPath, err)
|
||||
}
|
||||
|
||||
logPaths = append(logPaths, renderStdoutLogPath, renderStderrLogPath)
|
||||
logPaths = append(logPaths, renderStderrLogPath)
|
||||
generatedConfigs = append(generatedConfigs, renderGeneratedConfigPath)
|
||||
metadata["bounds_render_output_path"] = finalRenderOutputPath
|
||||
metadata["bounds_render_stdout_log_path"] = renderStdoutLogPath
|
||||
metadata["bounds_render_stderr_log_path"] = renderStderrLogPath
|
||||
metadata["bounds_render_generated_config_path"] = renderGeneratedConfigPath
|
||||
metadata["bounds_render_adapter_exit_code"] = renderRes.ExitCode
|
||||
@@ -223,7 +217,6 @@ func (trimStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*Stag
|
||||
InputPaths: inputPaths,
|
||||
Vars: vars,
|
||||
OutputPath: boundsOutputPath,
|
||||
StdoutLogPath: boundsStdoutLogPath,
|
||||
StderrLogPath: boundsStderrLogPath,
|
||||
GeneratedConfigPath: boundsGeneratedConfigPath,
|
||||
Timeout: boundsTimeout,
|
||||
@@ -233,11 +226,10 @@ func (trimStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*Stag
|
||||
if boundsRunErr != nil {
|
||||
if boundsRes.ValidationFailed {
|
||||
return nil, fmt.Errorf(
|
||||
"trim: scriptorium bounds validation failed (prompt_id=%q, output_path=%q, exit_code=%d, stdout_log=%q, stderr_log=%q): %w",
|
||||
"trim: scriptorium bounds validation failed (prompt_id=%q, output_path=%q, exit_code=%d, stderr_log=%q): %w",
|
||||
boundsReq.PromptID,
|
||||
boundsReq.OutputPath,
|
||||
boundsRes.ExitCode,
|
||||
coalesceString(boundsRes.StdoutLogPath, boundsReq.StdoutLogPath),
|
||||
coalesceString(boundsRes.StderrLogPath, boundsReq.StderrLogPath),
|
||||
boundsRunErr,
|
||||
)
|
||||
@@ -273,7 +265,7 @@ func (trimStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*Stag
|
||||
trimAction = "trim"
|
||||
}
|
||||
|
||||
logPaths = append(logPaths, boundsStdoutLogPath, boundsStderrLogPath)
|
||||
logPaths = append(logPaths, boundsStderrLogPath)
|
||||
generatedConfigs = append(generatedConfigs, boundsGeneratedConfigPath)
|
||||
metadata["bounds_confidence"] = boundsPayload.Confidence
|
||||
metadata["trim_action"] = trimAction
|
||||
@@ -282,7 +274,6 @@ func (trimStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*Stag
|
||||
metadata["warnings"] = boundsPayload.Warnings
|
||||
metadata["keep_selector"] = keepSelector
|
||||
metadata["run_bounds_output_path"] = finalBoundsOutputPath
|
||||
metadata["bounds_stdout_log_path"] = boundsStdoutLogPath
|
||||
metadata["bounds_stderr_log_path"] = boundsStderrLogPath
|
||||
metadata["bounds_generated_config_path"] = boundsGeneratedConfigPath
|
||||
metadata["bounds_adapter_exit_code"] = boundsRes.ExitCode
|
||||
@@ -292,7 +283,6 @@ func (trimStage) Run(ctx context.Context, env *Env, m *manifest.Manifest) (*Stag
|
||||
metadata["bounds_adapter_profile_id"] = boundsRes.ProfileID
|
||||
metadata["bounds_adapter_output_path"] = boundsRes.OutputPath
|
||||
metadata["bounds_adapter_generated_config"] = boundsRes.GeneratedConfigPath
|
||||
metadata["bounds_adapter_stdout_log_path"] = boundsRes.StdoutLogPath
|
||||
metadata["bounds_adapter_stderr_log_path"] = boundsRes.StderrLogPath
|
||||
if boundsRes.Metadata != nil {
|
||||
metadata["bounds_adapter_metadata"] = boundsRes.Metadata
|
||||
|
||||
@@ -107,7 +107,7 @@ func TestTrimStageRecordsLogAndGeneratedConfigRefs(t *testing.T) {
|
||||
t.Fatalf("trim.Run() error = %v", err)
|
||||
}
|
||||
logs := strings.Join(result.Logs, "\n")
|
||||
if !strings.Contains(logs, "scriptorium.bounds.stdout.log") || !strings.Contains(logs, "seriatim.trim.stdout.log") {
|
||||
if !strings.Contains(logs, "scriptorium.bounds.stderr.log") || strings.Contains(logs, "scriptorium.bounds.stdout.log") || !strings.Contains(logs, "seriatim.trim.stdout.log") {
|
||||
t.Fatalf("logs = %#v, want scriptorium+seriatim logs", result.Logs)
|
||||
}
|
||||
generated := strings.Join(result.GeneratedConfigs, "\n")
|
||||
@@ -379,9 +379,6 @@ func (r *boundsScriptoriumRunner) RunArtifact(_ context.Context, req scriptorium
|
||||
if err := writeTrimFixtureFile(req.OutputPath, body); err != nil {
|
||||
return scriptorium.ArtifactResult{}, err
|
||||
}
|
||||
if err := writeTrimFixtureFile(req.StdoutLogPath, "bounds stdout\n"); err != nil {
|
||||
return scriptorium.ArtifactResult{}, err
|
||||
}
|
||||
if err := writeTrimFixtureFile(req.StderrLogPath, "bounds stderr\n"); err != nil {
|
||||
return scriptorium.ArtifactResult{}, err
|
||||
}
|
||||
@@ -392,7 +389,6 @@ func (r *boundsScriptoriumRunner) RunArtifact(_ context.Context, req scriptorium
|
||||
}
|
||||
return scriptorium.ArtifactResult{
|
||||
OutputPath: req.OutputPath,
|
||||
StdoutLogPath: req.StdoutLogPath,
|
||||
StderrLogPath: req.StderrLogPath,
|
||||
GeneratedConfigPath: req.GeneratedConfigPath,
|
||||
ExitCode: 0,
|
||||
@@ -416,9 +412,6 @@ func (r *boundsScriptoriumRunner) RenderArtifact(_ context.Context, req scriptor
|
||||
if err := writeTrimFixtureFile(req.OutputPath, body); err != nil {
|
||||
return scriptorium.ArtifactResult{}, err
|
||||
}
|
||||
if err := writeTrimFixtureFile(req.StdoutLogPath, "render stdout\n"); err != nil {
|
||||
return scriptorium.ArtifactResult{}, err
|
||||
}
|
||||
if err := writeTrimFixtureFile(req.StderrLogPath, "render stderr\n"); err != nil {
|
||||
return scriptorium.ArtifactResult{}, err
|
||||
}
|
||||
@@ -429,7 +422,6 @@ func (r *boundsScriptoriumRunner) RenderArtifact(_ context.Context, req scriptor
|
||||
}
|
||||
return scriptorium.ArtifactResult{
|
||||
OutputPath: req.OutputPath,
|
||||
StdoutLogPath: req.StdoutLogPath,
|
||||
StderrLogPath: req.StderrLogPath,
|
||||
GeneratedConfigPath: req.GeneratedConfigPath,
|
||||
ExitCode: 0,
|
||||
|
||||
Reference in New Issue
Block a user