Files
windmill/cli/test/deploy_labels_unit.test.ts
T
f79e4b618d fix: copy labels into forks and detect label changes in compare (#12738)
* fix: copy labels into forks and detect label changes in compare

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

* fix: show labels in the compare diff and bump windmill-utils-internal

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

* fix: normalize app labels in the compare diff

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

* fix: keep target labels when a fork item has none set

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

* chore: publish utils-internal under the @windmill-labs org

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

* chore: publish utils-internal on release with trusted publishing

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

* chore: build the frontend from utils-internal source

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

* chore: drop the utils-internal version bump

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

* chore: bump utils-internal to 1.8.7

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Ruben Fiszel <ruben@windmill.dev>
2026-11-30 21:50:35 +01:00

151 lines
5.1 KiB
TypeScript

import { expect, test } from "bun:test";
import { deployItem } from "../windmill-utils-internal/src/deploy.ts";
// Variables, resources and folders are deployed from a body built field by field rather than
// spread from the source item, so any field left out of it is silently dropped in the target.
test("deployItem: carries labels for variables, resources and folders", async () => {
const labels = ["prod", "billing"];
const writes: [string, any][] = [];
const provider = (exists: boolean) =>
({
existsVariable: async () => exists,
existsResource: async () => exists,
existsFolder: async () => exists,
getVariable: async () => ({ value: "v", is_secret: false, labels }),
getResource: async () => ({
value: {},
resource_type: "postgresql",
labels,
}),
getFolder: async () => ({
name: "x",
display_name: "X folder",
owners: [],
extra_perms: {},
labels,
}),
...Object.fromEntries(
[
"createVariable",
"updateVariable",
"createResource",
"updateResource",
"createFolder",
"updateFolder",
].map((fn) => [
fn,
async (p: any) => void writes.push([fn, p.requestBody]),
]),
),
}) as any;
for (const exists of [false, true]) {
for (const [kind, path] of [
["variable", "f/x/v"],
["resource", "f/x/r"],
["folder", "f/x"],
]) {
const result = await deployItem(
provider(exists),
kind as any,
path,
"src",
"dst",
);
expect(result).toEqual({ success: true });
}
}
expect(writes.map(([fn]) => fn).sort()).toEqual([
"createFolder",
"createResource",
"createVariable",
"updateFolder",
"updateResource",
"updateVariable",
]);
for (const [, body] of writes) expect(body.labels).toEqual(labels);
// The compare page flags a folder whose display name differs, so dropping it leaves a
// conflict no deploy can clear.
for (const [fn, body] of writes) {
if (fn.endsWith("Folder")) expect(body.display_name).toEqual("X folder");
if (fn.endsWith("Resource")) expect(body.resource_type).toEqual("postgresql");
}
});
test("deployItem: keeps the target's labels when the source has none set", async () => {
// Forks can hold items whose labels were never copied; only an explicit [] is a clear.
for (const labels of [undefined, []]) {
const bodies: any[] = [];
const write = async (p: any) => void bodies.push(p.requestBody);
const provider = {
existsVariable: async () => true,
existsResource: async () => true,
existsFlowByPath: async () => true,
existsApp: async () => true,
getVariable: async () => ({ value: "v", is_secret: false, labels }),
getResource: async () => ({ value: {}, resource_type: "postgresql", labels }),
getFlowByPath: async () => ({ path: "f/x/i", value: { modules: [] }, labels }),
getAppByPath: async () => ({ path: "f/x/i", policy: {}, labels }),
updateVariable: write,
updateResource: write,
updateFlow: write,
updateApp: write,
} as any;
for (const kind of ["variable", "resource", "flow", "app"]) {
const result = await deployItem(provider, kind as any, "f/x/i", "src", "dst");
expect(result).toEqual({ success: true });
}
expect(bodies.map((b) => b.labels)).toEqual([labels, labels, labels, labels]);
}
});
test("deployItem: carries a resource type's file settings and clears unset ones", async () => {
const bodies: Record<string, any> = {};
const deploy = (exists: boolean, rt: any) =>
deployItem(
{
existsResourceType: async () => exists,
getResourceType: async () => rt,
createResourceType: async (p: any) => void (bodies.create = p.requestBody),
updateResourceType: async (p: any) => void (bodies.update = p.requestBody),
} as any,
"resource_type",
"csv_file",
"src",
"dst",
);
for (const rt of [
{ name: "csv_file", schema: {}, format_extension: "csv" },
{ name: "csv_file", schema: {}, is_fileset: true },
]) {
await deploy(false, rt);
await deploy(true, rt);
for (const body of [bodies.create, bodies.update]) {
expect(body.format_extension ?? undefined).toEqual(rt.format_extension);
expect(body.is_fileset ?? false).toEqual(rt.is_fileset ?? false);
}
}
// A type that stopped being a file type reads back without the fields.
await deploy(true, { name: "csv_file", schema: {} });
expect(bodies.update.format_extension).toBeNull();
expect(bodies.update.is_fileset).toEqual(false);
});
test("deployItem: clears a folder's labels when the source has none", async () => {
let body: any;
await deployItem(
{
existsFolder: async () => true,
// A folder with cleared labels reads back without the field at all.
getFolder: async () => ({ name: "x", owners: [], extra_perms: {} }),
updateFolder: async (p: any) => void (body = p.requestBody),
} as any,
"folder",
"f/x",
"src",
"dst",
);
expect(body.labels).toEqual([]);
});