Clarify Workflow ownership confirmation for standalone trigger deployment

Open
#16,858 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
nodejs, typescript
Domain
cli, cloud

Research direction

Start with packages/deploy-helpers/src/triggers/deploy.ts, which updates declared Workflows without calling checkWorkflowConflicts(), and compare it with check-workflow-conflicts.ts and validate-worker-props.ts. Run the offline repro script in the issue to see the unguarded PUT. Done means a maintainer decides the ownership policy; if the check is added, the repro's assertions must change to expect a Workflow GET and the conflict handling.

Written by the indexing model from the issue text.

Description

package:deploy-helpers product:workflows question
Summary of the issue

Should cf workers triggers deploy --prebuilt apply the same Workflow ownership confirmation policy as the regular upload preflight? The two paths currently handle an ownership conflict differently.

In an offline API fixture where shared-workflow belongs to other-worker, the standalone trigger command sends PUT /accounts/example-account/workflows/shared-workflow with script_name: "target-worker" and exits successfully without reading the Workflow's current owner or showing an ownership warning.

The existing checkWorkflowConflicts() helper detects the same fixture as a conflict. The regular upload preflight calls that helper; the standalone trigger path does not.

This establishes a difference in client-side checks. I could not find a documented confirmation policy for the standalone command, so I am asking whether this difference is intentional. All reproduction responses are mocked; live reassignment and server-side authorization behavior have not been tested.

Expected behaviour

Please clarify the intended ownership-confirmation policy for standalone trigger deployment. Applying the existing remote ownership check and an explicit continuation/abort decision would make it consistent with the upload preflight and help prevent accidental reassignment.

If applying the configured ownership without confirmation is intentional for this command, please document that behavior so callers can account for it.

Version of cf used

1.0.0-beta.29 (npm release). Also reproduced directly with @cloudflare/[email protected].

System information and package versions

Sanitized environment information (executable paths omitted):

System:
  OS: Windows 11 10.0.26300
  CPU: (16) x64 AMD Ryzen 7 PRO 8840U
Binaries:
  Node: 26.13.0
  npm: 11.20.0
npmPackages:
  cf: 1.0.0-beta.29
  @cloudflare/deploy-helpers: 0.26.2
  @cloudflare/workers-utils: 0.53.0
Reproduction (optional)

The following reproduces the actual command handler using Build Output and an HTTP mock with network access disabled. No Cloudflare account, token, or live resource is needed. The dummy token is used only by the mocked requests.

In an empty directory:

npm install --ignore-scripts [email protected] [email protected]
node repro.mjs

Save as repro.mjs:

import assert from 'node:assert/strict';
import { mkdtempSync, mkdirSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { MockAgent, setGlobalDispatcher } from 'undici';

// All HTTP requests must match this mock. No real API request is allowed.
const mock = new MockAgent();
mock.disableNetConnect();
setGlobalDispatcher(mock);
globalThis.fetch = async () => { throw new Error('Network disabled'); };
const calls = [];
mock.get('https://api.cloudflare.com').intercept({
  path: () => true, method: /GET|POST|PUT|PATCH|DELETE/,
}).reply(({ method, path, body }) => {
  calls.push({ method, path, ...(body ? { body: JSON.parse(body) } : {}) });
  let result;
  if (path === '/client/v4/accounts/example-account/workflows/shared-workflow') {
    result = method === 'GET'
      ? { name: 'shared-workflow', script_name: 'other-worker', class_name: 'OldClass' }
      : {};
  } else if (path === '/client/v4/accounts/example-account/workers/workers/target-worker') {
    result = { subdomain: { enabled: false, previews_enabled: false } };
  } else if (path === '/client/v4/accounts/example-account/workers/scripts/target-worker/subdomain' && method === 'POST') {
    result = { enabled: false, previews_enabled: false };
  } else if (path === '/client/v4/accounts/example-account/workers/subdomain') {
    result = { subdomain: 'example-subdomain' };
  } else throw new Error('Unexpected mocked request: ' + method + ' ' + path);
  return { statusCode: 200, data: JSON.stringify({ success: true, errors: [], messages: [], result }), responseOptions: { headers: { 'content-type': 'application/json' } } };
}).persist();

Object.assign(process.env, {
  CLOUDFLARE_API_TOKEN: 'offline-example-token', CLOUDFLARE_ACCOUNT_ID: 'example-account',
  CLOUDFLARE_SEND_METRICS: 'false', CLOUDFLARE_TELEMETRY_DISABLED: '1', CI: 'true',
});
const fixture = mkdtempSync(join(tmpdir(), 'cf-trigger-offline-'));
const output = join(fixture, '.cloudflare/output/v0');
const worker = join(output, 'workers/default');
mkdirSync(join(worker, 'bundle'), { recursive: true });
writeFileSync(join(output, 'config.json'), JSON.stringify({ accountId: 'example-account', buildContext: { isPreview: false } }));
writeFileSync(join(worker, 'worker.config.json'), JSON.stringify({
  name: 'target-worker', compatibilityDate: '2026-11-01', workersDev: false, previewUrls: false,
  exports: { NewClass: { type: 'workflow', name: 'shared-workflow' } },
  manifest: { type: 'complete', mainModule: 'index.js', modules: { 'index.js': { type: 'esm' } } },
}));
writeFileSync(join(worker, 'bundle/index.js'), 'export default {};');
process.chdir(fixture);
const { runMain } = await import('cf');
await runMain(['workers', 'triggers', 'deploy', '--prebuilt']);

assert.equal(calls.some(c => c.method === 'GET' && c.path.endsWith('/workflows/shared-workflow')), false);
assert.deepEqual(calls.at(-1), {
  method: 'PUT', path: '/client/v4/accounts/example-account/workflows/shared-workflow',
  body: { script_name: 'target-worker', class_name: 'NewClass' },
});
console.log(JSON.stringify({ offline: true, calls }, null, 2));
await mock.close();

The script succeeds and asserts that the Workflow PUT occurred without a preceding Workflow GET. If the existing ownership check is added to this path, the assertions intentionally need to change.

Relevant source:

Relevant error logs (optional)

No error is emitted in the mocked run:

Deploy triggers
Deployed target-worker triggers
  workflow: shared-workflow
Trigger deploy complete

Recorded API sequence:

GET  /accounts/example-account/workers/workers/target-worker
POST /accounts/example-account/workers/scripts/target-worker/subdomain
GET  /accounts/example-account/workers/subdomain
PUT  /accounts/example-account/workflows/shared-workflow
     {"script_name":"target-worker","class_name":"NewClass"}
Dominant language
TypeScript
Stars
4.7k
Forks
1.7k
Avg merge
1d 22h
Merged PRs (30d)
282

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cloudflare/workers-sdk

All issues in cloudflare/workers-sdk

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.