fix(chat): preserve layered IM workflow contracts

This commit is contained in:
克谨
2026-08-11 11:48:39 +08:00
parent 0148ad1800
commit 82dfee7291
8 changed files with 125 additions and 72 deletions
+1 -23
View File
@@ -79,23 +79,6 @@ type parameterSchema struct {
Enum []string `json:"enum,omitempty"`
}
type reviewedCompatibilityException struct {
Field string
Old string
New string
}
// reviewedCompatibilityExceptions is intentionally exact: safety fixes may
// need to tighten a historical contract, but that must not turn arbitrary
// confirmation drift into a compatible change.
var reviewedCompatibilityExceptions = map[string]reviewedCompatibilityException{
"chat/chat.update_streaming_card": {
Field: "confirmation",
Old: "not_required",
New: "user_required",
},
}
func main() {
os.Exit(run(os.Args[1:], os.Stdout, os.Stderr))
}
@@ -621,7 +604,7 @@ func checkToolCompatibility(toolPath string, oldTool, newTool toolSchema) []stri
{name: "confirmation", old: oldTool.Confirmation, new: newTool.Confirmation},
{name: "idempotency", old: oldTool.Idempotency, new: newTool.Idempotency},
} {
if field.old != field.new && !isReviewedCompatibilityException(toolPath, field.name, field.old, field.new) {
if field.old != field.new {
failures = append(failures, fmt.Sprintf("schema tool %q changed %s", toolPath, field.name))
}
}
@@ -657,11 +640,6 @@ func checkToolCompatibility(toolPath string, oldTool, newTool toolSchema) []stri
return failures
}
func isReviewedCompatibilityException(toolPath, field, oldValue, newValue string) bool {
exception, ok := reviewedCompatibilityExceptions[toolPath]
return ok && exception.Field == field && exception.Old == oldValue && exception.New == newValue
}
// reviewedInterfaceRefRedirect enumerates the exact, individually reviewed
// backend RPC migrations this gate accepts. Schema shape alone cannot prove two
// RPCs share business semantics, permissions, error behaviour, or side effects,
-19
View File
@@ -415,25 +415,6 @@ func TestSchemaCompatibilityRejectsContractDrift(t *testing.T) {
}
}
func TestSchemaCompatibilityAcceptsReviewedCardConfirmationHardening(t *testing.T) {
oldTool := baselineContract().Products["doc"].Tools["doc.create"]
newTool := oldTool
newTool.Confirmation = "user_required"
if failures := checkToolCompatibility("chat/chat.update_streaming_card", oldTool, newTool); len(failures) != 0 {
t.Fatalf("reviewed confirmation hardening failures = %v", failures)
}
if failures := checkToolCompatibility("chat/chat.other", oldTool, newTool); len(failures) == 0 {
t.Fatal("unreviewed confirmation hardening unexpectedly passed")
}
oldTool.Confirmation = "user_required"
newTool.Confirmation = "not_required"
if failures := checkToolCompatibility("chat/chat.update_streaming_card", oldTool, newTool); len(failures) == 0 {
t.Fatal("reviewed tool confirmation weakening unexpectedly passed")
}
}
func TestMergeContracts(t *testing.T) {
historical := baselineContract()
current := cloneContract(historical)