Skip to content

Commit 9c3094a

Browse files
fix: address review findings on publishing capability
- Treat empty relay secrets as unconfigured, matching the publisher's truthiness gate so the capability never advertises skipped publishes - Expose ServerSecretStore as a layer requirement instead of building a private instance, matching the other secret-store consumers Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 3c70760 commit 9c3094a

4 files changed

Lines changed: 37 additions & 17 deletions

File tree

‎apps/server/src/cli/connect.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ const runCloudCommand = Effect.fn("cloud.cli.run_cloud_command")(function* <A, E
448448
),
449449
RelayClient.layerCloudflared({ baseDir: config.baseDir }),
450450
EnvironmentAuth.runtimeLayer,
451-
ServerEnvironment.layer,
451+
ServerEnvironment.layer.pipe(Layer.provide(ServerSecretStore.layer)),
452452
bootServiceLayer(config),
453453
headlessRelayClientTracingLayer,
454454
).pipe(

‎apps/server/src/cloud/config.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,13 @@ export const readAgentActivityPublishingActive = (
4646
readSecretString(RELAY_URL_SECRET),
4747
readSecretString(RELAY_ENVIRONMENT_CREDENTIAL_SECRET),
4848
]);
49+
// Empty strings are as unconfigured as missing files: the publisher's
50+
// truthiness gate skips them, so the capability must too.
4951
return (
5052
isAgentActivityPublishingEnabledValue(enabled) &&
5153
url !== null &&
52-
environmentCredential !== null
54+
url !== "" &&
55+
environmentCredential !== null &&
56+
environmentCredential !== ""
5357
);
5458
}).pipe(Effect.orElseSucceed(() => false));

‎apps/server/src/environment/ServerEnvironment.test.ts‎

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { expect, it } from "@effect/vitest";
33
import * as Effect from "effect/Effect";
44
import * as FileSystem from "effect/FileSystem";
55
import * as Layer from "effect/Layer";
6+
import * as Option from "effect/Option";
67
import * as PlatformError from "effect/PlatformError";
78
import * as Schema from "effect/Schema";
89

@@ -20,7 +21,21 @@ const isServerEnvironmentIdPersistenceError = Schema.is(
2021
);
2122

2223
const makeServerEnvironmentLayer = (baseDir: string) =>
23-
ServerEnvironment.layer.pipe(Layer.provide(ServerConfig.layerTest(process.cwd(), baseDir)));
24+
ServerEnvironment.layer.pipe(
25+
Layer.provide(ServerSecretStore.layer),
26+
Layer.provide(ServerConfig.layerTest(process.cwd(), baseDir)),
27+
);
28+
29+
const emptySecretStoreLayer = Layer.succeed(
30+
ServerSecretStore.ServerSecretStore,
31+
ServerSecretStore.ServerSecretStore.of({
32+
get: () => Effect.succeed(Option.none()),
33+
set: () => Effect.void,
34+
create: () => Effect.void,
35+
getOrCreateRandom: () => Effect.succeed(new Uint8Array()),
36+
remove: () => Effect.void,
37+
}),
38+
);
2439

2540
const makeServerConfig = Effect.fn(function* (baseDir: string) {
2641
const derivedPaths = yield* ServerConfig.deriveServerPaths(baseDir, undefined);
@@ -87,9 +102,9 @@ it.layer(NodeServices.layer)("ServerEnvironmentLive", (it) => {
87102
prefix: "t3-server-environment-publish-test-",
88103
});
89104
const testLayer = Layer.mergeAll(
90-
makeServerEnvironmentLayer(baseDir),
91-
ServerSecretStore.layer.pipe(Layer.provide(ServerConfig.layerTest(process.cwd(), baseDir))),
92-
);
105+
ServerEnvironment.layer.pipe(Layer.provide(ServerSecretStore.layer)),
106+
ServerSecretStore.layer,
107+
).pipe(Layer.provide(ServerConfig.layerTest(process.cwd(), baseDir)));
93108

94109
yield* Effect.gen(function* () {
95110
const secrets = yield* ServerSecretStore.ServerSecretStore;
@@ -105,8 +120,15 @@ it.layer(NodeServices.layer)("ServerEnvironmentLive", (it) => {
105120
const withoutLink = yield* serverEnvironment.getDescriptor;
106121
expect(withoutLink.capabilities.agentActivityPublishing).toBe(false);
107122

108-
yield* secrets.set(RELAY_URL_SECRET, encode("https://relay.example"));
123+
// Empty credentials are as unconfigured as missing ones: the
124+
// publisher's truthiness gate skips them, so the capability must not
125+
// advertise publishing.
126+
yield* secrets.set(RELAY_URL_SECRET, encode(""));
109127
yield* secrets.set(RELAY_ENVIRONMENT_CREDENTIAL_SECRET, encode("credential"));
128+
const emptyUrl = yield* serverEnvironment.getDescriptor;
129+
expect(emptyUrl.capabilities.agentActivityPublishing).toBe(false);
130+
131+
yield* secrets.set(RELAY_URL_SECRET, encode("https://relay.example"));
110132
const linked = yield* serverEnvironment.getDescriptor;
111133
expect(linked.capabilities.agentActivityPublishing).toBe(true);
112134

@@ -150,11 +172,6 @@ it.layer(NodeServices.layer)("ServerEnvironmentLive", (it) => {
150172
writeAttempts.push(path);
151173
return Effect.fail(cause);
152174
},
153-
// The secret store the environment layer builds prepares its
154-
// directory on construction; only the environment-id operations
155-
// above are meant to fail here.
156-
makeDirectory: () => Effect.void,
157-
chmod: () => Effect.void,
158175
});
159176

160177
const error = yield* Effect.gen(function* () {
@@ -163,6 +180,7 @@ it.layer(NodeServices.layer)("ServerEnvironmentLive", (it) => {
163180
}).pipe(
164181
Effect.provide(
165182
ServerEnvironment.layer.pipe(
183+
Layer.provide(emptySecretStoreLayer),
166184
Layer.provide(Layer.merge(ServerConfig.layer(serverConfig), failingFileSystemLayer)),
167185
),
168186
),

‎apps/server/src/environment/ServerEnvironment.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ export const make = Effect.gen(function* () {
170170
/**
171171
* ServerEnvironment is acquired from persisted filesystem and host-process
172172
* state. It intentionally has no fallback Layer.succeed value: callers must
173-
* provide the external platform services and a ServerConfig.
173+
* provide the external platform services, a ServerConfig, and the
174+
* ServerSecretStore backing the descriptor's publishing capability.
174175
*/
175-
export const layer = Layer.effect(ServerEnvironment, make).pipe(
176-
Layer.provide(ProcessRunner.layer),
177-
Layer.provide(ServerSecretStore.layer),
178-
);
176+
export const layer = Layer.effect(ServerEnvironment, make).pipe(Layer.provide(ProcessRunner.layer));

0 commit comments

Comments
 (0)