Files
windmill/cli/test/conf_branch_override_unit.test.ts
centdix 5fd2c1a129 chore(cli): separate unit tests from integration tests and fix test cleanup (#8562)
* fix(cli): separate unit tests from integration tests and fix test cleanup

- Rename 14 non-backend test files to *_unit.test.ts convention
- Add UNIT_ONLY env var guard in setup.ts to skip cargo build/backend startup
- Add test:unit and test:integration scripts to package.json
- Use setsid on Linux for process group management so stop() kills both
  cargo and the windmill child process
- Fix exit handler to kill process group instead of just the direct child
- Add cleanupStaleTestResources() to drop orphaned windmill_test_* databases
  and kill orphaned backend processes on startup
- Rewrite TESTING.md with current bun-based instructions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(cli): fix process group approach - kill by db name instead of setsid

The setsid approach didn't work because setsid forks, making the PID
we get from Bun.spawn ephemeral. Instead, kill orphaned windmill child
processes by matching our unique database name in /proc/pid/environ.

Also add afterAll hook in setup.ts so full async cleanup (process kill
+ database drop) runs when all tests complete normally, not just on
SIGINT/SIGTERM.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(cli): address PR review feedback

- Remove duplicate cleanupStaleTestResources() call in getTestBackend()
  (already called in setup.ts)
- Add regex guard on database names before SQL interpolation
- Extract shared killWindmillProcessesByEnvMatch() helper to deduplicate
  process-killing logic
- Remove redundant test:integration script (test already runs everything)
- Flip setup.ts to if/else pattern for readability

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 16:13:33 +00:00

145 lines
4.6 KiB
TypeScript

import { expect, test } from "bun:test";
import { getEffectiveSettings, type SyncOptions } from "../src/core/conf.ts";
// =============================================================================
// CONF.TS BRANCH OVERRIDE TESTS
// Tests for getEffectiveSettings with branchOverride parameter
// =============================================================================
test("getEffectiveSettings: applies branch overrides when branchOverride is provided", async () => {
const config: SyncOptions = {
defaultTs: "bun",
includes: ["f/**"],
gitBranches: {
staging: {
overrides: {
includes: ["staging/**"],
skipVariables: true,
},
},
production: {
overrides: {
includes: ["prod/**"],
skipSecrets: true,
},
},
},
};
// Test with staging branch override
const stagingSettings = await getEffectiveSettings(config, undefined, true, true, "staging");
expect(stagingSettings.includes).toEqual(["staging/**"]);
expect(stagingSettings.skipVariables).toEqual(true);
expect(stagingSettings.skipSecrets).toEqual(undefined);
// Test with production branch override
const prodSettings = await getEffectiveSettings(config, undefined, true, true, "production");
expect(prodSettings.includes).toEqual(["prod/**"]);
expect(prodSettings.skipSecrets).toEqual(true);
expect(prodSettings.skipVariables).toEqual(undefined);
});
test("getEffectiveSettings: uses top-level settings when branchOverride has no overrides", async () => {
const config: SyncOptions = {
defaultTs: "bun",
includes: ["f/**"],
skipVariables: true,
gitBranches: {
staging: {
// No overrides defined
},
},
};
const settings = await getEffectiveSettings(config, undefined, true, true, "staging");
expect(settings.includes).toEqual(["f/**"]);
expect(settings.skipVariables).toEqual(true);
expect(settings.defaultTs).toEqual("bun");
});
test("getEffectiveSettings: uses top-level settings for unknown branch", async () => {
const config: SyncOptions = {
defaultTs: "bun",
includes: ["f/**"],
gitBranches: {
staging: {
overrides: {
includes: ["staging/**"],
},
},
},
};
const settings = await getEffectiveSettings(config, undefined, true, true, "nonexistent");
expect(settings.includes).toEqual(["f/**"]);
expect(settings.defaultTs).toEqual("bun");
});
test("getEffectiveSettings: promotionOverrides take precedence when promotion specified", async () => {
const config: SyncOptions = {
defaultTs: "bun",
includes: ["f/**"],
gitBranches: {
production: {
overrides: {
includes: ["prod/**"],
},
promotionOverrides: {
includes: ["promoted/**"],
skipVariables: true,
},
},
},
};
// Test without promotion flag - should use regular overrides
const normalSettings = await getEffectiveSettings(config, undefined, true, true, "production");
expect(normalSettings.includes).toEqual(["prod/**"]);
expect(normalSettings.skipVariables).toEqual(undefined);
// Test with promotion flag - should use promotionOverrides
const promoSettings = await getEffectiveSettings(config, "production", true, true);
expect(promoSettings.includes).toEqual(["promoted/**"]);
expect(promoSettings.skipVariables).toEqual(true);
});
test("getEffectiveSettings: branchOverride works without gitBranches config", async () => {
const config: SyncOptions = {
defaultTs: "bun",
includes: ["f/**"],
};
// Should not throw even with branchOverride but no gitBranches
const settings = await getEffectiveSettings(config, undefined, true, true, "staging");
expect(settings.includes).toEqual(["f/**"]);
expect(settings.defaultTs).toEqual("bun");
});
test("getEffectiveSettings: preserves all top-level settings in merged result", async () => {
const config: SyncOptions = {
defaultTs: "bun",
includes: ["f/**"],
excludes: ["*.test.ts"],
skipVariables: false,
skipResources: false,
skipFlows: false,
parallel: 4,
gitBranches: {
staging: {
overrides: {
skipVariables: true, // Override just this one
},
},
},
};
const settings = await getEffectiveSettings(config, undefined, true, true, "staging");
expect(settings.defaultTs).toEqual("bun");
expect(settings.includes).toEqual(["f/**"]);
expect(settings.excludes).toEqual(["*.test.ts"]);
expect(settings.skipVariables).toEqual(true); // Overridden
expect(settings.skipResources).toEqual(false);
expect(settings.skipFlows).toEqual(false);
expect(settings.parallel).toEqual(4);
});