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 delivers two improvements: hash collision tests for Context key migration ( Hash collision tests (
Confidence Score: 5/5Safe to merge — no P0 or P1 issues found; context key migration is complete and consistent across the codebase All remaining findings are P2 (a missing zero-hash assertion in one test loop). The typed-key migration is mechanically complete with no stray plain-string lookups remaining, and the hash collision tests provide solid coverage of realistic Kubernetes inputs. node_type_test.go — minor: mixed section missing zero-hash assert for consistency Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Input: taints, labels, unsetIndexedLabels"] --> B["h = fnv1a.Init64\n(offset basis: 14695981039346656037)"]
B --> C{"for each taint\n(sorted by Key)"}
C --> D["AddString64(key + '=' + value + ':' + effect + '$')"]
D --> C
C -- done --> E["AddString64('&')\nsection separator"]
E --> F{"for each label key\n(sorted)"}
F --> G["AddString64(key + '=' + value + '$')"]
G --> F
F -- done --> H["AddString64('&')\nsection separator"]
H --> I{"for each unset label key\n(sorted)"}
I --> J["AddString64(key + '$')"]
J --> I
I -- done --> K["return h (uint64 node type ID)"]
Reviews (2): Last reviewed commit: "Fix submit_test.go to use typed context ..." | Re-trigger Greptile |
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>
e73d5c1 to
b6801d3
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.