refactor(source-control): GitHub lives in @t3tools/source-control-github (#17607)

Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Opus 5.5 authored and GitHub committed 2026-10-09 14:50:02 -07:00
1 parent 8d1858d9d6
commit 507361bc73
51 files changed
+411 -195

No files matched your search

+1
View File
@@ -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:",
@@ -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))),
+23 -10
View File
@@ -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));
+1 -1
View File
@@ -35,7 +35,7 @@ import { ASSET_ROUTE_PREFIX, issueAssetUrl, resolveAsset } from "./AssetAccess.t
import * 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) => {
+1 -1
View File
@@ -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 presigned
+1 -1
View File
@@ -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";
@@ -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");
@@ -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),
);
@@ -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";
+3 -4
View File
@@ -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.l
const 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)),
@@ -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,
@@ -20,7 +20,8 @@ import * as AzureDevOpsCli from "@t3tools/source-control-azure-devops/server/Azu
import * 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)({}),
@@ -18,8 +18,9 @@ import * as AzureDevOpsPullRequestCli from "@t3tools/source-control-azure-devops
import * 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 })),
@@ -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);
@@ -15,6 +15,9 @@ import * as BitbucketPullRequestApi from "@t3tools/source-control-bitbucket/serv
import * 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,
@@ -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));
/**
+1 -7
View File
@@ -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)),
+1 -1
View File
@@ -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",
@@ -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.
@@ -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:"
}
}
@@ -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/h
import * 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", () =>
@@ -12,7 +12,7 @@ import { HttpClient, HttpClientRequest, type HttpClientResponse } from "effect/h
import { 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();
@@ -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);
@@ -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),
);
@@ -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),
),
),
@@ -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") {
@@ -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";
@@ -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,
@@ -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");
@@ -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());
@@ -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,
);
@@ -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.SourceControlProviderContext
export 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>) =>
@@ -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,
}),
});
@@ -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));
@@ -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 };
@@ -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";
/**
@@ -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") }),
);
@@ -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";
@@ -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* (inp
readonly 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];
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"types": ["node"]
},
"include": ["src"]
}
@@ -13,6 +13,7 @@
},
"dependencies": {
"@t3tools/contracts": "workspace:*",
"@t3tools/shared": "workspace:*",
"@t3tools/source-control-core": "workspace:*",
"effect": "catalog:"
},
@@ -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)),
}),
);
}),
);
+40
View File
@@ -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.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-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-core
+1
View File
@@ -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",