production runtime and mock removal
This commit is contained in:
1 parent
2ef3da7af5
commit
6480e503eb
55 files changed
+581
-540
No files matched your search
@@ -217,7 +217,6 @@ func writeOutputState(ctx context.Context, state JobStateWriter, job jobs.Job, i
|
||||
type GeneratedAssetImporter interface {
|
||||
List(context.Context, assets.Scope) ([]assets.Asset, error)
|
||||
ImportGenerated(context.Context, assets.Scope, assets.ImportGeneratedCommand) (assets.Asset, error)
|
||||
ImportMock(context.Context, assets.Scope, assets.ImportMockCommand) (assets.Asset, error)
|
||||
}
|
||||
|
||||
type OutputURLResolver func(jobs.Job) ([]string, error)
|
||||
@@ -240,24 +239,6 @@ func (r *AssetOutputRegistrar) Register(ctx context.Context, job jobs.Job) ([]st
|
||||
if err != nil {
|
||||
return nil, errors.New("register generation outputs")
|
||||
}
|
||||
if job.Provider == "mock" {
|
||||
if id := existingOutputID(existing, job.ID, "output:0"); id != "" {
|
||||
return []string{id}, nil
|
||||
}
|
||||
kind := assets.KindImage
|
||||
if job.Capability == "video.generate" {
|
||||
kind = assets.KindVideo
|
||||
}
|
||||
created, createErr := r.assets.ImportMock(ctx, scope, assets.ImportMockCommand{
|
||||
Capability: job.Capability, JobID: job.ID, Kind: kind,
|
||||
Tags: []string{"generated", job.Capability, "job:" + job.ID, "output:0"},
|
||||
Metadata: map[string]any{"capability": job.Capability, "jobId": job.ID, "index": 0},
|
||||
})
|
||||
if createErr != nil {
|
||||
return nil, errors.New("register generation outputs")
|
||||
}
|
||||
return []string{created.ID}, nil
|
||||
}
|
||||
urls, err := r.resolve(job)
|
||||
if err != nil || len(urls) == 0 {
|
||||
return nil, errors.New("register generation outputs")
|
||||
|
||||
@@ -128,33 +128,6 @@ func TestAssetOutputRegistrarUsesGeneratedOwnerScopedAssets(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutputRegisteringProcessorCreatesAndPersistsMockAssetWithoutRemoteFetch(t *testing.T) {
|
||||
for _, capability := range []string{"image.generate", "video.generate"} {
|
||||
t.Run(capability, func(t *testing.T) {
|
||||
creator := &assetCreatorStub{}
|
||||
registrar := NewAssetOutputRegistrar(creator, ResolveProviderOutputURLs)
|
||||
completed := jobs.Job{
|
||||
ID: "job-mock", OwnerID: "owner", Provider: "mock", Capability: capability,
|
||||
Prompt: "mock output", Status: jobs.StatusSucceeded,
|
||||
ResponsePayload: json.RawMessage(`{"status":"succeeded","outputUrls":["/generated-results/mock-task"]}`),
|
||||
}
|
||||
writer := &stateWriterStub{}
|
||||
processor := NewOutputRegisteringProcessor(&processorStub{job: completed}, registrar, writer)
|
||||
got, err := processor.Advance(context.Background(), jobs.Job{ID: "job-mock"})
|
||||
if err != nil || !reflect.DeepEqual(got.OutputAssetIDs, []string{"asset-1"}) || !reflect.DeepEqual(writer.outputIDs, []string{"asset-1"}) || len(creator.mockCommands) != 1 || creator.mockCommands[0].JobID != "job-mock" {
|
||||
t.Fatalf("Advance = %#v, %v mock=%#v persisted=%#v", got, err, creator.mockCommands, writer.outputIDs)
|
||||
}
|
||||
wantKind := assets.KindImage
|
||||
if capability == "video.generate" {
|
||||
wantKind = assets.KindVideo
|
||||
}
|
||||
if creator.mockCommands[0].Kind != wantKind || len(creator.commands) != 0 {
|
||||
t.Fatalf("mock command=%#v remote imports=%#v", creator.mockCommands[0], creator.commands)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveProviderOutputURLsAcceptsCurrentShapesAndDeduplicates(t *testing.T) {
|
||||
job := jobs.Job{ResponsePayload: json.RawMessage(`{"data":{"image_urls":["https://cdn.test/a.png","javascript:alert(1)"],"results":[{"url":"https://cdn.test/a.png"},{"url":"http://cdn.test/b.png"}]},"unrelated":"https://secret.test/not-output"}`)}
|
||||
got, err := ResolveProviderOutputURLs(job)
|
||||
@@ -401,10 +374,9 @@ func (s *outputRegistrarStub) Register(context.Context, jobs.Job) ([]string, err
|
||||
}
|
||||
|
||||
type assetCreatorStub struct {
|
||||
scopes []assets.Scope
|
||||
commands []assets.ImportGeneratedCommand
|
||||
mockCommands []assets.ImportMockCommand
|
||||
existing []assets.Asset
|
||||
scopes []assets.Scope
|
||||
commands []assets.ImportGeneratedCommand
|
||||
existing []assets.Asset
|
||||
}
|
||||
|
||||
func (s *assetCreatorStub) List(_ context.Context, _ assets.Scope) ([]assets.Asset, error) {
|
||||
@@ -417,12 +389,6 @@ func (s *assetCreatorStub) ImportGenerated(_ context.Context, scope assets.Scope
|
||||
return assets.Asset{ID: "asset-" + string(rune('0'+len(s.commands)))}, nil
|
||||
}
|
||||
|
||||
func (s *assetCreatorStub) ImportMock(_ context.Context, scope assets.Scope, command assets.ImportMockCommand) (assets.Asset, error) {
|
||||
s.scopes = append(s.scopes, scope)
|
||||
s.mockCommands = append(s.mockCommands, command)
|
||||
return assets.Asset{ID: "asset-" + string(rune('0'+len(s.mockCommands)))}, nil
|
||||
}
|
||||
|
||||
type platformBuilderStub struct{}
|
||||
|
||||
func (platformBuilderStub) Build(_ context.Context, owner, client, capability, idempotency string, body map[string]any) (jobs.CreateCommand, error) {
|
||||
|
||||
Reference in new issue
Block a user