mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-18 16:02:10 +00:00
68debab877
* feat(triggers): add AMQP (RabbitMQ) trigger using the lapin library Fixes WIN-2214 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore(triggers): defer AMQP cross-workspace deploy pending utils-internal publish Revert the amqp_trigger additions to the shared windmill-utils-internal TriggerDeployKind and the frontend cross-workspace deploy adapter: the frontend installs the published npm package, which lacks the new kind until a release is cut. AMQP create/edit/delete/list/sync/capture are unaffected (they use local types); only cross-workspace deploy/merge of AMQP triggers waits on the package bump. Also document the at-most-once ack in the consumer loop. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(triggers): address AMQP review — at-least-once ack, workspace cascade, contracts - ack AMQP deliveries only after successful dispatch; nack+requeue on failure - add ON DELETE CASCADE workspace FK so amqp_trigger rows are cleaned on workspace deletion (and the listener stops) - fix the /amqp_triggers/test OpenAPI body and add amqp_trigger to WorkspaceDiffRow.kind - register AMQP in the generated workspace trigger tool (create_trigger) - drop banned $bindable defaults on optional props in the config section - add build_uri unit tests (encoding, ports, vhost) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(triggers): stop AMQP poison-message loop and reconnect on transient drops Chaos testing against a live RabbitMQ broker showed the previous nack(requeue) + immediate re-poll spun a tight redelivery loop (~1000 critical-error reports/sec) on a poison message, and any connection blip permanently disabled the trigger (lapin has no built-in reconnect). - on dispatch failure: nack+requeue then stop consuming; the listener framework re-lists the trigger after its ping goes stale (~15s), backing redelivery off to that cadence instead of a tight loop (verified: rate dropped from ~1000/s to ~1 per ~26s, message preserved) - on connection/stream error: stop and let the framework reconnect instead of disabling; persistent failures are still disabled via get_consumer (verified: a forced connection close now auto-reconnects and resumes) - finish the AI create-trigger action wiring for AMQP: add amqp to CreatedResourceTriggerKind, the action-card registry, and the drawer registry so the result card renders and its "Open" action works Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(triggers): complete AMQP frontend registries and defer merge rows - add amqp to capturableTriggerTypes (so AmqpCapture mounts), the Runs jobTriggerKinds filter, and CLOUD_DISABLED_TRIGGER_TYPES - wire AMQP into global AI chat mode: TRIGGER_KINDS, the request union, writeTriggerSchema, triggerServices, and the draft adapter - stop emitting actionable AMQP fork-comparison rows (revert amqp_trigger from TRIGGER_OR_SCHEDULE_TABLES) since cross-workspace deploy is deferred until windmill-utils-internal is published — avoids a deploy that fails with "Unknown kind: amqp_trigger" - use design-system TextInput instead of raw <input> in the config section Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(triggers): complete AMQP session/draft registries and constrain prefetch - add amqp to the session-deploy, draft-compare, preview-router, and copilot workspace-item registries so AMQP drafts/deploys/nav/path resolution work - include amqp_count in the MoveDrawer attached-trigger rename warning - replace the raw prefetch <input> with a design-system TextInput bounded to an integer 1-65535 (backend u16) and block save on invalid values Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(triggers): make AMQP disconnect/reconnect consistent with the Kafka trigger lapin, like rdkafka, has no transparent reconnect, so the AMQP listener now mirrors the Kafka trigger's explicit reconnect loop instead of relying on the framework re-list (which disabled the trigger once get_consumer failed on a sustained outage): - get_consumer returns cheaply; consume owns a (re)connect loop that retries with a 30s backoff, reports a critical error every 10 failed attempts, and reports a recovered critical error once it reconnects — never disabling the trigger on a connectivity failure - a consumer/stream error breaks out to reconnect rather than disabling - dispatch failure still nacks+requeues (at-least-once) with a short backoff to avoid a tight poison-message loop, keeping the connection alive Verified against a live RabbitMQ broker: killing the broker keeps the trigger enabled and retrying (attempt N), and restarting it auto-reconnects (logs "reconnected after N attempts") and resumes dispatch. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(triggers): complete AMQP capture registries and constrain prefetch contract - add the 'amqp' case to triggerKindToTriggerType so opening the AMQP editor from a capture button no longer throws "Unknown TriggerKind: amqp" - register AmqpIcon in CaptureTable's icon map and add an AMQP entry to the script/flow CaptureButton menu - bound the OpenAPI prefetch_count to an integer 1-65535 (matches the Rust u16) and regenerate clients/prompts - require a non-empty exchange name when the exchange binding is enabled - build_uri: fall back to "/" on a blank vhost and bracket IPv6 hosts (+ tests) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(triggers): wire AMQP into pipeline graph, git-sync, and preprocessor types - asset_graph: discover attached amqp_trigger rows and emit an AMQP TriggerEdge so AMQP triggers render (and can be opened/deleted) on the data-pipeline canvas - frontend pipeline graph: add amqp to NativeTriggerKind, the add-trigger menu, node presentation, event-trigger set, annotation keywords, and the editor/service registrations - git-sync: add the amqp_trigger include pattern (+ test) so an AMQP git-sync deployment stages only its .amqp_trigger.* file, not an unrelated same-path object - preprocessor starters: add the AMQP event to the generated TS/Python/PHP trigger event types (kind/payload/exchange/routing_key/queue_name/redelivered/ delivery_tag) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(triggers): finish AMQP pipeline/parser wiring, prefetch validation, source lists - fix a stray edit that corrupted the pre-existing MqttTriggerEditor import ($lib/... path) in PipelineTriggerEditors.svelte - reject prefetch_count = 0 server-side in validate_config (RabbitMQ treats 0 as unlimited) and defensively skip basic_qos(0) in build_consumer (covers the capture path that bypasses CRUD validation) - recognize `// on amqp` in the canonical parser (TriggerSpec::Amqp) and add amqp to the CLI non-autorun/event-trigger sets so a pipeline cascade never runs an AMQP-only node as a manual root without an event - add amqp to the preprocessor intro lists and both pipeline AI instructions Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(triggers): reject zero AMQP prefetch in all paths and finish guidance lists - extract a shared validate_amqp_options used by both CRUD validate_config and build_consumer, so capture configs (which bypass CRUD validation) also reject prefetch 0 instead of silently connecting with an unlimited buffer (+ unit tests for 0/1/65535/None) - add AMQP to the main script-writing preprocessor-sources prompt and the CLI triggers-skill guidance list Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * docs(triggers): de-duplicate AMQP prefetch comment and fix GET response text - keep the zero-prefetch rationale only on the shared validate_amqp_options doc; drop the redundant call-site comments - correct the getAmqpTrigger OpenAPI 200 description ("deleted" -> "retrieved") Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore: update ee-repo-ref to aaa6cb89b05b76139252c64f057e53b94d12ac60 This commit updates the EE repository reference after PR #680 was merged in windmill-ee-private. Previous ee-repo-ref: 5da5fd65aca9594b2611837a52e4677b544b0380 New ee-repo-ref: aaa6cb89b05b76139252c64f057e53b94d12ac60 Automated by sync-ee-ref workflow. * chore(migrations): consolidate the four AMQP migrations into one The table and the three enum ADD VALUE statements (trigger_kind, job_trigger_kind, draft_kind) are one atomic feature. ALTER TYPE ... ADD VALUE runs inside the migration transaction on PG >= 14 (Windmill's minimum) since the amqp_trigger table doesn't reference those enum types, so they can share a single migration instead of four. Verified applying cleanly in a single transaction on a fresh DB. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
412 lines
14 KiB
TypeScript
412 lines
14 KiB
TypeScript
/**
|
|
* Unit tests for git utility functions.
|
|
* Tests pure functions only — no git subprocess calls.
|
|
*/
|
|
|
|
import { expect, test, describe } from "bun:test";
|
|
import {
|
|
getOriginalBranchForWorkspaceForks,
|
|
getWorkspaceIdForWorkspaceForkFromBranchName,
|
|
computeGitSyncDeployBranch,
|
|
composeGitSyncCommitHeader,
|
|
forkBranchName,
|
|
gitSyncIncludePattern,
|
|
deriveGitSyncDeployIncludes,
|
|
gitSyncCommitMessage,
|
|
isForkWorkspace,
|
|
} from "../src/utils/git.ts";
|
|
|
|
// =============================================================================
|
|
// getOriginalBranchForWorkspaceForks
|
|
// =============================================================================
|
|
|
|
describe("getOriginalBranchForWorkspaceForks", () => {
|
|
test("extracts original branch from valid fork branch name", () => {
|
|
expect(getOriginalBranchForWorkspaceForks("wm-fork/main/my-workspace")).toBe("main");
|
|
});
|
|
|
|
test("extracts multi-segment original branch", () => {
|
|
expect(
|
|
getOriginalBranchForWorkspaceForks("wm-fork/feature/cool-thing/my-workspace")
|
|
).toBe("feature/cool-thing");
|
|
});
|
|
|
|
test("returns null for null input", () => {
|
|
expect(getOriginalBranchForWorkspaceForks(null)).toBeNull();
|
|
});
|
|
|
|
test("returns null for empty string", () => {
|
|
expect(getOriginalBranchForWorkspaceForks("")).toBeNull();
|
|
});
|
|
|
|
test("returns null for non-fork branch", () => {
|
|
expect(getOriginalBranchForWorkspaceForks("main")).toBeNull();
|
|
expect(getOriginalBranchForWorkspaceForks("feature/my-feature")).toBeNull();
|
|
});
|
|
|
|
test("returns null for branch that starts with wm-fork but has no slashes after", () => {
|
|
expect(getOriginalBranchForWorkspaceForks("wm-fork")).toBeNull();
|
|
});
|
|
|
|
test("returns null when branch segment between slashes is empty", () => {
|
|
// "wm-fork//workspace" — start=8, end=8, end - start = 0
|
|
expect(getOriginalBranchForWorkspaceForks("wm-fork//workspace")).toBeNull();
|
|
});
|
|
});
|
|
|
|
// =============================================================================
|
|
// getWorkspaceIdForWorkspaceForkFromBranchName
|
|
// =============================================================================
|
|
|
|
describe("getWorkspaceIdForWorkspaceForkFromBranchName", () => {
|
|
test("extracts workspace id from valid fork branch name", () => {
|
|
expect(
|
|
getWorkspaceIdForWorkspaceForkFromBranchName("wm-fork/main/my-workspace")
|
|
).toBe("wm-fork-my-workspace");
|
|
});
|
|
|
|
test("returns null for non-fork branch", () => {
|
|
expect(getWorkspaceIdForWorkspaceForkFromBranchName("main")).toBeNull();
|
|
expect(
|
|
getWorkspaceIdForWorkspaceForkFromBranchName("feature/my-feature")
|
|
).toBeNull();
|
|
});
|
|
|
|
test("extracts workspace id with multi-segment original branch", () => {
|
|
expect(
|
|
getWorkspaceIdForWorkspaceForkFromBranchName("wm-fork/feature/cool/ws-id")
|
|
).toBe("wm-fork-ws-id");
|
|
});
|
|
});
|
|
|
|
// =============================================================================
|
|
// computeGitSyncDeployBranch — the regression guard.
|
|
//
|
|
// hub/28229 dropped this logic and pushed every deploy straight to the cloned
|
|
// base branch (e.g. protected `main`), breaking promotion. These pin the
|
|
// hub/28217 / hub/28230 branch-selection semantics.
|
|
// =============================================================================
|
|
|
|
describe("computeGitSyncDeployBranch", () => {
|
|
const base = {
|
|
workspaceId: "prod",
|
|
clonedBranchName: "main",
|
|
groupByFolder: false,
|
|
};
|
|
|
|
test("use_individual_branch=true -> dedicated wm_deploy branch (NOT main)", () => {
|
|
const branch = computeGitSyncDeployBranch({
|
|
...base,
|
|
useIndividualBranch: true,
|
|
items: [{ path_type: "script", path: "f/foo/bar" }],
|
|
});
|
|
expect(branch).toBe("wm_deploy/prod/script/f__foo__bar");
|
|
expect(branch).not.toBe("main");
|
|
});
|
|
|
|
test("dev workspace (parent + label) deploys to the label branch", () => {
|
|
expect(
|
|
computeGitSyncDeployBranch({
|
|
...base,
|
|
workspaceId: "staging-ws",
|
|
parentWorkspaceId: "prod",
|
|
devWorkspaceLabel: "staging",
|
|
useIndividualBranch: false,
|
|
items: [{ path_type: "script", path: "f/foo/bar" }],
|
|
})
|
|
).toBe("staging");
|
|
});
|
|
|
|
test("use_individual_branch=false -> null (stay on base/main, workspace-wide mode)", () => {
|
|
expect(
|
|
computeGitSyncDeployBranch({
|
|
...base,
|
|
useIndividualBranch: false,
|
|
items: [{ path_type: "script", path: "f/foo/bar" }],
|
|
})
|
|
).toBeNull();
|
|
});
|
|
|
|
test("group_by_folder=true -> per-folder wm_deploy branch (first 2 path segments)", () => {
|
|
expect(
|
|
computeGitSyncDeployBranch({
|
|
...base,
|
|
useIndividualBranch: true,
|
|
groupByFolder: true,
|
|
items: [{ path_type: "script", path: "f/team_a/deep/nested" }],
|
|
})
|
|
).toBe("wm_deploy/prod/f__team_a");
|
|
});
|
|
|
|
test("falls back to parent_path when path is absent", () => {
|
|
expect(
|
|
computeGitSyncDeployBranch({
|
|
...base,
|
|
useIndividualBranch: true,
|
|
items: [{ path_type: "flow", path: null, parent_path: "f/x/y" }],
|
|
})
|
|
).toBe("wm_deploy/prod/flow/f__x__y");
|
|
});
|
|
|
|
test("user/group objects never get a dedicated branch", () => {
|
|
expect(
|
|
computeGitSyncDeployBranch({
|
|
...base,
|
|
useIndividualBranch: true,
|
|
items: [{ path_type: "user", path: "u/alice" }],
|
|
})
|
|
).toBeNull();
|
|
expect(
|
|
computeGitSyncDeployBranch({
|
|
...base,
|
|
useIndividualBranch: true,
|
|
items: [{ path_type: "group", path: "g/admins" }],
|
|
})
|
|
).toBeNull();
|
|
});
|
|
|
|
test("empty items -> null", () => {
|
|
expect(
|
|
computeGitSyncDeployBranch({
|
|
...base,
|
|
useIndividualBranch: true,
|
|
items: [],
|
|
})
|
|
).toBeNull();
|
|
});
|
|
|
|
test("fork workspace -> wm-fork/<clonedBranch>/<id> regardless of individual-branch", () => {
|
|
expect(
|
|
computeGitSyncDeployBranch({
|
|
workspaceId: "wm-fork-myfork",
|
|
clonedBranchName: "main",
|
|
groupByFolder: false,
|
|
useIndividualBranch: false,
|
|
items: [{ path_type: "script", path: "f/foo/bar" }],
|
|
})
|
|
).toBe("wm-fork/main/myfork");
|
|
});
|
|
|
|
test("prefix-less fork (parent set, no label) beats the wm_deploy derivation", () => {
|
|
expect(
|
|
computeGitSyncDeployBranch({
|
|
workspaceId: "mydev",
|
|
parentWorkspaceId: "prod",
|
|
clonedBranchName: "main",
|
|
groupByFolder: false,
|
|
useIndividualBranch: true,
|
|
items: [{ path_type: "script", path: "f/foo/bar" }],
|
|
})
|
|
).toBe("wm-fork/main/mydev");
|
|
});
|
|
});
|
|
|
|
describe("forkBranchName", () => {
|
|
test("maps wm-fork-<id> to wm-fork/<branch>/<id>", () => {
|
|
expect(forkBranchName("wm-fork-abc", "main")).toBe("wm-fork/main/abc");
|
|
});
|
|
|
|
test("dev workspace label wins: the branch is the label verbatim", () => {
|
|
expect(forkBranchName("staging-ws", "main", "staging")).toBe("staging");
|
|
expect(forkBranchName("wm-fork-abc", "main", "dev")).toBe("dev");
|
|
});
|
|
|
|
test("prefix-less id without a label falls back to the wm-fork form", () => {
|
|
expect(forkBranchName("staging-ws", "main")).toBe("wm-fork/main/staging-ws");
|
|
});
|
|
});
|
|
|
|
describe("composeGitSyncCommitHeader", () => {
|
|
test("single type", () => {
|
|
expect(
|
|
composeGitSyncCommitHeader([{ path_type: "script", path: "a" }])
|
|
).toBe("[WM]: Deployed 1 script");
|
|
});
|
|
|
|
test("exactly 3 types: pluralises, orders by count, joins last with 'and'", () => {
|
|
expect(
|
|
composeGitSyncCommitHeader([
|
|
{ path_type: "script", path: "a" },
|
|
{ path_type: "script", path: "b" },
|
|
{ path_type: "flow", path: "c" },
|
|
{ path_type: "app", path: "d" },
|
|
])
|
|
).toBe("[WM]: Deployed 2 scripts, 1 flow, and 1 app");
|
|
});
|
|
|
|
test("4+ types: overflow collapses into 'other objects'", () => {
|
|
expect(
|
|
composeGitSyncCommitHeader([
|
|
{ path_type: "script", path: "a" },
|
|
{ path_type: "script", path: "b" },
|
|
{ path_type: "flow", path: "c" },
|
|
{ path_type: "app", path: "d" },
|
|
{ path_type: "resource", path: "e" },
|
|
{ path_type: "variable", path: "f" },
|
|
])
|
|
).toBe("[WM]: Deployed 2 scripts, 1 flow, 1 app and 2 other objects");
|
|
});
|
|
});
|
|
|
|
// =============================================================================
|
|
// gitSyncIncludePattern / deriveGitSyncDeployIncludes — replaces the hub
|
|
// script's regexFromPath + wmill_sync_pull include-derivation.
|
|
// =============================================================================
|
|
|
|
describe("gitSyncIncludePattern", () => {
|
|
test("script includes __mod/ folder for module scripts", () => {
|
|
expect(gitSyncIncludePattern("script", "f/foo/bar")).toBe(
|
|
"f/foo/bar.*,f/foo/bar__mod/**"
|
|
);
|
|
});
|
|
test("flow/app expand to dotted + __ folder patterns", () => {
|
|
expect(gitSyncIncludePattern("flow", "f/x")).toBe("f/x.flow/*,f/x__flow/*");
|
|
expect(gitSyncIncludePattern("app", "f/x")).toBe("f/x.app/*,f/x__app/*");
|
|
expect(gitSyncIncludePattern("raw_app", "f/x")).toBe(
|
|
"f/x.raw_app/**,f/x__raw_app/**"
|
|
);
|
|
});
|
|
test("folder and triggers", () => {
|
|
expect(gitSyncIncludePattern("folder", "f/x")).toBe("f/x/folder.meta.*");
|
|
expect(gitSyncIncludePattern("httptrigger", "f/t")).toBe(
|
|
"f/t.http_trigger.*"
|
|
);
|
|
expect(gitSyncIncludePattern("gcptrigger", "f/t")).toBe(
|
|
"f/t.gcp_trigger.*"
|
|
);
|
|
expect(gitSyncIncludePattern("amqptrigger", "f/t")).toBe(
|
|
"f/t.amqp_trigger.*"
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("deriveGitSyncDeployIncludes", () => {
|
|
test("splits multi-pattern includes (flow) and includes parent_path", () => {
|
|
const r = deriveGitSyncDeployIncludes(
|
|
[{ path_type: "flow", path: "f/a", parent_path: "f/b" }],
|
|
false
|
|
);
|
|
expect(r.extraIncludes).toEqual([
|
|
"f/a.flow/*",
|
|
"f/a__flow/*",
|
|
"f/b.flow/*",
|
|
"f/b__flow/*",
|
|
]);
|
|
});
|
|
|
|
test("workspace-wide mode force-includes deployed default-excluded kinds", () => {
|
|
const r = deriveGitSyncDeployIncludes(
|
|
[
|
|
{ path_type: "schedule", path: "f/s" },
|
|
{ path_type: "group", path: "g/g" },
|
|
{ path_type: "httptrigger", path: "f/t" },
|
|
{ path_type: "settings", path: "" },
|
|
{ path_type: "key", path: "" },
|
|
{ path_type: "user", path: "u/u" },
|
|
],
|
|
false
|
|
);
|
|
// Full-mirror repo: a deployed object of a default-excluded kind must be
|
|
// re-included even if wmill.yaml would skip it, so the flag is forced on.
|
|
expect(r.forcedIncludes).toEqual({
|
|
includeSchedules: true,
|
|
includeGroups: true,
|
|
includeTriggers: true,
|
|
includeSettings: true,
|
|
includeKey: true,
|
|
includeUsers: true,
|
|
});
|
|
});
|
|
|
|
test("workspace-wide mode only forces the kinds actually deployed", () => {
|
|
const r = deriveGitSyncDeployIncludes(
|
|
[{ path_type: "script", path: "f/s" }],
|
|
false
|
|
);
|
|
// Scripts are included by default — nothing to force.
|
|
expect(r.forcedIncludes).toEqual({});
|
|
});
|
|
|
|
test("individual-branch (promotion) mode forces NOTHING — defers to wmill.yaml", () => {
|
|
// Regression: these flags used to be force-disabled (set to false) in
|
|
// promotion mode, which CLOBBERED the promotion target's effective
|
|
// wmill.yaml config (an explicit false wins in pull's Object.assign merge).
|
|
// The server then stripped the object from the tarball, the pull wrote
|
|
// nothing, and `git add '<path>**'` failed with "pathspec did not match
|
|
// any files". Forcing nothing leaves the keys absent so the target's
|
|
// effective filters govern; extraIncludes still scopes the pull to the
|
|
// changed object.
|
|
const r = deriveGitSyncDeployIncludes(
|
|
[
|
|
{ path_type: "schedule", path: "f/s" },
|
|
{ path_type: "kafkatrigger", path: "f/t" },
|
|
],
|
|
true
|
|
);
|
|
expect(r.forcedIncludes).toEqual({});
|
|
expect(r.extraIncludes).toContain("f/s.schedule.*");
|
|
expect(r.extraIncludes).toContain("f/t.kafka_trigger.*");
|
|
});
|
|
|
|
test("regression: http_trigger promotion deploy does not clobber the target's includeTriggers", () => {
|
|
// Brad's scenario: an HTTP trigger is deployed and the promotion repo uses
|
|
// individual branches. path_type is "httptrigger" (the no-underscore value
|
|
// the backend puts on item.path_type — see git_sync_ee.rs
|
|
// insert_path_type_and_return_message). includeTriggers must NOT be forced
|
|
// false here, so the target's effective includeTriggers (true in Brad's
|
|
// config) is honored and the trigger file is pulled and committed.
|
|
const r = deriveGitSyncDeployIncludes(
|
|
[{ path_type: "httptrigger", path: "f/platform/on_call_chat_http_route" }],
|
|
true
|
|
);
|
|
expect(r.forcedIncludes.includeTriggers).toBeUndefined();
|
|
expect(r.extraIncludes).toContain(
|
|
"f/platform/on_call_chat_http_route.http_trigger.*"
|
|
);
|
|
});
|
|
});
|
|
|
|
// =============================================================================
|
|
// isForkWorkspace + gitSyncCommitMessage — 1:1 fidelity with the hub script.
|
|
// =============================================================================
|
|
|
|
describe("isForkWorkspace", () => {
|
|
test("true only for the wm-fork- workspace-id prefix", () => {
|
|
expect(isForkWorkspace("wm-fork-abc")).toBe(true);
|
|
expect(isForkWorkspace("prod")).toBe(false);
|
|
// "wm-fork" without the trailing dash is the BRANCH prefix, not a ws id
|
|
expect(isForkWorkspace("wm-fork")).toBe(false);
|
|
});
|
|
|
|
test("a parent workspace id marks prefix-less ids (dev workspaces) as forks", () => {
|
|
expect(isForkWorkspace("mydev", "prod")).toBe(true);
|
|
expect(isForkWorkspace("mydev", undefined)).toBe(false);
|
|
expect(isForkWorkspace("wm-fork-abc", undefined)).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("gitSyncCommitMessage (mirrors hub git_push quirks)", () => {
|
|
test("single item: uses its commit_msg verbatim, empty description", () => {
|
|
expect(
|
|
gitSyncCommitMessage([{ path_type: "script", path: "a", commit_msg: "msg" }])
|
|
).toEqual({ header: "msg", description: "" });
|
|
});
|
|
|
|
test("single item with NO commit_msg -> 'no commit msg' (hub fallback)", () => {
|
|
expect(
|
|
gitSyncCommitMessage([{ path_type: "script", path: "a" }])
|
|
).toEqual({ header: "no commit msg", description: "" });
|
|
});
|
|
|
|
test("multi item: composed header + newline-joined msgs, undefined -> ''", () => {
|
|
// hub pushes commit_msg once per item UNCONDITIONALLY, so the second
|
|
// (missing) entry joins as an empty string -> "first\n".
|
|
expect(
|
|
gitSyncCommitMessage([
|
|
{ path_type: "script", path: "a", commit_msg: "first" },
|
|
{ path_type: "flow", path: "b" },
|
|
])
|
|
).toEqual({ header: "[WM]: Deployed 1 script, 1 flow", description: "first\n" });
|
|
});
|
|
});
|