Repository navigation
feat: add issue category infrastructure for STIX and PHIX - #85
TiaTuinstra wants to merge 3 commits into
Conversation
|
Sorry, I missed this @TiaTuinstra , but I can get behind something like this as our taxonomy! Couple tweaks I'd suggest:
But I think it's good and we can go ahead |
…till goes to its own category when it has one
Lespernater
left a comment
There was a problem hiding this comment.
Besides some work once updating the base branch, only some smaller suggestions for testing/guards and a question about the intent from me. Well done!
|
|
||
| --- | ||
|
|
||
| ## Issue Categories |
| OEN_FORMAT: "identity", OEN_DUPLICATE: "identity", OEN_DUAL_ENROLLMENT: "identity", | ||
| NAME_DOB_DUPLICATE: "identity", IDENTITY_REVIEW: "identity", | ||
| // contact — phone format rules and per-record phone-type allowed-value rules | ||
| // (PHONE_TYPE_ALLOWED_VALUE is the file-level contact phone on the submission header; that stays "metadata") |
There was a problem hiding this comment.
Nice catch on PHONE_TYPE_ALLOWED_VALUE vs PHONETYPE_ALLOWED_VALUE!
| }; | ||
|
|
||
| export function issueCategory(ruleId: string, workflow: "stix" | "phix"): IssueCategory { | ||
| return (workflow === "stix" ? stixCategories : phixCategories)[ruleId] ?? "other"; |
There was a problem hiding this comment.
Non-blocking issue:
New rule IDs will drop into other silently + this mapping isn't yet tied to what the validators emit.
mainnow containsPOSTAL_CODE_US_ZIPandPO_BOX_NUMBER_FORMATfrom work after this branched. They got labels inoverview.tsbut will land inotherafter a rebase instead ofaddress.XML_PARSE_OR_NAMESPACE- non parse-able STIX file - lands inothercurrently but PHIX parse failure lands infile-structure- PR description says no
otherunder normal circumstances but no flag to highlight unmapped rules in CI or otherwise - Also on
main-lib/issueDescription.tsrule-ID switch that gives each issue a description so with this PR, introducing new STIX rules need edits in 3 places - label record, description switch and category map -> drift/maintenance risk, maybe this can be consolidated
Suggestions:
- After
mainrebase/merge - mapPOSTAL_CODE_US_ZIPandPO_BOX_NUMBER_FORMATtoaddress. - Map
XML_PARSE_OR_NAMESPACEtofile-structureand widendocs/validation-rules.md. - Possibly add a test that every labelled rule ID has a category so new rules fail CI until it is mapped? This may make
otherredundant? Maybe just add a flag that an issue is unmapped? Would need labels map exported fromoverview.ts:
it("maps every labelled STIX rule ID", () => {
for (const ruleId of Object.keys(ISSUE_TYPE_LABELS)) expect(issueCategory(ruleId, "stix")).not.toBe("other");
});- Alternatively, move the category next to label in one record per rule ID to reduce hand-edit sync burden.
| it("CATEGORY_LABELS has an entry for every IssueCategory", () => { | ||
| const categories: IssueCategory[] = [ | ||
| "file-structure", "metadata", "required", "date", "identity", "vaccine", | ||
| "coded-value", "address", "contact", "text-constraint", "other", |
There was a problem hiding this comment.
Nit:
Avoid repeating union build here, consider looping over CATEGORY_LABELS because adding a new 12th category to issueCategory and CATEGORY_LABELS but not to this list means the test still passes. Plus, I think a missing label is already caught by npm run typecheck, because CATEGORY_LABELS is typed Record<IssueCategory, string>. Consider:
for (const [category, label] of Object.entries(CATEGORY_LABELS)) expect(label.trim(), category).not.toBe("");Alternatively, export stixCategories and phixCategories to build a test here that also includes defined but unused categories and loop over categories instead of using CATEGORY_LABELS workaround.
const used = new Set([...Object.values(stixCategories), ...Object.values(phixCategories)]);
for (const category of Object.keys(CATEGORY_LABELS)) if (category !== "other") expect(used.has(category as IssueCategory), category).toBe(true);| ...count(result.issues), students: records.size, | ||
| schools: [...schools.values()].map(({ issues, ...entry }) => ({ ...entry, ...count(issues) })).sort((a, b) => b.errors - a.errors || b.total - a.total || a.schoolNumber.localeCompare(b.schoolNumber)), | ||
| types: [...types.values()].map(({ issues, ...entry }) => ({ ...entry, ...count(issues) })).sort((a, b) => b.total - a.total || a.ruleId.localeCompare(b.ruleId)), | ||
| types: [...types.values()].map(({ issues, ...entry }) => ({ ...entry, category: issueCategory(entry.ruleId, "stix"), ...count(issues) })).sort((a, b) => b.total - a.total || a.ruleId.localeCompare(b.ruleId)), |
There was a problem hiding this comment.
Question about intention:
types rows are keyed by rule ID and field but category only looks at rule ID. FIELD_LENGTH on StreetName, City or PostalCode counts as text-constraint, and a REQUIRED_FIELD on an address field from a custom ruleset counts as required. Versus on PHIX, PHIX_STREET_NAME_REQUIRED: "address".
In the case of a FIELD_LENGTH issue with an address field, is the planned "address issues" subtotal meant to leave those out, or should the field be able to steer the category for the generic rules like FIELD_LENGTH and REQUIRED_FIELD?
This matters more for downstream dashboard building of subtotals after these issue maps are merged because nothing reads category yet.
Considerations:
- Option:
issueCategory(ruleId, workflow, field?)returns a field-based category forFIELD_LENGTHandREQUIRED_FIELDwhen the field belongs to a group. - Another option: leave the rule as is and have the dashboard show
text-constraintandrequiredrows with their field.
Summary
Introduces a shared issue category layer in
lib/issueCategories.tsthat maps every validation rule ID to one of 14 workflow-agnostic categories. Wires categories into the STIXsummarizeValidationoutput so each entry in thetypesarray now carries acategoryfield alongside its existingruleId,field, and severity counts.Motivation
The validators emit dozens of distinct rule IDs. Without grouping, the quality assessment page can only show per-rule-ID subtotals, which are noisy and hard to act on. Categories enable:
Categories
parsemetadatarequireddatesidentityvaccinecoded-valuesaddresspostal-codecontactfield-lengthcharacter-policyservice-deliveryotherCategories that are currently only populated by one workflow are defined in the shared type from day one so both workflows can grow into them without changing the infrastructure.
Design decisions
Single shared type, workflow-specific mapping.
IssueCategoryandCATEGORY_LABELSlive inlib/and are workflow-agnostic. TheissueCategory(ruleId, workflow)function dispatches to a flatRecord<string, IssueCategory>for each workflow. Both fall back to"other"for unmapped rule IDs.One category per issue. Issues belong to exactly one category. Multi-tagging would make category subtotals unreliable — an issue tagged
["address", "coded-values"]would inflate both counts. This could be adjusted to allow multiple categories to be associated with each issue (i.e. coded-value and contact), depending on intended count handling.Explicit flat
Record's for both workflows. STIX generates allowed-value rule IDs dynamically at runtime as${field.toUpperCase()}_ALLOWED_VALUE, but the set of source fields is a fixed list invalidator.ts. Using a flatRecord(the same approach as PHIX) keeps both lookups uniform and makes every mapping greppable.Files changed
lib/issueCategories.ts— new; exportsIssueCategory,CATEGORY_LABELS, andissueCategory(ruleId, workflow)workflows/stix/validation/overview.ts— addscategoryfield to each entry in thetypesarray returned bysummarizeValidationtests/issueCategories.test.ts— new; covers STIX and PHIX mappings, fallback,cross-workflow isolation, and
CATEGORY_LABELSexhaustivenesstests/validationOverview.test.ts— adds integration assertions thatsummarizeValidationwires
categorycorrectly