fix: allow remote advisory to demote status set by bundled advisory
When applyCompatibilityAdvisory replaces an existing advisory, compute the base status/message by reversing the previous advisory's promotion. This enables a less-severe remote advisory (e.g. severity 'info' for 'supported') to correctly demote status that was elevated to 'error' by a bundled advisory—the core purpose of the remote override system.
This commit is contained in:
2 files changed
+67
-8
No files matched your search
@@ -4,6 +4,7 @@ import * as Effect from "effect/Effect";
|
||||
import { HttpClient, HttpClientResponse } from "effect/unstable/http";
|
||||
|
||||
import {
|
||||
applyBundledProviderCompatibilityAdvisory,
|
||||
clearProviderCompatibilityCacheForTests,
|
||||
createProviderCompatibilityAdvisory,
|
||||
enrichProviderSnapshotWithCompatibilityAdvisory,
|
||||
@@ -121,4 +122,42 @@ describe("provider compatibility", () => {
|
||||
recommendedVersion: "0.129.0",
|
||||
});
|
||||
});
|
||||
|
||||
it("remote advisory demotes status set by bundled advisory", async () => {
|
||||
// The bundled document marks <0.129.0 as "broken", so 0.128.0 triggers
|
||||
// an error advisory on the initial snapshot.
|
||||
const snapshotAfterBundled = applyBundledProviderCompatibilityAdvisory({
|
||||
snapshot: { ...baseProvider, version: "0.128.0" },
|
||||
driver: codexDriver,
|
||||
currentVersion: "0.128.0",
|
||||
});
|
||||
expect(snapshotAfterBundled.status).toBe("error");
|
||||
expect(snapshotAfterBundled.compatibilityAdvisory?.severity).toBe("error");
|
||||
|
||||
// The remote document relaxes the policy: 0.128.0 is now "supported".
|
||||
const remoteDocument = {
|
||||
version: 1,
|
||||
policies: [
|
||||
{
|
||||
t3CodeRange: ">=0.0.0",
|
||||
driver: "codex",
|
||||
recommendedRange: ">=0.129.0",
|
||||
recommendedVersion: "0.129.0",
|
||||
ranges: [{ status: "supported", range: ">=0.128.0" }],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const enriched = await Effect.runPromise(
|
||||
enrichProviderSnapshotWithCompatibilityAdvisory({
|
||||
...snapshotAfterBundled,
|
||||
instanceId: baseProvider.instanceId,
|
||||
driver: baseProvider.driver,
|
||||
}).pipe(Effect.provideService(HttpClient.HttpClient, jsonHttpClient(remoteDocument))),
|
||||
);
|
||||
|
||||
expect(enriched.status).toBe("ready");
|
||||
expect(enriched.compatibilityAdvisory?.severity).toBe("info");
|
||||
expect(enriched.message).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -281,6 +281,24 @@ export const resolveRemoteProviderCompatibilityDocument = Effect.fn(
|
||||
return document;
|
||||
});
|
||||
|
||||
function baseStatusWithoutAdvisory<Snapshot extends ProviderCompatibilitySnapshot>(
|
||||
snapshot: Snapshot,
|
||||
): Snapshot["status"] {
|
||||
const prev = snapshot.compatibilityAdvisory;
|
||||
if (!prev || !snapshot.enabled) return snapshot.status;
|
||||
if (prev.severity === "error" && snapshot.status === "error") return "ready";
|
||||
if (prev.severity === "warning" && snapshot.status === "warning") return "ready";
|
||||
return snapshot.status;
|
||||
}
|
||||
|
||||
function baseMessageWithoutAdvisory<Snapshot extends ProviderCompatibilitySnapshot>(
|
||||
snapshot: Snapshot,
|
||||
): Snapshot["message"] {
|
||||
const prev = snapshot.compatibilityAdvisory;
|
||||
if (prev?.message != null && snapshot.message === prev.message) return undefined;
|
||||
return snapshot.message;
|
||||
}
|
||||
|
||||
function applyCompatibilityAdvisory<Snapshot extends ProviderCompatibilitySnapshot>(
|
||||
snapshot: Snapshot,
|
||||
compatibilityAdvisory: ServerProviderCompatibilityAdvisory | undefined,
|
||||
@@ -290,6 +308,8 @@ function applyCompatibilityAdvisory<Snapshot extends ProviderCompatibilitySnapsh
|
||||
return snapshotWithoutAdvisory as Snapshot;
|
||||
}
|
||||
|
||||
const baseStatus = baseStatusWithoutAdvisory(snapshot);
|
||||
|
||||
const compatibilityMessage =
|
||||
compatibilityAdvisory.severity !== "info"
|
||||
? (compatibilityAdvisory.message ?? undefined)
|
||||
@@ -297,18 +317,18 @@ function applyCompatibilityAdvisory<Snapshot extends ProviderCompatibilitySnapsh
|
||||
const status =
|
||||
snapshot.enabled && compatibilityAdvisory.severity === "error"
|
||||
? "error"
|
||||
: snapshot.enabled &&
|
||||
compatibilityAdvisory.severity === "warning" &&
|
||||
snapshot.status === "ready"
|
||||
: snapshot.enabled && compatibilityAdvisory.severity === "warning" && baseStatus === "ready"
|
||||
? "warning"
|
||||
: snapshot.status;
|
||||
: baseStatus;
|
||||
|
||||
const baseMessage = baseMessageWithoutAdvisory(snapshot);
|
||||
const resolvedMessage = compatibilityMessage ?? baseMessage;
|
||||
const { message: _existingMessage, ...snapshotWithoutMessage } = snapshot;
|
||||
|
||||
return {
|
||||
...snapshot,
|
||||
...snapshotWithoutMessage,
|
||||
status,
|
||||
...(compatibilityMessage || snapshot.message
|
||||
? { message: compatibilityMessage ?? snapshot.message }
|
||||
: {}),
|
||||
...(resolvedMessage != null ? { message: resolvedMessage } : {}),
|
||||
compatibilityAdvisory,
|
||||
} as Snapshot;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user