refactor: store diff in action object (#1693) - #1701
Conversation
✅ Deploy Preview for endearing-brigadeiros-63f9d0 canceled.
|
dcoric
left a comment
There was a problem hiding this comment.
Thanks for picking this up @amnkarn, I verified the consumer coverage end-to-end (scanDiff, getPush, PushDetails, Cypress mocks) and the legacy fallbacks keep old DB records working, so the compat approach is right. Requesting changes on one compile-level issue plus a few design/test follow-ups:
PushActionViewtype breakstsc(inline, blocking)- diff now persisted 3x per push (inline)
- two test gaps (inline)
- plugin access expectation (inline)
Also: the -40 lines in package-lock.json (removal of "extraneous": true entries) look like an unrelated npm-prune side effect from a local install. Could you revert them or move them to a separate PR so the diff stays clean?
|
|
||
| export interface PushActionView extends Omit<Action, ActionMethods> { | ||
| diff: Step; | ||
| diff: Step | string; |
There was a problem hiding this comment.
[Blocking] This introduces a TypeScript compile error:
src/ui/types.ts(56,18): error TS2430: Interface 'PushActionView' incorrectly extends interface 'Omit<Action, ActionMethods>'.
Types of property 'diff' are incompatible.
Type 'string | Step' is not assignable to type 'string | undefined'.
Type 'Step' is not assignable to type 'string'.
Action.diff added in this PR is string | undefined, so this declaration no longer satisfies the base interface. Current PR CI doesn't run check-types, so it slips through, but it breaks npm run check-types and every contributor's IDE.
Suggested fix: diff: string | Step | undefined;. That is also more honest, since records without a diff step (e.g. tag pushes) are already undefined at runtime today.
| const diff = await git.diff([revisionRange]); | ||
| action.diff = diff; | ||
| step.log(diff); | ||
| step.setContent(diff); |
There was a problem hiding this comment.
The diff is now persisted in three places per push: action.diff, step content, and step logs. All three get serialized into the audit DB on every writeAudit (NeDB and Mongo). NeDB's getPushes has no projection, so the pushes-list payload also grows by another full-diff copy per push.
Now that all consumers read action.diff (the legacy fallback is only needed for old records), could we drop step.setContent(diff) and the full-diff step.log(diff) here and keep just a summary (e.g. diff size)? If you'd rather keep this PR minimal, let's at least note the extra storage copy in the description and track the cleanup as a follow-up.
|
|
||
| const { steps, commitFrom, commitTo } = action; | ||
| step.log(`Scanning diff: ${commitFrom}:${commitTo}`); | ||
| const diff = action.diff ?? steps.find((s) => s.stepName === 'diff')?.content; |
There was a problem hiding this comment.
Two test gaps worth closing:
- Precedence is untested. If
action.diffand thediffstep content ever diverge, this silently prefersaction.diff. A test pinning that precedence would lock the semantics in (the legacy fallback itself is already covered by the existing scanDiff tests). getPushintest/ui/git-push.test.tsis only mocked with the legacy step shape, so the newtypeof data.diff == 'string'branch has no coverage. A test with a top-level stringdiff(including the empty-string case, which should still win over the fallback) would help.
| ...data, | ||
| diff: data.steps.find((x: Step) => x.stepName === 'diff')!, | ||
| diff: | ||
| typeof data.diff == 'string' |
There was a problem hiding this comment.
Nit: use === over == to match codebase style.
One more expectation to manage: the plugin benefit from #1693 won't materialize from this change alone. Plugins are prepended to the chain, so they run before getDiff and can't read action.diff in the same pass. Real plugin access needs post-diff plugin positioning (part of the #1683 revamp scope). Worth softening that point in the PR description.
Fixes #1693
Description
This PR refactors
getDiffand related consumers to store and access the git diff directly on theactionobject (action.diff). This makes it easier for plugins and subsequent actions (likescanDiff) to retrieve the diff without needing to extract it from thestepcontent.Changes Made
getDiffto assign the diff string directly toaction.diffand updated theActioninterface.scanDiff.tsto retrieve the diff fromaction.diff.PushActionViewintypes.tsto acceptStep | stringfor the diff property.getPushingit-push.tsto handle the new string format.Backward Compatibility
To ensure historical database records and existing UI components do not break, fallback logic has been added. If
action.diffis not present (or is not a string), the system gracefully falls back to extracting the content fromsteps.find((s) => s.stepName === 'diff')?.contentin bothscanDiff.tsandgit-push.ts.