Skip to content

Versioning and history#3659

Open
Nocaxe wants to merge 56 commits intosource-academy:masterfrom
Nocaxe:Versioning-and-History
Open

Versioning and history#3659
Nocaxe wants to merge 56 commits intosource-academy:masterfrom
Nocaxe:Versioning-and-History

Conversation

@Nocaxe
Copy link
Copy Markdown

@Nocaxe Nocaxe commented Mar 16, 2026

Description

Related Issues and PRs:

Depends on source-academy/backend#1346
to be merged first.

See: #3074

This PR implements versioning and history for the editor in coding assignments, such as missions, quests, and paths. Currently there is no versioning, and the editor only saves and submits the latest version to the server.

This change aims to:
allow students to review or edit previous versions of their code
allow TA’s to understand their student’s coding process to better guide them
allow admins to check for suspicious coding patterns (copy pasting from AI or plagiarism)

Features:
Control Bar Changes:
The original save button has been removed, as the code is now autosaved with a 3 second debounce.
A new saving indicator shows the status of the code, between saving, saved, and saving failed. Whenever unsaved changes are detected, the indicator will show “Saving” and once the debounce expires and the code is saved, it shows “Saved” or “Saving failed” based on the response from the backend.
A new history button opens up the version history view explained below.

Saved Saving Failed

Note: The save button is NOT removed for team assessments as every save will override teammate’s code as well, so we keep the manual save. The saving indicator is removed, but the history button remains, as the version history viewing and restoring still works using manually submitted versions.

Team

Versions are stored in a linear fashion ordered and named by default by timestamp:
Timestamp 2 ← Current Version
Timestamp 1

When a previous version is restored, it is simply saved as a new version on top of the previous versions:
Timestamp 1 - restored ← Current Version
Timestamp 2
Timestamp 1

When the history button is clicked, a drawer opens up on the right of the screen, showing the versions and a preview of that version’s code. It also displays a diff viewer that shows the diff between their current code and the version they are previewing. The student can restore a version by clicking the “Restore this version” button after selecting and previewing that version.

Students can rename the versions by clicking on the default timestamp name. A separate timestamp will still remain below the name.

Screenshot 2026-04-08 at 4 58 02 PM

Possible improvements:
Saving deltas for small changes and snapshots for major changes.
Only display snapshots for major changes when opening the version history panel, and show the versions saved as deltas as a drop down if detailed versions are requested by the user.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Code quality improvements

Backend PR needs to be merged before this PR

How to test

Added tests to WorkspaceSaga.test.ts, WorkspaceReducer.test.ts, and WorkspaceActions.test.ts to test changes.

Manually tested coding in the editor to see if functionality is as expected
Steps taken:
Continuously typed to ensure debounce works
Stop typing to check if debounce runs out and code is submitted and saved
Check version history panel to see if all versions are displayed correctly
Rename a version and check if change is saved correctly
Restore a version and check if code is restored, submitted and renamed correctly
Edited code but made no changes to ensure duplicates are not saved as a new version
Refresh the page to check if the initial population of the editor causes an unwanted extra save

Checklist

  • I have tested this code

@Nocaxe Nocaxe added the Enhancement New feature request label Mar 16, 2026
@Nocaxe Nocaxe marked this pull request as ready for review March 23, 2026 09:41
@RichDom2185
Copy link
Copy Markdown
Member

Please fix the failing tests, thanks!

@RichDom2185
Copy link
Copy Markdown
Member

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a versioning and history system for coding assignments, which is a significant and well-implemented feature. The changes include auto-saving with a debounce mechanism, a UI for save status, and a version history panel for viewing, restoring, and renaming versions. The Redux state management and sagas are well-structured to support this new functionality.

My review includes a few suggestions:

  • A fix for a potential issue where the save button is missing for team assessments on mobile devices.
  • A performance improvement for the version history panel by memoizing sorted data.
  • A code quality improvement to enhance type safety in the new sagas.

@martin-henz martin-henz added the blocked Something else needs pass review first label Mar 26, 2026
@coveralls
Copy link
Copy Markdown

Coverage Report for CI Build 24125674061

Coverage decreased (-0.07%) to 41.648%

Details

  • Coverage decreased (-0.07%) from the base build.
  • Patch coverage: 117 uncovered changes across 9 files (100 of 217 lines covered, 46.08%).
  • 2 coverage regressions across 1 file.

Uncovered Changes

File Changed Covered %
src/commons/sagas/WorkspaceSaga/helpers/versionHistory.ts 114 39 34.21%
src/commons/controlBar/VersionHistoryPanel.tsx 33 14 42.42%
src/commons/sagas/RequestsSaga.ts 11 2 18.18%
src/commons/assessmentWorkspace/AssessmentWorkspace.tsx 16 9 56.25%
src/commons/controlBar/ControlBarSaveStatusIndicator.tsx 6 4 66.67%
src/commons/workspace/WorkspaceReducer.ts 21 19 90.48%
src/commons/mocks/BackendMocks.ts 1 0 0.0%
src/commons/sagas/WorkspaceSaga/index.ts 3 2 66.67%
src/commons/workspace/WorkspaceActions.ts 7 6 85.71%

Coverage Regressions

2 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
src/commons/controlBar/ControlBarSaveButton.tsx 2 20.0%

Coverage Stats

Coverage Status
Relevant Lines: 13636
Covered Lines: 6117
Line Coverage: 44.86%
Relevant Branches: 6891
Covered Branches: 2432
Branch Coverage: 35.29%
Branches in Coverage %: Yes
Coverage Strength: 28.99 hits per line

💛 - Coveralls

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

Labels

blocked Something else needs pass review first Enhancement New feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Versioning and history for student submissions

6 participants