Skip to content
TypeScript

fix(contracts): settings save again when the writing style has default fields (#22203)

MatiasGadebergd65249074b54
diff --git a/apps/server/src/serverSettings.test.ts b/apps/server/src/serverSettings.test.ts
index d8e3ec5ad24..e9cc4cb463e 100644
--- a/apps/server/src/serverSettings.test.ts
+++ b/apps/server/src/serverSettings.test.ts
@@ -1407,6 +1407,29 @@ it.layer(NodeServices.layer)("server settings", (it) => {
}).pipe(Effect.provide(layerServerSettings())),
);
+ it.effect("saves a writing style whose other fields are defaults", () =>
+ Effect.gen(function* () {
+ const serverSettings = yield* ServerSettingsModule.ServerSettingsService;
+ const serverConfig = yield* ServerConfig.ServerConfig;
+ const fileSystem = yield* FileSystem.FileSystem;
+ yield* serverSettings.updateSettings({
+ sourceControlWritingStyle: { mode: "conventional_commits" },
+ });
+ yield* serverSettings.updateSettings({ addProjectBaseDirectory: "~/Development" });
+
+ const raw = yield* fileSystem.readFileString(serverConfig.settingsPath);
+ assert.deepEqual(JSON.parse(raw), {
+ addProjectBaseDirectory: "~/Development",
+ sourceControlWritingStyle: { mode: "conventional_commits" },
+ });
+ assert.deepEqual((yield* serverSettings.getSettings).sourceControlWritingStyle, {
+ mode: "conventional_commits",
+ customInstructions: "",
+ followChangeRequestTemplates: true,
+ });
+ }).pipe(Effect.provide(layerServerSettings())),
+ );
+
it.effect("keeps the inline value on disk when secret migration fails", () => {
const cause = new ServerSecretStore.SecretStorePersistError({
resource: "provider environment secret",
diff --git a/packages/contracts/src/settings.ts b/packages/contracts/src/settings.ts
index d46ce4e227f..620f659befe 100644
--- a/packages/contracts/src/settings.ts
+++ b/packages/contracts/src/settings.ts
@@ -819,26 +819,27 @@ export const SourceControlWritingStyleSettings = Schema.Struct({
});
export type SourceControlWritingStyleSettings = typeof SourceControlWritingStyleSettings.Type;
-const SourceControlWritingStyleSetting = Schema.Union([
- TrimmedString,
- SourceControlWritingStyleSettings,
-]).pipe(
+const LegacySourceControlWritingStyle = TrimmedString.pipe(
Schema.decodeTo(
Schema.toType(SourceControlWritingStyleSettings),
SchemaTransformation.transform({
- decode: (value) =>
- typeof value === "string"
- ? {
- mode: value.length > 0 ? ("custom" as const) : ("repo_conventions" as const),
- customInstructions: value,
- followChangeRequestTemplates: true,
- }
- : value,
- encode: (value) => value,
+ decode: (value): SourceControlWritingStyleSettings => ({
+ mode: value.length > 0 ? "custom" : "repo_conventions",
+ customInstructions: value,
+ followChangeRequestTemplates: true,
+ }),
+ encode: (value) => value.customInstructions,
}),
),
);
+// The struct member comes first so encoding uses its defaulted fields: the server strips
+// default sub-fields before writing settings.json, and a toType target would reject them.
+const SourceControlWritingStyleSetting = Schema.Union([
+ SourceControlWritingStyleSettings,
+ LegacySourceControlWritingStyle,
+]);
+
export const BranchNamingMode = Schema.Literals(["static", "semantic", "custom"]);
export type BranchNamingMode = typeof BranchNamingMode.Type;