8000 test(agentcore): run test by Fodesu · Pull Request #84 · felinics/twilight · GitHub
[go: up one dir, main page]

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
32 changes: 32 additions & 0 deletions agentcore/run/creation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package run

import (
"testing"

"github.com/felinics/twilight/agentcore/ledger"
)

func mustNewRun(t testing.TB, id RunID, cause ledger.CausationID) NewRun {
t.Helper()
run, err := BuildNewRun(id, cause)
if err != nil {
t.Fatal(err)
}
return run
}

func TestNewRunValidation(t *testing.T) {
created := mustNewRun(t, "run-1", "session-1")
if created.RunID != "run-1" {
t.Fatalf("run id = %q", created.RunID)
}
for _, candidate := range []NewRun{
{},
{RunID: RunID(string([]byte{0xff}))},
{RunID: "run-1", CausationID: ledger.CausationID(string([]byte{0xff}))},
} {
if err := ValidateNewRun(candidate); err == nil {
t.Fatalf("invalid NewRun accepted: %+v", candidate)
}
}
}
28 changes: 28 additions & 0 deletions agentcore/run/fact_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package run

import (
"encoding/json"
"testing"
)

// RunEnded validates its tagged terminal value on the way to the wire: no
// end, an incomplete end or an end variant the schema does not know is
// refused by MarshalJSON, so no fact encoder can persist it.
func TestRunEndedTaggedUnionRejectsInvalidValues(t *testing.T) {
for name, fact := range map[string]RunEnded{
"nil end": {},
"stopped without reason": {End: RunStoppedEnd{}},
"failed without class": {End: RunFailedEnd{Reason: ReasonProviderFailure}},
"unknown end variant": {End: fakeRunEnd{}},
} {
t.Run(name, func(t *testing.T) {
if _, err := json.Marshal(fact); err == nil {
t.Fatal("invalid tagged terminal value was accepted")
}
})
}
}

type fakeRunEnd struct{}

func (fakeRunEnd) runEnd() {}
5 changes: 4 additions & 1 deletion provider/mimo/speech/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package speech

import "strings"

// formatPCM16 is the raw PCM output format name on the MiMo wire.
const formatPCM16 = "pcm16"

type audioConfig struct {
Voice string
Format string
Expand Down Expand Up @@ -30,7 +33,7 @@ func parseConfig(cfg map[string]any) audioConfig {

func contentTypeForFormat(format string) string {
switch strings.ToLower(strings.TrimSpace(format)) {
case "pcm16":
case formatPCM16:
return "audio/pcm"
case "wav":
return "audio/wav"
Expand Down
10 changes: 6 additions & 4 deletions provider/openai/completions/kimi_schema.go
8000
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
)

const kimiObjectType = "object"

// normalizeSchemaForKimi converts the supported subset of standard JSON
// Schema into Moonshot-flavored JSON Schema (MFJS). It always works on a deep
// copy so a provider request cannot mutate the caller's tool definition.
Expand Down Expand Up @@ -173,7 +175,7 @@ func normalizeKimiAnyOf(schema map[string]any, anyOf []any, path string) error {
}

hasObjectBundle := hasAnySchemaKeyword(schema, "properties", "required", "additionalProperties")
if parentType == "object" && hasObjectBundle {
if parentType == kimiObjectType && hasObjectBundle {
return distributeKimiObjectBundle(schema, anyOf, path)
}
if hasObjectBundle {
Expand Down Expand Up @@ -250,8 +252,8 @@ func distributeKimiObjectBundle(schema map[string]any, anyOf []any, path string)
}
if rawBranchType, exists := branch["type"]; exists {
branchType, ok := rawBranchType.(string)
if !ok || branchType != "object" {
return fmt.Errorf("%s.type: %v conflicts with parent type %q", branchPath, rawBranchType, "object")
if !ok || branchType != kimiObjectType {
return fmt.Errorf("%s.type: %v conflicts with parent type %q", branchPath, rawBranchType, kimiObjectType)
}
}
branchRequired, err := schemaStringArray(branch["required"], branchPath+".required")
Expand All @@ -263,7 +265,7 @@ func distributeKimiObjectBundle(schema map[string]any, anyOf []any, path string)
return err
}

branch["type"] = "object"
branch["type"] = kimiObjectType
branch["properties"] = cloneJSONValue(properties)
if hasAdditional {
branch["additionalProperties"] = rawAdditional
Expand Down
Loading
0