Skip to content

Commit e4d37c9

Browse files
test(server): settings mocks accept a patch computed from current settings
AI-assisted; verified with the tests and tools listed above.
1 parent d14a76b commit e4d37c9

4 files changed

Lines changed: 37 additions & 19 deletions

File tree

‎apps/server/src/device/DeviceService.test.ts‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,15 +313,18 @@ const fixture = Effect.fn("fixture")(function* (
313313
start: Effect.void,
314314
ready: Effect.void,
315315
getSettings: Ref.get(settings),
316-
updateSettings: (patch) =>
317-
Ref.updateAndGet(settings, (current) => ({
318-
...current,
319-
enableDeviceSupport: patch.enableDeviceSupport ?? current.enableDeviceSupport,
320-
enableAgentDeviceAccess:
321-
patch.enableAgentDeviceAccess ?? current.enableAgentDeviceAccess,
322-
deviceOnboardingCompleted:
323-
patch.deviceOnboardingCompleted ?? current.deviceOnboardingCompleted,
324-
})),
316+
updateSettings: (update) =>
317+
Ref.updateAndGet(settings, (current) => {
318+
const patch = ServerSettings.resolveServerSettingsPatch(current, update);
319+
return {
320+
...current,
321+
enableDeviceSupport: patch.enableDeviceSupport ?? current.enableDeviceSupport,
322+
enableAgentDeviceAccess:
323+
patch.enableAgentDeviceAccess ?? current.enableAgentDeviceAccess,
324+
deviceOnboardingCompleted:
325+
patch.deviceOnboardingCompleted ?? current.deviceOnboardingCompleted,
326+
};
327+
}),
325328
streamChanges: Stream.empty,
326329
subscribeChanges: Effect.succeed(Stream.empty),
327330
}),

‎apps/server/src/orchestration-v2/ThreadSettlementService.test.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
type OrchestrationV2ThreadShell,
2121
type PullRequestSummary,
2222
type ServerSettings as ContractServerSettings,
23-
type ServerSettingsPatch,
2423
} from "@t3tools/contracts";
2524
import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings";
2625
import * as SecureRandom from "effect/crypto/SecureRandom";
@@ -598,9 +597,13 @@ const makeHarness = Effect.fn("makeThreadSettlementHarness")(function* (options:
598597
const scriptRuns =
599598
yield* Queue.unbounded<ProjectSetupScriptRunner.ProjectSetupScriptRunnerInput>();
600599

601-
const updateSettings = (patch: ServerSettingsPatch) =>
600+
const updateSettings = (update: ServerSettings.ServerSettingsUpdate) =>
602601
Effect.gen(function* () {
603-
const next = applyServerSettingsPatch(yield* Ref.get(settings), patch);
602+
const current = yield* Ref.get(settings);
603+
const next = applyServerSettingsPatch(
604+
current,
605+
ServerSettings.resolveServerSettingsPatch(current, update),
606+
);
604607
yield* Ref.set(settings, next);
605608
yield* PubSub.publish(settingsChanges, next);
606609
return next;

‎apps/server/src/provider/ProviderRegistry.test.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,13 @@ function makeMutableServerSettingsService(
289289
start: Effect.void,
290290
ready: Effect.void,
291291
getSettings: Ref.get(settingsRef),
292-
updateSettings: (patch) =>
292+
updateSettings: (update) =>
293293
Effect.gen(function* () {
294294
const current = yield* Ref.get(settingsRef);
295-
const next = applyServerSettingsPatch(current, patch);
295+
const next = applyServerSettingsPatch(
296+
current,
297+
ServerSettingsModule.resolveServerSettingsPatch(current, update),
298+
);
296299
encodeServerSettings(next);
297300
yield* Ref.set(settingsRef, next);
298301
yield* PubSub.publish(changes, next);

‎apps/server/src/serverSettings.ts‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,16 @@ function ensureProviderInstanceMutationAllowed(
250250
return Effect.void;
251251
}
252252

253+
/** A function is computed from the current settings under the write lock. */
254+
export type ServerSettingsUpdate =
255+
| ServerSettingsPatch
256+
| ((current: ServerSettings) => ServerSettingsPatch);
257+
258+
export const resolveServerSettingsPatch = (
259+
current: ServerSettings,
260+
update: ServerSettingsUpdate,
261+
): ServerSettingsPatch => (typeof update === "function" ? update(current) : update);
262+
253263
export class ServerSettingsService extends Context.Service<
254264
ServerSettingsService,
255265
{
@@ -262,9 +272,8 @@ export class ServerSettingsService extends Context.Service<
262272

263273
readonly getSettings: Effect.Effect<ServerSettings, ServerSettingsError>;
264274

265-
/** A function patch is computed from the current settings under the write lock. */
266275
readonly updateSettings: (
267-
patch: ServerSettingsPatch | ((current: ServerSettings) => ServerSettingsPatch),
276+
patch: ServerSettingsUpdate,
268277
) => Effect.Effect<ServerSettings, ServerSettingsError>;
269278

270279
readonly updateProviderInstance: (
@@ -330,7 +339,7 @@ const makeTest = Effect.fn("serverSettings.makeTest")(function* (
330339
Effect.succeed(
331340
applyServerSettingsPatch(
332341
currentSettings,
333-
typeof patch === "function" ? patch(currentSettings) : patch,
342+
resolveServerSettingsPatch(currentSettings, patch),
334343
),
335344
),
336345
),
@@ -1190,7 +1199,7 @@ const make = Effect.gen(function* () {
11901199
};
11911200

11921201
const updateAndPersistSettings = (
1193-
patchInput: ServerSettingsPatch | ((current: ServerSettings) => ServerSettingsPatch),
1202+
patchInput: ServerSettingsUpdate,
11941203
update: (
11951204
current: ServerSettings,
11961205
patch: ServerSettingsPatch,
@@ -1206,7 +1215,7 @@ const make = Effect.gen(function* () {
12061215
cause: parseFailure.value,
12071216
});
12081217
}
1209-
const patch = typeof patchInput === "function" ? patchInput(current) : patchInput;
1218+
const patch = resolveServerSettingsPatch(current, patchInput);
12101219
// An older client echoes a reference as the redacted marker; restore it before vetting so
12111220
// a removed provider's reference is cleared below rather than restored by persistence.
12121221
const updated = withEchoedSecretReferences(current, yield* update(current, patch));

0 commit comments

Comments
 (0)