@@ -27,10 +27,9 @@ func TestColumnExtractConfigs_SelectBest(t *testing.T) {
2727 // workspace-specific configs
2828 makeConfig (42 , "my_bot" , "coze_loop" , "llm_span" ),
2929 makeConfig (42 , "" , "coze_loop" , "llm_span" ),
30- // default configs (wsID=0, with wildcards)
31- makeConfig (0 , "" , "*" , "llm_span" ), // all platform llm_span default
32- makeConfig (0 , "" , "prompt" , "*" ), // prompt platform default
33- makeConfig (0 , "" , "*" , "*" ), // universal fallback
30+ // default configs (wsID=0)
31+ makeConfig (0 , "" , "*" , "llm_span" ), // all platform llm_span default
32+ makeConfig (0 , "" , "prompt" , "root_span" ), // prompt root_span default
3433 }
3534
3635 tests := []struct {
@@ -83,19 +82,19 @@ func TestColumnExtractConfigs_SelectBest(t *testing.T) {
8382 wantSpan : "llm_span" ,
8483 },
8584 {
86- name : "no ws match, prompt platform -> default prompt, * " ,
85+ name : "no ws match, prompt + root_span -> default prompt, root_span " ,
8786 configs : allConfigs ,
8887 workspaceId : 999 ,
8988 agentName : "" ,
9089 platformType : "prompt" ,
91- spanListType : "all_span " ,
90+ spanListType : "root_span " ,
9291 wantWsID : 0 ,
9392 wantAgent : "" ,
9493 wantPlatform : "prompt" ,
95- wantSpan : "* " ,
94+ wantSpan : "root_span " ,
9695 },
9796 {
98- name : "prompt + llm_span: spanList exact (*,llm_span) wins over platform exact (prompt,*) " ,
97+ name : "prompt + llm_span: spanList exact (*,llm_span) wins" ,
9998 configs : allConfigs ,
10099 workspaceId : 999 ,
101100 agentName : "" ,
@@ -105,19 +104,17 @@ func TestColumnExtractConfigs_SelectBest(t *testing.T) {
105104 wantAgent : "" ,
106105 wantPlatform : "*" ,
107106 wantSpan : "llm_span" ,
108- // score: (*,llm_span) = 0+0+2+0 = 2; (prompt,*) = 0+0+0+1 = 1 -> llm_span wins
109107 },
110108 {
111- name : "unknown platform + unknown spanList -> universal fallback" ,
112- configs : allConfigs ,
109+ name : "unknown platform + unknown spanList -> no match" ,
110+ // DB query with platform_type IN ('custom','*') AND span_list_type IN ('custom_span','*')
111+ // returns nothing since no universal fallback exists
112+ configs : ColumnExtractConfigs {},
113113 workspaceId : 999 ,
114114 agentName : "" ,
115115 platformType : "custom" ,
116116 spanListType : "custom_span" ,
117- wantWsID : 0 ,
118- wantAgent : "" ,
119- wantPlatform : "*" ,
120- wantSpan : "*" ,
117+ wantNil : true ,
121118 },
122119 {
123120 name : "empty configs returns nil" ,
@@ -177,10 +174,10 @@ func TestColumnExtractConfigs_SelectBest(t *testing.T) {
177174 wantNil : true ,
178175 },
179176 {
180- name : "ws match + spanList match but agent and platform mismatch -> fallback to universal " ,
177+ name : "ws match + agent and platform mismatch -> fallback to default spanList match " ,
181178 configs : ColumnExtractConfigs {
182- makeConfig (42 , "bot_a" , "prompt" , "llm_span" ), // agent mismatch, platform mismatch
183- makeConfig (0 , "" , "*" , "* " ), // universal fallback
179+ makeConfig (42 , "bot_a" , "prompt" , "llm_span" ), // agent mismatch
180+ makeConfig (0 , "" , "*" , "llm_span " ), // default with spanList match
184181 },
185182 workspaceId : 42 ,
186183 agentName : "bot_x" ,
@@ -189,7 +186,122 @@ func TestColumnExtractConfigs_SelectBest(t *testing.T) {
189186 wantWsID : 0 ,
190187 wantAgent : "" ,
191188 wantPlatform : "*" ,
192- wantSpan : "*" ,
189+ wantSpan : "llm_span" ,
190+ },
191+ {
192+ name : "exact agent wins over empty agent even when empty agent appears first" ,
193+ configs : ColumnExtractConfigs {
194+ makeConfig (42 , "" , "coze_loop" , "llm_span" ),
195+ makeConfig (42 , "my_bot" , "coze_loop" , "llm_span" ),
196+ },
197+ workspaceId : 42 ,
198+ agentName : "my_bot" ,
199+ platformType : "coze_loop" ,
200+ spanListType : "llm_span" ,
201+ wantWsID : 42 ,
202+ wantAgent : "my_bot" ,
203+ wantPlatform : "coze_loop" ,
204+ wantSpan : "llm_span" ,
205+ },
206+ {
207+ name : "ws match but spanList mismatch -> fallback to default" ,
208+ configs : ColumnExtractConfigs {
209+ makeConfig (42 , "" , "coze_loop" , "llm_span" ),
210+ makeConfig (0 , "" , "*" , "root_span" ),
211+ },
212+ workspaceId : 42 ,
213+ agentName : "" ,
214+ platformType : "coze_loop" ,
215+ spanListType : "root_span" ,
216+ wantWsID : 0 ,
217+ wantAgent : "" ,
218+ wantPlatform : "*" ,
219+ wantSpan : "root_span" ,
220+ },
221+ {
222+ name : "ws match but platform mismatch -> fallback to default wildcard platform" ,
223+ configs : ColumnExtractConfigs {
224+ makeConfig (42 , "" , "prompt" , "llm_span" ),
225+ makeConfig (0 , "" , "*" , "llm_span" ),
226+ },
227+ workspaceId : 42 ,
228+ agentName : "" ,
229+ platformType : "coze_loop" ,
230+ spanListType : "llm_span" ,
231+ wantWsID : 0 ,
232+ wantAgent : "" ,
233+ wantPlatform : "*" ,
234+ wantSpan : "llm_span" ,
235+ },
236+ {
237+ name : "fallback: first matching config wins (order dependent)" ,
238+ configs : ColumnExtractConfigs {
239+ makeConfig (0 , "" , "*" , "root_span" ),
240+ makeConfig (0 , "" , "prompt" , "root_span" ),
241+ },
242+ workspaceId : 999 ,
243+ agentName : "" ,
244+ platformType : "prompt" ,
245+ spanListType : "root_span" ,
246+ wantWsID : 0 ,
247+ wantAgent : "" ,
248+ wantPlatform : "*" ,
249+ wantSpan : "root_span" ,
250+ },
251+ {
252+ name : "fallback: exact platform wins when it appears first" ,
253+ configs : ColumnExtractConfigs {
254+ makeConfig (0 , "" , "prompt" , "root_span" ),
255+ makeConfig (0 , "" , "*" , "root_span" ),
256+ },
257+ workspaceId : 999 ,
258+ agentName : "" ,
259+ platformType : "prompt" ,
260+ spanListType : "root_span" ,
261+ wantWsID : 0 ,
262+ wantAgent : "" ,
263+ wantPlatform : "prompt" ,
264+ wantSpan : "root_span" ,
265+ },
266+ {
267+ name : "workspaceId=0 matches default configs directly" ,
268+ configs : ColumnExtractConfigs {
269+ makeConfig (0 , "" , "*" , "llm_span" ),
270+ makeConfig (0 , "" , "prompt" , "root_span" ),
271+ },
272+ workspaceId : 0 ,
273+ agentName : "" ,
274+ platformType : "coze_loop" ,
275+ spanListType : "llm_span" ,
276+ wantWsID : 0 ,
277+ wantAgent : "" ,
278+ wantPlatform : "*" ,
279+ wantSpan : "llm_span" ,
280+ },
281+ {
282+ name : "single config exact match" ,
283+ configs : ColumnExtractConfigs {
284+ makeConfig (42 , "bot" , "coze_loop" , "llm_span" ),
285+ },
286+ workspaceId : 42 ,
287+ agentName : "bot" ,
288+ platformType : "coze_loop" ,
289+ spanListType : "llm_span" ,
290+ wantWsID : 42 ,
291+ wantAgent : "bot" ,
292+ wantPlatform : "coze_loop" ,
293+ wantSpan : "llm_span" ,
294+ },
295+ {
296+ name : "single config no match -> nil" ,
297+ configs : ColumnExtractConfigs {
298+ makeConfig (42 , "" , "coze_loop" , "llm_span" ),
299+ },
300+ workspaceId : 42 ,
301+ agentName : "" ,
302+ platformType : "coze_loop" ,
303+ spanListType : "root_span" ,
304+ wantNil : true ,
193305 },
194306 }
195307
@@ -209,44 +321,6 @@ func TestColumnExtractConfigs_SelectBest(t *testing.T) {
209321 }
210322}
211323
212- func TestConfigScore (t * testing.T ) {
213- cfg := & ColumnExtractConfig {
214- WorkspaceID : 42 , AgentName : "bot" , PlatformType : "coze_loop" , SpanListType : "llm_span" ,
215- }
216- // Full exact match = 8+4+2+1 = 15
217- require .Equal (t , 15 , configScore (cfg , 42 , "bot" , "coze_loop" , "llm_span" ))
218-
219- // Cross-workspace = -1
220- require .Equal (t , - 1 , configScore (cfg , 999 , "bot" , "coze_loop" , "llm_span" ))
221-
222- // Agent mismatch (non-empty agent in config, different query agent) = -1
223- require .Equal (t , - 1 , configScore (cfg , 42 , "other" , "coze_loop" , "llm_span" ))
224-
225- // Default ws=0, wildcard platform/span
226- defaultCfg := & ColumnExtractConfig {
227- WorkspaceID : 0 , AgentName : "" , PlatformType : "*" , SpanListType : "*" ,
228- }
229- // score = 0 (default ws) + 0 (empty agent) + 0 (wildcard platform) + 0 (wildcard span) = 0
230- require .Equal (t , 0 , configScore (defaultCfg , 42 , "bot" , "coze_loop" , "llm_span" ))
231-
232- // Default ws=0, exact span
233- llmDefault := & ColumnExtractConfig {
234- WorkspaceID : 0 , AgentName : "" , PlatformType : "*" , SpanListType : "llm_span" ,
235- }
236- // score = 0 + 0 + 2 + 0 = 2
237- require .Equal (t , 2 , configScore (llmDefault , 42 , "bot" , "coze_loop" , "llm_span" ))
238-
239- // Default ws=0, exact platform
240- promptDefault := & ColumnExtractConfig {
241- WorkspaceID : 0 , AgentName : "" , PlatformType : "prompt" , SpanListType : "*" ,
242- }
243- // score = 0 + 0 + 0 + 1 = 1
244- require .Equal (t , 1 , configScore (promptDefault , 42 , "" , "prompt" , "all_span" ))
245-
246- // Platform mismatch, not wildcard = -1
247- require .Equal (t , - 1 , configScore (promptDefault , 42 , "" , "coze_loop" , "llm_span" ))
248- }
249-
250324func TestColumnExtractConfig_Extract (t * testing.T ) {
251325 cfg := & ColumnExtractConfig {
252326 Columns : []ColumnExtractRule {
0 commit comments