From 20f2bbd826a33a95a41a6c7a660d9eac9cc16927 Mon Sep 17 00:00:00 2001 From: SomeoneWithOptions Date: Tue, 3 Nov 2026 21:07:29 -0500 Subject: [PATCH] fix: workflow, execution and community-package spec drift (n8n 2.46.4) - workflow: settings.engineType (server-owned; n8n 2.46 ignores it on write, older instances reject it as an unknown setting) is dropped from create/update bodies and reported as settings.engineType; settings.redactCallerExecutions round-trips unchanged. Node timestamps are still stripped for older instances and the write schema. - execution retry: data, workflowData and customData may be absent; text output says so on stderr, JSON omits them. - community-package install: model policyRestrictions, keep it in JSON and list blocked node types in text output with a node-policy hint on stderr. - credential create/update help: data fields accept n8n expressions. Co-Authored-By: Claude Opus 5.5 --- docs/n8n_community-package_install.md | 4 ++ docs/n8n_credential_create.md | 5 +- docs/n8n_credential_update.md | 3 +- docs/n8n_execution_retry.md | 6 ++- docs/n8n_workflow_create.md | 7 +-- docs/n8n_workflow_update.md | 8 +-- internal/cli/community_package.go | 41 +++++++++++++- internal/cli/community_package_test.go | 75 ++++++++++++++++++++++++++ internal/cli/credential.go | 8 +-- internal/cli/execution.go | 14 +++-- internal/cli/execution_test.go | 59 ++++++++++++++++++++ internal/cli/workflow.go | 15 +++--- internal/cli/workflow_test.go | 45 ++++++++++++++++ internal/n8n/community_package.go | 28 ++++++++++ internal/n8n/community_package_test.go | 64 ++++++++++++++++++++++ internal/n8n/execution.go | 4 +- internal/n8n/execution_test.go | 29 ++++++++++ internal/n8n/workflow.go | 30 +++++++---- internal/n8n/workflow_test.go | 58 ++++++++++++++++++++ 19 files changed, 469 insertions(+), 34 deletions(-) diff --git a/docs/n8n_community-package_install.md b/docs/n8n_community-package_install.md index d517429..43374ee 100644 --- a/docs/n8n_community-package_install.md +++ b/docs/n8n_community-package_install.md @@ -12,6 +12,10 @@ such as latest or beta; omit it to let npm select the version. Whether unverified packages may be installed is an instance setting: when it is off, only versions verified by n8n install. Installed package code runs inside n8n. +A node type policy does not stop the install. When the instance evaluates its +policies, the output lists each blocked node type of the package, or "none"; +JSON output carries them as policyRestrictions. + Interactive runs ask before installing. Non-interactive runs fail unless --yes is passed. Requires API-key authentication and communityPackage:install. Next step: 'n8n community-package list'. diff --git a/docs/n8n_credential_create.md b/docs/n8n_credential_create.md index 8dda298..13defe3 100644 --- a/docs/n8n_credential_create.md +++ b/docs/n8n_credential_create.md @@ -8,8 +8,9 @@ Create a credential from one JSON document. Required fields are name, type and data; optional fields are projectId, isResolvable, description (plain text, at most 512 characters; ignored when the instance has descriptions disabled) and id (1 to 16 letters, digits, underscores or hyphens, kept exactly; omit it to -have one generated). Because data contains secrets, JSON is accepted only -through --file or piped --stdin, never argv. +have one generated). data fields also accept n8n expressions: strings that +start with "=". Because data contains secrets, JSON is accepted only through +--file or piped --stdin, never argv. The request body is excluded from debug logs. Output contains metadata only. Requires credential:create; project creation can have additional role restrictions. diff --git a/docs/n8n_credential_update.md b/docs/n8n_credential_update.md index f9e7a87..8653923 100644 --- a/docs/n8n_credential_update.md +++ b/docs/n8n_credential_update.md @@ -7,7 +7,8 @@ Update a credential from secret JSON Update an owned credential from one JSON document. Accepted fields are name, description, type, data, isGlobal, isResolvable and isPartialData. Set isPartialData=true to merge provided data with stored data; false replaces the -full data object. Changing type requires data. description is at most 512 +full data object. Changing type requires data. data fields also accept n8n +expressions: strings that start with "=". description is at most 512 characters; null or "" clears it and omitting it keeps it. Managed credentials cannot be edited. diff --git a/docs/n8n_execution_retry.md b/docs/n8n_execution_retry.md index e072495..e181fe8 100644 --- a/docs/n8n_execution_retry.md +++ b/docs/n8n_execution_retry.md @@ -9,8 +9,10 @@ workflow definition stored with the original execution, making the retry reproducible. --latest-workflow instead loads the workflow currently saved on the instance. -The original execution is retained and the response identifies the new run. A -run that cannot be retried returns a conflict. This starts workflow work and may +The original execution is retained and the response identifies the new run. Its +run data, workflowData and customData are absent when the caller cannot read the +workflow's executions; the retry still starts. A run that cannot be retried +returns a conflict. This starts workflow work and may repeat its external side effects. Requires execution:retry. --idempotency-key KEY makes a retry after a timeout or lost response safe: diff --git a/docs/n8n_workflow_create.md b/docs/n8n_workflow_create.md index 984ea1d..5112ce3 100644 --- a/docs/n8n_workflow_create.md +++ b/docs/n8n_workflow_create.md @@ -11,9 +11,10 @@ nodes, ready to be edited in the UI or filled in by a later update. The input may be a document produced by 'n8n workflow get --output json': the read-only fields (id, versionId, active, timestamps, tags, sharing, node timestamps) and settings set to "DEFAULT" are dropped before sending, because -the API answers them with 400, and the dropped names are reported on stderr. A -null settings is sent as {}. --name, --project-id and --parent-folder-id -override what the document says. +the API answers them with 400, and the dropped names are reported on stderr. +settings.engineType is dropped too: n8n ignores it on write and instances +before 2.46 reject it. A null settings is sent as {}. --name, --project-id and +--parent-folder-id override what the document says. A created workflow is never published: publish it with 'n8n workflow publish'. Requires workflow:create. diff --git a/docs/n8n_workflow_update.md b/docs/n8n_workflow_update.md index 5828dd8..30e11a8 100644 --- a/docs/n8n_workflow_update.md +++ b/docs/n8n_workflow_update.md @@ -16,9 +16,11 @@ Read-only fields in the document (id, versionId, active, timestamps, tags, sharing, node timestamps) and settings set to "DEFAULT" are dropped before sending and reported on stderr, because the API answers them with 400; an omitted setting keeps the instance default, which is what "DEFAULT" means. -A null settings is sent as {}. Add "parentFolderId": "FOLDER_ID" to move -the workflow into a folder, or "parentFolderId": null to move it to the -project root; without the field the folder is unchanged. +settings.engineType is dropped and reported too: n8n ignores it on write and +instances before 2.46 reject it. A null settings is sent as {}. Add +"parentFolderId": "FOLDER_ID" to move the workflow into a folder, or +"parentFolderId": null to move it to the project root; without the field the +folder is unchanged. A published workflow is republished with the new version unless --no-publish is given. Republishing additionally needs the workflow:activate scope and the diff --git a/internal/cli/community_package.go b/internal/cli/community_package.go index 854c618..2534874 100644 --- a/internal/cli/community_package.go +++ b/internal/cli/community_package.go @@ -139,6 +139,9 @@ func newCommunityPackageInstallCommand(opts Options) *cobra.Command { "such as latest or beta; omit it to let npm select the version. Whether\n" + "unverified packages may be installed is an instance setting: when it is off,\n" + "only versions verified by n8n install. Installed package code runs inside n8n.\n\n" + + "A node type policy does not stop the install. When the instance evaluates its\n" + + "policies, the output lists each blocked node type of the package, or \"none\";\n" + + "JSON output carries them as policyRestrictions.\n\n" + "Interactive runs ask before installing. Non-interactive runs fail unless --yes\n" + "is passed. Requires API-key authentication and communityPackage:install.\n" + "Next step: 'n8n community-package list'.", @@ -332,7 +335,43 @@ func writeCommunityPackageText(opts Options, resolution config.Resolution, actio if pkg.FailedLoading { fmt.Fprintln(tw, "Status:\tfailed to load") } - return tw.Flush() + if restrictions := pkg.PolicyRestrictions; restrictions != nil { + if len(restrictions.NodeTypes) == 0 { + fmt.Fprintln(tw, "Blocked node types:\tnone") + } + for _, blocked := range restrictions.NodeTypes { + fmt.Fprintf(tw, "Blocked node type:\t%s (%s)\n", blocked.Type, describeBlockedNodeType(blocked)) + } + } + if err := tw.Flush(); err != nil { + return err + } + if pkg.PolicyRestrictions != nil && len(pkg.PolicyRestrictions.NodeTypes) > 0 { + count := fmt.Sprintf("%d node types", len(pkg.PolicyRestrictions.NodeTypes)) + if len(pkg.PolicyRestrictions.NodeTypes) == 1 { + count = "1 node type" + } + fmt.Fprintf(opts.Streams.Err, "Node type policies block %s of %s; the package is still %s. Review the policies with 'n8n node-policy instance get' or 'n8n node-policy project get PROJECT_ID'.\n", count, pkg.PackageName, strings.ToLower(action)) + } + return nil +} + +// describeBlockedNodeType says where a policy blocks a node type and whether a +// project can still allow it. +func describeBlockedNodeType(blocked n8n.CommunityPackageBlockedNodeType) string { + var where string + switch blocked.BlockedOn { + case n8n.BlockedOnInstance: + where = "blocked on the instance" + case n8n.BlockedOnProjects: + where = "blocked in one or more projects" + default: + where = "blocked on " + emptyDash(blocked.BlockedOn) + } + if blocked.OptInAvailable { + where += "; a project can allow it" + } + return where } func validateCommunityPackageArgument(name string) error { diff --git a/internal/cli/community_package_test.go b/internal/cli/community_package_test.go index 48b5f46..cdbca2a 100644 --- a/internal/cli/community_package_test.go +++ b/internal/cli/community_package_test.go @@ -118,6 +118,81 @@ func TestCommunityPackageInstallJSONNonInteractive(t *testing.T) { assertCLIJSON(t, `{"name":"n8n-nodes-example"}`, f.lastBody()) } +func TestCommunityPackageInstallPolicyRestrictionsText(t *testing.T) { + body := strings.TrimSuffix(cliCommunityPackage, "}") + `,"policyRestrictions":{"nodeTypes":[ + {"type":"n8n-nodes-example.example","blockedOn":"instance","optInAvailable":true}, + {"type":"n8n-nodes-example.other","blockedOn":"projects","optInAvailable":false}]}}` + f := communityPackageFixture(t, body) + got := f.run("community-package", "install", "n8n-nodes-example", "--yes") + if got.code != ExitSuccess { + t.Fatalf("exit code = %d, want %d (stderr: %s)", got.code, ExitSuccess, got.stderr) + } + for _, want := range []string{ + "Blocked node type: n8n-nodes-example.example (blocked on the instance; a project can allow it)", + "Blocked node type: n8n-nodes-example.other (blocked in one or more projects)", + } { + if !strings.Contains(got.stdout, want) { + t.Errorf("stdout missing %q\n%s", want, got.stdout) + } + } + for _, want := range []string{"block 2 node types of n8n-nodes-example", "still installed", "n8n node-policy instance get"} { + if !strings.Contains(got.stderr, want) { + t.Errorf("stderr missing %q\n%s", want, got.stderr) + } + } + if strings.Contains(got.stdout, "node-policy") { + t.Errorf("stdout carries the hint; it belongs on stderr\n%s", got.stdout) + } +} + +func TestCommunityPackageInstallPolicyRestrictionsNone(t *testing.T) { + f := communityPackageFixture(t, strings.TrimSuffix(cliCommunityPackage, "}")+`,"policyRestrictions":{"nodeTypes":[]}}`) + got := f.run("community-package", "install", "n8n-nodes-example", "--yes") + if got.code != ExitSuccess { + t.Fatalf("exit code = %d, want %d (stderr: %s)", got.code, ExitSuccess, got.stderr) + } + if !strings.Contains(got.stdout, "Blocked node types: none") { + t.Errorf("stdout missing empty policy result\n%s", got.stdout) + } + if got.stderr != "" { + t.Errorf("stderr = %q, want empty when nothing is blocked", got.stderr) + } +} + +func TestCommunityPackageInstallWithoutPolicyRestrictions(t *testing.T) { + f := communityPackageFixture(t, cliCommunityPackage) + got := f.run("community-package", "install", "n8n-nodes-example", "--yes") + if got.code != ExitSuccess { + t.Fatalf("exit code = %d, want %d (stderr: %s)", got.code, ExitSuccess, got.stderr) + } + if strings.Contains(got.stdout, "Blocked") { + t.Errorf("stdout = %q, want no policy lines when the instance evaluated no policy", got.stdout) + } +} + +func TestCommunityPackageInstallPolicyRestrictionsJSON(t *testing.T) { + f := communityPackageFixture(t, strings.TrimSuffix(cliCommunityPackage, "}")+ + `,"policyRestrictions":{"nodeTypes":[{"type":"n8n-nodes-example.example","blockedOn":"instance","optInAvailable":false}]}}`) + got := f.run("community-package", "install", "n8n-nodes-example", "--yes", "--output", "json") + if got.code != ExitSuccess { + t.Fatalf("exit code = %d, want %d (stderr: %s)", got.code, ExitSuccess, got.stderr) + } + if got.stderr != "" { + t.Errorf("stderr = %q, want JSON output to stay quiet", got.stderr) + } + var out struct { + PolicyRestrictions struct { + NodeTypes []map[string]any `json:"nodeTypes"` + } `json:"policyRestrictions"` + } + if err := json.Unmarshal([]byte(got.stdout), &out); err != nil { + t.Fatalf("stdout is not JSON: %v\n%s", err, got.stdout) + } + if len(out.PolicyRestrictions.NodeTypes) != 1 || out.PolicyRestrictions.NodeTypes[0]["blockedOn"] != "instance" { + t.Errorf("policyRestrictions = %+v, want the blocked node type", out.PolicyRestrictions) + } +} + func TestCommunityPackageInstallScopedName(t *testing.T) { f := communityPackageFixture(t, cliCommunityPackage) got := f.run("community-package", "install", "@acme/n8n-nodes-example", "--version", "beta", "--yes") diff --git a/internal/cli/credential.go b/internal/cli/credential.go index fe2dc96..a20e5b1 100644 --- a/internal/cli/credential.go +++ b/internal/cli/credential.go @@ -220,8 +220,9 @@ func newCredentialCreateCommand(opts Options) *cobra.Command { "data; optional fields are projectId, isResolvable, description (plain text, at\n" + "most 512 characters; ignored when the instance has descriptions disabled) and\n" + "id (1 to 16 letters, digits, underscores or hyphens, kept exactly; omit it to\n" + - "have one generated). Because data contains secrets, JSON is accepted only\n" + - "through --file or piped --stdin, never argv.\n\n" + + "have one generated). data fields also accept n8n expressions: strings that\n" + + "start with \"=\". Because data contains secrets, JSON is accepted only through\n" + + "--file or piped --stdin, never argv.\n\n" + "The request body is excluded from debug logs. Output contains metadata only.\n" + "Requires credential:create; project creation can have additional role restrictions.", Example: " n8n credential create --file credential.json\n" + @@ -265,7 +266,8 @@ func newCredentialUpdateCommand(opts Options) *cobra.Command { Long: "Update an owned credential from one JSON document. Accepted fields are name,\n" + "description, type, data, isGlobal, isResolvable and isPartialData. Set\n" + "isPartialData=true to merge provided data with stored data; false replaces the\n" + - "full data object. Changing type requires data. description is at most 512\n" + + "full data object. Changing type requires data. data fields also accept n8n\n" + + "expressions: strings that start with \"=\". description is at most 512\n" + "characters; null or \"\" clears it and omitting it keeps it. Managed credentials\n" + "cannot be edited.\n\n" + "Secret JSON is accepted only through --file or piped --stdin and is excluded from\n" + diff --git a/internal/cli/execution.go b/internal/cli/execution.go index c886d49..f5e3e3d 100644 --- a/internal/cli/execution.go +++ b/internal/cli/execution.go @@ -633,8 +633,10 @@ func newExecutionRetryCommand(opts Options) *cobra.Command { "workflow definition stored with the original execution, making the retry\n" + "reproducible. --latest-workflow instead loads the workflow currently saved on\n" + "the instance.\n\n" + - "The original execution is retained and the response identifies the new run. A\n" + - "run that cannot be retried returns a conflict. This starts workflow work and may\n" + + "The original execution is retained and the response identifies the new run. Its\n" + + "run data, workflowData and customData are absent when the caller cannot read the\n" + + "workflow's executions; the retry still starts. A run that cannot be retried\n" + + "returns a conflict. This starts workflow work and may\n" + "repeat its external side effects. Requires execution:retry.\n\n" + idempotencyHelp, Example: " n8n execution retry EXECUTION_ID\n" + @@ -679,7 +681,13 @@ func runExecutionRetry(ctx context.Context, opts Options, id string, f execution if f.output == outputJSON { return writeJSON(opts.Streams.Out, execution) } - return writeExecutionDetail(opts, resolution, "New execution", execution) + if err := writeExecutionDetail(opts, resolution, "New execution", execution); err != nil { + return err + } + if len(execution.Data) == 0 { + fmt.Fprintf(opts.Streams.Err, "The retry started, but %s returned no run data: the caller cannot read this workflow's executions. Follow it with 'n8n execution get %s' from a user who can.\n", resolution.URL, emptyDash(execution.ID)) + } + return nil } func newExecutionTagCommand(opts Options) *cobra.Command { diff --git a/internal/cli/execution_test.go b/internal/cli/execution_test.go index 48134ce..1ebe43b 100644 --- a/internal/cli/execution_test.go +++ b/internal/cli/execution_test.go @@ -303,6 +303,65 @@ func TestExecutionStopAndRetry(t *testing.T) { t.Errorf("stdout = %q (error: %v)", got.stdout, err) } }) + + t.Run("retry text with run data", func(t *testing.T) { + f := executionFixture(t, cliExecution) + got := f.run("execution", "retry", "1000") + if got.code != ExitSuccess { + t.Fatalf("exit = %d, stderr: %s", got.code, got.stderr) + } + if !strings.Contains(got.stdout, "Data included: true") { + t.Errorf("stdout = %q, want data included", got.stdout) + } + if got.stderr != "" { + t.Errorf("stderr = %q, want empty", got.stderr) + } + }) + + // n8n 2.46+ leaves data, workflowData and customData out when the caller + // cannot read the workflow's executions. + const withoutData = `{"id":"1001","mode":"retry","startedAt":"2026-09-17T10:00:01Z","workflowId":"wf-1","finished":false,"retryOf":"1000","status":"running","storedAt":"db"}` + + t.Run("retry text without run data", func(t *testing.T) { + f := executionFixture(t, withoutData) + got := f.run("execution", "retry", "1000") + if got.code != ExitSuccess { + t.Fatalf("exit = %d, stderr: %s", got.code, got.stderr) + } + for _, want := range []string{"New execution:", "1001", "Retry of:", "1000", "running", "Data included: false"} { + if !strings.Contains(got.stdout, want) { + t.Errorf("stdout missing %q\n%s", want, got.stdout) + } + } + for _, want := range []string{"no run data", "cannot read this workflow's executions", "n8n execution get 1001"} { + if !strings.Contains(got.stderr, want) { + t.Errorf("stderr missing %q\n%s", want, got.stderr) + } + } + }) + + t.Run("retry json without run data", func(t *testing.T) { + f := executionFixture(t, withoutData) + got := f.run("execution", "retry", "1000", "--output", "json") + if got.code != ExitSuccess { + t.Fatalf("exit = %d, stderr: %s", got.code, got.stderr) + } + if got.stderr != "" { + t.Errorf("stderr = %q, want JSON output to stay quiet", got.stderr) + } + var out map[string]json.RawMessage + if err := json.Unmarshal([]byte(got.stdout), &out); err != nil { + t.Fatalf("stdout is not JSON: %v\n%s", err, got.stdout) + } + if string(out["id"]) != `"1001"` { + t.Errorf("id = %s, want \"1001\"", out["id"]) + } + for _, field := range []string{"data", "workflowData", "customData", "annotation"} { + if _, ok := out[field]; ok { + t.Errorf("stdout carries %s = %s, want it absent", field, out[field]) + } + } + }) } func TestExecutionTags(t *testing.T) { diff --git a/internal/cli/workflow.go b/internal/cli/workflow.go index 5ac8e87..15ad2a1 100644 --- a/internal/cli/workflow.go +++ b/internal/cli/workflow.go @@ -354,9 +354,10 @@ func newWorkflowCreateCommand(opts Options) *cobra.Command { "The input may be a document produced by 'n8n workflow get --output json': the\n" + "read-only fields (id, versionId, active, timestamps, tags, sharing, node\n" + "timestamps) and settings set to \"DEFAULT\" are dropped before sending, because\n" + - "the API answers them with 400, and the dropped names are reported on stderr. A\n" + - "null settings is sent as {}. --name, --project-id and --parent-folder-id\n" + - "override what the document says.\n\n" + + "the API answers them with 400, and the dropped names are reported on stderr.\n" + + "settings.engineType is dropped too: n8n ignores it on write and instances\n" + + "before 2.46 reject it. A null settings is sent as {}. --name, --project-id and\n" + + "--parent-folder-id override what the document says.\n\n" + "A created workflow is never published: publish it with 'n8n workflow publish'.\n" + "Requires workflow:create.\n\n" + idempotencyHelp, @@ -472,9 +473,11 @@ func newWorkflowUpdateCommand(opts Options) *cobra.Command { "sharing, node timestamps) and settings set to \"DEFAULT\" are dropped before\n" + "sending and reported on stderr, because the API answers them with 400; an\n" + "omitted setting keeps the instance default, which is what \"DEFAULT\" means.\n" + - "A null settings is sent as {}. Add \"parentFolderId\": \"FOLDER_ID\" to move\n" + - "the workflow into a folder, or \"parentFolderId\": null to move it to the\n" + - "project root; without the field the folder is unchanged.\n\n" + + "settings.engineType is dropped and reported too: n8n ignores it on write and\n" + + "instances before 2.46 reject it. A null settings is sent as {}. Add\n" + + "\"parentFolderId\": \"FOLDER_ID\" to move the workflow into a folder, or\n" + + "\"parentFolderId\": null to move it to the project root; without the field the\n" + + "folder is unchanged.\n\n" + "A published workflow is republished with the new version unless --no-publish is\n" + "given. Republishing additionally needs the workflow:activate scope and the\n" + "project's workflow:publish permission; without them the new version is still\n" + diff --git a/internal/cli/workflow_test.go b/internal/cli/workflow_test.go index 28c8834..3a92727 100644 --- a/internal/cli/workflow_test.go +++ b/internal/cli/workflow_test.go @@ -417,6 +417,51 @@ func TestWorkflowWriteNormalizesReadDocument(t *testing.T) { }) } +// A 2.46 read carries settings.engineType, which the instance ignores on +// write and older instances reject, and settings.redactCallerExecutions, +// which is writable. +func TestWorkflowWriteN8n246Settings(t *testing.T) { + read := strings.Replace(cliWorkflow, `"settings":{"executionOrder":"v1"}`, + `"settings":{"executionOrder":"v1","engineType":"v1","redactCallerExecutions":false}`, 1) + + t.Run("get keeps both", func(t *testing.T) { + f := workflowFixture(t, read) + got := f.run("workflow", "get", "wf-1", "--output", "json") + if got.code != ExitSuccess { + t.Fatalf("exit = %d, stderr: %s", got.code, got.stderr) + } + var out map[string]json.RawMessage + if err := json.Unmarshal([]byte(got.stdout), &out); err != nil { + t.Fatalf("stdout is not JSON: %v", err) + } + assertCLIJSON(t, `{"executionOrder":"v1","engineType":"v1","redactCallerExecutions":false}`, string(out["settings"])) + }) + + for _, args := range [][]string{ + {"workflow", "create"}, + {"workflow", "update", "wf-1"}, + } { + t.Run(args[1], func(t *testing.T) { + f := workflowFixture(t, cliWorkflow) + got := f.run(append(args, "--input", writeWorkflowFile(t, read))...) + if got.code != ExitSuccess { + t.Fatalf("exit = %d, stderr: %s", got.code, got.stderr) + } + var body map[string]json.RawMessage + if err := json.Unmarshal([]byte(f.lastBody()), &body); err != nil { + t.Fatalf("request body is not JSON: %v", err) + } + assertCLIJSON(t, `{"executionOrder":"v1","redactCallerExecutions":false}`, string(body["settings"])) + if !strings.Contains(got.stderr, "settings.engineType") { + t.Errorf("stderr = %q, want settings.engineType reported", got.stderr) + } + if strings.Contains(got.stderr, "redactCallerExecutions") || strings.Contains(got.stderr, "nodes[]") { + t.Errorf("stderr = %q, want only server-owned fields reported", got.stderr) + } + }) + } +} + func TestWorkflowUpdateReplacesDefinition(t *testing.T) { t.Run("input is required", func(t *testing.T) { f := workflowFixture(t, cliWorkflow) diff --git a/internal/n8n/community_package.go b/internal/n8n/community_package.go index fca7015..44345f7 100644 --- a/internal/n8n/community_package.go +++ b/internal/n8n/community_package.go @@ -22,6 +22,34 @@ type CommunityPackage struct { UpdatedAt string `json:"updatedAt,omitempty"` UpdateAvailable string `json:"updateAvailable,omitempty"` FailedLoading bool `json:"failedLoading"` + // PolicyRestrictions is set by install only, and only when the instance + // evaluated its node type policies (they need a license). nil means no + // policy was evaluated; an empty NodeTypes means none blocks this package. + PolicyRestrictions *CommunityPackagePolicyRestrictions `json:"policyRestrictions,omitempty"` +} + +// CommunityPackagePolicyRestrictions lists the node types of a package that a +// node type policy blocks. The install itself does not fail because of them. +type CommunityPackagePolicyRestrictions struct { + NodeTypes []CommunityPackageBlockedNodeType `json:"nodeTypes"` +} + +// Node type policy scopes reported in [CommunityPackageBlockedNodeType.BlockedOn]. +const ( + // BlockedOnInstance means the instance blocks the node type by default. + BlockedOnInstance = "instance" + // BlockedOnProjects means the instance allows the node type but one or + // more projects block it. + BlockedOnProjects = "projects" +) + +// CommunityPackageBlockedNodeType is one blocked node type of a package. +type CommunityPackageBlockedNodeType struct { + Type string `json:"type"` + BlockedOn string `json:"blockedOn"` + // OptInAvailable reports that a project can allow the node type despite + // the instance policy. + OptInAvailable bool `json:"optInAvailable"` } // CommunityPackageNode is one node type supplied by a community package. diff --git a/internal/n8n/community_package_test.go b/internal/n8n/community_package_test.go index b7264f5..d0a9fb5 100644 --- a/internal/n8n/community_package_test.go +++ b/internal/n8n/community_package_test.go @@ -146,6 +146,70 @@ func TestInstallCommunityPackage(t *testing.T) { } } +func TestInstallCommunityPackagePolicyRestrictions(t *testing.T) { + body := strings.TrimSuffix(communityPackageBody, "}") + `,"policyRestrictions":{"nodeTypes":[ + {"type":"n8n-nodes-example.example","blockedOn":"instance","optInAvailable":true}, + {"type":"n8n-nodes-example.other","blockedOn":"projects","optInAvailable":false}]}}` + server := newCommunityPackageServer(t, packageJSONHandler(http.StatusOK, body)) + + installed, err := server.client(t).InstallCommunityPackage(context.Background(), InstallCommunityPackageRequest{Name: "n8n-nodes-example"}) + if err != nil { + t.Fatalf("InstallCommunityPackage: %v", err) + } + want := &CommunityPackagePolicyRestrictions{NodeTypes: []CommunityPackageBlockedNodeType{ + {Type: "n8n-nodes-example.example", BlockedOn: BlockedOnInstance, OptInAvailable: true}, + {Type: "n8n-nodes-example.other", BlockedOn: BlockedOnProjects}, + }} + if diff := cmp.Diff(want, installed.PolicyRestrictions); diff != "" { + t.Errorf("policyRestrictions mismatch (-want +got):\n%s", diff) + } + encoded, err := json.Marshal(installed) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + if !strings.Contains(string(encoded), `"policyRestrictions":{"nodeTypes":[{"type":"n8n-nodes-example.example","blockedOn":"instance","optInAvailable":true}`) { + t.Errorf("encoded package = %s, want policyRestrictions kept", encoded) + } +} + +func TestInstallCommunityPackagePolicyRestrictionsPresence(t *testing.T) { + tests := []struct { + name string + extra string + wantNil bool + wantJSON string + }{ + // Instances without licensed node type policies, and older instances, + // omit the field: it must stay absent in JSON output. + {name: "absent", wantNil: true}, + // An empty list means a policy was evaluated and blocks nothing. + {name: "empty", extra: `,"policyRestrictions":{"nodeTypes":[]}`, wantJSON: `"policyRestrictions":{"nodeTypes":[]}`}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + body := strings.TrimSuffix(communityPackageBody, "}") + tt.extra + "}" + server := newCommunityPackageServer(t, packageJSONHandler(http.StatusOK, body)) + installed, err := server.client(t).InstallCommunityPackage(context.Background(), InstallCommunityPackageRequest{Name: "n8n-nodes-example"}) + if err != nil { + t.Fatalf("InstallCommunityPackage: %v", err) + } + if got := installed.PolicyRestrictions == nil; got != tt.wantNil { + t.Fatalf("PolicyRestrictions nil = %t, want %t", got, tt.wantNil) + } + encoded, err := json.Marshal(installed) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + if tt.wantNil && strings.Contains(string(encoded), "policyRestrictions") { + t.Errorf("encoded package = %s, want no policyRestrictions", encoded) + } + if !tt.wantNil && !strings.Contains(string(encoded), tt.wantJSON) { + t.Errorf("encoded package = %s, want %s", encoded, tt.wantJSON) + } + }) + } +} + func TestInstallCommunityPackageOptionalFields(t *testing.T) { server := newCommunityPackageServer(t, packageJSONHandler(http.StatusOK, communityPackageBody)) _, err := server.client(t).InstallCommunityPackage(context.Background(), InstallCommunityPackageRequest{Name: "n8n-nodes-example"}) diff --git a/internal/n8n/execution.go b/internal/n8n/execution.go index 1142f6e..96aefd2 100644 --- a/internal/n8n/execution.go +++ b/internal/n8n/execution.go @@ -17,7 +17,9 @@ const ExecutionsPath = "/executions" // Execution is one workflow run. Data, WorkflowData and CustomData stay raw: // their shape depends on the workflow and can be large. They are absent unless -// detailed data was requested (except for retry, whose response includes them). +// detailed data was requested. Retry includes them without asking, except when +// the caller cannot read the workflow's executions (n8n 2.46+): then they and +// Annotation are absent. type Execution struct { ID string `json:"id"` Finished bool `json:"finished"` diff --git a/internal/n8n/execution_test.go b/internal/n8n/execution_test.go index 72492d8..cc9839e 100644 --- a/internal/n8n/execution_test.go +++ b/internal/n8n/execution_test.go @@ -2,6 +2,7 @@ package n8n import ( "context" + "encoding/json" "net/http" "strings" "testing" @@ -198,6 +199,34 @@ func TestExecutionRequests(t *testing.T) { } } +// retryWithoutDataResponse is a 2.46+ retry answered to a caller that cannot +// read the workflow's executions: data, workflowData, customData and +// annotation are left out. +const retryWithoutDataResponse = `{"id":"1001","mode":"retry","startedAt":"2026-09-17T10:00:01Z","workflowId":"wf-1","finished":false,"retryOf":"1000","status":"running","storedAt":"db"}` + +func TestRetryExecutionWithoutRunData(t *testing.T) { + server := newCommunityPackageServer(t, packageJSONHandler(http.StatusOK, retryWithoutDataResponse)) + execution, err := server.client(t).RetryExecution(context.Background(), "1000", RetryExecutionOptions{}) + if err != nil { + t.Fatalf("RetryExecution: %v", err) + } + if execution.ID != "1001" || execution.RetryOf == nil || *execution.RetryOf != "1000" || execution.Status != "running" { + t.Errorf("execution = %+v, want the new run", execution) + } + if execution.Data != nil || execution.WorkflowData != nil || execution.CustomData != nil || execution.Annotation != nil { + t.Errorf("execution = %+v, want data, workflowData, customData and annotation absent", execution) + } + encoded, err := json.Marshal(execution) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + for _, field := range []string{`"data"`, `"workflowData"`, `"customData"`, `"annotation"`} { + if strings.Contains(string(encoded), field) { + t.Errorf("encoded execution = %s, want no %s", encoded, field) + } + } +} + func TestExecutionValidationBeforeTransport(t *testing.T) { server := newCommunityPackageServer(t, packageJSONHandler(http.StatusOK, executionResponse)) client := server.client(t) diff --git a/internal/n8n/workflow.go b/internal/n8n/workflow.go index ddbea45..9d71f05 100644 --- a/internal/n8n/workflow.go +++ b/internal/n8n/workflow.go @@ -43,7 +43,16 @@ var ( nullableWorkflowFields = []string{"staticData", "pinData", "parentFolderId"} // readOnlyNodeFields are server-owned timestamps a node may carry on // read; the write schema marks them read-only. + // + // n8n 2.46 stopped returning them, but the write schema still lists them + // and older instances still send them, so they are still stripped. readOnlyNodeFields = []string{"createdAt", "updatedAt"} + // ignoredWorkflowSettings are server-owned settings: n8n 2.46+ returns + // engineType for reference and ignores any value written, while older + // instances reject it as an unknown setting (settings allow no extra keys). + // Dropping it keeps a 2.46 read writable everywhere, e.g. 'workflow copy' + // onto an older instance. redactCallerExecutions is writable and is kept. + ignoredWorkflowSettings = []string{"engineType"} ) // workflowSettingDefault is the read-side value that means "use the instance @@ -88,8 +97,9 @@ func (d WorkflowDocument) Set(field string, value any) error { // names: silently discarding part of a user's document would be worse than the // 400 it prevents. // -// Within the kept fields, settings whose value is "DEFAULT" (reported as -// settings.NAME) and node timestamps (reported as nodes[].createdAt and +// Within the kept fields, settings whose value is "DEFAULT" and the +// server-owned settings.engineType (reported as settings.NAME) and node +// timestamps (reported as nodes[].createdAt and // nodes[].updatedAt) are removed too, and a null settings becomes {}: reads // may carry all three, writes reject them. func (d WorkflowDocument) ForCreate() (WorkflowDocument, []string) { @@ -116,7 +126,7 @@ func (d WorkflowDocument) forWrite(allowed []string) (WorkflowDocument, []string case isJSONNull(raw) && !slices.Contains(nullableWorkflowFields, field): dropped = append(dropped, field) case field == "settings": - settings, removed := withoutDefaultSettings(raw) + settings, removed := withoutReadOnlySettings(raw) kept[field] = settings dropped = append(dropped, removed...) case field == "nodes": @@ -131,11 +141,12 @@ func (d WorkflowDocument) forWrite(allowed []string) (WorkflowDocument, []string return kept, dropped } -// withoutDefaultSettings removes settings whose value is the read-only -// "DEFAULT" marker and returns the removed names as settings.NAME. Settings -// that are not an object are returned unchanged for the server to judge; so -// are settings with nothing to remove, byte for byte. -func withoutDefaultSettings(raw json.RawMessage) (json.RawMessage, []string) { +// withoutReadOnlySettings removes settings whose value is the read-only +// "DEFAULT" marker, and the server-owned [ignoredWorkflowSettings] whatever +// their value, and returns the removed names as settings.NAME. Settings that +// are not an object are returned unchanged for the server to judge; so are +// settings with nothing to remove, byte for byte. +func withoutReadOnlySettings(raw json.RawMessage) (json.RawMessage, []string) { var settings map[string]json.RawMessage if err := json.Unmarshal(raw, &settings); err != nil { return raw, nil @@ -143,7 +154,8 @@ func withoutDefaultSettings(raw json.RawMessage) (json.RawMessage, []string) { var removed []string for name, value := range settings { var text string - if json.Unmarshal(value, &text) == nil && text == workflowSettingDefault { + if slices.Contains(ignoredWorkflowSettings, name) || + (json.Unmarshal(value, &text) == nil && text == workflowSettingDefault) { delete(settings, name) removed = append(removed, "settings."+name) } diff --git a/internal/n8n/workflow_test.go b/internal/n8n/workflow_test.go index d7eafea..353adec 100644 --- a/internal/n8n/workflow_test.go +++ b/internal/n8n/workflow_test.go @@ -306,6 +306,64 @@ func TestWorkflowDocumentForWriteNormalizesReadShapes(t *testing.T) { } } +// n8n 2.46 added settings.engineType (server-owned, ignored on write) and +// settings.redactCallerExecutions (writable), and stopped returning node +// timestamps. +func TestWorkflowSettingsFromN8n246(t *testing.T) { + const read = `{"id":"wf-1","name":"x","active":false,"isArchived":false,` + + `"nodes":[{"id":"n-1","name":"Webhook"}],"connections":{},` + + `"settings":{"executionOrder":"v1","engineType":"v1","redactCallerExecutions":false}}` + var workflow Workflow + if err := json.Unmarshal([]byte(read), &workflow); err != nil { + t.Fatalf("decode: %v", err) + } + encoded, err := json.Marshal(workflow) + if err != nil { + t.Fatalf("encode: %v", err) + } + var out map[string]json.RawMessage + if err := json.Unmarshal(encoded, &out); err != nil { + t.Fatalf("decode re-encoded: %v", err) + } + assertJSONEqual(t, `{"executionOrder":"v1","engineType":"v1","redactCallerExecutions":false}`, string(out["settings"])) + assertJSONEqual(t, `[{"id":"n-1","name":"Webhook"}]`, string(out["nodes"])) + + doc, err := workflow.Document() + if err != nil { + t.Fatalf("Document: %v", err) + } + for name, forWrite := range map[string]func() (WorkflowDocument, []string){ + "create": doc.ForCreate, + "update": doc.ForUpdate, + } { + t.Run(name, func(t *testing.T) { + kept, dropped := forWrite() + if slices.Contains(dropped, "nodes[].createdAt") || slices.Contains(dropped, "nodes[].updatedAt") { + t.Errorf("dropped = %v, want no node timestamps when the instance sent none", dropped) + } + if !slices.Contains(dropped, "settings.engineType") { + t.Errorf("dropped = %v, want settings.engineType reported", dropped) + } + assertJSONEqual(t, `{"executionOrder":"v1","redactCallerExecutions":false}`, string(kept["settings"])) + assertJSONEqual(t, `[{"id":"n-1","name":"Webhook"}]`, string(kept["nodes"])) + }) + } +} + +func TestWorkflowDocumentEngineTypeAnyValue(t *testing.T) { + for name, value := range map[string]string{"string": `"v2"`, "null": `null`} { + t.Run(name, func(t *testing.T) { + doc := writeDocument() + doc["settings"] = json.RawMessage(`{"engineType":` + value + `,"redactCallerExecutions":true}`) + kept, dropped := doc.ForUpdate() + if !slices.Equal(dropped, []string{"settings.engineType"}) { + t.Errorf("dropped = %v, want [settings.engineType]", dropped) + } + assertJSONEqual(t, `{"redactCallerExecutions":true}`, string(kept["settings"])) + }) + } +} + func TestWorkflowParentFolderID(t *testing.T) { for name, tt := range map[string]struct { body string