+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
393 lines
16 KiB
TypeScript
393 lines
16 KiB
TypeScript
import {
|
|
DEFAULT_SERVER_SETTINGS,
|
|
PROJECT_SCOPED_SERVER_SETTING_KEYS,
|
|
ProjectId,
|
|
ProviderInstanceId,
|
|
} from "@t3tools/contracts";
|
|
import { describe, expect, it } from "vite-plus/test";
|
|
import { createModelSelection } from "./model.ts";
|
|
import {
|
|
clearProjectSettingsOverrides,
|
|
hasProjectSettingsOverrides,
|
|
resolveProjectFileBackedSetting,
|
|
resolveProjectSettings,
|
|
resolveWorktreeCleanup,
|
|
withProjectSettingsOverrides,
|
|
} from "./projectSettings.ts";
|
|
import { applyServerSettingsPatch } from "./serverSettings.ts";
|
|
|
|
const projectId = ProjectId.make("project-a");
|
|
const otherProjectId = ProjectId.make("project-b");
|
|
|
|
describe("resolveProjectSettings", () => {
|
|
it("inherits every scopable key when the project has no overrides", () => {
|
|
const resolved = resolveProjectSettings(DEFAULT_SERVER_SETTINGS, projectId);
|
|
expect(resolved.settings).toBe(DEFAULT_SERVER_SETTINGS);
|
|
for (const key of PROJECT_SCOPED_SERVER_SETTING_KEYS) {
|
|
expect(resolved.sources[key]).toBe("environment");
|
|
}
|
|
expect(resolveProjectSettings(DEFAULT_SERVER_SETTINGS, null).settings).toBe(
|
|
DEFAULT_SERVER_SETTINGS,
|
|
);
|
|
});
|
|
|
|
it("ignores an override left undefined by a forward-compatible decode", () => {
|
|
const resolved = resolveProjectSettings(
|
|
{
|
|
...DEFAULT_SERVER_SETTINGS,
|
|
defaultRuntimeMode: "full-access",
|
|
projectSettingsOverrides: { [projectId]: { defaultRuntimeMode: undefined } as never },
|
|
},
|
|
projectId,
|
|
);
|
|
expect(resolved.settings.defaultRuntimeMode).toBe("full-access");
|
|
expect(resolved.sources.defaultRuntimeMode).toBe("environment");
|
|
expect(
|
|
hasProjectSettingsOverrides({
|
|
projectSettingsOverrides: { [projectId]: { defaultRuntimeMode: undefined } as never },
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
|
|
it("treats a null project like an absent one before the shell snapshot arrives", () => {
|
|
// The mobile new-task flow resolves settings while its selected project is
|
|
// still null; reading the aggregate's legacy fields off null crashed launch.
|
|
expect(resolveProjectSettings(DEFAULT_SERVER_SETTINGS, null, null).settings).toBe(
|
|
DEFAULT_SERVER_SETTINGS,
|
|
);
|
|
});
|
|
|
|
it("applies overrides per key and reports their source", () => {
|
|
const settings = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
|
|
defaultAutoPull: true,
|
|
sidebarAutoSettleAfterDays: 3,
|
|
projectSettingsOverrides: {
|
|
[projectId]: { defaultAutoPull: false, sidebarAutoSettleAfterDays: null },
|
|
},
|
|
});
|
|
const resolved = resolveProjectSettings(settings, projectId);
|
|
expect(resolved.settings.defaultAutoPull).toBe(false);
|
|
expect(resolved.settings.sidebarAutoSettleAfterDays).toBeNull();
|
|
expect(resolved.settings.defaultThreadEnvMode).toBe(settings.defaultThreadEnvMode);
|
|
expect(resolved.sources.defaultAutoPull).toBe("project");
|
|
expect(resolved.sources.sidebarAutoSettleAfterDays).toBe("project");
|
|
expect(resolved.sources.defaultThreadEnvMode).toBe("environment");
|
|
expect(resolveProjectSettings(settings, otherProjectId).settings.defaultAutoPull).toBe(true);
|
|
});
|
|
|
|
it("keeps the environment text generation model when the override's provider is disabled", () => {
|
|
const disabledSelection = createModelSelection(ProviderInstanceId.make("claudeAgent"), "opus");
|
|
const settings = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
|
|
providers: { claudeAgent: { enabled: false } },
|
|
projectSettingsOverrides: {
|
|
[projectId]: { textGenerationModelSelection: disabledSelection },
|
|
},
|
|
});
|
|
const resolved = resolveProjectSettings(settings, projectId);
|
|
expect(resolved.settings.textGenerationModelSelection).toEqual(
|
|
settings.textGenerationModelSelection,
|
|
);
|
|
expect(resolved.sources.textGenerationModelSelection).toBe("environment");
|
|
});
|
|
|
|
it("honours the aggregate's own fields only until the server has folded them", () => {
|
|
const aggregateModel = createModelSelection(ProviderInstanceId.make("codex"), "gpt-5.5");
|
|
const project = {
|
|
defaultModelSelection: aggregateModel,
|
|
defaultThreadEnvMode: "local" as const,
|
|
};
|
|
const unfolded = resolveProjectSettings(
|
|
{ ...DEFAULT_SERVER_SETTINGS, projectSettingsFolded: false },
|
|
projectId,
|
|
project,
|
|
);
|
|
expect(unfolded.settings.defaultModelSelection).toEqual(aggregateModel);
|
|
expect(unfolded.settings.defaultThreadEnvMode).toBe("local");
|
|
expect(unfolded.sources.defaultModelSelection).toBe("project");
|
|
// A stored override still beats the aggregate before the fold.
|
|
const overridden = resolveProjectSettings(
|
|
{
|
|
...DEFAULT_SERVER_SETTINGS,
|
|
projectSettingsFolded: false,
|
|
projectSettingsOverrides: { [projectId]: { defaultThreadEnvMode: "worktree" } },
|
|
},
|
|
projectId,
|
|
project,
|
|
);
|
|
expect(overridden.settings.defaultThreadEnvMode).toBe("worktree");
|
|
// After the fold a reset in the record wins over the stale aggregate.
|
|
const folded = resolveProjectSettings(
|
|
{ ...DEFAULT_SERVER_SETTINGS, projectSettingsFolded: true },
|
|
projectId,
|
|
project,
|
|
);
|
|
expect(folded.settings.defaultModelSelection).toBeNull();
|
|
expect(folded.sources.defaultModelSelection).toBe("environment");
|
|
});
|
|
|
|
it("keeps the environment default model when the override's provider is disabled", () => {
|
|
const disabledSelection = createModelSelection(ProviderInstanceId.make("claudeAgent"), "opus");
|
|
const settings = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
|
|
providers: { claudeAgent: { enabled: false } },
|
|
projectSettingsOverrides: { [projectId]: { defaultModelSelection: disabledSelection } },
|
|
});
|
|
const resolved = resolveProjectSettings(settings, projectId);
|
|
expect(resolved.settings.defaultModelSelection).toBeNull();
|
|
expect(resolved.sources.defaultModelSelection).toBe("environment");
|
|
});
|
|
});
|
|
|
|
describe("resolveProjectSettings with a t3.json", () => {
|
|
it("walks project override, environment value, file, then built-in for file-backed keys", () => {
|
|
const file = { defaultThreadEnvMode: "worktree" as const };
|
|
const fromOverride = resolveProjectSettings(
|
|
{
|
|
...DEFAULT_SERVER_SETTINGS,
|
|
projectSettingsOverrides: { [projectId]: { defaultThreadEnvMode: "local" } },
|
|
},
|
|
projectId,
|
|
null,
|
|
file,
|
|
);
|
|
expect(fromOverride.settings.defaultThreadEnvMode).toBe("local");
|
|
expect(fromOverride.sources.defaultThreadEnvMode).toBe("project");
|
|
|
|
const fromEnvironment = resolveProjectSettings(
|
|
{ ...DEFAULT_SERVER_SETTINGS, defaultThreadEnvMode: "local" },
|
|
projectId,
|
|
null,
|
|
file,
|
|
);
|
|
expect(fromEnvironment.settings.defaultThreadEnvMode).toBe("local");
|
|
expect(fromEnvironment.sources.defaultThreadEnvMode).toBe("environment");
|
|
|
|
const fromFile = resolveProjectSettings(DEFAULT_SERVER_SETTINGS, projectId, null, file);
|
|
expect(fromFile.settings.defaultThreadEnvMode).toBe("worktree");
|
|
expect(fromFile.sources.defaultThreadEnvMode).toBe("t3.json");
|
|
|
|
const builtIn = resolveProjectSettings(DEFAULT_SERVER_SETTINGS, projectId, null, null);
|
|
expect(builtIn.settings.defaultThreadEnvMode).toBe("local");
|
|
expect(builtIn.sources.defaultThreadEnvMode).toBe("environment");
|
|
// A stored null override defers like an unset one and is not reported
|
|
// as the project's value.
|
|
const nullOverride = resolveProjectSettings(
|
|
{
|
|
...DEFAULT_SERVER_SETTINGS,
|
|
projectSettingsOverrides: { [projectId]: { defaultThreadEnvMode: null } as never },
|
|
},
|
|
projectId,
|
|
null,
|
|
file,
|
|
);
|
|
expect(nullOverride.settings.defaultThreadEnvMode).toBe("worktree");
|
|
expect(nullOverride.sources.defaultThreadEnvMode).toBe("t3.json");
|
|
// A file that does not mention the key leaves the source alone too.
|
|
expect(
|
|
resolveProjectSettings(DEFAULT_SERVER_SETTINGS, projectId, null, {}).sources
|
|
.defaultThreadEnvMode,
|
|
).toBe("environment");
|
|
});
|
|
|
|
it("resolves one key from the settings tier, then the file, then the built-in", () => {
|
|
expect(
|
|
resolveProjectFileBackedSetting("worktreeSubmodules", "none", {
|
|
worktreeSubmodules: "top-level",
|
|
}),
|
|
).toEqual({ value: "none", source: "environment" });
|
|
expect(
|
|
resolveProjectFileBackedSetting("worktreeSubmodules", null, {
|
|
worktreeSubmodules: "top-level",
|
|
}),
|
|
).toEqual({ value: "top-level", source: "t3.json" });
|
|
expect(resolveProjectFileBackedSetting("worktreeSubmodules", null, null)).toEqual({
|
|
value: "recursive",
|
|
source: "environment",
|
|
});
|
|
});
|
|
|
|
it("leaves settings untouched when no file is passed", () => {
|
|
expect(resolveProjectSettings(DEFAULT_SERVER_SETTINGS, projectId).settings).toBe(
|
|
DEFAULT_SERVER_SETTINGS,
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("projectSettingsOverrides patches", () => {
|
|
it("replaces a project's entry, removes it with null, and drops empty entries", () => {
|
|
const first = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
|
|
projectSettingsOverrides: {
|
|
[projectId]: { defaultAutoPull: true, enableAgentBrowserAccess: false },
|
|
[otherProjectId]: { defaultAutoPull: false },
|
|
},
|
|
});
|
|
expect(hasProjectSettingsOverrides(first)).toBe(true);
|
|
const replaced = applyServerSettingsPatch(first, {
|
|
projectSettingsOverrides: { [projectId]: { enableAgentBrowserAccess: false } },
|
|
});
|
|
expect(replaced.projectSettingsOverrides[projectId]).toEqual({
|
|
enableAgentBrowserAccess: false,
|
|
});
|
|
expect(replaced.projectSettingsOverrides[otherProjectId]).toEqual({ defaultAutoPull: false });
|
|
const emptied = applyServerSettingsPatch(replaced, {
|
|
projectSettingsOverrides: { [projectId]: {} },
|
|
});
|
|
expect(emptied.projectSettingsOverrides[projectId]).toBeUndefined();
|
|
const removed = applyServerSettingsPatch(replaced, {
|
|
projectSettingsOverrides: { [projectId]: null },
|
|
});
|
|
expect(removed.projectSettingsOverrides).toEqual({
|
|
[otherProjectId]: { defaultAutoPull: false },
|
|
});
|
|
expect(hasProjectSettingsOverrides(DEFAULT_SERVER_SETTINGS)).toBe(false);
|
|
});
|
|
|
|
it("derives the legacy per-key maps from the generic record", () => {
|
|
const settings = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
|
|
projectSettingsOverrides: {
|
|
[projectId]: { defaultAutoPull: true, enableAgentBrowserAccess: false },
|
|
[otherProjectId]: { defaultProjectScripts: [] },
|
|
},
|
|
});
|
|
expect(settings.projectAutoPullOverrides).toEqual({ [projectId]: true });
|
|
expect(settings.projectAgentBrowserAccessOverrides).toEqual({ [projectId]: false });
|
|
expect(settings.projectScriptOverrides).toEqual({ [otherProjectId]: [] });
|
|
});
|
|
|
|
it("translates legacy per-key patches into the generic record", () => {
|
|
const written = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
|
|
projectAutoPullOverrides: { [projectId]: true },
|
|
projectAgentBrowserAccessOverrides: { [projectId]: false, [otherProjectId]: true },
|
|
});
|
|
expect(written.projectSettingsOverrides).toEqual({
|
|
[projectId]: { defaultAutoPull: true, enableAgentBrowserAccess: false },
|
|
[otherProjectId]: { enableAgentBrowserAccess: true },
|
|
});
|
|
const cleared = applyServerSettingsPatch(written, {
|
|
projectAgentBrowserAccessOverrides: { [projectId]: null, [otherProjectId]: null },
|
|
});
|
|
expect(cleared.projectSettingsOverrides).toEqual({ [projectId]: { defaultAutoPull: true } });
|
|
});
|
|
|
|
it("lets a canonical entry win over a legacy map for the same project", () => {
|
|
const current = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
|
|
projectSettingsOverrides: { [projectId]: { defaultAutoPull: true } },
|
|
});
|
|
// The canonical entry omits defaultAutoPull to clear it; the stale legacy
|
|
// map in the same patch must not put it back.
|
|
const next = applyServerSettingsPatch(current, {
|
|
projectSettingsOverrides: { [projectId]: { defaultThreadEnvMode: "local" } },
|
|
projectAutoPullOverrides: { [projectId]: true, [otherProjectId]: false },
|
|
});
|
|
expect(next.projectSettingsOverrides).toEqual({
|
|
[projectId]: { defaultThreadEnvMode: "local" },
|
|
[otherProjectId]: { defaultAutoPull: false },
|
|
});
|
|
});
|
|
|
|
it("builds replacement entries and clears individual keys", () => {
|
|
const settings = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
|
|
projectSettingsOverrides: {
|
|
[projectId]: { defaultAutoPull: true, enableAgentBrowserAccess: false },
|
|
},
|
|
});
|
|
expect(clearProjectSettingsOverrides(settings, projectId, ["defaultAutoPull"])).toEqual({
|
|
enableAgentBrowserAccess: false,
|
|
});
|
|
expect(
|
|
clearProjectSettingsOverrides(settings, projectId, [
|
|
"defaultAutoPull",
|
|
"enableAgentBrowserAccess",
|
|
]),
|
|
).toBeNull();
|
|
expect(clearProjectSettingsOverrides(settings, otherProjectId, ["defaultAutoPull"])).toBeNull();
|
|
expect(withProjectSettingsOverrides(settings, projectId, null)).toEqual({});
|
|
expect(
|
|
withProjectSettingsOverrides(settings, otherProjectId, { defaultThreadEnvMode: "worktree" }),
|
|
).toEqual({
|
|
...settings.projectSettingsOverrides,
|
|
[otherProjectId]: { defaultThreadEnvMode: "worktree" },
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("resolveWorktreeCleanup", () => {
|
|
it("inherits machine rules, disables one project and keeps custom rules isolated", () => {
|
|
const machine = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
|
|
storageCleanup: { worktreeAfterDays: 8, worktreeOnDelete: true, logsAfterDays: 3 },
|
|
});
|
|
const inherited = resolveWorktreeCleanup(machine, projectId);
|
|
const off = applyServerSettingsPatch(machine, {
|
|
projectSettingsOverrides: {
|
|
[projectId]: { worktreeCleanup: { mode: "off" } },
|
|
},
|
|
});
|
|
expect(resolveWorktreeCleanup(off, projectId)).toEqual({
|
|
worktreeAfterDays: null,
|
|
worktreeOnDelete: false,
|
|
worktreeOnMerge: false,
|
|
worktreeUnchanged: false,
|
|
});
|
|
expect(resolveWorktreeCleanup(off, otherProjectId)).toEqual(inherited);
|
|
const custom = applyServerSettingsPatch(off, {
|
|
projectSettingsOverrides: {
|
|
[projectId]: {
|
|
worktreeCleanup: { mode: "custom", rules: { ...inherited, worktreeAfterDays: 15 } },
|
|
},
|
|
},
|
|
});
|
|
expect(resolveWorktreeCleanup(custom, projectId).worktreeAfterDays).toBe(15);
|
|
expect(custom.storageCleanup.logsAfterDays).toBe(3);
|
|
const reset = applyServerSettingsPatch(custom, {
|
|
projectSettingsOverrides: {
|
|
[projectId]: clearProjectSettingsOverrides(custom, projectId, ["worktreeCleanup"]),
|
|
},
|
|
});
|
|
expect(resolveWorktreeCleanup(reset, projectId)).toEqual(inherited);
|
|
});
|
|
it("completes partial machine custom rules and preserves them across edits", () => {
|
|
const initial = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
|
|
storageCleanup: { worktreeAfterDays: 8, worktreeOnDelete: true },
|
|
});
|
|
const custom = applyServerSettingsPatch(initial, {
|
|
worktreeCleanup: { mode: "custom", rules: { worktreeOnMerge: true } },
|
|
});
|
|
const edited = applyServerSettingsPatch(custom, {
|
|
worktreeCleanup: { mode: "custom", rules: { worktreeAfterDays: 15 } },
|
|
});
|
|
expect(resolveWorktreeCleanup(edited, null)).toEqual({
|
|
worktreeAfterDays: 15,
|
|
worktreeOnDelete: true,
|
|
worktreeOnMerge: true,
|
|
worktreeUnchanged: false,
|
|
});
|
|
expect(
|
|
resolveWorktreeCleanup(applyServerSettingsPatch(edited, { worktreeCleanup: null }), null)
|
|
.worktreeAfterDays,
|
|
).toBe(8);
|
|
});
|
|
});
|
|
|
|
it("inherits branch naming defaults and applies project overrides independently", () => {
|
|
const settings = applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {
|
|
branchNamingMode: "static",
|
|
branchNamePrefix: "team/",
|
|
branchNameInstructions: "Use issue IDs.",
|
|
projectSettingsOverrides: { [projectId]: { branchNamingMode: "custom" } },
|
|
});
|
|
expect(resolveProjectSettings(settings, projectId).settings).toMatchObject({
|
|
branchNamingMode: "custom",
|
|
branchNamePrefix: "team/",
|
|
branchNameInstructions: "Use issue IDs.",
|
|
});
|
|
expect(resolveProjectSettings(settings, otherProjectId).settings).toMatchObject({
|
|
branchNamingMode: "static",
|
|
branchNamePrefix: "team/",
|
|
});
|
|
const cleared = applyServerSettingsPatch(settings, {
|
|
projectSettingsOverrides: {
|
|
[projectId]: clearProjectSettingsOverrides(settings, projectId, ["branchNamingMode"]),
|
|
},
|
|
});
|
|
expect(resolveProjectSettings(cleared, projectId).settings.branchNamingMode).toBe("static");
|
|
});
|