From 3bd301bc8ead6a459e4369577f91eb9688672b92 Mon Sep 17 00:00:00 2001 From: Ron Cohen Date: Sat, 14 Nov 2026 20:50:56 +0000 Subject: [PATCH 1/2] build: add opt-in Node SDK next prereleases --- .github/workflows/node-sdk-prerelease.yml | 151 ++++++ .github/workflows/package-ci.yml | 2 + package.json | 5 +- .../node-sdk-prerelease/registered.cts | 43 ++ .../fixtures/node-sdk-prerelease/runtime.cjs | 146 ++++++ .../node-sdk-prerelease/unregistered.cts | 41 ++ scripts/node-sdk-prerelease.mjs | 446 ++++++++++++++++++ scripts/node-sdk-prerelease.test.mjs | 410 ++++++++++++++++ yarn.lock | 10 + 9 files changed, 1253 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/node-sdk-prerelease.yml create mode 100644 scripts/fixtures/node-sdk-prerelease/registered.cts create mode 100644 scripts/fixtures/node-sdk-prerelease/runtime.cjs create mode 100644 scripts/fixtures/node-sdk-prerelease/unregistered.cts create mode 100644 scripts/node-sdk-prerelease.mjs create mode 100644 scripts/node-sdk-prerelease.test.mjs diff --git a/.github/workflows/node-sdk-prerelease.yml b/.github/workflows/node-sdk-prerelease.yml new file mode 100644 index 000000000..ee2e5caf0 --- /dev/null +++ b/.github/workflows/node-sdk-prerelease.yml @@ -0,0 +1,151 @@ +name: Node SDK next prerelease + +on: + workflow_dispatch: + inputs: + source_sha: + description: Exact 40-character commit SHA with passing Package CI + required: true + type: string + version: + description: Expected Node manifest version (2.0.0-next.N) + required: true + default: 2.0.0-next.0 + type: string + publish: + description: Publish the verified tarball to npm under next (false only prepares an artifact) + required: true + default: false + type: boolean + +permissions: + contents: read + +concurrency: + group: node-sdk-next-prerelease + cancel-in-progress: false + +jobs: + prepare: + runs-on: ubuntu-latest + timeout-minutes: 20 + permissions: + contents: read + checks: read + actions: read + outputs: + sha256: ${{ steps.prepare.outputs.sha256 }} + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.sha }} + path: release-tools + persist-credentials: false + - name: Validate dispatch and candidate identity + env: + WORKFLOW_REF: ${{ github.ref }} + SOURCE_SHA: ${{ inputs.source_sha }} + VERSION: ${{ inputs.version }} + run: | + test "$WORKFLOW_REF" = refs/heads/main + node release-tools/scripts/node-sdk-prerelease.mjs validate --version "$VERSION" --sha "$SOURCE_SHA" + - name: Require successful CI on the exact candidate + env: + GH_TOKEN: ${{ github.token }} + SOURCE_SHA: ${{ inputs.source_sha }} + VERSION: ${{ inputs.version }} + run: | + gh api --paginate --slurp "repos/$GITHUB_REPOSITORY/commits/$SOURCE_SHA/check-runs?per_page=100" > "$RUNNER_TEMP/candidate-checks.json" + node release-tools/scripts/node-sdk-prerelease.mjs ci --version "$VERSION" --sha "$SOURCE_SHA" --checks "$RUNNER_TEMP/candidate-checks.json" + - name: Require publication approval protection + if: ${{ inputs.publish }} + env: + GH_TOKEN: ${{ github.token }} + run: | + gh api "repos/$GITHUB_REPOSITORY/environments/npm-node-prerelease" > "$RUNNER_TEMP/prerelease-environment.json" + node release-tools/scripts/node-sdk-prerelease.mjs environment --environment "$RUNNER_TEMP/prerelease-environment.json" + - uses: actions/checkout@v4 + with: + ref: ${{ inputs.source_sha }} + path: candidate + persist-credentials: false + - name: Enable corepack + run: corepack enable + - uses: actions/setup-node@v6 + with: + node-version-file: release-tools/.nvmrc + cache: yarn + cache-dependency-path: candidate/yarn.lock + - name: Build, test and verify the actual packed package + id: prepare + env: + SOURCE_SHA: ${{ inputs.source_sha }} + VERSION: ${{ inputs.version }} + HUSKY: "0" + run: | + node release-tools/scripts/node-sdk-prerelease.mjs prepare \ + --source "$GITHUB_WORKSPACE/candidate" --output "$RUNNER_TEMP/node-sdk-next" \ + --version "$VERSION" --sha "$SOURCE_SHA" + - uses: actions/upload-artifact@v4 + with: + name: node-sdk-next + path: ${{ runner.temp }}/node-sdk-next/ + if-no-files-found: error + retention-days: 7 + + publish: + if: ${{ inputs.publish && github.ref == 'refs/heads/main' }} + needs: prepare + runs-on: ubuntu-latest + timeout-minutes: 5 + environment: npm-node-prerelease + permissions: + contents: read + id-token: write + steps: + # Only trusted workflow tools are checked out here. Candidate code and its + # dependency/lifecycle scripts never execute in this OIDC-enabled job. + - uses: actions/checkout@v4 + with: + ref: ${{ github.sha }} + persist-credentials: false + - uses: actions/setup-node@v6 + with: + node-version-file: .nvmrc + registry-url: https://registry.npmjs.org + scope: "@reflag" + - uses: actions/download-artifact@v4 + with: + name: node-sdk-next + path: ${{ runner.temp }}/node-sdk-next + - name: Verify immutable artifact and current registry state + env: + SOURCE_SHA: ${{ inputs.source_sha }} + VERSION: ${{ inputs.version }} + SHA256: ${{ needs.prepare.outputs.sha256 }} + run: | + node -e 'const [major,minor,patch] = require("node:child_process").execFileSync("npm", ["--version"], {encoding:"utf8"}).trim().split(".").map(Number); if (!(major > 11 || (major === 11 && (minor > 5 || (minor === 5 && patch >= 1))))) throw new Error("npm >=11.5.1 is required for trusted publishing");' + node scripts/node-sdk-prerelease.mjs verify \ + --output "$RUNNER_TEMP/node-sdk-next" --version "$VERSION" --sha "$SOURCE_SHA" --sha256 "$SHA256" + - name: Publish only the verified Node tarball under next + env: + VERSION: ${{ inputs.version }} + run: | + npm publish "$RUNNER_TEMP/node-sdk-next/reflag-node-sdk-$VERSION.tgz" \ + --tag next --access public --provenance --ignore-scripts --registry https://registry.npmjs.org + - name: Confirm next, artifact integrity and unchanged latest + env: + SOURCE_SHA: ${{ inputs.source_sha }} + VERSION: ${{ inputs.version }} + SHA256: ${{ needs.prepare.outputs.sha256 }} + run: | + # Registry/CDN reads may briefly lag a successful immutable publish. + for attempt in 1 2 3 4 5; do + if node scripts/node-sdk-prerelease.mjs verify --published \ + --output "$RUNNER_TEMP/node-sdk-next" --version "$VERSION" --sha "$SOURCE_SHA" --sha256 "$SHA256"; then + printf '\n### Published\n\n`@reflag/node-sdk@%s` under `next`; `latest` remains unchanged.\n' "$VERSION" >> "$GITHUB_STEP_SUMMARY" + exit 0 + fi + if [ "$attempt" = 5 ]; then exit 1; fi + sleep 2 + done diff --git a/.github/workflows/package-ci.yml b/.github/workflows/package-ci.yml index 0e78a2ab5..ab89ce074 100644 --- a/.github/workflows/package-ci.yml +++ b/.github/workflows/package-ci.yml @@ -29,6 +29,8 @@ jobs: - name: Restore package.json # This step is necessary because the previous step may have updated package.json run: git checkout -- package.json packages/*/package.json + - name: Test prerelease safeguards + run: yarn test:release - name: Install Playwright Browsers run: yarn playwright install --with-deps working-directory: ./packages/browser-sdk diff --git a/package.json b/package.json index f322f1b86..62228fc2e 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,8 @@ "build": "lerna run build --stream", "test:ci": "lerna run test:ci --stream", "test": "lerna run test --stream", + "test:release": "node --test scripts/node-sdk-prerelease.test.mjs", + "prerelease:node": "node scripts/node-sdk-prerelease.mjs", "format": "yarn fmt:fix && yarn lint:fix", "lint": "yarn oxlint .", "lint:ci": "yarn oxlint .", @@ -42,7 +44,8 @@ "typedoc-plugin-frontmatter": "^1.1.2", "typedoc-plugin-markdown": "^4.4.2", "typedoc-plugin-mdn-links": "^4.0.7", - "typescript": "^5.7.3" + "typescript": "^5.7.3", + "yaml": "^2.8.3" }, "resolutions": { "minimatch@npm:9.0.1": "npm:9.0.9", diff --git a/scripts/fixtures/node-sdk-prerelease/registered.cts b/scripts/fixtures/node-sdk-prerelease/registered.cts new file mode 100644 index 000000000..4196d1224 --- /dev/null +++ b/scripts/fixtures/node-sdk-prerelease/registered.cts @@ -0,0 +1,43 @@ +import { ReflagClient, type FlagValue } from "@reflag/node-sdk"; + +interface Settings { + model: string; + limits: { maxItems: number }; +} +declare module "@reflag/node-sdk" { + interface Flags { + settings: Settings; + model: "quick" | "quality"; + list: number[]; + arbitrary: FlagValue; + } +} +const client = new ReflagClient({ offline: true }); +const defaults: Settings = { model: "quick", limits: { maxItems: 10 } }; +const value: Settings = client.getFlag({}, "settings", defaults); +const mutable = client.bindClient({}).getFlag("settings", { + model: "quick", + limits: { maxItems: 10 }, +} as const); +mutable.limits.maxItems = 11; +const enabled: boolean = client.getFlag({}, "settings"); +const arbitrary: FlagValue = client.getFlag({}, "settings", null); +const model: string = client.getFlag({}, "model", "quick"); +client.getFlag({}, "arbitrary", { anyShape: [false, null, 0] }); +// @ts-expect-error unknown registered key +client.getFlag({}, "unknown"); +// @ts-expect-error missing required property +client.getFlag({}, "settings", { model: "quick" }); +// @ts-expect-error incompatible nested property +client.getFlag({}, "settings", { model: "quick", limits: { maxItems: "ten" } }); +// @ts-expect-error registered category mismatch +client.getFlag({}, "settings", 0); +// @ts-expect-error unknown registered literal +client.getFlag({}, "model", "unknown"); +// @ts-expect-error wrong array element +client.bindClient({}).getFlag("list", ["bad"]); +// @ts-expect-error remote defaults obey the same registered schema +client.getFlagRemote("settings", { model: "quick" }); +// @ts-expect-error direct values have no legacy config wrapper +void value.config.payload; +void [value, mutable, enabled, arbitrary, model]; diff --git a/scripts/fixtures/node-sdk-prerelease/runtime.cjs b/scripts/fixtures/node-sdk-prerelease/runtime.cjs new file mode 100644 index 000000000..d73b88cdb --- /dev/null +++ b/scripts/fixtures/node-sdk-prerelease/runtime.cjs @@ -0,0 +1,146 @@ +const assert = require("node:assert/strict"); +const { createServer } = require("node:http"); +const { createRequire } = require("node:module"); +const { ReflagClient } = require("@reflag/node-sdk"); + +const version = process.argv[2]; +const sdkRequire = createRequire(require.resolve("@reflag/node-sdk")); +assert.equal(require("@reflag/node-sdk/package.json").version, version); +assert.equal( + sdkRequire("@reflag/flag-evaluation/package.json").version, + "2.0.0", +); +for (const key of Object.keys(process.env)) + if (key.startsWith("REFLAG_")) delete process.env[key]; + +function flag(key, value) { + return { + key, + sourceVersionId: `version:${key}`, + variants: { selected: value }, + rules: [ + { + id: `rule:${key}`, + filter: { type: "constant", value: true }, + result: { type: "variant", variantKey: "selected" }, + }, + ], + }; +} +const events = []; +const requests = []; +const noop = () => undefined; +const server = createServer(async (request, response) => { + try { + requests.push({ + path: request.url, + version: request.headers["reflag-sdk-version"], + }); + response.setHeader("content-type", "application/json"); + if (request.url === "/flags") { + response.end( + JSON.stringify({ + success: true, + protocolVersion: 2, + flagStateVersion: 42, + segments: [], + flags: [ + flag("enabled", true), + flag("settings", { model: "quality", limits: { maxItems: 0 } }), + flag("false", false), + flag("zero", 0), + flag("empty", ""), + flag("nullable", null), + ], + }), + ); + } else if (request.url === "/bulk") { + let body = ""; + for await (const chunk of request) body += chunk; + events.push(...JSON.parse(body)); + response.end(JSON.stringify({ success: true })); + } else { + response.statusCode = 404; + response.end(JSON.stringify({ success: false })); + } + } catch (error) { + response.statusCode = 500; + response.end(JSON.stringify({ success: false })); + console.error(error); + } +}); + +(async () => { + await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve)); + const client = new ReflagClient({ + secretKey: "prereleaseFixtureSecretMoreThan22Chars", + apiBaseUrl: `http://127.0.0.1:${server.address().port}/`, + offline: false, + flagsSyncMode: "in-request", + flagsFetchRetries: 0, + batchOptions: { flushOnExit: false, intervalMs: 1000000 }, + logger: { debug: noop, info: noop, warn: noop, error: noop }, + }); + try { + await client.initialize(); + assert.equal(client.getFlag({}, "enabled"), true); + const settings = client.getFlag({}, "settings", { + model: "quick", + limits: { maxItems: 10 }, + }); + assert.deepEqual(settings, { model: "quality", limits: { maxItems: 0 } }); + settings.limits.maxItems = 99; + assert.equal( + client.getFlag({}, "settings", { + model: "quick", + limits: { maxItems: 10 }, + }).limits.maxItems, + 0, + ); + assert.equal(client.getFlag({}, "settings"), false); + assert.equal(client.getFlag({}, "false", true), false); + assert.equal(client.getFlag({}, "zero", 99), 0); + assert.equal(client.getFlag({}, "empty", "fallback"), ""); + assert.equal(client.getFlag({}, "nullable", null), null); + assert.equal(client.getFlag({}, "missing"), false); + await client.flush(); + const checksBeforeBootstrap = events.length; + assert.equal(client.getFlagsForBootstrap({}).protocolVersion, 2); + await client.flush(); + assert.equal(events.length, checksBeforeBootstrap); + assert.ok( + requests.some( + (request) => + request.path === "/flags" && + request.version === `node-sdk/${version}`, + ), + ); + assert.ok( + events.some( + (event) => + event.action === "check" && + event.key === "enabled" && + event.sourceVersionId === "version:enabled" && + event.evalResult === "selected", + ), + ); + assert.ok( + events.some( + (event) => + event.action === "check" && + event.key === "missing" && + !Object.hasOwn(event, "evalResult"), + ), + ); + console.log( + `Installed ${version}: direct values, defaults, copies, v2 transport, root checks and version header passed`, + ); + } finally { + client.destroy(); + server.closeAllConnections(); + await new Promise((resolve) => server.close(resolve)); + } +})().catch((error) => { + console.error(error); + process.exitCode = 1; +}); diff --git a/scripts/fixtures/node-sdk-prerelease/unregistered.cts b/scripts/fixtures/node-sdk-prerelease/unregistered.cts new file mode 100644 index 000000000..1b2ccfece --- /dev/null +++ b/scripts/fixtures/node-sdk-prerelease/unregistered.cts @@ -0,0 +1,41 @@ +import { ReflagClient, type FlagValue } from "@reflag/node-sdk"; + +interface Settings { + model: string; + limits: { maxItems: number }; +} +const defaults: Settings = { model: "quick", limits: { maxItems: 10 } }; +const readonlyDefaults = { model: "quick", limits: { maxItems: 10 } } as const; +const client = new ReflagClient({ offline: true }); +const value: Settings = client.getFlag({}, "settings", defaults); +const mutable = client.bindClient({}).getFlag("settings", readonlyDefaults); +mutable.model = "quality"; +mutable.limits.maxItems = 20; +const enabled: boolean = client.getFlag({}, "settings"); +const explicitUndefined: boolean = client.getFlag({}, "settings", undefined); +const arbitrary: FlagValue = client.getFlag({}, "settings", null); +const remote: Promise = client.getFlagRemote("settings", defaults); +const count: number = client.getFlag({}, "count", 0); +const label: string = client.getFlag({}, "label", ""); +const list: string[] = client.getFlag({}, "list", ["fallback"]); +type IsAny = 0 extends 1 & T ? true : false; +const notAny: IsAny = false; +// @ts-expect-error singular reads do not return wrappers +void value.isEnabled; +// @ts-expect-error Boolean-first bare reads do not infer object payloads +const missingDefault: Settings = client.getFlag({}, "settings"); +// @ts-expect-error widening must not preserve readonly primitive literals +const literal: "quick" = mutable.model; +void [ + value, + enabled, + explicitUndefined, + arbitrary, + remote, + count, + label, + list, + notAny, + missingDefault, + literal, +]; diff --git a/scripts/node-sdk-prerelease.mjs b/scripts/node-sdk-prerelease.mjs new file mode 100644 index 000000000..49959ce29 --- /dev/null +++ b/scripts/node-sdk-prerelease.mjs @@ -0,0 +1,446 @@ +import assert from "node:assert/strict"; +import { execFileSync } from "node:child_process"; +import { createHash } from "node:crypto"; +import { + appendFileSync, + existsSync, + mkdirSync, + mkdtempSync, + readFileSync, + realpathSync, + rmSync, + writeFileSync, +} from "node:fs"; +import { tmpdir } from "node:os"; +import { dirname, isAbsolute, join, relative, resolve } from "node:path"; +import { fileURLToPath, pathToFileURL } from "node:url"; + +export const PACKAGE = "@reflag/node-sdk"; +export const TAG = "next"; +export const EVALUATOR_VERSION = "2.0.0"; +const registry = "https://registry.npmjs.org"; +const toolsRoot = resolve(dirname(fileURLToPath(import.meta.url)), ".."); + +export function validateInputs(version, sha) { + assert.match( + version ?? "", + /^2\.0\.0-next\.(0|[1-9]\d*)$/, + "Expected 2.0.0-next.N", + ); + assert.match( + sha ?? "", + /^[a-f0-9]{40}$/, + "An exact lowercase commit SHA is required", + ); +} + +export function assertSuccessfulChecks(pages, sha) { + const checks = pages.flatMap((page) => page.check_runs ?? []); + const builds = checks.filter( + (check) => + check.name === "Build & Test" && check.app?.slug === "github-actions", + ); + assert.ok(builds.length, "No Package CI Build & Test check found"); + assert.ok( + builds.every( + (check) => + check.head_sha === sha && + check.status === "completed" && + check.conclusion === "success", + ), + "All Build & Test checks on the exact source commit must pass first", + ); +} + +export function assertPublicationEnvironment(environment) { + assert.equal(environment.name, "npm-node-prerelease"); + assert.ok( + environment.protection_rules?.some( + (rule) => + rule.type === "required_reviewers" && rule.reviewers?.length > 0, + ), + "Configure required reviewers on npm-node-prerelease before publishing", + ); +} + +export function validateManifest(manifest, version, packed = false) { + assert.equal(manifest.name, PACKAGE); + assert.equal(manifest.version, version); + assert.notEqual(manifest.private, true); + assert.equal( + manifest.repository?.url, + "https://github.com/reflagcom/javascript.git", + ); + assert.equal(manifest.publishConfig?.access, "public"); + assert.ok( + !manifest.publishConfig?.tag || manifest.publishConfig.tag === TAG, + "Unsafe publishConfig.tag", + ); + assert.ok( + !manifest.publishConfig?.registry || + manifest.publishConfig.registry === registry, + "Unexpected registry", + ); + assert.equal( + manifest.dependencies?.["@reflag/flag-evaluation"], + packed ? EVALUATOR_VERSION : "workspace:*", + "The prerelease must use the already-published evaluator 2.0.0", + ); + if (packed) { + for (const field of [ + "dependencies", + "optionalDependencies", + "peerDependencies", + ]) { + for (const specification of Object.values(manifest[field] ?? {})) { + assert.ok( + !/^(workspace:|file:|link:|portal:)/.test(specification), + "Unresolved local dependency in tarball", + ); + } + } + } +} + +export function validateRegistry(metadata, version, baseline, integrity) { + const latest = metadata["dist-tags"]?.latest; + assert.match( + latest ?? "", + /^1\.\d+\.\d+$/, + "latest must remain on stable v1", + ); + if (baseline !== undefined) + assert.equal( + latest, + baseline, + "latest changed; stop and inspect before continuing", + ); + if (integrity === undefined) { + assert.ok( + !Object.hasOwn(metadata.versions ?? {}, version), + `${version} is already published; do not overwrite or retag it`, + ); + } else { + assert.equal( + metadata["dist-tags"]?.[TAG], + version, + "next does not point to the published candidate", + ); + assert.equal( + metadata.versions?.[version]?.dist?.integrity, + integrity, + "Registry artifact differs from the verified tarball", + ); + } + return latest; +} + +function run(command, args, cwd, capture = false) { + return execFileSync(command, args, { + cwd, + encoding: "utf8", + stdio: ["ignore", capture ? "pipe" : "inherit", "inherit"], + maxBuffer: 16 * 1024 * 1024, + }); +} + +export function inspectTarball(tarball, version) { + const entries = run("tar", ["-tzf", tarball], undefined, true) + .trim() + .split("\n"); + assert.equal( + new Set(entries).size, + entries.length, + "Duplicate archive entries", + ); + for (const entry of entries) { + assert.ok( + !isAbsolute(entry) && !entry.split("/").includes(".."), + "Unsafe archive path", + ); + assert.match(entry, /^[A-Za-z0-9_./@,+-]+$/, "Unexpected archive filename"); + assert.ok( + entry === "package/" || + entry.startsWith("package/dist/") || + /^package\/(package\.json|README\.md|CHANGELOG\.md|LICEN[CS]E(?:\.(?:md|txt))?)$/.test( + entry, + ), + `Unexpected published file: ${entry}`, + ); + } + const listing = run("tar", ["-tvzf", tarball], undefined, true) + .trim() + .split("\n"); + assert.ok( + listing.every((entry) => /^[d-]/.test(entry)), + "Links and special archive entries are not allowed", + ); + const manifest = JSON.parse( + run("tar", ["-xOzf", tarball, "package/package.json"], undefined, true), + ); + validateManifest(manifest, version, true); + for (const path of [manifest.main, manifest.types, "./dist/package.json"]) { + assert.ok( + typeof path === "string" && path.startsWith("./dist/"), + "Missing compiled package entry point", + ); + assert.ok( + entries.includes(`package/${path.slice(2)}`), + `Missing packed entry point: ${path}`, + ); + } + const compiledManifest = JSON.parse( + run( + "tar", + ["-xOzf", tarball, "package/dist/package.json"], + undefined, + true, + ), + ); + assert.equal( + compiledManifest.version, + version, + "Compiled SDK version header would be stale", + ); + const bytes = readFileSync(tarball); + return { + sha256: createHash("sha256").update(bytes).digest("hex"), + integrity: `sha512-${createHash("sha512").update(bytes).digest("base64")}`, + }; +} + +async function registryMetadata() { + const response = await fetch(`${registry}/@reflag%2fnode-sdk`, { + headers: { "cache-control": "no-cache" }, + signal: AbortSignal.timeout(30000), + }); + assert.equal( + response.status, + 200, + "Cannot verify registry state; refusing to continue", + ); + return response.json(); +} + +function checkConsumer(tarball, version) { + const consumer = mkdtempSync( + join(tmpdir(), "reflag-node-prerelease-consumer-"), + ); + try { + writeFileSync( + join(consumer, "package.json"), + JSON.stringify({ + private: true, + dependencies: { [PACKAGE]: pathToFileURL(tarball).href }, + devDependencies: { typescript: "5.7.3", "@types/node": "22.12.0" }, + }), + ); + run( + "npm", + [ + "install", + "--ignore-scripts", + "--no-audit", + "--no-fund", + "--package-lock=false", + "--registry", + registry, + ], + consumer, + ); + const fixtures = join(toolsRoot, "scripts/fixtures/node-sdk-prerelease"); + for (const name of ["unregistered.cts", "registered.cts"]) { + writeFileSync(join(consumer, name), readFileSync(join(fixtures, name))); + run( + process.execPath, + [ + join(consumer, "node_modules/typescript/bin/tsc"), + "--noEmit", + "--strict", + "--module", + "NodeNext", + "--moduleResolution", + "NodeNext", + "--target", + "ES2022", + name, + ], + consumer, + ); + } + writeFileSync( + join(consumer, "runtime.cjs"), + readFileSync(join(fixtures, "runtime.cjs")), + ); + run(process.execPath, ["runtime.cjs", version], consumer); + } finally { + rmSync(consumer, { recursive: true, force: true }); + } +} + +export async function prepare({ source, output, version, sha }) { + validateInputs(version, sha); + source = realpathSync(source); + output = resolve(output); + assert.equal( + run("git", ["rev-parse", "HEAD"], source, true).trim(), + sha, + "Source checkout is not the requested commit", + ); + assert.equal( + run("git", ["status", "--porcelain"], source, true).trim(), + "", + "Source checkout must be clean", + ); + const sdk = join(source, "packages/node-sdk"); + validateManifest( + JSON.parse(readFileSync(join(sdk, "package.json"))), + version, + ); + assert.equal( + JSON.parse( + readFileSync(join(source, "packages/flag-evaluation/package.json")), + ).version, + EVALUATOR_VERSION, + ); + assert.ok( + relative(source, output).startsWith( + `..${process.platform === "win32" ? "\\" : "/"}`, + ) || isAbsolute(relative(source, output)), + "Write artifacts outside the source checkout", + ); + assert.ok( + !existsSync(output), + "Output directory already exists; refusing to overwrite an artifact", + ); + const latest = validateRegistry(await registryMetadata(), version); + mkdirSync(output, { recursive: false }); + run("yarn", ["install", "--immutable"], source); + // tsc does not remove obsolete output. Never pack leftovers from an older build. + rmSync(join(source, "packages/flag-evaluation/dist"), { + recursive: true, + force: true, + }); + rmSync(join(sdk, "dist"), { recursive: true, force: true }); + run("yarn", ["workspace", "@reflag/flag-evaluation", "build"], source); + run("yarn", ["workspace", PACKAGE, "test"], source); + run("yarn", ["workspace", PACKAGE, "build"], source); + const tarball = join(output, `reflag-node-sdk-${version}.tgz`); + run("yarn", ["workspace", PACKAGE, "pack", "--out", tarball], source); + const hashes = inspectTarball(tarball, version); + checkConsumer(tarball, version); + assert.equal( + run("git", ["status", "--porcelain"], source, true).trim(), + "", + "Preparation changed the source checkout", + ); + const candidate = { + name: PACKAGE, + version, + tag: TAG, + sourceSha: sha, + evaluatorVersion: EVALUATOR_VERSION, + latestBefore: latest, + ...hashes, + }; + writeFileSync( + join(output, "candidate.json"), + `${JSON.stringify(candidate, null, 2)}\n`, + ); + if (process.env.GITHUB_OUTPUT) + appendFileSync(process.env.GITHUB_OUTPUT, `sha256=${hashes.sha256}\n`); + if (process.env.GITHUB_STEP_SUMMARY) + appendFileSync( + process.env.GITHUB_STEP_SUMMARY, + `### Verified Node prerelease (not published)\n\n- Package: \`${PACKAGE}@${version}\`\n- Tag: \`${TAG}\` (latest remains \`${latest}\`)\n- Source: \`${sha}\`\n- Tarball SHA-256: \`${hashes.sha256}\`\n\nClean installed-package runtime and both strict TypeScript consumers passed.\n`, + ); + return candidate; +} + +export async function verify({ + output, + version, + sha, + sha256, + published = false, +}) { + validateInputs(version, sha); + assert.match( + sha256 ?? "", + /^[a-f0-9]{64}$/, + "Expected the preparation job's SHA-256", + ); + const candidate = JSON.parse(readFileSync(join(output, "candidate.json"))); + assert.equal(candidate.name, PACKAGE); + assert.equal(candidate.version, version); + assert.equal(candidate.tag, TAG); + assert.equal(candidate.sourceSha, sha); + assert.equal(candidate.evaluatorVersion, EVALUATOR_VERSION); + assert.equal(candidate.sha256, sha256); + const hashes = inspectTarball( + join(output, `reflag-node-sdk-${version}.tgz`), + version, + ); + assert.equal(hashes.sha256, sha256, "Artifact changed after verification"); + assert.equal(hashes.integrity, candidate.integrity); + validateRegistry( + await registryMetadata(), + version, + candidate.latestBefore, + published ? candidate.integrity : undefined, + ); + return candidate; +} + +async function main() { + const [command, ...args] = process.argv.slice(2); + const options = {}; + for (let i = 0; i < args.length; i++) { + const key = args[i]; + assert.ok( + [ + "--source", + "--output", + "--version", + "--sha", + "--sha256", + "--checks", + "--environment", + "--published", + ].includes(key), + `Unknown option: ${key}`, + ); + assert.ok( + !Object.hasOwn(options, key.slice(2)), + `Duplicate option: ${key}`, + ); + options[key.slice(2)] = key === "--published" ? true : args[++i]; + } + if (command === "validate") validateInputs(options.version, options.sha); + else if (command === "ci") { + validateInputs(options.version, options.sha); + assertSuccessfulChecks( + JSON.parse(readFileSync(options.checks)), + options.sha, + ); + } else if (command === "environment") + assertPublicationEnvironment(JSON.parse(readFileSync(options.environment))); + else if (command === "prepare") + console.log(JSON.stringify(await prepare(options), null, 2)); + else if (command === "verify") + console.log(JSON.stringify(await verify(options), null, 2)); + else + throw new Error( + "Use validate, ci, environment, prepare or verify. Publication is only in the manually approved workflow.", + ); +} + +if ( + process.argv[1] && + resolve(process.argv[1]) === fileURLToPath(import.meta.url) +) { + main().catch((error) => { + console.error(error); + process.exitCode = 1; + }); +} diff --git a/scripts/node-sdk-prerelease.test.mjs b/scripts/node-sdk-prerelease.test.mjs new file mode 100644 index 000000000..0e2f5dc52 --- /dev/null +++ b/scripts/node-sdk-prerelease.test.mjs @@ -0,0 +1,410 @@ +import assert from "node:assert/strict"; +import { execFileSync } from "node:child_process"; +import { + mkdirSync, + mkdtempSync, + readFileSync, + rmSync, + symlinkSync, + writeFileSync, +} from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { test } from "node:test"; + +import { parse } from "yaml"; + +import { + assertSuccessfulChecks, + assertPublicationEnvironment, + inspectTarball, + prepare, + verify, + validateInputs, + validateManifest, + validateRegistry, +} from "./node-sdk-prerelease.mjs"; + +const version = "2.0.0-next.0"; +const sha = "0809be2b95f43fa1785c6b7b188c03ac8fd40965"; +const manifest = { + name: "@reflag/node-sdk", + version, + repository: { url: "https://github.com/reflagcom/javascript.git" }, + publishConfig: { access: "public" }, + main: "./dist/src/index.js", + types: "./dist/types/src/index.d.ts", + dependencies: { "@reflag/flag-evaluation": "2.0.0" }, +}; + +function tarballFixture(fn) { + const root = mkdtempSync(join(tmpdir(), "reflag-prerelease-test-")); + const directory = join(root, "package"); + mkdirSync(join(directory, "dist/src"), { recursive: true }); + mkdirSync(join(directory, "dist/types/src"), { recursive: true }); + writeFileSync(join(directory, "package.json"), JSON.stringify(manifest)); + writeFileSync(join(directory, "dist/package.json"), JSON.stringify(manifest)); + writeFileSync(join(directory, "dist/src/index.js"), "module.exports = {};\n"); + writeFileSync(join(directory, "dist/types/src/index.d.ts"), "export {};\n"); + writeFileSync(join(directory, "README.md"), "Test fixture\n"); + const archive = join(root, "candidate.tgz"); + const pack = () => + execFileSync("tar", ["-czf", archive, "-C", root, "package"]); + try { + fn({ directory, archive, pack }); + } finally { + rmSync(root, { recursive: true, force: true }); + } +} + +test("only explicit next versions and immutable commit SHAs are accepted", () => { + validateInputs(version, sha); + validateInputs("2.0.0-next.12", sha); + for (const invalid of [ + "2.0.0", + "2.0.0-rc.0", + "1.8.3", + "3.0.0-next.0", + "2.0.0-next.01", + "2.0.0-next.0\n", + "next", + undefined, + ]) { + assert.throws(() => validateInputs(invalid, sha)); + } + for (const invalid of [ + "main", + "feature/node-sdk-v2", + sha.slice(0, 7), + sha.toUpperCase(), + `${sha};echo bad`, + undefined, + ]) { + assert.throws(() => validateInputs(version, invalid)); + } +}); + +test("requires successful GitHub Actions Build & Test checks for the exact SHA", () => { + const check = { + name: "Build & Test", + app: { slug: "github-actions" }, + head_sha: sha, + status: "completed", + conclusion: "success", + }; + assertSuccessfulChecks( + [{ check_runs: [check] }, { check_runs: [check] }], + sha, + ); + for (const checks of [ + [], + [{ ...check, app: { slug: "other-app" } }], + [{ ...check, head_sha: "a".repeat(40) }], + [{ ...check, status: "in_progress", conclusion: null }], + [check, { ...check, conclusion: "failure" }], + [{ ...check, conclusion: "skipped" }], + ]) { + assert.throws(() => assertSuccessfulChecks([{ check_runs: checks }], sha)); + } +}); + +test("publishing requires an existing environment with required reviewers", () => { + const environment = { + name: "npm-node-prerelease", + protection_rules: [ + { type: "required_reviewers", reviewers: [{ type: "User", id: 123 }] }, + ], + }; + assertPublicationEnvironment(environment); + for (const invalid of [ + { ...environment, name: "copilot" }, + { name: environment.name }, + { ...environment, protection_rules: [] }, + { + ...environment, + protection_rules: [{ type: "wait_timer", wait_timer: 10 }], + }, + { + ...environment, + protection_rules: [{ type: "required_reviewers", reviewers: [] }], + }, + ]) { + assert.throws(() => assertPublicationEnvironment(invalid)); + } +}); + +test("only the Node prerelease with the published evaluator is packable", () => { + validateManifest(manifest, version, true); + validateManifest( + { ...manifest, dependencies: { "@reflag/flag-evaluation": "workspace:*" } }, + version, + ); + const invalid = [ + { name: "@reflag/browser-sdk" }, + { version: "2.0.0" }, + { private: true }, + { repository: { url: "https://github.com/another/repository.git" } }, + { publishConfig: { access: "public", tag: "latest" } }, + { publishConfig: { access: "public", registry: "https://example.test" } }, + { dependencies: { "@reflag/flag-evaluation": "2.0.0-next.0" } }, + { dependencies: { "@reflag/flag-evaluation": "workspace:*" } }, + { optionalDependencies: { local: "file:../something" } }, + { peerDependencies: { local: "link:../something" } }, + ]; + for (const value of invalid) + assert.throws(() => + validateManifest({ ...manifest, ...value }, version, true), + ); +}); + +test("registry preflight refuses existing versions and any stable-tag drift", () => { + const metadata = { "dist-tags": { latest: "1.8.3" }, versions: {} }; + assert.equal(validateRegistry(metadata, version), "1.8.3"); + assert.throws(() => + validateRegistry({ ...metadata, versions: { [version]: {} } }, version), + ); + assert.throws(() => validateRegistry(metadata, version, "1.8.2")); + assert.throws(() => + validateRegistry( + { ...metadata, "dist-tags": { latest: version } }, + version, + ), + ); + assert.throws(() => + validateRegistry({ ...metadata, "dist-tags": {} }, version), + ); +}); + +test("postpublication verifies next and the exact tarball, without repairing tags", () => { + const metadata = { + "dist-tags": { latest: "1.8.3", next: version }, + versions: { [version]: { dist: { integrity: "sha512-fixture" } } }, + }; + validateRegistry(metadata, version, "1.8.3", "sha512-fixture"); + assert.throws(() => + validateRegistry(metadata, version, "1.8.3", "sha512-other"), + ); + assert.throws(() => + validateRegistry( + { ...metadata, "dist-tags": { latest: "1.8.3", next: "2.0.0-next.1" } }, + version, + "1.8.3", + "sha512-fixture", + ), + ); +}); + +test("tarball inspection checks entry points, build-time version and content hashes", () => { + tarballFixture(({ directory, archive, pack }) => { + pack(); + const first = inspectTarball(archive, version); + assert.match(first.sha256, /^[a-f0-9]{64}$/); + assert.match(first.integrity, /^sha512-/); + assert.deepEqual(inspectTarball(archive, version), first); + writeFileSync( + join(directory, "dist/src/index.js"), + "module.exports = { changed: true };\n", + ); + pack(); + assert.notEqual(inspectTarball(archive, version).sha256, first.sha256); + writeFileSync( + join(directory, "dist/package.json"), + JSON.stringify({ ...manifest, version: "2.0.0-next.1" }), + ); + pack(); + assert.throws( + () => inspectTarball(archive, version), + /version header would be stale/, + ); + }); +}); + +test("tarball inspection rejects source/demo files, links and missing declarations", () => { + tarballFixture(({ directory, archive, pack }) => { + writeFileSync(join(directory, ".env"), "test fixture, not a credential\n"); + pack(); + assert.throws( + () => inspectTarball(archive, version), + /Unexpected published file/, + ); + rmSync(join(directory, ".env")); + symlinkSync("package.json", join(directory, "dist/link")); + pack(); + assert.throws(() => inspectTarball(archive, version), /Links and special/); + rmSync(join(directory, "dist/link")); + rmSync(join(directory, "dist/types/src/index.d.ts")); + pack(); + assert.throws( + () => inspectTarball(archive, version), + /Missing packed entry point/, + ); + }); +}); + +test("preparation refuses dirty, moving or already-used checkouts before any build or registry request", async () => { + const root = mkdtempSync(join(tmpdir(), "reflag-prerelease-source-test-")); + const source = join(root, "source"); + const output = join(root, "artifact"); + mkdirSync(join(source, "packages/node-sdk"), { recursive: true }); + mkdirSync(join(source, "packages/flag-evaluation"), { recursive: true }); + writeFileSync( + join(source, "packages/node-sdk/package.json"), + JSON.stringify({ + ...manifest, + dependencies: { "@reflag/flag-evaluation": "workspace:*" }, + }), + ); + writeFileSync( + join(source, "packages/flag-evaluation/package.json"), + JSON.stringify({ version: "2.0.0" }), + ); + const git = (...args) => + execFileSync("git", args, { + cwd: source, + encoding: "utf8", + stdio: ["ignore", "pipe", "pipe"], + }); + try { + git("init", "--quiet"); + git( + "-c", + "user.name=Fixture", + "-c", + "user.email=fixture@example.test", + "add", + ".", + ); + git( + "-c", + "user.name=Fixture", + "-c", + "user.email=fixture@example.test", + "-c", + "core.hooksPath=/dev/null", + "commit", + "--quiet", + "-m", + "fixture", + ); + const sourceSha = git("rev-parse", "HEAD").trim(); + await assert.rejects( + prepare({ source, output, version, sha: "f".repeat(40) }), + /not the requested commit/, + ); + writeFileSync(join(source, "untracked.txt"), "not part of the release\n"); + await assert.rejects( + prepare({ source, output, version, sha: sourceSha }), + /checkout must be clean/, + ); + rmSync(join(source, "untracked.txt")); + mkdirSync(output); + await assert.rejects( + prepare({ source, output, version, sha: sourceSha }), + /already exists/, + ); + await assert.rejects( + prepare({ + source, + output: join(source, "artifact"), + version, + sha: sourceSha, + }), + /outside the source checkout/, + ); + } finally { + rmSync(root, { recursive: true, force: true }); + } +}); + +test("artifact verification rejects a substituted digest or source identity before registry access", async () => { + const root = mkdtempSync(join(tmpdir(), "reflag-prerelease-verify-test-")); + const digest = "a".repeat(64); + writeFileSync( + join(root, "candidate.json"), + JSON.stringify({ + name: manifest.name, + version, + tag: "next", + sourceSha: sha, + evaluatorVersion: "2.0.0", + sha256: digest, + }), + ); + try { + await assert.rejects( + verify({ output: root, version, sha, sha256: "b".repeat(64) }), + ); + await assert.rejects( + verify({ output: root, version, sha: "f".repeat(40), sha256: digest }), + ); + await assert.rejects( + verify({ output: root, version, sha, sha256: "" }), + /SHA-256/, + ); + } finally { + rmSync(root, { recursive: true, force: true }); + } +}); + +test("workflow is manually dispatched, defaults to artifact-only and fixes the npm tag", () => { + const workflow = parse( + readFileSync( + new URL("../.github/workflows/node-sdk-prerelease.yml", import.meta.url), + "utf8", + ), + ); + assert.deepEqual(Object.keys(workflow.on), ["workflow_dispatch"]); + assert.equal(workflow.on.workflow_dispatch.inputs.publish.default, false); + assert.equal(workflow.on.workflow_dispatch.inputs.version.default, version); + assert.deepEqual(workflow.permissions, { contents: "read" }); + assert.equal(workflow.concurrency["cancel-in-progress"], false); + const prepareJob = workflow.jobs.prepare; + const publish = workflow.jobs.publish; + assert.equal(prepareJob.permissions["id-token"], undefined); + assert.ok( + prepareJob.steps.some( + (step) => + step.if === "${{ inputs.publish }}" && + step.run?.includes("prerelease.mjs environment"), + ), + ); + assert.equal(publish.permissions["id-token"], "write"); + assert.match( + publish.if, + /inputs\.publish.*github\.ref == 'refs\/heads\/main'/, + ); + assert.equal(publish.needs, "prepare"); + assert.equal(publish.environment, "npm-node-prerelease"); + const commands = publish.steps.map((step) => step.run ?? "").join("\n"); + assert.match( + commands, + /--tag next --access public --provenance --ignore-scripts --registry https:\/\/registry\.npmjs\.org/, + ); + assert.match(commands, /verify --published/); + assert.doesNotMatch( + commands, + /changeset|dist-tag (?:add|rm)|yarn (?:build|install)|npm (?:run|install)/, + ); + const checkouts = publish.steps.filter((step) => + step.uses?.startsWith("actions/checkout@"), + ); + assert.equal(checkouts.length, 1); + assert.equal(checkouts[0].with.ref, "${{ github.sha }}"); + assert.equal(checkouts[0].with["persist-credentials"], false); + assert.ok( + publish.steps.some( + (step) => step.env?.SHA256 === "${{ needs.prepare.outputs.sha256 }}", + ), + ); + const packageCI = parse( + readFileSync( + new URL("../.github/workflows/package-ci.yml", import.meta.url), + "utf8", + ), + ); + assert.ok( + packageCI.jobs["build-and-test"].steps.some( + (step) => step.run === "yarn test:release", + ), + ); +}); diff --git a/yarn.lock b/yarn.lock index ae9636c4b..69b51fb1e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -20506,6 +20506,7 @@ __metadata: typedoc-plugin-markdown: "npm:^4.4.2" typedoc-plugin-mdn-links: "npm:^4.0.7" typescript: "npm:^5.7.3" + yaml: "npm:^2.8.3" languageName: unknown linkType: soft @@ -20764,6 +20765,15 @@ __metadata: languageName: node linkType: hard +"yaml@npm:^2.8.3": + version: 2.9.1 + resolution: "yaml@npm:2.9.1" + bin: + yaml: bin.mjs + checksum: 10c0/9d06676ef02b89559a8b10a71882bd2cdae81e8393dc8dbc871615c3259475d9609ad973d19cb3c9e71e72d6206e3d1e7aa241c7e55f3d16fd2e77db305827d6 + languageName: node + linkType: hard + "yargs-parser@npm:21.1.1, yargs-parser@npm:^21.1.1": version: 21.1.1 resolution: "yargs-parser@npm:21.1.1" From b6f02cc5da8e8435d06ac4d06e952d2a85d901bd Mon Sep 17 00:00:00 2001 From: Ron Cohen Date: Sat, 14 Nov 2026 21:07:36 +0000 Subject: [PATCH 2/2] fix: disable prerelease caches and require green security checks --- .github/workflows/node-sdk-prerelease.yml | 5 +- scripts/node-sdk-prerelease.mjs | 32 +++++++++++ scripts/node-sdk-prerelease.test.mjs | 69 ++++++++++++++++++++++- 3 files changed, 101 insertions(+), 5 deletions(-) diff --git a/.github/workflows/node-sdk-prerelease.yml b/.github/workflows/node-sdk-prerelease.yml index ee2e5caf0..71265a338 100644 --- a/.github/workflows/node-sdk-prerelease.yml +++ b/.github/workflows/node-sdk-prerelease.yml @@ -74,8 +74,8 @@ jobs: - uses: actions/setup-node@v6 with: node-version-file: release-tools/.nvmrc - cache: yarn - cache-dependency-path: candidate/yarn.lock + # Never save candidate-controlled dependencies into main's cache scope. + package-manager-cache: false - name: Build, test and verify the actual packed package id: prepare env: @@ -112,6 +112,7 @@ jobs: - uses: actions/setup-node@v6 with: node-version-file: .nvmrc + package-manager-cache: false registry-url: https://registry.npmjs.org scope: "@reflag" - uses: actions/download-artifact@v4 diff --git a/scripts/node-sdk-prerelease.mjs b/scripts/node-sdk-prerelease.mjs index 49959ce29..a440710af 100644 --- a/scripts/node-sdk-prerelease.mjs +++ b/scripts/node-sdk-prerelease.mjs @@ -41,6 +41,38 @@ export function assertSuccessfulChecks(pages, sha) { check.name === "Build & Test" && check.app?.slug === "github-actions", ); assert.ok(builds.length, "No Package CI Build & Test check found"); + for (const [name, app] of [ + ["CodeQL", "github-advanced-security"], + ["Oneleet Code Security Scan", "oneleet-code"], + ]) { + assert.ok( + checks.some( + (check) => + check.name === name && + check.app?.slug === app && + check.conclusion === "success", + ), + `Missing successful ${name} security check`, + ); + } + // Copilot's reviewer-agent execution is not a validation check or an approval. + // Its operational failure is omitted by GitHub's PR check rollup as well. + const validationChecks = checks.filter( + (check) => + !( + check.name === "copilot-pull-request-reviewer" && + check.app?.slug === "github-actions" + ), + ); + assert.ok( + validationChecks.every( + (check) => + check.head_sha === sha && + check.status === "completed" && + ["success", "neutral", "skipped"].includes(check.conclusion), + ), + "Every reported CI/security check must finish without failure", + ); assert.ok( builds.every( (check) => diff --git a/scripts/node-sdk-prerelease.test.mjs b/scripts/node-sdk-prerelease.test.mjs index 0e2f5dc52..ace8d8116 100644 --- a/scripts/node-sdk-prerelease.test.mjs +++ b/scripts/node-sdk-prerelease.test.mjs @@ -84,7 +84,7 @@ test("only explicit next versions and immutable commit SHAs are accepted", () => } }); -test("requires successful GitHub Actions Build & Test checks for the exact SHA", () => { +test("requires successful builds and no pending or failed source/security checks on the exact SHA", () => { const check = { name: "Build & Test", app: { slug: "github-actions" }, @@ -92,10 +92,37 @@ test("requires successful GitHub Actions Build & Test checks for the exact SHA", status: "completed", conclusion: "success", }; + const security = [ + { ...check, name: "CodeQL", app: { slug: "github-advanced-security" } }, + { + ...check, + name: "Oneleet Code Security Scan", + app: { slug: "oneleet-code" }, + }, + ]; assertSuccessfulChecks( - [{ check_runs: [check] }, { check_runs: [check] }], + [{ check_runs: [check, ...security] }, { check_runs: [check] }], sha, ); + assert.throws( + () => assertSuccessfulChecks([{ check_runs: [check] }], sha), + /security check/, + ); + assert.throws( + () => + assertSuccessfulChecks( + [ + { + check_runs: [ + check, + ...security.map((item) => ({ ...item, conclusion: "skipped" })), + ], + }, + ], + sha, + ), + /security check/, + ); for (const checks of [ [], [{ ...check, app: { slug: "other-app" } }], @@ -103,9 +130,34 @@ test("requires successful GitHub Actions Build & Test checks for the exact SHA", [{ ...check, status: "in_progress", conclusion: null }], [check, { ...check, conclusion: "failure" }], [{ ...check, conclusion: "skipped" }], + [check, { ...check, name: "CodeQL", conclusion: "failure" }], + [ + check, + { ...check, name: "Oneleet", status: "in_progress", conclusion: null }, + ], ]) { - assert.throws(() => assertSuccessfulChecks([{ check_runs: checks }], sha)); + assert.throws(() => + assertSuccessfulChecks([{ check_runs: [...security, ...checks] }], sha), + ); } + assertSuccessfulChecks( + [ + { + check_runs: [ + check, + ...security, + { + ...check, + name: "copilot-pull-request-reviewer", + conclusion: "failure", + }, + { ...check, name: "dependabot-merge", conclusion: "skipped" }, + { ...check, name: "informational", conclusion: "neutral" }, + ], + }, + ], + sha, + ); }); test("publishing requires an existing environment with required reviewers", () => { @@ -358,6 +410,17 @@ test("workflow is manually dispatched, defaults to artifact-only and fixes the n assert.equal(workflow.on.workflow_dispatch.inputs.version.default, version); assert.deepEqual(workflow.permissions, { contents: "read" }); assert.equal(workflow.concurrency["cancel-in-progress"], false); + for (const job of Object.values(workflow.jobs)) { + assert.ok( + job.steps.every((step) => !step.uses?.startsWith("actions/cache@")), + ); + for (const setup of job.steps.filter((step) => + step.uses?.startsWith("actions/setup-node@"), + )) { + assert.equal(setup.with.cache, undefined); + assert.equal(setup.with["package-manager-cache"], false); + } + } const prepareJob = workflow.jobs.prepare; const publish = workflow.jobs.publish; assert.equal(prepareJob.permissions["id-token"], undefined);