Add hash collision test for NodeType ID generation#4815
Add hash collision test for NodeType ID generation#4815tmchow wants to merge 3 commits intoarmadaproject:masterfrom
Conversation
Greptile SummaryThis PR adds hash collision tests for Confidence Score: 5/5This PR is safe to merge; all changes are either test additions or a consistent typed-key refactor with no remaining plain-string callers. The collision tests are correct and cover the stated combinations. The ctxkeys refactoring is complete — every writer and reader was updated together, the grep finds no leftover plain-string lookups, and the test files were updated in lockstep. No logic was changed in production code outside of the key type. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Incoming gRPC request] --> B[requestid.UnaryServerInterceptor]
B --> C["context.WithValue(ctx, ctxkeys.RequestIDKey, id)"]
C --> D[auth.CreateGrpcMiddlewareAuthFunction]
D --> E["context.WithValue(ctx, ctxkeys.UserKey, name)"]
E --> F["WithPrincipal → context.WithValue(ctx, ctxkeys.PrincipalKey, principal)"]
F --> G[Handler / interceptors read context]
G --> H["grpc.InterceptorLogger\nctx.Value(ctxkeys.UserKey)\nctx.Value(ctxkeys.RequestIDKey)"]
G --> I["auth.GetPrincipal\nctx.Value(ctxkeys.PrincipalKey)"]
G --> J["armadacontext.FromGrpcCtx\nctx.Value(ctxkeys.UserKey)\nctx.Value(ctxkeys.RequestIDKey)"]
Reviews (3): Last reviewed commit: "Fix submit_test.go to use typed context ..." | Re-trigger Greptile |
e73d5c1 to
b6801d3
Compare
Introduce a ctxkeys package with a custom ContextKey type to prevent
context value collisions from bare string keys. Replace all plain
string context keys ("principal", "user", "requestId") with typed
constants from the new package.
The ctxkeys package is a leaf dependency with no imports, avoiding
circular dependencies between auth, requestid, and armadacontext.
Closes armadaproject#4780
Signed-off-by: Trevin Chow <trevin@trevinchow.com>
Add tests verifying that nodeTypeIdFromTaintsAndLabels produces unique hashes for distinct combinations of taints, labels, and unset indexed labels using realistic Kubernetes inputs. Also verify the hash is never zero, even for empty inputs. Removes the TODO comment that requested these tests. Closes armadaproject#4778 Signed-off-by: Trevin Chow <trevin@trevinchow.com>
Update four test call-sites to use ctxkeys.PrincipalKey instead of the plain string key "principal". Without this, auth.GetPrincipal silently falls back to anonymousPrincipal since Go context lookups are type-sensitive. Signed-off-by: Trevin Chow <trevin@trevinchow.com>
b6801d3 to
0df0735
Compare
Adds tests for
nodeTypeIdFromTaintsAndLabelsthat verify:Tests 60+ unique inputs with zero collisions observed. Removes the TODO comment that requested this coverage.
Closes #4778
This PR was authored by a human with AI coding assistance.