Skip to content

Commit 055c450

Browse files
net0wellclaude
andcommitted
feat(core): RunPipelineAsync executa trilhas passo a passo (spec 003)
- resolve as ligações de cada passo (inclusive implícitas por nome) e aplica as conversões seguras (integer→decimal vira string decimal exata) - arquivos passam de um passo a outro sem cópia no nível da execução; orçamento de 200 MB por execução somando entradas e saídas - falha ou cancelamento num passo marca os seguintes como Skipped - saídas declaradas da trilha em GetOutput/GetFile; GetStepOutput para depurar - RunStageAsync e RunPipelineAsync compartilham o mesmo fluxo de execução Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 27f91a5 commit 055c450

4 files changed

Lines changed: 342 additions & 69 deletions

File tree

‎src/PythonScriptRunner.Abstractions/Running/IPythonRunner.cs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace PythonScriptRunner;
22

3-
/// <summary>Runs stages synchronously in the current process (one Python process per attempt).</summary>
3+
/// <summary>Runs stages and pipelines synchronously in the current process (one Python process per attempt).</summary>
44
public interface IPythonRunner
55
{
66
/// <summary>Runs a published stage and waits for its result.</summary>
@@ -14,6 +14,18 @@ public interface IPythonRunner
1414
/// <exception cref="InputValidationException">The inputs do not match the contract (no run is created).</exception>
1515
Task<RunResult> RunStageAsync(
1616
string stageKey, object? inputs, RunOptions? options = null, CancellationToken cancellationToken = default);
17+
18+
/// <summary>Runs a published pipeline step by step and waits for its result.</summary>
19+
/// <param name="pipelineKey">Pipeline key.</param>
20+
/// <param name="inputs">Pipeline inputs (same forms as <see cref="RunStageAsync"/>).</param>
21+
/// <param name="options">Version, idempotency key and caller identity.</param>
22+
/// <param name="cancellationToken">Cancels the run (the running step is stopped; the next ones are skipped).</param>
23+
/// <returns>The result with the declared pipeline outputs; failures are reported in <see cref="RunResult.Status"/>.</returns>
24+
/// <exception cref="PipelineNotFoundException">The pipeline does not exist.</exception>
25+
/// <exception cref="VersionNotFoundException">The requested version does not exist.</exception>
26+
/// <exception cref="InputValidationException">The inputs do not match the pipeline contract (no run is created).</exception>
27+
Task<RunResult> RunPipelineAsync(
28+
string pipelineKey, object? inputs, RunOptions? options = null, CancellationToken cancellationToken = default);
1729
}
1830

1931
/// <summary>Options of one run.</summary>
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System.Text.Json.Nodes;
2+
using PythonScriptRunner.Core.Execution;
3+
using PythonScriptRunner.Core.Values;
4+
5+
namespace PythonScriptRunner.Core.Pipelines;
6+
7+
/// <summary>Inputs of one pipeline step after resolving its bindings.</summary>
8+
internal sealed record StepInputs(JsonObject Wire, IReadOnlyList<InputFileCopy> Files, IReadOnlyList<InputError> Errors);
9+
10+
/// <summary>Resolves the inputs of a step from pipeline inputs, earlier step outputs, constants and implicit bindings.</summary>
11+
internal static class StepInputResolver
12+
{
13+
public static StepInputs Resolve(
14+
StageDefinition stage,
15+
PipelineDefinition pipeline,
16+
int index,
17+
JsonObject pipelineInputs,
18+
IReadOnlyDictionary<string, IReadOnlyList<PsrFile>> pipelineFiles,
19+
IReadOnlyDictionary<string, StepResult> completed)
20+
{
21+
var step = pipeline.Steps[index];
22+
var wire = new JsonObject();
23+
var files = new List<InputFileCopy>();
24+
var errors = new List<InputError>();
25+
foreach (var target in stage.Inputs)
26+
{
27+
var source = step.Bindings.FirstOrDefault(b => b.Input == target.Name)?.Source ?? Implicit(target, index, pipeline);
28+
var (value, sourceFiles) = Read(source, pipelineInputs, pipelineFiles, completed);
29+
if (target.Type.IsFile)
30+
{
31+
if (sourceFiles is { Count: > 0 })
32+
{
33+
files.AddRange(sourceFiles.Select((file, i) =>
34+
new InputFileCopy(target.Name, i, file.LocalPath!, file.FileName, file.ContentType, file.Length ?? 0, file.Sha256!)));
35+
}
36+
else if (target.Required)
37+
{
38+
errors.Add(Missing(target, source));
39+
}
40+
41+
continue;
42+
}
43+
44+
if (value is null)
45+
{
46+
if (target.Default is not null)
47+
{
48+
wire[target.Name] = target.Default.DeepClone();
49+
}
50+
else if (target.Required)
51+
{
52+
errors.Add(Missing(target, source));
53+
}
54+
55+
continue;
56+
}
57+
58+
var coerced = Coercion.Coerce(value, target.Type);
59+
var wireErrors = new List<WireError>();
60+
WireValidator.Validate(coerced, target, target.Name, wireErrors);
61+
errors.AddRange(wireErrors.Select(e => new InputError(e.Path, e.Code, e.Message)));
62+
wire[target.Name] = coerced;
63+
}
64+
65+
return new StepInputs(wire, files, errors);
66+
}
67+
68+
private static BindingSource? Implicit(FieldDefinition target, int index, PipelineDefinition pipeline)
69+
{
70+
if (index > 0)
71+
{
72+
return new StepOutputSource(pipeline.Steps[index - 1].Key, target.Name);
73+
}
74+
75+
return pipeline.Inputs.Any(f => f.Name == target.Name) ? new PipelineInputSource(target.Name) : null;
76+
}
77+
78+
private static (JsonNode? Value, IReadOnlyList<PsrFile>? Files) Read(
79+
BindingSource? source,
80+
JsonObject pipelineInputs,
81+
IReadOnlyDictionary<string, IReadOnlyList<PsrFile>> pipelineFiles,
82+
IReadOnlyDictionary<string, StepResult> completed) => source switch
83+
{
84+
PipelineInputSource input => (pipelineInputs[input.Field], pipelineFiles.GetValueOrDefault(input.Field)),
85+
StepOutputSource output when completed.TryGetValue(output.Step, out var result) =>
86+
(result.Outputs?[output.Field], result.Files.GetValueOrDefault(output.Field)),
87+
ConstantSource constant => (constant.Value, null),
88+
_ => (null, null),
89+
};
90+
91+
private static InputError Missing(FieldDefinition target, BindingSource? source) =>
92+
new(target.Name, "MISSING_REQUIRED_INPUT", source is null
93+
? "required input has no binding and no default"
94+
: $"required input received no value from {source}");
95+
}

0 commit comments

Comments
 (0)