TypeScript
refactor(source-control): GitHub lives in @t3tools/source-control-github (#17607)
Julius Marminge507361bc7301
diff --git a/apps/server/package.json b/apps/server/package.jsonindex ab9ad49d4e6..3dd02fcdcb5 100644--- a/apps/server/package.json+++ b/apps/server/package.json@@ -49,6 +49,7 @@"@t3tools/source-control-bitbucket": "workspace:*","@t3tools/source-control-core": "workspace:*","@t3tools/source-control-forgejo": "workspace:*",+ "@t3tools/source-control-github": "workspace:*","@t3tools/source-control-gitlab": "workspace:*","effect": "catalog:","jose": "catalog:",diff --git a/apps/server/scripts/evaluate-thread-titles.ts b/apps/server/scripts/evaluate-thread-titles.tsindex 598f6cc2f93..cb1553b5cdc 100644--- a/apps/server/scripts/evaluate-thread-titles.ts+++ b/apps/server/scripts/evaluate-thread-titles.ts@@ -23,7 +23,6 @@ import {} from "@t3tools/provider-core/server/threadTitleContext";import * as ThreadTitleLinks from "../src/textGeneration/ThreadTitleLinks.ts";import * as SourceControlProviderRegistry from "../src/sourceControl/SourceControlProviderRegistry.ts";-import * as GitHubApi from "../src/sourceControl/GitHubApi.ts";import * as SourceControlBuiltInDrivers from "../src/sourceControl/builtInDrivers.ts";import * as ServerSettings from "../src/serverSettings.ts";import * as VcsProcess from "../src/vcs/VcsProcess.ts";@@ -147,9 +146,7 @@ await Effect.runPromise(Layer.mergeAll(ProcessRunner.layer,SourceControlProviderRegistry.layer.pipe(- Layer.provide(- Layer.mergeAll(GitHubApi.layerWithDependencies, SourceControlBuiltInDrivers.layer),- ),+ Layer.provide(SourceControlBuiltInDrivers.layer),// Default settings: no saved Bitbucket token, gh's own GitHub account choice.Layer.provide(ServerSettings.layerTest()),Layer.provide(VcsDriverRegistry.layer.pipe(Layer.provide(VcsProjectConfig.layer))),diff --git a/apps/server/scripts/measure-pr-preview.ts b/apps/server/scripts/measure-pr-preview.tsindex 0f33ec9a613..8fca30c9148 100644--- a/apps/server/scripts/measure-pr-preview.ts+++ b/apps/server/scripts/measure-pr-preview.ts@@ -10,14 +10,19 @@ import * as Option from "effect/Option";import * as Schema from "effect/Schema";import { FetchHttpClient } from "effect/http";-import * as GitHubPullRequestApi from "../src/pullRequest/GitHubPullRequestApi.ts";-import * as GitHubPullRequestProvider from "../src/pullRequest/GitHubPullRequestProvider.ts";-import * as GitHubApi from "../src/sourceControl/GitHubApi.ts";-import * as GitHubCredentials from "../src/sourceControl/GitHubCredentials.ts";+import * as GitHubPullRequestApi from "@t3tools/source-control-github/server/GitHubPullRequestApi";+import * as GitHubPullRequestProvider from "@t3tools/source-control-github/server/GitHubPullRequestProvider";+import * as GitHubApi from "@t3tools/source-control-github/server/GitHubApi";+import * as GitHubCredentials from "@t3tools/source-control-github/server/GitHubCredentials";+import * as ServerConfig from "../src/config.ts";import * as ServerSettings from "../src/serverSettings.ts";-import * as GitHubQuota from "../src/sourceControl/githubQuota.ts";+import * as GitHubQuota from "@t3tools/source-control-github/server/GitHubQuota";import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";+import * as ServerSourceControlHost from "../src/sourceControl/ServerSourceControlHost.ts";+import * as GitVcsDriver from "../src/vcs/GitVcsDriver.ts";+import * as VcsDriverRegistry from "../src/vcs/VcsDriverRegistry.ts";import * as VcsProcess from "../src/vcs/VcsProcess.ts";+import * as VcsProjectConfig from "../src/vcs/VcsProjectConfig.ts";const [repository, ...numbers] = process.argv.slice(2);if (!repository || numbers.length === 0 || numbers.some((number) => !/^\d+$/.test(number))) {@@ -41,6 +46,17 @@ function withRateLimit(query: string): string {: `${query.slice(0, end)}\n rateLimit { cost }\n${query.slice(end)}`;}+// The server's host port over default settings: gh's own account choice, no saved token.+const sourceControlHost = ServerSourceControlHost.layer.pipe(+ Layer.provide(VcsDriverRegistry.layer.pipe(Layer.provide(VcsProjectConfig.layer))),+ Layer.provide(GitVcsDriver.layer),+ Layer.provide(ServerSettings.layerTest()),+ // A scratch state directory, so nothing here touches a real T3 home.+ Layer.provide(ServerConfig.layerTest(process.cwd(), { prefix: "t3-measure-pr-preview-" })),+ Layer.provideMerge(VcsProcess.layer),+ Layer.provideMerge(NodeServices.layer),+);+const measuredApi = Layer.effect(GitHubApi.GitHubApi,Effect.gen(function* () {@@ -73,18 +89,15 @@ const measuredApi = Layer.effect(});}),).pipe(- Layer.provide(GitHubCredentials.layer.pipe(Layer.provide(ServerSettings.layerTest()))),+ Layer.provide(GitHubCredentials.layer),Layer.provide(GitHubQuota.layer),Layer.provide(SourceControlRateLimit.layer),Layer.provide(FetchHttpClient.layer),- Layer.provide(VcsProcess.layer),- Layer.provide(NodeServices.layer),);const services = GitHubPullRequestApi.layer.pipe(Layer.provideMerge(measuredApi),- Layer.provideMerge(VcsProcess.layer),- Layer.provideMerge(NodeServices.layer),+ Layer.provideMerge(sourceControlHost),);const encodeJson = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));diff --git a/apps/server/src/assets/AssetAccess.test.ts b/apps/server/src/assets/AssetAccess.test.tsindex 12ec0025697..61197efb6a5 100644--- a/apps/server/src/assets/AssetAccess.test.ts+++ b/apps/server/src/assets/AssetAccess.test.ts@@ -35,7 +35,7 @@ import { ASSET_ROUTE_PREFIX, issueAssetUrl, resolveAsset } from "./AssetAccess.timport * as NativeAppIconResolver from "./NativeAppIconResolver.ts";import { openMediaFile } from "./MediaFile.ts";import { symlinksSupported } from "@t3tools/shared/testing/symlinks";-import * as GitHubCredentials from "../sourceControl/GitHubCredentials.ts";+import * as GitHubCredentials from "@t3tools/source-control-github/server/GitHubCredentials";import { githubMediaResponse } from "./GitHubMediaFetch.ts";vi.mock("node:fs/promises", async (importOriginal) => {diff --git a/apps/server/src/assets/GitHubMediaFetch.ts b/apps/server/src/assets/GitHubMediaFetch.tsindex 7b26c3e69ac..d05308f2afe 100644--- a/apps/server/src/assets/GitHubMediaFetch.ts+++ b/apps/server/src/assets/GitHubMediaFetch.ts@@ -12,7 +12,7 @@ import {type HttpClientResponse,} from "effect/http";-import * as GitHubCredentials from "../sourceControl/GitHubCredentials.ts";+import * as GitHubCredentials from "@t3tools/source-control-github/server/GitHubCredentials";/*** Exactly the hosts the credential is for. Everything a redirect leads to — the presigneddiff --git a/apps/server/src/git/GitManager.test.ts b/apps/server/src/git/GitManager.test.tsindex 92b7fcd607f..24dd7e1d54e 100644--- a/apps/server/src/git/GitManager.test.ts+++ b/apps/server/src/git/GitManager.test.ts@@ -43,7 +43,7 @@ import {ThreadId,} from "@t3tools/contracts";import * as DateTime from "effect/DateTime";-import { decodeGitHubPullRequestListJson } from "../sourceControl/gitHubPullRequests.ts";+import { decodeGitHubPullRequestListJson } from "@t3tools/source-control-github/server/gitHubPullRequests";import * as GitLabCli from "@t3tools/source-control-gitlab/server/GitLabCli";import type * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost";diff --git a/apps/server/src/pullRequest/PullRequestProviderRateLimit.test.ts b/apps/server/src/pullRequest/PullRequestProviderRateLimit.test.tsindex 6d35adc0724..8271c2f22dc 100644--- a/apps/server/src/pullRequest/PullRequestProviderRateLimit.test.ts+++ b/apps/server/src/pullRequest/PullRequestProviderRateLimit.test.ts@@ -2,12 +2,12 @@ import { assert, it } from "@effect/vitest";import * as AzureDevOpsCli from "@t3tools/source-control-azure-devops/server/AzureDevOpsCli";import * as BitbucketApi from "@t3tools/source-control-bitbucket/server/BitbucketApi";-import * as GitHubApi from "../sourceControl/GitHubApi.ts";+import * as GitHubApi from "@t3tools/source-control-github/server/GitHubApi";import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";import * as GitLabCli from "@t3tools/source-control-gitlab/server/GitLabCli";import { azureDevOpsProviderFailure } from "@t3tools/source-control-azure-devops/server/AzureDevOpsPullRequestProvider";import { bitbucketProviderFailure } from "@t3tools/source-control-bitbucket/server/BitbucketPullRequestProvider";-import { gitHubProviderFailure } from "./GitHubPullRequestProvider.ts";+import { gitHubProviderFailure } from "@t3tools/source-control-github/server/GitHubPullRequestProvider";import { gitLabProviderFailure } from "@t3tools/source-control-gitlab/server/GitLabPullRequestProvider";const cause = new Error("redacted provider failure");diff --git a/apps/server/src/pullRequest/PullRequestProviderRegistry.ts b/apps/server/src/pullRequest/PullRequestProviderRegistry.tsindex 5702957a0ff..66607a4c8ab 100644--- a/apps/server/src/pullRequest/PullRequestProviderRegistry.ts+++ b/apps/server/src/pullRequest/PullRequestProviderRegistry.ts@@ -3,9 +3,6 @@ import * as Effect from "effect/Effect";import * as Layer from "effect/Layer";import type { SourceControlProviderKind } from "@t3tools/contracts";-import * as GitHubApi from "../sourceControl/GitHubApi.ts";-import * as GitHubPullRequestApi from "./GitHubPullRequestApi.ts";-import * as GitHubPullRequestProvider from "./GitHubPullRequestProvider.ts";import * as BuiltInDrivers from "../sourceControl/builtInDrivers.ts";import type { PullRequestProviderApi } from "@t3tools/source-control-core/server/PullRequestProvider";@@ -36,24 +33,14 @@ export function fromProviders(* @public Service construction is part of the canonical Effect module API.*/export const make = Effect.gen(function* () {- const providers = yield* Effect.all([GitHubPullRequestProvider.make]);const drivers = yield* Effect.forEach(BuiltInDrivers.BUILT_IN_SOURCE_CONTROL_DRIVERS, (driver) =>driver.make.pipe(Effect.map((instance) => instance.pullRequests)),);- return fromProviders([- ...providers,- ...drivers.filter((provider): provider is PullRequestProviderApi => provider !== null),- ]);+ return fromProviders(+ drivers.filter((provider): provider is PullRequestProviderApi => provider !== null),+ );});export const layer = Layer.effect(PullRequestProviderRegistry, make).pipe(- Layer.provide(- GitHubPullRequestApi.layer.pipe(- Layer.provide(- // Built here too, so a registry built alone still has one budget and pause per host.- GitHubApi.layerWithDependencies,- ),- ),- ),Layer.provide(BuiltInDrivers.layer),);diff --git a/apps/server/src/pullRequest/PullRequestService.ts b/apps/server/src/pullRequest/PullRequestService.tsindex fb14ef896cd..0295673350b 100644--- a/apps/server/src/pullRequest/PullRequestService.ts+++ b/apps/server/src/pullRequest/PullRequestService.ts@@ -77,7 +77,7 @@ import {import { resolveProjectSettings } from "@t3tools/shared/projectSettings";import { detectSourceControlProviderFromRemoteUrl } from "@t3tools/shared/sourceControl";-import { AllowGitHubReserve } from "../sourceControl/GitHubApi.ts";+import { AllowGitHubReserve } from "@t3tools/source-control-github/server/GitHubApi";import * as ProjectService from "../project/ProjectService.ts";import * as ServerSettings from "../serverSettings.ts";import * as PullRequestFilesViewed from "../persistence/PullRequestFilesViewed.ts";diff --git a/apps/server/src/server.ts b/apps/server/src/server.tsindex ff4c4ef6c21..a5e23ed65b5 100644--- a/apps/server/src/server.ts+++ b/apps/server/src/server.ts@@ -52,7 +52,6 @@ import * as ProviderHostLive from "./provider/ProviderHostLive.ts";import * as AcpRegistrySupport from "@t3tools/provider-acp-registry/server/AcpRegistrySupport";import * as CheckpointDiffQuery from "./checkpointing/CheckpointDiffQuery.ts";import * as CheckpointStore from "./checkpointing/CheckpointStore.ts";-import * as GitHubApi from "./sourceControl/GitHubApi.ts";import * as ForgejoCli from "@t3tools/source-control-forgejo/server/ForgejoCli";import * as SourceControlBuiltInDrivers from "./sourceControl/builtInDrivers.ts";import * as TextGeneration from "./textGeneration/TextGeneration.ts";@@ -296,7 +295,7 @@ const layerPersistence = Layer.empty.pipe(Layer.provideMerge(SqlitePersistence.lconst layerVcsDriverRegistry = VcsDriverRegistry.layer.pipe(Layer.provide(VcsProjectConfig.layer));const layerSourceControlProviderRegistry = SourceControlProviderRegistry.layer.pipe(- Layer.provide(Layer.mergeAll(GitHubApi.layerWithDependencies, SourceControlBuiltInDrivers.layer)),+ Layer.provideMerge(SourceControlBuiltInDrivers.layer),Layer.provideMerge(GitVcsDriver.layer),Layer.provideMerge(layerVcsDriverRegistry),);@@ -585,9 +584,9 @@ const layerRuntimeCoreDependenciesBase = Layer.mergeAll(Layer.provideMerge(RuntimeLayer.layerEventInfrastructure),Layer.provideMerge(Layer.merge(ProjectStore.layer, ThreadSearch.layer)),Layer.provideMerge(layerServerSettings),- // The asset route uses the registry's GitHub credential for private PR media.+ // The asset route uses the registry's GitHub credential for private PR media, which the+ // built-in drivers' layer provides alongside the registry.Layer.provideMerge(layerSourceControlProviderRegistry),- Layer.provideMerge(GitHubApi.layerWithDependencies),Layer.provideMerge(layerGit),Layer.provideMerge(layerVcs),Layer.provideMerge(Layer.mergeAll(layerTerminal, layerPreview, layerDevice)),diff --git a/apps/server/src/sourceControl/ServerSourceControlHost.ts b/apps/server/src/sourceControl/ServerSourceControlHost.tsindex a21e7d5fe08..c5c55fd85ab 100644--- a/apps/server/src/sourceControl/ServerSourceControlHost.ts+++ b/apps/server/src/sourceControl/ServerSourceControlHost.ts@@ -24,6 +24,8 @@ export const layer = Layer.effect(settings: { get: serverSettings.getSettings },process: { run: process.run },git: {+ execute: git.execute,+ resolveCommit: git.resolveCommit,remotes: (cwd) =>vcsRegistry.resolve({ cwd }).pipe(Effect.map((handle) => handle.driver.listRemotes(cwd))),readConfigValue: git.readConfigValue,diff --git a/apps/server/src/sourceControl/SourceControlDiscovery.test.ts b/apps/server/src/sourceControl/SourceControlDiscovery.test.tsindex 3cda7d31d9f..b4503fb7535 100644--- a/apps/server/src/sourceControl/SourceControlDiscovery.test.ts+++ b/apps/server/src/sourceControl/SourceControlDiscovery.test.ts@@ -20,7 +20,8 @@ import * as AzureDevOpsCli from "@t3tools/source-control-azure-devops/server/Azuimport * as AzureDevOpsPullRequestCli from "@t3tools/source-control-azure-devops/server/AzureDevOpsPullRequestCli";import * as BitbucketApi from "@t3tools/source-control-bitbucket/server/BitbucketApi";import * as BitbucketPullRequestApi from "@t3tools/source-control-bitbucket/server/BitbucketPullRequestApi";-import * as GitHubApi from "./GitHubApi.ts";+import * as GitHubApi from "@t3tools/source-control-github/server/GitHubApi";+import * as GitHubPullRequestApi from "@t3tools/source-control-github/server/GitHubPullRequestApi";import * as GitLabCli from "@t3tools/source-control-gitlab/server/GitLabCli";import * as GitLabPullRequestCli from "@t3tools/source-control-gitlab/server/GitLabPullRequestCli";import * as ForgejoCli from "@t3tools/source-control-forgejo/server/ForgejoCli";@@ -46,6 +47,7 @@ const layerSourceControlProviderRegistryTest = (input: {Layer.mock(BitbucketApi.BitbucketApi)(input.bitbucket),Layer.mock(BitbucketPullRequestApi.BitbucketPullRequestApi)({}),ServerSettings.ServerSettingsService.layerTest(),+ Layer.mock(GitHubPullRequestApi.GitHubPullRequestApi)({}),Layer.mock(GitHubApi.GitHubApi)({}),Layer.mock(GitVcsDriver.GitVcsDriver)({}),Layer.mock(GitLabCli.GitLabCli)({}),diff --git a/apps/server/src/sourceControl/SourceControlProviderRegistry.test.ts b/apps/server/src/sourceControl/SourceControlProviderRegistry.test.tsindex b16ccfa44e7..bfed745ca29 100644--- a/apps/server/src/sourceControl/SourceControlProviderRegistry.test.ts+++ b/apps/server/src/sourceControl/SourceControlProviderRegistry.test.ts@@ -18,8 +18,9 @@ import * as AzureDevOpsPullRequestCli from "@t3tools/source-control-azure-devopsimport * as BitbucketApi from "@t3tools/source-control-bitbucket/server/BitbucketApi";import * as BitbucketPullRequestApi from "@t3tools/source-control-bitbucket/server/BitbucketPullRequestApi";import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";-import * as GitHubApi from "./GitHubApi.ts";-import * as GitHubCredentials from "./GitHubCredentials.ts";+import * as GitHubApi from "@t3tools/source-control-github/server/GitHubApi";+import * as GitHubPullRequestApi from "@t3tools/source-control-github/server/GitHubPullRequestApi";+import * as GitHubCredentials from "@t3tools/source-control-github/server/GitHubCredentials";import * as GitLabCli from "@t3tools/source-control-gitlab/server/GitLabCli";import * as GitLabPullRequestCli from "@t3tools/source-control-gitlab/server/GitLabPullRequestCli";import * as ForgejoCli from "@t3tools/source-control-forgejo/server/ForgejoCli";@@ -115,6 +116,7 @@ function makeRegistry(input: {Layer.mock(BitbucketApi.BitbucketApi)({}),Layer.mock(BitbucketPullRequestApi.BitbucketPullRequestApi)({}),ServerSettings.ServerSettingsService.layerTest(),+ Layer.mock(GitHubPullRequestApi.GitHubPullRequestApi)({}),Layer.mock(GitHubApi.GitHubApi)({// No GitHub credential unless a test supplies one, so custom hosts stay unclaimed.credential: (host) => Effect.fail(new GitHubCredentials.GitHubNotSignedInError({ host })),diff --git a/apps/server/src/sourceControl/SourceControlProviderRegistry.ts b/apps/server/src/sourceControl/SourceControlProviderRegistry.tsindex 607e1b957b9..153e8c21b11 100644--- a/apps/server/src/sourceControl/SourceControlProviderRegistry.ts+++ b/apps/server/src/sourceControl/SourceControlProviderRegistry.ts@@ -11,7 +11,6 @@ import {import type { SourceControlProviderKind } from "@t3tools/contracts";import { detectSourceControlProviderFromRemoteUrl } from "@t3tools/shared/sourceControl";-import * as GitHubSourceControlProvider from "./GitHubSourceControlProvider.ts";import * as BuiltInDrivers from "./builtInDrivers.ts";import * as SourceControlProvider from "@t3tools/source-control-core/server/SourceControlProvider";import {@@ -302,8 +301,6 @@ export const makeWithProviders = Effect.fn("makeSourceControlProviderRegistryWit);export const make = Effect.gen(function* () {- const github = yield* GitHubSourceControlProvider.make;- const githubDiscovery = yield* GitHubSourceControlProvider.makeDiscovery;const drivers = yield* Effect.forEach(BuiltInDrivers.BUILT_IN_SOURCE_CONTROL_DRIVERS, (driver) =>driver.make.pipe(Effect.map((instance): SourceControlProviderRegistration => ({@@ -313,19 +310,7 @@ export const make = Effect.gen(function* () {})),),);- // Discovery lists hosts in this order, so it is kept while hosts move into packages.- const order = ["github", "gitlab", "azure-devops", "bitbucket", "forgejo"];- const registrations: ReadonlyArray<SourceControlProviderRegistration> = [- {- kind: "github",- provider: github,- discovery: githubDiscovery,- },- ...drivers,- ];- return yield* makeWithProviders(- registrations.toSorted((left, right) => order.indexOf(left.kind) - order.indexOf(right.kind)),- );+ return yield* makeWithProviders(drivers);});export const layer = Layer.effect(SourceControlProviderRegistry, make);diff --git a/apps/server/src/sourceControl/builtInDrivers.ts b/apps/server/src/sourceControl/builtInDrivers.tsindex 9a972e9e5f0..2e830dec803 100644--- a/apps/server/src/sourceControl/builtInDrivers.ts+++ b/apps/server/src/sourceControl/builtInDrivers.ts@@ -15,6 +15,9 @@ import * as BitbucketPullRequestApi from "@t3tools/source-control-bitbucket/servimport * as BitbucketDriver from "@t3tools/source-control-bitbucket/server/driver";import * as ForgejoCli from "@t3tools/source-control-forgejo/server/ForgejoCli";import * as ForgejoDriver from "@t3tools/source-control-forgejo/server/driver";+import * as GitHubApi from "@t3tools/source-control-github/server/GitHubApi";+import * as GitHubPullRequestApi from "@t3tools/source-control-github/server/GitHubPullRequestApi";+import * as GitHubDriver from "@t3tools/source-control-github/server/driver";import * as GitLabCli from "@t3tools/source-control-gitlab/server/GitLabCli";import * as GitLabPullRequestCli from "@t3tools/source-control-gitlab/server/GitLabPullRequestCli";import * as GitLabDriver from "@t3tools/source-control-gitlab/server/driver";@@ -24,6 +27,7 @@ import * as Layer from "effect/Layer";import * as ServerSourceControlHost from "./ServerSourceControlHost.ts";const drivers = [+ GitHubDriver.driver,GitLabDriver.driver,AzureDevOpsDriver.driver,BitbucketDriver.driver,@@ -34,12 +38,16 @@ const drivers = [export type BuiltInSourceControlDriversEnv =(typeof drivers)[number] extends SourceControlDriver<infer R> ? R : never;+/** Ordered as the hosts appear in discovery. */export const BUILT_IN_SOURCE_CONTROL_DRIVERS: ReadonlyArray<SourceControlDriver<BuiltInSourceControlDriversEnv>> = drivers;/** The services the built-in drivers' packages own, plus the host port they all run against. */export const layer = Layer.mergeAll(+ // `GitHubApi.layerWithDependencies` carries the quota reserve and rate-limit pause every GitHub+ // reader shares, so the server builds it once, here.+ GitHubPullRequestApi.layer.pipe(Layer.provideMerge(GitHubApi.layerWithDependencies)),AzureDevOpsPullRequestCli.layer.pipe(Layer.provideMerge(AzureDevOpsCli.layer)),BitbucketPullRequestApi.layer.pipe(Layer.provideMerge(BitbucketApi.layer)),ForgejoCli.layer,diff --git a/apps/server/src/pullRequest/githubStackRebase.test.ts b/apps/server/src/sourceControl/githubStackRebase.test.tssimilarity index 88%rename from apps/server/src/pullRequest/githubStackRebase.test.tsrename to apps/server/src/sourceControl/githubStackRebase.test.tsindex 26b801d13bd..613c0016c65 100644--- a/apps/server/src/pullRequest/githubStackRebase.test.ts+++ b/apps/server/src/sourceControl/githubStackRebase.test.ts@@ -5,15 +5,26 @@ import * as FileSystem from "effect/FileSystem";import * as Layer from "effect/Layer";import * as Redacted from "effect/Redacted";-import * as GitHubApi from "../sourceControl/GitHubApi.ts";+import * as GitHubApi from "@t3tools/source-control-github/server/GitHubApi";+import { cascadeRebaseStack } from "@t3tools/source-control-github/server/githubStackRebase";++import * as ServerSettings from "../serverSettings.ts";+import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";+import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts";import * as VcsProcess from "../vcs/VcsProcess.ts";-import { cascadeRebaseStack } from "./githubStackRebase.ts";+import * as ServerSourceControlHost from "./ServerSourceControlHost.ts";const layer = Layer.mergeAll(Layer.mock(GitHubApi.GitHubApi)({credential: () => Effect.succeed({ token: Redacted.make("token"), fingerprint: "fp" }),}),- VcsProcess.layer,+ // The cascade runs real git through the server's host; the git driver itself is never asked.+ ServerSourceControlHost.layer.pipe(+ Layer.provide(ServerSettings.layerTest()),+ Layer.provide(Layer.mock(GitVcsDriver.GitVcsDriver)({})),+ Layer.provide(Layer.mock(VcsDriverRegistry.VcsDriverRegistry)({})),+ Layer.provideMerge(VcsProcess.layer),+ ),).pipe(Layer.provideMerge(NodeServices.layer));/**diff --git a/apps/server/src/ws.ts b/apps/server/src/ws.tsindex a3b239ffaa6..8e7a1210a50 100644--- a/apps/server/src/ws.ts+++ b/apps/server/src/ws.ts@@ -229,7 +229,6 @@ import * as SqlClient from "effect/sql/SqlClient";import * as PullRequestSyncReactor from "./orchestration-v2/PullRequestSyncReactor.ts";import * as SourceControlDiscovery from "./sourceControl/SourceControlDiscovery.ts";import * as SourceControlRepositoryService from "./sourceControl/SourceControlRepositoryService.ts";-import * as GitHubApi from "./sourceControl/GitHubApi.ts";import * as SourceControlBuiltInDrivers from "./sourceControl/builtInDrivers.ts";import * as SourceControlProviderRegistry from "./sourceControl/SourceControlProviderRegistry.ts";import * as GitVcsDriver from "./vcs/GitVcsDriver.ts";@@ -3199,12 +3198,7 @@ export const layer = Layer.unwrap(SourceControlDiscovery.layer.pipe(Layer.provide(SourceControlProviderRegistry.layer.pipe(- Layer.provide(- Layer.mergeAll(- GitHubApi.layerWithDependencies,- SourceControlBuiltInDrivers.layer,- ),- ),+ Layer.provide(SourceControlBuiltInDrivers.layer),Layer.provideMerge(GitVcsDriver.layer),Layer.provide(VcsDriverRegistry.layer.pipe(Layer.provide(VcsProjectConfig.layer)),diff --git a/package.json b/package.jsonindex 764f45f27c9..ba161940d2f 100644--- a/package.json+++ b/package.json@@ -28,7 +28,7 @@"tc": "vp run -r --concurrency-limit 2 typecheck","lint": "vp lint --report-unused-disable-directives","knip": "knip --preprocessor ./scripts/knip-schemas.ts",- "knip:check": "knip --include files,dependencies --no-config-hints && knip --workspace apps/server --workspace apps/desktop --workspace apps/web --workspace packages/client-runtime --workspace packages/contracts --workspace packages/effect-acp --workspace packages/effect-codex-app-server --workspace packages/shared --workspace packages/ssh --workspace packages/tailscale --workspace packages/provider-core --workspace packages/provider-acp --workspace packages/provider-acp-registry --workspace packages/provider-testing --workspace packages/provider-pi --workspace packages/provider-muse --workspace packages/provider-opencode --workspace packages/provider-cursor --workspace packages/provider-grok --workspace packages/source-control-core --workspace packages/source-control-azure-devops --workspace packages/source-control-bitbucket --workspace packages/source-control-forgejo --workspace packages/source-control-gitlab --workspace packages/source-control-testing --exports --preprocessor ./scripts/knip-schemas.ts --no-config-hints",+ "knip:check": "knip --include files,dependencies --no-config-hints && knip --workspace apps/server --workspace apps/desktop --workspace apps/web --workspace packages/client-runtime --workspace packages/contracts --workspace packages/effect-acp --workspace packages/effect-codex-app-server --workspace packages/shared --workspace packages/ssh --workspace packages/tailscale --workspace packages/provider-core --workspace packages/provider-acp --workspace packages/provider-acp-registry --workspace packages/provider-testing --workspace packages/provider-pi --workspace packages/provider-muse --workspace packages/provider-opencode --workspace packages/provider-cursor --workspace packages/provider-grok --workspace packages/source-control-core --workspace packages/source-control-azure-devops --workspace packages/source-control-bitbucket --workspace packages/source-control-forgejo --workspace packages/source-control-github --workspace packages/source-control-gitlab --workspace packages/source-control-testing --exports --preprocessor ./scripts/knip-schemas.ts --no-config-hints","knip:production": "knip --production --preprocessor ./scripts/knip-schemas.ts","lint:mobile": "node scripts/mobile-native-static-check.ts","test": "vp run -r test",diff --git a/packages/source-control-core/src/server/SourceControlHost.ts b/packages/source-control-core/src/server/SourceControlHost.tsindex 564b318d85b..a46db0fccf2 100644--- a/packages/source-control-core/src/server/SourceControlHost.ts+++ b/packages/source-control-core/src/server/SourceControlHost.ts@@ -54,6 +54,11 @@ export interface SourceControlProcessOutput {readonly stderrInvalidUtf8?: boolean;}+export type SourceControlGitOutput = Omit<+ SourceControlProcessOutput,+ "stdoutInvalidUtf8" | "stderrInvalidUtf8"+>;+export interface SourceControlGitRemoteBranch {readonly cwd: string;readonly remoteName: string;@@ -73,6 +78,16 @@ export class SourceControlHost extends Context.Service<) => Effect.Effect<SourceControlProcessOutput, VcsError>;};readonly git: {+ /** Runs `git -C cwd …args` through the server's git driver, with its limits and metrics. */+ readonly execute: (input: {+ readonly operation: string;+ readonly cwd: string;+ readonly args: ReadonlyArray<string>;+ }) => Effect.Effect<SourceControlGitOutput, GitCommandError>;+ readonly resolveCommit: (input: {+ readonly cwd: string;+ readonly revision: string;+ }) => Effect.Effect<{ readonly commitSha: string }, GitCommandError>;/*** Lists the remotes of the repository at `cwd`. The outer effect resolves the repository* and fails when the server cannot drive one there; the inner one lists its remotes.diff --git a/packages/source-control-github/package.json b/packages/source-control-github/package.jsonnew file mode 100644index 00000000000..739d6e8b5f3--- /dev/null+++ b/packages/source-control-github/package.json@@ -0,0 +1,85 @@+{+ "name": "@t3tools/source-control-github",+ "private": true,+ "type": "module",+ "exports": {+ "./server/driver": {+ "types": "./src/server/driver.ts",+ "import": "./src/server/driver.ts"+ },+ "./server/GitHubApi": {+ "types": "./src/server/GitHubApi.ts",+ "import": "./src/server/GitHubApi.ts"+ },+ "./server/gitHubAuthStatus": {+ "types": "./src/server/gitHubAuthStatus.ts",+ "import": "./src/server/gitHubAuthStatus.ts"+ },+ "./server/gitHubConditionalChecks": {+ "types": "./src/server/gitHubConditionalChecks.ts",+ "import": "./src/server/gitHubConditionalChecks.ts"+ },+ "./server/GitHubCredentials": {+ "types": "./src/server/GitHubCredentials.ts",+ "import": "./src/server/GitHubCredentials.ts"+ },+ "./server/githubGraphQl": {+ "types": "./src/server/githubGraphQl.ts",+ "import": "./src/server/githubGraphQl.ts"+ },+ "./server/GitHubPullRequestApi": {+ "types": "./src/server/GitHubPullRequestApi.ts",+ "import": "./src/server/GitHubPullRequestApi.ts"+ },+ "./server/gitHubPullRequestJson": {+ "types": "./src/server/gitHubPullRequestJson.ts",+ "import": "./src/server/gitHubPullRequestJson.ts"+ },+ "./server/GitHubPullRequestProvider": {+ "types": "./src/server/GitHubPullRequestProvider.ts",+ "import": "./src/server/GitHubPullRequestProvider.ts"+ },+ "./server/gitHubPullRequests": {+ "types": "./src/server/gitHubPullRequests.ts",+ "import": "./src/server/gitHubPullRequests.ts"+ },+ "./server/GitHubQuota": {+ "types": "./src/server/GitHubQuota.ts",+ "import": "./src/server/GitHubQuota.ts"+ },+ "./server/gitHubRepositoryResolution": {+ "types": "./src/server/gitHubRepositoryResolution.ts",+ "import": "./src/server/gitHubRepositoryResolution.ts"+ },+ "./server/GitHubSourceControlProvider": {+ "types": "./src/server/GitHubSourceControlProvider.ts",+ "import": "./src/server/GitHubSourceControlProvider.ts"+ },+ "./server/githubStackActions": {+ "types": "./src/server/githubStackActions.ts",+ "import": "./src/server/githubStackActions.ts"+ },+ "./server/githubStackRebase": {+ "types": "./src/server/githubStackRebase.ts",+ "import": "./src/server/githubStackRebase.ts"+ }+ },+ "scripts": {+ "typecheck": "tsc --noEmit",+ "test": "vp test run --config ../../vite.config.ts --dir ."+ },+ "dependencies": {+ "@t3tools/contracts": "workspace:*",+ "@t3tools/provider-core": "workspace:*",+ "@t3tools/shared": "workspace:*",+ "@t3tools/source-control-core": "workspace:*",+ "effect": "catalog:"+ },+ "devDependencies": {+ "@effect/platform-node": "catalog:",+ "@effect/vitest": "catalog:",+ "@t3tools/source-control-testing": "workspace:*",+ "@types/node": "catalog:",+ "vite-plus": "catalog:"+ }+}diff --git a/apps/server/src/sourceControl/GitHubApi.test.ts b/packages/source-control-github/src/server/GitHubApi.test.tssimilarity index 97%rename from apps/server/src/sourceControl/GitHubApi.test.tsrename to packages/source-control-github/src/server/GitHubApi.test.tsindex cd4c2fb384f..3287ebb8e1a 100644--- a/apps/server/src/sourceControl/GitHubApi.test.ts+++ b/packages/source-control-github/src/server/GitHubApi.test.ts@@ -1,4 +1,5 @@import { describe, expect, it } from "@effect/vitest";+import * as NodeCrypto from "@effect/platform-node/NodeCrypto";import * as NodeServices from "@effect/platform-node/NodeServices";import * as Effect from "effect/Effect";import * as Layer from "effect/Layer";@@ -12,10 +13,10 @@ import { HttpClient, HttpClientResponse, type HttpClientRequest } from "effect/himport * as GitHubApi from "./GitHubApi.ts";import * as GitHubCredentials from "./GitHubCredentials.ts";-import * as GitHubQuota from "./githubQuota.ts";+import * as GitHubQuota from "./GitHubQuota.ts";import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";-import * as VcsProcess from "../vcs/VcsProcess.ts";-import * as ServerSettings from "../serverSettings.ts";+import type * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";+import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost";const NOW = Date.parse("2026-10-05T12:00:00.000Z");@@ -439,11 +440,10 @@ describe("GitHubApi", () => {});describe("GitHubCredentials", () => {- const credentialsWith = (run: VcsProcess.VcsProcess["Service"]["run"]) =>+ const credentialsWith = (run: SourceControlHost.SourceControlHost["Service"]["process"]["run"]) =>GitHubCredentials.layer.pipe(- Layer.provide(Layer.mock(VcsProcess.VcsProcess)({ run })),- Layer.provide(NodeServices.layer),- Layer.provide(ServerSettings.layerTest()),+ Layer.provide(TestSourceControlHost.layer({ process: { run } })),+ Layer.provide(NodeCrypto.layer),);it.effect("fails with GitHubCliMissingError when gh is not on PATH", () =>diff --git a/apps/server/src/sourceControl/GitHubApi.ts b/packages/source-control-github/src/server/GitHubApi.tssimilarity index 98%rename from apps/server/src/sourceControl/GitHubApi.tsrename to packages/source-control-github/src/server/GitHubApi.tsindex 1cc66a1323c..e734e5ff07a 100644--- a/apps/server/src/sourceControl/GitHubApi.ts+++ b/packages/source-control-github/src/server/GitHubApi.ts@@ -12,7 +12,7 @@ import { HttpClient, HttpClientRequest, type HttpClientResponse } from "effect/himport { collectUint8StreamText } from "@t3tools/provider-core/server/collectStreamText";import * as GitHubCredentials from "./GitHubCredentials.ts";-import * as GitHubQuota from "./githubQuota.ts";+import * as GitHubQuota from "./GitHubQuota.ts";import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";const DEFAULT_TIMEOUT = Duration.seconds(30);@@ -30,7 +30,9 @@ export const PinnedGitHubCredential = Context.Reference<{readonly host: string;readonly token: Redacted.Redacted<string>;readonly credentialFingerprint: string;-} | null>("t3/sourceControl/PinnedGitHubCredential", { defaultValue: () => null });+} | null>("@t3tools/source-control-github/server/GitHubApi/PinnedGitHubCredential", {+ defaultValue: () => null,+});/*** Set by interactive callers (a user's read or write, not a background sweep). Requests made@@ -38,7 +40,7 @@ export const PinnedGitHubCredential = Context.Reference<{* pull request should not be refused because a background read exhausted the quota.*/export const AllowGitHubReserve = Context.Reference<boolean>(- "t3/sourceControl/AllowGitHubReserve",+ "@t3tools/source-control-github/server/GitHubApi/AllowGitHubReserve",{ defaultValue: () => false },);@@ -162,7 +164,7 @@ export class GitHubApi extends Context.Service<GitHubApiError>;}->()("t3/sourceControl/GitHubApi") {}+>()("@t3tools/source-control-github/server/GitHubApi") {}function normalizeHost(host: string): string {return host.trim().toLowerCase();diff --git a/apps/server/src/sourceControl/GitHubCredentials.test.ts b/packages/source-control-github/src/server/GitHubCredentials.test.tssimilarity index 76%rename from apps/server/src/sourceControl/GitHubCredentials.test.tsrename to packages/source-control-github/src/server/GitHubCredentials.test.tsindex 734a309f002..15ac6bf648a 100644--- a/apps/server/src/sourceControl/GitHubCredentials.test.ts+++ b/packages/source-control-github/src/server/GitHubCredentials.test.ts@@ -1,12 +1,14 @@+import * as NodeCrypto from "@effect/platform-node/NodeCrypto";import { afterEach, beforeEach, describe, expect, it, vi } from "@effect/vitest";-import * as NodeServices from "@effect/platform-node/NodeServices";import * as Effect from "effect/Effect";import * as Layer from "effect/Layer";import * as Redacted from "effect/Redacted";import { ChildProcessSpawner } from "effect/process";-import * as ServerSettings from "../serverSettings.ts";-import * as VcsProcess from "../vcs/VcsProcess.ts";+import { DEFAULT_SERVER_SETTINGS } from "@t3tools/contracts";+import type * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";+import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings";+import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost";import * as GitHubCredentials from "./GitHubCredentials.ts";const TOKEN_VARIABLES = [@@ -16,41 +18,51 @@ const TOKEN_VARIABLES = ["GITHUB_ENTERPRISE_TOKEN",] as const;+/** Settings keep `enabled` explicit; a host the test leaves it off is enabled. */+const hostSettings = (+ hosts: Record<string, { readonly account?: string; readonly enabled?: boolean }>,+) =>+ Object.fromEntries(+ Object.entries(hosts).map(([host, choice]) => [host, { enabled: true, ...choice }]),+ );+function harness(hosts: Record<string, { readonly account?: string; readonly enabled?: boolean }> = {},signedOut: ReadonlyArray<string> = [],tokens: Record<string, string> = {},) {const calls: Array<ReadonlyArray<string>> = [];- const process = Layer.mock(VcsProcess.VcsProcess)({- run: (input) =>- Effect.sync(() => {- calls.push(input.args);- const user = input.args[input.args.indexOf("--user") + 1];- if (input.args.includes("--user") && user !== undefined && signedOut.includes(user)) {- return {- exitCode: ChildProcessSpawner.ExitCode(0),- stdout: "",- stderr: "",- stdoutTruncated: false,- stderrTruncated: false,- };- }+ const run: SourceControlHost.SourceControlHost["Service"]["process"]["run"] = (input) =>+ Effect.sync(() => {+ calls.push(input.args);+ const user = input.args[input.args.indexOf("--user") + 1];+ if (input.args.includes("--user") && user !== undefined && signedOut.includes(user)) {return {exitCode: ChildProcessSpawner.ExitCode(0),- stdout: input.args.includes("--user") ? `token-for-${user}\n` : "active-token\n",+ stdout: "",stderr: "",stdoutTruncated: false,stderrTruncated: false,};- }),- });+ }+ return {+ exitCode: ChildProcessSpawner.ExitCode(0),+ stdout: input.args.includes("--user") ? `token-for-${user}\n` : "active-token\n",+ stderr: "",+ stdoutTruncated: false,+ stderrTruncated: false,+ };+ });const layer = GitHubCredentials.layer.pipe(Layer.provideMerge(- ServerSettings.ServerSettingsService.layerTest({ github: { hosts, tokens } }),+ TestSourceControlHost.layer({+ settings: applyServerSettingsPatch(DEFAULT_SERVER_SETTINGS, {+ github: { hosts: hostSettings(hosts), tokens },+ }),+ process: { run },+ }),),- Layer.provide(process),- Layer.provide(NodeServices.layer),+ Layer.provide(NodeCrypto.layer),);return { layer, calls };}@@ -112,20 +124,20 @@ describe("GitHubCredentials", () => {const { layer, calls } = harness();return Effect.gen(function* () {const credentials = yield* GitHubCredentials.GitHubCredentials;- const settings = yield* ServerSettings.ServerSettingsService;+ const settings = yield* TestSourceControlHost.TestSourceControlHostSettings;expect(Redacted.value((yield* credentials.get("github.com")).token)).toBe("active-token");- yield* settings.updateSettings({+ yield* settings.update({github: { hosts: { "github.com": { account: "work", enabled: true } } },});expect(Redacted.value((yield* credentials.get("github.com")).token)).toBe("token-for-work");- yield* settings.updateSettings({ github: { hosts: { "github.com": { enabled: false } } } });+ yield* settings.update({ github: { hosts: { "github.com": { enabled: false } } } });expect((yield* Effect.flip(credentials.get("github.com")))._tag).toBe("GitHubHostDisabledError",);- yield* settings.updateSettings({ github: { hosts: {} } });+ yield* settings.update({ github: { hosts: {} } });expect(Redacted.value((yield* credentials.get("github.com")).token)).toBe("active-token");// The unpinned token stayed cached; only the newly pinned account cost a gh call.expect(calls).toHaveLength(2);diff --git a/apps/server/src/sourceControl/GitHubCredentials.ts b/packages/source-control-github/src/server/GitHubCredentials.tssimilarity index 96%rename from apps/server/src/sourceControl/GitHubCredentials.tsrename to packages/source-control-github/src/server/GitHubCredentials.tsindex d47d57ea7ff..7483d7e02a5 100644--- a/apps/server/src/sourceControl/GitHubCredentials.ts+++ b/packages/source-control-github/src/server/GitHubCredentials.ts@@ -13,8 +13,7 @@ import * as Schema from "effect/Schema";import { HostProcessEnvironment, HostProcessWorkingDirectory } from "@t3tools/shared/hostProcess";-import * as ServerSettings from "../serverSettings.ts";-import * as VcsProcess from "../vcs/VcsProcess.ts";+import * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";/** How long a token is reused before `gh` is asked again, so a `gh auth switch` applies soon. */const TOKEN_TTL = Duration.minutes(5);@@ -94,7 +93,7 @@ export class GitHubCredentials extends Context.Service</** Drops the held token after GitHub refused it, so the next read asks its source again. */readonly invalidate: (host: string) => Effect.Effect<void>;}->()("t3/sourceControl/GitHubCredentials") {}+>()("@t3tools/source-control-github/server/GitHubCredentials") {}function normalizeHost(host: string): string {return host.trim().toLowerCase();@@ -128,8 +127,8 @@ export function environmentToken(/** @public Service construction is part of the canonical Effect module API. */export const make = Effect.gen(function* () {- const process = yield* VcsProcess.VcsProcess;- const serverSettings = yield* ServerSettings.ServerSettingsService;+ const sourceControlHost = yield* SourceControlHost.SourceControlHost;+ const process = sourceControlHost.process;const crypto = yield* Crypto.Crypto;const environment = yield* HostProcessEnvironment;const workingDirectory = yield* HostProcessWorkingDirectory;@@ -179,14 +178,14 @@ export const make = Effect.gen(function* () {/** The Settings choice for a host; unreadable settings fall back to gh's own choice. */const hostChoice = (host: string) =>- serverSettings.getSettings.pipe(+ sourceControlHost.settings.get.pipe(Effect.map((settings) => settings.github.hosts[host]),Effect.orElseSucceed(() => undefined),);/** A token saved in Settings for the host, read fresh so a saved or removed one applies at once. */const savedToken = (host: string) =>- serverSettings.getSettings.pipe(+ sourceControlHost.settings.get.pipe(Effect.map((settings) => settings.github.tokens[host]?.trim() || null),Effect.orElseSucceed(() => null),);diff --git a/apps/server/src/pullRequest/GitHubPullRequestApi.test.ts b/packages/source-control-github/src/server/GitHubPullRequestApi.test.tssimilarity index 99%rename from apps/server/src/pullRequest/GitHubPullRequestApi.test.tsrename to packages/source-control-github/src/server/GitHubPullRequestApi.test.tsindex 8888f4c11f4..badb7967758 100644--- a/apps/server/src/pullRequest/GitHubPullRequestApi.test.ts+++ b/packages/source-control-github/src/server/GitHubPullRequestApi.test.ts@@ -12,12 +12,12 @@ import * as Redacted from "effect/Redacted";import { HttpClient, HttpClientResponse } from "effect/http";-import { AllowGitHubReserve } from "../sourceControl/GitHubApi.ts";-import * as GitHubApi from "../sourceControl/GitHubApi.ts";-import * as GitHubCredentials from "../sourceControl/GitHubCredentials.ts";-import * as GitHubQuota from "../sourceControl/githubQuota.ts";+import { AllowGitHubReserve } from "./GitHubApi.ts";+import * as GitHubApi from "./GitHubApi.ts";+import * as GitHubCredentials from "./GitHubCredentials.ts";+import * as GitHubQuota from "./GitHubQuota.ts";import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";-import * as VcsProcess from "../vcs/VcsProcess.ts";+import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost";import * as GitHubPullRequestApi from "./GitHubPullRequestApi.ts";import { KnownWorkflowRuns } from "./gitHubConditionalChecks.ts";@@ -103,7 +103,8 @@ const layer = it.layer(Layer.provideMerge(mockApi),Layer.provideMerge(GitHubQuota.layer),Layer.provide(NodeCrypto.layer),- Layer.provide(VcsProcess.layer.pipe(Layer.provideMerge(NodeServices.layer))),+ Layer.provide(TestSourceControlHost.layer()),+ Layer.provide(NodeServices.layer),),);@@ -509,7 +510,7 @@ it.effect(Layer.provide(Layer.mergeAll(credentials, http)),Layer.provide(GitHubQuota.layer),Layer.provide(SourceControlRateLimit.layer),- Layer.merge(VcsProcess.layer),+ Layer.merge(TestSourceControlHost.layer()),Layer.provideMerge(NodeServices.layer),),),diff --git a/apps/server/src/pullRequest/GitHubPullRequestApi.ts b/packages/source-control-github/src/server/GitHubPullRequestApi.tssimilarity index 99%rename from apps/server/src/pullRequest/GitHubPullRequestApi.tsrename to packages/source-control-github/src/server/GitHubPullRequestApi.tsindex dd093df00b7..ceff9c6c0b5 100644--- a/apps/server/src/pullRequest/GitHubPullRequestApi.ts+++ b/packages/source-control-github/src/server/GitHubPullRequestApi.ts@@ -42,9 +42,9 @@ import {type PullRequestPreview,} from "@t3tools/contracts";-import * as GitHubApi from "../sourceControl/GitHubApi.ts";-import { readGraphQlPages } from "../sourceControl/githubGraphQl.ts";-import * as VcsProcess from "../vcs/VcsProcess.ts";+import * as GitHubApi from "./GitHubApi.ts";+import { readGraphQlPages } from "./githubGraphQl.ts";+import * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";import {ACTOR_AVATARS_GRAPHQL_QUERY,@@ -793,7 +793,7 @@ export class GitHubPullRequestApi extends Context.Service<readonly body: string;}) => Effect.Effect<void, GitHubPullRequestApiError>;}->()("t3/pullRequest/GitHubPullRequestApi") {}+>()("@t3tools/source-control-github/server/GitHubPullRequestApi") {}/*** The GraphQL API takes owner and name as separate arguments, so `owner/repo` is split here.@@ -1105,7 +1105,7 @@ const SIMPLE_ACTION_MUTATIONS = {/** @public Service construction is part of the canonical Effect module API. */export const make = Effect.gen(function* () {const api = yield* GitHubApi.GitHubApi;- const vcsProcess = yield* VcsProcess.VcsProcess;+ const sourceControlHost = yield* SourceControlHost.SourceControlHost;const fileSystem = yield* FileSystem.FileSystem;const revalidateChecks = yield* makeChecksRevalidator;const routingIdentities = new Map<@@ -2497,7 +2497,7 @@ export const make = Effect.gen(function* () {if (input.stackNumber !== undefined)return runGitHubStackAction({ ...input, stackNumber: input.stackNumber }).pipe(Effect.provideService(GitHubApi.GitHubApi, api),- Effect.provideService(VcsProcess.VcsProcess, vcsProcess),+ Effect.provideService(SourceControlHost.SourceControlHost, sourceControlHost),Effect.provideService(FileSystem.FileSystem, fileSystem),);if (input.action === "revert") {diff --git a/apps/server/src/pullRequest/GitHubPullRequestProvider.test.ts b/packages/source-control-github/src/server/GitHubPullRequestProvider.test.tssimilarity index 99%rename from apps/server/src/pullRequest/GitHubPullRequestProvider.test.tsrename to packages/source-control-github/src/server/GitHubPullRequestProvider.test.tsindex df4f7da4cd2..98e8aeb5c15 100644--- a/apps/server/src/pullRequest/GitHubPullRequestProvider.test.ts+++ b/packages/source-control-github/src/server/GitHubPullRequestProvider.test.ts@@ -6,7 +6,7 @@ import * as Result from "effect/Result";import type { PullRequestReaction } from "@t3tools/contracts";import { decodePullRequestDetailJson } from "./gitHubPullRequestJson.ts";-import * as GitHubApi from "../sourceControl/GitHubApi.ts";+import * as GitHubApi from "./GitHubApi.ts";import * as GitHubPullRequestApi from "./GitHubPullRequestApi.ts";import type { GitHubPullRequestCore } from "./gitHubPullRequestJson.ts";import { gitHubViewerPermissions, loginAvatarUrl, make } from "./GitHubPullRequestProvider.ts";diff --git a/apps/server/src/pullRequest/GitHubPullRequestProvider.ts b/packages/source-control-github/src/server/GitHubPullRequestProvider.tssimilarity index 99%rename from apps/server/src/pullRequest/GitHubPullRequestProvider.tsrename to packages/source-control-github/src/server/GitHubPullRequestProvider.tsindex 67f871501dd..a3030f6c86a 100644--- a/apps/server/src/pullRequest/GitHubPullRequestProvider.ts+++ b/packages/source-control-github/src/server/GitHubPullRequestProvider.ts@@ -7,7 +7,7 @@ import type {PullRequestViewerPermissions,} from "@t3tools/contracts";-import * as GitHubApi from "../sourceControl/GitHubApi.ts";+import * as GitHubApi from "./GitHubApi.ts";import * as GitHubPullRequestApi from "./GitHubPullRequestApi.ts";import {PullRequestProviderError,diff --git a/apps/server/src/sourceControl/githubQuota.test.ts b/packages/source-control-github/src/server/GitHubQuota.test.tssimilarity index 98%rename from apps/server/src/sourceControl/githubQuota.test.tsrename to packages/source-control-github/src/server/GitHubQuota.test.tsindex e9c1fac93eb..4c2c707cde7 100644--- a/apps/server/src/sourceControl/githubQuota.test.ts+++ b/packages/source-control-github/src/server/GitHubQuota.test.ts@@ -2,7 +2,7 @@ import { assert, describe, it } from "@effect/vitest";import * as Effect from "effect/Effect";import * as TestClock from "effect/testing/TestClock";-import * as GitHubQuota from "./githubQuota.ts";+import * as GitHubQuota from "./GitHubQuota.ts";import { CredentialScope } from "@t3tools/source-control-core/server/SourceControlRateLimit";const RESET = Date.parse("2099-08-13T14:00:00Z");diff --git a/apps/server/src/sourceControl/githubQuota.ts b/packages/source-control-github/src/server/GitHubQuota.tssimilarity index 98%rename from apps/server/src/sourceControl/githubQuota.tsrename to packages/source-control-github/src/server/GitHubQuota.tsindex 642c48fddc9..5dcd5469b9e 100644--- a/apps/server/src/sourceControl/githubQuota.ts+++ b/packages/source-control-github/src/server/GitHubQuota.ts@@ -70,7 +70,7 @@ export class GitHubQuota extends Context.Service<headers: Readonly<Record<string, string | undefined>>,) => Effect.Effect<void>;}->()("t3/sourceControl/githubQuota") {}+>()("@t3tools/source-control-github/server/GitHubQuota") {}const make = Effect.gen(function* () {const snapshots = yield* Ref.make<ReadonlyMap<string, QuotaSnapshot>>(new Map());diff --git a/apps/server/src/sourceControl/GitHubSourceControlProvider.test.ts b/packages/source-control-github/src/server/GitHubSourceControlProvider.test.tssimilarity index 98%rename from apps/server/src/sourceControl/GitHubSourceControlProvider.test.tsrename to packages/source-control-github/src/server/GitHubSourceControlProvider.test.tsindex 602acc9d1e2..fee5d5e9546 100644--- a/apps/server/src/sourceControl/GitHubSourceControlProvider.test.ts+++ b/packages/source-control-github/src/server/GitHubSourceControlProvider.test.ts@@ -10,8 +10,8 @@ import * as Schema from "effect/Schema";import { ChildProcessSpawner } from "effect/process";import * as TestClock from "effect/testing/TestClock";-import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";-import * as VcsProcess from "../vcs/VcsProcess.ts";+import type * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";+import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost";import * as GitHubApi from "./GitHubApi.ts";import * as GitHubCredentials from "./GitHubCredentials.ts";import { parseGitHubAuthStatus } from "./gitHubAuthStatus.ts";@@ -25,7 +25,7 @@ const processResult = (readonly stderr?: string;readonly exitCode?: ChildProcessSpawner.ExitCode;},-): VcsProcess.VcsProcessOutput => ({+): SourceControlHost.SourceControlProcessOutput => ({exitCode: options?.exitCode ?? ChildProcessSpawner.ExitCode(0),stdout,stderr: options?.stderr ?? "",@@ -33,7 +33,10 @@ const processResult = (stderrTruncated: false,});-const processOutput = (stdout: string, exitCode = 0): VcsProcess.VcsProcessOutput => ({+const processOutput = (+ stdout: string,+ exitCode = 0,+): SourceControlHost.SourceControlProcessOutput => ({exitCode: ChildProcessSpawner.ExitCode(exitCode),stdout,stderr: "",@@ -87,7 +90,7 @@ function harness(input: {git.push([name, args]);return value;});- const driver = Layer.mock(GitVcsDriver.GitVcsDriver)({+ const hostGit: Partial<SourceControlHost.SourceControlHost["Service"]["git"]> = {execute: (args) =>Effect.sync(() => {git.push(["execute", args.args]);@@ -108,18 +111,20 @@ function harness(input: {? Effect.succeed([...(input.localBranches ?? [])]): Effect.fail(input.gitFailure as never),resolveCommit: () => Effect.succeed({ commitSha: "abc123" }),- });- const process = Layer.mock(VcsProcess.VcsProcess)({- run: (args) =>- Effect.succeed(- args.args[0] === "remote"- ? processOutput(input.remotes)- : processOutput(input.resolved ?? "", input.resolved ? 0 : 1),- ),+ };+ const host = TestSourceControlHost.layer({+ git: hostGit,+ process: {+ run: (args) =>+ Effect.succeed(+ args.args[0] === "remote"+ ? processOutput(input.remotes)+ : processOutput(input.resolved ?? "", input.resolved ? 0 : 1),+ ),+ },});const layer = Layer.mergeAll(- driver,- process,+ host,Layer.mock(GitHubApi.GitHubApi)(input.api),NodeServices.layer,);diff --git a/apps/server/src/sourceControl/GitHubSourceControlProvider.ts b/packages/source-control-github/src/server/GitHubSourceControlProvider.tssimilarity index 98%rename from apps/server/src/sourceControl/GitHubSourceControlProvider.tsrename to packages/source-control-github/src/server/GitHubSourceControlProvider.tsindex 35876794048..0f442f65d71 100644--- a/apps/server/src/sourceControl/GitHubSourceControlProvider.ts+++ b/packages/source-control-github/src/server/GitHubSourceControlProvider.ts@@ -22,8 +22,6 @@ import { HostProcessEnvironment } from "@t3tools/shared/hostProcess";import { decodeJsonResult } from "@t3tools/shared/schemaJson";import { isSshRemoteUrl } from "@t3tools/shared/sourceControl";-import * as ServerSettings from "../serverSettings.ts";-import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";import * as GitHubApi from "./GitHubApi.ts";import {decodeGitHubPullRequestEntries,@@ -54,7 +52,7 @@ import {type SourceControlCliDiscoverySpec,type SourceControlManagedCliDiscoverySpec,} from "@t3tools/source-control-core/server/discovery";-import * as VcsProcess from "../vcs/VcsProcess.ts";+import * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";const decodeLinkSubject = Schema.decodeUnknownEffect(Schema.fromJsonString(@@ -192,9 +190,9 @@ function environmentTokenVariable(environment: NodeJS.ProcessEnv): string | null*/export const makeDiscovery = Effect.gen(function* () {const api = yield* GitHubApi.GitHubApi;- const process = yield* VcsProcess.VcsProcess;+ const sourceControlHost = yield* SourceControlHost.SourceControlHost;+ const process = sourceControlHost.process;const environment = yield* HostProcessEnvironment;- const serverSettings = yield* ServerSettings.ServerSettingsService;return {type: "managed-cli",@@ -202,7 +200,7 @@ export const makeDiscovery = Effect.gen(function* () {label: discovery.label,installHint: discovery.installHint,probe: Effect.fn("GitHubSourceControlProvider.discovery")(function* (cwd: string) {- const settings = yield* serverSettings.getSettings.pipe(+ const settings = yield* sourceControlHost.settings.get.pipe(Effect.map((current) => current.github),Effect.orElseSucceed(() => DEFAULT_SERVER_SETTINGS.github),);@@ -477,9 +475,10 @@ const contextHost = (context: SourceControlProvider.SourceControlProviderContextexport const make = Effect.gen(function* () {const api = yield* GitHubApi.GitHubApi;- const process = yield* VcsProcess.VcsProcess;+ const sourceControlHost = yield* SourceControlHost.SourceControlHost;+ const process = sourceControlHost.process;const environment = yield* HostProcessEnvironment;- const git = yield* GitVcsDriver.GitVcsDriver;+ const git = sourceControlHost.git;const fileSystem = yield* FileSystem.FileSystem;const gitRead = (cwd: string, args: ReadonlyArray<string>) =>diff --git a/packages/source-control-github/src/server/driver.ts b/packages/source-control-github/src/server/driver.tsnew file mode 100644index 00000000000..d57ba07b201--- /dev/null+++ b/packages/source-control-github/src/server/driver.ts@@ -0,0 +1,20 @@+/**+ * The GitHub driver: repository operations and discovery through `gh` and git, and pull requests+ * through the GitHub REST and GraphQL APIs.+ *+ * @module source-control-github/server/driver+ */+import { defineSourceControlDriver } from "@t3tools/source-control-core/server/driver";+import * as Effect from "effect/Effect";++import * as GitHubPullRequestProvider from "./GitHubPullRequestProvider.ts";+import * as GitHubSourceControlProvider from "./GitHubSourceControlProvider.ts";++export const driver = defineSourceControlDriver({+ kind: "github",+ make: Effect.all({+ sourceControl: GitHubSourceControlProvider.make,+ discovery: GitHubSourceControlProvider.makeDiscovery,+ pullRequests: GitHubPullRequestProvider.make,+ }),+});diff --git a/apps/server/src/sourceControl/gitHubAuthStatus.ts b/packages/source-control-github/src/server/gitHubAuthStatus.tssimilarity index 100%rename from apps/server/src/sourceControl/gitHubAuthStatus.tsrename to packages/source-control-github/src/server/gitHubAuthStatus.tsdiff --git a/apps/server/src/pullRequest/gitHubConditionalChecks.test.ts b/packages/source-control-github/src/server/gitHubConditionalChecks.test.tssimilarity index 99%rename from apps/server/src/pullRequest/gitHubConditionalChecks.test.tsrename to packages/source-control-github/src/server/gitHubConditionalChecks.test.tsindex 79048b1d745..a621e0e9ebb 100644--- a/apps/server/src/pullRequest/gitHubConditionalChecks.test.ts+++ b/packages/source-control-github/src/server/gitHubConditionalChecks.test.ts@@ -6,7 +6,7 @@ import * as Schema from "effect/Schema";import * as Redacted from "effect/Redacted";import type { PullRequestCheck } from "@t3tools/contracts";-import * as GitHubApi from "../sourceControl/GitHubApi.ts";+import * as GitHubApi from "./GitHubApi.ts";import { KnownWorkflowRuns, makeChecksRevalidator } from "./gitHubConditionalChecks.ts";const encodeJson = Schema.encodeSync(Schema.fromJsonString(Schema.Unknown));diff --git a/apps/server/src/pullRequest/gitHubConditionalChecks.ts b/packages/source-control-github/src/server/gitHubConditionalChecks.tssimilarity index 97%rename from apps/server/src/pullRequest/gitHubConditionalChecks.tsrename to packages/source-control-github/src/server/gitHubConditionalChecks.tsindex 353089ebf0f..afeb14a0935 100644--- a/apps/server/src/pullRequest/gitHubConditionalChecks.ts+++ b/packages/source-control-github/src/server/gitHubConditionalChecks.ts@@ -7,7 +7,7 @@ import * as Schema from "effect/Schema";import * as Semaphore from "effect/Semaphore";import { PositiveInt, type PullRequestChecks } from "@t3tools/contracts";-import * as GitHubApi from "../sourceControl/GitHubApi.ts";+import * as GitHubApi from "./GitHubApi.ts";import type { GitHubPullRequestDetail } from "./gitHubPullRequestJson.ts";import type { GitHubPullRequestApiError } from "./GitHubPullRequestApi.ts";import type { ProviderRepositoryRef } from "@t3tools/source-control-core/server/PullRequestProvider";@@ -43,7 +43,9 @@ export type KnownWorkflowRun = typeof WorkflowRunSchema.Type;export const KnownWorkflowRuns = Context.Reference<{readonly headSha: string;readonly runs: ReadonlyArray<KnownWorkflowRun>;-} | null>("t3/pullRequest/KnownWorkflowRuns", { defaultValue: () => null });+} | null>("@t3tools/source-control-github/server/gitHubConditionalChecks/KnownWorkflowRuns", {+ defaultValue: () => null,+});type Validator = { etag: string | undefined; next: boolean; body: string };diff --git a/apps/server/src/pullRequest/gitHubPullRequestJson.test.ts b/packages/source-control-github/src/server/gitHubPullRequestJson.test.tssimilarity index 100%rename from apps/server/src/pullRequest/gitHubPullRequestJson.test.tsrename to packages/source-control-github/src/server/gitHubPullRequestJson.test.tsdiff --git a/apps/server/src/pullRequest/gitHubPullRequestJson.ts b/packages/source-control-github/src/server/gitHubPullRequestJson.tssimilarity index 99%rename from apps/server/src/pullRequest/gitHubPullRequestJson.tsrename to packages/source-control-github/src/server/gitHubPullRequestJson.tsindex edca11f5a0d..956f1ef5f4a 100644--- a/apps/server/src/pullRequest/gitHubPullRequestJson.ts+++ b/packages/source-control-github/src/server/gitHubPullRequestJson.ts@@ -35,7 +35,7 @@ import type {import { quoteGitPatchPath } from "@t3tools/shared/gitPatchPath";import { decodeJsonResult } from "@t3tools/shared/schemaJson";-import { aliasedGraphQlDocument, type GraphQlDocument } from "../sourceControl/githubGraphQl.ts";+import { aliasedGraphQlDocument, type GraphQlDocument } from "./githubGraphQl.ts";import { dedupeChecks } from "@t3tools/source-control-core/server/pullRequestChecks";/**diff --git a/apps/server/src/sourceControl/gitHubPullRequests.ts b/packages/source-control-github/src/server/gitHubPullRequests.tssimilarity index 100%rename from apps/server/src/sourceControl/gitHubPullRequests.tsrename to packages/source-control-github/src/server/gitHubPullRequests.tsdiff --git a/apps/server/src/sourceControl/gitHubRepositoryResolution.test.ts b/packages/source-control-github/src/server/gitHubRepositoryResolution.test.tssimilarity index 100%rename from apps/server/src/sourceControl/gitHubRepositoryResolution.test.tsrename to packages/source-control-github/src/server/gitHubRepositoryResolution.test.tsdiff --git a/apps/server/src/sourceControl/gitHubRepositoryResolution.ts b/packages/source-control-github/src/server/gitHubRepositoryResolution.tssimilarity index 100%rename from apps/server/src/sourceControl/gitHubRepositoryResolution.tsrename to packages/source-control-github/src/server/gitHubRepositoryResolution.tsdiff --git a/apps/server/src/sourceControl/githubGraphQl.test.ts b/packages/source-control-github/src/server/githubGraphQl.test.tssimilarity index 100%rename from apps/server/src/sourceControl/githubGraphQl.test.tsrename to packages/source-control-github/src/server/githubGraphQl.test.tsdiff --git a/apps/server/src/sourceControl/githubGraphQl.ts b/packages/source-control-github/src/server/githubGraphQl.tssimilarity index 100%rename from apps/server/src/sourceControl/githubGraphQl.tsrename to packages/source-control-github/src/server/githubGraphQl.tsdiff --git a/apps/server/src/pullRequest/githubStackActions.test.ts b/packages/source-control-github/src/server/githubStackActions.test.tssimilarity index 95%rename from apps/server/src/pullRequest/githubStackActions.test.tsrename to packages/source-control-github/src/server/githubStackActions.test.tsindex 7600b9dc9a2..846d88332a6 100644--- a/apps/server/src/pullRequest/githubStackActions.test.ts+++ b/packages/source-control-github/src/server/githubStackActions.test.ts@@ -7,8 +7,8 @@ import * as TestClock from "effect/testing/TestClock";import * as FileSystem from "effect/FileSystem";import * as Redacted from "effect/Redacted";import { ChildProcessSpawner } from "effect/process";-import * as GitHubApi from "../sourceControl/GitHubApi.ts";-import * as VcsProcess from "../vcs/VcsProcess.ts";+import * as GitHubApi from "./GitHubApi.ts";+import * as TestSourceControlHost from "@t3tools/source-control-testing/TestSourceControlHost";import { runGitHubStackAction as runStackAction } from "./githubStackActions.ts";/**@@ -24,20 +24,22 @@ type Send = (/** Every git command the cascade ran, in order; none actually runs. */let gitCalls: Array<ReadonlyArray<string>> = [];const fakeGit = Layer.mergeAll(- Layer.mock(VcsProcess.VcsProcess)({- run: (input) =>- Effect.sync(() => {- gitCalls.push(input.args);- const stdout =- input.args[0] === "rev-parse" || input.args[0] === "merge-base" ? "new-sha\n" : "";- return {- exitCode: ChildProcessSpawner.ExitCode(0),- stdout,- stderr: "",- stdoutTruncated: false,- stderrTruncated: false,- };- }),+ TestSourceControlHost.layer({+ process: {+ run: (input) =>+ Effect.sync(() => {+ gitCalls.push(input.args);+ const stdout =+ input.args[0] === "rev-parse" || input.args[0] === "merge-base" ? "new-sha\n" : "";+ return {+ exitCode: ChildProcessSpawner.ExitCode(0),+ stdout,+ stderr: "",+ stdoutTruncated: false,+ stderrTruncated: false,+ };+ }),+ },}),FileSystem.layerNoop({ makeTempDirectoryScoped: () => Effect.succeed("/tmp/scratch") }),);diff --git a/apps/server/src/pullRequest/githubStackActions.ts b/packages/source-control-github/src/server/githubStackActions.tssimilarity index 98%rename from apps/server/src/pullRequest/githubStackActions.tsrename to packages/source-control-github/src/server/githubStackActions.tsindex c2e8fadb751..a6d90711620 100644--- a/apps/server/src/pullRequest/githubStackActions.ts+++ b/packages/source-control-github/src/server/githubStackActions.ts@@ -8,8 +8,8 @@ import * as Clock from "effect/Clock";import * as Result from "effect/Result";import * as Schema from "effect/Schema";-import * as GitHubApi from "../sourceControl/GitHubApi.ts";-import { aliasedGraphQlDocument } from "../sourceControl/githubGraphQl.ts";+import * as GitHubApi from "./GitHubApi.ts";+import { aliasedGraphQlDocument } from "./githubGraphQl.ts";import { decodePullRequestStacksJson } from "./gitHubPullRequestJson.ts";import { cascadeRebaseStack } from "./githubStackRebase.ts";diff --git a/apps/server/src/pullRequest/githubStackRebase.ts b/packages/source-control-github/src/server/githubStackRebase.tssimilarity index 96%rename from apps/server/src/pullRequest/githubStackRebase.tsrename to packages/source-control-github/src/server/githubStackRebase.tsindex 2cd2b5f88bb..a1dffa05d97 100644--- a/apps/server/src/pullRequest/githubStackRebase.ts+++ b/packages/source-control-github/src/server/githubStackRebase.ts@@ -4,8 +4,8 @@ import * as Redacted from "effect/Redacted";import * as Schema from "effect/Schema";import * as Base64 from "effect/encoding/Base64";-import * as GitHubApi from "../sourceControl/GitHubApi.ts";-import * as VcsProcess from "../vcs/VcsProcess.ts";+import * as GitHubApi from "./GitHubApi.ts";+import * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";/** One open layer of a stack, bottom to top, with the head the reader reviewed. */export interface CascadeLayer {@@ -58,7 +58,7 @@ export const cascadeRebaseStack = Effect.fn("cascadeRebaseStack")(function* (inpreadonly remote?: string;}) {const api = yield* GitHubApi.GitHubApi;- const process = yield* VcsProcess.VcsProcess;+ const { process } = yield* SourceControlHost.SourceControlHost;const fileSystem = yield* FileSystem.FileSystem;const { token } = yield* api.credential(input.host);const first = input.layers[0];diff --git a/packages/source-control-github/tsconfig.json b/packages/source-control-github/tsconfig.jsonnew file mode 100644index 00000000000..374bac55202--- /dev/null+++ b/packages/source-control-github/tsconfig.json@@ -0,0 +1,7 @@+{+ "extends": "../../tsconfig.base.json",+ "compilerOptions": {+ "types": ["node"]+ },+ "include": ["src"]+}diff --git a/packages/source-control-testing/package.json b/packages/source-control-testing/package.jsonindex 66426fe0337..60c1bbcf43b 100644--- a/packages/source-control-testing/package.json+++ b/packages/source-control-testing/package.json@@ -13,6 +13,7 @@},"dependencies": {"@t3tools/contracts": "workspace:*",+ "@t3tools/shared": "workspace:*","@t3tools/source-control-core": "workspace:*","effect": "catalog:"},diff --git a/packages/source-control-testing/src/TestSourceControlHost.ts b/packages/source-control-testing/src/TestSourceControlHost.tsindex eee1a96f13a..a4cb30db734 100644--- a/packages/source-control-testing/src/TestSourceControlHost.ts+++ b/packages/source-control-testing/src/TestSourceControlHost.ts@@ -1,15 +1,23 @@/**- * A `SourceControlHost.SourceControlHost` for provider tests. Settings are fixed unless the test- * supplies its own. Process runs and git operations go to what the test supplies; anything else- * dies, so an unexpected CLI or git call is visible.+ * A `SourceControlHost.SourceControlHost` for provider tests. Settings start from the defaults+ * or what the test supplies, and `TestSourceControlHostSettings` patches them mid-test the way a+ * client's settings write would. Process runs and git operations go to what the test supplies;+ * anything else dies, so an unexpected CLI or git call is visible.** @module source-control-testing/TestSourceControlHost*/-import { DEFAULT_SERVER_SETTINGS, type ServerSettings } from "@t3tools/contracts";+import {+ DEFAULT_SERVER_SETTINGS,+ type ServerSettings,+ type ServerSettingsPatch,+} from "@t3tools/contracts";+import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings";import * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";+import * as Context from "effect/Context";import * as Effect from "effect/Effect";import * as Layer from "effect/Layer";import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";+import * as Ref from "effect/Ref";export interface TestSourceControlHostOptions {readonly settings?: ServerSettings;@@ -17,12 +25,20 @@ export interface TestSourceControlHostOptions {readonly git?: Partial<SourceControlHost.SourceControlHost["Service"]["git"]>;}+/** Lets a test change the settings its `layer` reports. */+export class TestSourceControlHostSettings extends Context.Service<+ TestSourceControlHostSettings,+ { readonly update: (patch: ServerSettingsPatch) => Effect.Effect<void> }+>()("@t3tools/source-control-testing/TestSourceControlHost/TestSourceControlHostSettings") {}+type Git = SourceControlHost.SourceControlHost["Service"]["git"];const unexpectedGit = (operation: string) => () =>Effect.die(`Unexpected git ${operation} in a test that supplied none.`);const failingGit: Git = {+ execute: unexpectedGit("execute"),+ resolveCommit: unexpectedGit("resolveCommit"),remotes: unexpectedGit("remotes"),readConfigValue: unexpectedGit("readConfigValue"),resolvePrimaryRemoteName: unexpectedGit("resolvePrimaryRemoteName"),@@ -36,17 +52,25 @@ const failingGit: Git = {export const layer = (options: TestSourceControlHostOptions = {},-): Layer.Layer<SourceControlHost.SourceControlHost> =>- Layer.succeed(- SourceControlHost.SourceControlHost,- SourceControlHost.SourceControlHost.of({- settings: { get: Effect.succeed(options.settings ?? DEFAULT_SERVER_SETTINGS) },- process: {- run:- options.process?.run ??- ((input) => Effect.die(`Unexpected ${input.command} run in ${input.operation}.`)),- },- git: { ...failingGit, ...options.git },+): Layer.Layer<SourceControlHost.SourceControlHost | TestSourceControlHostSettings> =>+ Layer.effectContext(+ Effect.gen(function* () {+ const settings = yield* Ref.make(options.settings ?? DEFAULT_SERVER_SETTINGS);+ const host = SourceControlHost.SourceControlHost.of({+ settings: { get: Ref.get(settings) },+ process: {+ run:+ options.process?.run ??+ ((input) => Effect.die(`Unexpected ${input.command} run in ${input.operation}.`)),+ },+ git: { ...failingGit, ...options.git },+ });+ return Context.make(SourceControlHost.SourceControlHost, host).pipe(+ Context.add(TestSourceControlHostSettings, {+ update: (patch) =>+ Ref.update(settings, (current) => applyServerSettingsPatch(current, patch)),+ }),+ );}),);diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 5ad28290d98..cdee534c2d3 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -660,6 +660,9 @@ importers:'@t3tools/source-control-forgejo':specifier: workspace:*version: link:../../packages/source-control-forgejo+ '@t3tools/source-control-github':+ specifier: workspace:*+ version: link:../../packages/source-control-github'@t3tools/source-control-gitlab':specifier: workspace:*version: link:../../packages/source-control-gitlab@@ -1640,6 +1643,40 @@ importers:specifier: 1.0.0version: 1.0.0(@types/[email protected])(@vitest/[email protected]([email protected]))([email protected])([email protected])([email protected])([email protected](@noble/[email protected]))([email protected](@types/[email protected])([email protected]))([email protected])([email protected])([email protected])([email protected])([email protected])+ packages/source-control-github:+ dependencies:+ '@t3tools/contracts':+ specifier: workspace:*+ version: link:../contracts+ '@t3tools/provider-core':+ specifier: workspace:*+ version: link:../provider-core+ '@t3tools/shared':+ specifier: workspace:*+ version: link:../shared+ '@t3tools/source-control-core':+ specifier: workspace:*+ version: link:../source-control-core+ effect:+ specifier: 4.0.2+ version: 4.0.2(patch_hash=ec61ee307eaec3e17f757e0e6a16296ea4b7a8c3188df0c6ec5e66301fd78688)+ devDependencies:+ '@effect/platform-node':+ specifier: 4.0.2+ version: 4.0.2([email protected])([email protected](patch_hash=ec61ee307eaec3e17f757e0e6a16296ea4b7a8c3188df0c6ec5e66301fd78688))([email protected])([email protected])+ '@effect/vitest':+ specifier: 4.0.2+ version: 4.0.2(patch_hash=595b7d26fb635caba9c3d39fcb189bb78a000192f8d3b60ead7174b310d1ade9)(@types/[email protected])(@vitest/[email protected])([email protected])([email protected](patch_hash=ec61ee307eaec3e17f757e0e6a16296ea4b7a8c3188df0c6ec5e66301fd78688))([email protected])([email protected])([email protected](@noble/[email protected]))([email protected](@types/[email protected])([email protected]))([email protected])([email protected])([email protected])([email protected])([email protected])+ '@t3tools/source-control-testing':+ specifier: workspace:*+ version: link:../source-control-testing+ '@types/node':+ specifier: 24.12.4+ version: 24.12.4+ vite-plus:+ specifier: 1.0.0+ version: 1.0.0(@types/[email protected])(@vitest/[email protected]([email protected]))([email protected])([email protected])([email protected])([email protected](@noble/[email protected]))([email protected](@types/[email protected])([email protected]))([email protected])([email protected])([email protected])([email protected])([email protected])+packages/source-control-gitlab:dependencies:'@t3tools/contracts':@@ -1673,6 +1710,9 @@ importers:'@t3tools/contracts':specifier: workspace:*version: link:../contracts+ '@t3tools/shared':+ specifier: workspace:*+ version: link:../shared'@t3tools/source-control-core':specifier: workspace:*version: link:../source-control-corediff --git a/scripts/release-smoke.ts b/scripts/release-smoke.tsindex 96b1df41e1e..7bc6da48171 100644--- a/scripts/release-smoke.ts+++ b/scripts/release-smoke.ts@@ -41,6 +41,7 @@ const workspaceFiles = ["packages/source-control-bitbucket/package.json","packages/source-control-core/package.json","packages/source-control-forgejo/package.json",+ "packages/source-control-github/package.json","packages/source-control-gitlab/package.json","packages/source-control-testing/package.json","packages/effect-acp/package.json",