* fix(projects): restore cross-host grouping Random host-local project IDs replaced the remote-derived value that had also served as grouping identity. Persist a separate opaque group key and let normal boot reconciliation backfill older records without a migration. * fix(projects): keep ambiguous clones separate A shared remote can identify a project across hosts, but it cannot distinguish two independent clones on one host. Treat those keys as ambiguous so host-local project IDs remain separate. * fix(projects): preserve host-local project identity * fix(projects): strengthen grouping identity * test(app): update project host shape contract * fix(projects): preserve selected host identity * fix(projects): close grouped routing gaps * fix(projects): stabilize legacy subproject grouping * fix(projects): preserve selected project identity * fix(projects): isolate legacy host identity * fix(projects): preserve symlinked bootstrap roots * fix(projects): reconcile grouped custom names * fix(projects): stabilize settings and path identity * fix(projects): normalize default remote ports * fix(projects): harden host and remote identity * fix(projects): preserve host-scoped actions * fix(projects): preserve remote path semantics * fix(projects): model SCP remote semantics * fix(projects): keep settings on routed host * fix(projects): preserve SSH URL path semantics * fix(projects): separate identity from presentation * test(projects): use grouped identity in UI specs * fix(projects): harden grouped project routing * test(projects): expect framed settings route * fix(projects): preserve exact placement identity * fix(projects): harden grouping identity and routing * fix(projects): restore project key as grouping identity Random host-local project IDs had replaced the persisted cross-host value carried by projectKey. Keep projectId for routing while reconciliation owns and persists projectKey for grouping. * fix(projects): prevent project key collisions Preserve platform path semantics and generic remote transports in cross-host keys, and compare legacy checkout roots using filesystem equivalence before materializing ownership. * test(projects): assert host-scoped project keys * fix(projects): preserve project key compatibility Resolve legacy workspace project references at the daemon boundary while keeping projectKey as the cross-host identity. Complete generic SSH normalization without collapsing distinct repositories. * fix(projects): harden project reference identity * fix(projects): retain archived reference errors * fix(projects): scope legacy paths to hosts * test(app): model persisted project keys * fix(projects): retain absolute scp users * fix(projects): resolve legacy mutation aliases * fix(projects): preserve conservative identity boundaries * fix(projects): preserve legacy placement identity * test(projects): assert legacy placement identity * test(projects): expect canonical Windows keys * fix(projects): separate bootstrap identity fields * fix(projects): scope legacy paths by host * fix(projects): stabilize opaque project identity * fix(projects): preserve remaining opaque identities * fix(projects): classify forward-slash UNC roots * fix(projects): preserve opaque selection keys * fix(projects): frame host-local project keys * fix(projects): canonicalize framed identities * test(projects): isolate repeated remote fixtures * fix(projects): keep project key as UI identity * fix(projects): reconcile hydrated project references * fix(projects): preserve archived project identity * refactor(projects): group projects from project records, not workspaces Cross-host grouping had been built by hanging a projectKey off every workspace descriptor. That scoped the key to the wrong entity: the app then had to reconstruct project identity per workspace in six modules, which forced projectKey fallbacks into RPC arguments and a server-side resolver that turned grouping keys back into project ids. A workspace has a projectId. The key belongs to the project, and grouping is a display concern, so the daemon now publishes projects over project.list plus the existing project.update channel and the app groups them in one place. Projects are addressed by host-local projectId everywhere, including the settings route. Projects persisted without a key are backfilled by ordinary boot reconciliation, with no migration. Old daemons advertise no projectList capability and simply do not group. * test(projects): seed projects alongside workspaces in fixtures Sidebar fixtures seeded workspaces without their projects, which the daemon cannot produce now that projects arrive on their own channel, so nothing rendered. Adds a seeding helper that supplies both. Also drops the provisioning test for accepting a project key where a project id belongs; that resolver was removed deliberately. * fix(projects): keep derived project identity stable Four gaps left by shrinking the key derivation: Local keys used a bare path resolve, so one directory reached by a different spelling produced a different key and reset grouped identity. Windows CI caught this with the 8.3 and long-name forms of one temp path. Canonicalize through the shared realpath-aware normalization. Subproject display names lost their selected-path input, so every subproject of a monorepo rendered under the same remote-derived name. Reconciliation only ever backfilled a missing key, so a project whose remote changed stayed grouped with hosts on the old remote. Project settings kept a disconnected host selected and rendered a dead end with no way back to an editable host. * fix(projects): read scheme remotes as URLs, not scp form An `ssh://user@host:22/org/repo` remote matched the scp-form pattern first, because `[^@]+` happily eats `ssh://git`, so the port landed in the path and the project keyed as `remote:host/22/org/repo`. Two spellings of one remote therefore never grouped. Try scp form only when there is no scheme, and drop protocol-default ports so an explicitly written `:22` matches the same remote without it.
680 lines
20 KiB
TypeScript
680 lines
20 KiB
TypeScript
import type {
|
|
AgentMode,
|
|
AgentModelDefinition,
|
|
ProviderSnapshotEntry,
|
|
} from "@getpaseo/protocol/agent-types";
|
|
import type { ScheduleSummary } from "@getpaseo/protocol/schedule/types";
|
|
import type { FormPreferences } from "@/create-agent-preferences/preferences";
|
|
import { describe, expect, it } from "vitest";
|
|
import { buildProjectOptionId, type ScheduleProjectTarget } from "./schedule-project-targets";
|
|
import { openScheduleForm, type ScheduleFormSnapshot } from "./schedule-form-model";
|
|
|
|
type TestSchedule = ScheduleSummary & { serverId: string; serverName: string };
|
|
|
|
const HOSTS = [
|
|
{ serverId: "host-a", label: "Host A", supportsWorkspaceMultiplicity: true },
|
|
{ serverId: "host-b", label: "Host B", supportsWorkspaceMultiplicity: true },
|
|
] as const;
|
|
|
|
const MOCK_MODES: AgentMode[] = [{ id: "load-test", label: "Load test" }];
|
|
|
|
const HOST_A_MODELS: AgentModelDefinition[] = [
|
|
{
|
|
provider: "mock",
|
|
id: "model-a",
|
|
label: "Model A",
|
|
isDefault: true,
|
|
},
|
|
];
|
|
|
|
const HOST_B_MODELS: AgentModelDefinition[] = [
|
|
{
|
|
provider: "mock",
|
|
id: "model-b",
|
|
label: "Model B",
|
|
isDefault: true,
|
|
defaultThinkingOptionId: "high",
|
|
thinkingOptions: [
|
|
{ id: "low", label: "Low" },
|
|
{ id: "high", label: "High", isDefault: true },
|
|
],
|
|
},
|
|
];
|
|
|
|
const ALL_MODELS = [...HOST_A_MODELS, ...HOST_B_MODELS];
|
|
|
|
function target(input: {
|
|
serverId: string;
|
|
projectKey: string;
|
|
projectName: string;
|
|
cwd: string;
|
|
isGit?: boolean;
|
|
}): ScheduleProjectTarget {
|
|
return {
|
|
optionId: buildProjectOptionId(input.serverId, input.projectKey),
|
|
serverId: input.serverId,
|
|
serverName: input.serverId === "host-a" ? "Host A" : "Host B",
|
|
projectKey: input.projectKey,
|
|
projectName: input.projectName,
|
|
cwd: input.cwd,
|
|
isGit: input.isGit ?? true,
|
|
};
|
|
}
|
|
|
|
const PROJECT_TARGETS = [
|
|
target({
|
|
serverId: "host-a",
|
|
projectKey: "project-a",
|
|
projectName: "Project A",
|
|
cwd: "/repo/a",
|
|
}),
|
|
target({
|
|
serverId: "host-b",
|
|
projectKey: "project-b",
|
|
projectName: "Project B",
|
|
cwd: "/repo/b",
|
|
}),
|
|
];
|
|
|
|
function scheduleOnHost(input: {
|
|
serverId: string;
|
|
serverName: string;
|
|
cwd: string;
|
|
model: string;
|
|
cadence?: ScheduleSummary["cadence"];
|
|
}): TestSchedule {
|
|
return {
|
|
id: `schedule-${input.serverId}`,
|
|
serverId: input.serverId,
|
|
serverName: input.serverName,
|
|
name: "Nightly",
|
|
prompt: "Run the schedule",
|
|
cadence: input.cadence ?? { type: "cron", expression: "0 9 * * *" },
|
|
target: {
|
|
type: "new-agent",
|
|
config: {
|
|
provider: "mock",
|
|
cwd: input.cwd,
|
|
model: input.model,
|
|
modeId: "load-test",
|
|
thinkingOptionId: "high",
|
|
archiveOnFinish: false,
|
|
isolation: "worktree",
|
|
},
|
|
},
|
|
status: "active",
|
|
createdAt: "2026-07-01T00:00:00.000Z",
|
|
updatedAt: "2026-07-01T00:00:00.000Z",
|
|
nextRunAt: "2026-07-02T00:00:00.000Z",
|
|
lastRunAt: null,
|
|
pausedAt: null,
|
|
expiresAt: null,
|
|
maxRuns: 3,
|
|
};
|
|
}
|
|
|
|
function heartbeatOnHost(cadence: ScheduleSummary["cadence"]): TestSchedule {
|
|
return {
|
|
id: "heartbeat-host-a",
|
|
serverId: "host-a",
|
|
serverName: "Host A",
|
|
name: "Babysit",
|
|
prompt: "Check status",
|
|
cadence,
|
|
target: { type: "agent", agentId: "agent-1" },
|
|
status: "active",
|
|
createdAt: "2026-07-01T00:00:00.000Z",
|
|
updatedAt: "2026-07-01T00:00:00.000Z",
|
|
nextRunAt: "2026-07-02T00:00:00.000Z",
|
|
lastRunAt: null,
|
|
pausedAt: null,
|
|
expiresAt: null,
|
|
maxRuns: null,
|
|
};
|
|
}
|
|
|
|
function providerSnapshot(models: AgentModelDefinition[]): { entries: ProviderSnapshotEntry[] } {
|
|
return {
|
|
entries: [
|
|
{
|
|
provider: "mock",
|
|
label: "Mock",
|
|
status: "ready",
|
|
enabled: true,
|
|
fetchedAt: "2026-07-01T00:00:00.000Z",
|
|
models,
|
|
modes: MOCK_MODES,
|
|
defaultModeId: "load-test",
|
|
},
|
|
],
|
|
};
|
|
}
|
|
|
|
function open(snapshot: Omit<ScheduleFormSnapshot, "hosts">) {
|
|
return openScheduleForm({
|
|
...snapshot,
|
|
hosts: HOSTS,
|
|
});
|
|
}
|
|
|
|
function openWithHosts(snapshot: ScheduleFormSnapshot) {
|
|
return openScheduleForm(snapshot);
|
|
}
|
|
|
|
function applyPreferences(form: ReturnType<typeof open>, preferences: FormPreferences) {
|
|
form.applyPreferences(preferences);
|
|
}
|
|
|
|
describe("schedule form model", () => {
|
|
it("opens edit from the schedule host snapshot and completes that host resolution", () => {
|
|
const previous = open({
|
|
mode: "edit",
|
|
schedule: scheduleOnHost({
|
|
serverId: "host-a",
|
|
serverName: "Host A",
|
|
cwd: "/repo/a",
|
|
model: "model-a",
|
|
}),
|
|
defaults: { serverId: null, projectTargets: PROJECT_TARGETS, preferences: {} },
|
|
});
|
|
previous.applyProviderSnapshot("host-a", providerSnapshot(HOST_A_MODELS));
|
|
previous.close();
|
|
|
|
const form = open({
|
|
mode: "edit",
|
|
schedule: scheduleOnHost({
|
|
serverId: "host-b",
|
|
serverName: "Host B",
|
|
cwd: "/repo/b",
|
|
model: "model-b",
|
|
}),
|
|
defaults: { serverId: null, projectTargets: PROJECT_TARGETS, preferences: {} },
|
|
});
|
|
|
|
expect(form.getState()).toMatchObject({
|
|
mode: "edit",
|
|
selectedServerId: "host-b",
|
|
workingDir: "/repo/b",
|
|
selectedProvider: "mock",
|
|
selectedModel: "model-b",
|
|
selectedMode: "load-test",
|
|
selectedThinkingOptionId: "high",
|
|
projectDisplay: { label: "Project B" },
|
|
selectedProjectOptionId: buildProjectOptionId("host-b", "project-b"),
|
|
archiveOnFinish: false,
|
|
isolation: "worktree",
|
|
effectiveIsolation: "worktree",
|
|
providerResolutionByServerId: { "host-b": "pending" },
|
|
providerSnapshotRequest: {
|
|
serverId: "host-b",
|
|
cwd: "/repo/b",
|
|
},
|
|
});
|
|
|
|
form.applyProviderSnapshot("host-b", providerSnapshot(HOST_B_MODELS));
|
|
|
|
expect(form.getState()).toMatchObject({
|
|
selectedServerId: "host-b",
|
|
selectedModelDisplay: { label: "Model B" },
|
|
selectedModeDisplay: { label: "Load test" },
|
|
selectedThinkingDisplay: { label: "High" },
|
|
providerResolutionByServerId: { "host-b": "complete" },
|
|
providerSnapshotRequest: null,
|
|
});
|
|
});
|
|
|
|
it("opens create pristine after an edit instance closes", () => {
|
|
const edit = open({
|
|
mode: "edit",
|
|
schedule: scheduleOnHost({
|
|
serverId: "host-b",
|
|
serverName: "Host B",
|
|
cwd: "/repo/b",
|
|
model: "model-b",
|
|
}),
|
|
defaults: { serverId: null, projectTargets: PROJECT_TARGETS, preferences: {} },
|
|
});
|
|
edit.close();
|
|
|
|
const create = open({
|
|
mode: "create",
|
|
defaults: { serverId: "host-a", projectTargets: PROJECT_TARGETS, preferences: {} },
|
|
});
|
|
|
|
expect(create.getState()).toMatchObject({
|
|
mode: "create",
|
|
selectedServerId: "host-a",
|
|
workingDir: "",
|
|
selectedProvider: null,
|
|
selectedModel: "",
|
|
selectedMode: "",
|
|
selectedThinkingOptionId: "",
|
|
projectDisplay: null,
|
|
selectedProjectOptionId: "",
|
|
selectedModelDisplay: null,
|
|
selectedThinkingDisplay: null,
|
|
archiveOnFinish: true,
|
|
isolation: "local",
|
|
effectiveIsolation: "local",
|
|
providerResolutionByServerId: {},
|
|
});
|
|
});
|
|
|
|
it("derives the host to project to model disclosure chain from model state", () => {
|
|
const form = open({
|
|
mode: "create",
|
|
defaults: { serverId: "host-a", projectTargets: PROJECT_TARGETS, preferences: {} },
|
|
});
|
|
|
|
expect(form.getState().disclosure).toEqual({
|
|
showProjectField: true,
|
|
showModelField: false,
|
|
showThinkingField: false,
|
|
showModeField: false,
|
|
showIsolationField: false,
|
|
showArchiveOnFinishField: false,
|
|
});
|
|
|
|
form.setProject(buildProjectOptionId("host-a", "project-a"), { label: "Project A" });
|
|
|
|
expect(form.getState().disclosure).toEqual({
|
|
showProjectField: true,
|
|
showModelField: true,
|
|
showThinkingField: false,
|
|
showModeField: false,
|
|
showIsolationField: true,
|
|
showArchiveOnFinishField: true,
|
|
});
|
|
|
|
form.applyProviderSnapshot("host-a", providerSnapshot(HOST_B_MODELS));
|
|
form.setModel("mock", "model-b");
|
|
|
|
expect(form.getState().disclosure).toEqual({
|
|
showProjectField: true,
|
|
showModelField: true,
|
|
showThinkingField: true,
|
|
showModeField: true,
|
|
showIsolationField: true,
|
|
showArchiveOnFinishField: true,
|
|
});
|
|
});
|
|
|
|
it("hides isolation unless the selected project can create a worktree", () => {
|
|
const nonGitTarget = target({
|
|
serverId: "host-a",
|
|
projectKey: "plain-project",
|
|
projectName: "Plain Project",
|
|
cwd: "/tmp/plain",
|
|
isGit: false,
|
|
});
|
|
const nonGit = open({
|
|
mode: "create",
|
|
defaults: { serverId: "host-a", projectTargets: [nonGitTarget], preferences: {} },
|
|
});
|
|
|
|
nonGit.setProject(nonGitTarget.optionId, { label: "Plain Project" });
|
|
|
|
expect(nonGit.getState().disclosure).toMatchObject({
|
|
showIsolationField: false,
|
|
showArchiveOnFinishField: true,
|
|
});
|
|
|
|
const gitTarget = target({
|
|
serverId: "host-a",
|
|
projectKey: "git-project",
|
|
projectName: "Git Project",
|
|
cwd: "/tmp/git",
|
|
isGit: true,
|
|
});
|
|
const unsupportedHost = openWithHosts({
|
|
mode: "create",
|
|
hosts: [{ serverId: "host-a", label: "Host A" }],
|
|
defaults: { serverId: "host-a", projectTargets: [gitTarget], preferences: {} },
|
|
});
|
|
|
|
unsupportedHost.setProject(gitTarget.optionId, { label: "Git Project" });
|
|
|
|
expect(unsupportedHost.getState().disclosure).toMatchObject({
|
|
showIsolationField: false,
|
|
showArchiveOnFinishField: false,
|
|
});
|
|
expect(
|
|
Object.prototype.hasOwnProperty.call(unsupportedHost.getState(), "submitIsolation"),
|
|
).toBe(true);
|
|
expect(
|
|
Object.prototype.hasOwnProperty.call(unsupportedHost.getState(), "submitArchiveOnFinish"),
|
|
).toBe(true);
|
|
expect(
|
|
(unsupportedHost.getState() as unknown as { submitIsolation?: string }).submitIsolation,
|
|
).toBeUndefined();
|
|
expect(
|
|
(unsupportedHost.getState() as unknown as { submitArchiveOnFinish?: boolean })
|
|
.submitArchiveOnFinish,
|
|
).toBeUndefined();
|
|
});
|
|
|
|
it("shows modes for providers without selectable models", () => {
|
|
const form = open({
|
|
mode: "create",
|
|
defaults: { serverId: "host-a", projectTargets: PROJECT_TARGETS, preferences: {} },
|
|
});
|
|
|
|
form.setProject(buildProjectOptionId("host-a", "project-a"), { label: "Project A" });
|
|
form.applyProviderSnapshot("host-a", providerSnapshot([]));
|
|
form.setModel("mock", "");
|
|
|
|
expect(form.getState()).toMatchObject({
|
|
selectedProvider: "mock",
|
|
selectedModel: "",
|
|
disclosure: {
|
|
showModeField: true,
|
|
showThinkingField: false,
|
|
},
|
|
});
|
|
});
|
|
|
|
it("preserves stored worktree isolation until host resolution proves it unavailable", () => {
|
|
const nonGitTarget = target({
|
|
serverId: "host-b",
|
|
projectKey: "plain-project",
|
|
projectName: "Plain Project",
|
|
cwd: "/repo/b",
|
|
isGit: false,
|
|
});
|
|
const form = open({
|
|
mode: "edit",
|
|
schedule: scheduleOnHost({
|
|
serverId: "host-b",
|
|
serverName: "Host B",
|
|
cwd: "/repo/b",
|
|
model: "model-b",
|
|
}),
|
|
defaults: { serverId: null, projectTargets: [nonGitTarget], preferences: {} },
|
|
});
|
|
|
|
expect(form.getState()).toMatchObject({
|
|
isolation: "worktree",
|
|
effectiveIsolation: "worktree",
|
|
canUseWorktreeIsolation: false,
|
|
providerResolutionByServerId: { "host-b": "pending" },
|
|
});
|
|
|
|
form.applyProviderSnapshot("host-b", providerSnapshot(HOST_B_MODELS));
|
|
|
|
expect(form.getState()).toMatchObject({
|
|
isolation: "worktree",
|
|
effectiveIsolation: "local",
|
|
canUseWorktreeIsolation: false,
|
|
providerResolutionByServerId: { "host-b": "complete" },
|
|
});
|
|
});
|
|
|
|
it("displays a representable legacy interval without submitting a cadence change", () => {
|
|
const form = open({
|
|
mode: "edit",
|
|
schedule: scheduleOnHost({
|
|
serverId: "host-a",
|
|
serverName: "Host A",
|
|
cwd: "/repo/a",
|
|
model: "model-a",
|
|
cadence: { type: "every", everyMs: 60_000 },
|
|
}),
|
|
defaults: {
|
|
serverId: null,
|
|
projectTargets: PROJECT_TARGETS,
|
|
preferences: {},
|
|
timezone: "Europe/Madrid",
|
|
},
|
|
});
|
|
|
|
expect(form.getState().cadence).toEqual({
|
|
type: "cron",
|
|
expression: "* * * * *",
|
|
timezone: "Europe/Madrid",
|
|
});
|
|
form.setName("Renamed without touching cadence");
|
|
|
|
expect(form.getState().submitCadence).toBeUndefined();
|
|
});
|
|
|
|
it("does not rewrite an unrepresentable legacy interval until cadence changes", () => {
|
|
const originalCadence = { type: "every" as const, everyMs: 90 * 60_000 };
|
|
const form = open({
|
|
mode: "edit",
|
|
schedule: scheduleOnHost({
|
|
serverId: "host-a",
|
|
serverName: "Host A",
|
|
cwd: "/repo/a",
|
|
model: "model-a",
|
|
cadence: originalCadence,
|
|
}),
|
|
defaults: {
|
|
serverId: null,
|
|
projectTargets: PROJECT_TARGETS,
|
|
preferences: {},
|
|
timezone: "Europe/Madrid",
|
|
},
|
|
});
|
|
|
|
expect(form.getState().cadence).toEqual({
|
|
type: "cron",
|
|
expression: "*/59 * * * *",
|
|
timezone: "Europe/Madrid",
|
|
});
|
|
|
|
form.setName("Renamed without touching cadence");
|
|
|
|
expect(form.getState().submitCadence).toBeUndefined();
|
|
|
|
form.setCadence({
|
|
type: "cron",
|
|
expression: "0 9 * * *",
|
|
timezone: "Europe/Madrid",
|
|
});
|
|
|
|
expect(form.getState().submitCadence).toEqual({
|
|
type: "cron",
|
|
expression: "0 9 * * *",
|
|
timezone: "Europe/Madrid",
|
|
});
|
|
});
|
|
|
|
it("requires a cron choice before updating a legacy heartbeat", () => {
|
|
const form = open({
|
|
mode: "edit",
|
|
schedule: heartbeatOnHost({ type: "every", everyMs: 90 * 60_000 }),
|
|
defaults: {
|
|
serverId: null,
|
|
projectTargets: PROJECT_TARGETS,
|
|
preferences: {},
|
|
timezone: "Europe/Madrid",
|
|
},
|
|
});
|
|
|
|
expect(form.getState()).toMatchObject({ targetKind: "agent", canSubmit: false });
|
|
|
|
form.setCadence({ type: "cron", expression: "0 9 * * *", timezone: "Europe/Madrid" });
|
|
|
|
expect(form.getState()).toMatchObject({
|
|
submitCadence: { type: "cron", expression: "0 9 * * *", timezone: "Europe/Madrid" },
|
|
canSubmit: true,
|
|
});
|
|
});
|
|
|
|
it("clears provider selection while resolving a different project", () => {
|
|
const form = open({
|
|
mode: "create",
|
|
defaults: { serverId: "host-a", projectTargets: PROJECT_TARGETS, preferences: {} },
|
|
});
|
|
form.setPrompt("Run on a selected project.");
|
|
form.setProject(buildProjectOptionId("host-a", "project-a"), { label: "Project A" });
|
|
form.applyProviderSnapshot("host-a", providerSnapshot(HOST_A_MODELS));
|
|
form.setModel("mock", "model-a");
|
|
|
|
expect(form.getState()).toMatchObject({
|
|
selectedServerId: "host-a",
|
|
workingDir: "/repo/a",
|
|
selectedProvider: "mock",
|
|
selectedModel: "model-a",
|
|
canSubmit: true,
|
|
});
|
|
|
|
form.setProject(buildProjectOptionId("host-b", "project-b"), { label: "Project B" });
|
|
|
|
expect(form.getState()).toMatchObject({
|
|
selectedServerId: "host-b",
|
|
workingDir: "/repo/b",
|
|
selectedProvider: null,
|
|
selectedModel: "",
|
|
modelSelectorProviders: [],
|
|
canSubmit: false,
|
|
providerResolutionByServerId: { "host-a": "complete", "host-b": "pending" },
|
|
providerSnapshotRequest: { serverId: "host-b", cwd: "/repo/b" },
|
|
});
|
|
|
|
form.applyProviderSnapshot("host-b", providerSnapshot(HOST_B_MODELS));
|
|
|
|
expect(form.getState()).toMatchObject({
|
|
selectedServerId: "host-b",
|
|
selectedProvider: null,
|
|
selectedModel: "",
|
|
providerResolutionByServerId: { "host-a": "complete", "host-b": "complete" },
|
|
providerSnapshotRequest: null,
|
|
modelSelectorProviders: [expect.objectContaining({ id: "mock", label: "Mock" })],
|
|
});
|
|
});
|
|
|
|
it("applies new project targets without resetting selected values", () => {
|
|
const projectA = PROJECT_TARGETS[0];
|
|
const form = open({
|
|
mode: "create",
|
|
defaults: { serverId: "host-a", projectTargets: [projectA], preferences: {} },
|
|
});
|
|
form.setName("Draft name");
|
|
form.setPrompt("Draft prompt");
|
|
form.setProject(projectA.optionId, { label: "Project A" });
|
|
|
|
form.applyProjectTargets([
|
|
projectA,
|
|
target({
|
|
serverId: "host-a",
|
|
projectKey: "project-c",
|
|
projectName: "Project C",
|
|
cwd: "/repo/c",
|
|
}),
|
|
]);
|
|
|
|
expect(form.getState()).toMatchObject({
|
|
name: "Draft name",
|
|
prompt: "Draft prompt",
|
|
selectedServerId: "host-a",
|
|
workingDir: "/repo/a",
|
|
projectDisplay: { label: "Project A" },
|
|
selectedProjectOptionId: projectA.optionId,
|
|
projectOptions: [
|
|
{
|
|
id: projectA.optionId,
|
|
value: projectA.optionId,
|
|
label: "Project A",
|
|
testID: "schedule-project-option-project-a",
|
|
},
|
|
{
|
|
id: buildProjectOptionId("host-a", "project-c"),
|
|
value: buildProjectOptionId("host-a", "project-c"),
|
|
label: "Project C",
|
|
testID: "schedule-project-option-project-c",
|
|
},
|
|
],
|
|
});
|
|
});
|
|
|
|
it("hydrates an edited schedule's project label when its host targets arrive", () => {
|
|
const form = open({
|
|
mode: "edit",
|
|
schedule: scheduleOnHost({
|
|
serverId: "host-b",
|
|
serverName: "Host B",
|
|
cwd: "/repo/b",
|
|
model: "model-b",
|
|
}),
|
|
defaults: { serverId: null, projectTargets: [], preferences: {} },
|
|
});
|
|
|
|
expect(form.getState().projectDisplay).toEqual({ label: "/repo/b" });
|
|
|
|
form.applyProjectTargets(PROJECT_TARGETS);
|
|
|
|
expect(form.getState()).toMatchObject({
|
|
projectDisplay: { label: "Project B" },
|
|
selectedProjectOptionId: buildProjectOptionId("host-b", "project-b"),
|
|
});
|
|
});
|
|
|
|
it("hydrates late create preferences without overwriting user changes or edited schedules", () => {
|
|
const savedPreferences: FormPreferences = {
|
|
provider: "mock",
|
|
providerPreferences: {
|
|
mock: {
|
|
model: "model-b",
|
|
mode: "load-test",
|
|
thinkingByModel: { "model-b": "high" },
|
|
},
|
|
},
|
|
isolation: "worktree",
|
|
};
|
|
|
|
const create = open({
|
|
mode: "create",
|
|
defaults: { serverId: "host-a", projectTargets: PROJECT_TARGETS, preferences: {} },
|
|
});
|
|
create.applyProviderSnapshot("host-a", providerSnapshot(ALL_MODELS));
|
|
|
|
applyPreferences(create, savedPreferences);
|
|
|
|
expect(create.getState()).toMatchObject({
|
|
selectedProvider: "mock",
|
|
selectedModel: "model-b",
|
|
selectedMode: "load-test",
|
|
selectedThinkingOptionId: "high",
|
|
isolation: "worktree",
|
|
});
|
|
|
|
const userEdited = open({
|
|
mode: "create",
|
|
defaults: { serverId: "host-a", projectTargets: PROJECT_TARGETS, preferences: {} },
|
|
});
|
|
userEdited.applyProviderSnapshot("host-a", providerSnapshot(ALL_MODELS));
|
|
userEdited.setModel("mock", "model-a");
|
|
userEdited.setIsolation("local");
|
|
|
|
applyPreferences(userEdited, savedPreferences);
|
|
|
|
expect(userEdited.getState()).toMatchObject({
|
|
selectedProvider: "mock",
|
|
selectedModel: "model-a",
|
|
isolation: "local",
|
|
});
|
|
|
|
const edit = open({
|
|
mode: "edit",
|
|
schedule: scheduleOnHost({
|
|
serverId: "host-a",
|
|
serverName: "Host A",
|
|
cwd: "/repo/a",
|
|
model: "model-a",
|
|
}),
|
|
defaults: { serverId: null, projectTargets: PROJECT_TARGETS, preferences: {} },
|
|
});
|
|
edit.applyProviderSnapshot("host-a", providerSnapshot(ALL_MODELS));
|
|
|
|
applyPreferences(edit, { ...savedPreferences, isolation: "local" });
|
|
|
|
expect(edit.getState()).toMatchObject({
|
|
selectedProvider: "mock",
|
|
selectedModel: "model-a",
|
|
selectedMode: "load-test",
|
|
isolation: "worktree",
|
|
});
|
|
});
|
|
});
|