GeezerVison is showing github.com — fix(server): cloned projects no longer show the enclosing repository · pingdotgg/t3code@d1c3253
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -125,6 +125,7 @@ const layerTest = Layer.mergeAll(RuntimeLayer.layer, RuntimeLayer.layerEventSink | 125 | 125 | repositoryIdentityResolved: false, | 126 | 126 | }), | 127 | 127 | invalidate: () => Effect.void, | | 128 | + refresh: () => Effect.void, | 128 | 129 | subscribeChanges: Effect.never, | 129 | 130 | }), | 130 | 131 | ), | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/orchestration-v2/runtimeLayer.test.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -463,6 +463,7 @@ const layerSharedApplicationDataPlaneTest = Layer.mergeAll( | 463 | 463 | repositoryIdentityResolved: false, | 464 | 464 | }), | 465 | 465 | invalidate: () => Effect.void, | | 466 | + refresh: () => Effect.void, | 466 | 467 | subscribeChanges: Effect.never, | 467 | 468 | }), | 468 | 469 | ), | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/project/ProjectEnrichmentService.test.ts +59Lines changed: 59 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import * as NodeServices from "@effect/platform-node/NodeServices"; | 1 | 2 | import { assert, it } from "@effect/vitest"; | 2 | 3 | import type { RepositoryIdentity } from "@t3tools/contracts"; | 3 | 4 | import * as Deferred from "effect/Deferred"; | 4 | 5 | import * as Effect from "effect/Effect"; | | 6 | +import * as FileSystem from "effect/FileSystem"; | 5 | 7 | import * as Layer from "effect/Layer"; | 6 | 8 | import * as Logger from "effect/Logger"; | | 9 | +import * as Path from "effect/Path"; | 7 | 10 | import * as PubSub from "effect/PubSub"; | 8 | 11 | import * as Ref from "effect/Ref"; | 9 | 12 | import { TestClock } from "effect/testing"; | 10 | 13 |
| | 14 | +import * as ProcessRunner from "../processRunner.ts"; | 11 | 15 | import * as WorkspacePaths from "../workspace/WorkspacePaths.ts"; | 12 | 16 |
| 13 | 17 | import * as ProjectEnrichment from "./ProjectEnrichmentService.ts"; | @@ -486,3 +490,58 @@ it.effect( | 486 | 490 | }).pipe(Effect.provide(layer(layerMetadata))); | 487 | 491 | }), | 488 | 492 | ); | | 493 | + | | 494 | +const git = (cwd: string, args: ReadonlyArray<string>) => | | 495 | + Effect.gen(function* () { | | 496 | + const processRunner = yield* ProcessRunner.ProcessRunner; | | 497 | + return yield* processRunner.run({ command: "git", args: ["-C", cwd, ...args] }); | | 498 | + }).pipe(Effect.provide(ProcessRunner.layer)); | | 499 | + | | 500 | +it.layer(NodeServices.layer)("ProjectEnrichmentService with Git", (it) => { | | 501 | + it.effect("shows a clone's own repository once it lands inside another repository", () => | | 502 | + Effect.gen(function* () { | | 503 | + const fileSystem = yield* FileSystem.FileSystem; | | 504 | + const path = yield* Path.Path; | | 505 | + const home = yield* fileSystem.makeTempDirectoryScoped({ | | 506 | + prefix: "t3-project-enrichment-clone-test-", | | 507 | + }); | | 508 | + yield* git(home, ["init"]); | | 509 | + yield* git(home, ["remote", "add", "origin", "[email protected]:example/dotfiles.git"]); | | 510 | + // The clone's project and empty folder exist before git creates the repository. | | 511 | + const destination = path.join(home, "t3code"); | | 512 | + yield* fileSystem.makeDirectory(destination); | | 513 | + | | 514 | + const service = yield* ProjectEnrichment.ProjectEnrichmentService; | | 515 | + const changes = yield* service.subscribeChanges; | | 516 | + yield* service.request(destination); | | 517 | + const duringClone = yield* PubSub.take(changes); | | 518 | + assert.equal( | | 519 | + duringClone.enrichment.repositoryIdentity?.canonicalKey, | | 520 | + "github.com/example/dotfiles", | | 521 | + ); | | 522 | + | | 523 | + yield* git(destination, ["init"]); | | 524 | + yield* git(destination, ["remote", "add", "origin", "[email protected]:example/t3code.git"]); | | 525 | + yield* service.refresh(destination); | | 526 | + | | 527 | + const published = yield* PubSub.take(changes); | | 528 | + assert.equal( | | 529 | + published.enrichment.repositoryIdentity?.canonicalKey, | | 530 | + "github.com/example/t3code", | | 531 | + ); | | 532 | + const afterClone = yield* service.peek(destination); | | 533 | + assert.equal(afterClone.repositoryIdentity?.canonicalKey, "github.com/example/t3code"); | | 534 | + }).pipe( | | 535 | + Effect.provide( | | 536 | + layer( | | 537 | + Layer.merge( | | 538 | + RepositoryIdentityResolver.layer.pipe(Layer.provide(NodeServices.layer)), | | 539 | + Layer.succeed(ProjectFaviconResolver.ProjectFaviconResolver, { | | 540 | + resolvePath: () => Effect.succeed(null), | | 541 | + }), | | 542 | + ), | | 543 | + ), | | 544 | + ), | | 545 | + ), | | 546 | + ); | | 547 | +}); |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/project/ProjectEnrichmentService.ts +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -61,6 +61,11 @@ export class ProjectEnrichmentService extends Context.Service< | 61 | 61 | readonly getAvailable: (workspaceRoot: string) => Effect.Effect<ProjectEnrichment>; | 62 | 62 | /** Invalidate workspace-derived metadata. */ | 63 | 63 | readonly invalidate: (workspaceRoots: Iterable<string>) => Effect.Effect<void>; | | 64 | + /** | | 65 | + * Re-resolve a root whose repository changed on disk, such as a finished | | 66 | + * clone, and publish the new identity. | | 67 | + */ | | 68 | + readonly refresh: (workspaceRoot: string) => Effect.Effect<void>; | 64 | 69 | /** Subscribe to ephemeral completion notifications. */ | 65 | 70 | readonly subscribeChanges: Effect.Effect< | 66 | 71 | PubSub.Subscription<ProjectEnrichmentChange>, | @@ -299,11 +304,22 @@ export const make = Effect.fn("ProjectEnrichmentService.make")(function* ( | 299 | 304 | ); | 300 | 305 | }); | 301 | 306 |
| | 307 | + const refresh: ProjectEnrichmentService["Service"]["refresh"] = Effect.fn( | | 308 | + "ProjectEnrichmentService.refresh", | | 309 | + )(function* (workspaceRoot) { | | 310 | + // Both caches hold the old repository: the resolver's, keyed by Git root, | | 311 | + // and this one, keyed by workspace root. | | 312 | + yield* repositoryIdentityResolver.resolve(workspaceRoot, { refresh: true }); | | 313 | + yield* invalidate([workspaceRoot]); | | 314 | + yield* resolveRepositoryIdentity(workspaceRoot); | | 315 | + }); | | 316 | + | 302 | 317 | return ProjectEnrichmentService.of({ | 303 | 318 | peek, | 304 | 319 | request, | 305 | 320 | getAvailable, | 306 | 321 | invalidate, | | 322 | + refresh, | 307 | 323 | subscribeChanges: PubSub.subscribe(changes), | 308 | 324 | }); | 309 | 325 | }); | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/ws.ts +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1250,6 +1250,7 @@ const layerWsRpc = ( | 1250 | 1250 | const projectCloneTracker = yield* ProjectCloneTracker.ProjectCloneTracker; | 1251 | 1251 | const repositoryIdentityResolver = | 1252 | 1252 | yield* RepositoryIdentityResolver.RepositoryIdentityResolver; | | 1253 | + const projectEnrichment = yield* ProjectEnrichmentService.ProjectEnrichmentService; | 1253 | 1254 | const agentSessionScanner = yield* AgentSessionScanner.AgentSessionScanner; | 1254 | 1255 | const agentSessionImporter = yield* AgentSessionImporter.AgentSessionImporter; | 1255 | 1256 | const checkpointDiffQuery = yield* CheckpointDiffQuery.CheckpointDiffQuery; | @@ -2552,7 +2553,9 @@ const layerWsRpc = ( | 2552 | 2553 | ), | 2553 | 2554 | ), | 2554 | 2555 | onCloned: (project) => | 2555 | | - repositoryIdentityResolver.resolve(project.workspaceRoot, { refresh: true }).pipe( | | 2556 | + // Metadata resolved while the folder was empty may describe an | | 2557 | + // enclosing repository, such as a home directory under Git. | | 2558 | + projectEnrichment.refresh(project.workspaceRoot).pipe( | 2556 | 2559 | Effect.andThen( | 2557 | 2560 | projectService.update({ | 2558 | 2561 | commandId: CommandId.make(`project-clone-done:${project.projectId}`), | |
|