Skip to content

Commit 9585bef

Browse files
donjor-agent[bot]donjor
authored andcommitted
fix(fork): refresh legacy setup scripts in project settings overrides (#1866)
## Problem After setup-script adoption, project settings and the header **Setup Worktree** action keep the legacy `vp run setup:worktree`. Startup reconciliation refreshes only `project.scripts`, but `resolveProjectScripts` reads `projectSettingsOverrides[id].defaultProjectScripts` first. ## Change `reconcileSetupScriptsFork` also runs each override's scripts through `refreshPersistedSetupScripts`, so only exact legacy generated commands change. A patch entry replaces the whole override set, so the update writes the full entry. ```ts for (const [projectId, entry] of Object.entries(projectSettingsOverrides)) { const current = entry.defaultProjectScripts; if (current === undefined) continue; const scripts = refreshPersistedSetupScripts(current); if (scripts !== current) refreshed[projectId] = { ...entry, defaultProjectScripts: scripts }; } ``` ## Scope and approval Closes #1774 Human decision: fix it in the fork, inside the existing `.fork.` reconcile path. ## Verification - [x] **Settings:** Edit Action shows the new command - [x] **Header:** Setup Worktree runs the new command - [x] **Test:** fails before the fix, passes after - [x] **Test:** custom override command unchanged - [x] **Test:** sibling `defaultAutoPull` kept - [x] **Runtime:** legacy override refreshed on restart - [x] `vp run fork:ci` → exit 0 - [ ] `vp run check:changed` → exit 1 **check:changed:** format, lint, knip, and typecheck pass. 2 tests fail that do not import the changed files; the first fails alone too: ```text GitManager.test.ts > includes CLAUDE.md for Claude writers only when it differs from AGENTS.md markdownPipeline.browser.test.ts > renders interactive tasks, workspace chips, and code chrome ``` **Settings → Project → Actions** after restart: ![1774-actions.png](https://github.com/user-attachments/assets/a692b685-5f2b-4945-822d-e1a4e853148f) **Header → Script actions → Edit Setup Worktree.** Both surfaces resolve through `resolveProjectScripts`. Running it in the empty fixture fails with Node `MODULE_NOT_FOUND`, not the legacy `vite-plus` error. ![1774-header-edit.png](https://github.com/user-attachments/assets/3d2ed414-73f8-4678-9f84-b90e6c6e3f77) Claude Opus 5.5 in Claude Code. ## Fork trailers Fork-Domain: upstream-fixes Fork-Tier: bugfix Fork-Upstreamable: no Co-authored-by: donjor <[email protected]>
1 parent 7cd6ea1 commit 9585bef

2 files changed

Lines changed: 79 additions & 20 deletions

File tree

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,60 @@
11
import * as NodeServices from "@effect/platform-node/NodeServices";
2-
import { type OrchestrationProjectShell, ProjectId } from "@t3tools/contracts";
2+
import { type OrchestrationProjectShell, ProjectId, type ProjectScript } from "@t3tools/contracts";
33
import { assert, it } from "@effect/vitest";
44
import * as Effect from "effect/Effect";
5+
import * as Layer from "effect/Layer";
56

67
import * as ProjectStore from "./orchestration-v2/ProjectStore.ts";
78
import * as ProjectService from "./project/ProjectService.ts";
9+
import * as ServerSettings from "./serverSettings.ts";
810
import { reconcileSetupScriptsFork } from "./serverRuntimeStartup.fork.ts";
911

1012
const legacyGeneratedCommand =
1113
"vp i && ln -sf $T3CODE_PROJECT_ROOT/.env .env && " +
1214
"ln -sf $T3CODE_PROJECT_ROOT/infra/relay/.env infra/relay/.env && " +
1315
"node apps/web/scripts/warm-dep-cache.ts";
1416

17+
const setupScript = (command: string): ProjectScript => ({
18+
id: "setup-worktree",
19+
name: "Setup Worktree",
20+
command,
21+
icon: "configure",
22+
runOnWorktreeCreate: true,
23+
});
24+
1525
const makeProject = (id: string, command: string): OrchestrationProjectShell => ({
1626
id: ProjectId.make(id),
1727
title: id,
1828
workspaceRoot: `/repo/${id}`,
1929
defaultModelSelection: null,
20-
scripts: [
21-
{
22-
id: "setup-worktree",
23-
name: "Setup Worktree",
24-
command,
25-
icon: "configure",
26-
runOnWorktreeCreate: true,
27-
},
28-
],
30+
scripts: [setupScript(command)],
2931
createdAt: "2026-01-01T00:00:00.000Z",
3032
updatedAt: "2026-01-01T00:00:00.000Z",
3133
});
3234

35+
const reconcile = (input: {
36+
readonly projects: ReadonlyArray<OrchestrationProjectShell>;
37+
readonly updates: ProjectService.ProjectUpdateInput[];
38+
}) =>
39+
reconcileSetupScriptsFork.pipe(
40+
Effect.provideService(ProjectStore.ProjectStoreV2, {
41+
listShells: () => Effect.succeed(input.projects),
42+
} as unknown as ProjectStore.ProjectStoreV2["Service"]),
43+
Effect.provideService(ProjectService.ProjectService, {
44+
update: (update: ProjectService.ProjectUpdateInput) =>
45+
Effect.sync(() => input.updates.push(update)).pipe(Effect.as({} as never)),
46+
} as unknown as ProjectService.ProjectService["Service"]),
47+
);
48+
3349
it.effect("persists only an unmodified imported fork setup command", () => {
3450
const stale = makeProject("stale", legacyGeneratedCommand);
3551
const custom = makeProject("custom", "vp i && ./scripts/configure-worktree.sh");
3652
const updates: ProjectService.ProjectUpdateInput[] = [];
3753

38-
return reconcileSetupScriptsFork.pipe(
39-
Effect.provideService(ProjectStore.ProjectStoreV2, {
40-
listShells: () => Effect.succeed([stale, custom]),
41-
} as unknown as ProjectStore.ProjectStoreV2["Service"]),
42-
Effect.provideService(ProjectService.ProjectService, {
43-
update: (input: ProjectService.ProjectUpdateInput) =>
44-
Effect.sync(() => updates.push(input)).pipe(Effect.as({} as never)),
45-
} as unknown as ProjectService.ProjectService["Service"]),
46-
Effect.provide(NodeServices.layer),
54+
return reconcile({ projects: [stale, custom], updates }).pipe(
55+
Effect.provide(
56+
Layer.merge(ServerSettings.ServerSettingsService.layerTest(), NodeServices.layer),
57+
),
4758
Effect.tap(() =>
4859
Effect.sync(() => {
4960
assert.equal(updates.length, 1);
@@ -55,3 +66,35 @@ it.effect("persists only an unmodified imported fork setup command", () => {
5566
),
5667
);
5768
});
69+
70+
it.effect("refreshes a legacy generated setup command in project settings overrides", () => {
71+
const stale = ProjectId.make("stale");
72+
const custom = ProjectId.make("custom");
73+
const customScripts = [setupScript("vp i && ./scripts/configure-worktree.sh")];
74+
75+
return Effect.gen(function* () {
76+
yield* reconcile({ projects: [], updates: [] });
77+
const { projectSettingsOverrides } = yield* (yield* ServerSettings.ServerSettingsService)
78+
.getSettings;
79+
assert.deepStrictEqual(projectSettingsOverrides[stale], {
80+
defaultAutoPull: true,
81+
defaultProjectScripts: [setupScript("node scripts/setup-worktree.ts")],
82+
});
83+
assert.deepStrictEqual(projectSettingsOverrides[custom]?.defaultProjectScripts, customScripts);
84+
}).pipe(
85+
Effect.provide(
86+
Layer.merge(
87+
ServerSettings.ServerSettingsService.layerTest({
88+
projectSettingsOverrides: {
89+
[stale]: {
90+
defaultAutoPull: true,
91+
defaultProjectScripts: [setupScript("vp run setup:worktree")],
92+
},
93+
[custom]: { defaultProjectScripts: customScripts },
94+
},
95+
}),
96+
NodeServices.layer,
97+
),
98+
),
99+
);
100+
});

‎apps/server/src/serverRuntimeStartup.fork.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import { CommandId } from "@t3tools/contracts";
1+
import { CommandId, type ProjectSettingsOverrides } from "@t3tools/contracts";
22
import * as Cause from "effect/Cause";
33
import * as Crypto from "effect/Crypto";
44
import * as Effect from "effect/Effect";
55

66
import * as ProjectStore from "./orchestration-v2/ProjectStore.ts";
77
import * as ProjectService from "./project/ProjectService.ts";
88
import { refreshPersistedSetupScripts } from "./project/ProjectSetupScriptRunner.ts";
9+
import * as ServerSettings from "./serverSettings.ts";
910

1011
/**
1112
* Startup phase: persist the refreshed form of every unmodified legacy generated
1213
* setup script, so project settings show the command worktree setup runs.
14+
* Project settings overrides win over `project.scripts`, so both are refreshed.
1315
*/
1416
export const reconcileSetupScriptsFork = Effect.gen(function* () {
1517
const crypto = yield* Crypto.Crypto;
@@ -27,6 +29,20 @@ export const reconcileSetupScriptsFork = Effect.gen(function* () {
2729
scripts,
2830
});
2931
}
32+
33+
const serverSettings = yield* ServerSettings.ServerSettingsService;
34+
const { projectSettingsOverrides } = yield* serverSettings.getSettings;
35+
const refreshed: Record<string, ProjectSettingsOverrides> = {};
36+
for (const [projectId, entry] of Object.entries(projectSettingsOverrides)) {
37+
const current = entry.defaultProjectScripts;
38+
if (current === undefined) continue;
39+
const scripts = refreshPersistedSetupScripts(current);
40+
if (scripts !== current) refreshed[projectId] = { ...entry, defaultProjectScripts: scripts };
41+
}
42+
if (Object.keys(refreshed).length > 0) {
43+
// A patch entry replaces that project's whole override set, hence the full entry.
44+
yield* serverSettings.updateSettings({ projectSettingsOverrides: refreshed });
45+
}
3046
}).pipe(
3147
Effect.catchCauseIf(
3248
(cause) => !Cause.hasInterrupts(cause),

0 commit comments

Comments
 (0)