Normalize timestamps across VCS and source control contracts
- Switch freshness and PR update times to typed `DateTime`/`Option` values - Update GitHub and VCS adapters, tests, and sorting to use the new shapes
This commit is contained in:
1 parent
38185dc696
commit
6d7de0b314
9 files changed
+51
-34
No files matched your search
@@ -71,7 +71,7 @@ interface OpenPrInfo {
|
||||
|
||||
interface PullRequestInfo extends OpenPrInfo, PullRequestHeadRemoteInfo {
|
||||
state: "open" | "closed" | "merged";
|
||||
updatedAt: string | null;
|
||||
updatedAt: Option.Option<DateTime.Utc>;
|
||||
}
|
||||
|
||||
interface ResolvedPullRequest {
|
||||
@@ -273,12 +273,18 @@ function toPullRequestInfo(summary: ChangeRequest): PullRequestInfo {
|
||||
};
|
||||
}
|
||||
|
||||
function parseDateTimeMillis(value: string | null): number {
|
||||
if (!value) {
|
||||
return 0;
|
||||
}
|
||||
const parsed = DateTime.make(value);
|
||||
return Option.isSome(parsed) ? DateTime.toEpochMillis(parsed.value) : 0;
|
||||
function compareOptionalDateTimeDesc(
|
||||
left: Option.Option<DateTime.Utc>,
|
||||
right: Option.Option<DateTime.Utc>,
|
||||
): number {
|
||||
return Option.match(left, {
|
||||
onNone: () => (Option.isNone(right) ? 0 : 1),
|
||||
onSome: (leftValue) =>
|
||||
Option.match(right, {
|
||||
onNone: () => -1,
|
||||
onSome: (rightValue) => DateTime.Order(rightValue, leftValue),
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
function gitManagerError(operation: string, detail: string, cause?: unknown): GitManagerError {
|
||||
@@ -858,7 +864,7 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
||||
baseRefName: firstPullRequest.baseRefName,
|
||||
headRefName: firstPullRequest.headRefName,
|
||||
state: "open",
|
||||
updatedAt: null,
|
||||
updatedAt: Option.none(),
|
||||
} satisfies PullRequestInfo;
|
||||
}
|
||||
}
|
||||
@@ -889,11 +895,9 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
|
||||
}
|
||||
}
|
||||
|
||||
const parsed = Array.from(parsedByNumber.values()).toSorted((a, b) => {
|
||||
const left = parseDateTimeMillis(a.updatedAt);
|
||||
const right = parseDateTimeMillis(b.updatedAt);
|
||||
return right - left;
|
||||
});
|
||||
const parsed = Array.from(parsedByNumber.values()).toSorted((a, b) =>
|
||||
compareOptionalDateTimeDesc(a.updatedAt, b.updatedAt),
|
||||
);
|
||||
|
||||
const latestOpenPr = parsed.find((pr) => pr.state === "open");
|
||||
if (latestOpenPr) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Cause, Exit, Result, Schema } from "effect";
|
||||
import { Cause, DateTime, Exit, Option, Result, Schema } from "effect";
|
||||
import { PositiveInt, TrimmedNonEmptyString } from "@t3tools/contracts";
|
||||
import { decodeJsonResult, formatSchemaError } from "@t3tools/shared/schemaJson";
|
||||
|
||||
@@ -9,7 +9,7 @@ export interface NormalizedGitHubPullRequestRecord {
|
||||
readonly baseRefName: string;
|
||||
readonly headRefName: string;
|
||||
readonly state: "open" | "closed" | "merged";
|
||||
readonly updatedAt: string | null;
|
||||
readonly updatedAt: Option.Option<DateTime.Utc>;
|
||||
readonly isCrossRepository?: boolean;
|
||||
readonly headRepositoryNameWithOwner?: string | null;
|
||||
readonly headRepositoryOwnerLogin?: string | null;
|
||||
@@ -23,7 +23,7 @@ const GitHubPullRequestSchema = Schema.Struct({
|
||||
headRefName: TrimmedNonEmptyString,
|
||||
state: Schema.optional(Schema.NullOr(Schema.String)),
|
||||
mergedAt: Schema.optional(Schema.NullOr(Schema.String)),
|
||||
updatedAt: Schema.optional(Schema.NullOr(Schema.String)),
|
||||
updatedAt: Schema.optional(Schema.OptionFromNullOr(Schema.DateTimeUtcFromString)),
|
||||
isCrossRepository: Schema.optional(Schema.Boolean),
|
||||
headRepository: Schema.optional(
|
||||
Schema.NullOr(
|
||||
@@ -80,8 +80,7 @@ function normalizeGitHubPullRequestRecord(
|
||||
baseRefName: raw.baseRefName,
|
||||
headRefName: raw.headRefName,
|
||||
state: normalizeGitHubPullRequestState(raw),
|
||||
updatedAt:
|
||||
typeof raw.updatedAt === "string" && raw.updatedAt.trim().length > 0 ? raw.updatedAt : null,
|
||||
updatedAt: raw.updatedAt ?? Option.none(),
|
||||
...(typeof raw.isCrossRepository === "boolean"
|
||||
? { isCrossRepository: raw.isCrossRepository }
|
||||
: {}),
|
||||
|
||||
@@ -29,6 +29,7 @@ import { assert, it } from "@effect/vitest";
|
||||
import { assertFailure, assertInclude, assertTrue } from "@effect/vitest/utils";
|
||||
import {
|
||||
Deferred,
|
||||
DateTime,
|
||||
Duration,
|
||||
Effect,
|
||||
FileSystem,
|
||||
@@ -50,6 +51,8 @@ import { RpcClient, RpcSerialization } from "effect/unstable/rpc";
|
||||
import * as Socket from "effect/unstable/socket/Socket";
|
||||
import { vi } from "vitest";
|
||||
|
||||
const TEST_EPOCH = DateTime.makeUnsafe("1970-01-01T00:00:00.000Z");
|
||||
|
||||
import type { ServerConfigShape } from "./config.ts";
|
||||
import { deriveServerPaths, ServerConfig } from "./config.ts";
|
||||
import { makeRoutesLayer } from "./server.ts";
|
||||
@@ -395,7 +398,8 @@ const buildAppUnderTest = (options?: {
|
||||
truncated: false,
|
||||
freshness: {
|
||||
source: "live-local",
|
||||
observedAt: new Date(0).toISOString(),
|
||||
observedAt: TEST_EPOCH,
|
||||
expiresAt: Option.none(),
|
||||
},
|
||||
}),
|
||||
filterIgnoredPaths: (_cwd, relativePaths) => Effect.succeed(relativePaths),
|
||||
@@ -416,7 +420,8 @@ const buildAppUnderTest = (options?: {
|
||||
metadataPath: null,
|
||||
freshness: {
|
||||
source: "live-local" as const,
|
||||
observedAt: new Date(0).toISOString(),
|
||||
observedAt: TEST_EPOCH,
|
||||
expiresAt: Option.none(),
|
||||
},
|
||||
}
|
||||
: null,
|
||||
@@ -444,7 +449,8 @@ const buildAppUnderTest = (options?: {
|
||||
metadataPath: null,
|
||||
freshness: {
|
||||
source: "live-local",
|
||||
observedAt: new Date(0).toISOString(),
|
||||
observedAt: TEST_EPOCH,
|
||||
expiresAt: Option.none(),
|
||||
},
|
||||
},
|
||||
driver: defaultVcsDriver,
|
||||
@@ -2154,7 +2160,8 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
||||
truncated: false,
|
||||
freshness: {
|
||||
source: "live-local",
|
||||
observedAt: new Date(0).toISOString(),
|
||||
observedAt: TEST_EPOCH,
|
||||
expiresAt: Option.none(),
|
||||
},
|
||||
}),
|
||||
filterIgnoredPaths: (_cwd, relativePaths) =>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { Effect, Layer } from "effect";
|
||||
import { DateTime, Effect, Layer, Option } from "effect";
|
||||
|
||||
import { GitHubCli, type GitHubCliShape } from "../git/Services/GitHubCli.ts";
|
||||
import * as GitHubSourceControlProvider from "./GitHubSourceControlProvider.ts";
|
||||
@@ -46,7 +46,7 @@ it.effect("maps GitHub PR summaries into provider-neutral change requests", () =
|
||||
baseRefName: "main",
|
||||
headRefName: "feature/source-control",
|
||||
state: "open",
|
||||
updatedAt: null,
|
||||
updatedAt: Option.none(),
|
||||
isCrossRepository: true,
|
||||
headRepositoryNameWithOwner: "fork/t3code",
|
||||
headRepositoryOwnerLogin: "fork",
|
||||
@@ -99,7 +99,10 @@ it.effect("uses gh json listing for non-open change request state queries", () =
|
||||
]);
|
||||
assert.strictEqual(changeRequests[0]?.provider, "github");
|
||||
assert.strictEqual(changeRequests[0]?.state, "merged");
|
||||
assert.strictEqual(changeRequests[0]?.updatedAt, "2026-01-02T00:00:00.000Z");
|
||||
assert.deepStrictEqual(
|
||||
changeRequests[0]?.updatedAt,
|
||||
Option.some(DateTime.makeUnsafe("2026-01-02T00:00:00.000Z")),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Effect, Layer, Result, Schema } from "effect";
|
||||
import { Effect, Layer, Option, Result, Schema } from "effect";
|
||||
import {
|
||||
SourceControlProviderError,
|
||||
type ChangeRequest,
|
||||
@@ -28,7 +28,7 @@ function toChangeRequest(summary: GitHubPullRequestSummary): ChangeRequest {
|
||||
baseRefName: summary.baseRefName,
|
||||
headRefName: summary.headRefName,
|
||||
state: summary.state ?? "open",
|
||||
updatedAt: null,
|
||||
updatedAt: Option.none(),
|
||||
...(summary.isCrossRepository !== undefined
|
||||
? { isCrossRepository: summary.isCrossRepository }
|
||||
: {}),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Context, DateTime, Effect, Layer } from "effect";
|
||||
import { Context, DateTime, Effect, Layer, Option } from "effect";
|
||||
|
||||
import {
|
||||
GitCommandError,
|
||||
@@ -204,7 +204,8 @@ const nowFreshness = Effect.fn("GitVcsDriver.nowFreshness")(function* () {
|
||||
const now = yield* DateTime.now;
|
||||
return {
|
||||
source: "live-local" as const,
|
||||
observedAt: DateTime.formatIso(now),
|
||||
observedAt: now,
|
||||
expiresAt: Option.none(),
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { assert, it } from "@effect/vitest";
|
||||
import { DateTime, Option } from "effect";
|
||||
import { Effect, FileSystem, Layer, Path, type PlatformError, type Scope } from "effect";
|
||||
import { describe } from "vitest";
|
||||
|
||||
@@ -59,7 +60,8 @@ export function runVcsDriverContractSuite<R, E>(input: VcsDriverContractSuiteInp
|
||||
assert.equal(identity?.kind, input.kind);
|
||||
assert.isTrue(identity?.rootPath.endsWith(cwd));
|
||||
assert.equal(identity?.freshness.source, "live-local");
|
||||
assert.equal(typeof identity?.freshness.observedAt, "string");
|
||||
assert.isTrue(DateTime.isDateTime(identity?.freshness.observedAt));
|
||||
assert.isTrue(Option.isNone(identity?.freshness.expiresAt ?? Option.none()));
|
||||
assert.equal(yield* driver.isInsideWorkTree(cwd), true);
|
||||
|
||||
const path = yield* Path.Path;
|
||||
@@ -91,7 +93,8 @@ export function runVcsDriverContractSuite<R, E>(input: VcsDriverContractSuiteInp
|
||||
assert.include(result.paths, "untracked.ts");
|
||||
assert.equal(result.truncated, false);
|
||||
assert.equal(result.freshness.source, "live-local");
|
||||
assert.equal(typeof result.freshness.observedAt, "string");
|
||||
assert.isTrue(DateTime.isDateTime(result.freshness.observedAt));
|
||||
assert.isTrue(Option.isNone(result.freshness.expiresAt));
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ export const ChangeRequest = Schema.Struct({
|
||||
baseRefName: TrimmedNonEmptyString,
|
||||
headRefName: TrimmedNonEmptyString,
|
||||
state: ChangeRequestState,
|
||||
updatedAt: Schema.NullOr(TrimmedNonEmptyString),
|
||||
updatedAt: Schema.Option(Schema.DateTimeUtc),
|
||||
isCrossRepository: Schema.optional(Schema.Boolean),
|
||||
headRepositoryNameWithOwner: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
headRepositoryOwnerLogin: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
|
||||
|
||||
@@ -14,8 +14,8 @@ export type VcsFreshnessSource = typeof VcsFreshnessSource.Type;
|
||||
|
||||
export const VcsFreshness = Schema.Struct({
|
||||
source: VcsFreshnessSource,
|
||||
observedAt: TrimmedNonEmptyString,
|
||||
expiresAt: Schema.optional(TrimmedNonEmptyString),
|
||||
observedAt: Schema.DateTimeUtc,
|
||||
expiresAt: Schema.Option(Schema.DateTimeUtc),
|
||||
});
|
||||
export type VcsFreshness = typeof VcsFreshness.Type;
|
||||
|
||||
|
||||
Reference in new issue
Block a user