|
| 1 | +import { describe, it } from "node:test" |
| 2 | +import assert from "node:assert/strict" |
| 3 | +import fs from "node:fs" |
| 4 | +import path from "node:path" |
| 5 | +import { fileURLToPath } from "node:url" |
| 6 | + |
| 7 | +const __filename = fileURLToPath(import.meta.url) |
| 8 | +const __dirname = path.dirname(__filename) |
| 9 | +const repoRoot = path.resolve(__dirname, "..", "..") |
| 10 | +const artifactPath = path.join(repoRoot, "openapi", "components", "tinynode-shared-components.openapi.yaml") |
| 11 | +const workflowPath = path.join(repoRoot, ".github", "workflows", "shared_openapi_sync.yaml") |
| 12 | + |
| 13 | +describe("Shared OpenAPI artifact sync scaffolding.", () => { |
| 14 | + it("the canonical shared artifact has valid OpenAPI structure. __exists __core", () => { |
| 15 | + const artifact = fs.readFileSync(artifactPath, "utf8") |
| 16 | + assert.match(artifact, /^openapi: 3\.\d+\.\d+/m, "artifact must declare an openapi 3.x version") |
| 17 | + assert.match(artifact, /^\s+title: \S/m, "artifact info.title must be present and non-empty") |
| 18 | + assert.match(artifact, /^\s+version: \d+\.\d+\.\d+/m, "artifact info.version must be a semver-style string") |
| 19 | + assert.match(artifact, /^components:/m, "artifact must define a top-level components section") |
| 20 | + assert.match(artifact, /^\s+schemas:/m, "artifact must define components.schemas") |
| 21 | + }) |
| 22 | + |
| 23 | + it("the sync workflow targets the correct receiver repo and paths. __exists __core", () => { |
| 24 | + const workflow = fs.readFileSync(workflowPath, "utf8") |
| 25 | + assert.match(workflow, /repository:\s*cubap\/rerum_openapi/, "workflow must check out cubap/rerum_openapi as the receiver") |
| 26 | + assert.match(workflow, /openapi\/components\/tinynode-shared-components\.openapi\.yaml/, "workflow must reference the canonical source path") |
| 27 | + assert.match(workflow, /schemas\/openapi\/tinynode-shared-components\.openapi\.yaml/, "workflow must reference the receiver target path") |
| 28 | + assert.match( |
| 29 | + workflow, |
| 30 | + /cp\s+openapi\/components\/tinynode-shared-components\.openapi\.yaml\s+\S*schemas\/openapi\/tinynode-shared-components\.openapi\.yaml/, |
| 31 | + "workflow's cp command must copy from the canonical source to the receiver target — a retargeted copy would silently corrupt the receiver" |
| 32 | + ) |
| 33 | + }) |
| 34 | + |
| 35 | + it("the sync workflow uses the expected action version and org secret. __exists __core", () => { |
| 36 | + const workflow = fs.readFileSync(workflowPath, "utf8") |
| 37 | + assert.match(workflow, /peter-evans\/create-pull-request@v\d+/, "workflow must use a pinned major version of peter-evans/create-pull-request") |
| 38 | + assert.match( |
| 39 | + workflow, |
| 40 | + /secrets\.OPENAPI(?!\w)/, |
| 41 | + "workflow must read the org-level secret named OPENAPI — a rename here breaks the sync silently at the receiver checkout step" |
| 42 | + ) |
| 43 | + }) |
| 44 | +}) |
0 commit comments