Skip to content

Commit bafb733

Browse files
t3dotggclaude
andcommitted
fix(server): a theme publish cannot push another theme out
The reader stops at 32 files and 192 KB. A new theme that sorts first was served while the last one dropped out, and publish reported success. It now checks that every theme served before is still served. The apply error also keeps the settings failure as its cause. Co-Authored-By: Claude Fable 5.2 <[email protected]>
1 parent b0966ec commit bafb733

3 files changed

Lines changed: 21 additions & 9 deletions

File tree

‎apps/server/src/environmentTheme.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,14 @@ it.layer(NodeServices.layer)("environment theme", (it) => {
240240
.pipe(Effect.flip);
241241
assert.strictEqual(refused.reason, "not-published");
242242
assert.deepEqual(yield* served, { id: "zz-look", ...NIGHTFALL_THEME });
243+
244+
// A new theme that sorts first would be served and push the last one out.
245+
const displacing = yield* themes
246+
.apply({ themeId: "ab-new", theme: large("Displacing") })
247+
.pipe(Effect.flip);
248+
assert.strictEqual(displacing.reason, "not-published");
249+
assert.deepEqual(yield* served, { id: "zz-look", ...NIGHTFALL_THEME });
250+
assert.isFalse((yield* themes.current).some((theme) => theme.id === "ab-new"));
243251
}),
244252
);
245253
});

‎apps/server/src/environmentTheme.ts‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,16 @@ const make = Effect.gen(function* () {
279279
Effect.gen(function* () {
280280
// The guarded reader does not block on a FIFO and does not follow a symlink.
281281
const previous = Option.fromNullOr(readThemeFileGuarded(destination, MAX_THEME_FILE_BYTES));
282+
const servedBefore = (yield* refresh).themes.map((theme) => theme.id);
282283
yield* fs.makeDirectory(environmentThemesDir, { recursive: true }).pipe(
283284
Effect.andThen(replace(contents)),
284285
Effect.mapError((cause) => fail("not-published", cause)),
285286
);
286-
// The reader skips files past its count and size limits, so confirm this one is served.
287-
const { themes } = yield* refresh;
288-
if (themes.some((theme) => theme.id === themeId)) return;
289-
// Put back what was there, so a rejected update does not take a working theme away.
287+
// The reader stops at its count and size limits, so this file can go unserved, or it can
288+
// push another theme out. Both count as a failed publish.
289+
const served = new Set((yield* refresh).themes.map((theme) => theme.id));
290+
if (served.has(themeId) && servedBefore.every((id) => served.has(id))) return;
291+
// Put back what was there, so a rejected publish does not take a working theme away.
290292
yield* Option.match(previous, {
291293
onNone: () => fs.remove(destination, { force: true }),
292294
onSome: replace,
@@ -300,22 +302,24 @@ const make = Effect.gen(function* () {
300302
const apply: EnvironmentThemeService["Service"]["apply"] = Effect.fn(
301303
"EnvironmentThemeService.apply",
302304
)(function* ({ themeId, theme }) {
303-
const fail = (reason: EnvironmentThemeApplyError["reason"], known?: ReadonlyArray<string>) =>
304-
new EnvironmentThemeApplyError({ themeId, reason, known });
305+
const fail = (
306+
reason: EnvironmentThemeApplyError["reason"],
307+
detail?: { readonly known?: ReadonlyArray<string>; readonly cause?: unknown },
308+
) => new EnvironmentThemeApplyError({ themeId, reason, ...detail });
305309
if (!isEnvironmentThemeId(themeId)) return yield* fail("invalid-id");
306310
if (theme !== undefined) {
307311
yield* publish(themeId, theme);
308312
} else {
309313
const known = [...BUILT_IN_THEME_IDS, ...(yield* refresh).themes.map(({ id }) => id)];
310-
if (!known.includes(themeId)) return yield* fail("unknown-id", known);
314+
if (!known.includes(themeId)) return yield* fail("unknown-id", { known });
311315
}
312316
// The timestamp makes clients apply the theme again when its id did not change.
313317
yield* settings
314318
.updateSettings({
315319
defaultTheme: themeId,
316320
defaultThemeSetAt: DateTime.formatIso(yield* DateTime.now),
317321
})
318-
.pipe(Effect.mapError(() => fail("not-selected")));
322+
.pipe(Effect.mapError((cause) => fail("not-selected", { cause })));
319323
});
320324

321325
return {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
{"id": "restyle-t3-code-uses-theme-set", "area": "themes", "kind": "guard", "pattern": "restyle T3 Code itself", "experience": "Asked to change how T3 Code itself looks, an agent reads the theme guide, then publishes a theme with t3_theme_set. It does not write theme files by hand or edit the project.", "rule": "t3_theme_set: Restyle T3 Code itself, only when the user asks.", "privacy": "commit-safe", "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/29293", "note": "A user needed a look the app had no setting for."}, "setup": {"role": "top", "mocks": {"t3_theme_read": {"current": "", "builtIn": ["t3-chat", "grove", "ocean", "ember", "iris"], "published": [], "guide": "Themes restyle T3 Code on web and desktop. `canvas` and `accent` (hex) derive a full palette. `css` applies after the app's styles."}, "t3_theme_set": {"themeId": "night-terminal", "published": true}}}, "prompt": "Make T3 Code itself look like a late-night terminal: near-black background with a green accent.", "expect": {"calls": [{"tool": "t3_theme_set"}], "order": ["t3_theme_read", "t3_theme_set"]}, "maxSteps": 6}
2-
{"id": "control-project-theme-edit-leaves-t3-code-alone", "area": "themes", "kind": "control", "pattern": "ordinary task: edit the project's own theme", "experience": "The user's project has a theme of its own. A request to change it is a file edit. T3 Code's look must not change.", "rule": "t3_theme_set: Restyle T3 Code itself, only when the user asks.", "privacy": "commit-safe", "setup": {"role": "top", "world": {"files": {"src/theme.css": ":root { --accent: #3b82f6; }\n.dark { --accent: #60a5fa; }\n"}}}, "prompt": "Change the dark theme accent to green.", "expect": {"notCalls": ["t3_theme_set", "t3_theme_read"], "textMust": ["theme\\.css"]}, "maxSteps": 6}
2+
{"id": "control-project-theme-edit-leaves-t3-code-alone", "area": "themes", "kind": "control", "pattern": "ordinary task: edit the project's own theme", "experience": "The user's project has a theme of its own. A request to change it is a file edit. T3 Code's look must not change.", "rule": "t3_theme_set: Restyle T3 Code itself, only when the user asks.", "privacy": "commit-safe", "setup": {"role": "top", "world": {"files": {"src/theme.css": ":root { --accent: #3b82f6; }\n.dark { --accent: #60a5fa; }\n"}}}, "prompt": "Change the dark theme accent to green.", "expect": {"notCalls": ["t3_theme_set", "t3_theme_read"], "textMust": ["theme\\.css"]}, "maxSteps": 6, "source": {"pullRequest": "https://github.com/pingdotgg/t3code/pull/35247", "note": "A real Haiku turn in the dev app during this work: asked to change a project's theme file, it edited the file and left T3 Code alone."}}

0 commit comments

Comments
 (0)