Extend provider adapter runtime contract
This commit is contained in:
1 parent
0388e1003b
commit
203a48060e
3 files changed
+78
-27
No files matched your search
@@ -9,6 +9,30 @@ import { SdlcService } from "../../src/main/services/sdlc-service";
|
||||
import { EVAL_SUITE_KEY, PROVIDER_AUTH_TYPE, SDLC_RUN_STATE } from "../../src/shared/domain";
|
||||
import { PROVIDER_CATALOG } from "../../src/shared/provider-catalog";
|
||||
|
||||
const PROVIDER_SECRET_SAMPLES: Record<string, string> = {
|
||||
openai: "sk-live-provider",
|
||||
anthropic: "sk-live-provider",
|
||||
xai: "sk-live-provider",
|
||||
groq: "sk-live-provider",
|
||||
"github-copilot": "ghu_live_provider",
|
||||
"google-antigravity": "antigravity-session",
|
||||
"gpt-account": "chatgpt-session",
|
||||
"azure-openai": JSON.stringify({
|
||||
baseUrl: "https://acme.openai.azure.com",
|
||||
deployment: "gpt-5.4",
|
||||
secret: "azure-key",
|
||||
}),
|
||||
"aws-bedrock": JSON.stringify({
|
||||
region: "us-east-1",
|
||||
secret: JSON.stringify({ accessKeyId: "AKIA123", secretAccessKey: "aws-secret" }),
|
||||
}),
|
||||
"vertex-ai": JSON.stringify({
|
||||
projectId: "acme-ai",
|
||||
region: "us-central1",
|
||||
secret: JSON.stringify({ client_email: "agent@acme.iam.gserviceaccount.com", private_key: "key" }),
|
||||
}),
|
||||
};
|
||||
|
||||
function createConnection(): DatabaseConnection {
|
||||
return new DatabaseConnection(join(tmpdir(), `agentcompany-new-contract-${randomUUID()}.db`));
|
||||
}
|
||||
@@ -33,32 +57,8 @@ describe("provider contracts", () => {
|
||||
});
|
||||
|
||||
test("parses credential profiles with required fields", () => {
|
||||
const samples: Record<string, string> = {
|
||||
openai: "sk-live-provider",
|
||||
anthropic: "sk-live-provider",
|
||||
xai: "sk-live-provider",
|
||||
groq: "sk-live-provider",
|
||||
"github-copilot": "ghu_live_provider",
|
||||
"google-antigravity": "antigravity-session",
|
||||
"gpt-account": "chatgpt-session",
|
||||
"azure-openai": JSON.stringify({
|
||||
baseUrl: "https://acme.openai.azure.com",
|
||||
deployment: "gpt-5.4",
|
||||
secret: "azure-key",
|
||||
}),
|
||||
"aws-bedrock": JSON.stringify({
|
||||
region: "us-east-1",
|
||||
secret: JSON.stringify({ accessKeyId: "AKIA123", secretAccessKey: "aws-secret" }),
|
||||
}),
|
||||
"vertex-ai": JSON.stringify({
|
||||
projectId: "acme-ai",
|
||||
region: "us-central1",
|
||||
secret: JSON.stringify({ client_email: "agent@acme.iam.gserviceaccount.com", private_key: "key" }),
|
||||
}),
|
||||
};
|
||||
|
||||
for (const provider of PROVIDER_CATALOG) {
|
||||
const profile = providerAdapters[provider.key].parseAuthProfile(samples[provider.key]);
|
||||
const profile = providerAdapters[provider.key].parseAuthProfile(PROVIDER_SECRET_SAMPLES[provider.key]);
|
||||
if (provider.authType === PROVIDER_AUTH_TYPE.API_KEY) expect(profile.type).toBe("api_key");
|
||||
if (provider.authType === PROVIDER_AUTH_TYPE.OAUTH_PKCE) expect(profile.type).toBe("access_token");
|
||||
if (provider.authType === PROVIDER_AUTH_TYPE.ACCOUNT_SUBSCRIPTION) expect(profile.type).toBe("account_token");
|
||||
@@ -81,6 +81,15 @@ describe("provider contracts", () => {
|
||||
}))).toThrow("Azure base URL must use HTTPS.");
|
||||
});
|
||||
|
||||
test("exposes model listing and rate limit adapter contracts", async () => {
|
||||
for (const provider of PROVIDER_CATALOG) {
|
||||
const adapter = providerAdapters[provider.key];
|
||||
const authProfile = adapter.parseAuthProfile(PROVIDER_SECRET_SAMPLES[provider.key]);
|
||||
await expect(adapter.listModels({ authProfile, model: provider.defaultModel })).resolves.toEqual(provider.models);
|
||||
await expect(adapter.getRateLimitState({ authProfile, model: provider.defaultModel })).resolves.toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
test("runs the seeded contract eval suite", () => {
|
||||
const connection = createConnection();
|
||||
const organization = new OrganizationService(connection.db);
|
||||
@@ -100,7 +109,7 @@ describe("provider contracts", () => {
|
||||
.get(runId) as { state: string; failed_count: number; result_json: string };
|
||||
const result = JSON.parse(run.result_json) as { checks: Array<{ key: string; passed: boolean }> };
|
||||
expect(run).toMatchObject({ state: SDLC_RUN_STATE.PASSED, failed_count: 0 });
|
||||
expect(result.checks.map((check) => check.key).sort()).toEqual(["provider_adapter_coverage", "schema_version"]);
|
||||
expect(result.checks.map((check) => check.key).sort()).toEqual(["provider_adapter_coverage", "provider_runtime_contract", "schema_version"]);
|
||||
expect(result.checks.every((check) => check.passed)).toBe(true);
|
||||
connection.close();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user