Files
windmill/cli/test/override_settings_behavior.test.ts
Ruben Fiszel 5b97092997 feat: unify CLI config to workspaces, deprecate gitBranches/environments (#8767)
* refactor: unify CLI config to workspaces, deprecate gitBranches/environments

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

* chore: update frontend examples and regenerate system prompts for workspaces config

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

* test: update test files to use workspaces config instead of gitBranches

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

* fix: handle --branch with --base-url correctly in sync pull/push

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

* feat: warn when --workspace overrides auto-detected branch or misses config entry

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

* feat: show reason why workspace was selected in log message

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

* docs: clarify specificItems file naming uses gitBranch as suffix

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

* refactor: rename branch-specific to workspace-specific, use workspace name as file suffix

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

* refactor: rename branch-specific to workspace-specific, add comprehensive integration tests

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

* refactor: simplify bind and init to be workspace-centric

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

* refactor: make bind/unbind interactive with --workspace and --branch flags

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

* refactor: make bind interactive with profile selection, workspace name, and optional branch

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

* refactor: init offers to bind workspace using same flow as wmill workspace bind

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

* fix: skip backend git-sync check in init when no workspace was bound

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

* fix: skip all API calls in init when no workspace was bound

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

* feat: log when RT namespace is skipped, offer to generate it after bind

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

* fix: warn when no workspace bound during init

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

* fix: init git-sync check uses bound workspace, not active profile

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

* fix: init uses selected profile directly, avoids re-resolving and duplicate prompt

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

* fix: init skips requireLogin, uses bound profile token directly

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

* feat: auto-pick or prompt workspace from config when no branch matches

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

* fix: show configured workspaces list and bind hint in resolution messages

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

* fix: cache bound profile to avoid duplicate profile selection prompts in init

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

* fix: hoist boundProfile scope, add 2 comprehensive integration tests covering all flows

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

* fix: rt.d.ts prompt defaults to no when file exists, better description

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

* fix: remove empty overrides from generated config, add specificItems hint

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

* fix: add inline comments for non-trivial fields, add overrides/promotionOverrides hints to bound workspaces

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

* chore: regenerate system prompts

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

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-04-09 19:46:34 +00:00

262 lines
8.5 KiB
TypeScript

import { expect, test } from "bun:test";
import { writeFile } from "node:fs/promises";
import { getEffectiveSettings } from "../src/core/conf.ts";
import { withTestBackend } from "./test_backend.ts";
import { addWorkspace } from "../workspace.ts";
import { parseJsonFromCLIOutput } from "./test_config_helpers.ts";
// =============================================================================
// OVERRIDE SETTINGS BEHAVIOR TESTS
// Tests for gitBranches override inheritance and file filtering behavior
// =============================================================================
test("Override Settings: branch override inherits non-overridden settings from base config", async () => {
const config = {
includes: ["default/**"],
skipVariables: true, // Base has this as true
skipResources: true, // Base has this as true
skipApps: false, // Base has this as false
defaultTs: "bun" as const,
workspaces: {
main: {
overrides: {
includes: ["override/**"],
skipApps: true // Override only changes skipApps, should inherit other skip flags
}
}
}
};
const effective = await getEffectiveSettings(
config,
undefined, // promotion
true, // skipBranchValidation
true, // suppressLogs
"main" // branchOverride
);
// Override values should be used
expect(effective.includes).toEqual(["override/**"]);
expect(effective.skipApps).toEqual(true);
// Should inherit skip flags from base config
expect(effective.skipVariables).toEqual(true);
expect(effective.skipResources).toEqual(true);
expect(effective.defaultTs).toEqual("bun");
});
test("Override Settings: branch-specific settings take precedence", async () => {
const config = {
includes: ["default/**"],
skipVariables: false,
workspaces: {
main: {
overrides: {
skipVariables: true,
includes: ["main/**"]
}
},
dev: {
overrides: {
skipVariables: false,
includes: ["dev/**"]
}
}
}
};
// Test main branch
const mainEffective = await getEffectiveSettings(
config,
undefined,
true,
true,
"main"
);
expect(mainEffective.includes).toEqual(["main/**"]);
expect(mainEffective.skipVariables).toEqual(true);
// Test dev branch
const devEffective = await getEffectiveSettings(
config,
undefined,
true,
true,
"dev"
);
expect(devEffective.includes).toEqual(["dev/**"]);
expect(devEffective.skipVariables).toEqual(false);
});
// =============================================================================
// INTEGRATION TESTS - File Filtering Behavior with gitBranches
// =============================================================================
test("Integration: sync pull with skipVariables branch override excludes variable files", async () => {
await withTestBackend(async (backend, tempDir) => {
// Set up workspace
const testWorkspace = {
remote: backend.baseUrl,
workspaceId: backend.workspace,
name: "skip_variables_test",
token: backend.token
};
await addWorkspace(testWorkspace, { force: true, configDir: backend.testConfigDir });
// Create wmill.yaml with gitBranches override that skips variables
await writeFile(`${tempDir}/wmill.yaml`, `defaultTs: bun
includes:
- "**"
skipVariables: false
gitBranches:
test_branch:
overrides:
skipVariables: true`, "utf-8");
// Run sync pull with --branch to force using test_branch config
const result = await backend.runCLICommand([
'sync', 'pull',
'--branch', 'test_branch',
'--dry-run',
'--json-output'
], tempDir);
expect(result.code).toEqual(0);
// Parse output and verify variable files are NOT included
const output = parseJsonFromCLIOutput(result.stdout);
const changePaths = (output.changes || []).map((c: any) => c.path);
const hasVariableFile = changePaths.some((path: string) => path.includes('.variable.yaml'));
expect(hasVariableFile).toEqual(false);
// Verify other files ARE included
const hasOtherFiles = changePaths.some((path: string) =>
!path.includes('.variable.yaml') && !path.includes('wmill.yaml')
);
expect(hasOtherFiles).toBeTruthy();
});
});
test("Integration: sync pull respects includes branch override for file filtering", async () => {
await withTestBackend(async (backend, tempDir) => {
// Set up workspace
const testWorkspace = {
remote: backend.baseUrl,
workspaceId: backend.workspace,
name: "includes_test",
token: backend.token
};
await addWorkspace(testWorkspace, { force: true, configDir: backend.testConfigDir });
// Create wmill.yaml with gitBranches override for includes
await writeFile(`${tempDir}/wmill.yaml`, `defaultTs: bun
includes:
- "**"
gitBranches:
restricted_branch:
overrides:
includes:
- "users/**"
- "groups/**"`, "utf-8");
// Run sync pull with --branch to use restricted includes
const result = await backend.runCLICommand([
'sync', 'pull',
'--branch', 'restricted_branch',
'--include-users',
'--include-groups',
'--dry-run',
'--json-output'
], tempDir);
expect(result.code).toEqual(0);
// Parse output
const output = parseJsonFromCLIOutput(result.stdout);
const changePaths = (output.changes || []).map((c: any) => c.path);
// Normalize paths for cross-platform comparison (Windows uses backslashes)
const normalizedPaths = changePaths.map((p: string) => p.replace(/\\/g, '/'));
// Verify users/groups are included
const hasUserFiles = normalizedPaths.some((path: string) => path.includes('users/'));
const hasGroupFiles = normalizedPaths.some((path: string) => path.includes('groups/'));
expect(hasUserFiles || hasGroupFiles).toBeTruthy();
// Verify f/** files are NOT included (due to restrictive includes)
const hasFolderFiles = normalizedPaths.some((path: string) => path.startsWith('f/'));
expect(hasFolderFiles).toEqual(false);
});
});
test("Integration: different branches have different settings", async () => {
await withTestBackend(async (backend, tempDir) => {
// Set up workspace
const testWorkspace = {
remote: backend.baseUrl,
workspaceId: backend.workspace,
name: "multi_branch_test",
token: backend.token
};
await addWorkspace(testWorkspace, { force: true, configDir: backend.testConfigDir });
// Create wmill.yaml with different settings per branch
await writeFile(`${tempDir}/wmill.yaml`, `defaultTs: bun
includes:
- "**"
skipVariables: false
skipResources: false
gitBranches:
prod:
overrides:
skipVariables: true
skipResources: true
dev:
overrides:
skipVariables: false
skipResources: false`, "utf-8");
// Test prod branch - should skip variables and resources
const prodResult = await backend.runCLICommand([
'sync', 'pull',
'--branch', 'prod',
'--dry-run',
'--json-output'
], tempDir);
expect(prodResult.code).toEqual(0);
const prodOutput = parseJsonFromCLIOutput(prodResult.stdout);
const prodPaths = (prodOutput.changes || []).map((c: any) => c.path);
const prodHasVariables = prodPaths.some((path: string) => path.includes('.variable.yaml'));
const prodHasResources = prodPaths.some((path: string) => path.includes('.resource.yaml'));
expect(prodHasVariables).toEqual(false);
expect(prodHasResources).toEqual(false);
// Test dev branch - should include variables and resources
const devResult = await backend.runCLICommand([
'sync', 'pull',
'--branch', 'dev',
'--dry-run',
'--json-output'
], tempDir);
expect(devResult.code).toEqual(0);
const devOutput = parseJsonFromCLIOutput(devResult.stdout);
const devPaths = (devOutput.changes || []).map((c: any) => c.path);
const devHasVariables = devPaths.some((path: string) => path.includes('.variable.yaml'));
const devHasResources = devPaths.some((path: string) => path.includes('.resource.yaml'));
expect(devHasVariables).toEqual(true);
expect(devHasResources).toEqual(true);
});
});