Skip to content

Commit cded3b5

Browse files
test(server): share one layer across the identity refresh tests
AI-assisted; verified with the tests and tools listed above.
1 parent 87bd636 commit cded3b5

1 file changed

Lines changed: 74 additions & 130 deletions

File tree

‎apps/server/src/orchestration-v2/RunFinalizationService.test.ts‎

Lines changed: 74 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -262,116 +262,21 @@ it.effect("replaces a still-running PR lookup when a newer turn finishes", () =>
262262
}).pipe(Effect.provide(layer));
263263
});
264264

265-
it.effect("resolves the identity of a project whose remote was added during the turn", () =>
266-
Effect.gen(function* () {
267-
const fileSystem = yield* FileSystem.FileSystem;
268-
const workspaceRoot = yield* fileSystem.makeTempDirectoryScoped({
269-
prefix: "t3-run-finalization-identity-test-",
270-
});
271-
const git = (args: ReadonlyArray<string>) =>
272-
Effect.gen(function* () {
273-
const processRunner = yield* ProcessRunner.ProcessRunner;
274-
return yield* processRunner.run({ command: "git", args: ["-C", workspaceRoot, ...args] });
275-
}).pipe(Effect.provide(ProcessRunner.layer));
276-
yield* git(["init"]);
277-
278-
const projectId = ProjectId.make("project-remote-added");
279-
const threadId = ThreadId.make("thread-remote-added");
280-
const runId = RunId.make("completed-run");
281-
const layerEnrichment = Layer.effect(
282-
ProjectEnrichment.ProjectEnrichmentService,
283-
ProjectEnrichment.make(),
284-
).pipe(
285-
Layer.provideMerge(RepositoryIdentityResolver.layer),
286-
Layer.provideMerge(
287-
Layer.succeed(ProjectFaviconResolver.ProjectFaviconResolver, {
288-
invalidate: () => Effect.void,
289-
resolvePath: () => Effect.succeed(null),
290-
}),
291-
),
292-
);
293-
const layer = RunFinalization.layerObserver.pipe(
294-
Layer.provideMerge(
295-
Layer.mergeAll(
296-
layerEnrichment,
297-
Layer.mock(WorkspaceEntries.WorkspaceEntries)({ refresh: () => Effect.void }),
298-
Layer.mock(PullRequestService.PullRequestService)({
299-
refreshAfterTurn: () => Effect.void,
300-
}),
301-
Layer.mock(VcsStatusBroadcaster.VcsStatusBroadcaster)({
302-
refreshLocalStatus: () =>
303-
Effect.succeed({
304-
isRepo: true,
305-
hasPrimaryRemote: true,
306-
isDefaultRef: true,
307-
refName: "main",
308-
hasWorkingTreeChanges: false,
309-
workingTree: { files: [], insertions: 0, deletions: 0 },
310-
}),
311-
}),
312-
Layer.mock(ProjectionStore.ProjectionStoreV2)({
313-
getThreadShell: () =>
314-
Effect.succeed({
315-
id: threadId,
316-
projectId,
317-
branch: "main",
318-
worktreePath: null,
319-
activeRunId: null,
320-
} as OrchestrationV2ThreadShell),
321-
}),
322-
Layer.mock(ProjectService.ProjectService)({
323-
getById: () => Effect.succeedSome({ id: projectId, workspaceRoot } as Project),
324-
}),
325-
),
326-
),
327-
);
328-
329-
yield* Effect.gen(function* () {
330-
const enrichment = yield* ProjectEnrichment.ProjectEnrichmentService;
331-
// A shell read before the turn caches the folder as having no repository.
332-
assert.isNull(yield* enrichment.readRepositoryIdentity(workspaceRoot));
333-
334-
yield* git(["remote", "add", "origin", "https://github.com/t3-triage/example-29929.git"]);
335-
const changes = yield* enrichment.subscribeChanges;
336-
const observer = yield* RunFinalization.RunFinalizationObserver;
337-
yield* observer.refresh({ cwd: workspaceRoot, threadId, runId });
338-
339-
// The refresh runs in the background; until it publishes, the cached null still reads as resolved.
340-
const change = yield* PubSub.take(changes);
341-
assert.strictEqual(
342-
change.enrichment.repositoryIdentity?.locator.remoteUrl,
343-
"https://github.com/t3-triage/example-29929.git",
344-
"the project's repository identity is still null after the turn added a remote",
345-
);
346-
}).pipe(Effect.scoped, Effect.provide(layer));
347-
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
348-
);
349-
350-
const stubbedIdentityProject = {
351-
projectId: ProjectId.make("project-stubbed-identity"),
352-
threadId: ThreadId.make("thread-stubbed-identity"),
353-
runId: RunId.make("completed-run"),
354-
workspaceRoot: "/repo-stubbed-identity",
355-
};
356-
const stubbedIdentity: RepositoryIdentity = {
357-
canonicalKey: "example.test/stubbed-identity",
358-
locator: {
359-
source: "git-remote",
360-
remoteName: "origin",
361-
remoteUrl: "https://example.test/stubbed-identity.git",
362-
},
363-
};
265+
const identityProjectId = ProjectId.make("project-identity-refresh");
266+
const identityThreadId = ThreadId.make("thread-identity-refresh");
267+
const identityRunId = RunId.make("completed-run");
364268

365-
const layerStubbedIdentityResolver = (
366-
resolve: RepositoryIdentityResolver.RepositoryIdentityResolver["Service"]["resolve"],
269+
const layerIdentityRefresh = <R>(
270+
workspaceRoot: string,
271+
resolver: Layer.Layer<RepositoryIdentityResolver.RepositoryIdentityResolver, never, R>,
367272
) =>
368273
RunFinalization.layerObserver.pipe(
369274
Layer.provideMerge(
370275
Layer.mergeAll(
371276
Layer.effect(ProjectEnrichment.ProjectEnrichmentService, ProjectEnrichment.make()).pipe(
372277
Layer.provide(
373278
Layer.mergeAll(
374-
Layer.succeed(RepositoryIdentityResolver.RepositoryIdentityResolver, { resolve }),
279+
resolver,
375280
Layer.succeed(ProjectFaviconResolver.ProjectFaviconResolver, {
376281
invalidate: () => Effect.void,
377282
resolvePath: () => Effect.succeed(null),
@@ -395,34 +300,90 @@ const layerStubbedIdentityResolver = (
395300
Layer.mock(ProjectionStore.ProjectionStoreV2)({
396301
getThreadShell: () =>
397302
Effect.succeed({
398-
id: stubbedIdentityProject.threadId,
399-
projectId: stubbedIdentityProject.projectId,
303+
id: identityThreadId,
304+
projectId: identityProjectId,
400305
branch: "main",
401306
activeRunId: null,
402307
} as OrchestrationV2ThreadShell),
403308
}),
404309
Layer.mock(ProjectService.ProjectService)({
405-
getById: () =>
406-
Effect.succeedSome({
407-
id: stubbedIdentityProject.projectId,
408-
workspaceRoot: stubbedIdentityProject.workspaceRoot,
409-
} as Project),
310+
getById: () => Effect.succeedSome({ id: identityProjectId, workspaceRoot } as Project),
410311
}),
411312
),
412313
),
413314
);
414315

316+
it.effect("resolves the identity of a project whose remote was added during the turn", () =>
317+
Effect.gen(function* () {
318+
const fileSystem = yield* FileSystem.FileSystem;
319+
const processRunner = yield* ProcessRunner.ProcessRunner;
320+
const workspaceRoot = yield* fileSystem.makeTempDirectoryScoped({
321+
prefix: "t3-run-finalization-identity-test-",
322+
});
323+
const git = (args: ReadonlyArray<string>) =>
324+
processRunner.run({ command: "git", args: ["-C", workspaceRoot, ...args] });
325+
yield* git(["init"]);
326+
327+
yield* Effect.gen(function* () {
328+
const enrichment = yield* ProjectEnrichment.ProjectEnrichmentService;
329+
// A shell read before the turn caches the folder as having no repository.
330+
assert.isNull(yield* enrichment.readRepositoryIdentity(workspaceRoot));
331+
332+
yield* git(["remote", "add", "origin", "https://github.com/t3-triage/example-29929.git"]);
333+
const changes = yield* enrichment.subscribeChanges;
334+
const observer = yield* RunFinalization.RunFinalizationObserver;
335+
yield* observer.refresh({
336+
cwd: workspaceRoot,
337+
threadId: identityThreadId,
338+
runId: identityRunId,
339+
});
340+
341+
const change = yield* PubSub.take(changes);
342+
assert.strictEqual(
343+
change.enrichment.repositoryIdentity?.locator.remoteUrl,
344+
"https://github.com/t3-triage/example-29929.git",
345+
"the project's repository identity is still null after the turn added a remote",
346+
);
347+
}).pipe(
348+
Effect.scoped,
349+
Effect.provide(layerIdentityRefresh(workspaceRoot, RepositoryIdentityResolver.layer)),
350+
);
351+
}).pipe(
352+
Effect.scoped,
353+
Effect.provide(ProcessRunner.layer.pipe(Layer.provideMerge(NodeServices.layer))),
354+
),
355+
);
356+
415357
it.effect("returns from the post-turn refresh while the identity resolver is still running", () => {
416-
const { workspaceRoot, threadId, runId } = stubbedIdentityProject;
358+
const workspaceRoot = "/repo-stubbed-identity";
359+
const identity: RepositoryIdentity = {
360+
canonicalKey: "example.test/stubbed-identity",
361+
locator: {
362+
source: "git-remote",
363+
remoteName: "origin",
364+
remoteUrl: "https://example.test/stubbed-identity.git",
365+
},
366+
};
417367
const releaseResolver = Deferred.makeUnsafe<void>();
418368
let remoteAdded = false;
369+
const resolver = Layer.succeed(RepositoryIdentityResolver.RepositoryIdentityResolver, {
370+
resolve: (_cwd, options) =>
371+
options?.refresh
372+
? Deferred.await(releaseResolver).pipe(
373+
Effect.map(() => {
374+
remoteAdded = true;
375+
return identity;
376+
}),
377+
)
378+
: Effect.sync(() => (remoteAdded ? identity : null)),
379+
});
419380
return Effect.gen(function* () {
420381
const enrichment = yield* ProjectEnrichment.ProjectEnrichmentService;
421382
assert.isNull(yield* enrichment.readRepositoryIdentity(workspaceRoot));
422383
const changes = yield* enrichment.subscribeChanges;
423384
const observer = yield* RunFinalization.RunFinalizationObserver;
424385
const refresh = yield* observer
425-
.refresh({ cwd: workspaceRoot, threadId, runId })
386+
.refresh({ cwd: workspaceRoot, threadId: identityThreadId, runId: identityRunId })
426387
.pipe(Effect.timeoutOption("1 minute"), Effect.forkChild({ startImmediately: true }));
427388
yield* TestClock.adjust("1 minute");
428389
assert.isTrue(
@@ -432,23 +393,6 @@ it.effect("returns from the post-turn refresh while the identity resolver is sti
432393

433394
yield* Deferred.succeed(releaseResolver, undefined);
434395
const change = yield* PubSub.take(changes);
435-
assert.strictEqual(
436-
change.enrichment.repositoryIdentity?.canonicalKey,
437-
stubbedIdentity.canonicalKey,
438-
);
439-
}).pipe(
440-
Effect.scoped,
441-
Effect.provide(
442-
layerStubbedIdentityResolver((_cwd, options) =>
443-
options?.refresh
444-
? Deferred.await(releaseResolver).pipe(
445-
Effect.map(() => {
446-
remoteAdded = true;
447-
return stubbedIdentity;
448-
}),
449-
)
450-
: Effect.sync(() => (remoteAdded ? stubbedIdentity : null)),
451-
),
452-
),
453-
);
396+
assert.strictEqual(change.enrichment.repositoryIdentity?.canonicalKey, identity.canonicalKey);
397+
}).pipe(Effect.scoped, Effect.provide(layerIdentityRefresh(workspaceRoot, resolver)));
454398
});

0 commit comments

Comments
 (0)