fix: stream platform builder progress
This commit is contained in:
@@ -185,6 +185,58 @@ func TestDockerDistributionBuilderKeepsSecretInIsolatedInput(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDockerDistributionBuilderStreamsProgressMarkers(t *testing.T) {
|
||||
sourceDir := createBuilderSource(t)
|
||||
workspaceDir := t.TempDir()
|
||||
var progress []DistributionBuildProgress
|
||||
builder := NewDockerDistributionBuilder(DockerDistributionBuilderConfig{
|
||||
DockerBinary: "docker-test",
|
||||
Image: "browser-platform-distribution-builder:1.0.0",
|
||||
SourceDir: sourceDir,
|
||||
WorkspaceDir: workspaceDir,
|
||||
CommandRunner: func(_ context.Context, _ string, args ...string) ([]byte, error) {
|
||||
if len(args) > 0 && (args[0] == "version" || args[0] == "image") {
|
||||
return []byte("27.0.0"), nil
|
||||
}
|
||||
return nil, errors.New("unexpected non-stream command")
|
||||
},
|
||||
CommandStream: func(_ context.Context, _ string, args []string, onLine func(string)) ([]byte, error) {
|
||||
onLine("__platform_builder_progress__|72|build_compile: compiling run target executable")
|
||||
outputDir := builderMountHostPath(t, args, "/workspace/output")
|
||||
if err := os.WriteFile(filepath.Join(outputDir, "run"), []byte("compiled-run"), 0o700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return []byte("builder finished"), nil
|
||||
},
|
||||
})
|
||||
payload, err := builder.BuildWithProgress(domain.DistributionBuildInput{
|
||||
JobID: "job-progress",
|
||||
ComponentKind: domain.DistributionComponentRun,
|
||||
PluginID: "game.scum",
|
||||
TargetOS: "linux",
|
||||
TargetArch: "amd64",
|
||||
OutputFilename: "run",
|
||||
AuthKey: "component-key",
|
||||
}, func(item DistributionBuildProgress) {
|
||||
progress = append(progress, item)
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("build with progress: %v", err)
|
||||
}
|
||||
if string(payload) != "compiled-run" {
|
||||
t.Fatalf("unexpected built payload %q", payload)
|
||||
}
|
||||
found := false
|
||||
for _, item := range progress {
|
||||
if item.Percent == 72 && item.Message == "build_compile: compiling run target executable" {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Fatalf("streamed progress marker was not reported: %+v", progress)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDockerDistributionBuilderRedactsFailureAndTimeout(t *testing.T) {
|
||||
sourceDir := createBuilderSource(t)
|
||||
workspaceDir := t.TempDir()
|
||||
|
||||
Reference in New Issue
Block a user