Skip to content

test(activity): cover Activity-ProjectManager wiring through real construction - #8246

Merged
walterbender merged 5 commits into
sugarlabs:masterfrom
vanshika2720:test/integration-activity-projectmanager
Aug 26, 2026
Merged

test(activity): cover Activity-ProjectManager wiring through real construction#8246
walterbender merged 5 commits into
sugarlabs:masterfrom
vanshika2720:test/integration-activity-projectmanager

Conversation

@vanshika2720

Copy link
Copy Markdown
Collaborator

Description

Adds integration coverage for the wiring between the real Activity and ProjectManager components.

The test loads both js/activity.js and js/project-manager.js unmodified into the same vm context, following the dependency order used by js/loader.js. This allows Activity construction to invoke the real setupProjectManager(this) path instead of replacing the project manager with a mock.

The test verifies that a real Activity receives a real ProjectManager, that the project manager references the same activity instance, and that a real prepareExport() call reads and mutates state belonging to that activity.

No production code is changed.

Category

  • Bug Fix — Fixes a bug or incorrect behavior
  • Feature — Adds new functionality
  • Performance — Improves load time, memory, rendering, etc.
  • Tests
  • Documentation — Updates to docs, comments, or README
  • Chore / Refactor — Maintenance, cleanup, or refactoring with no behavior change
  • CI/CD — Changes to workflows and automation

Changes Made

  • Added js/__tests__/activity-projectmanager-integration.test.js.
  • Loads the real Activity and ProjectManager implementations into a shared vm context.
  • Verifies that Activity construction creates and wires a real ProjectManager.
  • Verifies that activity.projectManager.activity references the same Activity instance.
  • Exercises the real ProjectManager.prepareExport() method against a small block/turtle fixture.
  • Verifies the resulting export and the corresponding Activity state mutation.
  • Keeps production code untouched and limits the integration boundary to synchronous behavior that does not require DOM/canvas or file I/O.

Visual Changes

Not applicable. This change only adds automated tests.


Testing Performed

  • New integration test: 2/2 passed.
  • Activity test suite: 132 tests passed.
  • ProjectManager test suite: 106 tests passed.
  • Integration-named test suites: 6 files / 54 tests passed with no cross-test leakage.
  • ESLint: clean.
  • Prettier: clean.
  • git diff --check: clean.
  • Full Jest run: clean apart from two pre-existing unrelated failures:
    • musickeyboard.test.js — existing failure reproduced independently.
    • camera.test.js — full-suite worker SIGSEGV; the test passes when run in isolation.

Checklist

  • I have tested these changes locally and they work as expected.
  • I have added/updated tests that prove the effectiveness of these changes.
  • I have updated the documentation to reflect these changes, if applicable.
  • I have followed the project's coding style guidelines.
  • I have run npm run lint and npx prettier --check . with no errors.
  • I have addressed the code review feedback from the previous submission, if applicable.
  • I have enabled "Allow edits from maintainers" (required for auto-rebase; affects PR branch only).

Additional Notes

This test covers a previously untested integration boundary: real Activity construction wiring a real ProjectManager instance.

Existing coverage tests Activity with a mocked setupProjectManager and tests ProjectManager against a plain fake activity, but neither exercises both real components together. This test fills that gap without introducing DOM/canvas-heavy setup.

prepareExport() was selected because it is synchronous and can exercise the real Activity/ProjectManager relationship without requiring the file-loading or UI infrastructure used by saveLocally and doLoad.

The test does not currently provide a full project load/save round trip. Those flows still depend on additional Turtles/Blocks infrastructure and can be covered separately if needed.

@github-actions github-actions Bot added tests Adds or updates test coverage size/L Large: 250-499 lines changed area/javascript Changes to JS source files area/tests Changes to test files labels Aug 25, 2026
@Ashutoshx7

Copy link
Copy Markdown
Member

lmk when its ready for review

…struction

Extends the real-component integration series (noteclamp/pitch/volume/
meter/tone dispatch tests) one layer up: neither the existing Activity
toolbar test nor the ProjectManager unit tests exercise a real Activity
wired to a real ProjectManager together. This loads both js/activity.js
and js/project-manager.js unmodified into one vm sandbox, in the same
dependency order as js/loader.js, so setupProjectManager(this) runs for
real during construction. Asserts the resulting projectManager is a real
ProjectManager instance pointing back at the same activity, and that a
real prepareExport() call serializes that activity's real block/turtle
state.

Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
Address review feedback on the prior commit:

- prepareExport() mutation check seeded hasMatrixDataBlock to true before
  the call, since Activity never initializes that field itself - the
  previous version could pass even if prepareExport() never touched it.
  Asserting it flips to false now actually proves the call mutated the
  real Activity, not a detached copy.
- Dropped the _loadAnimationIntervalId assertion; it only restates a
  ProjectManager implementation detail unrelated to the Activity wiring
  boundary and would make the test brittle against unrelated refactors.
- The activity.js source split now throws with a clear message if the
  expected initialization line isn't found, instead of silently running
  more of the module than intended.

Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
Address further review feedback:

