-
Notifications
You must be signed in to change notification settings - Fork 2.4k
fix(core): restore file history snapshots on resume #4253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -61,6 +61,21 @@ export interface RewindResult { | |||||||||||||||||||||
| const MAX_SNAPSHOTS = 100; | ||||||||||||||||||||||
| const FILE_HISTORY_DIR = 'file-history'; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| function toValidDate(value: unknown): Date | null { | ||||||||||||||||||||||
| if (value instanceof Date) { | ||||||||||||||||||||||
| return Number.isNaN(value.getTime()) ? null : value; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| if (typeof value !== 'string' && typeof value !== 'number') { | ||||||||||||||||||||||
| return null; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| const normalized = new Date(value); | ||||||||||||||||||||||
| return Number.isNaN(normalized.getTime()) ? null : normalized; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| function isFileHistoryBackupRecord(value: unknown): value is FileHistoryBackup { | ||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The type guard
Suggested change
— qwen-latest-series-invite-beta-v28 via Qwen Code /review |
||||||||||||||||||||||
| return !!value && typeof value === 'object'; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| function isENOENT(e: unknown): boolean { | ||||||||||||||||||||||
| return ( | ||||||||||||||||||||||
| typeof e === 'object' && | ||||||||||||||||||||||
|
|
@@ -311,13 +326,42 @@ export class FileHistoryService { | |||||||||||||||||||||
| const trackedFiles = new Set<string>(); | ||||||||||||||||||||||
| const migrated: FileHistorySnapshot[] = []; | ||||||||||||||||||||||
| for (const snapshot of snapshots) { | ||||||||||||||||||||||
| if ( | ||||||||||||||||||||||
| !snapshot?.promptId || | ||||||||||||||||||||||
| !snapshot.trackedFileBackups || | ||||||||||||||||||||||
| typeof snapshot.trackedFileBackups !== 'object' | ||||||||||||||||||||||
| ) { | ||||||||||||||||||||||
| continue; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const timestamp = toValidDate(snapshot.timestamp); | ||||||||||||||||||||||
| if (!timestamp) { | ||||||||||||||||||||||
| continue; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const trackedFileBackups: Record<string, FileHistoryBackup> = {}; | ||||||||||||||||||||||
| for (const [p, backup] of Object.entries(snapshot.trackedFileBackups)) { | ||||||||||||||||||||||
| if (!isFileHistoryBackupRecord(backup)) { | ||||||||||||||||||||||
| continue; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const backupTime = toValidDate(backup.backupTime); | ||||||||||||||||||||||
| if (!backupTime) { | ||||||||||||||||||||||
| continue; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| const trackingPath = this.maybeShortenFilePath(p); | ||||||||||||||||||||||
| trackedFiles.add(trackingPath); | ||||||||||||||||||||||
| trackedFileBackups[trackingPath] = backup; | ||||||||||||||||||||||
| trackedFileBackups[trackingPath] = { | ||||||||||||||||||||||
| ...backup, | ||||||||||||||||||||||
| backupTime, | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| migrated.push({ ...snapshot, trackedFileBackups }); | ||||||||||||||||||||||
| migrated.push({ | ||||||||||||||||||||||
| ...snapshot, | ||||||||||||||||||||||
| timestamp, | ||||||||||||||||||||||
| trackedFileBackups, | ||||||||||||||||||||||
| }); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| this.state = { | ||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] Consider capping before assignment: if (migrated.length > MAX_SNAPSHOTS) {
migrated = migrated.slice(migrated.length - MAX_SNAPSHOTS);
}— qwen-latest-series-invite-beta-v28 via Qwen Code /review |
||||||||||||||||||||||
| snapshots: migrated, | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Nice to have] Indentation regression: this
it(...)line was re-indented from 4 spaces to 2 spaces, breaking alignment with sibling test cases in the samedescribeblock. Likely an accidental edit during rebase.— qwen-latest-series-invite-beta-v28 via Qwen Code /review