Detach git status refresh after git actions

Co-authored-by: codex <[email protected]>
This commit is contained in:
Julius Marmingeandcodex committed 2026-04-05 18:02:52 -07:00
1 parent 5326507ff5
commit a49910639c
2 files changed
+91 -11

No files matched your search

+86 -1
View File
@@ -22,7 +22,16 @@ import {
} from "@t3tools/contracts";
import { assert, it } from "@effect/vitest";
import { assertFailure, assertInclude, assertTrue } from "@effect/vitest/utils";
import { Duration, Effect, FileSystem, Layer, ManagedRuntime, Path, Stream } from "effect";
import {
Deferred,
Duration,
Effect,
FileSystem,
Layer,
ManagedRuntime,
Path,
Stream,
} from "effect";
import {
FetchHttpClient,
HttpBody,
@@ -1791,6 +1800,82 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
);
it.effect(
"starts a background local git status refresh after a successful git.runStackedAction",
() =>
Effect.gen(function* () {
const localRefreshStarted = yield* Deferred.make<void>();
yield* buildAppUnderTest({
layers: {
gitManager: {
invalidateLocalStatus: () => Effect.void,
invalidateRemoteStatus: () => Effect.void,
localStatus: () =>
Deferred.succeed(localRefreshStarted, undefined).pipe(
Effect.ignore,
Effect.andThen(
Effect.succeed({
isRepo: true,
hasOriginRemote: true,
isDefaultBranch: false,
branch: "feature/demo",
hasWorkingTreeChanges: false,
workingTree: { files: [], insertions: 0, deletions: 0 },
}),
),
),
remoteStatus: () =>
Effect.sleep(Duration.seconds(2)).pipe(
Effect.as({
hasUpstream: true,
aheadCount: 0,
behindCount: 0,
pr: null,
}),
),
runStackedAction: () =>
Effect.succeed({
action: "commit" as const,
branch: { status: "skipped_not_requested" as const },
commit: {
status: "created" as const,
commitSha: "abc123",
subject: "feat: demo",
},
push: { status: "skipped_not_requested" as const },
pr: { status: "skipped_not_requested" as const },
toast: {
title: "Committed abc123",
description: "feat: demo",
cta: {
kind: "run_action" as const,
label: "Push",
action: {
kind: "push" as const,
},
},
},
}),
},
},
});
const wsUrl = yield* getWsServerUrl("/ws");
yield* Effect.scoped(
withWsRpcClient(wsUrl, (client) =>
client[WS_METHODS.gitRunStackedAction]({
actionId: "action-1",
cwd: "/tmp/repo",
action: "commit",
}).pipe(Stream.runCollect),
),
);
yield* Deferred.await(localRefreshStarted);
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
);
it.effect("routes websocket rpc orchestration methods", () =>
Effect.gen(function* () {
const now = new Date().toISOString();
+5 -10
View File
@@ -1,4 +1,4 @@
import { Cause, Effect, Layer, Option, Queue, Ref, Schema, Scope, Stream } from "effect";
import { Cause, Effect, Layer, Option, Queue, Ref, Schema, Stream } from "effect";
import {
CommandId,
EventId,
@@ -67,8 +67,6 @@ const WsRpcLayer = WsRpcGroup.toLayer(
const workspaceEntries = yield* WorkspaceEntries;
const workspaceFileSystem = yield* WorkspaceFileSystem;
const projectSetupScriptRunner = yield* ProjectSetupScriptRunner;
const wsBackgroundScope = yield* Effect.acquireRelease(Scope.make(), Scope.close);
const serverCommandId = (tag: string) =>
CommandId.makeUnsafe(`server:${tag}:${crypto.randomUUID()}`);
@@ -353,8 +351,8 @@ const WsRpcLayer = WsRpcGroup.toLayer(
const refreshGitStatus = (cwd: string) =>
gitStatusBroadcaster
.enqueueRefreshStatus(cwd)
.pipe(Effect.ignoreCause({ log: true }), Effect.forkIn(wsBackgroundScope), Effect.asVoid);
.refreshStatus(cwd)
.pipe(Effect.ignoreCause({ log: true }), Effect.forkDetach, Effect.asVoid);
return WsRpcGroup.of({
[ORCHESTRATION_WS_METHODS.getSnapshot]: (_input) =>
@@ -606,11 +604,8 @@ const WsRpcLayer = WsRpcGroup.toLayer(
Effect.matchCauseEffect({
onFailure: (cause) => Queue.failCause(queue, cause),
onSuccess: () =>
Queue.end(queue).pipe(
Effect.asVoid,
Effect.andThen(
refreshGitStatus(input.cwd).pipe(Effect.ignore({ log: true })),
),
refreshGitStatus(input.cwd).pipe(
Effect.andThen(Queue.end(queue).pipe(Effect.asVoid)),
),
}),
),