- Stop slicing activity.js at the literal string
  "const activity = new Activity();" to isolate the Activity class before
  its auto-instantiation. Instead run the file completely unmodified: the
  sandbox's define() stub is a no-op, so the trailing domReady bootstrap
  call it's wrapped in is created but never invoked, and the file's own
  top-level singleton construction becomes the instance under test.
  "this.activity = activity;" pulls that binding out of the vm script's
  scope, the same way this test already does for the Activity class name
  itself. This removes all coupling to a specific statement's exact text
  and layout, replacing it with only the module's own load-bearing
  identifiers ("Activity", "activity"). Each test now loads a fresh vm
  context so no state can leak between them.
- Reworded the header comment: unrelated Activity dependencies (Turtles,
  Blocks, Logo, the setupXController functions, etc.) are stubbed to keep
  construction free of real DOM/audio/canvas machinery Jest can't provide -
  they sit outside the Activity-ProjectManager seam, not on either side of
  it, so 'never mocks either side of that seam' was imprecise.
- Loosened the prepareExport() serialization check from a full deep-equal
  of the exported array to the specific facts that show the real block and
  turtle graphs were read (the turtle's real id in the start block's
  args, the note block's connection resolving through the real block
  list) - exact serialization format is already covered by
  project-manager.test.js.
- Split the second test into two single-purpose tests: one for reading
  Activity-owned state through ProjectManager, one for ProjectManager
  writing back to the same real Activity instance (hasMatrixDataBlock).

Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
Address feedback that the wiring test's ~280-line bespoke vm sandbox was
disproportionate to the 2-3 assertions it backed, and largely duplicated
activity_toolbar_integration.test.js's own sandbox:

- Factor the shared dependency stubs (Turtles, Blocks, Logo, the various
  setupXController functions, etc. - everything outside whatever seam a
  given test is exercising) into js/__tests__/helpers/activity-vm-sandbox.js,
  a small loader that runs the real, unmodified activity.js in a vm context
  and returns it. activity_toolbar_integration.test.js now uses it too
  (behavior unchanged: still gets a real Activity with setupProjectManager
  mocked, still exercises the same toolbar-delegation methods) instead of
  keeping its own duplicate copy of the same ~120-line scaffold.
- activity-projectmanager-integration.test.js now only adds what its own
  seam needs on top of the shared helper: the real project-manager.js
  source (via the helper's prependCode hook) instead of the shared
  sandbox's default mocked setupProjectManager, plus the handful of extra
  globals project-manager.js's methods read at call time.
- Trimmed the wiring test itself from three tests validating pieces of
  prepareExport()'s serialization contract (already covered in
  project-manager.test.js) down to two: real construction wiring
  (activity.projectManager instanceof ProjectManager, back-reference to the
  same activity), and one combined check that a real prepareExport() call
  both reads Activity-owned state (exported block count matches the real
  blockList) and mutates the same real Activity instance
  (hasMatrixDataBlock, seeded to the opposite value first so the assertion
  actually proves the mutation).

Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
… loading into it

Address further review feedback:

- Restored a structural assertion on prepareExport()'s output: the
  second block's connection (originally block index 0) resolves to the
  first block's exported index, and its name/position are checked too -
  proving ProjectManager walked the real activity.blocks.blockList graph
  to build that entry, not just that the array happened to have the right
  length.
- Trimmed js/__tests__/helpers/activity-vm-sandbox.js's stub set to only
  what Activity's constructor actually touches directly - verified
  empirically by removing stubs until construction stopped succeeding.
  Turtles/Palettes/Blocks/Logo/LanguageBox/ThemeBox/SaveInterface/
  StatsWindow/Trashcan/PasteBox/HelpWidget/GIFAnimator/i18next/
  AlertController/platformColor/globalActivity/LEADING/MYDEFINES/jQuery/
  createjs are never referenced during construction itself: they're wired
  up later by setupDependencies(), which only runs from the domReady
  bootstrap callback the sandbox's no-op define() never invokes.
- Moved the real-project-manager loading logic (reading project-manager.js,
  appending the this.setupProjectManager/this.ProjectManager exposers) into
  the helper as loadActivityWithRealProjectManager(), so the integration
  test itself only expresses intent instead of repeating that plumbing.

Signed-off-by: Vanshika <pahalvanshikaa@gmail.com>
@vanshika2720
vanshika2720 force-pushed the test/integration-activity-projectmanager branch from 9682277 to 788a4ac Compare August 26, 2026 14:22
@codecov

codecov Bot commented Aug 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.33%. Comparing base (4d5d7bf) to head (788a4ac).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8246   +/-   ##
=======================================
  Coverage   65.33%   65.33%           
=======================================
  Files         190      190           
  Lines       59318    59318           
=======================================
  Hits        38758    38758           
  Misses      20560    20560           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vanshika2720
vanshika2720 marked this pull request as ready for review August 26, 2026 14:41
@vanshika2720

Copy link
Copy Markdown
Collaborator Author

@Ashutoshx7 ready

@walterbender
walterbender merged commit c523dfc into sugarlabs:master Aug 26, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/javascript Changes to JS source files area/tests Changes to test files size/L Large: 250-499 lines changed tests Adds or updates test coverage

Projects

Development

Successfully merging this pull request may close these issues.

3 participants