Skip to content

Commit d674f60

Browse files
committed
test(server): cover Publish identity refresh and failed turn-end refresh
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01WvDgDwRRG8xvtoABQ8KwtC
1 parent b0ef34e commit d674f60

2 files changed

Lines changed: 116 additions & 46 deletions

File tree

‎apps/server/src/orchestration/ThreadPullRequestReactor.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,48 @@ describe("ThreadPullRequestReactor", () => {
433433
),
434434
);
435435

436+
it.effect("keeps the snapshot identity when a turn-end refresh fails", () =>
437+
Effect.scoped(
438+
Effect.gen(function* () {
439+
const current = thread("refresh-failed");
440+
let refreshes = 0;
441+
let pullRequestOpened = false;
442+
const fixture = yield* makeHarness({
443+
threads: [current],
444+
branchPullRequest: (_input, options) =>
445+
Effect.sync(() => {
446+
if (options?.refresh) pullRequestOpened = true;
447+
return pullRequestOpened ? branchPullRequest() : null;
448+
}),
449+
// Only the turn-end refresh fails; the pre-save recheck succeeds.
450+
resolveRepositoryIdentity: (_cwd, options) =>
451+
Effect.sync(() =>
452+
options?.refresh && refreshes++ === 0 ? null : project.repositoryIdentity,
453+
),
454+
});
455+
yield* Effect.gen(function* () {
456+
const reactor = yield* fixture.start();
457+
yield* fixture.publish({
458+
type: "thread.unsettled",
459+
sequence: 2,
460+
eventId: EventId.make("unsettled"),
461+
aggregateKind: "thread",
462+
aggregateId: current.id,
463+
occurredAt: NOW,
464+
commandId: null,
465+
causationEventId: null,
466+
correlationId: null,
467+
metadata: {},
468+
payload: { threadId: current.id, reason: "activity", updatedAt: NOW },
469+
});
470+
yield* Queue.take(fixture.reads);
471+
yield* reactor.drain;
472+
expect((yield* Ref.get(fixture.commands))[0]?.branchPullRequest).toEqual(reference(42));
473+
}).pipe(Effect.provide(fixture.layer));
474+
}),
475+
),
476+
);
477+
436478
it.effect("uses live worktrees and falls back to the project for removed worktrees", () =>
437479
Effect.scoped(
438480
Effect.gen(function* () {

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

Lines changed: 74 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7649,56 +7649,84 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
76497649
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
76507650
);
76517651

7652-
it.effect("re-emits the project after initializing its repository", () =>
7653-
Effect.gen(function* () {
7654-
const dispatched: Array<string> = [];
7655-
const refreshedRoots: Array<string> = [];
7656-
const metaUpdateDispatched = yield* Deferred.make<void>();
7657-
const project = makeDefaultOrchestrationReadModel().projects[0]!;
7652+
it.effect.each(["init", "publish"] as const)(
7653+
"re-emits the project after %s adds its repository",
7654+
(action) =>
7655+
Effect.gen(function* () {
7656+
const dispatched: Array<string> = [];
7657+
const refreshedRoots: Array<string> = [];
7658+
const metaUpdateDispatched = yield* Deferred.make<void>();
7659+
const project = makeDefaultOrchestrationReadModel().projects[0]!;
76587660

7659-
yield* buildAppUnderTest({
7660-
layers: {
7661-
orchestrationEngine: {
7662-
dispatch: (command) =>
7663-
Effect.sync(() => {
7664-
dispatched.push(command.type);
7665-
return { sequence: dispatched.length };
7666-
}).pipe(
7667-
Effect.tap(() =>
7668-
command.type === "project.meta.update"
7669-
? Deferred.succeed(metaUpdateDispatched, undefined)
7670-
: Effect.void,
7661+
yield* buildAppUnderTest({
7662+
layers: {
7663+
orchestrationEngine: {
7664+
dispatch: (command) =>
7665+
Effect.sync(() => {
7666+
dispatched.push(command.type);
7667+
return { sequence: dispatched.length };
7668+
}).pipe(
7669+
Effect.tap(() =>
7670+
command.type === "project.meta.update"
7671+
? Deferred.succeed(metaUpdateDispatched, undefined)
7672+
: Effect.void,
7673+
),
76717674
),
7672-
),
7673-
},
7674-
projectionSnapshotQuery: {
7675-
getActiveProjectByWorkspaceRoot: (workspaceRoot) =>
7676-
Effect.succeed(
7677-
workspaceRoot === project.workspaceRoot
7678-
? Option.some({ ...project, repositoryIdentity: null })
7679-
: Option.none(),
7680-
),
7681-
},
7682-
repositoryIdentityResolver: {
7683-
resolve: (cwd, options) =>
7684-
Effect.sync(() => {
7685-
if (options?.refresh) refreshedRoots.push(cwd);
7686-
return null;
7687-
}),
7675+
},
7676+
projectionSnapshotQuery: {
7677+
getActiveProjectByWorkspaceRoot: (workspaceRoot) =>
7678+
Effect.succeed(
7679+
workspaceRoot === project.workspaceRoot
7680+
? Option.some({ ...project, repositoryIdentity: null })
7681+
: Option.none(),
7682+
),
7683+
},
7684+
repositoryIdentityResolver: {
7685+
resolve: (cwd, options) =>
7686+
Effect.sync(() => {
7687+
if (options?.refresh) refreshedRoots.push(cwd);
7688+
return null;
7689+
}),
7690+
},
7691+
sourceControlRepositoryService: {
7692+
publishRepository: () =>
7693+
Effect.succeed({
7694+
repository: {
7695+
provider: "github",
7696+
nameWithOwner: "t3tools/t3code",
7697+
url: "https://github.com/t3tools/t3code",
7698+
sshUrl: "[email protected]:t3tools/t3code.git",
7699+
},
7700+
remoteName: "origin",
7701+
remoteUrl: "[email protected]:t3tools/t3code.git",
7702+
branch: "main",
7703+
status: "pushed",
7704+
}),
7705+
},
76887706
},
7689-
},
7690-
});
7707+
});
76917708

7692-
const wsUrl = yield* getWsServerUrl("/ws");
7693-
yield* Effect.scoped(
7694-
withWsRpcClient(wsUrl, (client) =>
7695-
client[WS_METHODS.vcsInit]({ cwd: project.workspaceRoot }),
7696-
),
7697-
);
7698-
yield* Deferred.await(metaUpdateDispatched);
7699-
assert.deepEqual(refreshedRoots, [project.workspaceRoot]);
7700-
assert.deepEqual(dispatched, ["project.meta.update"]);
7701-
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
7709+
const wsUrl = yield* getWsServerUrl("/ws");
7710+
yield* Effect.scoped(
7711+
withWsRpcClient(wsUrl, (client) =>
7712+
Effect.gen(function* () {
7713+
if (action === "init") {
7714+
yield* client[WS_METHODS.vcsInit]({ cwd: project.workspaceRoot });
7715+
} else {
7716+
yield* client[WS_METHODS.sourceControlPublishRepository]({
7717+
cwd: project.workspaceRoot,
7718+
provider: "github",
7719+
repository: "t3tools/t3code",
7720+
visibility: "private",
7721+
});
7722+
}
7723+
}),
7724+
),
7725+
);
7726+
yield* Deferred.await(metaUpdateDispatched);
7727+
assert.deepEqual(refreshedRoots, [project.workspaceRoot]);
7728+
assert.deepEqual(dispatched, ["project.meta.update"]);
7729+
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
77027730
);
77037731

77047732
it.effect("records thread analytics only after a client command succeeds", () =>

0 commit comments

Comments
 (0)