Skip to content

docs(changeset): Removing Interactive Graph Builder and refactoring tests/storybook to use more standardized generator patterns.#3415

Open
SonicScrewdriver wants to merge 19 commits intomainfrom
maximum-overline
Open

docs(changeset): Removing Interactive Graph Builder and refactoring tests/storybook to use more standardized generator patterns.#3415
SonicScrewdriver wants to merge 19 commits intomainfrom
maximum-overline

Conversation

@SonicScrewdriver
Copy link
Copy Markdown
Contributor

@SonicScrewdriver SonicScrewdriver commented Mar 25, 2026

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:

  • Tests Pass

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 25, 2026

🗄️ Schema Change: No Changes ✅

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 25, 2026

Size Change: +208 B (+0.04%)

Total Size: 498 kB

📦 View Changed
Filename Size Change
packages/perseus-core/dist/es/index.js 25.4 kB +208 B (+0.83%)
ℹ️ View Unchanged
Filename Size
packages/kas/dist/es/index.js 20.5 kB
packages/keypad-context/dist/es/index.js 1 kB
packages/kmath/dist/es/index.js 6.36 kB
packages/math-input/dist/es/index.js 98.5 kB
packages/math-input/dist/es/strings.js 1.61 kB
packages/perseus-core/dist/es/index.item-splitting.js 12 kB
packages/perseus-editor/dist/es/index.js 102 kB
packages/perseus-linter/dist/es/index.js 9.3 kB
packages/perseus-score/dist/es/index.js 9.7 kB
packages/perseus-utils/dist/es/index.js 403 B
packages/perseus/dist/es/index.js 194 kB
packages/perseus/dist/es/strings.js 8.27 kB
packages/pure-markdown/dist/es/index.js 1.39 kB
packages/simple-markdown/dist/es/index.js 6.71 kB

compressed-size-action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 25, 2026

🛠️ Item Splitting: No Changes ✅

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 25, 2026

npm Snapshot: Published

Good news!! We've packaged up the latest commit from this PR (4923c64) and published it to npm. You
can install it using the tag PR3415.

Example:

pnpm add @khanacademy/perseus@PR3415

If you are working in Khan Academy's frontend, you can run the below command.

./dev/tools/bump_perseus_version.ts -t PR3415

If you are working in Khan Academy's webapp, you can run the below command.

./dev/tools/bump_perseus_version.js -t PR3415

});
});

describe("generateIGExponentialGraph", () => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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">>,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +243 to +265

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>;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.md line 322 references ...interactive-graph-question-builder.ts — withLogarithm(), LogarithmGraphConfig
  • packages/perseus/src/widgets/interactive-graphs/__docs__/notes/tangent.md line 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

  1. The PR diff shows interactive-graph-question-builder.ts deleted (entire file removed with --- a/.../interactive-graph-question-builder.ts diff header).
  2. logarithm.md line 322 contains the literal string interactive-graph-question-builder.ts — withLogarithm(), LogarithmGraphConfig — a path that no longer resolves.
  3. tangent.md line 187 contains the literal string interactive-graph-question-builder.ts — Builder — also a dead path.
  4. The new replacement module interactive-graph-widget-generator.ts is added by this PR and exports graph generators such as generateIGTangentGraph, generateIGExponentialGraph, etc.
  5. Neither doc file appears in the PR diff, confirming neither was updated.

@ivyolamit
Copy link
Copy Markdown
Contributor

@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.

🔗 https://github.com/Khan/perseus/blob/main/packages/perseus/src/widgets/interactive-graphs/__docs__/notes/new-graph-type.md#tips

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants