alt/apps/cli/internal/operator/parser_map_test.go
toki c0db4b24c1 feat(live-trading): 계좌 동기화와 감사 추적을 추가한다
Live Trading Boundary의 남은 account-sync/audit-trail 작업을 완료해 운영자 headless workflow와 roadmap 완료 후보 상태를 함께 반영한다.
2026-06-08 11:18:41 +09:00

88 lines
2.7 KiB
Go

package operator
import (
"testing"
"google.golang.org/protobuf/proto"
altv1 "git.toki-labs.com/toki/alt/packages/contracts/gen/go/alt/v1"
protoSocket "git.toki-labs.com/toki/proto-socket/go"
)
func TestParserMapIncludesRunnerMessages(t *testing.T) {
pm := ParserMap()
required := []proto.Message{
&altv1.HelloRequest{},
&altv1.HelloResponse{},
&altv1.ListInstrumentsRequest{},
&altv1.ListInstrumentsResponse{},
&altv1.ListBarsRequest{},
&altv1.ListBarsResponse{},
// market import command surface a later CLI subtask sends/receives
&altv1.ImportDailyBarsRequest{},
&altv1.ImportDailyBarsResponse{},
// backtest surface is parsed too so the CLI rail matches the API/worker
// parser maps and a later subtask can reuse it without drift.
&altv1.StartBacktestRequest{},
&altv1.GetBacktestResultResponse{},
&altv1.CompareBacktestRunsResponse{},
// paper trading surface is parsed too so the CLI rail matches the
// API/worker parser maps for paper start/state without drift.
&altv1.StartPaperTradingRequest{},
&altv1.StartPaperTradingResponse{},
&altv1.GetPaperTradingStateRequest{},
&altv1.GetPaperTradingStateResponse{},
&altv1.PaperTradingState{},
// paper order lifecycle surface: submit / cancel / fill
&altv1.SubmitPaperOrderRequest{},
&altv1.SubmitPaperOrderResponse{},
&altv1.CancelPaperOrderRequest{},
&altv1.CancelPaperOrderResponse{},
&altv1.FillPaperOrderRequest{},
&altv1.FillPaperOrderResponse{},
// live trading surface: broker capability probe
&altv1.GetLiveBrokerCapabilitiesRequest{},
&altv1.GetLiveBrokerCapabilitiesResponse{},
&altv1.LiveBrokerCapability{},
// live account sync surface: sync from broker / get last snapshot
&altv1.SyncLiveAccountRequest{},
&altv1.SyncLiveAccountResponse{},
&altv1.GetLiveAccountSnapshotRequest{},
&altv1.GetLiveAccountSnapshotResponse{},
&altv1.LiveAccountSnapshot{},
&altv1.LiveCashBalance{},
&altv1.LivePositionSnapshot{},
}
for _, m := range required {
name := protoSocket.TypeNameOf(m)
if _, ok := pm[name]; !ok {
t.Errorf("parser map missing %q", name)
}
}
}
func TestParserMapRoundTripsHelloResponse(t *testing.T) {
pm := ParserMap()
name := protoSocket.TypeNameOf(&altv1.HelloResponse{})
parser, ok := pm[name]
if !ok {
t.Fatalf("parser map missing %q", name)
}
data, err := proto.Marshal(&altv1.HelloResponse{ServerName: "alt-api", Capabilities: []string{"hello"}})
if err != nil {
t.Fatalf("marshal: %v", err)
}
msg, err := parser(data)
if err != nil {
t.Fatalf("parse: %v", err)
}
resp, ok := msg.(*altv1.HelloResponse)
if !ok {
t.Fatalf("parsed %T, want *altv1.HelloResponse", msg)
}
if resp.GetServerName() != "alt-api" {
t.Errorf("server name = %q, want alt-api", resp.GetServerName())
}
}