Files
windmill/cli/test/pull_on_behalf_of_marker.test.ts
Ruben Fiszel 2d77e74207 fix(cli): stop emitting has_on_behalf_of/has_permissioned_as: false on pull (#10188)
With syncBehavior v1 the pull strips the user-specific on_behalf_of_email /
permissioned_as from metadata and keeps a boolean marker so a later push can
preserve remote ownership. The marker was written unconditionally as
`!!<field>`, so every ownerless script, flow, schedule and trigger (the vast
majority) got a `has_on_behalf_of: false` / `has_permissioned_as: false` line,
producing a spurious diff on every pull.

Absence of the marker already means "no owner" everywhere it's read on push, so
only emit the key when true.

Fixes WIN-2201

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-19 09:30:49 +02:00

59 lines
2.0 KiB
TypeScript

import { expect, test } from "bun:test";
import { readFile, writeFile } from "node:fs/promises";
import { withTestBackend } from "./test_backend.ts";
import { addWorkspace } from "../workspace.ts";
import { setClient } from "../src/core/client.ts";
// Regression guard for WIN-2201: with syncBehavior v1 the pull strips
// `on_behalf_of_email` and keeps only a boolean marker. That marker must be
// emitted ONLY when an owner exists — writing `has_on_behalf_of: false` for the
// (overwhelmingly common) ownerless script produced a spurious diff on every pull.
test("pull omits has_on_behalf_of for ownerless scripts", async () => {
await withTestBackend(async (backend, tempDir) => {
await addWorkspace(
{
remote: backend.baseUrl,
workspaceId: backend.workspace,
name: "obo_marker_test",
token: backend.token,
},
{ force: true, configDir: backend.testConfigDir },
);
setClient(backend.token, backend.baseUrl);
await writeFile(
`${tempDir}/wmill.yaml`,
`defaultTs: bun\nsyncBehavior: v1\nincludes:\n - "**"\nexcludes: []`,
"utf-8",
);
const scriptPath = "f/test/no_owner";
const createResp = await backend.apiRequest!(
`/api/w/${backend.workspace}/scripts/create`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
path: scriptPath,
content: `export async function main() { return 1; }`,
language: "bun",
summary: "no owner",
description: "",
}),
},
);
expect(createResp.status).toBeLessThan(300);
const pullResult = await backend.runCLICommand(
["sync", "pull", "--yes"],
tempDir,
"obo_marker_test",
);
expect(pullResult.code).toEqual(0);
const meta = await readFile(`${tempDir}/${scriptPath}.script.yaml`, "utf-8");
expect(meta).not.toContain("has_on_behalf_of");
expect(meta).not.toContain("on_behalf_of_email");
});
});