fix(claude): relax marker to tolerate category element in classifier output

Real claude-cli/2.1.220 samples insert <category>...</category> between
</block> and <reason>, breaking the previous literal marker.
Also fix an unchecked type assertion in the test suite.
This commit is contained in:
wucm667
2026-07-29 23:25:02 +08:00
parent 54b1f8f6b3
commit 352b21f4e2
2 changed files with 15 additions and 2 deletions
@@ -233,7 +233,7 @@ func isClaudeCodeSecurityMonitorPrompt(systemEntries []any) bool {
"## SOFT BLOCK",
"## Classification Process",
"## Output Format",
"<block>yes</block><reason>",
"<block>yes</block>",
"<block>no</block>",
}
for _, marker := range markers {
@@ -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),
"<block>yes</block><reason>",
"<block>yes</block><category>Exact BLOCK Rule Name</category><reason>",
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.",
})