mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-18 16:02:10 +00:00
81b23a2ba0
* feat: make the fork lineage the only deploy relationship `workspace_settings.deploy_to` (2023) and `workspace.parent_workspace_id` (2025) both expressed "which workspace does this one deploy into". Fork creation and dev-workspace attach seeded both, but nothing kept them in agreement, so every reader picked one and they disagreed. Drop `deploy_to`. A migration folds surviving pairs into the lineage: a sole claimant on a target with no dev workspace becomes that target's dev workspace and keeps its own job tags, while many-to-one pairs become plain forks. Pairs that the lineage cannot express -- dangling target, self-reference, chain, mutual -- are reported and left unlinked. Job tags were never lineage-aware: `per_workspace_tag` mapped any parented workspace to its parent while `$workspace` interpolated the raw id, so a fork running a script tagged `<tag>-$workspace` produced a tag no worker serves and the job queued forever. Both paths now resolve to the nearest ancestor whose id an admin would provision workers for. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: preserve unconvertible deploy links and sweep tag caches on reparent Review findings on the deploy_to unification: - convert chains instead of discarding them, and keep whatever the lineage cannot express in workspace_deploy_to_unmigrated so the down migration can restore it - ignore soft-deleted workspaces when choosing between a dev workspace and a plain fork; an archived claimant was demoting live pairs - mirror attach_dev_workspace's git-sync strip, which the migration skipped - sweep the tag cache over whole subtrees on rename and delete: tag resolution now walks ancestors, so a nested fork kept a tag nothing serves - call a dev workspace a dev workspace in the settings copy - redirect a root away from ?tab=deploy_to instead of rendering an empty target Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: detect lineage cycles and record archived links in the deploy_to migration Second review round on the unification: - detect cycles over the lineage as it would exist after conversion, not over the deploy_to graph alone: a root whose target was one of its own forks closed a loop that no deploy_to edge revealed - record an archived source's link instead of filtering it out entirely, which dropped it with the column - treat a fork whose deploy_to merely repeats its parent as redundant rather than reporting every pre-existing fork as unmigrated - read the row count from the lineage update rather than the git-sync one - sweep the tag cache when archiving a dev workspace, the last site that mutates is_dev_workspace without one Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: resolve $workspace on preprocessed flow tags regardless of $args Third review round on the unification: - a flow tag containing only `$workspace` skipped interpolation entirely on the preprocessed path, because the branch that ran it keys on `$args`. The raw tag was written back and named a queue no worker serves. Resolve `$workspace` before the branch and leave `$args` to it. - record the new table's foreign key in the schema summary - describe what the archive tag sweep actually does: the dev flag is cleared for any archived workspace, which is why it is unconditional Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: keep the deploy_to leftovers table only when it holds something * fix: sweep tag caches on archive only where the dev flag actually changes * feat: broadcast lineage changes and walk ws_specific ancestors only - propagate tag-cache invalidation across processes over notify_events: the cache is per-process, so replicas kept resolving stale lineage for the TTL. The listener clears the whole cache rather than tracking ids, since a single mutation invalidates an unbounded set of descendants and lineage changes are rare admin actions. - narrow list_ws_specific_versions to ancestors: walking down as well made a root fan out over its entire live fork subtree, and each member costs an identity lookup plus an RLS switch and probe. Ancestors are bounded by the fork depth limit. - probe the leftovers table unqualified so rollback restores on a PG_SCHEMA install, where search_path is not public - drop the nativets client method for the removed edit_deploy_to endpoint Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: let a prod see its dev workspace in ws_specific, and stop the walk oscillating Descending into plain forks made a root fan out over its whole live fork subtree, but a dev workspace is the paired editable environment rather than a throwaway copy, so a prod should still see it. There is at most one per parent and attach rejects nested dev chains, so that edge stays bounded. The edges run both ways, so the recursion never converged: it bounced parent<->dev until the depth cap on every call, 33 rows for a two-member set. A visited-path guard ends the walk when nothing new is reachable. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: keep dev pairings unnested, gate the delete broadcast, cover the ws_specific walk Fifth review round: - a root that already owns a dev workspace no longer converts: linking it under its deploy target would leave that dev nested beneath a fork, the shape attach_dev_workspace refuses to create. The link is preserved instead. - broadcast a lineage change on delete only when descendants are orphaned. Deleting a leaf, which ephemeral fork churn does constantly, changes nobody else's resolution and was making every replica drop its whole tag cache. - call list_ws_specific_versions in a test. plpgsql defers everything past a raw parse to the first call, so replaying the migration only proved it parses. - use unwrap_or_default for the descendant sweeps, which run after the transaction has committed; a transient failure must not fail the request - trim the traversal comment to the four-line limit Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: cache the renamed tally query and clear instance alerts on conversion The integration test's query was never cached: `cargo sqlx prepare` without --all-targets skips test targets entirely, and renaming its fixture workspace changed the query text. Regenerated with --all-targets --features all_sqlx_features,private, which is what lets the EE-gated otel test compile. Also from review: - clear error_handler_fallback_to_instance_alerts on converted workspaces. Dispatch ignores it once a parent exists, but the settings page keeps submitting the stored true, which the API rejects on a fork. - restore the schema summary row to the file's name: columns format and put it back in alphabetical order Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: never cache an unresolvable tag workspace, and unadvertise the removed endpoint - lookup_tag_workspace cached a "no row" result as self-resolution. A rename resolves the new id before its row lands, so a fork could be pinned to its own wm-fork-* id -- which nothing serves -- for the whole TTL, and its schedules kept re-pushing onto that dead tag. Fall back for the call without caching, matching how the error path already behaved. - change_workspace_id swept its children but never itself. Sweep the new and old ids and broadcast unconditionally, since a rename always changes lineage. - openapi-deref.{json,yaml} are served to clients via include_str!, so they were advertising edit_deploy_to after it started 404ing. The audit-action enum keeps the entry: historical rows still carry it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: align the served YAML spec with the JSON one and correct two comments - the YAML deref lost the removed path but kept deploy_to on get_settings, so the two served specs disagreed. Both are now identical. - the rename-sweep comment blamed cached-unresolvable lookups, which the same commit stopped caching. The real reason is that workspace ids are reclaimable, so a new id can carry a previous occupant's resolution. - the instance-alert comment claimed the settings page submits the stored true and gets a 400. It hides the option on a fork and sends false; the hazard is the value outliving the pairing and re-enabling alerts after a detach. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * chore: update ee-repo-ref to 82da6cb2bafeda18acd6b70c599013a12117ecb0 This commit updates the EE repository reference after PR #694 was merged in windmill-ee-private. Previous ee-repo-ref: f9ddf6a75aa13d1c13a3d7216a361a96f75ca435 New ee-repo-ref: 82da6cb2bafeda18acd6b70c599013a12117ecb0 Automated by sync-ee-ref workflow. * fix: grant the deploy_to preservation table to the windmill roles * test: drop the one-shot migration tests, keep the ws_specific execution guard The two conversion tests replayed the migration against the fully-migrated schema, which is not how it runs -- in production it runs mid-sequence against the schema as of that point. A later migration touching workspace or workspace_settings would break them without breaking anything real, and sqlx checksums already freeze a released migration. They earned their keep finding the archived-claimant and nested-dev cases during development; there is nothing left for them to guard. list_ws_specific_versions is different: it is live, no caller exercises it, and plpgsql only parses a function body until first call. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * fix: invalidate a reclaimed fork id cluster-wide without flushing every entry Gating the delete broadcast on orphaned descendants stopped leaf churn flushing every replica, but fork ids are reclaimable: the deleting process invalidated locally while every other replica kept the old parent for the TTL, so a job pushed in a recreated fork routed to the previous parent's tag. The broadcast payload now carries meaning. A workspace id drops that one entry, used for leaf deletion where exactly one id changed what it denotes. The `*` sentinel drops everything, used for attach, detach, archive, rename and deletions that orphan descendants -- reshaping a subtree no single id names. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * docs: name the right broadcast for each invalidation case * docs: attach does invalidate the tag cache; the resolver walks the whole chain --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
272 lines
9.2 KiB
TypeScript
272 lines
9.2 KiB
TypeScript
/**
|
|
* Unit tests for settings.ts pure functions.
|
|
* Tests migrateToGroupedFormat which converts legacy flat settings to grouped format.
|
|
*/
|
|
|
|
import { expect, test, describe } from "bun:test";
|
|
import { migrateToGroupedFormat } from "../src/core/settings.ts";
|
|
|
|
// =============================================================================
|
|
// migrateToGroupedFormat
|
|
// =============================================================================
|
|
|
|
describe("migrateToGroupedFormat", () => {
|
|
test("migrates legacy auto_invite fields to grouped format", () => {
|
|
const legacy = {
|
|
name: "my-workspace",
|
|
auto_invite_enabled: true,
|
|
auto_invite_as: "operator",
|
|
auto_invite_mode: "add",
|
|
};
|
|
const result = migrateToGroupedFormat(legacy);
|
|
expect(result.auto_invite).toEqual({
|
|
enabled: true,
|
|
operator: true,
|
|
mode: "add",
|
|
});
|
|
});
|
|
|
|
test("migrates legacy auto_invite with non-operator role", () => {
|
|
const legacy = {
|
|
name: "ws",
|
|
auto_invite_enabled: true,
|
|
auto_invite_as: "developer",
|
|
auto_invite_mode: "invite",
|
|
};
|
|
const result = migrateToGroupedFormat(legacy);
|
|
expect(result.auto_invite).toEqual({
|
|
enabled: true,
|
|
operator: false,
|
|
mode: "invite",
|
|
});
|
|
});
|
|
|
|
test("migrates legacy auto_invite when disabled", () => {
|
|
const legacy = {
|
|
name: "ws",
|
|
auto_invite_enabled: false,
|
|
auto_invite_as: "operator",
|
|
};
|
|
const result = migrateToGroupedFormat(legacy);
|
|
expect(result.auto_invite!.enabled).toBe(false);
|
|
});
|
|
|
|
test("preserves already-grouped auto_invite", () => {
|
|
const grouped = {
|
|
name: "ws",
|
|
auto_invite: { enabled: true, operator: false, mode: "invite" as const },
|
|
};
|
|
const result = migrateToGroupedFormat(grouped);
|
|
expect(result.auto_invite).toEqual({
|
|
enabled: true,
|
|
operator: false,
|
|
mode: "invite",
|
|
});
|
|
});
|
|
|
|
test("migrates legacy error_handler string to grouped format", () => {
|
|
const legacy = {
|
|
name: "ws",
|
|
error_handler: "u/admin/error_handler",
|
|
error_handler_extra_args: { notify: true },
|
|
error_handler_muted_on_cancel: true,
|
|
};
|
|
const result = migrateToGroupedFormat(legacy);
|
|
expect(result.error_handler).toEqual({
|
|
path: "u/admin/error_handler",
|
|
extra_args: { notify: true },
|
|
muted_on_cancel: true,
|
|
});
|
|
});
|
|
|
|
test("preserves already-grouped error_handler", () => {
|
|
const grouped = {
|
|
name: "ws",
|
|
error_handler: {
|
|
path: "u/admin/handler",
|
|
extra_args: {},
|
|
muted_on_cancel: false,
|
|
},
|
|
};
|
|
const result = migrateToGroupedFormat(grouped);
|
|
expect(result.error_handler).toEqual({
|
|
path: "u/admin/handler",
|
|
extra_args: {},
|
|
muted_on_cancel: false,
|
|
});
|
|
});
|
|
|
|
test("migrates legacy success_handler string to grouped format", () => {
|
|
const legacy = {
|
|
name: "ws",
|
|
success_handler: "u/admin/on_success",
|
|
success_handler_extra_args: { channel: "#deploys" },
|
|
};
|
|
const result = migrateToGroupedFormat(legacy);
|
|
expect(result.success_handler).toEqual({
|
|
path: "u/admin/on_success",
|
|
extra_args: { channel: "#deploys" },
|
|
});
|
|
});
|
|
|
|
test("preserves already-grouped success_handler", () => {
|
|
const grouped = {
|
|
name: "ws",
|
|
success_handler: { path: "u/admin/handler", extra_args: {} },
|
|
};
|
|
const result = migrateToGroupedFormat(grouped);
|
|
expect(result.success_handler).toEqual({
|
|
path: "u/admin/handler",
|
|
extra_args: {},
|
|
});
|
|
});
|
|
|
|
test("copies non-legacy fields through", () => {
|
|
const settings = {
|
|
name: "my-workspace",
|
|
webhook: "https://example.com/hook",
|
|
// Older settings files still carry deploy_to; it is no longer a setting and must be dropped.
|
|
deploy_to: "staging",
|
|
default_app: "u/admin/dashboard",
|
|
mute_critical_alerts: true,
|
|
color: "#ff0000",
|
|
};
|
|
const result = migrateToGroupedFormat(settings);
|
|
expect(result.name).toBe("my-workspace");
|
|
expect(result.webhook).toBe("https://example.com/hook");
|
|
expect("deploy_to" in result).toBe(false);
|
|
expect(result.default_app).toBe("u/admin/dashboard");
|
|
expect(result.mute_critical_alerts).toBe(true);
|
|
expect(result.color).toBe("#ff0000");
|
|
});
|
|
|
|
test("handles minimal settings with only name", () => {
|
|
const result = migrateToGroupedFormat({ name: "ws" });
|
|
expect(result.name).toBe("ws");
|
|
expect(result.auto_invite).toBeUndefined();
|
|
expect(result.error_handler).toBeUndefined();
|
|
expect(result.success_handler).toBeUndefined();
|
|
});
|
|
|
|
test("defaults name to empty string when missing", () => {
|
|
const result = migrateToGroupedFormat({});
|
|
expect(result.name).toBe("");
|
|
});
|
|
|
|
test("defaults auto_invite_mode to invite when missing", () => {
|
|
const legacy = {
|
|
name: "ws",
|
|
auto_invite_enabled: true,
|
|
auto_invite_as: "operator",
|
|
};
|
|
const result = migrateToGroupedFormat(legacy);
|
|
expect(result.auto_invite!.mode).toBe("invite");
|
|
});
|
|
|
|
test("defaults error_handler_muted_on_cancel to false when missing", () => {
|
|
const legacy = {
|
|
name: "ws",
|
|
error_handler: "u/admin/handler",
|
|
};
|
|
const result = migrateToGroupedFormat(legacy);
|
|
expect(result.error_handler!.muted_on_cancel).toBe(false);
|
|
});
|
|
|
|
test("preserves ai_config, large_file_storage, git_sync, default_scripts, operator_settings", () => {
|
|
const settings = {
|
|
name: "ws",
|
|
ai_config: { provider: "openai" },
|
|
large_file_storage: { type: "s3" },
|
|
git_sync: { enabled: true },
|
|
default_scripts: { python: "template.py" },
|
|
operator_settings: { hideCode: true },
|
|
};
|
|
const result = migrateToGroupedFormat(settings);
|
|
expect(result.ai_config).toEqual({ provider: "openai" });
|
|
expect(result.large_file_storage).toEqual({ type: "s3" });
|
|
expect(result.git_sync).toEqual({ enabled: true });
|
|
expect(result.default_scripts).toEqual({ python: "template.py" });
|
|
expect(result.operator_settings).toEqual({ hideCode: true });
|
|
});
|
|
|
|
test("does not include undefined fields in result", () => {
|
|
const result = migrateToGroupedFormat({ name: "ws" });
|
|
expect("webhook" in result).toBe(false);
|
|
expect("deploy_to" in result).toBe(false);
|
|
expect("color" in result).toBe(false);
|
|
expect("slack_team_id" in result).toBe(false);
|
|
expect("slack_name" in result).toBe(false);
|
|
expect("slack_command_script" in result).toBe(false);
|
|
});
|
|
|
|
test("copies slack fields through", () => {
|
|
const settings = {
|
|
name: "ws",
|
|
slack_team_id: "T12345",
|
|
slack_name: "my-team",
|
|
slack_command_script: "u/admin/slack_handler",
|
|
};
|
|
const result = migrateToGroupedFormat(settings);
|
|
expect(result.slack_team_id).toBe("T12345");
|
|
expect(result.slack_name).toBe("my-team");
|
|
expect(result.slack_command_script).toBe("u/admin/slack_handler");
|
|
});
|
|
|
|
// error_handler / success_handler: null must round-trip through migration so
|
|
// that `wmill sync push` can forward it to the backend as a "clear remote"
|
|
// signal. Before this fix, null fell through the truthy-object + string
|
|
// branches and ended up as undefined, making an explicit `error_handler: null`
|
|
// in settings.yaml a no-op under the universal "omit = clear" rule.
|
|
test("preserves explicit null error_handler", () => {
|
|
const result = migrateToGroupedFormat({ name: "ws", error_handler: null });
|
|
expect(result.error_handler).toBeNull();
|
|
expect("error_handler" in result).toBe(true);
|
|
});
|
|
|
|
test("preserves explicit null success_handler", () => {
|
|
const result = migrateToGroupedFormat({ name: "ws", success_handler: null });
|
|
expect(result.success_handler).toBeNull();
|
|
expect("success_handler" in result).toBe(true);
|
|
});
|
|
|
|
test("preserves both null handlers alongside a populated handler", () => {
|
|
const result = migrateToGroupedFormat({
|
|
name: "ws",
|
|
error_handler: { path: "u/admin/err", muted_on_cancel: false },
|
|
success_handler: null,
|
|
});
|
|
expect(result.error_handler).toEqual({
|
|
path: "u/admin/err",
|
|
muted_on_cancel: false,
|
|
});
|
|
expect(result.success_handler).toBeNull();
|
|
});
|
|
|
|
// slack_oauth_client_id / slack_oauth_client_secret are the workspace-level
|
|
// OAuth override. Pull always emits them (null when DB is NULL), and push
|
|
// forwards whatever is in YAML — both present upserts, anything else deletes.
|
|
test("copies slack_oauth_client_id / _secret through (populated)", () => {
|
|
const result = migrateToGroupedFormat({
|
|
name: "ws",
|
|
slack_oauth_client_id: "1234567890.1234567890",
|
|
slack_oauth_client_secret: "abcdef0123456789",
|
|
});
|
|
expect(result.slack_oauth_client_id).toBe("1234567890.1234567890");
|
|
expect(result.slack_oauth_client_secret).toBe("abcdef0123456789");
|
|
});
|
|
|
|
test("copies slack_oauth_client_id / _secret through (null)", () => {
|
|
const result = migrateToGroupedFormat({
|
|
name: "ws",
|
|
slack_oauth_client_id: null,
|
|
slack_oauth_client_secret: null,
|
|
});
|
|
// migrateToGroupedFormat only copies fields that are `!== undefined`;
|
|
// null is a valid value and must flow through so the push comparison sees
|
|
// "local is null, remote is null → equal" instead of treating absence as
|
|
// "not in YAML".
|
|
expect(result.slack_oauth_client_id).toBeNull();
|
|
expect(result.slack_oauth_client_secret).toBeNull();
|
|
});
|
|
});
|