Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions examples/testutil/live.go

This file was deleted.

34 changes: 0 additions & 34 deletions examples/testutil/testutil.go

This file was deleted.

14 changes: 7 additions & 7 deletions forward/batch_execution_live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import (
"testing"

"github.com/QoderAI/qoder-cloud-agents-sdk-go/convention/option"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/examples/testutil"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/forward"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/internal/testsupport"
)

func TestForwardBatchE2ELive(t *testing.T) {
testutil.RequireE2E(t, "FORWARD")
testsupport.RequireE2E(t, "FORWARD")
s := newLiveSuite(t, "WRITE", "EXECUTION")
ctx, cancel := context.WithTimeout(context.Background(), testutil.ExecutionTimeout(t))
ctx, cancel := context.WithTimeout(context.Background(), testsupport.ExecutionTimeout(t))
defer cancel()
identity := s.identity(t)
template := s.template(t, s.environment(t).ID)
marker := testutil.Marker(t)
marker := testsupport.Marker(t)
customID := liveName("task")
line, err := json.Marshal(map[string]any{"custom_id": customID, "template_id": template.ID, "identity_id": identity.ID, "body": map[string]any{"input": "Reply with exactly " + marker}})
liveCheck(t, err)
Expand All @@ -44,7 +44,7 @@ func TestForwardBatchE2ELive(t *testing.T) {
if batchTerminal(batch.Status) {
break
}
if err = testutil.PollPause(ctx); err != nil {
if err = testsupport.PollPause(ctx); err != nil {
t.Fatalf("batch=%s status=%s (execution depends on the server's batch window): %v", batchID, batch.Status, err)
}
}
Expand Down Expand Up @@ -132,7 +132,7 @@ func (s *liveSuite) finishBatch(ctx context.Context, id, customID, identityID, t
if batchTerminal(current.Status) {
break
}
if err = testutil.PollPause(ctx); err != nil {
if err = testsupport.PollPause(ctx); err != nil {
return fmt.Errorf("batch=%s remains %s: %w", id, current.Status, err)
}
}
Expand All @@ -144,7 +144,7 @@ func (s *liveSuite) finishBatch(ctx context.Context, id, customID, identityID, t
}
rows, err := s.batchOutput(ctx, id)
if err != nil {
return &testutil.CleanupFailure{Err: err}
return &testsupport.CleanupFailure{Err: err}
}
if len(rows) != 1 || rows[0].CustomID != customID || rows[0].IdentityID != identityID || rows[0].TemplateID != templateID {
return fmt.Errorf("batch=%s cleanup output does not match the test input", id)
Expand Down
4 changes: 2 additions & 2 deletions forward/cleanup_live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package forward_test
import (
"context"
"encoding/json"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/examples/testutil"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/internal/testsupport"
"io"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestBatchMissingOutputCleanupOffline(t *testing.T) {
return reply(r, 200, `{"id":"batch","status":"cancelled","output_file_id":"internal","request_counts":{"total":1}}`), nil
})}
err := s.finishBatch(context.Background(), "batch", "task", "identity", "template")
if err == nil || testutil.ResourceAlreadyGone(err) {
if err == nil || testsupport.ResourceAlreadyGone(err) {
t.Fatalf("missing output silently ignored: %v", err)
}
}
Expand Down
23 changes: 13 additions & 10 deletions forward/execution_live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (

"github.com/QoderAI/qoder-cloud-agents-sdk-go/convention"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/convention/option"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/examples/testutil"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/forward"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/internal/testsupport"
)

func (s *liveSuite) waitTurn(t *testing.T, sessionID, after string, expected []string, tool, streaming bool) {
t.Helper()
ctx, cancel := context.WithTimeout(context.Background(), testutil.ExecutionTimeout(t))
ctx, cancel := context.WithTimeout(context.Background(), testsupport.ExecutionTimeout(t))
defer cancel()
result := testutil.TurnResult{LastID: after}
result := testsupport.TurnResult{LastID: after}
observe := func(raw string) bool {
t.Helper()
if err := result.Observe(raw); err != nil {
Expand All @@ -29,7 +29,7 @@ func (s *liveSuite) waitTurn(t *testing.T, sessionID, after string, expected []s
return result.Complete
}
if streaming {
stream := s.client.Sessions.Events.StreamEvents(ctx, sessionID, forward.SessionEventStreamParams{LastEventID: forward.String(after), IncludeToolCalls: forward.Bool(true)}, option.WithRequestTimeout(testutil.ExecutionTimeout(t)))
stream := s.client.Sessions.Events.StreamEvents(ctx, sessionID, forward.SessionEventStreamParams{LastEventID: forward.String(after), IncludeToolCalls: forward.Bool(true)}, option.WithRequestTimeout(testsupport.ExecutionTimeout(t)))
defer stream.Close()
for stream.Next() {
if observe(stream.Current().RawJSON()) {
Expand All @@ -54,7 +54,7 @@ func (s *liveSuite) waitTurn(t *testing.T, sessionID, after string, expected []s
if result.Complete {
break
}
liveCheck(t, testutil.PollPause(ctx))
liveCheck(t, testsupport.PollPause(ctx))
}
}
if err := result.Verify(expected, tool); err != nil {
Expand Down Expand Up @@ -93,7 +93,7 @@ func (s *liveSuite) finishSession(ctx context.Context, id string) error {
if session.Status == "idle" || session.Status == "terminated" {
break
}
if err = testutil.PollPause(ctx); err != nil {
if err = testsupport.PollPause(ctx); err != nil {
return err
}
}
Expand All @@ -102,12 +102,15 @@ func (s *liveSuite) finishSession(ctx context.Context, id string) error {
return err
}
func TestForwardExecutionE2ELive(t *testing.T) {
testutil.RequireE2E(t, "FORWARD")
testsupport.RequireE2E(t, "FORWARD")
s := newLiveSuite(t, "WRITE", "EXECUTION")
ctx := s.context(t)
env := s.environment(t)
identity := s.identity(t)
fileToken, envToken, skillToken, memoryToken := testutil.Marker(t), testutil.Marker(t), testutil.Marker(t), testutil.Marker(t)
identityName := liveName("identity")
identity, err := s.client.Identities.New(ctx, forward.IdentityNewParams{ExternalID: identityName, Name: forward.String(identityName), Metadata: map[string]any{"suite": "sdk-live"}})
liveCheck(t, err)
s.cleanup(t, "identity", func(ctx context.Context) error { _, err := s.client.Identities.Delete(ctx, identity.ID); return err })
fileToken, envToken, skillToken, memoryToken := testsupport.Marker(t), testsupport.Marker(t), testsupport.Marker(t), testsupport.Marker(t)
file := s.file(t, "sdk-e2e.txt", "session_resource", fileToken)
skillName := liveName("proof")
skill, err := s.client.Skills.New(ctx, forward.SkillNewParams{Files: []io.Reader{convention.UploadFile{Name: skillName + "/SKILL.md", Reader: strings.NewReader(fmt.Sprintf("---\nname: %s\ndescription: Provides the SDK_E2E_SKILL_TOKEN for SDK verification.\n---\nWhen asked for SDK_E2E_SKILL_TOKEN return exactly: %s\n", skillName, skillToken))}}})
Expand Down Expand Up @@ -136,7 +139,7 @@ func TestForwardExecutionE2ELive(t *testing.T) {
liveCheck(t, err)
s.cleanupSession(t, session.ID)
t.Logf("model=%s identity=%s template=%s file=%s skill=%s memory_store=%s", os.Getenv("QODER_FORWARD_MODEL"), identity.ID, template.ID, file.ID, skill.ID, store.ID)
echo := testutil.Marker(t)
echo := testsupport.Marker(t)
for _, scenario := range []struct {
name, prompt string
expected []string
Expand Down
8 changes: 4 additions & 4 deletions forward/failure_contracts_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package forward_test

import (
"github.com/QoderAI/qoder-cloud-agents-sdk-go/examples/testutil"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/internal/testsupport"
"testing"
)

func TestForwardFailureContracts(t *testing.T) {
var endpoints []testutil.Endpoint
var endpoints []testsupport.Endpoint
for _, c := range contracts(t) {
endpoints = append(endpoints, testutil.Endpoint{Service: c.Service, Method: c.Name})
endpoints = append(endpoints, testsupport.Endpoint{Service: c.Service, Method: c.Name})
}
testutil.FailureContracts(t, endpoints, func(fn testutil.Transport) any { return testClient(roundTripFunc(fn)) })
testsupport.FailureContracts(t, endpoints, func(fn testsupport.Transport) any { return testClient(roundTripFunc(fn)) })
}
10 changes: 5 additions & 5 deletions forward/live_helpers_live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

"github.com/QoderAI/qoder-cloud-agents-sdk-go/convention"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/convention/option"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/examples/testutil"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/forward"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/internal/testsupport"
)

type liveSuite struct {
Expand Down Expand Up @@ -43,7 +43,7 @@ func newLiveSuite(t *testing.T, gates ...string) *liveSuite {
}
}
timeout := time.Duration(seconds) * time.Second
return &liveSuite{timeout: timeout, scenarioTimeout: testutil.ExecutionTimeout(t), client: forward.NewClient(option.WithPAT(os.Getenv("QODER_FORWARD_PAT")), option.WithRequestTimeout(timeout), option.WithMaxRetries(0), testutil.RequestLog(t))}
return &liveSuite{timeout: timeout, scenarioTimeout: testsupport.ExecutionTimeout(t), client: forward.NewClient(option.WithPAT(os.Getenv("QODER_FORWARD_PAT")), option.WithRequestTimeout(timeout), option.WithMaxRetries(0), testsupport.RequestLog(t))}
}

func liveEnabled(gate string) bool {
Expand All @@ -54,7 +54,7 @@ func liveName(prefix string) string { return fmt.Sprintf("sdk-%s-%d", prefix, ti
func liveCheck(t *testing.T, err error) {
t.Helper()
if err != nil {
t.Fatal(testutil.SafeError(err))
t.Fatal(testsupport.SafeError(err))
}
}
func (s *liveSuite) context(t *testing.T) context.Context {
Expand All @@ -69,10 +69,10 @@ func (s *liveSuite) cleanup(t *testing.T, label string, fn func(context.Context)
ctx, cancel := context.WithTimeout(context.Background(), s.scenarioTimeout)
defer cancel()
if err := fn(ctx); err != nil {
if testutil.ResourceAlreadyGone(err) {
if testsupport.ResourceAlreadyGone(err) {
return
}
t.Errorf("cleanup %s: %s", label, testutil.SafeError(err))
t.Errorf("cleanup %s: %s", label, testsupport.SafeError(err))
}
})
}
Expand Down
12 changes: 6 additions & 6 deletions forward/schedule_execution_live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ package forward_test
import (
"context"
"fmt"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/examples/testutil"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/forward"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/internal/testsupport"
"testing"
)

func TestForwardScheduleE2ELive(t *testing.T) {
testutil.RequireE2E(t, "FORWARD")
testsupport.RequireE2E(t, "FORWARD")
s := newLiveSuite(t, "WRITE", "EXECUTION")
ctx, cancel := context.WithTimeout(context.Background(), testutil.ExecutionTimeout(t))
ctx, cancel := context.WithTimeout(context.Background(), testsupport.ExecutionTimeout(t))
defer cancel()
env := s.environment(t)
identity := s.identity(t)
template := s.template(t, env.ID)
marker := testutil.Marker(t)
marker := testsupport.Marker(t)
schedule, err := s.client.Schedules.New(ctx, forward.ScheduleNewParams{IdentityID: identity.ID, TemplateID: template.ID, EnvironmentID: env.ID, Name: liveName("schedule-e2e"), InitialEvents: []map[string]any{{"type": "user.message", "content": "Reply with exactly " + marker}}, TriggerPolicy: map[string]any{"type": "manual"}, Execution: map[string]any{"max_attempts": 1, "max_concurrent_runs": 1}})
liveCheck(t, err)
s.cleanup(t, "schedule "+schedule.ID, func(ctx context.Context) error {
Expand All @@ -43,7 +43,7 @@ func TestForwardScheduleE2ELive(t *testing.T) {
if run.Status == "failed" || run.Status == "skipped" {
t.Fatalf("schedule run=%s status=%s", runID, run.Status)
}
if err = testutil.PollPause(ctx); err != nil {
if err = testsupport.PollPause(ctx); err != nil {
t.Fatalf("schedule run=%s session=%s status=%s: %v", runID, sessionID, run.Status, err)
}
}
Expand All @@ -68,7 +68,7 @@ func (s *liveSuite) finishScheduleRun(ctx context.Context, runID, identityID str
if run.Status == "completed" {
return fmt.Errorf("completed run %s has no session", runID)
}
if err = testutil.PollPause(ctx); err != nil {
if err = testsupport.PollPause(ctx); err != nil {
return fmt.Errorf("run=%s remains %s without a session: %w", runID, run.Status, err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions forward/test_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (

"github.com/QoderAI/qoder-cloud-agents-sdk-go/convention"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/convention/option"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/examples/testutil"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/forward"
"github.com/QoderAI/qoder-cloud-agents-sdk-go/internal/testsupport"
)

const pathSegment = "segment /?%#"
Expand Down Expand Up @@ -338,7 +338,7 @@ func checkDecoded(t *testing.T, result any) {
}
func checkFields(t *testing.T, v reflect.Value, path string) {
t.Helper()
testutil.CheckFields(t, v, path)
testsupport.CheckFields(t, v, path)
}

func jsonObject(t *testing.T, value any) map[string]any {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package testutil contains shared assertions for the two SDK contract suites.
package testutil
package testsupport

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testutil
package testsupport

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testutil
package testsupport

import (
"encoding/json"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package testutil
package testsupport

import (
"context"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//go:build live

package testutil
package testsupport

import (
"context"
Expand Down
14 changes: 14 additions & 0 deletions internal/testsupport/surface_offline_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package testsupport

// 反向守护:若任一离线符号被误挪到 //go:build live 文件,此文件离线编译即 RED。
var (
_ Endpoint
_ Transport
_ TurnResult
_ CleanupFailure
_ = FailureContracts
_ = CheckFields
_ = InvokeJSON
_ = SafeError
_ = ResourceAlreadyGone
)
Loading
Loading