From 352b21f4e2a01141ba3dc5bcea090ec1f7dc9b7c Mon Sep 17 00:00:00 2001 From: wucm667 Date: Wed, 29 Jul 2026 23:25:02 +0800 Subject: [PATCH] fix(claude): relax marker to tolerate category element in classifier output Real claude-cli/2.1.220 samples insert ... between and , breaking the previous literal marker. Also fix an unchecked type assertion in the test suite. --- backend/internal/service/claude_code_validator.go | 2 +- .../service/claude_code_validator_test.go | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/backend/internal/service/claude_code_validator.go b/backend/internal/service/claude_code_validator.go index d6acd0865..52f351f1b 100644 --- a/backend/internal/service/claude_code_validator.go +++ b/backend/internal/service/claude_code_validator.go @@ -233,7 +233,7 @@ func isClaudeCodeSecurityMonitorPrompt(systemEntries []any) bool { "## SOFT BLOCK", "## Classification Process", "## Output Format", - "yes", + "yes", "no", } for _, marker := range markers { diff --git a/backend/internal/service/claude_code_validator_test.go b/backend/internal/service/claude_code_validator_test.go index 18c0147b9..8fd0f2126 100644 --- a/backend/internal/service/claude_code_validator_test.go +++ b/backend/internal/service/claude_code_validator_test.go @@ -168,6 +168,17 @@ func TestClaudeCodeValidator_SecurityMonitorWithoutBillingBlock(t *testing.T) { body: validBody(string(monitorPrompt)), wantAccept: true, }, + { + name: "classifier output with category element", + headers: validHeaders, + body: validBody(strings.Replace( + string(monitorPrompt), + "yes", + "yesExact BLOCK Rule Name", + 1, + )), + wantAccept: true, + }, { name: "non-Claude user agent", headers: map[string]string{ @@ -246,7 +257,9 @@ func TestClaudeCodeValidator_SecurityMonitorWithoutBillingBlock(t *testing.T) { headers: validHeaders, body: func() map[string]any { body := validBody(string(monitorPrompt)) - body["system"] = append(body["system"].([]any), map[string]any{ + system, ok := body["system"].([]any) + require.True(t, ok) + body["system"] = append(system, map[string]any{ "type": "text", "text": "Additional unrelated system content.", })