From 783d3205472c4314edd16e3d261d1cd2e4da2989 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 13 Mar 2026 21:29:07 +0000 Subject: [PATCH] test: tighten shared requirements coverage --- src/shared/requirements.test.ts | 85 +++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/src/shared/requirements.test.ts b/src/shared/requirements.test.ts index 06d48ec2e..0a05a0eb8 100644 --- a/src/shared/requirements.test.ts +++ b/src/shared/requirements.test.ts @@ -1,7 +1,9 @@ import { describe, expect, it } from "vitest"; import { buildConfigChecks, + evaluateRequirements, evaluateRequirementsFromMetadata, + evaluateRequirementsFromMetadataWithRemote, resolveMissingAnyBins, resolveMissingBins, resolveMissingEnv, @@ -79,4 +81,87 @@ describe("requirements helpers", () => { expect(res.missing.os).toEqual(["darwin"]); expect(res.eligible).toBe(false); }); + + it("evaluateRequirements reports config checks and all missing categories directly", () => { + const res = evaluateRequirements({ + always: false, + required: { + bins: ["node"], + anyBins: ["bun", "deno"], + env: ["OPENAI_API_KEY"], + config: ["browser.enabled", "gateway.enabled"], + os: ["darwin"], + }, + hasLocalBin: () => false, + hasRemoteBin: (bin) => bin === "node", + hasRemoteAnyBin: () => false, + localPlatform: "linux", + remotePlatforms: ["windows"], + isEnvSatisfied: () => false, + isConfigSatisfied: (path) => path === "gateway.enabled", + }); + + expect(res.missing).toEqual({ + bins: [], + anyBins: ["bun", "deno"], + env: ["OPENAI_API_KEY"], + config: ["browser.enabled"], + os: ["darwin"], + }); + expect(res.configChecks).toEqual([ + { path: "browser.enabled", satisfied: false }, + { path: "gateway.enabled", satisfied: true }, + ]); + expect(res.eligible).toBe(false); + }); + + it("clears missing requirements when always is true but preserves config checks", () => { + const res = evaluateRequirements({ + always: true, + required: { + bins: ["node"], + anyBins: ["bun"], + env: ["OPENAI_API_KEY"], + config: ["browser.enabled"], + os: ["darwin"], + }, + hasLocalBin: () => false, + localPlatform: "linux", + isEnvSatisfied: () => false, + isConfigSatisfied: () => false, + }); + + expect(res.missing).toEqual({ bins: [], anyBins: [], env: [], config: [], os: [] }); + expect(res.configChecks).toEqual([{ path: "browser.enabled", satisfied: false }]); + expect(res.eligible).toBe(true); + }); + + it("evaluateRequirementsFromMetadataWithRemote wires remote predicates and platforms through", () => { + const res = evaluateRequirementsFromMetadataWithRemote({ + always: false, + metadata: { + requires: { bins: ["node"], anyBins: ["bun"], env: ["OPENAI_API_KEY"] }, + os: ["darwin"], + }, + remote: { + hasBin: (bin) => bin === "node", + hasAnyBin: (bins) => bins.includes("bun"), + platforms: ["darwin"], + }, + hasLocalBin: () => false, + localPlatform: "linux", + isEnvSatisfied: (name) => name === "OPENAI_API_KEY", + isConfigSatisfied: () => true, + }); + + expect(res.required).toEqual({ + bins: ["node"], + anyBins: ["bun"], + env: ["OPENAI_API_KEY"], + config: [], + os: ["darwin"], + }); + expect(res.missing).toEqual({ bins: [], anyBins: [], env: [], config: [], os: [] }); + expect(res.eligible).toBe(true); + }); });