Use native prepared previews and correct diagnostic references

This commit is contained in:
2026-11-26 04:08:40 +00:00
parent fcd7cffd18
commit b790cc73ca
9 changed files with 81 additions and 107 deletions

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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

View File

@@ -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,