Files
windmill/cli/test/push_workspace_settings_identity_unit.test.ts
T
df61dea5fa fix: keep instance groups when editing auto-invite (#11217)
* fix: keep instance groups when editing auto-invite and push them from sync

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

* fix: compare settings.yaml without undeclared instance groups on push

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

* fix: read a missing auto_invite as empty when diffing settings.yaml on push

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

* chore: update ee-repo-ref to f2fced19fcae81de7f6dac545010ce404c052e1b

This commit updates the EE repository reference after PR #813 was merged in windmill-ee-private.

Previous ee-repo-ref: cf4258c1232720ca3b82db2b22ea1fb4bca9533e

New ee-repo-ref: f2fced19fcae81de7f6dac545010ce404c052e1b

Automated by sync-ee-ref workflow.

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
2026-09-18 14:32:55 +02:00

117 lines
4.0 KiB
TypeScript

/**
* Regression guard: `sync push` (pushWorkspaceSettings) must never apply the
* workspace display name from settings.yaml, and must apply the color only when
* the file carries one. Rationale lives at the apply sites in settings.ts.
*/
import { expect, test, describe, beforeEach, mock } from "bun:test";
let changeWorkspaceNameCalls: unknown[] = [];
let changeWorkspaceColorCalls: unknown[] = [];
let editWebhookCalls: unknown[] = [];
let remoteName = "";
let remoteColor: string | undefined = undefined;
let remoteWebhook: string | undefined = undefined;
// Every wmill.* call reachable from pushWorkspaceSettings is stubbed so the
// function runs without a backend; only the three we assert on record calls.
mock.module("../gen/services.gen.ts", () => ({
getSettings: async (_a: { workspace: string }) => ({
webhook: remoteWebhook,
color: remoteColor,
}),
getWorkspaceName: async (_a: { workspace: string }) => remoteName,
changeWorkspaceName: async (a: unknown) => {
changeWorkspaceNameCalls.push(a);
},
changeWorkspaceColor: async (a: unknown) => {
changeWorkspaceColorCalls.push(a);
},
editWebhook: async (a: unknown) => {
editWebhookCalls.push(a);
},
editAutoInvite: async () => {},
editInstanceGroups: async () => {},
editErrorHandler: async () => {},
editSuccessHandler: async () => {},
editCopilotConfig: async () => {},
editLargeFileStorageConfig: async () => {},
editWorkspaceGitSyncConfig: async () => {},
editWorkspaceDefaultApp: async () => {},
editDefaultScripts: async () => {},
workspaceMuteCriticalAlertsUi: async () => {},
updateOperatorSettings: async () => {},
editDataTableConfig: async () => {},
editSlackCommand: async () => {},
setWorkspaceSlackOauthConfig: async () => {},
deleteWorkspaceSlackOauthConfig: async () => {},
}));
const { pushWorkspaceSettings } = await import("../src/core/settings.ts");
describe("pushWorkspaceSettings workspace identity", () => {
const ws = "phoenix";
beforeEach(() => {
changeWorkspaceNameCalls = [];
changeWorkspaceColorCalls = [];
editWebhookCalls = [];
remoteName = "phoenix";
remoteColor = undefined;
remoteWebhook = undefined;
});
test("a differing name in settings.yaml is not applied to the workspace", async () => {
// Another setting also differs so the function proceeds past its no-op early
// return; only that setting must be applied, never the name.
remoteWebhook = "https://old";
await pushWorkspaceSettings(ws, "settings", undefined, {
name: "phoenix-staging",
webhook: "https://new",
});
expect(editWebhookCalls.length).toBe(1);
expect(changeWorkspaceNameCalls.length).toBe(0);
});
test("a name-only difference is a complete no-op", async () => {
await pushWorkspaceSettings(ws, "settings", undefined, {
name: "phoenix-staging",
});
expect(editWebhookCalls.length).toBe(0);
expect(changeWorkspaceNameCalls.length).toBe(0);
});
test("a settings.yaml without a color key does not clear the workspace color", async () => {
remoteColor = "#ff0000";
remoteWebhook = "https://old";
await pushWorkspaceSettings(ws, "settings", undefined, {
name: "phoenix",
webhook: "https://new",
});
expect(editWebhookCalls.length).toBe(1);
expect(changeWorkspaceColorCalls.length).toBe(0);
});
test("a color in settings.yaml is applied when it differs from the workspace", async () => {
remoteColor = "#ff0000";
await pushWorkspaceSettings(ws, "settings", undefined, {
name: "phoenix",
color: "#00ff00",
});
expect(editWebhookCalls.length).toBe(0);
expect(changeWorkspaceColorCalls).toEqual([
{ workspace: ws, requestBody: { color: "#00ff00" } },
]);
});
test("a color matching the workspace is a complete no-op", async () => {
remoteColor = "#ff0000";
await pushWorkspaceSettings(ws, "settings", undefined, {
name: "phoenix",
color: "#ff0000",
});
expect(editWebhookCalls.length).toBe(0);
expect(changeWorkspaceColorCalls.length).toBe(0);
});
});