Repository navigation
MAINT: frontend Knip cleanups for dependencies, unused exports and duplicated constants - #4418
Open
Abhiram Shaji (abhiramshaji-cyber) wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the frontend dependency and export cleanup.
No open issues 🎉
1 file not reviewed
frontend/package-lock.json: Generated file
What changed in this PR
This PR follows #4413’s Knip configuration work by cleaning up unused dependencies and exports in PyRIT’s frontend, without intended UI behavior changes.
Changes:
- Add
@jest/globalsexplicitly and remove directschedulerandts-nodedependencies. - Remove unused helpers and a type, and make file-local constants and validation helpers private.
- Reuse existing baseline-technique and seed-search-limit definitions; leave
COMMON_SCENARIO_PARAMETER_NAMESunchanged pending clarification.
| File | Description |
|---|---|
frontend/src/utils/routeParams.ts |
Remove unused parseChatRoute. |
frontend/src/utils/attackAnalytics.ts |
Make internal analytics constants private. |
frontend/src/types/index.ts |
Remove unused ScenarioRunEstimator type. |
frontend/src/services/api.ts |
Import the existing seed-search limit instead of duplicating it. |
frontend/src/hooks/useScenarioResultHierarchy.ts |
Make hierarchy limits private. |
frontend/src/components/Scenarios/scenarioTechniqueSets.ts |
Remove unused technique-label helpers. |
frontend/src/components/Scenarios/scenarioLaunchForm.ts |
Remove the duplicate baseline-technique constant. |
frontend/src/components/Scenarios/ScenarioDetail.tsx |
Import the baseline technique from scenarioConfigForm. |
frontend/src/components/Datasets/seedExampleQuery.ts |
Make page-size bounds and seed-type validation private. |
frontend/src/components/Datasets/datasetQuery.ts |
Make the default dataset sort private. |
frontend/src/components/Config/targetFilters.ts |
Make modality ordering private. |
frontend/package.json |
Update direct development dependencies. |
frontend/package-lock.json |
Sync dependency changes and remove ts-node-only packages. |
Review effort: Balanced
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Knip still flagged 20 real leftovers in the frontend after #4413, and this PR fixes all but one, which is held back as a question below.
This is the second PR from #3730, following Roman Lutz (@romanlutz)'s list there. Thanks again for rerunning Knip on newer main and catching what had drifted.
What this code is for
frontend/is the PyRIT web UI, built with Vite and tested with Jest. #4413 addedfrontend/knip.jsonso Knip skips the fixture, transformer and type false positives. What Knip reports after that is the real list this PR works through: dependencies inpackage.json, and exports insrc/that nothing imports.Before this PR
A contributor runs Knip 5.88 in
frontend/with theknip.jsonfrom #4413, on main at9a4db873.package.json:schedulerandts-nodeare listed but nothing imports them.src/test-utils/autoRefresh.ts: it imports@jest/globals, which is not listed, only installed throughjest.src/: 16 exports have no importer, includingparseChatRouteinsrc/utils/routeParams.ts, which nothing calls at all.BASELINE_TECHNIQUEis not reported, becauseScenarioPresetEditor.test.tsxdoesimport * as scenarioConfigForm, but the same object is still defined twice, inscenarioConfigForm.tsandscenarioLaunchForm.ts.ScenarioRunEstimator).After this PR
Same contributor, same command.
package.jsonlists@jest/globalsat30.5.2, the same version asjest, and no longer listsschedulerorts-node.parseChatRoute,ScenarioRunEstimator,techniqueSetOptionLabelandtechniqueSetDisplayNameare gone.BASELINE_TECHNIQUEandMAX_SEED_SEARCH_LENGTHeach have one definition that the other file imports.COMMON_SCENARIO_PARAMETER_NAMESinscenarioLaunchRequest.ts, left alone on purpose (see the question at the end).flowchart LR classDef box fill:#eef1ff,stroke:#4c5bd4,color:#111827 classDef bad fill:#ffd6d6,stroke:#cc0000,color:#111827,stroke-width:3px classDef good fill:#c8f0c8,stroke:#008800,color:#111827,stroke-width:3px subgraph BEFORE["BEFORE: 20 Knip findings"] direction TB B1["contributor runs knip in frontend"] --> B2["reads package.json"] B2 --> B3["reads every export in src"] B3 --> B4{"listed or exported but never imported?"} B4 -->|"yes for 20 items"| B5["2 deps, 1 unlisted, 16 exports, 1 type"] B4 -->|"no"| B6["used code, not reported"] end subgraph AFTER["AFTER: 1 Knip finding, held on purpose"] direction TB A1["contributor runs knip in frontend"] --> A2["reads package.json"] A2 --> A3["reads every export in src"] A3 --> A4{"THE CHANGE: deps fixed, dead code removed"} A4 -->|"only one left"| A5["COMMON_SCENARIO_PARAMETER_NAMES"] A4 -->|"everything else"| A6["lint, typecheck, build still pass"] end B1 ~~~ A1 class B1,B2,B3,B6 box class A1,A2,A3,A6 box class B4,B5 bad class A4,A5 good linkStyle 3 stroke:#cc0000,stroke-width:5px linkStyle 8 stroke:#008800,stroke-width:5px style BEFORE fill:#fff5f5,stroke:#cc0000,color:#111827 style AFTER fill:#f3fff3,stroke:#008800,color:#111827The change
Two commits:
package.jsonandpackage-lock.json: add@jest/globals30.5.2, removets-nodeandscheduler(done withnpm). The lockfile only dropsts-nodeand the packages it pulled in.scheduler0.28.0stays installed throughreact-dom, so the/scheduler/chunk match invite.config.tsstill finds it. As you suggested, thets-noderemoval lives in this PR, in the dependency commit separate from the source edits, so a revert is cheap if CI disagrees.src/:BASELINE_TECHNIQUEis removed fromscenarioLaunchForm.ts, andScenarioDetail.tsxnow imports it from./scenarioConfigForm, which still uses and exports it, so theimport * as scenarioConfigFormtest keeps working.services/api.tsnow importsMAX_SEED_SEARCH_LENGTHfromseedExampleQuery.tsinstead of keeping its own copy. That's the first import fromcomponentsinsideservices, so if you'd rather keep that direction clean I can just unexport it and leave the two copies.parseChatRoute(utils/routeParams.ts),ScenarioRunEstimator(types/index.ts),techniqueSetOptionLabelandtechniqueSetDisplayName, which onlytechniqueSetOptionLabelcalled (scenarioTechniqueSets.ts).MODALITY_ORDER,DEFAULT_DATASET_SORT,MIN_SEED_PAGE_SIZE,MAX_SEED_PAGE_SIZE,isSeedType,HIERARCHY_MAX_NODES,HIERARCHY_CHILD_PAGE_SIZE,ANALYTICS_GROUP_LIMIT,ANALYTICS_MAX_PREDICATES,ANALYTICS_ASR_DEFINITION,ANALYTICS_ALL_ASR_DEFINITION.Locally,
npm run lint,npm run type-checkandnpm run buildpass. On Node 22 withts-nodegone, Jest still loadsjest.config.tsand runs the full suite. The only failure I saw wasApp.drafts.test.tsx"dirty draft confirmation", which was flaky for me on unmodified main too.What changes for a user
exportand the shared copies keep the same values.ts-nodeand its dependencies).A question on
COMMON_SCENARIO_PARAMETER_NAMESFor
COMMON_SCENARIO_PARAMETER_NAMESI left both copies as they are. The preset copy inscenarioConfigForm.tslooks like a snapshot of the oldScenarioDetailset from #2931.dataset_overrides(#3143),local_technique_factory(#3449) andscoring_target(#3794) were only added to the launch copy afterwards. Would you like the preset editor to import the shared set fromscenarioLaunchRequest.ts, or should presets still be able to edit any of those three?The two functions that read each set:
dynamicScenarioParameters, which filters by the smaller set, and its 6 preset editor callers, Functions view in Architect
scenarioDynamicParameters, which filters by the larger set, and its callers (the launch form and a test helper), Functions view in Architect
Side note: both sets also leave out
operation_idandincompatible_technique_policy, whichScenario._common_scenario_parametersdeclares. I didn't touch that here, just mentioning it in case it's useful for that decision.Related: #3730, #4413