Files
kandev/apps/web/lib/backend-fixture-env.test.ts
T
Carlos Florêncio bc218dfbbe feat: add workspace sources from files panel (#1900)
* feat: add workspace sources from files panel

* fix: preserve worktree identity during recovery

* feat: unify workspace source actions

* fix: validate recovered workspace repositories

* fix: harden workspace source filesystem boundaries

* test: split workspace repository chip coverage

* fix: restrict repository rescan recovery paths

* fix: stabilize workspace source CI checks

* test: canonicalize workspace source paths

* test: align workspace source container paths

* fix: populate direct workspace repository names

* test: preserve git fixture rewrites across restarts

* test: isolate backend git fixture config

* fix: resume remote workspace executions before creation

* fix: preserve ssh agent identity during resume

* fix: preserve SSH workspace across backend restart

* fix: simplify workspace actions trigger

* fix: refine add workspace repositories UX

* docs: narrow workspace source UX updates

* fix: avoid phantom turn on session resume

* test(web): normalize workspace source request headers

* feat(web): streamline workspace source picker

* docs: remove trailing spaces from workspace source plan

* fix: prevent resume status from creating phantom turns

* fix(web): stabilize workspace source attachment

* refactor(web): extract workspace source store contract

* fix: avoid phantom turns on idle agent resume

* fix: address backend static analysis findings

* fix: preserve agentctl readiness status value

* fix: preserve resume messages without active turns

* fix: resume agents from promoted workspace root

* chore: merge origin/main into feature/add-new-repo-folder-d97

* feat(web): explain workspace source consequences

* test(websocket): count session activity subscription
2026-07-25 21:29:53 +01:00

91 lines
3.5 KiB
TypeScript

import { expect, test } from "vitest";
import { BackendFixtureEnvOverrides, createScopedEnvUse } from "../e2e/fixtures/backend-env";
test("keeps a scoped backend environment across restarts and restores baseline on release", () => {
const overrides = new BackendFixtureEnvOverrides();
const release = overrides.add({
GIT_CONFIG_COUNT: "1",
GIT_CONFIG_KEY_0: "url.http://172.17.0.1:40123/.insteadOf",
GIT_CONFIG_VALUE_0: "https://gitlab.com/",
});
const expectedEnv = {
PATH: "/bin",
GIT_CONFIG_COUNT: "1",
GIT_CONFIG_KEY_0: "url.http://172.17.0.1:40123/.insteadOf",
GIT_CONFIG_VALUE_0: "https://gitlab.com/",
};
expect(overrides.apply({ PATH: "/bin" })).toEqual(expectedEnv);
expect(overrides.apply({ PATH: "/bin" })).toEqual(expectedEnv);
expect(() =>
overrides.add({ GIT_CONFIG_KEY_0: "url.http://172.17.0.1:40124/.insteadOf" }),
).toThrow("conflicting backend fixture environment override");
release();
expect(overrides.apply({ PATH: "/bin" })).toEqual({ PATH: "/bin" });
});
test("merges one-shot restart values without overriding an active scoped value", () => {
const overrides = new BackendFixtureEnvOverrides();
const release = overrides.add({ GIT_CONFIG_COUNT: "1" });
expect(overrides.apply({ PATH: "/bin" }, { KANDEV_MOCK_AGENT: "only" })).toEqual({
PATH: "/bin",
GIT_CONFIG_COUNT: "1",
KANDEV_MOCK_AGENT: "only",
});
expect(overrides.apply({ PATH: "/bin" }, { GIT_CONFIG_COUNT: "1" })).toEqual({
PATH: "/bin",
GIT_CONFIG_COUNT: "1",
});
expect(() => overrides.apply({ PATH: "/bin" }, { GIT_CONFIG_COUNT: "2" })).toThrow(
"conflicting backend fixture environment override",
);
release();
});
test("restores the baseline environment after activation and restoration both fail", async () => {
const overrides = new BackendFixtureEnvOverrides();
const activationError = new Error("activation failed");
const restoreError = new Error("baseline restoration failed");
const outcomes = [activationError, restoreError];
const observedEnvironments: Record<string, string>[] = [];
const useEnv = createScopedEnvUse(overrides, async () => {
observedEnvironments.push(overrides.apply({ PATH: "/bin" }));
throw outcomes.shift();
});
await expect(useEnv({ GIT_CONFIG_COUNT: "1" })).rejects.toMatchObject({
errors: [activationError, restoreError],
message: "failed to activate backend fixture environment and restore baseline",
});
expect(observedEnvironments).toEqual([{ PATH: "/bin", GIT_CONFIG_COUNT: "1" }, { PATH: "/bin" }]);
expect(overrides.apply({ PATH: "/bin" })).toEqual({ PATH: "/bin" });
});
test("retries release until the baseline restart is healthy", async () => {
const overrides = new BackendFixtureEnvOverrides();
const releaseError = new Error("baseline restart failed");
const outcomes = [undefined, releaseError, undefined];
const observedEnvironments: Record<string, string>[] = [];
const useEnv = createScopedEnvUse(overrides, async () => {
observedEnvironments.push(overrides.apply({ PATH: "/bin" }));
const outcome = outcomes.shift();
if (outcome) throw outcome;
});
const release = await useEnv({ GIT_CONFIG_COUNT: "1" });
await expect(release()).rejects.toThrow("baseline restart failed");
expect(overrides.apply({ PATH: "/bin" })).toEqual({ PATH: "/bin" });
await release();
await release();
expect(observedEnvironments).toEqual([
{ PATH: "/bin", GIT_CONFIG_COUNT: "1" },
{ PATH: "/bin" },
{ PATH: "/bin" },
]);
});