Files
windmill/backend/tests/fixtures/job_provenance_versions.sql
60d07dc0d9 fix: issue oidc tokens to a deployed flow's dynamic select (#12046)
* fix: issue oidc tokens to a deployed flow's dynamic select

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: leave dyn select previews on a dedicated worker unproven

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: match every dedicated worker tag shape in the dyn select check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: cover hashed dedicated worker tags of long workspace ids

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep a flow dyn select claimed when a script or app shares its sub

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
2026-10-28 01:28:43 +01:00

114 lines
10 KiB
SQL

-- Add-on fixture for job_provenance.rs (combine with `base.sql` and `job_provenance.sql`):
-- past versions of f/t/tool and f/t/agent, a deleted version of f/t/tool, and flow steps
-- of f/t/agent under a regular run and under restarts.
INSERT INTO script (workspace_id, hash, path, content, language, kind, created_by, schema, summary, description, lock, created_at, archived)
VALUES ('test-workspace', 1111111110, 'f/t/tool', 'echo old tool', 'bash', 'script', 'test-user', '{}', '', '', '', NOW() - interval '1 day', true);
INSERT INTO script (workspace_id, hash, path, content, language, kind, created_by, schema, summary, description, lock, created_at, archived, deleted)
VALUES ('test-workspace', 1111111109, 'f/t/tool', '', 'bash', 'script', 'test-user', '{}', '', '', '', NOW() - interval '2 days', true, true);
INSERT INTO flow_version (id, workspace_id, path, value, schema, created_by, created_at)
VALUES (2222222221, 'test-workspace', 'f/t/agent', '{"modules":[]}', '{}', 'test-user', NOW() - interval '1 day');
UPDATE flow SET versions = ARRAY[2222222221::bigint, 2222222222::bigint]
WHERE workspace_id = 'test-workspace' AND path = 'f/t/agent';
INSERT INTO v2_job (id, workspace_id, kind, runnable_path, runnable_id, parent_job, created_by, permissioned_as, permissioned_as_email)
VALUES
-- the past tool version, run under the current flow version
('3bb0c0de-0000-4000-8000-000000000101', 'test-workspace', 'script', 'f/t/tool', 1111111110, '3bb0c0de-0000-4000-8000-000000000001', 'test-user', 'u/test-user', 'test@windmill.dev'),
-- the current tool version, run under the past flow version
('3bb0c0de-0000-4000-8000-000000000102', 'test-workspace', 'flow', 'f/t/agent', 2222222221, NULL, 'test-user', 'u/test-user', 'test@windmill.dev'),
('3bb0c0de-0000-4000-8000-000000000103', 'test-workspace', 'script', 'f/t/tool', 1111111111, '3bb0c0de-0000-4000-8000-000000000102', 'test-user', 'u/test-user', 'test@windmill.dev'),
-- the deleted tool version
('3bb0c0de-0000-4000-8000-000000000104', 'test-workspace', 'script', 'f/t/tool', 1111111109, NULL, 'test-user', 'u/test-user', 'test@windmill.dev'),
-- under the current flow version: an inline step, a loop body and a step of that body
('3bb0c0de-0000-4000-8000-000000000105', 'test-workspace', 'flowscript', 'f/t/agent/a', 4444444442, '3bb0c0de-0000-4000-8000-000000000001', 'test-user', 'u/test-user', 'test@windmill.dev'),
('3bb0c0de-0000-4000-8000-000000000106', 'test-workspace', 'flownode', 'f/t/agent/loop-0', 4444444444, '3bb0c0de-0000-4000-8000-000000000001', 'test-user', 'u/test-user', 'test@windmill.dev'),
('3bb0c0de-0000-4000-8000-000000000107', 'test-workspace', 'flowscript', 'f/t/agent/loop-0/b', 4444444446, '3bb0c0de-0000-4000-8000-000000000106', 'test-user', 'u/test-user', 'test@windmill.dev'),
-- an inline step under the past flow version
('3bb0c0de-0000-4000-8000-000000000108', 'test-workspace', 'flowscript', 'f/t/agent/a', 4444444441, '3bb0c0de-0000-4000-8000-000000000102', 'test-user', 'u/test-user', 'test@windmill.dev'),
-- a loop body restarted on its own, and a step of it
('3bb0c0de-0000-4000-8000-000000000109', 'test-workspace', 'flownode', 'f/t/agent/loop-0', 4444444443, NULL, 'test-user', 'u/test-user', 'test@windmill.dev'),
('3bb0c0de-0000-4000-8000-000000000110', 'test-workspace', 'flowscript', 'f/t/agent/loop-0/b', 4444444449, '3bb0c0de-0000-4000-8000-000000000109', 'test-user', 'u/test-user', 'test@windmill.dev'),
-- a body kept by a nested restart under the current flow version, and a step of it
('3bb0c0de-0000-4000-8000-000000000111', 'test-workspace', 'flownode', 'f/t/agent/branchone-1', 4444444445, '3bb0c0de-0000-4000-8000-000000000001', 'test-user', 'u/test-user', 'test@windmill.dev'),
('3bb0c0de-0000-4000-8000-000000000112', 'test-workspace', 'flowscript', 'f/t/agent/branchone-1/c', 4444444447, '3bb0c0de-0000-4000-8000-000000000111', 'test-user', 'u/test-user', 'test@windmill.dev');
-- An inline body (a flow deployed before flow nodes runs it as a preview) kept by a nested
-- restart under the current flow version, and a step of it.
INSERT INTO v2_job (id, workspace_id, kind, runnable_path, parent_job, created_by, permissioned_as, permissioned_as_email)
VALUES
('3bb0c0de-0000-4000-8000-000000000113', 'test-workspace', 'flowpreview', 'f/t/agent/branchone-0', '3bb0c0de-0000-4000-8000-000000000001', 'test-user', 'u/test-user', 'test@windmill.dev'),
('3bb0c0de-0000-4000-8000-000000000114', 'test-workspace', 'preview', 'f/t/agent/branchone-0/c', '3bb0c0de-0000-4000-8000-000000000113', 'test-user', 'u/test-user', 'test@windmill.dev');
-- The restarted bodies: two still running, one completed.
INSERT INTO v2_job_queue (id, workspace_id, scheduled_for, running)
VALUES
('3bb0c0de-0000-4000-8000-000000000111', 'test-workspace', NOW(), true),
('3bb0c0de-0000-4000-8000-000000000113', 'test-workspace', NOW(), true);
INSERT INTO v2_job_status (id, flow_status)
VALUES
('3bb0c0de-0000-4000-8000-000000000111',
'{"restarted_from": {"flow_job_id": "3bb0c0de-0000-4000-8000-0000000000ff", "step_id": "br"}}'),
('3bb0c0de-0000-4000-8000-000000000113',
'{"restarted_from": {"flow_job_id": "3bb0c0de-0000-4000-8000-0000000000fd", "step_id": "br"}}');
INSERT INTO v2_job_completed (id, workspace_id, duration_ms, status, flow_status)
VALUES ('3bb0c0de-0000-4000-8000-000000000109', 'test-workspace', 0, 'success',
'{"restarted_from": {"flow_job_id": "3bb0c0de-0000-4000-8000-0000000000fe", "step_id": "l"}}');
-- Loop bodies restarted on their own from completed runs: one of the current flow version,
-- one of the past version, and one that was itself a restart; with a step of the first.
INSERT INTO v2_job (id, workspace_id, kind, runnable_path, runnable_id, parent_job, created_by, permissioned_as, permissioned_as_email)
VALUES
('3bb0c0de-0000-4000-8000-000000000115', 'test-workspace', 'flownode', 'f/t/agent/loop-0', 4444444444, '3bb0c0de-0000-4000-8000-000000000001', 'test-user', 'u/test-user', 'test@windmill.dev'),
('3bb0c0de-0000-4000-8000-000000000116', 'test-workspace', 'flownode', 'f/t/agent/loop-0', 4444444444, NULL, 'test-user', 'u/test-user', 'test@windmill.dev'),
('3bb0c0de-0000-4000-8000-000000000117', 'test-workspace', 'flowscript', 'f/t/agent/loop-0/b', 4444444446, '3bb0c0de-0000-4000-8000-000000000116', 'test-user', 'u/test-user', 'test@windmill.dev'),
('3bb0c0de-0000-4000-8000-000000000118', 'test-workspace', 'flownode', 'f/t/agent/loop-0', 4444444443, '3bb0c0de-0000-4000-8000-000000000102', 'test-user', 'u/test-user', 'test@windmill.dev'),
('3bb0c0de-0000-4000-8000-000000000119', 'test-workspace', 'flownode', 'f/t/agent/loop-0', 4444444443, NULL, 'test-user', 'u/test-user', 'test@windmill.dev'),
('3bb0c0de-0000-4000-8000-000000000120', 'test-workspace', 'flownode', 'f/t/agent/loop-0', 4444444443, NULL, 'test-user', 'u/test-user', 'test@windmill.dev');
INSERT INTO v2_job_completed (id, workspace_id, duration_ms, status)
VALUES
('3bb0c0de-0000-4000-8000-000000000115', 'test-workspace', 0, 'success'),
('3bb0c0de-0000-4000-8000-000000000118', 'test-workspace', 0, 'success');
INSERT INTO v2_job_queue (id, workspace_id, scheduled_for, running)
VALUES
('3bb0c0de-0000-4000-8000-000000000116', 'test-workspace', NOW(), true),
('3bb0c0de-0000-4000-8000-000000000119', 'test-workspace', NOW(), true),
('3bb0c0de-0000-4000-8000-000000000120', 'test-workspace', NOW(), true);
INSERT INTO v2_job_status (id, flow_status)
VALUES
('3bb0c0de-0000-4000-8000-000000000116',
'{"restarted_from": {"flow_job_id": "3bb0c0de-0000-4000-8000-000000000115", "step_id": "b"}}'),
('3bb0c0de-0000-4000-8000-000000000119',
'{"restarted_from": {"flow_job_id": "3bb0c0de-0000-4000-8000-000000000118", "step_id": "b"}}'),
('3bb0c0de-0000-4000-8000-000000000120',
'{"restarted_from": {"flow_job_id": "3bb0c0de-0000-4000-8000-000000000109", "step_id": "b"}}');
-- Dynamic selects of f/t/agent, run as parentless previews at its path: the current and the
-- past version's code, then the current code altered by what `run/preview` lets a caller set
-- (a script hash, a lock, temp script refs) and code no version has.
UPDATE flow_version SET schema = json_build_object('x-windmill-dyn-select-code',
'export function f() { return ' || id || ' }', 'x-windmill-dyn-select-lang', 'bun')
WHERE workspace_id = 'test-workspace' AND path = 'f/t/agent';
INSERT INTO v2_job (id, workspace_id, kind, runnable_path, runnable_id, raw_code, raw_lock, script_lang, args, created_by, permissioned_as, permissioned_as_email)
VALUES
('3bb0c0de-0000-4000-8000-000000000201', 'test-workspace', 'preview', 'f/t/agent', NULL, 'export function f() { return 2222222222 }', NULL, 'bun', '{"_ENTRYPOINT_OVERRIDE": "f"}', 'test-user', 'u/test-user', 'test@windmill.dev'),
('3bb0c0de-0000-4000-8000-000000000202', 'test-workspace', 'preview', 'f/t/agent', NULL, 'export function f() { return 2222222221 }', NULL, 'bun', NULL, 'test-user', 'u/test-user', 'test@windmill.dev'),
('3bb0c0de-0000-4000-8000-000000000203', 'test-workspace', 'preview', 'f/t/agent', 1111111111, 'export function f() { return 2222222222 }', NULL, 'bun', NULL, 'test-user', 'u/test-user', 'test@windmill.dev'),
('3bb0c0de-0000-4000-8000-000000000204', 'test-workspace', 'preview', 'f/t/agent', NULL, 'export function f() { return 2222222222 }', '{}', 'bun', NULL, 'test-user', 'u/test-user', 'test@windmill.dev'),
('3bb0c0de-0000-4000-8000-000000000205', 'test-workspace', 'preview', 'f/t/agent', NULL, 'export function f() { return 2222222222 }', NULL, 'bun', '{"_TEMP_SCRIPT_REFS": {}}', 'test-user', 'u/test-user', 'test@windmill.dev'),
('3bb0c0de-0000-4000-8000-000000000206', 'test-workspace', 'preview', 'f/t/agent', NULL, 'export function f() { return 1 }', NULL, 'bun', NULL, 'test-user', 'u/test-user', 'test@windmill.dev');
-- The current code routed to a dedicated worker (its tag hashed, as long ones are), which
-- runs its own script.
INSERT INTO v2_job (id, workspace_id, kind, runnable_path, raw_code, script_lang, tag, created_by, permissioned_as, permissioned_as_email)
VALUES ('3bb0c0de-0000-4000-8000-000000000207', 'test-workspace', 'preview', 'f/t/agent', 'export function f() { return 2222222222 }', 'bun', 'test-workspace:f/t/agent#0123456789', 'test-user', 'u/test-user', 'test@windmill.dev');