Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3edc33ea14 | ||
|
|
9502396a57 |
No files matched your search
@@ -240,139 +240,6 @@ describe("provider compatibility", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.effect("falls back to default remote URLs when the env override parses empty", () => {
|
||||
const remoteDocument = {
|
||||
version: 1,
|
||||
policies: [
|
||||
{
|
||||
t3CodeRange: ">=0.0.0",
|
||||
driver: "codex",
|
||||
recommendedRange: "<0.130.0",
|
||||
recommendedVersion: "0.129.0",
|
||||
ranges: [{ status: "broken", range: ">=0.130.0" }],
|
||||
},
|
||||
],
|
||||
};
|
||||
const requestedUrls: string[] = [];
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const previousOverride = process.env.T3_PROVIDER_COMPATIBILITY_MAP_URL;
|
||||
process.env.T3_PROVIDER_COMPATIBILITY_MAP_URL = " , ";
|
||||
const enriched = yield* enrichProviderSnapshotWithCompatibilityAdvisory(baseProvider).pipe(
|
||||
Effect.provideService(
|
||||
HttpClient.HttpClient,
|
||||
jsonHttpClient((url) => {
|
||||
requestedUrls.push(url);
|
||||
return url === DEFAULT_PROVIDER_COMPATIBILITY_MAP_URL
|
||||
? { payload: remoteDocument }
|
||||
: { payload: {}, status: 404 };
|
||||
}),
|
||||
),
|
||||
Effect.ensuring(
|
||||
Effect.sync(() => {
|
||||
if (previousOverride === undefined) {
|
||||
delete process.env.T3_PROVIDER_COMPATIBILITY_MAP_URL;
|
||||
} else {
|
||||
process.env.T3_PROVIDER_COMPATIBILITY_MAP_URL = previousOverride;
|
||||
}
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
expect(requestedUrls).toEqual([DEFAULT_PROVIDER_COMPATIBILITY_MAP_URL]);
|
||||
expect(enriched.compatibilityAdvisory).toMatchObject({ status: "broken" });
|
||||
});
|
||||
});
|
||||
|
||||
it.effect("lets the remote map relax a bundled compatibility error", () => {
|
||||
const bundledMessage =
|
||||
"This provider harness version 0.130.0 is known to be incompatible with this T3 Code release. Use 0.129.0.";
|
||||
const remoteDocument = {
|
||||
version: 1,
|
||||
policies: [
|
||||
{
|
||||
t3CodeRange: ">=0.0.0",
|
||||
driver: "codex",
|
||||
recommendedRange: ">=0.130.0",
|
||||
recommendedVersion: "0.130.0",
|
||||
ranges: [{ status: "supported", range: ">=0.130.0" }],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const enriched = yield* enrichProviderSnapshotWithCompatibilityAdvisory({
|
||||
...baseProvider,
|
||||
status: "error",
|
||||
message: bundledMessage,
|
||||
compatibilityAdvisory: {
|
||||
status: "broken",
|
||||
severity: "error",
|
||||
currentVersion: "0.130.0",
|
||||
message: bundledMessage,
|
||||
recommendedRange: "<0.130.0",
|
||||
recommendedVersion: "0.129.0",
|
||||
ranges: [{ status: "broken", range: ">=0.130.0" }],
|
||||
},
|
||||
}).pipe(
|
||||
Effect.provideService(
|
||||
HttpClient.HttpClient,
|
||||
jsonHttpClient(() => ({ payload: remoteDocument })),
|
||||
),
|
||||
);
|
||||
|
||||
expect(enriched.status).toBe("ready");
|
||||
expect(enriched.message).toBeUndefined();
|
||||
expect(enriched.compatibilityAdvisory).toMatchObject({ status: "supported" });
|
||||
});
|
||||
});
|
||||
|
||||
it.effect("preserves genuine probe errors when the remote map relaxes a bundled advisory", () => {
|
||||
const bundledMessage =
|
||||
"This provider harness version 0.130.0 is known to be incompatible with this T3 Code release. Use 0.129.0.";
|
||||
const probeErrorMessage = "CLI health-check failed: process exited with code 1";
|
||||
const remoteDocument = {
|
||||
version: 1,
|
||||
policies: [
|
||||
{
|
||||
t3CodeRange: ">=0.0.0",
|
||||
driver: "codex",
|
||||
recommendedRange: ">=0.130.0",
|
||||
recommendedVersion: "0.130.0",
|
||||
ranges: [{ status: "supported", range: ">=0.130.0" }],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const enriched = yield* enrichProviderSnapshotWithCompatibilityAdvisory({
|
||||
...baseProvider,
|
||||
status: "error",
|
||||
message: bundledMessage,
|
||||
compatibilityAdvisory: {
|
||||
status: "broken",
|
||||
severity: "error",
|
||||
currentVersion: "0.130.0",
|
||||
message: bundledMessage,
|
||||
recommendedRange: "<0.130.0",
|
||||
recommendedVersion: "0.129.0",
|
||||
ranges: [{ status: "broken", range: ">=0.130.0" }],
|
||||
preAdvisoryStatus: "error",
|
||||
preAdvisoryMessage: probeErrorMessage,
|
||||
},
|
||||
}).pipe(
|
||||
Effect.provideService(
|
||||
HttpClient.HttpClient,
|
||||
jsonHttpClient(() => ({ payload: remoteDocument })),
|
||||
),
|
||||
);
|
||||
|
||||
expect(enriched.status).toBe("error");
|
||||
expect(enriched.message).toBe(probeErrorMessage);
|
||||
expect(enriched.compatibilityAdvisory).toMatchObject({ status: "supported" });
|
||||
});
|
||||
});
|
||||
|
||||
it.effect("falls back to the bundled map when the remote compatibility fetch fails", () =>
|
||||
Effect.gen(function* () {
|
||||
const enriched = yield* enrichProviderSnapshotWithCompatibilityAdvisory({
|
||||
|
||||
@@ -39,6 +39,7 @@ type ProviderCompatibilitySnapshot = Pick<ServerProvider, "enabled" | "status" |
|
||||
|
||||
const T3_CODE_VERSION = packageJson.version;
|
||||
const REMOTE_COMPATIBILITY_CACHE_TTL_MS = 15 * 60 * 1_000;
|
||||
const REMOTE_COMPATIBILITY_NEGATIVE_CACHE_TTL_MS = 60 * 1_000;
|
||||
const REMOTE_COMPATIBILITY_TIMEOUT_MS = 2_500;
|
||||
|
||||
export const DEFAULT_PROVIDER_COMPATIBILITY_MAP_URL =
|
||||
@@ -114,11 +115,10 @@ function remoteCompatibilityMapUrls(): ReadonlyArray<string> {
|
||||
if (!configured) {
|
||||
return DEFAULT_PROVIDER_COMPATIBILITY_MAP_URLS;
|
||||
}
|
||||
const urls = configured
|
||||
return configured
|
||||
.split(",")
|
||||
.map((url) => url.trim())
|
||||
.filter((url) => url.length > 0);
|
||||
return urls.length > 0 ? urls : DEFAULT_PROVIDER_COMPATIBILITY_MAP_URLS;
|
||||
}
|
||||
|
||||
function policyMatches(input: {
|
||||
@@ -291,8 +291,11 @@ export const resolveRemoteProviderCompatibilityDocument = Effect.fn(
|
||||
}
|
||||
|
||||
const document = yield* fetchRemoteCompatibilityDocument(url);
|
||||
const ttl = document
|
||||
? REMOTE_COMPATIBILITY_CACHE_TTL_MS
|
||||
: REMOTE_COMPATIBILITY_NEGATIVE_CACHE_TTL_MS;
|
||||
remoteCompatibilityCache.set(url, {
|
||||
expiresAt: now + REMOTE_COMPATIBILITY_CACHE_TTL_MS,
|
||||
expiresAt: now + ttl,
|
||||
document,
|
||||
});
|
||||
if (document) {
|
||||
@@ -307,9 +310,9 @@ function applyCompatibilityAdvisory<Snapshot extends ProviderCompatibilitySnapsh
|
||||
snapshot: Snapshot,
|
||||
compatibilityAdvisory: ServerProviderCompatibilityAdvisory | undefined,
|
||||
): Snapshot {
|
||||
const baseSnapshot = removeExistingCompatibilityAdvisory(snapshot);
|
||||
if (!compatibilityAdvisory) {
|
||||
return baseSnapshot;
|
||||
const { compatibilityAdvisory: _omit, ...snapshotWithoutAdvisory } = snapshot;
|
||||
return snapshotWithoutAdvisory as Snapshot;
|
||||
}
|
||||
|
||||
const compatibilityMessage =
|
||||
@@ -321,56 +324,20 @@ function applyCompatibilityAdvisory<Snapshot extends ProviderCompatibilitySnapsh
|
||||
? "error"
|
||||
: snapshot.enabled &&
|
||||
compatibilityAdvisory.severity === "warning" &&
|
||||
baseSnapshot.status === "ready"
|
||||
snapshot.status === "ready"
|
||||
? "warning"
|
||||
: baseSnapshot.status;
|
||||
|
||||
const advisoryWithPreState: ServerProviderCompatibilityAdvisory = {
|
||||
...compatibilityAdvisory,
|
||||
preAdvisoryStatus: baseSnapshot.status,
|
||||
...(baseSnapshot.message ? { preAdvisoryMessage: baseSnapshot.message } : {}),
|
||||
};
|
||||
: snapshot.status;
|
||||
|
||||
return {
|
||||
...baseSnapshot,
|
||||
...snapshot,
|
||||
status,
|
||||
...(compatibilityMessage || baseSnapshot.message
|
||||
? { message: compatibilityMessage ?? baseSnapshot.message }
|
||||
...(compatibilityMessage || snapshot.message
|
||||
? { message: compatibilityMessage ?? snapshot.message }
|
||||
: {}),
|
||||
compatibilityAdvisory: advisoryWithPreState,
|
||||
compatibilityAdvisory,
|
||||
} as Snapshot;
|
||||
}
|
||||
|
||||
function removeExistingCompatibilityAdvisory<Snapshot extends ProviderCompatibilitySnapshot>(
|
||||
snapshot: Snapshot,
|
||||
): Snapshot {
|
||||
if (!snapshot.compatibilityAdvisory) {
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
const { compatibilityAdvisory: existingCompatibilityAdvisory, ...baseSnapshot } = snapshot;
|
||||
const compatibilityMessage =
|
||||
existingCompatibilityAdvisory.severity !== "info"
|
||||
? (existingCompatibilityAdvisory.message ?? undefined)
|
||||
: undefined;
|
||||
if (compatibilityMessage && baseSnapshot.message === compatibilityMessage) {
|
||||
const { message: _message, ...snapshotWithoutCompatibilityMessage } = baseSnapshot;
|
||||
const restoredStatus =
|
||||
existingCompatibilityAdvisory.preAdvisoryStatus ?? (snapshot.enabled ? "ready" : "disabled");
|
||||
return {
|
||||
...snapshotWithoutCompatibilityMessage,
|
||||
status: restoredStatus,
|
||||
...(existingCompatibilityAdvisory.preAdvisoryMessage
|
||||
? { message: existingCompatibilityAdvisory.preAdvisoryMessage }
|
||||
: {}),
|
||||
} as Snapshot;
|
||||
}
|
||||
if (existingCompatibilityAdvisory.preAdvisoryStatus !== undefined) {
|
||||
return { ...baseSnapshot, status: existingCompatibilityAdvisory.preAdvisoryStatus } as Snapshot;
|
||||
}
|
||||
return baseSnapshot as Snapshot;
|
||||
}
|
||||
|
||||
export function applyBundledProviderCompatibilityAdvisory<
|
||||
Snapshot extends ProviderCompatibilitySnapshot,
|
||||
>(input: {
|
||||
|
||||
@@ -163,8 +163,6 @@ export const ServerProviderCompatibilityAdvisory = Schema.Struct({
|
||||
ranges: Schema.Array(ServerProviderCompatibilityRange).pipe(
|
||||
Schema.withDecodingDefault(Effect.succeed([])),
|
||||
),
|
||||
preAdvisoryStatus: Schema.optionalKey(ServerProviderState),
|
||||
preAdvisoryMessage: Schema.optionalKey(TrimmedNonEmptyString),
|
||||
});
|
||||
export type ServerProviderCompatibilityAdvisory = typeof ServerProviderCompatibilityAdvisory.Type;
|
||||
|
||||
|
||||
Reference in new issue
Block a user