Skip to content

Commit

Permalink
fix(snapshot): define resourceToPreview from resources changed. (#1453)
Browse files Browse the repository at this point in the history
<!-- For Coveo Employees only. Fill this section.

CDX-XXX

-->

## Proposed changes

The current algorithm doesn't take into account the resources the user
can access.
To solves that, we could either:
 - Query/cache what resources the user can access when we query it
 - Only do the expanded preview on resources that change.

## Breaking changes


## Testing

- [ ] Unit Tests:
Snapshot UTs are tangled, changing it will be difficult/require a
rewrite.
- [ ] Functionnal Tests:
Corner-case, would require to create orgs without some access right or
some stuff like that.
- [ ] Manual Tests:
In the only known affected environment (customer-owned), I managed to
reproduce the issue the same customer reported.
- Tested with the current version of the CLI, dev build from master:
Crash
 - Tested with dev build from this branch: No Crash.

---------

Co-authored-by: Olivier Lamothe <[email protected]>
  • Loading branch information
louis-bompart and olamothe authored Mar 14, 2024
1 parent 8488ce2 commit c4095f8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
16 changes: 8 additions & 8 deletions packages/cli-e2e/__tests__/__snapshots__/atomic.specs.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ HashedFolder {
HashedFolder {
"children": [
HashedFile {
"hash": "61GVF7l8bCVXW00H2rtInTKwoqY=",
"hash": "e5DQ3kRU03Vmp2BC+mjlSypQjKE=",
"name": "index.css",
},
],
"hash": "FQZ6fv/Z/8DhwZWuUbrLwgTt6r8=",
"hash": "IMDEBLQ/slaFFRst+lJYHMRm07E=",
"name": "style",
},
HashedFolder {
Expand All @@ -104,15 +104,15 @@ HashedFolder {
"name": "utils",
},
],
"hash": "pBlrdRw5yuMk/S0mFDAUBGrEvMs=",
"hash": "K9gD9O4uCLlQbxYAgmEW6K+5EAw=",
"name": "src",
},
HashedFile {
"hash": "9nyo2P7hCKS4uXz6KBbyR2tzRtY=",
"name": "tsconfig.json",
},
],
"hash": "MX8XJmhwXYKcItyHsBvb0tWTjlM=",
"hash": "TZXkS/G4E85OYZrwyJxf/QI7lJ8=",
"name": "normalizedDir",
}
`;
Expand Down Expand Up @@ -329,11 +329,11 @@ HashedFolder {
HashedFolder {
"children": [
HashedFile {
"hash": "/limo6D9Trxh05AOjVfMeecwXR8=",
"hash": "xbqB+xpmHNlBnQf+PCHR+rT3tfg=",
"name": "index.css",
},
],
"hash": "/ARqEzx1ZY/+YdpH3eOpUbZnjj8=",
"hash": "Z+bQXHQFJdpSE56ncUOv3fWRy6w=",
"name": "style",
},
HashedFolder {
Expand All @@ -347,15 +347,15 @@ HashedFolder {
"name": "utils",
},
],
"hash": "FJTdsvHKymcS4bWGsVDxdv5+xI0=",
"hash": "9IWPASf2gKXfg4rrJ+k4DSwv4c4=",
"name": "src",
},
HashedFile {
"hash": "9nyo2P7hCKS4uXz6KBbyR2tzRtY=",
"name": "tsconfig.json",
},
],
"hash": "fXSss5dlkGuizSP8OXlIF3OvP2Q=",
"hash": "20bLNlmkPR5jmaL2CitCTveWor8=",
"name": "normalizedDir",
}
`;
Expand Down
4 changes: 3 additions & 1 deletion packages/cli-e2e/__tests__/angular.specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ describe('ui:create:angular', () => {
message.indexOf('Warnings while compiling') === -1 &&
message.indexOf(
'require function is used in a way in which dependencies cannot be statically extracted'
) === -1
) === -1 &&
message.indexOf('@reduxjs/toolkit/dist/uncheckedindexed.ts') ===
-1
)
).toEqual([]);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {DotFolder} from '../../project/dotFolder';
import {cwd} from 'process';
import {buildResourcesToExport} from '../pullModel/validation/model';
import {startSpinner, stopSpinner} from '@coveo/cli-commons/utils/ux';
import {SnapshotReporter} from '../snapshotReporter';

export class ExpandedPreviewer {
private static readonly previewDirectoryName = 'preview';
Expand All @@ -28,9 +29,8 @@ export class ExpandedPreviewer {
private readonly projectToPreview: Project,
private readonly shouldDelete: boolean
) {
this.resourcesToPreview = Object.keys(
report.resourceOperationResults
) as ResourceSnapshotType[];
const reporter = new SnapshotReporter(report);
this.resourcesToPreview = reporter.getAffectedResourceTypes();
}

private static get previewDirectory() {
Expand Down
21 changes: 21 additions & 0 deletions packages/cli/core/src/lib/snapshot/snapshotReporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,27 @@ export class SnapshotReporter {
) > 0;
}

public getAffectedResourceTypes(): ResourceSnapshotType[] {
const isResourceTypeReportAffected = (
report: ResourceSnapshotsReportOperationModel
) =>
Object.values(report).reduce(
(operation, total) => operation + total,
0
) === 0;
const changedResourcesTypes: ResourceSnapshotType[] = [];
for (const resourceType of Object.keys(this.report.resourceOperations)) {
if (
isResourceTypeReportAffected(
this.report.resourceOperations[resourceType]
)
) {
changedResourcesTypes.push(resourceType as ResourceSnapshotType);
}
}
return changedResourcesTypes;
}

public hasChangedResources() {
const totalUnchanges =
this.getOperationTypeTotalCount('resourcesUnchanged');
Expand Down

0 comments on commit c4095f8

Please sign in to comment.