fix(server): wrap the shared client-name alternation like claudewatcher does (#209)
The deployment injects CLAUDE_INGEST_CLIENT_BLOCK as a bare alternation of client names; claudewatcher compiles it as (?i)\b(...)\b. The raw/ router used it raw, so a short client name would match inside ordinary words and park clips that have nothing to do with the client. INGEST_CLIENT_BLOCK stays a full regexp, used as is. Mutation-checked. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/mathiasbq/hyperguild/ingestion/internal/wing"
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -129,3 +130,41 @@ func TestEnvFlag(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// The deployment injects CLAUDE_INGEST_CLIENT_BLOCK as an ALTERNATION OF CLIENT
|
||||
// NAMES that claudewatcher wraps in \b(...)\b. Used raw, a short name would match
|
||||
// inside ordinary words and park half the clips.
|
||||
func TestIngestClientPattern(t *testing.T) {
|
||||
get := func(m map[string]string) func(string) string { return func(k string) string { return m[k] } }
|
||||
tests := []struct {
|
||||
name string
|
||||
env map[string]string
|
||||
want string
|
||||
}{
|
||||
{"nothing set", map[string]string{}, ""},
|
||||
{"explicit pattern is a full regexp, used as is", map[string]string{"INGEST_CLIENT_BLOCK": `acme\s+corp`, "CLAUDE_INGEST_CLIENT_BLOCK": "other"}, `acme\s+corp`},
|
||||
{"the shared client-name alternation is wrapped like claudewatcher wraps it", map[string]string{"CLAUDE_INGEST_CLIENT_BLOCK": "dif|trucker"}, `\b(dif|trucker)\b`},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert.Equal(t, tt.want, ingestClientPattern(get(tt.env)))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestIngestClientPattern_AShortClientNameDoesNotParkOrdinaryWords(t *testing.T) {
|
||||
pattern := ingestClientPattern(func(k string) string {
|
||||
if k == "CLAUDE_INGEST_CLIENT_BLOCK" {
|
||||
return "dif|trucker"
|
||||
}
|
||||
return ""
|
||||
})
|
||||
r, err := wing.NewRouter(t.TempDir(), "web-clip", pattern)
|
||||
require.NoError(t, err)
|
||||
d := r.Resolve(context.Background(), wing.Note{Text: "a different approach to modifying prompts"})
|
||||
assert.Equal(t, wing.Default, d.Source, "'dif' inside 'different' and 'modifying' is not the client")
|
||||
d = r.Resolve(context.Background(), wing.Note{Text: "kickoff for the DIF project next week"})
|
||||
assert.Equal(t, wing.Exception, d.Source)
|
||||
d = r.Resolve(context.Background(), wing.Note{Text: "Trucker, the client, asked for"})
|
||||
assert.Equal(t, wing.Exception, d.Source)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user