mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-07 13:28:39 +08:00
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:
@@ -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.",
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user