TypeScript
fix(contracts): preserve authoritative URLs on pull request links (#21575)
Julius Marminge822091e2d279
diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.tsindex fffba793598..5024127de33 100644--- a/apps/server/src/orchestration-v2/Orchestrator.ts+++ b/apps/server/src/orchestration-v2/Orchestrator.ts@@ -569,6 +569,9 @@ function legacyPullRequestLink(linkedAt: DateTime.formatIso(now),snapshot: null,stack: null,+ ...(existing?.repositoryWebUrl !== undefined && {+ repositoryWebUrl: existing.repositoryWebUrl,+ }),...(existing?.endedWatch && { endedWatch: existing.endedWatch }),},existing?.watch,@@ -3070,10 +3073,20 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functiocommand.source !== "stack-dismissed";if (existing && !undismisses) return thread;const link = existing- ? { ...existing, source: command.source, url: command.url }+ ? {+ ...existing,+ source: command.source,+ url: command.url,+ ...(command.repositoryWebUrl !== undefined && {+ repositoryWebUrl: command.repositoryWebUrl,+ }),+ }: {...key,url: command.url,+ ...(command.repositoryWebUrl !== undefined && {+ repositoryWebUrl: command.repositoryWebUrl,+ }),source: command.source,linkedAt: DateTime.formatIso(now),snapshot: null,@@ -3167,6 +3180,11 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio{...key,url: command.link.url,+ ...((command.link.repositoryWebUrl ?? dismissed?.repositoryWebUrl) !==+ undefined && {+ repositoryWebUrl:+ command.link.repositoryWebUrl ?? dismissed?.repositoryWebUrl,+ }),source: command.link.source,linkedAt: startedAt,snapshot: null,diff --git a/apps/server/src/orchestration-v2/runtimeLayer.test.ts b/apps/server/src/orchestration-v2/runtimeLayer.test.tsindex 1b6a7de8a94..3132ba6a0e9 100644--- a/apps/server/src/orchestration-v2/runtimeLayer.test.ts+++ b/apps/server/src/orchestration-v2/runtimeLayer.test.ts@@ -5375,7 +5375,8 @@ it.layer(Layer.fresh(layerSharedApplicationDataPlaneTest))("compact PR events",worktreePath: null,});const key = { host: "github.com", repository: "pingdotgg/t3code" };- for (const number of [1, 2, 3]) {+ const repositoryWebUrl = "https://github.com/pingdotgg/t3code/pull/2";+ for (const number of [1, 2]) {yield* orchestrator.dispatch({type: "thread.pull-request.link",commandId: CommandId.make(`compact-pr-link-${number}`),@@ -5384,8 +5385,31 @@ it.layer(Layer.fresh(layerSharedApplicationDataPlaneTest))("compact PR events",number,url: `https://github.com/pingdotgg/t3code/pull/${number}`,source: "manual",+ ...(number === 2 ? { repositoryWebUrl } : {}),});}+ const watchedLink = {+ url: "https://github.com/pingdotgg/t3code/pull/3",+ repositoryWebUrl: "https://github.com/pingdotgg/t3code/pull/3",+ source: "manual" as const,+ };+ yield* orchestrator.dispatch({+ type: "thread.pull-request.watch",+ commandId: CommandId.make("compact-pr-watch-new"),+ threadId,+ ...key,+ number: 3,+ watching: true,+ link: watchedLink,+ });+ yield* orchestrator.dispatch({+ type: "thread.pull-request.watch",+ commandId: CommandId.make("compact-pr-watch-existing"),+ threadId,+ ...key,+ number: 2,+ watching: true,+ });const before = yield* orchestrator.getThreadShell(threadId);yield* orchestrator.dispatch({type: "thread.pull-request-link.sync",@@ -5425,6 +5449,8 @@ it.layer(Layer.fresh(layerSharedApplicationDataPlaneTest))("compact PR events",assert.deepEqual(after?.pullRequests?.[0], before?.pullRequests?.[0]);assert.deepEqual(after?.pullRequests?.[2], before?.pullRequests?.[2]);assert.equal(after?.pullRequests?.[1]?.stack?.id, "updated");+ assert.propertyVal(after?.pullRequests?.[1], "repositoryWebUrl", repositoryWebUrl);+ assert.deepInclude(after?.pullRequests?.[2], watchedLink);assert.isTrue((yield* maintenance.rebuild).valid);assert.deepEqual((yield* orchestrator.getThreadShell(threadId))?.pullRequests,diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.tsindex 2dc4296bb96..52037ace794 100644--- a/packages/contracts/src/orchestrationV2.ts+++ b/packages/contracts/src/orchestrationV2.ts@@ -2690,6 +2690,7 @@ export const OrchestrationV2Command = Schema.Union([...ThreadPullRequestKey.fields,url: TrimmedNonEmptyString,source: ThreadPullRequestLinkSource,+ repositoryWebUrl: Schema.optional(TrimmedNonEmptyString),}),Schema.Struct({type: Schema.Literal("thread.pull-request.unlink"),@@ -2712,7 +2713,11 @@ export const OrchestrationV2Command = Schema.Union([...ThreadPullRequestKey.fields,watching: Schema.Boolean,link: Schema.optional(- Schema.Struct({ url: TrimmedNonEmptyString, source: ThreadPullRequestLinkSource }),+ Schema.Struct({+ url: TrimmedNonEmptyString,+ source: ThreadPullRequestLinkSource,+ repositoryWebUrl: Schema.optional(TrimmedNonEmptyString),+ }),),}),Schema.Struct({diff --git a/packages/contracts/src/threadPullRequest.ts b/packages/contracts/src/threadPullRequest.tsindex cf0bdf62414..6d3bf6df087 100644--- a/packages/contracts/src/threadPullRequest.ts+++ b/packages/contracts/src/threadPullRequest.ts@@ -101,6 +101,8 @@ export type ThreadPullRequestWatch = typeof ThreadPullRequestWatch.Type;export const ThreadPullRequestLink = Schema.Struct({...ThreadPullRequestKey.fields,url: TrimmedNonEmptyString,+ /** An actual browser or clone URL; older agent display URLs may be synthesized. */+ repositoryWebUrl: Schema.optional(TrimmedNonEmptyString),source: ThreadPullRequestLinkSource,linkedAt: IsoDateTime,snapshot: Schema.NullOr(ThreadPullRequestSnapshot),