docs(changeset): Removing Interactive Graph Builder and refactoring tests/storybook to use more standardized generator patterns.#3415
docs(changeset): Removing Interactive Graph Builder and refactoring tests/storybook to use more standardized generator patterns.#3415SonicScrewdriver wants to merge 19 commits intomainfrom
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review.
Tip: disable this comment in your organization's Code Review settings.
🗄️ Schema Change: No Changes ✅ |
|
Size Change: +208 B (+0.04%) Total Size: 498 kB 📦 View Changed
ℹ️ View Unchanged
|
🛠️ Item Splitting: No Changes ✅ |
npm Snapshot: PublishedGood news!! We've packaged up the latest commit from this PR (4923c64) and published it to npm. You Example: pnpm add @khanacademy/perseus@PR3415If you are working in Khan Academy's frontend, you can run the below command. ./dev/tools/bump_perseus_version.ts -t PR3415If you are working in Khan Academy's webapp, you can run the below command. ./dev/tools/bump_perseus_version.js -t PR3415 |
| }); | ||
| }); | ||
|
|
||
| describe("generateIGExponentialGraph", () => { |
There was a problem hiding this comment.
Decided to round out the tests for the new graphs while I was in here.
|
|
||
| export function generateIGAngleGraph( | ||
| options?: Partial<PerseusGraphTypeAngle>, | ||
| options?: Partial<Omit<PerseusGraphTypeAngle, "type">>, |
There was a problem hiding this comment.
This is just some additional type safety that brings these generators inline with the implementation of the rest of the IG generators.
| "*.cypress.ts", | ||
| "*.test.ts", | ||
| "*.test.tsx", | ||
| "*.testdata.ts", |
There was a problem hiding this comment.
It made sense to me to add a global override for our test data as it seems reasonable for these files to be exempt, but I'm also happy to remove this and re-add the file-specific override for interactive-graph.testdata.ts.
...ges/perseus/src/widgets/interactive-graphs/__docs__/interactive-graph-regression.stories.tsx
Show resolved
Hide resolved
packages/perseus-core/src/utils/generators/interactive-graph-widget-generator.ts
Show resolved
Hide resolved
packages/perseus/src/widgets/interactive-graphs/interactive-graph.testdata.ts
Show resolved
Hide resolved
...ges/perseus/src/widgets/interactive-graphs/__docs__/interactive-graph-regression.stories.tsx
Show resolved
Hide resolved
packages/perseus-core/src/utils/generators/interactive-graph-widget-generator.ts
Outdated
Show resolved
Hide resolved
packages/perseus/src/widgets/interactive-graphs/interactive-graph.testdata.ts
Show resolved
Hide resolved
packages/perseus/src/widgets/interactive-graphs/interactive-graph.testdata.ts
Show resolved
Hide resolved
|
|
||
| export function generateInteractiveGraphQuestion( | ||
| options?: Partial<PerseusInteractiveGraphWidgetOptions> & { | ||
| content?: string; | ||
| isStatic?: boolean; | ||
| }, | ||
| ): PerseusRenderer { | ||
| const {content, isStatic, ...widgetOptions} = options ?? {}; | ||
|
|
||
| // The `graph` and `correct` fields share all fields except for | ||
| // the answers (coords, center, etc.) When only `correct` is provided, | ||
| // derive `graph` from it by stripping the answer-specific fields. | ||
| // This allows us to keep our test data more succinct. | ||
| if (widgetOptions.correct && !widgetOptions.graph) { | ||
| const { | ||
| coords: _, | ||
| coord: __, | ||
| center: ___, | ||
| radius: ____, | ||
| asymptote: _____, | ||
| match: ______, | ||
| ...graphConfig | ||
| } = widgetOptions.correct as Record<string, unknown>; |
There was a problem hiding this comment.
🟡 The developer architecture notes in logarithm.md (line 322) and tangent.md (line 187) still reference interactive-graph-question-builder.ts, which this PR deletes. Developers following these notes to implement a new graph type will hit a broken file reference; update both notes to point to the replacement module interactive-graph-widget-generator.ts.
Extended reasoning...
What the bug is and how it manifests
This PR deletes packages/perseus/src/widgets/interactive-graphs/interactive-graph-question-builder.ts and replaces it with packages/perseus-core/src/utils/generators/interactive-graph-widget-generator.ts. However, two developer architecture notes — logarithm.md and tangent.md — were not updated alongside this deletion. Both notes contain explicit file-path references that are now dead.
packages/perseus/src/widgets/interactive-graphs/__docs__/notes/logarithm.mdline 322 references...interactive-graph-question-builder.ts — withLogarithm(), LogarithmGraphConfigpackages/perseus/src/widgets/interactive-graphs/__docs__/notes/tangent.mdline 187 references...interactive-graph-question-builder.ts — Builder
The specific code path that triggers it
These notes are static Markdown documentation files intended to guide developers implementing new graph types. They list the files and functions a developer needs to touch, with interactive-graph-question-builder.ts called out as containing the builder class. Since that file no longer exists in the repository after this PR, any developer following the guide will look for a file that is simply gone.
Why existing code doesn't prevent it
The deletion of the builder was a source-code change; there is no automated tooling that cross-checks prose documentation for file-path accuracy. The notes were written to describe the old architecture and were not updated in this refactor.
What the impact would be
A developer tasked with adding a new interactive graph type (e.g., logarithm or tangent) would consult these notes, encounter the dead reference, and either waste time searching for the file or be left confused about where the builder logic now lives. The correct file is packages/perseus-core/src/utils/generators/interactive-graph-widget-generator.ts, which is where all the new generator functions (e.g., generateIGExponentialGraph, generateIGAbsoluteValueGraph) live.
How to fix it
In both logarithm.md:322 and tangent.md:187, replace the reference to interactive-graph-question-builder.ts with packages/perseus-core/src/utils/generators/interactive-graph-widget-generator.ts and update the function/class names cited to match the new generator API (e.g., the generator functions instead of withLogarithm()/LogarithmGraphConfig/Builder).
Step-by-step proof
- The PR diff shows
interactive-graph-question-builder.tsdeleted (entire file removed with--- a/.../interactive-graph-question-builder.tsdiff header). logarithm.mdline 322 contains the literal stringinteractive-graph-question-builder.ts — withLogarithm(), LogarithmGraphConfig— a path that no longer resolves.tangent.mdline 187 contains the literal stringinteractive-graph-question-builder.ts — Builder— also a dead path.- The new replacement module
interactive-graph-widget-generator.tsis added by this PR and exports graph generators such asgenerateIGTangentGraph,generateIGExponentialGraph, etc. - Neither doc file appears in the PR diff, confirming neither was updated.
|
@SonicScrewdriver just reading the PR description, what do you think of adding an info in our notes as a tip? To ensure that this pattern will be followed moving forward. |
…se similar generator patterns to the rest of Perseus.
…r and refactoring tests/storybook to use more standardized generator patterns.
040238b to
7f59b85
Compare
There was a problem hiding this comment.
Previous feedback addressed — critical fixture bugs fixed, intentional display-graph-type changes acknowledged. LGTM.
Extended reasoning...
Overview
This PR removes the class (and its duplicate in the editor package) and replaces all call sites with the functional / generators already exported from @khanacademy/perseus-core. Changes touch test data files, Storybook stories, and test files across three packages; no production widget logic is modified.
Security risks
None. All changes are confined to test utilities, Storybook stories, and test data. No auth, crypto, or user-facing code paths are touched.
Level of scrutiny
This is a large but mechanical refactoring of test/story infrastructure. The main risk is behavioral divergence during migration (old builder had implicit defaults like SegmentGraphConfig as the fallback graph type), which is exactly what the prior review rounds surfaced and which the author has now addressed. The PR is appropriate for bot approval given: (1) the logic being changed is test-only, (2) all identified regressions were fixed, and (3) no new bugs were found.
Other factors
Prior inline comments flagged circle fixture missing center/radius defaults, several segmentWith* fixtures defaulting to a linear graph, segmentWithLockedFunction missing a correct field, and the match field leaking into graph for polygon questions. The current file state confirms all of these were remediated. The author explicitly resolved the display-story graph-type comments as intentional. One minor residual: logarithm.md and tangent.md still reference the deleted builder file path, but that is a documentation-only nit that does not affect runtime behaviour.
Summary:
Remove the old Interactive Graph Builder and refactor our tests to use the same generator patterns as the rest of Perseus.
Issue: LEMS-4008
Test plan: