Fix provider compatibility advisory state
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
278ba2db93
commit
e035af7654
4 files changed
+141
-18
No files matched your search
@@ -286,6 +286,42 @@ describe("provider compatibility", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it.effect("does not cache failed remote compatibility fetches", () => {
|
||||
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[] = [];
|
||||
let attempt = 0;
|
||||
|
||||
return Effect.gen(function* () {
|
||||
yield* ProviderCompatibility.enrichProviderSnapshotWithCompatibilityAdvisory(baseProvider);
|
||||
const enriched =
|
||||
yield* ProviderCompatibility.enrichProviderSnapshotWithCompatibilityAdvisory(baseProvider);
|
||||
|
||||
expect(requestedUrls).toEqual([
|
||||
ProviderCompatibility.DEFAULT_PROVIDER_COMPATIBILITY_MAP_URL,
|
||||
ProviderCompatibility.GITHUB_PROVIDER_COMPATIBILITY_MAP_URL,
|
||||
ProviderCompatibility.DEFAULT_PROVIDER_COMPATIBILITY_MAP_URL,
|
||||
]);
|
||||
expect(enriched.compatibilityAdvisory).toMatchObject({ status: "broken" });
|
||||
}).pipe(
|
||||
provideCompatibility((url) => {
|
||||
requestedUrls.push(url);
|
||||
attempt += 1;
|
||||
return attempt === 3 ? { payload: remoteDocument } : { payload: {}, status: 404 };
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it.effect("falls back from the hosted map to the GitHub raw mirror", () => {
|
||||
const remoteDocument = {
|
||||
version: 1,
|
||||
@@ -404,6 +440,79 @@ describe("provider compatibility", () => {
|
||||
});
|
||||
});
|
||||
|
||||
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* ProviderCompatibility.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(provideCompatibility(() => ({ payload: remoteDocument })));
|
||||
|
||||
expect(enriched.status).toBe("error");
|
||||
expect(enriched.message).toBe(probeErrorMessage);
|
||||
expect(enriched.compatibilityAdvisory).toMatchObject({ status: "supported" });
|
||||
});
|
||||
});
|
||||
|
||||
it.effect("keeps probe error messages when warning advisories do not change status", () => {
|
||||
const probeErrorMessage = "Authentication failed";
|
||||
const remoteDocument = {
|
||||
version: 1,
|
||||
policies: [
|
||||
{
|
||||
t3CodeRange: ">=0.0.0",
|
||||
driver: "codex",
|
||||
recommendedRange: ">=0.130.0",
|
||||
recommendedVersion: "0.130.0",
|
||||
ranges: [{ status: "graceful", range: ">=0.130.0" }],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
return Effect.gen(function* () {
|
||||
const enriched = yield* ProviderCompatibility.enrichProviderSnapshotWithCompatibilityAdvisory(
|
||||
{
|
||||
...baseProvider,
|
||||
status: "error",
|
||||
message: probeErrorMessage,
|
||||
},
|
||||
).pipe(provideCompatibility(() => ({ payload: remoteDocument })));
|
||||
|
||||
expect(enriched.status).toBe("error");
|
||||
expect(enriched.message).toBe(probeErrorMessage);
|
||||
expect(enriched.compatibilityAdvisory).toMatchObject({ status: "graceful" });
|
||||
});
|
||||
});
|
||||
|
||||
it.effect("falls back to the bundled map when the remote compatibility fetch fails", () =>
|
||||
Effect.gen(function* () {
|
||||
const enriched = yield* ProviderCompatibility.enrichProviderSnapshotWithCompatibilityAdvisory(
|
||||
|
||||
@@ -252,13 +252,6 @@ const fetchRemoteCompatibilityDocument = Effect.fn("fetchRemoteCompatibilityDocu
|
||||
),
|
||||
);
|
||||
|
||||
export const resolveRemoteProviderCompatibilityDocument = Effect.fn(
|
||||
"resolveRemoteProviderCompatibilityDocument",
|
||||
)(function* () {
|
||||
const compatibility = yield* ProviderCompatibilityService;
|
||||
return yield* compatibility.resolveRemoteDocument;
|
||||
});
|
||||
|
||||
function applyCompatibilityAdvisory<Snapshot extends ProviderCompatibilitySnapshot>(
|
||||
snapshot: Snapshot,
|
||||
compatibilityAdvisory: ServerProviderCompatibilityAdvisory | undefined,
|
||||
@@ -268,18 +261,23 @@ function applyCompatibilityAdvisory<Snapshot extends ProviderCompatibilitySnapsh
|
||||
return baseSnapshot;
|
||||
}
|
||||
|
||||
const compatibilityMessage =
|
||||
compatibilityAdvisory.severity !== "info"
|
||||
? (compatibilityAdvisory.message ?? undefined)
|
||||
: undefined;
|
||||
const status =
|
||||
snapshot.enabled && compatibilityAdvisory.severity === "error"
|
||||
baseSnapshot.enabled && compatibilityAdvisory.severity === "error"
|
||||
? "error"
|
||||
: snapshot.enabled &&
|
||||
: baseSnapshot.enabled &&
|
||||
compatibilityAdvisory.severity === "warning" &&
|
||||
baseSnapshot.status === "ready"
|
||||
? "warning"
|
||||
: baseSnapshot.status;
|
||||
const compatibilityMessage =
|
||||
status !== baseSnapshot.status && compatibilityAdvisory.severity !== "info"
|
||||
? (compatibilityAdvisory.message ?? undefined)
|
||||
: undefined;
|
||||
const advisoryWithPreState: ServerProviderCompatibilityAdvisory = {
|
||||
...compatibilityAdvisory,
|
||||
preAdvisoryStatus: baseSnapshot.status,
|
||||
...(baseSnapshot.message ? { preAdvisoryMessage: baseSnapshot.message } : {}),
|
||||
};
|
||||
|
||||
return {
|
||||
...baseSnapshot,
|
||||
@@ -287,7 +285,7 @@ function applyCompatibilityAdvisory<Snapshot extends ProviderCompatibilitySnapsh
|
||||
...(compatibilityMessage || baseSnapshot.message
|
||||
? { message: compatibilityMessage ?? baseSnapshot.message }
|
||||
: {}),
|
||||
compatibilityAdvisory,
|
||||
compatibilityAdvisory: advisoryWithPreState,
|
||||
} as Snapshot;
|
||||
}
|
||||
|
||||
@@ -305,9 +303,20 @@ function removeExistingCompatibilityAdvisory<Snapshot extends ProviderCompatibil
|
||||
: undefined;
|
||||
if (compatibilityMessage && baseSnapshot.message === compatibilityMessage) {
|
||||
const { message: _message, ...snapshotWithoutCompatibilityMessage } = baseSnapshot;
|
||||
const restoredStatus =
|
||||
existingCompatibilityAdvisory.preAdvisoryStatus ?? (snapshot.enabled ? "ready" : "disabled");
|
||||
return {
|
||||
...snapshotWithoutCompatibilityMessage,
|
||||
status: snapshot.enabled ? "ready" : "disabled",
|
||||
status: restoredStatus,
|
||||
...(existingCompatibilityAdvisory.preAdvisoryMessage
|
||||
? { message: existingCompatibilityAdvisory.preAdvisoryMessage }
|
||||
: {}),
|
||||
} as Snapshot;
|
||||
}
|
||||
if (existingCompatibilityAdvisory.preAdvisoryStatus !== undefined) {
|
||||
return {
|
||||
...baseSnapshot,
|
||||
status: existingCompatibilityAdvisory.preAdvisoryStatus,
|
||||
} as Snapshot;
|
||||
}
|
||||
return baseSnapshot as Snapshot;
|
||||
@@ -371,7 +380,10 @@ export const makeProviderCompatibilityService = Effect.fn("makeProviderCompatibi
|
||||
function* () {
|
||||
const remoteDocumentCache = yield* Cache.makeWith(fetchRemoteCompatibilityDocument, {
|
||||
capacity: REMOTE_COMPATIBILITY_CACHE_CAPACITY,
|
||||
timeToLive: (exit) => (Exit.isSuccess(exit) ? REMOTE_COMPATIBILITY_CACHE_TTL : Duration.zero),
|
||||
timeToLive: (exit) =>
|
||||
Exit.isSuccess(exit) && exit.value !== null
|
||||
? REMOTE_COMPATIBILITY_CACHE_TTL
|
||||
: Duration.zero,
|
||||
});
|
||||
|
||||
const resolveRemoteDocument = Effect.gen(function* () {
|
||||
|
||||
@@ -46,8 +46,8 @@ describe("providerModelsFromSettings", () => {
|
||||
describe("buildServerProvider", () => {
|
||||
it("leaves compatibility unset when no bundled policy matches this T3 Code version", () => {
|
||||
const provider = buildServerProvider({
|
||||
driver: ProviderDriverKind.make("codex"),
|
||||
presentation: { displayName: "Codex" },
|
||||
driver: ProviderDriverKind.make("unmapped-test-driver"),
|
||||
presentation: { displayName: "Test" },
|
||||
enabled: true,
|
||||
checkedAt: "2026-04-10T00:00:00.000Z",
|
||||
models: [],
|
||||
|
||||
@@ -165,6 +165,8 @@ 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