mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-13 11:40:53 +08:00
Since e233c02 the judge writer prefixes its reason with "[model]" while
interceptSource, the approvalDecisionSource SQL fallback and the archive
restore checked "[Model]", so model-decided rows were inserted with
decision_source='unknown' and missed by the decision_source=model filter.
- db: add ModelReasonPrefix ("[model]") and isModelReason, which also
accepts the pre-e233c02 "[模型]" prefix; readers compare
case-insensitively (lower(reason) LIKE in SQL).
- intercept: the writer builds its reason through JudgeReason, using the
shared constant.
- schema.sql: idempotent backfill of 'unknown' rows without a rule whose
reason carries either prefix.
- tests: un-skip TestInterceptFilterHTTP (it failed only because of
this), make the db filter fixture use the constant, and add a
Postgres-free test pinning the writer output to interceptSource.
Fixes #156
38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
package db_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/Autumn-27/artex/db"
|
|
"github.com/Autumn-27/artex/intercept"
|
|
)
|
|
|
|
// The judge writer (package intercept) and the decision_source readers (package
|
|
// db) must agree on the reason prefix; this pins them together without Postgres.
|
|
func TestInterceptSourceMatchesJudgeWriter(t *testing.T) {
|
|
for _, tc := range []struct{ action, message string }{
|
|
{"allow", ""},
|
|
{"deny", "destructive command outside the workspace"},
|
|
{"ask", db.ModelReasonPrefix + " already prefixed"},
|
|
} {
|
|
reason := intercept.JudgeReason(tc.action, tc.message)
|
|
if got := db.InterceptSource(0, reason); got != "model" {
|
|
t.Fatalf("JudgeReason(%q, %q) = %q classified as %q, want model", tc.action, tc.message, reason, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestInterceptSourceLegacyModelPrefix(t *testing.T) {
|
|
for _, reason := range []string{"[模型] 允许", "[Model] fixture"} {
|
|
if got := db.InterceptSource(0, reason); got != "model" {
|
|
t.Fatalf("%q classified as %q, want model", reason, got)
|
|
}
|
|
}
|
|
if got := db.InterceptSource(0, "legacy reason"); got != "unknown" {
|
|
t.Fatalf("plain reason classified as %q, want unknown", got)
|
|
}
|
|
if got := db.InterceptSource(7, "[model] rule wins"); got != "rule" {
|
|
t.Fatalf("rule row classified as %q, want rule", got)
|
|
}
|
|
}
|