Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 0 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/proxy/actions/Action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Action {
commitData?: CommitData[] = [];
commitFrom?: string;
commitTo?: string;
diff?: string;
branch?: string;
message?: string;
author?: string;
Expand Down
1 change: 1 addition & 0 deletions src/proxy/processors/push-action/getDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const exec = async (_req: Request, action: Action): Promise<Action> => {
step.log(`Executing "git diff ${commitFrom} ${action.commitTo}" in ${path}`);
const revisionRange = `${commitFrom}..${action.commitTo}`;
const diff = await git.diff([revisionRange]);
action.diff = diff;
step.log(diff);
step.setContent(diff);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

} catch (error: unknown) {
Expand Down
7 changes: 3 additions & 4 deletions src/proxy/processors/push-action/scanDiff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,10 @@ const exec = async (_req: Request, action: Action): Promise<Action> => {

const { steps, commitFrom, commitTo } = action;
step.log(`Scanning diff: ${commitFrom}:${commitTo}`);
const diff = action.diff ?? steps.find((s) => s.stepName === 'diff')?.content;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two test gaps worth closing:

  1. Precedence is untested. If action.diff and the diff step content ever diverge, this silently prefers action.diff. A test pinning that precedence would lock the semantics in (the legacy fallback itself is already covered by the existing scanDiff tests).
  2. getPush in test/ui/git-push.test.ts is only mocked with the legacy step shape, so the new typeof data.diff == 'string' branch has no coverage. A test with a top-level string diff (including the empty-string case, which should still win over the fallback) would help.


const diff = steps.find((s) => s.stepName === 'diff')?.content;

step.log(diff);
const diffViolations = getDiffViolations(diff, action.project, step);
step.log(diff as string);
const diffViolations = getDiffViolations(diff as string, action.project, step);

if (diffViolations) {
const formattedMatches = Array.isArray(diffViolations)
Expand Down
5 changes: 4 additions & 1 deletion src/ui/services/git-push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ const getPush = async (id: string): Promise<ServiceResult<PushActionView>> => {
const data: Action = response.data;
const actionView: PushActionView = {
...data,
diff: data.steps.find((x: Step) => x.stepName === 'diff')!,
diff:
typeof data.diff === 'string'
? data.diff
: data.steps.find((x: Step) => x.stepName === 'diff')!,
};
return successResult(actionView);
} catch (error: unknown) {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ export interface BackendResponse {
message: string;
}

export interface PushActionView extends Omit<Action, ActionMethods> {
diff: Step;
export interface PushActionView extends Omit<Action, ActionMethods | 'diff'> {
diff?: string | Step;
}

export interface RepoView extends Repo {
Expand Down
8 changes: 6 additions & 2 deletions src/ui/views/PushDetails/PushDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ const PushDetails = () => {
if (!push) return <div>No push data found</div>;

const commitCount = push.commitData?.length ?? 0;
const changeFileCount = countDiffFiles(push.diff?.content ?? '');
const diffText =
typeof push.diff === 'string'
? push.diff
: (push.diff?.content ?? push.steps?.find((s) => s.stepName === 'diff')?.content ?? '');
const changeFileCount = countDiffFiles(diffText);
const stepCount = push.steps?.length ?? 0;

let statusTitle: PushStatusTitle = 'Pending';
Expand Down Expand Up @@ -456,7 +460,7 @@ const PushDetails = () => {
</Stack>
</GitProxyUnderlinePanels.Panel>
<GitProxyUnderlinePanels.Panel>
<Diff diff={push.diff?.content || ''} />
<Diff diff={diffText} />
</GitProxyUnderlinePanels.Panel>
<GitProxyUnderlinePanels.Panel>
<StepsTimeline steps={push.steps ?? []} />
Expand Down
42 changes: 22 additions & 20 deletions test/fixtures/test-package/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/integration/forcePush.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ describe('Force Push Integration Test', () => {
expect(typeof diffStep.content).toBe('string');
expect(diffStep.content.length).toBeGreaterThan(0);

expect(typeof afterGetDiff.diff).toBe('string');
expect((afterGetDiff.diff as string).length).toBeGreaterThan(0);
expect(afterGetDiff.diff).toEqual(diffStep.content);

const afterScanDiff = await scanDiff(req, afterGetDiff);
const scanStep = afterScanDiff.steps.find((s: Step) => s.stepName === 'scanDiff');

Expand Down
4 changes: 2 additions & 2 deletions test/processors/getDiff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ describe('getDiff', () => {
const result = await exec({} as Request, action);

expect(result.steps[0].error).toBe(false);
expect(result.steps[0].content).toContain('modified content');
expect(result.steps[0].content).toContain('initial content');
expect(result.diff).toContain('modified content');
expect(result.diff).toContain('initial content');
});

it('should get diff between commits with no changes', async () => {
Expand Down
13 changes: 13 additions & 0 deletions test/processors/scanDiff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ describe('Scan commit diff', () => {
await db.deleteRepo(TEST_REPO._id);
});

it('prefers action.diff over diff step content if both exist', async () => {
const action = new Action('1', 'type', 'method', 1, 'test/repo.git');
action.diff = generateDiff('AKIAIOSFODNN7EXAMPLE'); // AWS key in action.diff (should trigger block)
const harmlessStep = generateDiffStep('harmless content without key');
action.steps = [harmlessStep];
action.setCommit('38cdc3e', '8a9c321');
action.setBranch('b');
action.setMessage('Message');

const { error } = await processor.exec({} as Request, action);
expect(error).toBe(true);
});

it('should block push when diff includes AWS Access Key ID', async () => {
const action = new Action('1', 'type', 'method', 1, 'test/repo.git');
const diffStep = generateDiffStep(generateDiff('AKIAIOSFODNN7EXAMPLE'));
Expand Down
36 changes: 36 additions & 0 deletions test/ui/git-push.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,42 @@ describe('git-push service', () => {
);
});

it('returns push data with string diff when top-level diff is a string', async () => {
const pushData = {
id: 'push-123',
diff: 'diff content string',
steps: [{ stepName: 'diff', data: 'fallback step diff' }],
};

axiosMock.mockResolvedValue({ data: pushData });

const result = await getPush('push-123');

expect(result.success).toBe(true);
expect(result.data).toEqual({
...pushData,
diff: 'diff content string',
});
});

it('returns push data with empty string diff when top-level diff is empty string', async () => {
const pushData = {
id: 'push-123',
diff: '',
steps: [{ stepName: 'diff', data: 'fallback step diff' }],
};

axiosMock.mockResolvedValue({ data: pushData });

const result = await getPush('push-123');

expect(result.success).toBe(true);
expect(result.data).toEqual({
...pushData,
diff: '',
});
});

it('returns error result when getPush fails', async () => {
axiosMock.mockRejectedValue({
response: {
Expand Down