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
6 changes: 6 additions & 0 deletions .changeset/keep-collection-ids.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@openfn/project': patch
'@openfn/cli': patch
---

Fix deploying to a different project failing once that project has collections
2 changes: 1 addition & 1 deletion packages/project/src/merge/merge-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export function merge(
source.credentials,
target.credentials
),
collections: source.collections,
collections: mergeCollections(source.collections, target.collections),
channels: mergeChannels(source.channels, target.channels),
}
: {
Expand Down
18 changes: 13 additions & 5 deletions packages/project/test/merge/merge-project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ test('replace mode: undefined local collections leave the target collections alo
t.deepEqual(result.collections, targetCollections);
});

test('sandbox mode: source collections fully replace target collections', (t) => {
test('sandbox mode: source collections replace target collections, keeping target uuid on a name match', (t) => {
const wf = {
steps: [
{ id: 'x', name: 'X', adaptor: 'common', expression: 'fn(s => s)' },
Expand All @@ -395,17 +395,25 @@ test('sandbox mode: source collections fully replace target collections', (t) =>

const targetCollections = [
{ uuid: 'remote-uuid-1', name: 'target-collection' },
{ uuid: 'remote-uuid-2', name: 'shared-collection' },
];
// the source's own uuids belong to a different project
const sourceCollections = [
{ name: 'source-collection' },
{ uuid: 'source-uuid', name: 'shared-collection' },
];
const sourceCollections = [{ name: 'source-collection' }];

const target = createProject(wf_a, 'a', { collections: targetCollections });
const source = createProject(wf_b, 'b', { collections: sourceCollections });

const result = merge(source, target, { mode: SANDBOX_MERGE });

// b's collections are wholly replaced by a's - sandbox mode does a raw
// swap here, unlike replace mode's name-matching mergeCollections
t.deepEqual(result.collections, sourceCollections);
// a shared collection must keep the target's uuid, or the deploy tries to
// create a duplicate and Lightning rejects it
t.deepEqual(result.collections, [
{ name: 'source-collection', uuid: undefined },
{ name: 'shared-collection', uuid: 'remote-uuid-2' },
]);
});

test('sandbox mode: target channels are preserved when source has none', (t) => {
Expand Down
Loading