-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add modify existing workflow action and output schema validation #14
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
Changes from 2 commits
e7bddc0
2ccdb75
f4eb83b
0579a46
e094e0d
a0df5e9
bd69c8d
22d87ba
c66b258
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| name: Schema Update | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: '0 3 * * 1' # Monday 3AM UTC | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| check: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| actions: write | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: oven-sh/setup-bun@v2 | ||
| - run: bun install | ||
|
|
||
| - name: Generate schemas | ||
| run: bun run crawl | ||
|
|
||
| - name: Capture trigger schemas | ||
| run: bun run scripts/capture-trigger-schemas.ts --from-existing | ||
|
||
| env: | ||
| N8N_API_KEY: ${{ secrets.N8N_API_KEY }} | ||
standujar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| N8N_HOST: ${{ secrets.N8N_HOST }} | ||
|
|
||
| - run: bun run build | ||
|
|
||
| - name: Download latest release | ||
| run: | | ||
| mkdir -p /tmp/latest | ||
| bunx npm pack @elizaos/plugin-n8n-workflow@latest --pack-destination /tmp | ||
| tar xzf /tmp/elizaos-plugin-n8n-workflow-*.tgz -C /tmp/latest | ||
|
Comment on lines
+27
to
+31
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. First-release scenario will fail silently. If ♻️ Suggested fix - name: Download latest release
+ id: download
+ continue-on-error: true
run: |
mkdir -p /tmp/latest
bunx npm pack `@elizaos/plugin-n8n-workflow`@latest --pack-destination /tmp
tar xzf /tmp/elizaos-plugin-n8n-workflow-*.tgz -C /tmp/latestThen in the compare step, treat a download failure as "changed": - name: Compare with latest release
id: compare
run: |
+ if [ "${{ steps.download.outcome }}" = "failure" ]; then
+ echo "No previous release found — treating as changed"
+ echo "changed=true" >> $GITHUB_OUTPUT
+ exit 0
+ fi
CHANGED=false🤖 Prompt for AI Agents |
||
|
|
||
| - name: Compare with latest release | ||
| id: compare | ||
| run: | | ||
| CHANGED=false | ||
|
|
||
| for file in defaultNodes.json schemaIndex.json triggerSchemaIndex.json; do | ||
| NEW="dist/data/$file" | ||
| OLD="/tmp/latest/package/dist/data/$file" | ||
|
|
||
| if [ ! -f "$NEW" ]; then | ||
| continue | ||
| fi | ||
|
Comment on lines
+42
to
+44
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. Missing local artifact skipped silently — may mask build failures. If 🤖 Prompt for AI Agents |
||
|
|
||
| if [ ! -f "$OLD" ]; then | ||
| echo "$file: NEW file (not in latest release)" | ||
| CHANGED=true | ||
| continue | ||
| fi | ||
|
|
||
| if ! diff <(jq -S . "$NEW") <(jq -S . "$OLD") > /dev/null 2>&1; then | ||
| echo "$file: CHANGED" | ||
| CHANGED=true | ||
| else | ||
| echo "$file: unchanged" | ||
| fi | ||
| done | ||
|
|
||
| echo "changed=$CHANGED" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Bump version | ||
| if: steps.compare.outputs.changed == 'true' | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| npm version patch --no-git-tag-version | ||
| VERSION=$(jq -r .version package.json) | ||
| git add package.json | ||
| git commit -m "chore: bump to v${VERSION} (schema update)" | ||
| git push | ||
|
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. Security concern: This workflow automatically pushes version bumps to main without creating a PR for review. Risk: Schema changes could introduce breaking changes that bypass code review. Recommendation: Instead of auto-pushing, create a PR: - name: Create PR for schema update
if: steps.compare.outputs.changed == 'true'
run: |
git checkout -b schema-update-$(date +%Y%m%d)
git add package.json dist/data/
git commit -m "chore: update schemas (automated)"
git push origin schema-update-$(date +%Y%m%d)
gh pr create --title "chore: update schemas" --body "Automated schema update from scheduled job" |
||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Trigger publish | ||
| if: steps.compare.outputs.changed == 'true' | ||
| run: gh workflow run npm-deploy.yml | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -513,6 +513,79 @@ describe('CREATE_N8N_WORKFLOW action', () => { | |
| }); | ||
| }); | ||
|
|
||
| // ========================================================================== | ||
| // MODIFY INCLUDES CHANGES IN PREVIEW | ||
| // ========================================================================== | ||
|
|
||
| describe('handler - modify includes changes in preview', () => { | ||
| test('preview data includes changed parameters after modify', async () => { | ||
| const draft: WorkflowDraft = { | ||
| workflow: { | ||
| name: 'Gmail Forward', | ||
| nodes: [ | ||
| { | ||
| name: 'Gmail Trigger', | ||
| type: 'n8n-nodes-base.gmailTrigger', | ||
| typeVersion: 1, | ||
| position: [0, 0] as [number, number], | ||
| parameters: { pollTimes: { item: [{ mode: 'everyMinute' }] } }, | ||
| }, | ||
| { | ||
| name: 'Forward Email', | ||
| type: 'n8n-nodes-base.gmail', | ||
| typeVersion: 2, | ||
| position: [200, 0] as [number, number], | ||
| parameters: { operation: 'send', sendTo: '[email protected]' }, | ||
| credentials: { gmailOAuth2Api: { id: 'cred-1', name: 'Gmail' } }, | ||
| }, | ||
| ], | ||
| connections: { | ||
| 'Gmail Trigger': { main: [[{ node: 'Forward Email', type: 'main', index: 0 }]] }, | ||
| }, | ||
| }, | ||
| prompt: 'Forward emails', | ||
| userId: 'user-001', | ||
| createdAt: Date.now(), | ||
| }; | ||
|
|
||
| const modifiedWorkflow = { | ||
| ...draft.workflow, | ||
| nodes: [ | ||
| draft.workflow.nodes[0], | ||
| { | ||
| ...draft.workflow.nodes[1], | ||
| parameters: { operation: 'send', sendTo: '[email protected]' }, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const mockService = createMockService({ | ||
| modifyWorkflowDraft: mock(() => Promise.resolve(modifiedWorkflow)), | ||
| }); | ||
|
|
||
| const runtime = createMockRuntime({ | ||
| services: { [N8N_WORKFLOW_SERVICE_TYPE]: mockService }, | ||
| useModel: createUseModelMock({ intent: 'modify', reason: 'User wants to modify' }), | ||
| cache: { 'workflow_draft:user-001': draft }, | ||
| }); | ||
|
|
||
| const callback = createMockCallback(); | ||
|
|
||
| await createWorkflowAction.handler( | ||
| runtime, | ||
| createMockMessage({ content: { text: 'change email to [email protected]' } }), | ||
| createMockState(), | ||
| { intent: 'modify', modification: 'change email to [email protected]' }, | ||
| callback | ||
| ); | ||
|
|
||
| // The callback text should contain the new email (changes are passed to formatActionResponse) | ||
| const calls = (callback as any).mock.calls; | ||
| const lastText = calls[calls.length - 1][0].text; | ||
| expect(lastText).toContain('[email protected]'); | ||
| }); | ||
| }); | ||
|
|
||
| // ========================================================================== | ||
| // CALLBACK SUCCESS STATUS TESTS | ||
| // ========================================================================== | ||
|
|
||
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.
Security concern - secrets in script execution: The trigger schema capture script receives N8N credentials and could potentially access/modify workflows.
Risk: If the script is compromised or has a bug, it could leak credentials or modify production workflows.
Recommendations: