From a599ab80d8db80bfa275bad9845b933290044482 Mon Sep 17 00:00:00 2001 From: HosniBelfeki Date: Sun, 1 Nov 2026 22:54:19 +0100 Subject: [PATCH] node: build the facts-limit test rules without the parser authorizerFactLimitRules parsed its 1100 rules one by one, and biscuit-go's parser.FromStringRule builds a new grammar on every call. Under the race detector that took about 12s, inside the 15s context of TestCallMCPTool_ProviderNotGrantedIsNotRetried, so on a busy runner the second tool call ran out of time and failed with "context deadline exceeded" instead of the facts limit. Build the same rules as biscuit.Rule values. The authorizer evaluates exactly the same rules, so both tests still stop at the facts limit. --- internal/node/labels_gate_test.go | 20 +++++++++++--------- internal/node/mcp_handlers_test.go | 2 +- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/internal/node/labels_gate_test.go b/internal/node/labels_gate_test.go index 49820fe6..b163903b 100644 --- a/internal/node/labels_gate_test.go +++ b/internal/node/labels_gate_test.go @@ -359,15 +359,17 @@ func TestLabelGateTellsUnreachableFromDenied(t *testing.T) { // authorizerFactLimitRules are mesh policy rules that derive more facts // from role(node) than the authorizer admits, so any check that adds them // stops at datalog.ErrWorldRunLimitMaxFacts before it reaches a verdict. -func authorizerFactLimitRules(t *testing.T) []biscuit.Rule { - t.Helper() - texts := make([]string, 0, 1100) +// Each is limit_fact_(true) <- role("mesh:role:node"), built directly: +// the parser builds a new grammar for every rule, which for 1100 rules +// takes most of a test's deadline under the race detector. +func authorizerFactLimitRules() []biscuit.Rule { + role := biscuit.Predicate{Name: "role", IDs: []biscuit.Term{biscuit.String(api.RoleNode)}} + rules := make([]biscuit.Rule, 0, 1100) for i := range 1100 { - texts = append(texts, fmt.Sprintf("limit_fact_%d(true) <- role(%q)", i, api.RoleNode)) - } - rules, err := api.ParseDatalogRules(texts) - if err != nil { - t.Fatalf("ParseDatalogRules: %v", err) + rules = append(rules, biscuit.Rule{ + Head: biscuit.Predicate{Name: fmt.Sprintf("limit_fact_%d", i), IDs: []biscuit.Term{biscuit.Bool(true)}}, + Body: []biscuit.Predicate{role}, + }) } return rules } @@ -398,7 +400,7 @@ func TestLabelGateTellsAuthorizerLimitFromDenied(t *testing.T) { t.Errorf("timeout: got %d %q, want 504", status, text) } - full := &AgentMeshNode{trustedKeys: trusted, BiscuitTimeout: 500 * time.Millisecond, MeshPolicyRules: authorizerFactLimitRules(t)} + full := &AgentMeshNode{trustedKeys: trusted, BiscuitTimeout: 500 * time.Millisecond, MeshPolicyRules: authorizerFactLimitRules()} err = full.checkProvider(granted, providerPeer, nil, "mcp://calc") if !errors.Is(err, datalog.ErrWorldRunLimitMaxFacts) || errors.Is(err, ErrProviderNotGranted) { t.Fatalf("checkProvider over the facts limit = %v, want an error wrapping %v and not %v", err, datalog.ErrWorldRunLimitMaxFacts, ErrProviderNotGranted) diff --git a/internal/node/mcp_handlers_test.go b/internal/node/mcp_handlers_test.go index e14e3a97..0ca44e39 100644 --- a/internal/node/mcp_handlers_test.go +++ b/internal/node/mcp_handlers_test.go @@ -658,7 +658,7 @@ func TestCallMCPTool_ProviderNotGrantedIsNotRetried(t *testing.T) { // grant, and it is not retried either: the same credential and policy // reach the limit again. nodeA.MeshPolicyMu.Lock() - nodeA.MeshPolicyRules = authorizerFactLimitRules(t) + nodeA.MeshPolicyRules = authorizerFactLimitRules() nodeA.MeshPolicyMu.Unlock() _, err = nodeA.CallMCPTool(ctx, nodeB.Host.ID(), "mcp://code-reviewer/review_pr", map[string]any{}, nil) if !errors.Is(err, datalog.ErrWorldRunLimitMaxFacts) || errors.Is(err, ErrProviderNotGranted) {