-
Notifications
You must be signed in to change notification settings - Fork 17
feat(ws-worker): support multi-root @local adaptor resolution #1397
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
Open
jeremi
wants to merge
2
commits into
OpenFn:main
Choose a base branch
from
jeremi:feat/multi-root-local-adaptors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@openfn/ws-worker': minor | ||
| --- | ||
|
|
||
| Support comma-separated `OPENFN_ADAPTORS_REPO` so a private adaptor monorepo can be loaded alongside the canonical OpenFn adaptors monorepo. When a job pins an adaptor to `@local`, the worker now walks the configured roots in order and resolves to the first root that contains `packages/<shortName>/package.json`. Single-path values continue to work unchanged. Earlier paths win on collision, mirroring Lightning's `AdaptorRegistry` precedence rules so the registry view and the worker's execution path stay consistent. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| import test from 'ava'; | ||
| import fs from 'node:fs'; | ||
| import os from 'node:os'; | ||
| import path from 'node:path'; | ||
| import type { | ||
| LightningPlan, | ||
| LightningJob, | ||
|
|
@@ -7,6 +10,17 @@ import type { | |
| import convertPlan from '../../src/util/convert-lightning-plan'; | ||
| import { Job } from '@openfn/lexicon'; | ||
|
|
||
| // Builds a temporary monorepo root with package.json files in each named adaptor. | ||
| const makeMonorepo = (adaptors: string[]) => { | ||
|
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. Not wild about the file IO stuff in these tests to be honest. Mostly in this repo we use the |
||
| const root = fs.mkdtempSync(path.join(os.tmpdir(), 'multi-root-')); | ||
| for (const adaptor of adaptors) { | ||
| const pkgDir = path.join(root, 'packages', adaptor); | ||
| fs.mkdirSync(pkgDir, { recursive: true }); | ||
| fs.writeFileSync(path.join(pkgDir, 'package.json'), '{}'); | ||
| } | ||
| return root; | ||
| }; | ||
|
|
||
| // Creates a lightning node (job or trigger) | ||
| const createNode = (props = {}) => | ||
| ({ | ||
|
|
@@ -585,6 +599,112 @@ test('Use local paths', (t) => { | |
| }); | ||
| }); | ||
|
|
||
| test('Use local paths: resolves @local against a single existing root', (t) => { | ||
| const root = makeMonorepo(['common']); | ||
|
|
||
| const run: Partial<LightningPlan> = { | ||
| id: 'w', | ||
| jobs: [createNode({ id: 'a', adaptor: 'common@local' })], | ||
| triggers: [{ id: 't', type: 'cron' }], | ||
| edges: [createEdge('t', 'a')], | ||
| }; | ||
|
|
||
| const { plan } = convertPlan(run as LightningPlan, { monorepoPath: root }); | ||
| const [, a] = plan.workflow.steps as any[]; | ||
|
|
||
| t.deepEqual(a.linker.common, { | ||
| path: path.resolve(root, 'packages', 'common'), | ||
| version: 'local', | ||
| }); | ||
| }); | ||
|
|
||
| test('Use local paths: walks comma-separated roots in order, first match wins', (t) => { | ||
| const privateRoot = makeMonorepo(['publicschema']); | ||
| const canonicalRoot = makeMonorepo(['common', 'publicschema']); | ||
|
|
||
| const run: Partial<LightningPlan> = { | ||
| id: 'w', | ||
| jobs: [ | ||
| createNode({ id: 'a', adaptor: 'common@local' }), | ||
| createNode({ id: 'b', adaptor: 'publicschema@local' }), | ||
| ], | ||
| triggers: [{ id: 't', type: 'cron' }], | ||
| edges: [createEdge('t', 'a'), createEdge('a', 'b')], | ||
| }; | ||
|
|
||
| const { plan } = convertPlan(run as LightningPlan, { | ||
| monorepoPath: `${privateRoot},${canonicalRoot}`, | ||
| }); | ||
| const [, a, b] = plan.workflow.steps as any[]; | ||
|
|
||
| // common only exists in the canonical root, so it falls through. | ||
| t.is(a.linker.common.path, path.resolve(canonicalRoot, 'packages', 'common')); | ||
| // publicschema exists in both; the private (earlier) root wins. | ||
| t.is( | ||
| b.linker.publicschema.path, | ||
| path.resolve(privateRoot, 'packages', 'publicschema') | ||
| ); | ||
| }); | ||
|
|
||
| test('Use local paths: ignores roots that do not contain the adaptor', (t) => { | ||
| const emptyRoot = makeMonorepo([]); | ||
| const realRoot = makeMonorepo(['http']); | ||
|
|
||
| const run: Partial<LightningPlan> = { | ||
| id: 'w', | ||
| jobs: [createNode({ id: 'a', adaptor: 'http@local' })], | ||
| triggers: [{ id: 't', type: 'cron' }], | ||
| edges: [createEdge('t', 'a')], | ||
| }; | ||
|
|
||
| const { plan } = convertPlan(run as LightningPlan, { | ||
| monorepoPath: `${emptyRoot},${realRoot}`, | ||
| }); | ||
| const [, a] = plan.workflow.steps as any[]; | ||
|
|
||
| t.is(a.linker.http.path, path.resolve(realRoot, 'packages', 'http')); | ||
| }); | ||
|
|
||
| test('Use local paths: trims whitespace and drops empty segments', (t) => { | ||
| const root = makeMonorepo(['common']); | ||
|
|
||
| const run: Partial<LightningPlan> = { | ||
| id: 'w', | ||
| jobs: [createNode({ id: 'a', adaptor: 'common@local' })], | ||
| triggers: [{ id: 't', type: 'cron' }], | ||
| edges: [createEdge('t', 'a')], | ||
| }; | ||
|
|
||
| const { plan } = convertPlan(run as LightningPlan, { | ||
| monorepoPath: ` , ${root} , `, | ||
| }); | ||
| const [, a] = plan.workflow.steps as any[]; | ||
|
|
||
| t.is(a.linker.common.path, path.resolve(root, 'packages', 'common')); | ||
| }); | ||
|
|
||
| test('Use local paths: falls back to the first root when no root has the adaptor', (t) => { | ||
| const rootA = makeMonorepo([]); | ||
| const rootB = makeMonorepo([]); | ||
|
|
||
| const run: Partial<LightningPlan> = { | ||
| id: 'w', | ||
| jobs: [createNode({ id: 'a', adaptor: 'mystery@local' })], | ||
| triggers: [{ id: 't', type: 'cron' }], | ||
| edges: [createEdge('t', 'a')], | ||
| }; | ||
|
|
||
| const { plan } = convertPlan(run as LightningPlan, { | ||
| monorepoPath: `${rootA},${rootB}`, | ||
| }); | ||
| const [, a] = plan.workflow.steps as any[]; | ||
|
|
||
| // The candidate path under the first root is surfaced even though the | ||
| // adaptor is missing, so the runtime emits a clean "missing adaptor" | ||
| // error instead of crashing on a malformed joined path. | ||
| t.is(a.linker.mystery.path, path.resolve(rootA, 'packages', 'mystery')); | ||
| }); | ||
|
|
||
| test('pass globals from lightning run to plan', (t) => { | ||
| const GLOBALS_CONTENT = "export const prefixer = (v) => 'prefix-' + v"; | ||
| const run: Partial<LightningPlan> = { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Way too many comments here, and in the wrong place. But I can tidy that up before merge to main. I presume these are AI generated?