Re-vendor the shared files from sneak/prompts at 0653579 (closes #52)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
Takes .golangci.yml, .dockerignore, .gitignore, .editorconfig, the workflow and REPO_POLICIES.md from sneak/prompts 0653579, with this repository's own entries after the shared content. Lint (golangci-lint v2.14.0) and test are Dockerfile phases that script/lint and script/test build alone with a new CACHEBUST value, keeping Go's and golangci-lint's caches; the image build depends on both. make fmt and make fmt-check also format the markdown with prettier, pinned in yarn.lock. The agent guidance moves to AGENTS.md. The Go code is fixed for what the new configuration finds, and the AS and prefix detail reads now return the rows' error after their loops. Model: opus-5-5
This commit was merged in pull request #85.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// Package ristypes defines the data structures for RIS Live BGP messages and announcements.
|
||||
// Package ristypes defines the data structures for RIS Live BGP messages and
|
||||
// announcements.
|
||||
package ristypes
|
||||
|
||||
import (
|
||||
@@ -33,25 +34,30 @@ type ASPath []int
|
||||
func (p *ASPath) UnmarshalJSON(data []byte) error {
|
||||
// First try to unmarshal as a simple array of integers
|
||||
var simple []int
|
||||
if err := json.Unmarshal(data, &simple); err == nil {
|
||||
|
||||
err := json.Unmarshal(data, &simple)
|
||||
if err == nil {
|
||||
*p = ASPath(simple)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// If that fails, unmarshal as array of interfaces and flatten
|
||||
var raw []interface{}
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
var raw []any
|
||||
|
||||
err = json.Unmarshal(data, &raw)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Flatten the array
|
||||
result := make([]int, 0)
|
||||
|
||||
for _, item := range raw {
|
||||
switch v := item.(type) {
|
||||
case float64:
|
||||
result = append(result, int(v))
|
||||
case []interface{}:
|
||||
case []any:
|
||||
// Nested array - flatten it
|
||||
for _, nested := range v {
|
||||
if num, ok := nested.(float64); ok {
|
||||
@@ -78,6 +84,8 @@ type RISLiveMessage struct {
|
||||
// It contains metadata about the BGP session (peer, ASN, host) along with
|
||||
// the actual BGP update data including AS path, communities, announcements,
|
||||
// and withdrawals.
|
||||
//
|
||||
//nolint:tagliatelle // field names are the RIS Live feed's
|
||||
type RISMessage struct {
|
||||
Type string `json:"type"`
|
||||
Timestamp float64 `json:"timestamp"`
|
||||
@@ -108,6 +116,8 @@ type RISMessage struct {
|
||||
// RISAnnouncement represents a BGP route announcement within a RIS message.
|
||||
// It contains the next hop IP address and the list of prefixes being announced
|
||||
// via that next hop.
|
||||
//
|
||||
//nolint:tagliatelle // field names are the RIS Live feed's
|
||||
type RISAnnouncement struct {
|
||||
NextHop string `json:"next_hop"`
|
||||
Prefixes []string `json:"prefixes"`
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package ristypes
|
||||
package ristypes_test
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"git.eeqj.de/sneak/routewatch/internal/ristypes"
|
||||
)
|
||||
|
||||
// messageExamplesPath is the captured RIS Live feed used as decode fixtures,
|
||||
@@ -15,32 +17,43 @@ const messageExamplesPath = "../../docs/message-examples.json"
|
||||
// streamer does and checks that the fields no handler reads (Community, Raw)
|
||||
// stay empty while the fields handlers use (Path, Announcements) still decode.
|
||||
func TestDecodeDropsCommunityAndRaw(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
f, err := os.Open(messageExamplesPath)
|
||||
if err != nil {
|
||||
t.Fatalf("open fixtures: %v", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
defer func() {
|
||||
_ = f.Close()
|
||||
}()
|
||||
|
||||
var messages, withPath, withAnnouncements int
|
||||
|
||||
scanner := bufio.NewScanner(f)
|
||||
scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Bytes()
|
||||
if len(line) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
var wrapper RISLiveMessage
|
||||
if err := json.Unmarshal(line, &wrapper); err != nil {
|
||||
var wrapper ristypes.RISLiveMessage
|
||||
|
||||
err := json.Unmarshal(line, &wrapper)
|
||||
if err != nil {
|
||||
t.Fatalf("unmarshal message %d: %v", messages+1, err)
|
||||
}
|
||||
|
||||
messages++
|
||||
|
||||
msg := wrapper.Data
|
||||
if msg.Community != nil {
|
||||
t.Errorf("message %d: Community decoded, want empty: %v", messages, msg.Community)
|
||||
t.Errorf("message %d: Community decoded, want empty: %v",
|
||||
messages, msg.Community)
|
||||
}
|
||||
|
||||
if msg.Raw != "" {
|
||||
t.Errorf("message %d: Raw decoded, want empty", messages)
|
||||
}
|
||||
@@ -48,11 +61,14 @@ func TestDecodeDropsCommunityAndRaw(t *testing.T) {
|
||||
if len(msg.Path) > 0 {
|
||||
withPath++
|
||||
}
|
||||
|
||||
if len(msg.Announcements) > 0 {
|
||||
withAnnouncements++
|
||||
}
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
|
||||
err = scanner.Err()
|
||||
if err != nil {
|
||||
t.Fatalf("scan fixtures: %v", err)
|
||||
}
|
||||
|
||||
@@ -62,6 +78,7 @@ func TestDecodeDropsCommunityAndRaw(t *testing.T) {
|
||||
// The fixtures include announcement messages; a used field must still decode,
|
||||
// otherwise an empty Community/Raw would prove nothing.
|
||||
if withPath == 0 || withAnnouncements == 0 {
|
||||
t.Fatalf("used fields did not decode: withPath=%d withAnnouncements=%d", withPath, withAnnouncements)
|
||||
t.Fatalf("used fields did not decode: withPath=%d withAnnouncements=%d",
|
||||
withPath, withAnnouncements)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user