| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | import type { Setting } from "@g1t/contracts"; |
| 4 | import { settingOverride } from "./setting-overrides.ts"; |
| 5 | |
| 6 | const workspace: Setting = { id: "w", name: "TOKEN", kind: "secret", scope: "workspace", value: null, updatedAt: "", environments: [], availableTo: ["workflows", "deployments"], projects: [] }; |
| 7 | const project: Setting = { ...workspace, id: "p", scope: "project" }; |
| 8 | |
| 9 | test("full overrides remain visible on both scopes", () => { |
| 10 | assert.equal(settingOverride(workspace, [workspace, project]), "Overridden by project"); |
| 11 | assert.match(settingOverride(project, [workspace, project])!, /^Overrides workspace/); |
| 12 | }); |
| 13 | |
| 14 | test("environment-restricted project keys still suppress workspace fallback", () => { |
| 15 | assert.equal(settingOverride(workspace, [workspace, { ...project, environments: ["production"] }]), "Overridden by project"); |
| 16 | assert.equal(settingOverride({ ...workspace, environments: ["production"] }, [workspace, { ...project, environments: ["preview"] }]), "Overridden by project"); |
| 17 | }); |
| 18 | |
| 19 | test("only shared readers are overridden", () => { |
| 20 | assert.equal(settingOverride(workspace, [workspace, { ...project, availableTo: ["workflows"] }]), "Partially overridden: Workflows"); |
| 21 | assert.equal(settingOverride(workspace, [workspace, { ...project, availableTo: ["workflows"] }, { ...project, availableTo: ["deployments"] }]), "Overridden by project"); |
| 22 | }); |
| 23 | |
| 24 | test("different names, kinds and readers do not override", () => { |
| 25 | const scoped = { ...workspace, availableTo: ["workflows"] }; |
| 26 | for (const other of [{ ...project, name: "OTHER" }, { ...project, kind: "variable" }, { ...project, availableTo: ["deployments"] }]) { |
| 27 | assert.equal(settingOverride(scoped, [scoped, other]), null); |
| 28 | } |
| 29 | }); |