- Adds nullable `workspace_id` to AI Gateway interceptions without a foreign key or index. - Derives direct attribution from strictly parsed server-minted workspace session-token names, excluding user-created tokens and validating the embedded owner. - Derives delegated Coder Agents attribution from the persisted chat workspace ID. - Records `workspace_id` through the additive v1.3 gateway protocol and structured interception logs. - Exposes attribution in session details through `interception_attributions`, including tool-less interceptions and null values for unknown attribution. Closes AIGOV-637 Generated by Coder Agents.
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package codersdk_test
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/v2/codersdk"
|
|
)
|
|
|
|
func TestAIBridgeAttributionMarshalJSON(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
for _, tt := range []struct {
|
|
name string
|
|
attribution codersdk.AIBridgeAttribution
|
|
want string
|
|
}{
|
|
{name: "nil", want: `{}`},
|
|
{name: "empty", attribution: codersdk.AIBridgeAttribution{}, want: `{}`},
|
|
{name: "known", attribution: codersdk.AIBridgeAttribution{"workspace_id": "workspace-id"}, want: `{"workspace_id":"workspace-id"}`},
|
|
} {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
t.Parallel()
|
|
data, err := json.Marshal(tt.attribution)
|
|
require.NoError(t, err)
|
|
require.JSONEq(t, tt.want, string(data))
|
|
|
|
for _, value := range []any{
|
|
codersdk.AIBridgeThread{Attribution: tt.attribution},
|
|
codersdk.AIBridgeAgenticAction{Attribution: tt.attribution},
|
|
} {
|
|
data, err := json.Marshal(value)
|
|
require.NoError(t, err)
|
|
var fields map[string]json.RawMessage
|
|
require.NoError(t, json.Unmarshal(data, &fields))
|
|
require.JSONEq(t, tt.want, string(fields["attribution"]))
|
|
}
|
|
})
|
|
}
|
|
}
|